Annotation of loncom/interface/lonrequestcourse.pm, revision 1.31
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.31 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.30 2009/09/07 06:30:49 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: =head1 NAME
31:
32: Apache::lonrequestcourse.pm
33:
34: =head1 SYNOPSIS
35:
36: Allows users to request creation of new courses.
37:
38: This is part of the LearningOnline Network with CAPA project
39: described at http://www.lon-capa.org.
40:
41: =head1 SUBROUTINES
42:
43: =over
44:
45: =item handler()
46:
1.27 raeburn 47: =item get_breadcrumbs()
48:
1.12 raeburn 49: =item header()
50:
51: =item form_elements()
52:
53: =item onload_action()
54:
55: =item check_can_request()
56:
57: =item course_types()
58:
59: =item print_main_menu()
60:
61: =item request_administration()
62:
1.27 raeburn 63: =item close_popup_form()
64:
65: =item get_instcode()
66:
1.12 raeburn 67: =item print_request_form()
68:
69: =item print_enrollment_menu()
70:
1.27 raeburn 71: =item show_invalid_crosslists()
72:
1.12 raeburn 73: =item inst_section_selector()
74:
75: =item date_setting_table()
76:
77: =item print_personnel_menu()
78:
79: =item print_request_status()
80:
81: =item print_request_logs()
82:
83: =item print_review()
84:
85: =item dates_from_form()
86:
87: =item courseinfo_form()
88:
89: =item clone_form()
90:
91: =item clone_text()
92:
93: =item coursecode_form()
94:
95: =item get_course_dom()
96:
97: =item display_navbuttons()
98:
99: =item print_request_outcome()
100:
101: =item get_processtype()
102:
103: =item check_autolimit()
104:
105: =item retrieve_settings()
106:
107: =item get_request_settings()
108:
1.27 raeburn 109: =item extract_instcode()
110:
111: =item generate_date_items()
112:
1.1 raeburn 113: =back
114:
115: =cut
116:
117: package Apache::lonrequestcourse;
118:
119: use strict;
120: use Apache::Constants qw(:common :http);
121: use Apache::lonnet;
122: use Apache::loncommon;
123: use Apache::lonlocal;
1.8 raeburn 124: use Apache::loncoursequeueadmin;
1.30 raeburn 125: use Apache::lonuserutils;
1.4 raeburn 126: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 127:
128: sub handler {
129: my ($r) = @_;
1.20 raeburn 130: &Apache::loncommon::content_type($r,'text/html');
131: $r->send_http_header;
1.1 raeburn 132: if ($r->header_only) {
133: return OK;
134: }
135:
1.27 raeburn 136: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
137: ['action','showdom','cnum','state']);
1.2 raeburn 138: &Apache::lonhtmlcommon::clear_breadcrumbs();
139: my $dom = &get_course_dom();
1.1 raeburn 140: my $action = $env{'form.action'};
141: my $state = $env{'form.state'};
1.27 raeburn 142: my (%states,%stored);
143: my ($jscript,$uname,$udom,$result,$warning);
144:
145: $states{'display'} = ['details'];
146: $states{'view'} = ['pick_request','details','cancel','removal'];
147: $states{'log'} = ['filter','display'];
148: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
149:
150: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
151: unless ($env{'form.state'} eq 'crstype') {
152: unshift(@{$states{'new'}},'codepick');
153: }
154: }
155:
156: foreach my $key (keys(%states)) {
157: if (ref($states{$key}) eq 'ARRAY') {
158: unshift (@{$states{$key}},'crstype');
159: }
160: }
161:
162: my @invalidcrosslist;
163: my %trail = (
164: crstype => 'Course Request Action',
165: codepick => 'Category',
166: courseinfo => 'Description',
167: enrollment => 'Access Dates',
168: personnel => 'Personnel',
169: review => 'Review',
170: process => 'Result',
171: pick_request => 'Display Summary',
172: details => 'Request Details',
173: cancel => 'Cancel Request',
174: removal => 'Outcome',
175: );
176:
177: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
178: $trail{'enrollment'} = 'Enrollment';
179: }
180:
181: my ($page,$crumb,$newinstcode,$codechk,$checkedcode) =
182: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26 raeburn 183: if ($action eq 'display') {
184: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
185: my $namespace = 'courserequestqueue';
186: if ($env{'form.cnum'} ne '') {
187: my $cnum = $env{'form.cnum'};
188: my $reqkey = $cnum.'_approval';
189: my $namespace = 'courserequestqueue';
190: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
191: my %queued =
192: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
193: if (ref($queued{$reqkey}) eq 'HASH') {
194: $uname = $queued{$reqkey}{'ownername'};
195: $udom = $queued{$reqkey}{'ownerdom'};
196: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
197: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
198: } else {
199: $warning = &mt('Invalid username or domain for course requestor');
200: }
201: } else {
202: $warning = &mt('No information was found for this course request.');
203: }
204: } else {
205: $warning = &mt('No course request ID provided.');
206: }
207: } else {
208: $warning = &mt('You do not have rights to view course request information.');
209: }
210: } elsif ((defined($state)) && (defined($action))) {
1.16 raeburn 211: if (($action eq 'view') && ($state eq 'details')) {
212: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
213: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2 raeburn 214: }
1.27 raeburn 215: } elsif ($env{'form.crstype'} eq 'official') {
216: if (&Apache::lonnet::auto_run('',$dom)) {
217: if (($action eq 'new') && (($state eq 'enrollment') ||
218: ($state eq 'personnel'))) {
219: my $checkcrosslist = 0;
220: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
221: if ($env{'form.crosslist_'.$i}) {
222: $checkcrosslist ++;
223: }
224: }
225: if ($checkcrosslist) {
226: my %codechk;
227: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
228: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
229: \%cat_titles,
230: \%cat_order,
231: \@code_order);
232: my $numtitles = scalar(@codetitles);
233: if ($numtitles) {
234: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
235: if ($env{'form.crosslist_'.$i}) {
236: my $codecheck;
237: my $crosslistcode = '';
238: foreach my $item (@code_order) {
239: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
240: }
241: if ($crosslistcode ne '') {
242: $codechk{$i} =
243: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
244: }
245: unless ($codechk{$i} eq 'valid') {
246: $env{'form.crosslist_'.$i} = '';
247: push(@invalidcrosslist,$crosslistcode);
248: }
249: }
250: }
251: }
252: }
253: }
254: }
1.2 raeburn 255: }
1.16 raeburn 256: my %elements = &form_elements($dom);
1.2 raeburn 257: my $elementsref = {};
258: if (ref($elements{$action}) eq 'HASH') {
259: if (ref($elements{$action}{$state}) eq 'HASH') {
260: $elementsref = $elements{$action}{$state};
261: }
262: }
1.16 raeburn 263: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
264: $env{'form.clonedom'} = $dom;
265: }
1.30 raeburn 266: if ($state eq 'crstype') {
267: $jscript = &mainmenu_javascript();
268: } else {
269: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
270: }
1.2 raeburn 271: }
272:
273: if ($state eq 'personnel') {
274: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
275: }
276:
277: my $loaditems = &onload_action($action,$state);
278:
1.1 raeburn 279: my %can_request;
280: my $canreq = &check_can_request($dom,\%can_request);
281: if ($action eq 'new') {
282: if ($canreq) {
283: if ($state eq 'crstype') {
1.3 raeburn 284: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
285: $crumb);
1.1 raeburn 286: } else {
1.27 raeburn 287: &request_administration($r,$action,$state,$page,\%states,$dom,
288: $jscript,$loaditems,$crumb,$newinstcode,
289: $codechk,$checkedcode,\@invalidcrosslist);
1.1 raeburn 290: }
291: } else {
1.3 raeburn 292: $r->print(&header('Course Requests').$crumb.
1.1 raeburn 293: '<div class="LC_warning">'.
294: &mt('You do not have privileges to request creation of courses.').
1.2 raeburn 295: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 296: }
297: } elsif ($action eq 'view') {
1.10 raeburn 298: if ($state eq 'crstype') {
1.30 raeburn 299: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb);
1.26 raeburn 300: } else {
301: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
302: $loaditems,$crumb);
303: }
304: } elsif ($action eq 'display') {
305: if ($warning ne '') {
306: my $args = { only_body => 1 };
307: $r->print(&header('Course Requests','','',$args).$crumb.
308: '<h3>'.&mt('Course Request Details').'</h3>'.
309: '<div class="LC_warning">'.$warning.'</div>'.
310: &close_popup_form());
1.11 raeburn 311: } else {
1.26 raeburn 312: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.27 raeburn 313: $loaditems,$crumb,'','','','',$uname,$udom);
1.10 raeburn 314: }
1.1 raeburn 315: } elsif ($action eq 'log') {
1.3 raeburn 316: &print_request_logs($jscript,$loaditems,$crumb);
1.1 raeburn 317: } else {
1.3 raeburn 318: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb);
1.1 raeburn 319: }
320: return OK;
321: }
322:
1.30 raeburn 323: sub mainmenu_javascript {
324: return <<"END";
325: function setType(courseForm) {
326: for (var i=0; i<courseForm.crstype.length; i++) {
327: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
328: courseForm.crstype.options[i].selected = true;
329: } else {
330: courseForm.crstype.options[i].selected = false;
331: }
332: }
333: }
334:
335: function setAction(courseForm) {
336: for (var i=0; i<courseForm.action.length; i++) {
337: if (courseForm.action.options[i].value == "$env{'form.action'}") {
338: courseForm.action.options[i].selected = true;
339: } else {
340: courseForm.action.options[i].selected = false;
341: }
342: }
343: }
344: END
345: }
346:
1.27 raeburn 347: sub get_breadcrumbs {
348: my ($dom,$action,$state,$states,$trail) = @_;
349: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles);
350: my $page = 0;
351: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
352: if (defined($action)) {
353: my $done = 0;
354: my $i=0;
355: if (ref($states->{$action}) eq 'ARRAY') {
356: while ($i<@{$states->{$action}} && !$done) {
357: if ($states->{$action}[$i] eq $$state) {
358: $page = $i;
359: $done = 1;
360: }
361: $i++;
362: }
363: }
364: if ($env{'form.crstype'} eq 'official') {
365: if ($page > 1) {
366: if ($states->{$action}[$page-1] eq 'codepick') {
367: if ($env{'form.instcode'} eq '') {
368: ($newinstcode,$numtitles) = &get_instcode($dom);
369: if ($numtitles) {
370: if ($newinstcode eq '') {
371: $$state = 'codepick';
372: $page --;
373: } else {
374: $codechk =
375: &Apache::lonnet::auto_validate_instcode('',
376: $dom,$newinstcode);
377: if ($codechk ne 'valid') {
378: $$state = 'codepick';
379: $page --;
380: }
381: $checkedcode = 1;
382: }
383: }
384: }
385: }
386: }
387: }
388: for (my $i=0; $i<@{$states->{$action}}; $i++) {
389: if ($$state eq $states->{$action}[$i]) {
390: &Apache::lonhtmlcommon::add_breadcrumb(
391: {text=>"$trail->{$$state}"});
392: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
393: last;
394: } else {
395: if (($$state eq 'process') || ($$state eq 'removal')) {
396: &Apache::lonhtmlcommon::add_breadcrumb(
397: { href => '/adm/requestcourse',
398: text => "$trail->{$states->{$action}[$i]}",
399: }
400: );
401: } else {
402: &Apache::lonhtmlcommon::add_breadcrumb(
403: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
404: text => "$trail->{$states->{$action}[$i]}", }
405: );
406: }
407: }
408: }
409: } else {
410: &Apache::lonhtmlcommon::add_breadcrumb(
411: {text=>'Pick Action'});
412: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
413: }
414: } else {
415: &Apache::lonhtmlcommon::add_breadcrumb(
416: {text=>'Pick Action'});
417: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
418: }
419: return ($page,$crumb,$newinstcode,$codechk,$checkedcode);
420: }
421:
1.2 raeburn 422: sub header {
1.26 raeburn 423: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2 raeburn 424: if ($jscript) {
1.6 raeburn 425: $jscript = '<script type="text/javascript">'."\n".
426: '// <![CDATA['."\n".
427: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 428: }
429: if ($loaditems) {
1.26 raeburn 430: if (ref($args) eq 'HASH') {
431: my %loadhash = (
432: 'add_entries' => $loaditems,
433: );
434: my %arghash = (%loadhash,%{$args});
435: $args = \%arghash;
436: } else {
437: $args = {'add_entries' => $loaditems,};
438: }
1.3 raeburn 439: }
1.26 raeburn 440: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2 raeburn 441: }
442:
443: sub form_elements {
444: my ($dom) = @_;
445: my %elements =
446: (
447: new => {
448: crstype => {
449: crstype => 'selectbox',
450: action => 'selectbox',
1.16 raeburn 451: origcnum => 'hidden',
1.2 raeburn 452: },
453: courseinfo => {
454: cdescr => 'text',
1.13 raeburn 455: clonecrs => 'text',
456: clonedom => 'selectbox',
1.2 raeburn 457: datemode => 'radio',
458: dateshift => 'text',
459: },
460: enrollment => {
1.13 raeburn 461: accessstart_month => 'selectbox',
462: accessstart_hour => 'selectbox',
463: accessend_month => 'selectbox',
464: accessend_hour => 'selectbox',
465: accessstart_day => 'text',
466: accessstart_year => 'text',
467: accessstart_minute => 'text',
468: accessstart_second => 'text',
469: accessend_day => 'text',
470: accessend_year => 'text',
471: accessend_minute => 'text',
472: accessend_second => 'text',
1.2 raeburn 473: no_end_date => 'checkbox',
474: },
475: personnel => {
476: addperson => 'checkbox',
477: },
1.13 raeburn 478: review => {
479: cnum => 'hidden',
480: },
1.2 raeburn 481: },
482: view => {
483: crstype => {
484: crstype => 'selectbox',
485: action => 'selectbox',
486: },
487: },
488: );
1.13 raeburn 489: my %servers = &Apache::lonnet::get_servers($dom,'library');
490: my $numlib = keys(%servers);
491: if ($numlib > 1) {
492: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
493: } else {
494: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
495: }
1.2 raeburn 496: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
497: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
498: \%cat_order,\@code_order);
499: my $numtitles = scalar(@codetitles);
500: if ($numtitles) {
501: my %extras;
502: $lastitem = pop(@codetitles);
503: $extras{'instcode_'.$lastitem} = 'text';
504: foreach my $item (@codetitles) {
505: $extras{'instcode_'.$item} = 'selectbox';
506: }
507: $elements{'new'}{'codepick'} = \%extras;
508: }
509: if (&Apache::lonnet::auto_run('',$dom)) {
510: my %extras = (
511: sectotal => 'hidden',
1.13 raeburn 512: enrollstart_month => 'selectbox',
513: enrollstart_hour => 'selectbox',
514: enrollend_month => 'selectbox',
515: enrollend_hour => 'selectbox',
516: enrollstart_day => 'text',
517: enrollstart_year => 'text',
518: enrollstart_minute => 'text',
519: enrollstart_second => 'text',
520: enrollend_day => 'text',
521: enrollend_year => 'text',
522: enrollend_minute => 'text',
523: enrollend_second => 'text',
1.2 raeburn 524: addcrosslist => 'checkbox',
525: autoadds => 'radio',
526: autodrops => 'radio',
527: );
528: if ($env{'form.sectotal'} > 0) {
529: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 ! raeburn 530: $extras{'sec_'.$i} = 'radio';
! 531: $extras{'secnum_'.$i} = 'text';
! 532: $extras{'loncapasec_'.$i} = 'text';
1.2 raeburn 533: }
534: }
535: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 536: if ($env{'form.addcrosslist'}) {
537: $crosslisttotal ++;
538: }
1.24 raeburn 539: if (!$crosslisttotal) {
1.2 raeburn 540: $crosslisttotal = 1;
541: }
1.27 raeburn 542:
1.24 raeburn 543: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
544: if ($numtitles) {
545: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
546: }
547: if (@codetitles > 0) {
548: foreach my $item (@codetitles) {
549: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2 raeburn 550: }
551: }
1.24 raeburn 552: $extras{'crosslist_'.$i} = 'checkbox';
553: $extras{'crosslist_'.$i.'_instsec'} = 'text',
554: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2 raeburn 555: }
556: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
557: %{$elements{'new'}{'enrollment'}} = %mergedhash;
558: }
559: my %people;
560: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 561: if ($env{'form.addperson'}) {
562: $persontotal ++;
563: }
564: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 565: $persontotal = 1;
566: }
567: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 568: $people{'person_'.$i.'_uname'} = 'text',
569: $people{'person_'.$i.'_dom'} = 'selectbox',
570: $people{'person_'.$i.'_hidedom'} = 'hidden',
571: $people{'person_'.$i.'_firstname'} = 'text',
572: $people{'person_'.$i.'_lastname'} = 'text',
573: $people{'person_'.$i.'_emailaddr'} = 'text',
574: $people{'person_'.$i.'_role'} = 'selectbox',
575: $people{'person_'.$i.'_sec'} = 'selectbox',
576: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 577: }
578: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
579: %{$elements{'new'}{'personnel'}} = %personnelhash;
580: return %elements;
581: }
582:
583: sub onload_action {
584: my ($action,$state) = @_;
585: my %loaditems;
586: if (($action eq 'new') || ($action eq 'view')) {
1.30 raeburn 587: if ($state eq 'crstype') {
588: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
589: } else {
590: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs)';
591: }
1.2 raeburn 592: }
593: return \%loaditems;
594: }
595:
1.1 raeburn 596: sub check_can_request {
597: my ($dom,$can_request) = @_;
598: my $canreq = 0;
1.4 raeburn 599: my ($types,$typename) = &course_types();
1.19 raeburn 600: my @options = ('approval','validate','autolimit');
601: my $optregex = join('|',@options);
1.4 raeburn 602: if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
603: foreach my $type (@{$types}) {
1.1 raeburn 604: if (&Apache::lonnet::usertools_access($env{'user.name'},
605: $env{'user.domain'},
606: $type,undef,'requestcourses')) {
607: $canreq ++;
608: if ($dom eq $env{'user.domain'}) {
609: $can_request->{$type} = 1;
610: }
611: }
612: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
613: my @curr = split(',',$env{'environment.reqcrsotherdom.'.$type});
614: if (@curr > 0) {
615: $canreq ++;
616: unless ($dom eq $env{'user.domain'}) {
1.19 raeburn 617: if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) {
1.1 raeburn 618: $can_request->{$type} = 1;
619: }
620: }
621: }
622: }
623: }
624: }
625: return $canreq;
626: }
627:
1.4 raeburn 628: sub course_types {
629: my @types = ('official','unofficial','community');
630: my %typename = (
631: official => 'Official course',
632: unofficial => 'Unofficial course',
633: community => 'Community',
634: );
635: return (\@types,\%typename);
636: }
637:
638:
1.1 raeburn 639: sub print_main_menu {
1.3 raeburn 640: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb) = @_;
1.4 raeburn 641: my ($types,$typename) = &course_types();
1.1 raeburn 642: my $onchange;
643: unless ($env{'form.interface'} eq 'textual') {
644: $onchange = 1;
645: }
646:
1.2 raeburn 647: my $nextstate_setter = "\n";
648: if (ref($states) eq 'HASH') {
649: foreach my $key (keys(%{$states})) {
650: if (ref($states->{$key}) eq 'ARRAY') {
651: $nextstate_setter .=
652: " if (actionchoice == '$key') {
653: nextstate = '".$states->{$key}[1]."';
654: }
655: ";
656: }
657: }
658: }
1.1 raeburn 659:
1.2 raeburn 660: my $js = <<"END";
1.1 raeburn 661:
1.2 raeburn 662: function nextPage(formname) {
1.27 raeburn 663: var crschoice = document.mainmenu_coursetype.crstype.value;
664: var actionchoice = document.mainmenu_action.action.value;
1.2 raeburn 665: if (check_can_request(crschoice,actionchoice) == true) {
666: if ((actionchoice == 'new') && (crschoice == 'official')) {
667: nextstate = 'codepick';
668: } else {
669: $nextstate_setter
1.27 raeburn 670: }
671: formname.crstype.value = crschoice;
672: formname.action.value = actionchoice;
1.1 raeburn 673: formname.state.value= nextstate;
674: formname.submit();
675: }
676: return;
677: }
678:
1.2 raeburn 679: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 680: var official = '';
681: var unofficial = '';
682: var community = '';
683: END
684:
685: foreach my $item (keys(%{$can_request})) {
686: $js .= "
687: $item = 1;
688: ";
689: }
690: my %lt = &Apache::lonlocal::texthash(
691: official => 'You are not permitted to request creation of an official course in this domain.',
692: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
693: community => 'You are not permitted to request creation of a community this domain.',
694: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
695: );
696: $js .= <<END;
697: if (crschoice == 'official') {
698: if (official != 1) {
699: alert("$lt{'official'}");
700: return false;
701: }
702: } else {
703: if (crschoice == 'unofficial') {
704: if (unofficial != 1) {
705: alert("$lt{'unofficial'}");
706: return false;
707: }
708: } else {
709: if (crschoice == 'community') {
710: if (community != 1) {
711: alert("$lt{'community'}");
712: return false;
713: }
714: } else {
715: if (actionchoice == 'new') {
716: alert("$lt{'all'}");
717: return false;
718: }
719: }
720: }
721: }
722: return true;
723: }
724:
725: END
726:
1.27 raeburn 727: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.'<div>'.
728: &Apache::lonhtmlcommon::start_pick_box().
729: &Apache::lonhtmlcommon::row_title(&mt('Course Domain')).
1.1 raeburn 730: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
731: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
732: if (!$onchange) {
733: $r->print(' <input type="submit" name="godom" value="'.
734: &mt('Change').'" />');
735: }
1.27 raeburn 736: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.1 raeburn 737:
1.2 raeburn 738: my $formname = 'requestcrs';
1.1 raeburn 739: my $nexttext = &mt('Next');
1.27 raeburn 740: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
741: <form name="mainmenu_action" method="post" action="">
1.1 raeburn 742: <select size="1" name="action" >
1.2 raeburn 743: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 744: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
745: <option value="log">'.&mt('View request history').'</option>
1.27 raeburn 746: </select></form>'.
747: &Apache::lonhtmlcommon::row_closure(1).
748: &Apache::lonhtmlcommon::row_title(&mt('Course Type')).'
749: <form name="mainmenu_coursetype" method="post" action="">
1.1 raeburn 750: <select size="1" name="crstype">
1.4 raeburn 751: <option value="any">'.&mt('All types').'</option>');
752: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
753: foreach my $type (@{$types}) {
754: my $selected = '';
755: if ($type eq 'official') {
756: $selected = ' selected="selected"';
757: }
758: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
759: '</option>'."\n");
760: }
761: }
1.27 raeburn 762: $r->print('</select></form>'."\n".
763: &Apache::lonhtmlcommon::row_closure(1)."\n".
764: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
765: '<div><form name="'.$formname.'" method="post" action="">'."\n".
766: '<input type="hidden" name="state" value="crstype" />'."\n".
767: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
768: '<input type="hidden" name="crstype" value="" />'."\n".
769: '<input type="hidden" name="action" value="" />'."\n".
770: '<input type="button" name="next" value="'.$nexttext.
771: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
772: '</form></div>');
1.1 raeburn 773: $r->print(&Apache::loncommon::end_page());
774: return;
775: }
776:
777: sub request_administration {
1.27 raeburn 778: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
779: $newinstcode,$codechk,$checkedcode,$invalidcrosslist,$uname,$udom) = @_;
1.2 raeburn 780: my $js;
1.16 raeburn 781: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 782: $js = <<END;
1.1 raeburn 783:
784: function nextPage(formname,nextstate) {
785: formname.state.value= nextstate;
786: formname.submit();
787: }
1.16 raeburn 788:
789: END
790: }
791: if (($action eq 'new') || ($action eq 'view')) {
792: $js .= <<END;
793:
1.1 raeburn 794: function backPage(formname,prevstate) {
795: formname.state.value = prevstate;
796: formname.submit();
797: }
798:
799: END
1.2 raeburn 800: }
801: if ($action eq 'new') {
802: my $jsextra;
1.31 ! raeburn 803: if ($state eq 'courseinfo') {
1.2 raeburn 804: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31 ! raeburn 805: } elsif ($state eq 'enrollment') {
! 806: if (($env{'form.crstype'} eq 'official') &&
! 807: (&Apache::lonnet::auto_run('',$dom))) {
! 808: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
! 809: }
! 810: } elsif ($state eq 'personnel') {
! 811: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
1.1 raeburn 812: }
1.3 raeburn 813: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
1.27 raeburn 814: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
815: $codechk,$checkedcode,$invalidcrosslist);
1.2 raeburn 816: } elsif ($action eq 'view') {
1.16 raeburn 817: my $jsextra;
818: my $formname = 'requestcrs';
819: my $prev = $states->{$action}[$page-1];
820: my $next = $states->{$action}[$page+1];
821: if ($state eq 'pick_request') {
822: $next = $states->{$action}[$page+1];
823: $jsextra = &viewrequest_javascript($formname,$next);
824: } elsif ($state eq 'details') {
825: $jsextra = &viewdetails_javascript($formname);
826:
827: } elsif ($state eq 'cancel') {
828: $jsextra = &viewcancel_javascript($formname);
829: }
830: $r->print(&header('Manage course requests',$js.$jscript.$jsextra,$loaditems).
831: $crumb);
832: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 833: if ($state eq 'pick_request') {
1.16 raeburn 834: $r->print('<h3>'.&mt('Pending course requests').'</h3><div>'."\n".$form."\n".
1.30 raeburn 835: &print_request_status($dom).'</form></div>');
1.16 raeburn 836: } elsif ($state eq 'details') {
837: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
838: my $origcnum = $env{'form.cnum'};
839: if ($origcnum eq '') {
840: $origcnum = $env{'form.origcnum'};
841: }
842: if ($env{'form.crstype'} eq 'official') {
843: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
844: \%cat_order,\@code_order);
845: }
846: $r->print('<h3>'.&mt('Course Request Details').'</h3><div>'."\n".$form."\n".
1.26 raeburn 847: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.16 raeburn 848: \@code_order)."\n".
849: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
850: my @excluded = &get_excluded_elements($dom,$states,'new','review');
851: push(@excluded,'origcnum');
852: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
853: my $other = 'modify';
854: my %navtxt = &Apache::lonlocal::texthash (
855: prev => 'Back',
856: other => 'Modify Request',
857: next => 'Cancel Request',
858: );
1.31 ! raeburn 859: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
! 860: $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16 raeburn 861: $r->print('</form>');
862: } elsif ($state eq 'cancel') {
863: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
864: $r->print('<h3>'.&mt('Cancel course request').'</h3><div>'."\n".$form."\n".
865: $output);
866: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
867: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
868: my %navtxt = &Apache::lonlocal::texthash (
869: prev => 'Back',
870: next => 'Confirm Cancellation',
871: );
872: if ($result eq 'ok') {
1.31 ! raeburn 873: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16 raeburn 874: $navtxt{'next'},$state);
875: } else {
1.31 ! raeburn 876: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
! 877: '',$state);
1.16 raeburn 878: }
879: $r->print('</form>');
880: } elsif ($state eq 'removal') {
881: my $cnum = $env{'form.origcnum'};
882: my $statuskey = 'status:'.$dom.':'.$cnum;
883: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
884: $env{'user.domain'},$env{'user.name'});
885: my $currstatus = $userreqhash{$statuskey};
886: my ($result,$error);
887: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
888: my %status = (
889: $statuskey => 'cancelled',
890: );
891: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
892: if ($statusresult eq 'ok') {
893: my $delresult =
894: &Apache::lonnet::del_dom('courserequestqueue',
895: [$cnum.'_'.$currstatus],$dom);
896: if ($delresult eq 'ok') {
897: $result = 'ok';
898: } else {
899: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
900: }
901: } else {
902: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
903: }
904: } else {
905: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
906: }
907: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
908: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
909: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
910: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
911: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
912: if ($result eq 'ok') {
913: $r->print(&mt('Your course request has been cancelled.'));
914: } else {
915: $r->print('<div class="LC_error">'.
916: &mt('The request cancellation process was not complete.').
917: '<br />'.$error.'</div>');
918: }
919: $r->print('</form>');
1.11 raeburn 920: }
1.26 raeburn 921: } elsif ($action eq 'display') {
922: my $formname = 'requestcrs';
923: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
924: if ($env{'form.crstype'} eq 'official') {
925: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
926: \%cat_order,\@code_order);
927: }
928: $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
929: $crumb."\n".'<h3>'.&mt('Course Request Details').'</h3>'.
930: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
931: \@code_order,$uname,$udom)."\n".'</div>'.
932: &close_popup_form());
1.1 raeburn 933: } elsif ($action eq 'log') {
1.11 raeburn 934: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 935: }
1.2 raeburn 936: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 937: return;
938: }
939:
1.31 ! raeburn 940: sub enrollment_lcsec_js {
! 941: my %alerts = §ion_check_alerts();
! 942: my $secname = $alerts{'badsec'};
! 943: my $secnone = $alerts{'reserved'};
! 944: my $output = '
! 945: function validateEnrollSections(formname,nextstate) {
! 946: var badsectotal = 0;
! 947: var reservedtotal = 0;
! 948: var secTest = "";
! 949: ';
! 950: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
! 951: $output .= "
! 952: var selSec = 0;
! 953: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
! 954: if (document.requestcrs.sec_".$i."[j].checked) {
! 955: selSec = document.requestcrs.sec_".$i."[j].value;
! 956: }
! 957: if (selSec == 1) {
! 958: secTest = validsection(document.requestcrs.loncapasec_".$i.");
! 959: if (secTest == 'badsec') {
! 960: badsectotal++;
! 961: }
! 962: if (secTest == 'reserved') {
! 963: reservedtotal++;
! 964: }
! 965: }
! 966: }
! 967: ";
! 968: }
! 969: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
! 970: $output .= "
! 971: if (document.requestcrs.crosslist_".$i.".checked) {
! 972: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
! 973: if (secTest == 'badsec') {
! 974: badsectotal++;
! 975: }
! 976: if (secTest == 'reserved') {
! 977: reservedtotal++;
! 978: }
! 979: }
! 980: ";
! 981: }
! 982: $output .= "
! 983: if (badsectotal>0) {
! 984: alert('$secname');
! 985: return false;
! 986: }
! 987: if (reservedtotal>0) {
! 988: alert('$secnone');
! 989: return false;
! 990: }
! 991: formname.state.value= nextstate;
! 992: formname.submit();
! 993: return;
! 994: }
! 995: ";
! 996: return $output;
! 997: }
! 998:
! 999: sub personnel_lcsec_js {
! 1000: my %alerts = §ion_check_alerts();
! 1001: my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
! 1002: my $secnone = $alerts{'reserved'};
! 1003: my $output = '
! 1004: function validatePersonnelSections(formname,nextstate) {
! 1005: var badsectotal = 0;
! 1006: var reservedtotal = 0;
! 1007: var secTest = "";
! 1008: ';
! 1009: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
! 1010: $output .= "
! 1011: if (document.requestcrs.person_".$i."_uname.value != '') {
! 1012: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
! 1013: if (secTest == 'badsec') {
! 1014: badsectotal++;
! 1015: }
! 1016: if (secTest == 'reserved') {
! 1017: reservedtotal++;
! 1018: }
! 1019: }
! 1020: ";
! 1021: }
! 1022: $output .= "
! 1023: if (badsectotal > 0) {
! 1024: alert('$secname');
! 1025: return false;
! 1026: } else {
! 1027: if (reservedtotal > 0) {
! 1028: alert('$secnone');
! 1029: return false;
! 1030: }
! 1031: }
! 1032: formname.state.value = nextstate;
! 1033: formname.submit();
! 1034: return;
! 1035: }
! 1036: ";
! 1037: return $output;
! 1038: }
! 1039:
! 1040: sub section_check_alerts {
! 1041: my %lt =
! 1042: &Apache::lonlocal::texthash(
! 1043: 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.",
! 1044: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
! 1045: separate => 'Separate multiple sections with a comma.'
! 1046: );
! 1047: return %lt;
! 1048: }
! 1049:
! 1050: sub section_check_javascript {
! 1051: return <<"END";
! 1052: function validsection(field,mult) {
! 1053: var str = field.value;
! 1054: var badsec=0;
! 1055: var reserved=0;
! 1056: if (window.RegExp) {
! 1057: var badsecnum=0;
! 1058: var reservednum=0;
! 1059: var pattern=/[^a-zA-Z0-9]/;
! 1060: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
! 1061: str = str.replace(/[ ]{2,}/gi," ");
! 1062: if (mult == '1') {
! 1063: var sections = new Array();
! 1064: sections = str.split(/\\s*[\\s,;:]\\s*/);
! 1065: var i;
! 1066: for (i=0; i<sections.length; i++) {
! 1067: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
! 1068: if (pattern.test(sections[i])) {
! 1069: badsecnum++;
! 1070: } else {
! 1071: if (sections[i] == 'none') {
! 1072: reservednum++;
! 1073: }
! 1074: }
! 1075: }
! 1076: }
! 1077: } else {
! 1078: if ((str != '') && (str != undefined) && (str != null)) {
! 1079: if (pattern.test(str)) {
! 1080: badsecnum++;
! 1081: } else {
! 1082: if (str == 'none') {
! 1083: reservednum++;
! 1084: }
! 1085: }
! 1086: }
! 1087: }
! 1088: if (badsecnum > 0) {
! 1089: return 'badsec';
! 1090: }
! 1091: if (reservednum > 0) {
! 1092: return 'reserved';
! 1093: }
! 1094: }
! 1095: return;
! 1096: }
! 1097: END
! 1098: }
! 1099:
1.26 raeburn 1100: sub close_popup_form {
1101: my $close= &mt('Close Window');
1102: return << "END";
1103: <p><form name="displayreq" action="" method="post">
1104: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1105: </form></p>
1106: END
1107: }
1108:
1.27 raeburn 1109: sub get_instcode {
1110: my ($dom) = @_;
1111: my ($instcode,$numtitles);
1112: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1113: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1114: \%cat_order,\@code_order);
1115: $numtitles = scalar(@codetitles);
1116: if (@code_order > 0) {
1117: my $message;
1118: foreach my $item (@code_order) {
1119: $instcode .= $env{'form.instcode_'.$item};
1120: }
1121: }
1122: return ($instcode,$numtitles);
1123: }
1124:
1.1 raeburn 1125: sub print_request_form {
1.27 raeburn 1126: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1127: $invalidcrosslist) = @_;
1.1 raeburn 1128: my $formname = 'requestcrs';
1.2 raeburn 1129: my ($next,$prev,$message,$output,$codepicker,$crstype);
1130: $prev = $states->{$action}[$page-1];
1131: $next = $states->{$action}[$page+1];
1.4 raeburn 1132: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 1133: prev => 'Back',
1.4 raeburn 1134: next => 'Next',
1135: );
1.2 raeburn 1136: $crstype = $env{'form.crstype'};
1.1 raeburn 1137: $r->print('<form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30 raeburn 1138: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1139: @disallowed);
1.1 raeburn 1140: if ($crstype eq 'official') {
1.2 raeburn 1141: if ($env{'form.instcode'} ne '') {
1142: $instcode = $env{'form.instcode'};
1.27 raeburn 1143: } elsif ($newinstcode ne '') {
1144: $instcode = $newinstcode;
1.2 raeburn 1145: }
1.27 raeburn 1146: if ($checkedcode) {
1147: if ($codechk eq 'valid') {
1148: $message = '<div class="LC_info">'.
1149: &mt('The chosen course category [_1] is valid.','<b>'.
1150: $instcode.'</b>').
1151: '<input type="hidden" name="instcode" value="'.
1152: $instcode.'" /></div>';
1.2 raeburn 1153: } else {
1154: $message = '<div class="LC_warning">'.
1.27 raeburn 1155: &mt('No course was found matching your choice of institutional course category.');
1156: if ($codechk ne '') {
1157: $message .= '<br />'.$codechk;
1158: }
1159: $message .= '</div>';
1.2 raeburn 1160: $prev = 'crstype';
1161: }
1162: $r->print($message);
1.1 raeburn 1163: }
1.2 raeburn 1164: }
1165: if ($prev eq 'crstype') {
1.4 raeburn 1166: if ($crstype eq 'official') {
1167: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1168: \%cat_order,\@code_order);
1169: }
1.2 raeburn 1170: if (@code_order > 0) {
1.1 raeburn 1171: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1172: \%cat_titles,\%cat_order);
1.2 raeburn 1173: if ($codepicker) {
1174: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
1175: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1176: } else {
1.20 raeburn 1177: $next = $states->{$action}[$page+2];
1.15 raeburn 1178: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1179: }
1180: } else {
1.20 raeburn 1181: if ($crstype eq 'official') {
1182: $next = $states->{$action}[$page+2];
1183: }
1.15 raeburn 1184: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 1185: }
1.2 raeburn 1186: } elsif ($prev eq 'codepick') {
1.27 raeburn 1187: if ($instcode eq '') {
1.20 raeburn 1188: $prev = $states->{$action}[$page-2];
1189: }
1.15 raeburn 1190: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1191: } elsif ($state eq 'enrollment') {
1.4 raeburn 1192: if ($crstype eq 'official') {
1193: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1194: \%cat_order,\@code_order);
1195: }
1.2 raeburn 1196: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1.27 raeburn 1197: \%cat_titles,\%cat_order,\@code_order,
1198: $invalidcrosslist));
1.2 raeburn 1199: } elsif ($state eq 'personnel') {
1.27 raeburn 1200: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1.4 raeburn 1201: } elsif ($state eq 'review') {
1.30 raeburn 1202: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1203: my $now = time;
1204: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1205: my $personname = $env{'form.person_'.$i.'_uname'};
1206: my $persondom = $env{'form.person_'.$i.'_dom'};
1207: if (($personname =~ /^$match_username$/) &&
1208: ($persondom =~ /^$match_domain$/)) {
1209: if (&Apache::lonnet::domain($persondom)) {
1210: my $personhome =
1211: &Apache::lonnet::homeserver($personname,$persondom);
1212: if ($personhome eq 'no_host') {
1213: if ($persondom ne $dom) {
1214: my $skipuser = 1;
1215: if ($env{'user.role.dc./'.$persondom.'/'}) {
1216: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1217: if (((!$start) || ($start < $now)) &&
1218: ((!$end) || ($end > $now))) {
1219: $skipuser = 0;
1220: }
1221: }
1222: if ($skipuser) {
1223: push(@disallowed,$i);
1224: $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1225: next;
1226: }
1227: }
1228: if (&get_cancreate_status($persondom,$personname,$dom)) {
1229: my ($allowed,$msg) =
1230: &check_newuser_rules($persondom,$personname,
1231: \%alerts,\%rulematch,\%inst_results,
1232: \%curr_rules,\%got_rules);
1233: if ($allowed) {
1234: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1235: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1236: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1237: }
1238: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1239: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1240: }
1241: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1242: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1243: }
1244: }
1245: } else {
1246: push(@disallowed,$i);
1247: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1248: }
1249: } else {
1250: push(@disallowed,$i);
1251: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1252: }
1253: } else {
1254: my %userenv =
1255: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1256: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1257: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1258: }
1259: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1260: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1261: }
1262: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1263: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1264: }
1265: }
1266: } elsif ($personname ne '') {
1267: push(@disallowed,$i);
1268: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1269: }
1270: } elsif ($personname ne '') {
1271: push(@disallowed,$i);
1272: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1273: }
1274: }
1.16 raeburn 1275: my $cnum;
1276: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1277: $cnum = $env{'form.origcnum'};
1278: } else {
1279: $cnum = &Apache::lonnet::generate_coursenum($dom);
1280: }
1.4 raeburn 1281: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1282: \%cat_order,\@code_order);
1.27 raeburn 1283: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>'.
1.30 raeburn 1284: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1.16 raeburn 1285: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.4 raeburn 1286: $navtxt{'next'} = &mt('Submit course request');
1.10 raeburn 1287: } elsif ($state eq 'process') {
1288: if ($crstype eq 'official') {
1289: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1290: \%cat_order,\@code_order);
1291: }
1.27 raeburn 1292: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1293: \@code_order);
1.13 raeburn 1294: $r->print($result);
1.27 raeburn 1295: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1296: $r->print('<p>');
1297: if ($storeresult eq 'ok') {
1298: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1299: &mt('Modify this request').'</a>'.(' 'x4));
1300: }
1301: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1302: return;
1303: }
1.1 raeburn 1304: }
1.16 raeburn 1305: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24 raeburn 1306: if ($state eq 'personnel') {
1307: push(@excluded,'persontotal');
1308: }
1.30 raeburn 1309: if ($state eq 'review') {
1310: if (@disallowed > 0) {
1311: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1312: my @currsecs = ¤t_lc_sections();
1313: if (@currsecs) {
1314: push(@items,'sec');
1315: }
1316: my $count = 0;
1317: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1318: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1319: if (grep(/^$i$/,@disallowed)) {
1320: foreach my $item (@items) {
1321: $env{'form.person_'.$i.'_'.$item} = '';
1322: }
1323: } else {
1324: foreach my $item (@items) {
1325: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1326: }
1327: }
1328: }
1329: $count ++;
1330: }
1331: $env{'form.persontotal'} = $count;
1332:
1333: }
1334: }
1.27 raeburn 1335: if ($state eq 'enrollment') {
1336: push(@excluded,'crosslisttotal');
1337: }
1.16 raeburn 1338: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1.31 ! raeburn 1339: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
! 1340: $navtxt{'next'},$state);
1.16 raeburn 1341: return;
1342: }
1343:
1.30 raeburn 1344: sub get_cancreate_status {
1345: my ($persondom,$personname,$dom) = @_;
1346: my ($rules,$ruleorder) =
1347: &Apache::lonnet::inst_userrules($persondom,'username');
1348: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1349: $rules);
1350: return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
1351: }
1352:
1353: sub check_newuser_rules {
1354: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1355: $got_rules) = @_;
1356: my $allowed = 1;
1357: my $newuser = 1;
1358: my ($checkhash,$userchkmsg);
1359: my $checks = { 'username' => 1 };
1360: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1361: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1362: $inst_results,$curr_rules,$got_rules);
1363: if (ref($alerts->{'username'}) eq 'HASH') {
1364: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1365: my $domdesc =
1366: &Apache::lonnet::domain($persondom,'description');
1367: if ($alerts->{'username'}{$persondom}{$personname}) {
1368: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1369: $userchkmsg =
1370: &Apache::loncommon::instrule_disallow_msg('username',
1371: $domdesc,1).
1372: &Apache::loncommon::user_rule_formats($persondom,
1373: $domdesc,$curr_rules->{$persondom}{'username'},
1374: 'username');
1375: }
1376: $allowed = 0;
1377: }
1378: }
1379: }
1380: return ($allowed,$userchkmsg);
1381: }
1382:
1.16 raeburn 1383: sub get_excluded_elements {
1384: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 1385: my @excluded = ('counter');
1386: my %elements = &form_elements($dom);
1387: if (ref($states) eq 'HASH') {
1388: if (ref($states->{$action}) eq 'ARRAY') {
1389: my @items = @{$states->{$action}};
1390: my $numitems = scalar(@items);
1391: if ($numitems) {
1392: for (my $i=$numitems-1; $i>=0; $i--) {
1393: if (ref($elements{$action}) eq 'HASH') {
1394: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 1395: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 1396: push(@excluded,$key);
1397: }
1398: }
1399: }
1400: last if ($items[$i] eq $state);
1401: }
1402: }
1403: }
1404: }
1405: if (grep(/^instcode_/,@excluded)) {
1406: push(@excluded,'instcode');
1.1 raeburn 1407: }
1.16 raeburn 1408: return @excluded;
1.1 raeburn 1409: }
1410:
1.2 raeburn 1411: sub print_enrollment_menu {
1.27 raeburn 1412: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1413: $invalidcrosslist) =@_;
1414: my ($sections,$autoenroll,$access_dates,$output);
1.2 raeburn 1415: my $starttime = time;
1416: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1417:
1418: my %accesstitles = (
1419: 'start' => 'Default start access',
1.16 raeburn 1420: 'end' => 'Default end access',
1.2 raeburn 1421: );
1422: my %enrolltitles = (
1423: 'start' => 'Start auto-enrollment',
1424: 'end' => 'End auto-enrollment',
1425: );
1426: if ($env{'form.crstype'} eq 'official') {
1427: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1428: $output = &show_invalid_crosslists($invalidcrosslist);
1429: my ($section_form,$crosslist_form);
1.2 raeburn 1430: $section_form = &inst_section_selector($dom,$instcode);
1.27 raeburn 1431: if ($section_form) {
1432: $sections = &Apache::lonhtmlcommon::row_headline().
1433: '<h3>'.&mt('Sections for auto-enrollment').'</h3>'.
1434: &Apache::lonhtmlcommon::row_closure(1).
1435: $section_form;
1436: }
1.2 raeburn 1437: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1438: if (!$crosslisttotal) {
1.2 raeburn 1439: $crosslisttotal = 1;
1440: }
1441: if ($env{'form.addcrosslist'}) {
1442: $crosslisttotal ++;
1443: }
1444: for (my $i=0; $i<$crosslisttotal; $i++) {
1445: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1446: $cat_titles,$cat_order,$i);
1447: }
1448: if ($crosslist_form) {
1449: $crosslist_form .=
1450: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1451: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1452: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1453: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27 raeburn 1454: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1455: $sections .= &Apache::lonhtmlcommon::row_headline.
1456: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1457: &Apache::lonhtmlcommon::row_closure(1).
1458: $crosslist_form;
1.2 raeburn 1459: }
1.27 raeburn 1460: $autoenroll =
1.2 raeburn 1461: &Apache::lonhtmlcommon::row_title(&mt('Add registered students automatically')).
1462: '<span class="LC_nobreak"><label>'.
1463: '<input type="radio" name="autoadds" value="1">'.
1464: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1465: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1466: &mt('No').'</label></span>'.
1.27 raeburn 1467: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 1468: &Apache::lonhtmlcommon::row_title(&mt('Drop unregistered students automatically')).
1469: '<span class="LC_nobreak"><label>'.
1470: '<input type="radio" name="autodrops" value="1">'.
1471: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1472: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1473: &mt('No').'</label></span>'.
1.27 raeburn 1474: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 1475: &date_setting_table($starttime,$endtime,$formname,'enroll',%enrolltitles);
1476: }
1477: }
1.27 raeburn 1478: my $access_dates =
1.2 raeburn 1479: &date_setting_table($starttime,$endtime,$formname,'access',%accesstitles);
1.27 raeburn 1480: $output .= &Apache::lonhtmlcommon::start_pick_box();
1481: if ($sections) {
1482: $output .= $sections;
1483: }
1484: if ($autoenroll) {
1485: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1486: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1487: &Apache::lonhtmlcommon::row_closure(1).
1488: $autoenroll;
1489: }
1490: if ($access_dates) {
1491: my $header = &mt('Access dates for students');
1492: if ($env{'form.crstype'} eq 'community') {
1493: $header = &mt('Access dates for community members');
1494: }
1495: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1496: '<h3>'.$header.'</h3>'.
1497: &Apache::lonhtmlcommon::row_closure(1).
1498: $access_dates
1.2 raeburn 1499: }
1.27 raeburn 1500: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1501: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2 raeburn 1502: }
1503:
1.27 raeburn 1504: sub show_invalid_crosslists {
1505: my ($invalidcrosslist) = @_;
1506: my $output;
1507: if (ref($invalidcrosslist) eq 'ARRAY') {
1508: if (@{$invalidcrosslist} > 0) {
1509: $output = '<div class="LC_warning">'.
1510: &mt('The following crosslisted courses were invalid:').'<ul>';
1511: foreach my $item (@{$invalidcrosslist}) {
1512: $output .= '<li>'.$item.'</li>';
1513: }
1514: $output .= '</ul></div><br />';
1515: }
1516: }
1517: return $output;
1518: }
1519:
1520:
1.1 raeburn 1521: sub inst_section_selector {
1.2 raeburn 1522: my ($dom,$instcode) = @_;
1523: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1524: my $sectotal = scalar(@sections);
1.1 raeburn 1525: my $output;
1.2 raeburn 1526: if ($sectotal) {
1.27 raeburn 1527: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1528: &Apache::loncommon::start_data_table().
1529: &Apache::loncommon::start_data_table_row().
1530: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1531: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1532: '<th>'.&mt('Institutional Section').'</th>'.
1533: '<th>'.&mt('LON-CAPA section').'</th>'.
1534: &Apache::loncommon::end_data_table_row();
1535: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1536: my $colflag = $i%2;
1.31 ! raeburn 1537: my $secon = ' checked="checked"';
! 1538: my $secoff = '';
1.24 raeburn 1539: if ($env{'form.origcnum'}) {
1.31 ! raeburn 1540: $secoff = $secon;
! 1541: $secon='';
1.24 raeburn 1542: }
1.1 raeburn 1543: $output .= &Apache::loncommon::start_data_table_row().
1.31 ! raeburn 1544: '<td><label><input type="radio" name="sec_'.$i.
! 1545: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
! 1546: (' 'x2).'<label><input type="radio" name="sec_'.$i.
! 1547: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
! 1548: '<td align="center">'.$sections[$i].
1.1 raeburn 1549: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1550: $sections[$i].'" /></td>'.
1.1 raeburn 1551: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1552: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1553: &Apache::loncommon::end_data_table_row();
1554: }
1.2 raeburn 1555: $output .= &Apache::loncommon::end_data_table().
1556: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1557: }
1558: return $output;
1559: }
1560:
1.2 raeburn 1561: sub date_setting_table {
1.14 raeburn 1562: my ($starttime,$endtime,$formname,$prefix,%datetitles) = @_;
1.2 raeburn 1563: my ($perpetual,$table);
1.14 raeburn 1564: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 1565: $starttime,'','','',1,'','','',1);
1.14 raeburn 1566: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 1567: $endtime,'','','',1,'','','',1);
1.27 raeburn 1568: my $closure = '';
1.14 raeburn 1569: if ($prefix eq 'access') {
1.2 raeburn 1570: $perpetual = ' <span class="LC_nobreak"><label>'.
1571: '<input type="checkbox" name="no_end_date" />'.
1572: &mt('No end date').'</label></span>';
1.27 raeburn 1573: $closure = '1';
1.2 raeburn 1574: }
1575: $table = &Apache::lonhtmlcommon::row_title($datetitles{'start'}).
1576: $startform.
1.27 raeburn 1577: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 1578: &Apache::lonhtmlcommon::row_title($datetitles{'end'}).
1579: $endform.$perpetual.
1.27 raeburn 1580: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 1581: return $table;
1582: }
1583:
1584: sub print_personnel_menu {
1.27 raeburn 1585: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1586: my $output;
1587: if ($crstype eq 'official') {
1588: if (&Apache::lonnet::auto_run('',$dom)) {
1589: $output .= &show_invalid_crosslists($invalidcrosslist);
1590: }
1591: }
1592: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 1593: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1594: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1595: $persontotal = 1;
1596: }
1597: if ($env{'form.addperson'}) {
1598: $persontotal ++;
1599: }
1.13 raeburn 1600: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1601:
1602: my $roleoptions;
1603: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 1604: my $type = 'Course';
1605: if ($crstype eq 'community') {
1606: $type = 'Community';
1607: }
1.2 raeburn 1608: foreach my $role (@roles) {
1.28 raeburn 1609: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1610: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1611: }
1612: my %customroles=&Apache::lonuserutils::my_custom_roles();
1613: if (keys(%customroles) > 0) {
1614: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 1615: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 1616: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1617: }
1618: }
1619:
1.30 raeburn 1620: my @currsecs = ¤t_lc_sections();
1.2 raeburn 1621:
1622: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1623: if (@currsecs) {
1624: my $existsize = scalar(@currsecs);
1625: if ($existsize > 3) {
1626: $existsize = 3;
1627: }
1628: if ($existsize > 1) {
1629: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1630: }
1631: @currsecs = sort { $a <=> $b } (@currsecs);
1632: $existtitle = &mt('Official').': ';
1633: $existops = '<option value="">'.&mt('None').'</option>';
1634: foreach my $sec (@currsecs) {
1635: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1636: }
1637: $seccolspan = ' colspan="2"';
1638: $newtitle = &mt('Other').': ';
1639: }
1640:
1.27 raeburn 1641: if ($persontotal) {
1642: $output .= &Apache::lonhtmlcommon::row_headline().
1643: '<h3>'.&mt('Requestor is automatically assigned Course Coordinator role.').' '.&mt('Include other personnel?').'</h3>';
1644: }
1.2 raeburn 1645: for (my $i=0; $i<$persontotal; $i++) {
1646: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1647: my $linkargstr = join("','",@linkargs);
1.29 raeburn 1648: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 1649: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 1650: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 1651: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1652: 1,$onchange).
1.29 raeburn 1653: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 1654: my %form_elems;
1655: foreach my $item (@items) {
1656: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1657: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1658: 'value="" readonly="readonly" />';
1659: }
1660: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1661: $roleoptions.'</select>';
1662: my $sectionselector;
1663: if (@currsecs) {
1664: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1665: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1666: }
1667: $sectionselector .= $newtitle.
1.14 raeburn 1668: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29 raeburn 1669: my $usersrchlinktxt = &mt('Search for user');
1670: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1671: $usersrchlinktxt);
1672: my $userchklinktxt = &mt('Check username');
1673: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1674: $userchklinktxt,'checkusername');
1.2 raeburn 1675: $output .=
1.29 raeburn 1676: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1677: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1678: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1679: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1680: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1681: '</tr>'."\n".'<tr>'.
1.13 raeburn 1682: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1683: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1684: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.2 raeburn 1685: '<tr><td align="center" valign="top">'.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1686: '<td'.$seccolspan.' align="center" valign="top">'.&mt('Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1687: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1688: }
1689: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1690: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1691: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1692: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1693: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1694: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1695: return $output;
1696: }
1697:
1.30 raeburn 1698: sub current_lc_sections {
1699: my @currsecs;
1700: if ($env{'form.sectotal'}) {
1701: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 ! raeburn 1702: if ($env{'form.sec_'.$i}) {
! 1703: if (defined($env{'form.loncapasec_'.$i})) {
! 1704: my $lcsec = $env{'form.loncapasec_'.$i};
! 1705: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
! 1706: push(@currsecs,$lcsec);
! 1707: }
1.30 raeburn 1708: }
1709: }
1710: }
1711: }
1712: return @currsecs;
1713: }
1714:
1.1 raeburn 1715: sub print_request_status {
1.11 raeburn 1716: my ($dom) = @_;
1.14 raeburn 1717: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1718: $env{'user.name'},'^status:'.$dom);
1719: my ($output,$formname,%queue_by_date,%typenames);
1720: if ($env{'form.crstype'} eq 'any') {
1721: %typenames = &Apache::lonlocal::texthash (
1722: official => 'Official course',
1723: unofficial => 'Unofficial course',
1724: community => 'Community',
1725: );
1726: }
1727: foreach my $key (keys(%statusinfo)) {
1728: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1729: (undef,my($cdom,$cnum)) = split(':',$key);
1730: next if ($cdom ne $dom);
1731: my $requestkey = $cdom.'_'.$cnum;
1732: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1733: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1734: $env{'user.domain'},$env{'user.name'});
1735: my $entry;
1736: my $timestamp = $history{'reqtime'};
1737: my $crstype = $history{'crstype'};
1738: my $disposition = $history{'disposition'};
1739: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1740: next unless (($env{'form.crstype'} eq 'any') ||
1741: ($env{'form.crstype'} eq $crstype));
1742: next unless (($disposition eq 'approval') ||
1743: ($disposition eq 'pending'));
1744: if (ref($history{'details'}) eq 'HASH') {
1745: $entry = $requestkey.':'.$crstype.':'.
1746: &escape($history{'details'}{'cdescr'});
1747: if ($crstype eq 'official') {
1748: $entry .= ':'.&escape($history{'details'}{'instcode'});
1749: }
1750: }
1751: if ($entry ne '') {
1752: if (exists($queue_by_date{$timestamp})) {
1753: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1754: push(@{$queue_by_date{$timestamp}},$entry);
1755: }
1756: } else {
1757: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 1758: }
1759: }
1760: }
1761: }
1762: }
1.11 raeburn 1763: $formname = 'requestcrs';
1.10 raeburn 1764: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.16 raeburn 1765: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1766:
1.10 raeburn 1767: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 1768: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1769: '<input type="hidden" name="showdom" value="" />'."\n".
1770: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 1771: if (@sortedtimes > 0) {
1772: $output .= &Apache::loncommon::start_data_table().
1773: &Apache::loncommon::start_data_table_header_row().
1774: '<th>'.&mt('Action').'</th>'.
1.14 raeburn 1775: '<th>'.&mt('Course Description').'</th>'.
1776: '<th>'.&mt('Domain').'</th>';
1777: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 1778: $output .= '<th>'.&mt('Type').'</th>';
1779: }
1.14 raeburn 1780: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 1781: $output .= '<th>'.&mt('Institutional Code').'</th>';
1782: }
1783: $output .= '<th>'.&mt('Date requested').'</th>'.
1784: &Apache::loncommon::end_data_table_header_row();
1785: my $count = 0;
1786: foreach my $item (@sortedtimes) {
1787: my $showtime = &Apache::lonlocal::locallocaltime($item);
1788: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1789: foreach my $request (sort(@{$queue_by_date{$item}})) {
1790: my ($key,$type,$desc,$instcode) = split(':',$request);
1791: my ($cdom,$cnum) = split('_',$key);
1792: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 1793: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 1794: '<td>'.&unescape($desc).'</td>'.
1795: '<td>'.$cdom.'</td>';
1796: if ($env{'form.crstype'} eq 'any') {
1797: my $typename = $typenames{$type};
1798: if ($typename eq '') {
1799: $typename = &mt('Unknown type');
1800: }
1801: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 1802: }
1.14 raeburn 1803: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 1804: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 1805: my $showinstcode;
1806: if ($type eq 'official') {
1807: $showinstcode = &unescape($instcode);
1808: } else {
1809: $showinstcode = &mt('Not applicable');
1810: }
1811: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 1812: }
1813: $output .= '<td>'.$showtime.'</td>'.
1814: &Apache::loncommon::end_data_table_row();
1815: }
1816: }
1817: }
1818: $output .= &Apache::loncommon::end_data_table();
1819: } else {
1.11 raeburn 1820: $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>';
1.10 raeburn 1821: }
1822: $output .= '
1.30 raeburn 1823: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 1824: return $output;
1.1 raeburn 1825: }
1826:
1.16 raeburn 1827: sub print_cancel_request {
1828: my ($dom,$cnum) = @_;
1829: my $requestkey = $dom.'_'.$cnum;
1830: my ($result,$output);
1831: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1832: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1833: $env{'user.domain'},$env{'user.name'});
1834: my $timestamp = $history{'reqtime'};
1835: my $crstype = $history{'crstype'};
1836: my $status = $history{'status'};
1837: if (($status eq 'cancelled') || ($status eq 'created')) {
1838: if ($status eq 'cancelled') {
1839: $output = &mt('This request has already been cancelled.');
1840: } elsif ($status eq 'created') {
1841: $output = &mt('This request has already been processed, and a course created.');
1842: }
1843: $output = &mt('No further action will be taken');
1844: } elsif (ref($history{'details'}) eq 'HASH') {
1845: my ($types,$typename) = &course_types();
1846: my $showtype = $crstype;
1847: if (defined($typename->{$crstype})) {
1848: $showtype = $typename->{$crstype};
1849: }
1850: $output = '<p>'.&Apache::loncommon::start_data_table().
1851: &Apache::loncommon::start_data_table_header_row().
1852: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
1853: '<th>'.&mt('Type').'</th>'.
1854: &Apache::loncommon::end_data_table_header_row().
1855: &Apache::loncommon::start_data_table_row().
1856: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
1857: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
1858: '<td>'.$showtype.'</td>'.
1859: &Apache::loncommon::end_data_table_row().
1860: &Apache::loncommon::end_data_table().
1861: '<br /><div class="LC_warning">'.
1862: &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
1863: $result = 'ok';
1864: } else {
1865: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
1866: }
1867: } else {
1868: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
1869: }
1870: return ($result,$output);
1871: }
1872:
1873: sub viewrequest_javascript {
1874: my ($formname,$next) = @_;
1875: return <<"ENDJS";
1876:
1877: function chooseRequest(cdom,cnum) {
1878: document.$formname.showdom.value = cdom;
1879: document.$formname.cnum.value = cnum;
1880: nextPage(document.$formname,'$next');
1881: }
1882:
1883: ENDJS
1884: }
1885:
1886: sub viewdetails_javascript {
1887: my ($formname) = @_;
1888: return << "ENDJS";
1889:
1890: function nextPage(formname,nextstate) {
1891: if (nextstate == "modify") {
1892: formname.state.value = "personnel";
1893: formname.action.value = "new";
1894: } else {
1895: formname.state.value = nextstate;
1896: }
1897: formname.submit();
1898: }
1899:
1900: function backPage(formname,prevstate) {
1901: formname.state.value = prevstate;
1902: formname.submit();
1903: }
1904:
1905: ENDJS
1906: }
1907:
1908: sub viewcancel_javascript {
1909: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
1910: 'Your request will be removed.');
1911: return << "ENDJS";
1912: function nextPage(formname,nextstate) {
1913: if (confirm('$alert')) {
1914: formname.state.value = nextstate;
1915: formname.submit();
1916: }
1917: return;
1918: }
1919:
1920: ENDJS
1921: }
1922:
1.1 raeburn 1923: sub print_request_logs {
1.10 raeburn 1924: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 1925: return;
1926: }
1927:
1928: sub print_review {
1.30 raeburn 1929: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
1930: $disallowed,$disallowmsg) = @_;
1.4 raeburn 1931: my ($types,$typename) = &course_types();
1932: my ($owner,$ownername,$owneremail);
1.26 raeburn 1933: if ($uname eq '' || $udom eq '') {
1934: $uname = $env{'user.name'};
1935: $udom = $env{'user.domain'};
1936: }
1937: $owner = $uname.':'.$udom;
1938: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
1939: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 1940: foreach my $email ('permanentemail','critnotification','notification') {
1941: $owneremail = $emails{$email};
1942: last if ($owneremail ne '');
1943: }
1944: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1945: $section_headers,$section_values,$personnel_headers,$personnel_values);
1946:
1947: $crstypename = $env{'form.crstype'};
1948: if (ref($typename) eq 'HASH') {
1949: unless ($typename->{$env{'form.crstype'}} eq '') {
1950: $crstypename = $typename->{$env{'form.crstype'}};
1951: }
1952: }
1.16 raeburn 1953: my $category = 'Course';
1954: if ($env{'form.crstype'} eq 'community') {
1955: $category = 'Community';
1956: }
1.4 raeburn 1957:
1958: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1959: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1960:
1.16 raeburn 1961: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
1962: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 1963: if ($env{'form.crstype'} eq 'official') {
1964: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1965: foreach my $title (@{$codetitles}) {
1966: if ($env{'form.instcode_'.$title} ne '') {
1967: $inst_headers .= '<th>'.$title.'</th>';
1968: my $longitem = $env{'form.instcode_'.$title};
1969: if (ref($cat_titles->{$title}) eq 'HASH') {
1970: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
1971: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
1972: }
1973: }
1974: $inst_values .= '<td>'.$longitem.'</td>';
1975: }
1976: }
1977: }
1978: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 1979: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 1980: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
1981: '<th>'.&mt('Automatic Drops').'</th>'.
1982: '<th>'.&mt('Enrollment Starts').'</th>'.
1983: '<th>'.&mt('Enrollment Ends').'</th>';
1984: $section_headers = '<th>'.&mt('Sections').'</th>'.
1985: '<th>'.&mt('Crosslistings').'</th>';
1986:
1.13 raeburn 1987: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 1988: my @autoroster = (&mt('No'),&mt('Yes'));
1989: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
1990: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 1991: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
1992: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 1993: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
1994: &mt('Institutional section').'</th>'.
1995: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 1996: my $secinfo;
1.4 raeburn 1997: if ($env{'form.sectotal'} > 0) {
1998: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1999: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2000: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2001: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2002: $secinfo .= $env{'form.loncapasec_'.$i};
2003: } else {
2004: $secinfo .= &mt('None');
1.4 raeburn 2005: }
1.5 raeburn 2006: $secinfo .= '</td></tr>';
1.4 raeburn 2007: }
2008: }
2009: }
1.6 raeburn 2010: if ($secinfo eq '') {
2011: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2012: }
1.6 raeburn 2013: $section_values .= $secinfo.'</table></td><td>'.
2014: '<table class="LC_innerpickbox"><tr><th>'.
2015: &mt('Institutional course/section').'</th>'.
2016: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2017: my $xlistinfo;
1.24 raeburn 2018: my $crosslisttotal = $env{'form.crosslisttotal'};
2019: if (!$crosslisttotal) {
2020: $crosslisttotal = 1;
2021: }
2022: for (my $i=0; $i<$crosslisttotal; $i++) {
2023: if ($env{'form.crosslist_'.$i}) {
2024: $xlistinfo .= '<tr><td>';
2025: if (ref($code_order) eq 'ARRAY') {
2026: if (@{$code_order} > 0) {
2027: foreach my $item (@{$code_order}) {
2028: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2029: }
2030: }
2031: }
1.24 raeburn 2032: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2033: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2034: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2035: } else {
2036: $xlistinfo .= &mt('None');
2037: }
2038: $xlistinfo .= '</td></tr>';
1.4 raeburn 2039: }
2040: }
1.6 raeburn 2041: if ($xlistinfo eq '') {
2042: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2043: }
1.24 raeburn 2044: $section_values .= $xlistinfo;
1.4 raeburn 2045: }
1.24 raeburn 2046: $section_values .= '</table></td>';
1.4 raeburn 2047: }
2048:
2049: my %ctxt = &clone_text();
2050: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.13 raeburn 2051: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
2052: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.15 raeburn 2053: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2054: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
2055: if ($canclone) {
2056: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2057: $env{'form.clonecrs'},('description','internal.coursecode'));
2058: if (keys(%courseenv) > 0) {
2059: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2060: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2061: my $cloneinst = $courseenv{'internal.coursecode'};
2062: if ($cloneinst ne '') {
1.18 raeburn 2063: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 2064: } else {
1.18 raeburn 2065: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 2066: }
2067: $inst_values .= '</td><td>';
2068: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 2069: $inst_values .= $ctxt{'prd'};
1.15 raeburn 2070: } elsif ($env{'form.datemode'} eq 'shift') {
2071: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2072: } else {
2073: $inst_values .= $ctxt{'ncd'};
2074: }
2075: $inst_values .= '</td>';
2076: } else {
2077: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2078: }
2079: } else {
2080: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2081: }
1.4 raeburn 2082: } else {
2083: $inst_values .= '<td>'.&mt('None').'</td>';
2084: }
2085: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2086: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 2087: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2088: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2089: if ($accessend == 0) {
1.4 raeburn 2090: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2091: } else {
1.13 raeburn 2092: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 2093: }
2094:
2095: my $container = 'Course';
2096: if ($env{'form.crstype'} eq 'community') {
2097: $container = 'Community';
2098: }
2099:
2100: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2101: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2102: '</th>';
2103: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
2104: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
2105: '<td>'.&mt('None').'</td></tr>';
2106: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2107: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2108: if (ref($disallowed) eq 'ARRAY') {
2109: next if (grep(/^$i$/,@{$disallowed}));
2110: }
1.31 ! raeburn 2111: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
! 2112: my @allsecs;
! 2113: foreach my $sec (@officialsecs) {
! 2114: next unless ($sec =~ /\w/);
! 2115: next if ($sec =~ /\W/);
! 2116: next if ($sec eq 'none');
! 2117: push(@allsecs,$sec);
! 2118: }
1.14 raeburn 2119: my $newsec = $env{'form.person_'.$i.'_newsec'};
2120: $newsec =~ s/^\s+//;
2121: $newsec =~s/\s+$//;
1.31 ! raeburn 2122: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2123: foreach my $sec (@newsecs) {
1.31 ! raeburn 2124: next unless ($sec =~ /\w/);
1.14 raeburn 2125: next if ($sec =~ /\W/);
1.31 ! raeburn 2126: next if ($sec eq 'none');
1.14 raeburn 2127: if ($sec ne '') {
2128: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2129: push(@allsecs,$sec);
2130: }
2131: }
2132: }
1.24 raeburn 2133: my $showsec;
1.14 raeburn 2134: if (@allsecs) {
2135: $showsec = join(', ',@allsecs);
2136: }
1.24 raeburn 2137: if ($showsec eq '') {
2138: $showsec = &mt('None');
2139: }
2140: if ($env{'form.person_'.$i.'_role'} eq 'cc') {
2141: $showsec = &mt('None');
2142: }
1.28 raeburn 2143: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2144: $personnel_values .=
1.13 raeburn 2145: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2146: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2147: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2148: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2149: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2150: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2151: }
2152: }
1.30 raeburn 2153: my $output;
2154: if (ref($disallowed) eq 'ARRAY') {
2155: if (@{$disallowed} > 0) {
2156: if (ref($disallowmsg) eq 'HASH') {
2157: $output = '<p class="LC_warning">'.
2158: &mt('Not all requested personnel could be included.').'<ul>';
2159: foreach my $item (@{$disallowed}) {
2160: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2161: }
2162: $output .= '</ul></p>';
2163: }
2164: }
2165: }
2166: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 2167: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 2168: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 2169: '<th>'.&mt('Name').'</th>'.
2170: '<th>'.&mt('Username:Domain').'</th>'.
2171: '<th>'.&mt('E-mail address').'</th>'.
2172: '</tr><tr>'."\n".
2173: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2174: '<td>'.$owneremail.'</td>'.
2175: '</tr></table>'."\n".
2176: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 2177: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 2178: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2179: '<tr>'.$inst_values.'</tr></table>'."\n".
2180: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2181: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 2182: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2183: '<tr>'.$enroll_values.'</tr></table>'."\n".
2184: &Apache::lonhtmlcommon::row_closure();
2185: if ($section_headers ne '') {
2186: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2187: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2188: '<tr>'.$section_values.'</tr></table>'."\n".
2189: &Apache::lonhtmlcommon::row_closure();
2190: }
2191: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2192: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2193: $personnel_values.'</table>'."\n".
2194: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 2195: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 2196: return $output;
2197: }
2198:
2199: sub dates_from_form {
2200: my ($startname,$endname) = @_;
2201: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2202: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 2203: if ($endname eq 'accessend') {
1.4 raeburn 2204: if (exists($env{'form.no_end_date'}) ) {
2205: $enddate = 0;
2206: }
2207: }
2208: return ($startdate,$enddate);
1.1 raeburn 2209: }
2210:
2211: sub courseinfo_form {
1.15 raeburn 2212: my ($dom,$formname,$crstype,$next) = @_;
2213: my $nodescr = &mt('You must provide a (brief) course description.');
2214: my $js_validate = <<"ENDJS";
2215: <script type="text/javascript">
2216: // <![CDATA['
2217:
2218: function validateForm() {
2219: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
2220: alert('$nodescr');
2221: return;
2222: }
2223: nextPage(document.$formname,'$next');
2224: }
2225: // ]]
2226: </script>
2227:
2228: ENDJS
1.27 raeburn 2229: my $title = &mt('Brief Course Description');
2230: if ($crstype eq 'community') {
2231: $title = &mt('Brief Community Description');
2232: }
1.15 raeburn 2233: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2234: &Apache::lonhtmlcommon::row_headline().
2235: '<h3>'.$title.'</h3>'.
2236: &Apache::lonhtmlcommon::row_closure(1).
2237: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.13 raeburn 2238: '<input type="text" size="40" name="cdescr" />';
2239: my ($home_server_pick,$numlib) =
2240: &Apache::loncommon::home_server_form_item($dom,'chome',
2241: 'default','hide');
2242: if ($numlib > 1) {
2243: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2244: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 2245: }
2246: $output .= $home_server_pick.
1.27 raeburn 2247: &Apache::lonhtmlcommon::row_closure().
2248: &Apache::lonhtmlcommon::row_headline().
2249: '<h3>'.&mt('Clone content and settings from an existing course?').'</h3>'.
1.13 raeburn 2250: &Apache::lonhtmlcommon::row_closure(1).
1.27 raeburn 2251: &clone_form($dom,$formname,$crstype).
2252: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1.1 raeburn 2253: return $output;
2254: }
2255:
2256: sub clone_form {
2257: my ($dom,$formname,$crstype) = @_;
2258: my $type = 'Course';
2259: if ($crstype eq 'community') {
2260: $type = 'Community';
2261: }
1.13 raeburn 2262: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
2263: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 2264: my %lt = &clone_text();
1.2 raeburn 2265: my $output .=
2266: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.29 raeburn 2267: '<input type="text" size="25" name="clonecrs" value="" />'.
1.2 raeburn 2268: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
2269: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1.27 raeburn 2270: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2271: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2272: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2273: '</label><br /><label>'.
2274: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2275: '</label><br /><label>'.
2276: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2277: $lt{'shd'}.'</label>'.
2278: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 2279: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2280: return $output;
2281: }
2282:
1.16 raeburn 2283: sub clone_text {
1.4 raeburn 2284: return &Apache::lonlocal::texthash(
2285: 'cid' => 'Course ID',
2286: 'dmn' => 'Domain',
2287: 'dsh' => 'Date Shift',
2288: 'ncd' => 'Do not clone date parameters',
2289: 'prd' => 'Clone date parameters as-is',
2290: 'shd' => 'Shift date parameters by number of days',
2291: );
2292: }
2293:
1.1 raeburn 2294: sub coursecode_form {
1.2 raeburn 2295: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 2296: my $output;
1.2 raeburn 2297: my %rowtitle = (
2298: instcode => 'Course Category',
2299: crosslist => 'Cross Listed Course',
2300: );
1.1 raeburn 2301: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2302: (ref($cat_order))) {
1.2 raeburn 2303: my ($sel,$instsec,$lcsec);
2304: $sel = $context;
2305: if ($context eq 'crosslist') {
2306: $sel .= '_'.$num;
2307: $instsec = &mt('Institutional section').'<br />'.
2308: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2309: $lcsec = &mt('LON-CAPA section').'<br />'.
2310: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2311: }
1.1 raeburn 2312: if (@{$codetitles} > 0) {
2313: my $lastitem = pop(@{$codetitles});
1.2 raeburn 2314: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 2315: if (@{$codetitles} > 0) {
1.2 raeburn 2316: $output = &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2317: '<table><tr>';
1.1 raeburn 2318: if ($context eq 'crosslist') {
1.2 raeburn 2319: $output .= '<td>'.&mt('Include?').'<br />'.
2320: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 2321: }
2322: foreach my $title (@{$codetitles}) {
2323: if (ref($cat_order->{$title}) eq 'ARRAY') {
2324: if (@{$cat_order->{$title}} > 0) {
2325: $output .= '<td align="center">'.$title.'<br />'."\n".
2326: '<select name="'.$sel.'_'.$title.'">'."\n".
2327: ' <option value="" selected="selected">'.
2328: &mt('Select').'</option>'."\n";
2329: foreach my $item (@{$cat_order->{$title}}) {
2330: my $longitem = $item;
2331: if (ref($cat_titles->{$title}) eq 'HASH') {
2332: if ($cat_titles->{$title}{$item} ne '') {
2333: $longitem = $cat_titles->{$title}{$item};
2334: }
2335: }
2336: $output .= '<option value="'.$item.'">'.$longitem.
2337: '</option>'."\n";
2338: }
2339: }
2340: $output .= '</select></td>'."\n";
2341: }
2342: }
2343: if ($context eq 'crosslist') {
2344: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 2345: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2346: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 2347: } else {
2348: $output .= '</tr></table>'.
2349: &Apache::lonhtmlcommon::row_closure().
2350: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2351: $lastinput;
2352: }
2353: } else {
2354: if ($context eq 'crosslist') {
2355: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 2356: '<table><tr>'.
2357: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2358: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2359: '</tr></table>';
1.1 raeburn 2360: } else {
2361: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2362: $lastinput;
2363: }
2364: }
1.2 raeburn 2365: $output .= &Apache::lonhtmlcommon::row_closure(1);
2366: push(@$codetitles,$lastitem);
2367: } elsif ($context eq 'crosslist') {
2368: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2369: '<table><tr><td align="center">'.
2370: '<span class="LC_nobreak">'.&mt('Include?').
2371: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2372: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2373: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2374: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2375: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2376: }
2377: }
2378: return $output;
2379: }
2380:
2381: sub get_course_dom {
2382: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 2383: if ($env{'form.showdom'} ne '') {
2384: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2385: return $env{'form.showdom'};
2386: }
2387: }
1.1 raeburn 2388: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.19 raeburn 2389: my ($types,$typename) = &course_types();
2390: if (ref($types) eq 'ARRAY') {
2391: foreach my $type (@{$types}) {
2392: if (&Apache::lonnet::usertools_access($env{'user.name'},
2393: $env{'user.domain'},$type,
2394: undef,'requestcourses')) {
2395: return $env{'user.domain'};
2396: }
2397: }
2398: my @possible_doms;
2399: foreach my $type (@{$types}) {
2400: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2401: if ($dom_str ne '') {
2402: my @domains = split(',',$dom_str);
2403: foreach my $entry (@domains) {
2404: my ($extdom,$extopt) = split(':',$entry);
2405: if ($extdom eq $env{'request.role.domain'}) {
2406: return $extdom;
2407: }
2408: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2409: push(@possible_doms,$extdom);
2410: }
2411: }
2412: }
2413: }
2414: if (@possible_doms) {
2415: @possible_doms = sort(@possible_doms);
2416: return $possible_doms[0];
2417: }
2418: }
1.1 raeburn 2419: $codedom = $env{'user.domain'};
2420: if ($env{'request.role.domain'} ne '') {
2421: $codedom = $env{'request.role.domain'};
2422: }
2423: }
2424: return $codedom;
2425: }
2426:
2427: sub display_navbuttons {
1.31 ! raeburn 2428: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 2429: $r->print('<div class="LC_navbuttons">');
2430: if ($prev) {
1.16 raeburn 2431: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 ! raeburn 2432: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 2433: (' 'x3));
1.1 raeburn 2434: } elsif ($prevtext) {
1.16 raeburn 2435: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2436: 'onclick="javascript:history.back()"/>'.(' 'x3));
2437: }
2438: if ($state eq 'details') {
2439: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 ! raeburn 2440: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 2441: ')" />');
1.1 raeburn 2442: }
1.31 ! raeburn 2443: my $gotnext;
1.15 raeburn 2444: if ($state eq 'courseinfo') {
1.16 raeburn 2445: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2446: 'onclick="javascript:validateForm();" />');
1.31 ! raeburn 2447: $gotnext = 1;
! 2448: } elsif ($state eq 'enrollment') {
! 2449: if (($env{'form.crstype'} eq 'official') &&
! 2450: (&Apache::lonnet::auto_run('',$dom))) {
! 2451: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
! 2452: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
! 2453: $gotnext = 1;
! 2454: }
! 2455: } elsif ($state eq 'personnel') {
! 2456: if ($env{'form.persontotal'} > 0) {
! 2457: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
! 2458: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
! 2459: $gotnext = 1;
! 2460: }
! 2461: }
! 2462: unless ($gotnext) {
! 2463: if ($next) {
! 2464: $r->print('
! 2465: <input type="button" name="next" value="'.$nexttext.'" '.
! 2466: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
! 2467: }
1.1 raeburn 2468: }
2469: $r->print('</div>');
2470: }
2471:
2472: sub print_request_outcome {
1.10 raeburn 2473: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 2474: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 2475: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 2476: my $sectotal = $env{'form.sectotal'};
2477: my $crosslisttotal = 0;
1.10 raeburn 2478: $cnum = $env{'form.cnum'};
1.8 raeburn 2479: unless ($cnum =~ /^$match_courseid$/) {
2480: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2481: return $output;
2482: }
1.11 raeburn 2483:
1.10 raeburn 2484: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 2485: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2486: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2487: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2488: }
2489: }
1.10 raeburn 2490: $now = time;
2491: $crstype = $env{'form.crstype'};
1.17 raeburn 2492: my @instsections;
1.8 raeburn 2493: if ($crstype eq 'official') {
2494: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 2495: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 2496: }
1.10 raeburn 2497: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2498: if ($env{'form.sec_'.$i}) {
2499: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 2500: my $sec = $env{'form.secnum_'.$i};
2501: $sections{$i}{'inst'} = $sec;
2502: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2503: push(@instsections,$sec);
2504: }
1.13 raeburn 2505: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 2506: }
2507: }
2508: }
2509: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2510: if ($env{'form.crosslist_'.$i}) {
2511: my $xlistinfo = '';
2512: if (ref($code_order) eq 'ARRAY') {
2513: if (@{$code_order} > 0) {
2514: foreach my $item (@{$code_order}) {
2515: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2516: }
2517: }
2518: }
1.22 raeburn 2519: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 2520: if ($xlistinfo ne '') {
2521: $crosslisttotal ++;
2522: }
1.22 raeburn 2523: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 2524: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 2525: }
2526: }
1.14 raeburn 2527: } else {
2528: $enrollstart = '';
2529: $enrollend = '';
1.10 raeburn 2530: }
2531: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2532: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 2533: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 2534: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
2535: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 2536: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
2537: $personnel{$uname.':'.$udom} = {
2538: firstname => $env{'form.person_'.$i.'_firstname'},
2539: lastname => $env{'form.person_'.$i.'_lastname'},
2540: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
2541: };
2542: }
2543: my $role = $env{'form.person_'.$i.'_role'};
2544: unless ($role eq '') {
1.16 raeburn 2545: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 2546: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
2547: unless (grep(/^\Q$role\E$/,@curr_roles)) {
2548: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
2549: }
2550: } else {
2551: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
2552: }
2553: if ($role eq 'cc') {
2554: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
2555: } else {
1.14 raeburn 2556: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 ! raeburn 2557: my @allsecs;
! 2558: foreach my $sec (@currsec) {
! 2559: next unless ($sec =~ /\w/);
! 2560: next if ($sec =~ /\W/);
! 2561: next if ($sec eq 'none');
! 2562: push(@allsecs,$sec);
! 2563: }
1.14 raeburn 2564: my $newsec = $env{'form.person_'.$i.'_newsec'};
2565: $newsec =~ s/^\s+//;
2566: $newsec =~s/\s+$//;
2567: my @newsecs = split(/[\s,;]+/,$newsec);
2568: foreach my $sec (@newsecs) {
2569: next if ($sec =~ /\W/);
1.31 ! raeburn 2570: next if ($sec eq 'none');
1.14 raeburn 2571: if ($sec ne '') {
1.31 ! raeburn 2572: unless (grep(/^\Q$sec\E$/,@allsecs)) {
! 2573: push(@allsecs,$sec);
1.13 raeburn 2574: }
2575: }
2576: }
1.31 ! raeburn 2577: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 2578: }
2579: }
1.10 raeburn 2580: } else {
2581: push(@missingdom,$uname.':'.$udom);
2582: }
2583: } else {
2584: push(@baduname,$uname.':'.$udom);
2585: }
1.8 raeburn 2586: }
1.13 raeburn 2587: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 2588: my $autodrops = 0;
2589: if ($env{'form.autodrops'}) {
2590: $autodrops = $env{'form.autodrops'};
2591: }
2592: my $autoadds = 0;
2593: if ($env{'form.autoadds'}) {
2594: $autodrops = $env{'form.autoadds'};
2595: }
2596: if ($env{'form.autoadds'}) {
2597: $autodrops = $env{'form.autoadds'};
2598: }
2599: my $instcode = '';
2600: if (exists($env{'form.instcode'})) {
2601: $instcode = $env{'form.instcode'};
2602: }
1.15 raeburn 2603: my $clonecrs = '';
2604: my $clonedom = '';
2605: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
2606: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 2607: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2608: $env{'form.clonedom'});
1.15 raeburn 2609: if ($clonehome ne 'no_host') {
1.16 raeburn 2610: my $canclone =
2611: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2612: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1.15 raeburn 2613: if ($canclone) {
2614: $clonecrs = $env{'form.clonecrs'};
2615: $clonedom = $env{'form.clonedom'};
2616: }
2617: }
2618: }
1.8 raeburn 2619: my $details = {
1.10 raeburn 2620: owner => $env{'user.name'},
2621: domain => $env{'user.domain'},
2622: cdom => $dom,
1.11 raeburn 2623: cnum => $cnum,
1.13 raeburn 2624: coursehome => $env{'form.chome'},
2625: cdescr => $env{'form.cdescr'},
1.10 raeburn 2626: crstype => $env{'form.crstype'},
1.14 raeburn 2627: instcode => $instcode,
1.15 raeburn 2628: clonedom => $clonedom,
2629: clonecrs => $clonecrs,
1.10 raeburn 2630: datemode => $env{'form.datemode'},
1.14 raeburn 2631: dateshift => $env{'form.dateshift'},
2632: sectotal => $sectotal,
1.10 raeburn 2633: sections => \%sections,
1.14 raeburn 2634: crosslisttotal => $crosslisttotal,
1.13 raeburn 2635: crosslists => \%crosslistings,
1.14 raeburn 2636: autoadds => $autoadds,
2637: autodrops => $autodrops,
1.13 raeburn 2638: enrollstart => $enrollstart,
2639: enrollend => $enrollend,
2640: accessstart => $accessstart,
2641: accessend => $accessend,
1.10 raeburn 2642: personnel => \%personnel,
1.8 raeburn 2643: };
1.27 raeburn 2644: my (@inststatuses,$storeresult,$creationresult);
1.9 raeburn 2645: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 2646: if ($val eq '') {
2647: if ($crstype eq 'official') {
1.19 raeburn 2648: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 2649: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 2650: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 2651: } elsif ($crstype eq 'community') {
2652: $output = &mt('You are not permitted to request creation of communities');
2653: } else {
2654: $output = &mt('Unrecognized course type: [_1]',$crstype);
2655: }
1.27 raeburn 2656: $storeresult = 'notpermitted';
1.8 raeburn 2657: } else {
1.14 raeburn 2658: my ($disposition,$message,$reqstatus);
1.8 raeburn 2659: my %reqhash = (
1.14 raeburn 2660: reqtime => $now,
1.10 raeburn 2661: crstype => $crstype,
2662: details => $details,
1.8 raeburn 2663: );
2664: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 2665: my $validationerror;
1.10 raeburn 2666: if ($val eq 'autolimit=') {
2667: $disposition = 'process';
2668: } elsif ($val =~ /^autolimit=(\d+)$/) {
2669: my $limit = $1;
1.8 raeburn 2670: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 2671: $dom,$crstype,$limit,\$message);
1.8 raeburn 2672: } elsif ($val eq 'validate') {
1.21 raeburn 2673: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 2674: if (@inststatuses > 0) {
2675: $inststatuslist = join(',',@inststatuses);
2676: }
2677: my $instseclist;
2678: if (@instsections > 0) {
2679: $instseclist = join(',',@instsections);
2680: }
1.21 raeburn 2681: $validationchk =
2682: &Apache::lonnet::auto_courserequest_validation($dom,
2683: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2684: $inststatuslist,$instcode,$instseclist);
2685: if ($validationchk =~ /:/) {
2686: ($validation,$message) = split(':',$validationchk);
2687: } else {
2688: $validation = $validationchk;
2689: }
2690: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 2691: $disposition = 'approval';
2692: $validationerror = $1;
1.23 raeburn 2693: } else {
2694: $disposition = $validation;
1.17 raeburn 2695: }
1.8 raeburn 2696: } else {
2697: $disposition = 'approval';
2698: }
1.14 raeburn 2699: $reqhash{'disposition'} = $disposition;
2700: $reqstatus = $disposition;
1.16 raeburn 2701: my ($modified,$queued);
1.8 raeburn 2702: if ($disposition eq 'rejected') {
2703: $output = &mt('Your course request was rejected.');
2704: if ($message) {
2705: $output .= '<div class="LC_warning">'.$message.'</div>';
2706: }
1.27 raeburn 2707: $storeresult = 'rejected';
1.8 raeburn 2708: } elsif ($disposition eq 'process') {
1.14 raeburn 2709: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2710: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
2711: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 2712: my $type = 'Course';
2713: if ($crstype eq 'community') {
2714: $type = 'Community';
2715: }
2716: foreach my $role (@roles) {
2717: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2718: }
1.14 raeburn 2719: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2720: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2721: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2722: if ($result eq 'created') {
1.8 raeburn 2723: $disposition = 'created';
1.14 raeburn 2724: $reqstatus = 'created';
1.28 raeburn 2725: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
2726: \%longroles);
2727: $output = '<p>'.&mt('Your course request has been processed and the course has been created.').
2728: '<br />'.$role_result.'</p>';
1.27 raeburn 2729: $creationresult = 'created';
1.8 raeburn 2730: } else {
1.14 raeburn 2731: $output = '<span class="LC_error">'.
2732: &mt('An error occurred when processing your course request.').
2733: '<br />'.
2734: &mt('You may want to review the request details and submit the request again.').
2735: '</span>';
1.27 raeburn 2736: $creationresult = 'error';
1.8 raeburn 2737: }
2738: } else {
2739: my $requestid = $cnum.'_'.$disposition;
2740: my $request = {
2741: $requestid => {
2742: timestamp => $now,
2743: crstype => $crstype,
2744: ownername => $env{'user.name'},
2745: ownerdom => $env{'user.domain'},
1.13 raeburn 2746: description => $env{'form.cdescr'},
1.8 raeburn 2747: },
2748: };
1.16 raeburn 2749: my $statuskey = 'status:'.$dom.':'.$cnum;
2750: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2751: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 2752: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 2753: $modified = 1;
1.25 raeburn 2754: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2755: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2756: [$cnum.'_approval',
2757: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 2758: if (($queuehash{$cnum.'_approval'} ne '') ||
2759: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 2760: $queued = 1;
2761: }
2762: }
2763: unless ($queued) {
2764: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2765: $dom);
2766: if ($putresult eq 'ok') {
2767: $output = &mt('Your course request has been recorded.').'<br />'.
2768: ¬ification_information($disposition,$req_notifylist,
2769: $cnum,$now);
1.8 raeburn 2770: } else {
1.16 raeburn 2771: $reqstatus = 'domainerror';
2772: $reqhash{'disposition'} = $disposition;
2773: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2774: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 2775: }
2776: }
2777: }
1.27 raeburn 2778: my ($statusresult);
1.10 raeburn 2779: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2780: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
2781: 'courserequests');
1.14 raeburn 2782: if ($storeresult eq 'ok') {
2783: my %status = (
2784: 'status:'.$dom.':'.$cnum => $reqstatus,
2785: );
1.27 raeburn 2786: $statusresult = &Apache::lonnet::put('courserequests',\%status);
1.14 raeburn 2787: }
1.10 raeburn 2788: } else {
2789: $storeresult = 'error: invalid requestkey format';
2790: }
1.8 raeburn 2791: if ($storeresult ne 'ok') {
1.13 raeburn 2792: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
2793: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 2794: } elsif ($statusresult ne 'ok') {
1.28 raeburn 2795: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
1.14 raeburn 2796: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 2797: }
1.16 raeburn 2798: if ($modified && $queued && $storeresult eq 'ok') {
2799: $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
2800: ¬ification_information($disposition,$req_notifylist,$cnum,$now);
2801: }
1.17 raeburn 2802: if ($validationerror ne '') {
1.19 raeburn 2803: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17 raeburn 2804: }
1.16 raeburn 2805: }
1.27 raeburn 2806: if ($creationresult ne '') {
2807: return ($creationresult,$output);
2808: } else {
2809: return ($storeresult,$output);
2810: }
1.16 raeburn 2811: }
2812:
1.28 raeburn 2813: sub update_requestors_roles {
2814: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
2815: my $now = time;
2816: my ($active,$future,$numactive,$numfuture,$output);
2817: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
2818: if (ref($details) eq 'HASH') {
2819: if (ref($details->{'personnel'}) eq 'HASH') {
2820: if (ref($details->{'personnel'}{$owner}) eq 'HASH') {
2821: my @roles;
2822: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
2823: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
2824: unless (grep(/^cc$/,@roles)) {
2825: push(@roles,'cc');
2826: }
2827: } else {
2828: @roles = ('cc');
2829: }
2830: foreach my $role (@roles) {
2831: my $start = $now;
2832: my $end = '0';
2833: if ($role eq 'st') {
2834: if ($details->{'accessstart'} ne '') {
2835: $start = $details->{'accessstart'};
2836: }
2837: if ($details->{'accessend'} ne '') {
2838: $end = $details->{'accessend'};
2839: }
2840: }
2841: my @usecs;
2842: if ($role ne 'cc') {
2843: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
2844: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
2845: }
2846: }
2847: if ($role eq 'st') {
2848: if (@usecs > 1) {
2849: my $firstsec = $usecs[0];
2850: @usecs = ($firstsec);
2851: }
2852: }
2853: if (@usecs == 0) {
2854: push(@usecs,'');
2855: }
2856: foreach my $usec (@usecs) {
2857: my (%userroles,%newrole,%newgroups,$spec,$area);
2858: my $area = '/'.$dom.'/'.$cnum;
2859: my $spec = $role.'.'.$area;
2860: if ($usec ne '') {
2861: $spec .= '/'.$usec;
2862: $area .= '/'.$usec;
2863: }
2864: if ($role =~ /^cr\//) {
2865: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
2866: $cnum,$spec,$area);
2867: } else {
2868: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
2869: $spec,$cnum,$area);
2870: }
2871: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
2872: \%newgroups);
2873: $userroles{'user.role.'.$spec} = $start.'.'.$end;
2874: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
2875: if (($end == 0) || ($end > $now)) {
2876: my $showrole = $role;
2877: if ($role =~ /^cr\//) {
2878: $showrole = &Apache::lonnet::plaintext($role,$crstype);
2879: } elsif (ref($longroles) eq 'HASH') {
2880: if ($longroles->{$role} ne '') {
2881: $showrole = $longroles->{$role};
2882: }
2883: }
2884: if ($start <= $now) {
2885: $active .= '<li><a href="/adm/roles?selectrole=1&'. $spec.'=1">'.$showrole;
2886: if ($usec ne '') {
2887: $active .= ' - '.&mt('section:').' '.$usec;
2888: }
2889: $active .= '</a></li>';
2890: $numactive ++;
2891: } else {
2892: $future .= '<li>'.$showrole;
2893: if ($usec ne '') {
2894: $future .= ' - '.&mt('section:').' '.$usec;
2895: }
2896: $future .= '</li>';
2897: $numfuture ++;
2898: }
2899: }
2900: }
2901: }
2902: }
2903: }
2904: }
2905: if ($active) {
2906: if ($numactive == 1) {
2907: $output = &mt('Use the following link to enter the course:');
2908: } else {
2909: $output = &mt('Use the following links to your new roles to enter the course:');
2910: }
2911: $output .= ' <ul>'.$active.'</ul><br />';
2912: }
2913: if ($future) {
2914: $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'})).
2915: ' <ul>'.$future.'</ul>';
2916: }
2917: return $output;
2918: }
2919:
1.16 raeburn 2920: sub notification_information {
2921: my ($disposition,$req_notifylist,$cnum,$now) = @_;
2922: my %emails = &Apache::loncommon::getemails();
2923: my $address;
2924: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
2925: $address = $emails{'permanentemail'};
2926: if ($address eq '') {
2927: $address = $emails{'notification'};
2928: }
2929: }
2930: my $output;
2931: if ($disposition eq 'approval') {
2932: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
2933: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
2934: if ($address ne '') {
2935: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
2936: }
2937: if ($req_notifylist) {
2938: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
2939: $env{'user.domain'});
2940: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2941: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
2942: }
1.17 raeburn 2943: } elsif ($disposition eq 'pending') {
1.16 raeburn 2944: $output .= '<div class="LC_info">'.
2945: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
2946: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
2947: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
2948: '</div>';
1.17 raeburn 2949: } else {
2950: $output .= '<div class="LC_warning">'.
2951: &mt('Your request status is: [_1].',$disposition).
2952: '</div>'
1.8 raeburn 2953: }
2954: return $output;
2955: }
2956:
2957: sub get_processtype {
1.9 raeburn 2958: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
2959: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 2960: my (%userenv,%settings,$val);
1.19 raeburn 2961: my @options = ('autolimit','validate','approval');
1.8 raeburn 2962: if ($dom eq $env{'user.domain'}) {
2963: %userenv =
2964: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
2965: 'requestcourses.'.$crstype,'inststatus');
2966: if ($userenv{'requestcourses.'.$crstype}) {
2967: $val = $userenv{'requestcourses.'.$crstype};
2968: @{$inststatuses} = ('_custom_');
2969: } else {
2970: my ($task,%alltasks);
1.9 raeburn 2971: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
2972: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 2973: if (ref($settings{$crstype}) eq 'HASH') {
1.23 raeburn 2974: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1.8 raeburn 2975: $val = $settings{$crstype}{'_LC_adv'};
2976: @{$inststatuses} = ('_LC_adv_');
2977: } else {
2978: if ($userenv{'inststatus'} ne '') {
2979: @{$inststatuses} = split(',',$userenv{'inststatus'});
2980: } else {
1.13 raeburn 2981: @{$inststatuses} = ('default');
1.8 raeburn 2982: }
2983: foreach my $status (@{$inststatuses}) {
2984: if (exists($settings{$crstype}{$status})) {
2985: my $value = $settings{$crstype}{$status};
2986: next unless ($value);
2987: unless (exists($alltasks{$value})) {
2988: if (ref($alltasks{$value}) eq 'ARRAY') {
2989: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
2990: push(@{$alltasks{$value}},$status);
2991: }
2992: } else {
2993: @{$alltasks{$value}} = ($status);
2994: }
2995: }
2996: }
2997: }
2998: my $maxlimit = 0;
1.13 raeburn 2999:
1.8 raeburn 3000: foreach my $key (sort(keys(%alltasks))) {
3001: if ($key =~ /^autolimit=(\d*)$/) {
3002: if ($1 eq '') {
3003: $val ='autolimit=';
3004: last;
3005: } elsif ($1 > $maxlimit) {
3006: $maxlimit = $1;
3007: }
3008: }
3009: }
3010: if ($maxlimit) {
3011: $val = 'autolimit='.$maxlimit;
3012: } else {
3013: foreach my $option (@options) {
3014: if ($alltasks{$option}) {
3015: $val = $option;
3016: last;
3017: }
3018: }
3019: }
3020: }
3021: }
3022: }
3023: }
3024: } else {
3025: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
3026: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19 raeburn 3027: if ($userenv{'reqcrsotherdom.'.$crstype}) {
3028: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
3029: my $optregex = join('|',@options);
3030: foreach my $item (@doms) {
3031: my ($extdom,$extopt) = split(':',$item);
3032: if ($extdom eq $dom) {
3033: if ($extopt =~ /^($optregex)(=?\d*)$/) {
3034: $val = $1.$2;
3035: }
3036: last;
3037: }
1.8 raeburn 3038: }
3039: @{$inststatuses} = ('_external_');
3040: }
3041: }
3042: return $val;
3043: }
3044:
3045: sub check_autolimit {
1.10 raeburn 3046: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3047: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
3048: 'userroles',['active','future'],['cc'],[$dom]);
3049: my ($types,$typename) = &course_types();
3050: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
3051: my %count;
3052: if (ref($types) eq 'ARRAY') {
3053: foreach my $type (@{$types}) {
3054: $count{$type} = 0;
3055: }
3056: }
3057: foreach my $key (keys(%requests)) {
3058: my ($cdom,$cnum) = split('_',$key);
3059: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
3060: if (ref($requests{$key}) eq 'HASH') {
3061: my $type = $requests{$key}{'crstype'};
3062: if ($type =~ /^official|unofficial|community$/) {
3063: $count{$type} ++;
3064: }
3065: }
3066: }
3067: }
3068: if ($count{$crstype} < $limit) {
3069: return 'process';
3070: } else {
3071: if (ref($typename) eq 'HASH') {
3072: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').'<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
3073: }
3074: return 'rejected';
3075: }
1.1 raeburn 3076: return;
3077: }
3078:
1.2 raeburn 3079: sub retrieve_settings {
1.26 raeburn 3080: my ($dom,$cnum,$udom,$uname) = @_;
3081: if ($udom eq '' || $uname eq '') {
3082: $udom = $env{'user.domain'};
3083: $uname = $env{'user.name'};
3084: }
3085: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 3086: if ($result eq 'ok') {
1.26 raeburn 3087: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 3088: $env{'form.chome'} = $reqinfo{'coursehome'};
3089: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3090: $env{'form.crstype'} = $reqinfo{'crstype'};
3091: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3092: &generate_date_items($reqinfo{'accessend'},'accessend');
3093: if ($reqinfo{'accessend'} == 0) {
3094: $env{'form.no_end_date'} = 1;
3095: }
3096: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3097: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3098: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3099: }
3100: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3101: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3102: $env{'form.datemode'} = $reqinfo{'datemode'};
3103: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3104: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
3105: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3106: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3107: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3108: $env{'form.autdrops'} = $reqinfo{'autodrops'};
3109: $env{'form.instcode'} = $reqinfo{'instcode'};
1.24 raeburn 3110: my $crscode = {
3111: $cnum => $reqinfo{'instcode'},
3112: };
3113: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16 raeburn 3114: }
3115: my @currsec;
3116: if (ref($reqinfo{'sections'}) eq 'HASH') {
3117: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3118: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 3119: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 3120: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 3121: $env{'form.sec_'.$i} = '1';
1.16 raeburn 3122: if (!grep(/^\Q$sec\E$/,@currsec)) {
3123: push(@currsec,$sec);
3124: }
3125: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3126: }
3127: }
3128: }
1.24 raeburn 3129: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3130: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3131: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3132: $env{'form.crosslist_'.$i} = '1';
3133: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3134: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3135: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3136: my $key = $cnum.$i;
3137: my $crscode = {
3138: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3139: };
3140: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3141: }
1.16 raeburn 3142: }
3143: }
3144: }
3145: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3146: my $i = 0;
3147: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3148: my ($uname,$udom) = split(':',$user);
3149: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3150: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3151: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3152: $env{'form.person_'.$i.'_role'} = $role;
3153: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3154: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3155: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3156: $env{'form.person_'.$i.'_uname'} = $uname;
3157: $env{'form.person_'.$i.'_dom'} = $udom;
3158: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3159: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3160: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3161: my @newsecs;
3162: if (@usecs > 0) {
3163: foreach my $sec (@usecs) {
3164: if (grep(/^\Q$sec\E/,@currsec)) {
3165: $env{'form.person_'.$i.'_sec'} = $sec;
3166: } else {
1.20 raeburn 3167: push(@newsecs,$sec);
1.16 raeburn 3168: }
3169: }
3170: }
3171: if (@newsecs > 0) {
3172: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3173: }
3174: }
3175: }
3176: $i ++;
3177: }
3178: }
3179: }
3180: }
3181: $env{'form.persontotal'} = $i;
3182: }
3183: }
3184: }
3185: return $result;
3186: }
3187:
3188: sub get_request_settings {
1.26 raeburn 3189: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 3190: my $requestkey = $dom.'_'.$cnum;
3191: my ($result,%reqinfo);
3192: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 3193: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 3194: my $disposition = $history{'disposition'};
3195: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3196: if (ref($history{'details'}) eq 'HASH') {
3197: %reqinfo = %{$history{'details'}};
3198: $result = 'ok';
3199: } else {
3200: $result = 'nothash';
3201: }
3202: } else {
3203: $result = 'notqueued';
3204: }
3205: } else {
3206: $result = 'invalid';
3207: }
3208: return ($result,%reqinfo);
3209: }
1.2 raeburn 3210:
1.16 raeburn 3211: sub extract_instcode {
1.24 raeburn 3212: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 3213: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 3214: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3215: \@codetitles,\%cat_titles,
3216: \%cat_order) eq 'ok') {
3217: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 3218: if (@codetitles > 0) {
3219: my $sel = $element;
3220: if ($element eq 'crosslist') {
3221: $sel .= '_'.$counter;
3222: }
3223: foreach my $title (@codetitles) {
1.24 raeburn 3224: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 3225: }
3226: }
3227: }
3228: }
3229: return;
1.2 raeburn 3230: }
3231:
1.16 raeburn 3232: sub generate_date_items {
3233: my ($currentval,$item) = @_;
3234: if ($currentval =~ /\d+/) {
3235: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3236: &Apache::lonhtmlcommon::get_timedates($currentval);
3237: $env{'form.'.$item.'_day'} = $mday;
3238: $env{'form.'.$item.'_month'} = $month+1;
3239: $env{'form.'.$item.'_year'} = $year;
3240: }
3241: return;
1.2 raeburn 3242: }
3243:
1.1 raeburn 3244: 1;
3245:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>