Annotation of loncom/interface/lonrequestcourse.pm, revision 1.34
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.34 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.33 2009/09/09 15:49:26 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.34 ! raeburn 727: $r->print(&header('Course Requests',$js.$jscript,$loaditems).$crumb.
! 728: '<p>'.&mt('Request creation of a new course, or manage pending course requests.').'</p>'.
! 729: '<div>'.
1.27 raeburn 730: &Apache::lonhtmlcommon::start_pick_box().
731: &Apache::lonhtmlcommon::row_title(&mt('Course Domain')).
1.1 raeburn 732: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
733: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange));
734: if (!$onchange) {
735: $r->print(' <input type="submit" name="godom" value="'.
736: &mt('Change').'" />');
737: }
1.27 raeburn 738: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.1 raeburn 739:
1.2 raeburn 740: my $formname = 'requestcrs';
1.1 raeburn 741: my $nexttext = &mt('Next');
1.27 raeburn 742: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
743: <form name="mainmenu_action" method="post" action="">
1.1 raeburn 744: <select size="1" name="action" >
1.2 raeburn 745: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 746: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
747: <option value="log">'.&mt('View request history').'</option>
1.27 raeburn 748: </select></form>'.
749: &Apache::lonhtmlcommon::row_closure(1).
750: &Apache::lonhtmlcommon::row_title(&mt('Course Type')).'
751: <form name="mainmenu_coursetype" method="post" action="">
1.1 raeburn 752: <select size="1" name="crstype">
1.4 raeburn 753: <option value="any">'.&mt('All types').'</option>');
754: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
755: foreach my $type (@{$types}) {
756: my $selected = '';
757: if ($type eq 'official') {
758: $selected = ' selected="selected"';
759: }
760: $r->print('<option value="'.$type.'"'.$selected.'>'.$typename->{$type}.
761: '</option>'."\n");
762: }
763: }
1.27 raeburn 764: $r->print('</select></form>'."\n".
765: &Apache::lonhtmlcommon::row_closure(1)."\n".
766: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
767: '<div><form name="'.$formname.'" method="post" action="">'."\n".
768: '<input type="hidden" name="state" value="crstype" />'."\n".
769: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
770: '<input type="hidden" name="crstype" value="" />'."\n".
771: '<input type="hidden" name="action" value="" />'."\n".
772: '<input type="button" name="next" value="'.$nexttext.
773: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
774: '</form></div>');
1.1 raeburn 775: $r->print(&Apache::loncommon::end_page());
776: return;
777: }
778:
779: sub request_administration {
1.27 raeburn 780: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
781: $newinstcode,$codechk,$checkedcode,$invalidcrosslist,$uname,$udom) = @_;
1.2 raeburn 782: my $js;
1.16 raeburn 783: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 784: $js = <<END;
1.1 raeburn 785:
786: function nextPage(formname,nextstate) {
787: formname.state.value= nextstate;
788: formname.submit();
789: }
1.16 raeburn 790:
791: END
792: }
793: if (($action eq 'new') || ($action eq 'view')) {
794: $js .= <<END;
795:
1.1 raeburn 796: function backPage(formname,prevstate) {
797: formname.state.value = prevstate;
798: formname.submit();
799: }
800:
801: END
1.2 raeburn 802: }
803: if ($action eq 'new') {
804: my $jsextra;
1.31 raeburn 805: if ($state eq 'courseinfo') {
1.2 raeburn 806: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31 raeburn 807: } elsif ($state eq 'enrollment') {
808: if (($env{'form.crstype'} eq 'official') &&
809: (&Apache::lonnet::auto_run('',$dom))) {
810: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
811: }
812: } elsif ($state eq 'personnel') {
813: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
1.1 raeburn 814: }
1.3 raeburn 815: $r->print(&header('Request a course',$js.$jscript,$loaditems,$jsextra).$crumb);
1.27 raeburn 816: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
817: $codechk,$checkedcode,$invalidcrosslist);
1.2 raeburn 818: } elsif ($action eq 'view') {
1.16 raeburn 819: my $jsextra;
820: my $formname = 'requestcrs';
821: my $prev = $states->{$action}[$page-1];
822: my $next = $states->{$action}[$page+1];
823: if ($state eq 'pick_request') {
824: $next = $states->{$action}[$page+1];
825: $jsextra = &viewrequest_javascript($formname,$next);
826: } elsif ($state eq 'details') {
827: $jsextra = &viewdetails_javascript($formname);
828:
829: } elsif ($state eq 'cancel') {
830: $jsextra = &viewcancel_javascript($formname);
831: }
832: $r->print(&header('Manage course requests',$js.$jscript.$jsextra,$loaditems).
833: $crumb);
834: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 835: if ($state eq 'pick_request') {
1.16 raeburn 836: $r->print('<h3>'.&mt('Pending course requests').'</h3><div>'."\n".$form."\n".
1.30 raeburn 837: &print_request_status($dom).'</form></div>');
1.16 raeburn 838: } elsif ($state eq 'details') {
839: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
840: my $origcnum = $env{'form.cnum'};
841: if ($origcnum eq '') {
842: $origcnum = $env{'form.origcnum'};
843: }
844: if ($env{'form.crstype'} eq 'official') {
845: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
846: \%cat_order,\@code_order);
847: }
848: $r->print('<h3>'.&mt('Course Request Details').'</h3><div>'."\n".$form."\n".
1.26 raeburn 849: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.16 raeburn 850: \@code_order)."\n".
851: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
852: my @excluded = &get_excluded_elements($dom,$states,'new','review');
853: push(@excluded,'origcnum');
854: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
855: my $other = 'modify';
856: my %navtxt = &Apache::lonlocal::texthash (
857: prev => 'Back',
858: other => 'Modify Request',
859: next => 'Cancel Request',
860: );
1.31 raeburn 861: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
862: $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16 raeburn 863: $r->print('</form>');
864: } elsif ($state eq 'cancel') {
865: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
866: $r->print('<h3>'.&mt('Cancel course request').'</h3><div>'."\n".$form."\n".
867: $output);
868: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
869: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
870: my %navtxt = &Apache::lonlocal::texthash (
871: prev => 'Back',
872: next => 'Confirm Cancellation',
873: );
874: if ($result eq 'ok') {
1.31 raeburn 875: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16 raeburn 876: $navtxt{'next'},$state);
877: } else {
1.31 raeburn 878: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
879: '',$state);
1.16 raeburn 880: }
881: $r->print('</form>');
882: } elsif ($state eq 'removal') {
883: my $cnum = $env{'form.origcnum'};
884: my $statuskey = 'status:'.$dom.':'.$cnum;
885: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
886: $env{'user.domain'},$env{'user.name'});
887: my $currstatus = $userreqhash{$statuskey};
888: my ($result,$error);
889: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
890: my %status = (
891: $statuskey => 'cancelled',
892: );
893: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
894: if ($statusresult eq 'ok') {
895: my $delresult =
896: &Apache::lonnet::del_dom('courserequestqueue',
897: [$cnum.'_'.$currstatus],$dom);
898: if ($delresult eq 'ok') {
899: $result = 'ok';
900: } else {
901: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
902: }
903: } else {
904: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
905: }
906: } else {
907: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
908: }
909: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
910: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
911: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
912: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
913: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
914: if ($result eq 'ok') {
915: $r->print(&mt('Your course request has been cancelled.'));
916: } else {
917: $r->print('<div class="LC_error">'.
918: &mt('The request cancellation process was not complete.').
919: '<br />'.$error.'</div>');
920: }
921: $r->print('</form>');
1.11 raeburn 922: }
1.26 raeburn 923: } elsif ($action eq 'display') {
924: my $formname = 'requestcrs';
925: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
926: if ($env{'form.crstype'} eq 'official') {
927: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
928: \%cat_order,\@code_order);
929: }
930: $r->print(&header('Course Request','','','',{ 'only_body' => 1}).
931: $crumb."\n".'<h3>'.&mt('Course Request Details').'</h3>'.
932: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
933: \@code_order,$uname,$udom)."\n".'</div>'.
934: &close_popup_form());
1.1 raeburn 935: } elsif ($action eq 'log') {
1.11 raeburn 936: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 937: }
1.2 raeburn 938: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 939: return;
940: }
941:
1.31 raeburn 942: sub enrollment_lcsec_js {
943: my %alerts = §ion_check_alerts();
944: my $secname = $alerts{'badsec'};
945: my $secnone = $alerts{'reserved'};
946: my $output = '
947: function validateEnrollSections(formname,nextstate) {
948: var badsectotal = 0;
949: var reservedtotal = 0;
950: var secTest = "";
951: ';
952: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
953: $output .= "
954: var selSec = 0;
955: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
956: if (document.requestcrs.sec_".$i."[j].checked) {
957: selSec = document.requestcrs.sec_".$i."[j].value;
958: }
959: if (selSec == 1) {
960: secTest = validsection(document.requestcrs.loncapasec_".$i.");
961: if (secTest == 'badsec') {
962: badsectotal++;
963: }
964: if (secTest == 'reserved') {
965: reservedtotal++;
966: }
967: }
968: }
969: ";
970: }
971: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
972: $output .= "
973: if (document.requestcrs.crosslist_".$i.".checked) {
974: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
975: if (secTest == 'badsec') {
976: badsectotal++;
977: }
978: if (secTest == 'reserved') {
979: reservedtotal++;
980: }
981: }
982: ";
983: }
984: $output .= "
985: if (badsectotal>0) {
986: alert('$secname');
987: return false;
988: }
989: if (reservedtotal>0) {
990: alert('$secnone');
991: return false;
992: }
993: formname.state.value= nextstate;
994: formname.submit();
995: return;
996: }
997: ";
998: return $output;
999: }
1000:
1001: sub personnel_lcsec_js {
1002: my %alerts = §ion_check_alerts();
1003: my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
1004: my $secnone = $alerts{'reserved'};
1005: my $output = '
1006: function validatePersonnelSections(formname,nextstate) {
1007: var badsectotal = 0;
1008: var reservedtotal = 0;
1009: var secTest = "";
1010: ';
1011: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1012: $output .= "
1013: if (document.requestcrs.person_".$i."_uname.value != '') {
1014: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1015: if (secTest == 'badsec') {
1016: badsectotal++;
1017: }
1018: if (secTest == 'reserved') {
1019: reservedtotal++;
1020: }
1021: }
1022: ";
1023: }
1024: $output .= "
1025: if (badsectotal > 0) {
1026: alert('$secname');
1027: return false;
1028: } else {
1029: if (reservedtotal > 0) {
1030: alert('$secnone');
1031: return false;
1032: }
1033: }
1034: formname.state.value = nextstate;
1035: formname.submit();
1036: return;
1037: }
1038: ";
1039: return $output;
1040: }
1041:
1042: sub section_check_alerts {
1043: my %lt =
1044: &Apache::lonlocal::texthash(
1045: 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.",
1046: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1047: separate => 'Separate multiple sections with a comma.'
1048: );
1049: return %lt;
1050: }
1051:
1052: sub section_check_javascript {
1053: return <<"END";
1054: function validsection(field,mult) {
1055: var str = field.value;
1056: var badsec=0;
1057: var reserved=0;
1058: if (window.RegExp) {
1059: var badsecnum=0;
1060: var reservednum=0;
1061: var pattern=/[^a-zA-Z0-9]/;
1062: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1063: str = str.replace(/[ ]{2,}/gi," ");
1064: if (mult == '1') {
1065: var sections = new Array();
1066: sections = str.split(/\\s*[\\s,;:]\\s*/);
1067: var i;
1068: for (i=0; i<sections.length; i++) {
1069: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1070: if (pattern.test(sections[i])) {
1071: badsecnum++;
1072: } else {
1073: if (sections[i] == 'none') {
1074: reservednum++;
1075: }
1076: }
1077: }
1078: }
1079: } else {
1080: if ((str != '') && (str != undefined) && (str != null)) {
1081: if (pattern.test(str)) {
1082: badsecnum++;
1083: } else {
1084: if (str == 'none') {
1085: reservednum++;
1086: }
1087: }
1088: }
1089: }
1090: if (badsecnum > 0) {
1091: return 'badsec';
1092: }
1093: if (reservednum > 0) {
1094: return 'reserved';
1095: }
1096: }
1097: return;
1098: }
1099: END
1100: }
1101:
1.26 raeburn 1102: sub close_popup_form {
1103: my $close= &mt('Close Window');
1104: return << "END";
1105: <p><form name="displayreq" action="" method="post">
1106: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1107: </form></p>
1108: END
1109: }
1110:
1.27 raeburn 1111: sub get_instcode {
1112: my ($dom) = @_;
1113: my ($instcode,$numtitles);
1114: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1115: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1116: \%cat_order,\@code_order);
1117: $numtitles = scalar(@codetitles);
1118: if (@code_order > 0) {
1119: my $message;
1120: foreach my $item (@code_order) {
1121: $instcode .= $env{'form.instcode_'.$item};
1122: }
1123: }
1124: return ($instcode,$numtitles);
1125: }
1126:
1.1 raeburn 1127: sub print_request_form {
1.27 raeburn 1128: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1129: $invalidcrosslist) = @_;
1.1 raeburn 1130: my $formname = 'requestcrs';
1.2 raeburn 1131: my ($next,$prev,$message,$output,$codepicker,$crstype);
1132: $prev = $states->{$action}[$page-1];
1133: $next = $states->{$action}[$page+1];
1.4 raeburn 1134: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 1135: prev => 'Back',
1.4 raeburn 1136: next => 'Next',
1137: );
1.2 raeburn 1138: $crstype = $env{'form.crstype'};
1.34 ! raeburn 1139: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30 raeburn 1140: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1141: @disallowed);
1.1 raeburn 1142: if ($crstype eq 'official') {
1.2 raeburn 1143: if ($env{'form.instcode'} ne '') {
1144: $instcode = $env{'form.instcode'};
1.27 raeburn 1145: } elsif ($newinstcode ne '') {
1146: $instcode = $newinstcode;
1.2 raeburn 1147: }
1.27 raeburn 1148: if ($checkedcode) {
1149: if ($codechk eq 'valid') {
1150: $message = '<div class="LC_info">'.
1151: &mt('The chosen course category [_1] is valid.','<b>'.
1152: $instcode.'</b>').
1153: '<input type="hidden" name="instcode" value="'.
1154: $instcode.'" /></div>';
1.2 raeburn 1155: } else {
1156: $message = '<div class="LC_warning">'.
1.27 raeburn 1157: &mt('No course was found matching your choice of institutional course category.');
1158: if ($codechk ne '') {
1159: $message .= '<br />'.$codechk;
1160: }
1161: $message .= '</div>';
1.2 raeburn 1162: $prev = 'crstype';
1163: }
1164: $r->print($message);
1.1 raeburn 1165: }
1.2 raeburn 1166: }
1167: if ($prev eq 'crstype') {
1.4 raeburn 1168: if ($crstype eq 'official') {
1169: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1170: \%cat_order,\@code_order);
1171: }
1.2 raeburn 1172: if (@code_order > 0) {
1.1 raeburn 1173: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1174: \%cat_titles,\%cat_order);
1.2 raeburn 1175: if ($codepicker) {
1.34 ! raeburn 1176: $r->print(&mt('Specify the course to be created.').
! 1177: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
! 1178: $codepicker.
1.2 raeburn 1179: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1180: } else {
1.20 raeburn 1181: $next = $states->{$action}[$page+2];
1.15 raeburn 1182: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1183: }
1184: } else {
1.20 raeburn 1185: if ($crstype eq 'official') {
1186: $next = $states->{$action}[$page+2];
1187: }
1.15 raeburn 1188: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 1189: }
1.2 raeburn 1190: } elsif ($prev eq 'codepick') {
1.27 raeburn 1191: if ($instcode eq '') {
1.20 raeburn 1192: $prev = $states->{$action}[$page-2];
1193: }
1.15 raeburn 1194: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1195: } elsif ($state eq 'enrollment') {
1.4 raeburn 1196: if ($crstype eq 'official') {
1197: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1198: \%cat_order,\@code_order);
1199: }
1.2 raeburn 1200: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1.27 raeburn 1201: \%cat_titles,\%cat_order,\@code_order,
1202: $invalidcrosslist));
1.2 raeburn 1203: } elsif ($state eq 'personnel') {
1.27 raeburn 1204: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1.4 raeburn 1205: } elsif ($state eq 'review') {
1.30 raeburn 1206: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1207: my $now = time;
1208: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1209: my $personname = $env{'form.person_'.$i.'_uname'};
1210: my $persondom = $env{'form.person_'.$i.'_dom'};
1211: if (($personname =~ /^$match_username$/) &&
1212: ($persondom =~ /^$match_domain$/)) {
1213: if (&Apache::lonnet::domain($persondom)) {
1214: my $personhome =
1215: &Apache::lonnet::homeserver($personname,$persondom);
1216: if ($personhome eq 'no_host') {
1217: if ($persondom ne $dom) {
1218: my $skipuser = 1;
1219: if ($env{'user.role.dc./'.$persondom.'/'}) {
1220: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1221: if (((!$start) || ($start < $now)) &&
1222: ((!$end) || ($end > $now))) {
1223: $skipuser = 0;
1224: }
1225: }
1226: if ($skipuser) {
1227: push(@disallowed,$i);
1228: $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1229: next;
1230: }
1231: }
1232: if (&get_cancreate_status($persondom,$personname,$dom)) {
1233: my ($allowed,$msg) =
1234: &check_newuser_rules($persondom,$personname,
1235: \%alerts,\%rulematch,\%inst_results,
1236: \%curr_rules,\%got_rules);
1237: if ($allowed) {
1238: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1239: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1240: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1241: }
1242: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1243: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1244: }
1245: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1246: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1247: }
1248: }
1249: } else {
1250: push(@disallowed,$i);
1251: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1252: }
1253: } else {
1254: push(@disallowed,$i);
1255: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1256: }
1257: } else {
1258: my %userenv =
1259: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1260: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1261: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1262: }
1263: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1264: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1265: }
1266: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1267: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1268: }
1269: }
1270: } elsif ($personname ne '') {
1271: push(@disallowed,$i);
1272: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1273: }
1274: } elsif ($personname ne '') {
1275: push(@disallowed,$i);
1276: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1277: }
1278: }
1.16 raeburn 1279: my $cnum;
1280: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1281: $cnum = $env{'form.origcnum'};
1282: } else {
1283: $cnum = &Apache::lonnet::generate_coursenum($dom);
1284: }
1.4 raeburn 1285: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1286: \%cat_order,\@code_order);
1.27 raeburn 1287: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>'.
1.30 raeburn 1288: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1.16 raeburn 1289: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.4 raeburn 1290: $navtxt{'next'} = &mt('Submit course request');
1.10 raeburn 1291: } elsif ($state eq 'process') {
1292: if ($crstype eq 'official') {
1293: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1294: \%cat_order,\@code_order);
1295: }
1.27 raeburn 1296: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1297: \@code_order);
1.13 raeburn 1298: $r->print($result);
1.27 raeburn 1299: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1300: $r->print('<p>');
1301: if ($storeresult eq 'ok') {
1302: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1303: &mt('Modify this request').'</a>'.(' 'x4));
1304: }
1305: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1306: return;
1307: }
1.1 raeburn 1308: }
1.16 raeburn 1309: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24 raeburn 1310: if ($state eq 'personnel') {
1311: push(@excluded,'persontotal');
1312: }
1.30 raeburn 1313: if ($state eq 'review') {
1314: if (@disallowed > 0) {
1315: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1316: my @currsecs = ¤t_lc_sections();
1317: if (@currsecs) {
1318: push(@items,'sec');
1319: }
1320: my $count = 0;
1321: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1322: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1323: if (grep(/^$i$/,@disallowed)) {
1324: foreach my $item (@items) {
1325: $env{'form.person_'.$i.'_'.$item} = '';
1326: }
1327: } else {
1328: foreach my $item (@items) {
1329: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1330: }
1331: }
1332: }
1333: $count ++;
1334: }
1335: $env{'form.persontotal'} = $count;
1336:
1337: }
1338: }
1.27 raeburn 1339: if ($state eq 'enrollment') {
1340: push(@excluded,'crosslisttotal');
1341: }
1.16 raeburn 1342: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1.31 raeburn 1343: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1344: $navtxt{'next'},$state);
1.16 raeburn 1345: return;
1346: }
1347:
1.30 raeburn 1348: sub get_cancreate_status {
1349: my ($persondom,$personname,$dom) = @_;
1350: my ($rules,$ruleorder) =
1351: &Apache::lonnet::inst_userrules($persondom,'username');
1352: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1353: $rules);
1354: return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
1355: }
1356:
1357: sub check_newuser_rules {
1358: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1359: $got_rules) = @_;
1360: my $allowed = 1;
1361: my $newuser = 1;
1362: my ($checkhash,$userchkmsg);
1363: my $checks = { 'username' => 1 };
1364: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1365: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1366: $inst_results,$curr_rules,$got_rules);
1367: if (ref($alerts->{'username'}) eq 'HASH') {
1368: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1369: my $domdesc =
1370: &Apache::lonnet::domain($persondom,'description');
1371: if ($alerts->{'username'}{$persondom}{$personname}) {
1372: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1373: $userchkmsg =
1374: &Apache::loncommon::instrule_disallow_msg('username',
1375: $domdesc,1).
1376: &Apache::loncommon::user_rule_formats($persondom,
1377: $domdesc,$curr_rules->{$persondom}{'username'},
1378: 'username');
1379: }
1380: $allowed = 0;
1381: }
1382: }
1383: }
1384: return ($allowed,$userchkmsg);
1385: }
1386:
1.16 raeburn 1387: sub get_excluded_elements {
1388: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 1389: my @excluded = ('counter');
1390: my %elements = &form_elements($dom);
1391: if (ref($states) eq 'HASH') {
1392: if (ref($states->{$action}) eq 'ARRAY') {
1393: my @items = @{$states->{$action}};
1394: my $numitems = scalar(@items);
1395: if ($numitems) {
1396: for (my $i=$numitems-1; $i>=0; $i--) {
1397: if (ref($elements{$action}) eq 'HASH') {
1398: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 1399: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 1400: push(@excluded,$key);
1401: }
1402: }
1403: }
1404: last if ($items[$i] eq $state);
1405: }
1406: }
1407: }
1408: }
1409: if (grep(/^instcode_/,@excluded)) {
1410: push(@excluded,'instcode');
1.1 raeburn 1411: }
1.16 raeburn 1412: return @excluded;
1.1 raeburn 1413: }
1414:
1.2 raeburn 1415: sub print_enrollment_menu {
1.27 raeburn 1416: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1417: $invalidcrosslist) =@_;
1.34 ! raeburn 1418: my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1.2 raeburn 1419: my $starttime = time;
1420: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1421:
1422: my %accesstitles = (
1423: 'start' => 'Default start access',
1.16 raeburn 1424: 'end' => 'Default end access',
1.2 raeburn 1425: );
1426: my %enrolltitles = (
1427: 'start' => 'Start auto-enrollment',
1428: 'end' => 'End auto-enrollment',
1429: );
1430: if ($env{'form.crstype'} eq 'official') {
1431: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1432: $output = &show_invalid_crosslists($invalidcrosslist);
1433: my ($section_form,$crosslist_form);
1.2 raeburn 1434: $section_form = &inst_section_selector($dom,$instcode);
1.27 raeburn 1435: if ($section_form) {
1436: $sections = &Apache::lonhtmlcommon::row_headline().
1.34 ! raeburn 1437: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
! 1438: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1.27 raeburn 1439: &Apache::lonhtmlcommon::row_closure(1).
1440: $section_form;
1441: }
1.2 raeburn 1442: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1443: if (!$crosslisttotal) {
1.2 raeburn 1444: $crosslisttotal = 1;
1445: }
1446: if ($env{'form.addcrosslist'}) {
1447: $crosslisttotal ++;
1448: }
1449: for (my $i=0; $i<$crosslisttotal; $i++) {
1450: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1451: $cat_titles,$cat_order,$i);
1452: }
1453: if ($crosslist_form) {
1454: $crosslist_form .=
1455: &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1456: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1457: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1458: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27 raeburn 1459: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1460: $sections .= &Apache::lonhtmlcommon::row_headline.
1461: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1462: &Apache::lonhtmlcommon::row_closure(1).
1463: $crosslist_form;
1.2 raeburn 1464: }
1.34 ! raeburn 1465: $hasauto = 1;
1.27 raeburn 1466: $autoenroll =
1.34 ! raeburn 1467: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1.2 raeburn 1468: '<span class="LC_nobreak"><label>'.
1469: '<input type="radio" name="autoadds" value="1">'.
1470: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1471: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1472: &mt('No').'</label></span>'.
1.27 raeburn 1473: &Apache::lonhtmlcommon::row_closure(1).
1.34 ! raeburn 1474: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1.2 raeburn 1475: '<span class="LC_nobreak"><label>'.
1476: '<input type="radio" name="autodrops" value="1">'.
1477: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1478: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1479: &mt('No').'</label></span>'.
1.27 raeburn 1480: &Apache::lonhtmlcommon::row_closure(1).
1.34 ! raeburn 1481: &date_setting_table($starttime,$endtime,$formname,'enroll',
! 1482: $hasauto,%enrolltitles);
1.2 raeburn 1483: }
1484: }
1.27 raeburn 1485: my $access_dates =
1.34 ! raeburn 1486: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
! 1487: %accesstitles);
1.27 raeburn 1488: $output .= &Apache::lonhtmlcommon::start_pick_box();
1489: if ($sections) {
1490: $output .= $sections;
1491: }
1492: if ($autoenroll) {
1493: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1494: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1495: &Apache::lonhtmlcommon::row_closure(1).
1496: $autoenroll;
1497: }
1498: if ($access_dates) {
1499: my $header = &mt('Access dates for students');
1500: if ($env{'form.crstype'} eq 'community') {
1501: $header = &mt('Access dates for community members');
1502: }
1503: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1504: '<h3>'.$header.'</h3>'.
1505: &Apache::lonhtmlcommon::row_closure(1).
1506: $access_dates
1.2 raeburn 1507: }
1.27 raeburn 1508: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1509: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2 raeburn 1510: }
1511:
1.27 raeburn 1512: sub show_invalid_crosslists {
1513: my ($invalidcrosslist) = @_;
1514: my $output;
1515: if (ref($invalidcrosslist) eq 'ARRAY') {
1516: if (@{$invalidcrosslist} > 0) {
1517: $output = '<div class="LC_warning">'.
1518: &mt('The following crosslisted courses were invalid:').'<ul>';
1519: foreach my $item (@{$invalidcrosslist}) {
1520: $output .= '<li>'.$item.'</li>';
1521: }
1522: $output .= '</ul></div><br />';
1523: }
1524: }
1525: return $output;
1526: }
1527:
1528:
1.1 raeburn 1529: sub inst_section_selector {
1.2 raeburn 1530: my ($dom,$instcode) = @_;
1531: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1532: my $sectotal = scalar(@sections);
1.1 raeburn 1533: my $output;
1.2 raeburn 1534: if ($sectotal) {
1.27 raeburn 1535: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1536: &Apache::loncommon::start_data_table().
1537: &Apache::loncommon::start_data_table_row().
1538: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1539: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1540: '<th>'.&mt('Institutional Section').'</th>'.
1.34 ! raeburn 1541: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
! 1542: ' '.&mt('LON-CAPA section').'</th>'.
1.2 raeburn 1543: &Apache::loncommon::end_data_table_row();
1544: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1545: my $colflag = $i%2;
1.31 raeburn 1546: my $secon = ' checked="checked"';
1547: my $secoff = '';
1.24 raeburn 1548: if ($env{'form.origcnum'}) {
1.31 raeburn 1549: $secoff = $secon;
1550: $secon='';
1.24 raeburn 1551: }
1.1 raeburn 1552: $output .= &Apache::loncommon::start_data_table_row().
1.31 raeburn 1553: '<td><label><input type="radio" name="sec_'.$i.
1554: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1555: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1556: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1557: '<td align="center">'.$sections[$i].
1.1 raeburn 1558: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1559: $sections[$i].'" /></td>'.
1.1 raeburn 1560: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1561: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1562: &Apache::loncommon::end_data_table_row();
1563: }
1.2 raeburn 1564: $output .= &Apache::loncommon::end_data_table().
1565: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1566: }
1567: return $output;
1568: }
1569:
1.2 raeburn 1570: sub date_setting_table {
1.34 ! raeburn 1571: my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
1.2 raeburn 1572: my ($perpetual,$table);
1.14 raeburn 1573: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 1574: $starttime,'','','',1,'','','',1);
1.14 raeburn 1575: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 1576: $endtime,'','','',1,'','','',1);
1.27 raeburn 1577: my $closure = '';
1.14 raeburn 1578: if ($prefix eq 'access') {
1.2 raeburn 1579: $perpetual = ' <span class="LC_nobreak"><label>'.
1580: '<input type="checkbox" name="no_end_date" />'.
1581: &mt('No end date').'</label></span>';
1.27 raeburn 1582: $closure = '1';
1.2 raeburn 1583: }
1.34 ! raeburn 1584:
! 1585: my %help_item = (
! 1586: access => {
! 1587: start => 'Course_Request_Access_Start',
! 1588: end => 'Course_Request_Access_End',
! 1589: },
! 1590: enroll => {
! 1591: start => 'Course_Request_Enroll_Start',
! 1592: end => 'Course_Request_Enroll_End',
! 1593: },
! 1594: );
! 1595: if ($hasauto) {
! 1596: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
! 1597: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
! 1598: }
! 1599:
! 1600: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
! 1601: ' '.$datetitles{'start'}).$startform.
1.27 raeburn 1602: &Apache::lonhtmlcommon::row_closure(1).
1.34 ! raeburn 1603: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
! 1604: ' '.$datetitles{'end'}).$endform.$perpetual.
1.27 raeburn 1605: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 1606: return $table;
1607: }
1608:
1609: sub print_personnel_menu {
1.27 raeburn 1610: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1611: my $output;
1612: if ($crstype eq 'official') {
1613: if (&Apache::lonnet::auto_run('',$dom)) {
1614: $output .= &show_invalid_crosslists($invalidcrosslist);
1615: }
1616: }
1617: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 1618: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1619: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1620: $persontotal = 1;
1621: }
1622: if ($env{'form.addperson'}) {
1623: $persontotal ++;
1624: }
1.13 raeburn 1625: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1626:
1627: my $roleoptions;
1628: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 1629: my $type = 'Course';
1630: if ($crstype eq 'community') {
1631: $type = 'Community';
1632: }
1.2 raeburn 1633: foreach my $role (@roles) {
1.28 raeburn 1634: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1635: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1636: }
1637: my %customroles=&Apache::lonuserutils::my_custom_roles();
1638: if (keys(%customroles) > 0) {
1639: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 1640: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 1641: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1642: }
1643: }
1644:
1.30 raeburn 1645: my @currsecs = ¤t_lc_sections();
1.2 raeburn 1646:
1647: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1648: if (@currsecs) {
1649: my $existsize = scalar(@currsecs);
1650: if ($existsize > 3) {
1651: $existsize = 3;
1652: }
1653: if ($existsize > 1) {
1654: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1655: }
1656: @currsecs = sort { $a <=> $b } (@currsecs);
1657: $existtitle = &mt('Official').': ';
1658: $existops = '<option value="">'.&mt('None').'</option>';
1659: foreach my $sec (@currsecs) {
1660: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1661: }
1662: $seccolspan = ' colspan="2"';
1663: $newtitle = &mt('Other').': ';
1664: }
1665:
1.27 raeburn 1666: if ($persontotal) {
1.32 raeburn 1667: my %lt = &Apache::lonlocal::texthash(
1668: community => 'Requestor is automatically assigned Coordinator role.',
1669: official => 'Requestor is automatically assigned Course Coordinator role.',
1670: );
1671: $lt{'unofficial'} = $lt{'official'};
1.27 raeburn 1672: $output .= &Apache::lonhtmlcommon::row_headline().
1.34 ! raeburn 1673: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27 raeburn 1674: }
1.2 raeburn 1675: for (my $i=0; $i<$persontotal; $i++) {
1676: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1677: my $linkargstr = join("','",@linkargs);
1.29 raeburn 1678: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 1679: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 1680: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 1681: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1682: 1,$onchange).
1.29 raeburn 1683: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 1684: my %form_elems;
1685: foreach my $item (@items) {
1686: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1687: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1688: 'value="" readonly="readonly" />';
1689: }
1690: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1691: $roleoptions.'</select>';
1692: my $sectionselector;
1693: if (@currsecs) {
1694: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1695: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1696: }
1697: $sectionselector .= $newtitle.
1.14 raeburn 1698: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29 raeburn 1699: my $usersrchlinktxt = &mt('Search for user');
1700: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1701: $usersrchlinktxt);
1702: my $userchklinktxt = &mt('Check username');
1703: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1704: $userchklinktxt,'checkusername');
1.2 raeburn 1705: $output .=
1.29 raeburn 1706: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1707: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1708: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1709: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1710: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1711: '</tr>'."\n".'<tr>'.
1.13 raeburn 1712: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1713: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1714: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34 ! raeburn 1715: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
! 1716: '<td'.$seccolspan.' align="center" valign="top">'.
! 1717: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2 raeburn 1718: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1719: }
1720: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another?')).
1721: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1722: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1723: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1724: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.34 ! raeburn 1725: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
! 1726: '<p>'.&mt('You may also add users later, once the course has been created, by using the "Manage course users" link, accessible from the "Main Menu".').'</p>';
1.2 raeburn 1727: return $output;
1728: }
1729:
1.30 raeburn 1730: sub current_lc_sections {
1731: my @currsecs;
1732: if ($env{'form.sectotal'}) {
1733: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 1734: if ($env{'form.sec_'.$i}) {
1735: if (defined($env{'form.loncapasec_'.$i})) {
1736: my $lcsec = $env{'form.loncapasec_'.$i};
1737: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1738: push(@currsecs,$lcsec);
1739: }
1.30 raeburn 1740: }
1741: }
1742: }
1743: }
1744: return @currsecs;
1745: }
1746:
1.1 raeburn 1747: sub print_request_status {
1.11 raeburn 1748: my ($dom) = @_;
1.14 raeburn 1749: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1750: $env{'user.name'},'^status:'.$dom);
1751: my ($output,$formname,%queue_by_date,%typenames);
1752: if ($env{'form.crstype'} eq 'any') {
1753: %typenames = &Apache::lonlocal::texthash (
1754: official => 'Official course',
1755: unofficial => 'Unofficial course',
1756: community => 'Community',
1757: );
1758: }
1759: foreach my $key (keys(%statusinfo)) {
1760: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1761: (undef,my($cdom,$cnum)) = split(':',$key);
1762: next if ($cdom ne $dom);
1763: my $requestkey = $cdom.'_'.$cnum;
1764: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1765: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1766: $env{'user.domain'},$env{'user.name'});
1767: my $entry;
1768: my $timestamp = $history{'reqtime'};
1769: my $crstype = $history{'crstype'};
1770: my $disposition = $history{'disposition'};
1771: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1772: next unless (($env{'form.crstype'} eq 'any') ||
1773: ($env{'form.crstype'} eq $crstype));
1774: next unless (($disposition eq 'approval') ||
1775: ($disposition eq 'pending'));
1776: if (ref($history{'details'}) eq 'HASH') {
1777: $entry = $requestkey.':'.$crstype.':'.
1778: &escape($history{'details'}{'cdescr'});
1779: if ($crstype eq 'official') {
1780: $entry .= ':'.&escape($history{'details'}{'instcode'});
1781: }
1782: }
1783: if ($entry ne '') {
1784: if (exists($queue_by_date{$timestamp})) {
1785: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1786: push(@{$queue_by_date{$timestamp}},$entry);
1787: }
1788: } else {
1789: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 1790: }
1791: }
1792: }
1793: }
1794: }
1.11 raeburn 1795: $formname = 'requestcrs';
1.10 raeburn 1796: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.16 raeburn 1797: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1798:
1.10 raeburn 1799: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 1800: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1801: '<input type="hidden" name="showdom" value="" />'."\n".
1802: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 1803: if (@sortedtimes > 0) {
1804: $output .= &Apache::loncommon::start_data_table().
1805: &Apache::loncommon::start_data_table_header_row().
1806: '<th>'.&mt('Action').'</th>'.
1.14 raeburn 1807: '<th>'.&mt('Course Description').'</th>'.
1808: '<th>'.&mt('Domain').'</th>';
1809: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 1810: $output .= '<th>'.&mt('Type').'</th>';
1811: }
1.14 raeburn 1812: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 1813: $output .= '<th>'.&mt('Institutional Code').'</th>';
1814: }
1815: $output .= '<th>'.&mt('Date requested').'</th>'.
1816: &Apache::loncommon::end_data_table_header_row();
1817: my $count = 0;
1818: foreach my $item (@sortedtimes) {
1819: my $showtime = &Apache::lonlocal::locallocaltime($item);
1820: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1821: foreach my $request (sort(@{$queue_by_date{$item}})) {
1822: my ($key,$type,$desc,$instcode) = split(':',$request);
1823: my ($cdom,$cnum) = split('_',$key);
1824: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 1825: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 1826: '<td>'.&unescape($desc).'</td>'.
1827: '<td>'.$cdom.'</td>';
1828: if ($env{'form.crstype'} eq 'any') {
1829: my $typename = $typenames{$type};
1830: if ($typename eq '') {
1831: $typename = &mt('Unknown type');
1832: }
1833: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 1834: }
1.14 raeburn 1835: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 1836: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 1837: my $showinstcode;
1838: if ($type eq 'official') {
1839: $showinstcode = &unescape($instcode);
1840: } else {
1841: $showinstcode = &mt('Not applicable');
1842: }
1843: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 1844: }
1845: $output .= '<td>'.$showtime.'</td>'.
1846: &Apache::loncommon::end_data_table_row();
1847: }
1848: }
1849: }
1850: $output .= &Apache::loncommon::end_data_table();
1851: } else {
1.11 raeburn 1852: $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 1853: }
1854: $output .= '
1.30 raeburn 1855: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 1856: return $output;
1.1 raeburn 1857: }
1858:
1.16 raeburn 1859: sub print_cancel_request {
1860: my ($dom,$cnum) = @_;
1861: my $requestkey = $dom.'_'.$cnum;
1862: my ($result,$output);
1863: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1864: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1865: $env{'user.domain'},$env{'user.name'});
1866: my $timestamp = $history{'reqtime'};
1867: my $crstype = $history{'crstype'};
1868: my $status = $history{'status'};
1869: if (($status eq 'cancelled') || ($status eq 'created')) {
1870: if ($status eq 'cancelled') {
1871: $output = &mt('This request has already been cancelled.');
1872: } elsif ($status eq 'created') {
1873: $output = &mt('This request has already been processed, and a course created.');
1874: }
1875: $output = &mt('No further action will be taken');
1876: } elsif (ref($history{'details'}) eq 'HASH') {
1877: my ($types,$typename) = &course_types();
1878: my $showtype = $crstype;
1879: if (defined($typename->{$crstype})) {
1880: $showtype = $typename->{$crstype};
1881: }
1882: $output = '<p>'.&Apache::loncommon::start_data_table().
1883: &Apache::loncommon::start_data_table_header_row().
1884: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
1885: '<th>'.&mt('Type').'</th>'.
1886: &Apache::loncommon::end_data_table_header_row().
1887: &Apache::loncommon::start_data_table_row().
1888: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
1889: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
1890: '<td>'.$showtype.'</td>'.
1891: &Apache::loncommon::end_data_table_row().
1892: &Apache::loncommon::end_data_table().
1893: '<br /><div class="LC_warning">'.
1894: &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
1895: $result = 'ok';
1896: } else {
1897: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
1898: }
1899: } else {
1900: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
1901: }
1902: return ($result,$output);
1903: }
1904:
1905: sub viewrequest_javascript {
1906: my ($formname,$next) = @_;
1907: return <<"ENDJS";
1908:
1909: function chooseRequest(cdom,cnum) {
1910: document.$formname.showdom.value = cdom;
1911: document.$formname.cnum.value = cnum;
1912: nextPage(document.$formname,'$next');
1913: }
1914:
1915: ENDJS
1916: }
1917:
1918: sub viewdetails_javascript {
1919: my ($formname) = @_;
1920: return << "ENDJS";
1921:
1922: function nextPage(formname,nextstate) {
1923: if (nextstate == "modify") {
1924: formname.state.value = "personnel";
1925: formname.action.value = "new";
1926: } else {
1927: formname.state.value = nextstate;
1928: }
1929: formname.submit();
1930: }
1931:
1932: function backPage(formname,prevstate) {
1933: formname.state.value = prevstate;
1934: formname.submit();
1935: }
1936:
1937: ENDJS
1938: }
1939:
1940: sub viewcancel_javascript {
1941: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
1942: 'Your request will be removed.');
1943: return << "ENDJS";
1944: function nextPage(formname,nextstate) {
1945: if (confirm('$alert')) {
1946: formname.state.value = nextstate;
1947: formname.submit();
1948: }
1949: return;
1950: }
1951:
1952: ENDJS
1953: }
1954:
1.1 raeburn 1955: sub print_request_logs {
1.10 raeburn 1956: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 1957: return;
1958: }
1959:
1960: sub print_review {
1.30 raeburn 1961: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
1962: $disallowed,$disallowmsg) = @_;
1.4 raeburn 1963: my ($types,$typename) = &course_types();
1964: my ($owner,$ownername,$owneremail);
1.26 raeburn 1965: if ($uname eq '' || $udom eq '') {
1966: $uname = $env{'user.name'};
1967: $udom = $env{'user.domain'};
1968: }
1969: $owner = $uname.':'.$udom;
1970: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
1971: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 1972: foreach my $email ('permanentemail','critnotification','notification') {
1973: $owneremail = $emails{$email};
1974: last if ($owneremail ne '');
1975: }
1976: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
1977: $section_headers,$section_values,$personnel_headers,$personnel_values);
1978:
1979: $crstypename = $env{'form.crstype'};
1980: if (ref($typename) eq 'HASH') {
1981: unless ($typename->{$env{'form.crstype'}} eq '') {
1982: $crstypename = $typename->{$env{'form.crstype'}};
1983: }
1984: }
1.16 raeburn 1985: my $category = 'Course';
1986: if ($env{'form.crstype'} eq 'community') {
1987: $category = 'Community';
1988: }
1.4 raeburn 1989:
1990: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
1991: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
1992:
1.16 raeburn 1993: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
1994: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 1995: if ($env{'form.crstype'} eq 'official') {
1996: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
1997: foreach my $title (@{$codetitles}) {
1998: if ($env{'form.instcode_'.$title} ne '') {
1999: $inst_headers .= '<th>'.$title.'</th>';
2000: my $longitem = $env{'form.instcode_'.$title};
2001: if (ref($cat_titles->{$title}) eq 'HASH') {
2002: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2003: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2004: }
2005: }
2006: $inst_values .= '<td>'.$longitem.'</td>';
2007: }
2008: }
2009: }
2010: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 2011: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 2012: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2013: '<th>'.&mt('Automatic Drops').'</th>'.
2014: '<th>'.&mt('Enrollment Starts').'</th>'.
2015: '<th>'.&mt('Enrollment Ends').'</th>';
2016: $section_headers = '<th>'.&mt('Sections').'</th>'.
2017: '<th>'.&mt('Crosslistings').'</th>';
2018:
1.13 raeburn 2019: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 2020: my @autoroster = (&mt('No'),&mt('Yes'));
2021: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2022: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 2023: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2024: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 2025: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2026: &mt('Institutional section').'</th>'.
2027: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2028: my $secinfo;
1.4 raeburn 2029: if ($env{'form.sectotal'} > 0) {
2030: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2031: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2032: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2033: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2034: $secinfo .= $env{'form.loncapasec_'.$i};
2035: } else {
2036: $secinfo .= &mt('None');
1.4 raeburn 2037: }
1.5 raeburn 2038: $secinfo .= '</td></tr>';
1.4 raeburn 2039: }
2040: }
2041: }
1.6 raeburn 2042: if ($secinfo eq '') {
2043: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2044: }
1.6 raeburn 2045: $section_values .= $secinfo.'</table></td><td>'.
2046: '<table class="LC_innerpickbox"><tr><th>'.
2047: &mt('Institutional course/section').'</th>'.
2048: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2049: my $xlistinfo;
1.24 raeburn 2050: my $crosslisttotal = $env{'form.crosslisttotal'};
2051: if (!$crosslisttotal) {
2052: $crosslisttotal = 1;
2053: }
2054: for (my $i=0; $i<$crosslisttotal; $i++) {
2055: if ($env{'form.crosslist_'.$i}) {
2056: $xlistinfo .= '<tr><td>';
2057: if (ref($code_order) eq 'ARRAY') {
2058: if (@{$code_order} > 0) {
2059: foreach my $item (@{$code_order}) {
2060: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2061: }
2062: }
2063: }
1.24 raeburn 2064: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2065: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2066: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2067: } else {
2068: $xlistinfo .= &mt('None');
2069: }
2070: $xlistinfo .= '</td></tr>';
1.4 raeburn 2071: }
2072: }
1.6 raeburn 2073: if ($xlistinfo eq '') {
2074: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2075: }
1.24 raeburn 2076: $section_values .= $xlistinfo;
1.4 raeburn 2077: }
1.24 raeburn 2078: $section_values .= '</table></td>';
1.4 raeburn 2079: }
2080:
2081: my %ctxt = &clone_text();
2082: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.13 raeburn 2083: if (($env{'form.clonecrs'} =~ /^$match_name$/) &&
2084: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.15 raeburn 2085: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2086: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
2087: if ($canclone) {
2088: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2089: $env{'form.clonecrs'},('description','internal.coursecode'));
2090: if (keys(%courseenv) > 0) {
2091: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2092: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2093: my $cloneinst = $courseenv{'internal.coursecode'};
2094: if ($cloneinst ne '') {
1.18 raeburn 2095: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 2096: } else {
1.18 raeburn 2097: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 2098: }
2099: $inst_values .= '</td><td>';
2100: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 2101: $inst_values .= $ctxt{'prd'};
1.15 raeburn 2102: } elsif ($env{'form.datemode'} eq 'shift') {
2103: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2104: } else {
2105: $inst_values .= $ctxt{'ncd'};
2106: }
2107: $inst_values .= '</td>';
2108: } else {
2109: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2110: }
2111: } else {
2112: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2113: }
1.4 raeburn 2114: } else {
2115: $inst_values .= '<td>'.&mt('None').'</td>';
2116: }
2117: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2118: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 2119: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2120: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2121: if ($accessend == 0) {
1.4 raeburn 2122: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2123: } else {
1.13 raeburn 2124: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 2125: }
2126:
2127: my $container = 'Course';
2128: if ($env{'form.crstype'} eq 'community') {
2129: $container = 'Community';
2130: }
2131:
2132: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2133: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2134: '</th>';
2135: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
2136: '<td>'.&Apache::lonnet::plaintext('cc',$container).'</td>'.
2137: '<td>'.&mt('None').'</td></tr>';
2138: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2139: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2140: if (ref($disallowed) eq 'ARRAY') {
2141: next if (grep(/^$i$/,@{$disallowed}));
2142: }
1.31 raeburn 2143: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2144: my @allsecs;
2145: foreach my $sec (@officialsecs) {
2146: next unless ($sec =~ /\w/);
2147: next if ($sec =~ /\W/);
2148: next if ($sec eq 'none');
2149: push(@allsecs,$sec);
2150: }
1.14 raeburn 2151: my $newsec = $env{'form.person_'.$i.'_newsec'};
2152: $newsec =~ s/^\s+//;
2153: $newsec =~s/\s+$//;
1.31 raeburn 2154: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2155: foreach my $sec (@newsecs) {
1.31 raeburn 2156: next unless ($sec =~ /\w/);
1.14 raeburn 2157: next if ($sec =~ /\W/);
1.31 raeburn 2158: next if ($sec eq 'none');
1.14 raeburn 2159: if ($sec ne '') {
2160: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2161: push(@allsecs,$sec);
2162: }
2163: }
2164: }
1.24 raeburn 2165: my $showsec;
1.14 raeburn 2166: if (@allsecs) {
2167: $showsec = join(', ',@allsecs);
2168: }
1.24 raeburn 2169: if ($showsec eq '') {
2170: $showsec = &mt('None');
2171: }
2172: if ($env{'form.person_'.$i.'_role'} eq 'cc') {
2173: $showsec = &mt('None');
2174: }
1.28 raeburn 2175: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2176: $personnel_values .=
1.13 raeburn 2177: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2178: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2179: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2180: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2181: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2182: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2183: }
2184: }
1.30 raeburn 2185: my $output;
2186: if (ref($disallowed) eq 'ARRAY') {
2187: if (@{$disallowed} > 0) {
2188: if (ref($disallowmsg) eq 'HASH') {
2189: $output = '<p class="LC_warning">'.
2190: &mt('Not all requested personnel could be included.').'<ul>';
2191: foreach my $item (@{$disallowed}) {
2192: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2193: }
2194: $output .= '</ul></p>';
2195: }
2196: }
2197: }
2198: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 2199: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 2200: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 2201: '<th>'.&mt('Name').'</th>'.
2202: '<th>'.&mt('Username:Domain').'</th>'.
2203: '<th>'.&mt('E-mail address').'</th>'.
2204: '</tr><tr>'."\n".
2205: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2206: '<td>'.$owneremail.'</td>'.
2207: '</tr></table>'."\n".
2208: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 2209: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 2210: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2211: '<tr>'.$inst_values.'</tr></table>'."\n".
2212: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2213: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 2214: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2215: '<tr>'.$enroll_values.'</tr></table>'."\n".
2216: &Apache::lonhtmlcommon::row_closure();
2217: if ($section_headers ne '') {
2218: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2219: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2220: '<tr>'.$section_values.'</tr></table>'."\n".
2221: &Apache::lonhtmlcommon::row_closure();
2222: }
2223: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2224: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2225: $personnel_values.'</table>'."\n".
2226: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 2227: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 2228: return $output;
2229: }
2230:
2231: sub dates_from_form {
2232: my ($startname,$endname) = @_;
2233: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2234: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 2235: if ($endname eq 'accessend') {
1.4 raeburn 2236: if (exists($env{'form.no_end_date'}) ) {
2237: $enddate = 0;
2238: }
2239: }
2240: return ($startdate,$enddate);
1.1 raeburn 2241: }
2242:
2243: sub courseinfo_form {
1.15 raeburn 2244: my ($dom,$formname,$crstype,$next) = @_;
1.32 raeburn 2245: my %lt = &Apache::lonlocal::texthash(
2246: official => 'You must provide a (brief) course description.',
2247: community => 'You must provide a (brief) community description.'
2248: );
2249: $lt{'unofficial'} = $lt{'official'};
1.15 raeburn 2250: my $js_validate = <<"ENDJS";
2251: <script type="text/javascript">
2252: // <![CDATA['
2253:
2254: function validateForm() {
2255: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.32 raeburn 2256: alert('$lt{$crstype}');
1.15 raeburn 2257: return;
2258: }
2259: nextPage(document.$formname,'$next');
2260: }
2261: // ]]
2262: </script>
2263:
2264: ENDJS
1.27 raeburn 2265: my $title = &mt('Brief Course Description');
2266: if ($crstype eq 'community') {
2267: $title = &mt('Brief Community Description');
2268: }
1.15 raeburn 2269: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2270: &Apache::lonhtmlcommon::row_headline().
1.34 ! raeburn 2271: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 2272: &Apache::lonhtmlcommon::row_closure(1).
2273: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.13 raeburn 2274: '<input type="text" size="40" name="cdescr" />';
2275: my ($home_server_pick,$numlib) =
2276: &Apache::loncommon::home_server_form_item($dom,'chome',
2277: 'default','hide');
2278: if ($numlib > 1) {
2279: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2280: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 2281: }
2282: $output .= $home_server_pick.
1.27 raeburn 2283: &Apache::lonhtmlcommon::row_closure().
2284: &Apache::lonhtmlcommon::row_headline().
1.34 ! raeburn 2285: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.&mt('Clone content and settings from an existing course?').'</h3>'.
1.13 raeburn 2286: &Apache::lonhtmlcommon::row_closure(1).
1.27 raeburn 2287: &clone_form($dom,$formname,$crstype).
2288: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1.1 raeburn 2289: return $output;
2290: }
2291:
2292: sub clone_form {
2293: my ($dom,$formname,$crstype) = @_;
2294: my $type = 'Course';
2295: if ($crstype eq 'community') {
2296: $type = 'Community';
2297: }
1.13 raeburn 2298: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').
2299: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 2300: my %lt = &clone_text();
1.2 raeburn 2301: my $output .=
2302: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.29 raeburn 2303: '<input type="text" size="25" name="clonecrs" value="" />'.
1.2 raeburn 2304: '</label>'.&Apache::lonhtmlcommon::row_closure(1).'<label>'.
2305: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'</label>'.
1.27 raeburn 2306: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2307: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2308: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2309: '</label><br /><label>'.
2310: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2311: '</label><br /><label>'.
2312: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2313: $lt{'shd'}.'</label>'.
2314: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 2315: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2316: return $output;
2317: }
2318:
1.16 raeburn 2319: sub clone_text {
1.4 raeburn 2320: return &Apache::lonlocal::texthash(
2321: 'cid' => 'Course ID',
2322: 'dmn' => 'Domain',
2323: 'dsh' => 'Date Shift',
2324: 'ncd' => 'Do not clone date parameters',
2325: 'prd' => 'Clone date parameters as-is',
2326: 'shd' => 'Shift date parameters by number of days',
2327: );
2328: }
2329:
1.1 raeburn 2330: sub coursecode_form {
1.2 raeburn 2331: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 2332: my $output;
1.2 raeburn 2333: my %rowtitle = (
2334: instcode => 'Course Category',
2335: crosslist => 'Cross Listed Course',
2336: );
1.34 ! raeburn 2337: my %helpitem = (
! 2338: instcode => 'Course_Request_Category',
! 2339: crosslist => 'Course_Request_Crosslist',
! 2340: );
1.1 raeburn 2341: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2342: (ref($cat_order))) {
1.2 raeburn 2343: my ($sel,$instsec,$lcsec);
2344: $sel = $context;
2345: if ($context eq 'crosslist') {
2346: $sel .= '_'.$num;
2347: $instsec = &mt('Institutional section').'<br />'.
2348: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2349: $lcsec = &mt('LON-CAPA section').'<br />'.
2350: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2351: }
1.1 raeburn 2352: if (@{$codetitles} > 0) {
2353: my $lastitem = pop(@{$codetitles});
1.2 raeburn 2354: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 2355: if (@{$codetitles} > 0) {
1.34 ! raeburn 2356: $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}).
1.2 raeburn 2357: '<table><tr>';
1.1 raeburn 2358: if ($context eq 'crosslist') {
1.2 raeburn 2359: $output .= '<td>'.&mt('Include?').'<br />'.
2360: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 2361: }
2362: foreach my $title (@{$codetitles}) {
2363: if (ref($cat_order->{$title}) eq 'ARRAY') {
2364: if (@{$cat_order->{$title}} > 0) {
2365: $output .= '<td align="center">'.$title.'<br />'."\n".
2366: '<select name="'.$sel.'_'.$title.'">'."\n".
2367: ' <option value="" selected="selected">'.
2368: &mt('Select').'</option>'."\n";
2369: foreach my $item (@{$cat_order->{$title}}) {
2370: my $longitem = $item;
2371: if (ref($cat_titles->{$title}) eq 'HASH') {
2372: if ($cat_titles->{$title}{$item} ne '') {
2373: $longitem = $cat_titles->{$title}{$item};
2374: }
2375: }
2376: $output .= '<option value="'.$item.'">'.$longitem.
2377: '</option>'."\n";
2378: }
2379: }
2380: $output .= '</select></td>'."\n";
2381: }
2382: }
2383: if ($context eq 'crosslist') {
2384: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 2385: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2386: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 2387: } else {
2388: $output .= '</tr></table>'.
2389: &Apache::lonhtmlcommon::row_closure().
2390: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2391: $lastinput;
2392: }
2393: } else {
2394: if ($context eq 'crosslist') {
2395: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 2396: '<table><tr>'.
2397: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2398: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2399: '</tr></table>';
1.1 raeburn 2400: } else {
2401: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2402: $lastinput;
2403: }
2404: }
1.2 raeburn 2405: $output .= &Apache::lonhtmlcommon::row_closure(1);
2406: push(@$codetitles,$lastitem);
2407: } elsif ($context eq 'crosslist') {
2408: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2409: '<table><tr><td align="center">'.
2410: '<span class="LC_nobreak">'.&mt('Include?').
2411: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2412: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2413: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2414: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2415: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2416: }
2417: }
2418: return $output;
2419: }
2420:
2421: sub get_course_dom {
2422: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 2423: if ($env{'form.showdom'} ne '') {
2424: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2425: return $env{'form.showdom'};
2426: }
2427: }
1.1 raeburn 2428: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.19 raeburn 2429: my ($types,$typename) = &course_types();
2430: if (ref($types) eq 'ARRAY') {
2431: foreach my $type (@{$types}) {
2432: if (&Apache::lonnet::usertools_access($env{'user.name'},
2433: $env{'user.domain'},$type,
2434: undef,'requestcourses')) {
2435: return $env{'user.domain'};
2436: }
2437: }
2438: my @possible_doms;
2439: foreach my $type (@{$types}) {
2440: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2441: if ($dom_str ne '') {
2442: my @domains = split(',',$dom_str);
2443: foreach my $entry (@domains) {
2444: my ($extdom,$extopt) = split(':',$entry);
2445: if ($extdom eq $env{'request.role.domain'}) {
2446: return $extdom;
2447: }
2448: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2449: push(@possible_doms,$extdom);
2450: }
2451: }
2452: }
2453: }
2454: if (@possible_doms) {
2455: @possible_doms = sort(@possible_doms);
2456: return $possible_doms[0];
2457: }
2458: }
1.1 raeburn 2459: $codedom = $env{'user.domain'};
2460: if ($env{'request.role.domain'} ne '') {
2461: $codedom = $env{'request.role.domain'};
2462: }
2463: }
2464: return $codedom;
2465: }
2466:
2467: sub display_navbuttons {
1.31 raeburn 2468: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 2469: $r->print('<div class="LC_navbuttons">');
2470: if ($prev) {
1.16 raeburn 2471: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 2472: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 2473: (' 'x3));
1.1 raeburn 2474: } elsif ($prevtext) {
1.16 raeburn 2475: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2476: 'onclick="javascript:history.back()"/>'.(' 'x3));
2477: }
2478: if ($state eq 'details') {
2479: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 2480: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 2481: ')" />');
1.1 raeburn 2482: }
1.31 raeburn 2483: my $gotnext;
1.15 raeburn 2484: if ($state eq 'courseinfo') {
1.16 raeburn 2485: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2486: 'onclick="javascript:validateForm();" />');
1.31 raeburn 2487: $gotnext = 1;
2488: } elsif ($state eq 'enrollment') {
2489: if (($env{'form.crstype'} eq 'official') &&
2490: (&Apache::lonnet::auto_run('',$dom))) {
2491: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2492: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
2493: $gotnext = 1;
2494: }
2495: } elsif ($state eq 'personnel') {
2496: if ($env{'form.persontotal'} > 0) {
2497: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2498: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
2499: $gotnext = 1;
2500: }
2501: }
2502: unless ($gotnext) {
2503: if ($next) {
2504: $r->print('
2505: <input type="button" name="next" value="'.$nexttext.'" '.
2506: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
2507: }
1.1 raeburn 2508: }
2509: $r->print('</div>');
2510: }
2511:
2512: sub print_request_outcome {
1.10 raeburn 2513: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 2514: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 2515: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 2516: my $sectotal = $env{'form.sectotal'};
2517: my $crosslisttotal = 0;
1.10 raeburn 2518: $cnum = $env{'form.cnum'};
1.8 raeburn 2519: unless ($cnum =~ /^$match_courseid$/) {
2520: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2521: return $output;
2522: }
1.11 raeburn 2523:
1.10 raeburn 2524: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 2525: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2526: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2527: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2528: }
2529: }
1.10 raeburn 2530: $now = time;
2531: $crstype = $env{'form.crstype'};
1.17 raeburn 2532: my @instsections;
1.8 raeburn 2533: if ($crstype eq 'official') {
2534: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 2535: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 2536: }
1.10 raeburn 2537: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2538: if ($env{'form.sec_'.$i}) {
2539: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 2540: my $sec = $env{'form.secnum_'.$i};
2541: $sections{$i}{'inst'} = $sec;
2542: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2543: push(@instsections,$sec);
2544: }
1.13 raeburn 2545: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 2546: }
2547: }
2548: }
2549: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2550: if ($env{'form.crosslist_'.$i}) {
2551: my $xlistinfo = '';
2552: if (ref($code_order) eq 'ARRAY') {
2553: if (@{$code_order} > 0) {
2554: foreach my $item (@{$code_order}) {
2555: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2556: }
2557: }
2558: }
1.22 raeburn 2559: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 2560: if ($xlistinfo ne '') {
2561: $crosslisttotal ++;
2562: }
1.22 raeburn 2563: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 2564: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 2565: }
2566: }
1.14 raeburn 2567: } else {
2568: $enrollstart = '';
2569: $enrollend = '';
1.10 raeburn 2570: }
2571: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2572: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 2573: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 2574: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
2575: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 2576: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
2577: $personnel{$uname.':'.$udom} = {
2578: firstname => $env{'form.person_'.$i.'_firstname'},
2579: lastname => $env{'form.person_'.$i.'_lastname'},
2580: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
2581: };
2582: }
2583: my $role = $env{'form.person_'.$i.'_role'};
2584: unless ($role eq '') {
1.16 raeburn 2585: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 2586: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
2587: unless (grep(/^\Q$role\E$/,@curr_roles)) {
2588: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
2589: }
2590: } else {
2591: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
2592: }
2593: if ($role eq 'cc') {
2594: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
2595: } else {
1.14 raeburn 2596: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 2597: my @allsecs;
2598: foreach my $sec (@currsec) {
2599: next unless ($sec =~ /\w/);
2600: next if ($sec =~ /\W/);
2601: next if ($sec eq 'none');
2602: push(@allsecs,$sec);
2603: }
1.14 raeburn 2604: my $newsec = $env{'form.person_'.$i.'_newsec'};
2605: $newsec =~ s/^\s+//;
2606: $newsec =~s/\s+$//;
2607: my @newsecs = split(/[\s,;]+/,$newsec);
2608: foreach my $sec (@newsecs) {
2609: next if ($sec =~ /\W/);
1.31 raeburn 2610: next if ($sec eq 'none');
1.14 raeburn 2611: if ($sec ne '') {
1.31 raeburn 2612: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2613: push(@allsecs,$sec);
1.13 raeburn 2614: }
2615: }
2616: }
1.31 raeburn 2617: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 2618: }
2619: }
1.10 raeburn 2620: } else {
2621: push(@missingdom,$uname.':'.$udom);
2622: }
2623: } else {
2624: push(@baduname,$uname.':'.$udom);
2625: }
1.8 raeburn 2626: }
1.13 raeburn 2627: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 2628: my $autodrops = 0;
2629: if ($env{'form.autodrops'}) {
2630: $autodrops = $env{'form.autodrops'};
2631: }
2632: my $autoadds = 0;
2633: if ($env{'form.autoadds'}) {
2634: $autodrops = $env{'form.autoadds'};
2635: }
2636: if ($env{'form.autoadds'}) {
2637: $autodrops = $env{'form.autoadds'};
2638: }
2639: my $instcode = '';
2640: if (exists($env{'form.instcode'})) {
2641: $instcode = $env{'form.instcode'};
2642: }
1.15 raeburn 2643: my $clonecrs = '';
2644: my $clonedom = '';
2645: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
2646: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 2647: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2648: $env{'form.clonedom'});
1.15 raeburn 2649: if ($clonehome ne 'no_host') {
1.16 raeburn 2650: my $canclone =
2651: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
2652: $env{'user.domain'},$env{'form.clonecrs'}, $env{'form.clonedom'});
1.15 raeburn 2653: if ($canclone) {
2654: $clonecrs = $env{'form.clonecrs'};
2655: $clonedom = $env{'form.clonedom'};
2656: }
2657: }
2658: }
1.8 raeburn 2659: my $details = {
1.10 raeburn 2660: owner => $env{'user.name'},
2661: domain => $env{'user.domain'},
2662: cdom => $dom,
1.11 raeburn 2663: cnum => $cnum,
1.13 raeburn 2664: coursehome => $env{'form.chome'},
2665: cdescr => $env{'form.cdescr'},
1.10 raeburn 2666: crstype => $env{'form.crstype'},
1.14 raeburn 2667: instcode => $instcode,
1.15 raeburn 2668: clonedom => $clonedom,
2669: clonecrs => $clonecrs,
1.10 raeburn 2670: datemode => $env{'form.datemode'},
1.14 raeburn 2671: dateshift => $env{'form.dateshift'},
2672: sectotal => $sectotal,
1.10 raeburn 2673: sections => \%sections,
1.14 raeburn 2674: crosslisttotal => $crosslisttotal,
1.13 raeburn 2675: crosslists => \%crosslistings,
1.14 raeburn 2676: autoadds => $autoadds,
2677: autodrops => $autodrops,
1.13 raeburn 2678: enrollstart => $enrollstart,
2679: enrollend => $enrollend,
2680: accessstart => $accessstart,
2681: accessend => $accessend,
1.10 raeburn 2682: personnel => \%personnel,
1.8 raeburn 2683: };
1.27 raeburn 2684: my (@inststatuses,$storeresult,$creationresult);
1.9 raeburn 2685: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 2686: if ($val eq '') {
2687: if ($crstype eq 'official') {
1.19 raeburn 2688: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 2689: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 2690: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 2691: } elsif ($crstype eq 'community') {
2692: $output = &mt('You are not permitted to request creation of communities');
2693: } else {
2694: $output = &mt('Unrecognized course type: [_1]',$crstype);
2695: }
1.27 raeburn 2696: $storeresult = 'notpermitted';
1.8 raeburn 2697: } else {
1.14 raeburn 2698: my ($disposition,$message,$reqstatus);
1.8 raeburn 2699: my %reqhash = (
1.14 raeburn 2700: reqtime => $now,
1.10 raeburn 2701: crstype => $crstype,
2702: details => $details,
1.8 raeburn 2703: );
2704: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 2705: my $validationerror;
1.10 raeburn 2706: if ($val eq 'autolimit=') {
2707: $disposition = 'process';
2708: } elsif ($val =~ /^autolimit=(\d+)$/) {
2709: my $limit = $1;
1.8 raeburn 2710: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 2711: $dom,$crstype,$limit,\$message);
1.8 raeburn 2712: } elsif ($val eq 'validate') {
1.21 raeburn 2713: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 2714: if (@inststatuses > 0) {
2715: $inststatuslist = join(',',@inststatuses);
2716: }
2717: my $instseclist;
2718: if (@instsections > 0) {
2719: $instseclist = join(',',@instsections);
2720: }
1.21 raeburn 2721: $validationchk =
2722: &Apache::lonnet::auto_courserequest_validation($dom,
2723: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2724: $inststatuslist,$instcode,$instseclist);
2725: if ($validationchk =~ /:/) {
2726: ($validation,$message) = split(':',$validationchk);
2727: } else {
2728: $validation = $validationchk;
2729: }
2730: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 2731: $disposition = 'approval';
2732: $validationerror = $1;
1.23 raeburn 2733: } else {
2734: $disposition = $validation;
1.17 raeburn 2735: }
1.8 raeburn 2736: } else {
2737: $disposition = 'approval';
2738: }
1.14 raeburn 2739: $reqhash{'disposition'} = $disposition;
2740: $reqstatus = $disposition;
1.16 raeburn 2741: my ($modified,$queued);
1.8 raeburn 2742: if ($disposition eq 'rejected') {
2743: $output = &mt('Your course request was rejected.');
2744: if ($message) {
2745: $output .= '<div class="LC_warning">'.$message.'</div>';
2746: }
1.27 raeburn 2747: $storeresult = 'rejected';
1.8 raeburn 2748: } elsif ($disposition eq 'process') {
1.14 raeburn 2749: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2750: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
2751: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.8 raeburn 2752: my $type = 'Course';
2753: if ($crstype eq 'community') {
2754: $type = 'Community';
2755: }
2756: foreach my $role (@roles) {
2757: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2758: }
1.14 raeburn 2759: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2760: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2761: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2762: if ($result eq 'created') {
1.8 raeburn 2763: $disposition = 'created';
1.14 raeburn 2764: $reqstatus = 'created';
1.28 raeburn 2765: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
2766: \%longroles);
2767: $output = '<p>'.&mt('Your course request has been processed and the course has been created.').
2768: '<br />'.$role_result.'</p>';
1.27 raeburn 2769: $creationresult = 'created';
1.8 raeburn 2770: } else {
1.14 raeburn 2771: $output = '<span class="LC_error">'.
2772: &mt('An error occurred when processing your course request.').
2773: '<br />'.
2774: &mt('You may want to review the request details and submit the request again.').
2775: '</span>';
1.27 raeburn 2776: $creationresult = 'error';
1.8 raeburn 2777: }
2778: } else {
2779: my $requestid = $cnum.'_'.$disposition;
2780: my $request = {
2781: $requestid => {
2782: timestamp => $now,
2783: crstype => $crstype,
2784: ownername => $env{'user.name'},
2785: ownerdom => $env{'user.domain'},
1.13 raeburn 2786: description => $env{'form.cdescr'},
1.8 raeburn 2787: },
2788: };
1.16 raeburn 2789: my $statuskey = 'status:'.$dom.':'.$cnum;
2790: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2791: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 2792: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 2793: $modified = 1;
1.25 raeburn 2794: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2795: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2796: [$cnum.'_approval',
2797: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 2798: if (($queuehash{$cnum.'_approval'} ne '') ||
2799: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 2800: $queued = 1;
2801: }
2802: }
2803: unless ($queued) {
2804: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2805: $dom);
2806: if ($putresult eq 'ok') {
2807: $output = &mt('Your course request has been recorded.').'<br />'.
2808: ¬ification_information($disposition,$req_notifylist,
2809: $cnum,$now);
1.8 raeburn 2810: } else {
1.16 raeburn 2811: $reqstatus = 'domainerror';
2812: $reqhash{'disposition'} = $disposition;
2813: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2814: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 2815: }
2816: }
2817: }
1.27 raeburn 2818: my ($statusresult);
1.10 raeburn 2819: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2820: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
2821: 'courserequests');
1.14 raeburn 2822: if ($storeresult eq 'ok') {
2823: my %status = (
2824: 'status:'.$dom.':'.$cnum => $reqstatus,
2825: );
1.27 raeburn 2826: $statusresult = &Apache::lonnet::put('courserequests',\%status);
1.14 raeburn 2827: }
1.10 raeburn 2828: } else {
2829: $storeresult = 'error: invalid requestkey format';
2830: }
1.8 raeburn 2831: if ($storeresult ne 'ok') {
1.13 raeburn 2832: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
2833: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 2834: } elsif ($statusresult ne 'ok') {
1.28 raeburn 2835: $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 2836: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 2837: }
1.16 raeburn 2838: if ($modified && $queued && $storeresult eq 'ok') {
2839: $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
2840: ¬ification_information($disposition,$req_notifylist,$cnum,$now);
2841: }
1.17 raeburn 2842: if ($validationerror ne '') {
1.19 raeburn 2843: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17 raeburn 2844: }
1.16 raeburn 2845: }
1.27 raeburn 2846: if ($creationresult ne '') {
2847: return ($creationresult,$output);
2848: } else {
2849: return ($storeresult,$output);
2850: }
1.16 raeburn 2851: }
2852:
1.28 raeburn 2853: sub update_requestors_roles {
2854: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
2855: my $now = time;
2856: my ($active,$future,$numactive,$numfuture,$output);
2857: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
2858: if (ref($details) eq 'HASH') {
2859: if (ref($details->{'personnel'}) eq 'HASH') {
2860: if (ref($details->{'personnel'}{$owner}) eq 'HASH') {
2861: my @roles;
2862: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
2863: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
2864: unless (grep(/^cc$/,@roles)) {
2865: push(@roles,'cc');
2866: }
2867: } else {
2868: @roles = ('cc');
2869: }
2870: foreach my $role (@roles) {
2871: my $start = $now;
2872: my $end = '0';
2873: if ($role eq 'st') {
2874: if ($details->{'accessstart'} ne '') {
2875: $start = $details->{'accessstart'};
2876: }
2877: if ($details->{'accessend'} ne '') {
2878: $end = $details->{'accessend'};
2879: }
2880: }
2881: my @usecs;
2882: if ($role ne 'cc') {
2883: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
2884: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
2885: }
2886: }
2887: if ($role eq 'st') {
2888: if (@usecs > 1) {
2889: my $firstsec = $usecs[0];
2890: @usecs = ($firstsec);
2891: }
2892: }
2893: if (@usecs == 0) {
2894: push(@usecs,'');
2895: }
2896: foreach my $usec (@usecs) {
2897: my (%userroles,%newrole,%newgroups,$spec,$area);
2898: my $area = '/'.$dom.'/'.$cnum;
2899: my $spec = $role.'.'.$area;
2900: if ($usec ne '') {
2901: $spec .= '/'.$usec;
2902: $area .= '/'.$usec;
2903: }
2904: if ($role =~ /^cr\//) {
2905: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
2906: $cnum,$spec,$area);
2907: } else {
2908: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
2909: $spec,$cnum,$area);
2910: }
2911: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
2912: \%newgroups);
2913: $userroles{'user.role.'.$spec} = $start.'.'.$end;
2914: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
2915: if (($end == 0) || ($end > $now)) {
2916: my $showrole = $role;
2917: if ($role =~ /^cr\//) {
2918: $showrole = &Apache::lonnet::plaintext($role,$crstype);
2919: } elsif (ref($longroles) eq 'HASH') {
2920: if ($longroles->{$role} ne '') {
2921: $showrole = $longroles->{$role};
2922: }
2923: }
2924: if ($start <= $now) {
2925: $active .= '<li><a href="/adm/roles?selectrole=1&'. $spec.'=1">'.$showrole;
2926: if ($usec ne '') {
2927: $active .= ' - '.&mt('section:').' '.$usec;
2928: }
2929: $active .= '</a></li>';
2930: $numactive ++;
2931: } else {
2932: $future .= '<li>'.$showrole;
2933: if ($usec ne '') {
2934: $future .= ' - '.&mt('section:').' '.$usec;
2935: }
2936: $future .= '</li>';
2937: $numfuture ++;
2938: }
2939: }
2940: }
2941: }
2942: }
2943: }
2944: }
2945: if ($active) {
2946: if ($numactive == 1) {
2947: $output = &mt('Use the following link to enter the course:');
2948: } else {
2949: $output = &mt('Use the following links to your new roles to enter the course:');
2950: }
2951: $output .= ' <ul>'.$active.'</ul><br />';
2952: }
2953: if ($future) {
2954: $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'})).
2955: ' <ul>'.$future.'</ul>';
2956: }
2957: return $output;
2958: }
2959:
1.16 raeburn 2960: sub notification_information {
2961: my ($disposition,$req_notifylist,$cnum,$now) = @_;
2962: my %emails = &Apache::loncommon::getemails();
2963: my $address;
2964: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
2965: $address = $emails{'permanentemail'};
2966: if ($address eq '') {
2967: $address = $emails{'notification'};
2968: }
2969: }
2970: my $output;
2971: if ($disposition eq 'approval') {
2972: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
2973: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
2974: if ($address ne '') {
2975: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
2976: }
2977: if ($req_notifylist) {
2978: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
2979: $env{'user.domain'});
2980: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
2981: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
2982: }
1.17 raeburn 2983: } elsif ($disposition eq 'pending') {
1.16 raeburn 2984: $output .= '<div class="LC_info">'.
2985: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
2986: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
2987: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
2988: '</div>';
1.17 raeburn 2989: } else {
2990: $output .= '<div class="LC_warning">'.
2991: &mt('Your request status is: [_1].',$disposition).
2992: '</div>'
1.8 raeburn 2993: }
2994: return $output;
2995: }
2996:
2997: sub get_processtype {
1.9 raeburn 2998: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
2999: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 3000: my (%userenv,%settings,$val);
1.19 raeburn 3001: my @options = ('autolimit','validate','approval');
1.8 raeburn 3002: if ($dom eq $env{'user.domain'}) {
3003: %userenv =
3004: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
3005: 'requestcourses.'.$crstype,'inststatus');
3006: if ($userenv{'requestcourses.'.$crstype}) {
3007: $val = $userenv{'requestcourses.'.$crstype};
3008: @{$inststatuses} = ('_custom_');
3009: } else {
3010: my ($task,%alltasks);
1.9 raeburn 3011: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
3012: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 3013: if (ref($settings{$crstype}) eq 'HASH') {
1.23 raeburn 3014: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1.8 raeburn 3015: $val = $settings{$crstype}{'_LC_adv'};
3016: @{$inststatuses} = ('_LC_adv_');
3017: } else {
3018: if ($userenv{'inststatus'} ne '') {
3019: @{$inststatuses} = split(',',$userenv{'inststatus'});
3020: } else {
1.13 raeburn 3021: @{$inststatuses} = ('default');
1.8 raeburn 3022: }
3023: foreach my $status (@{$inststatuses}) {
3024: if (exists($settings{$crstype}{$status})) {
3025: my $value = $settings{$crstype}{$status};
3026: next unless ($value);
3027: unless (exists($alltasks{$value})) {
3028: if (ref($alltasks{$value}) eq 'ARRAY') {
3029: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
3030: push(@{$alltasks{$value}},$status);
3031: }
3032: } else {
3033: @{$alltasks{$value}} = ($status);
3034: }
3035: }
3036: }
3037: }
3038: my $maxlimit = 0;
1.13 raeburn 3039:
1.8 raeburn 3040: foreach my $key (sort(keys(%alltasks))) {
3041: if ($key =~ /^autolimit=(\d*)$/) {
3042: if ($1 eq '') {
3043: $val ='autolimit=';
3044: last;
3045: } elsif ($1 > $maxlimit) {
3046: $maxlimit = $1;
3047: }
3048: }
3049: }
3050: if ($maxlimit) {
3051: $val = 'autolimit='.$maxlimit;
3052: } else {
3053: foreach my $option (@options) {
3054: if ($alltasks{$option}) {
3055: $val = $option;
3056: last;
3057: }
3058: }
3059: }
3060: }
3061: }
3062: }
3063: }
3064: } else {
3065: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
3066: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19 raeburn 3067: if ($userenv{'reqcrsotherdom.'.$crstype}) {
3068: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
3069: my $optregex = join('|',@options);
3070: foreach my $item (@doms) {
3071: my ($extdom,$extopt) = split(':',$item);
3072: if ($extdom eq $dom) {
3073: if ($extopt =~ /^($optregex)(=?\d*)$/) {
3074: $val = $1.$2;
3075: }
3076: last;
3077: }
1.8 raeburn 3078: }
3079: @{$inststatuses} = ('_external_');
3080: }
3081: }
3082: return $val;
3083: }
3084:
3085: sub check_autolimit {
1.10 raeburn 3086: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3087: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
3088: 'userroles',['active','future'],['cc'],[$dom]);
3089: my ($types,$typename) = &course_types();
3090: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
3091: my %count;
3092: if (ref($types) eq 'ARRAY') {
3093: foreach my $type (@{$types}) {
3094: $count{$type} = 0;
3095: }
3096: }
3097: foreach my $key (keys(%requests)) {
3098: my ($cdom,$cnum) = split('_',$key);
3099: if (exists($crsroles{$cnum.':'.$cdom.':cc'})) {
3100: if (ref($requests{$key}) eq 'HASH') {
3101: my $type = $requests{$key}{'crstype'};
3102: if ($type =~ /^official|unofficial|community$/) {
3103: $count{$type} ++;
3104: }
3105: }
3106: }
3107: }
3108: if ($count{$crstype} < $limit) {
3109: return 'process';
3110: } else {
3111: if (ref($typename) eq 'HASH') {
3112: $$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);
3113: }
3114: return 'rejected';
3115: }
1.1 raeburn 3116: return;
3117: }
3118:
1.2 raeburn 3119: sub retrieve_settings {
1.26 raeburn 3120: my ($dom,$cnum,$udom,$uname) = @_;
3121: if ($udom eq '' || $uname eq '') {
3122: $udom = $env{'user.domain'};
3123: $uname = $env{'user.name'};
3124: }
3125: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 3126: if ($result eq 'ok') {
1.26 raeburn 3127: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 3128: $env{'form.chome'} = $reqinfo{'coursehome'};
3129: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3130: $env{'form.crstype'} = $reqinfo{'crstype'};
3131: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3132: &generate_date_items($reqinfo{'accessend'},'accessend');
3133: if ($reqinfo{'accessend'} == 0) {
3134: $env{'form.no_end_date'} = 1;
3135: }
3136: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3137: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3138: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3139: }
3140: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3141: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3142: $env{'form.datemode'} = $reqinfo{'datemode'};
3143: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3144: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
3145: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3146: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3147: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3148: $env{'form.autdrops'} = $reqinfo{'autodrops'};
3149: $env{'form.instcode'} = $reqinfo{'instcode'};
1.24 raeburn 3150: my $crscode = {
3151: $cnum => $reqinfo{'instcode'},
3152: };
3153: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16 raeburn 3154: }
3155: my @currsec;
3156: if (ref($reqinfo{'sections'}) eq 'HASH') {
3157: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3158: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 3159: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 3160: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 3161: $env{'form.sec_'.$i} = '1';
1.16 raeburn 3162: if (!grep(/^\Q$sec\E$/,@currsec)) {
3163: push(@currsec,$sec);
3164: }
3165: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3166: }
3167: }
3168: }
1.24 raeburn 3169: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3170: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3171: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3172: $env{'form.crosslist_'.$i} = '1';
3173: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3174: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3175: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3176: my $key = $cnum.$i;
3177: my $crscode = {
3178: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3179: };
3180: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3181: }
1.16 raeburn 3182: }
3183: }
3184: }
3185: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3186: my $i = 0;
3187: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3188: my ($uname,$udom) = split(':',$user);
3189: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3190: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3191: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3192: $env{'form.person_'.$i.'_role'} = $role;
3193: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3194: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3195: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3196: $env{'form.person_'.$i.'_uname'} = $uname;
3197: $env{'form.person_'.$i.'_dom'} = $udom;
3198: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3199: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3200: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3201: my @newsecs;
3202: if (@usecs > 0) {
3203: foreach my $sec (@usecs) {
3204: if (grep(/^\Q$sec\E/,@currsec)) {
3205: $env{'form.person_'.$i.'_sec'} = $sec;
3206: } else {
1.20 raeburn 3207: push(@newsecs,$sec);
1.16 raeburn 3208: }
3209: }
3210: }
3211: if (@newsecs > 0) {
3212: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3213: }
3214: }
3215: }
3216: $i ++;
3217: }
3218: }
3219: }
3220: }
3221: $env{'form.persontotal'} = $i;
3222: }
3223: }
3224: }
3225: return $result;
3226: }
3227:
3228: sub get_request_settings {
1.26 raeburn 3229: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 3230: my $requestkey = $dom.'_'.$cnum;
3231: my ($result,%reqinfo);
3232: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 3233: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 3234: my $disposition = $history{'disposition'};
3235: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3236: if (ref($history{'details'}) eq 'HASH') {
3237: %reqinfo = %{$history{'details'}};
3238: $result = 'ok';
3239: } else {
3240: $result = 'nothash';
3241: }
3242: } else {
3243: $result = 'notqueued';
3244: }
3245: } else {
3246: $result = 'invalid';
3247: }
3248: return ($result,%reqinfo);
3249: }
1.2 raeburn 3250:
1.16 raeburn 3251: sub extract_instcode {
1.24 raeburn 3252: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 3253: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 3254: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3255: \@codetitles,\%cat_titles,
3256: \%cat_order) eq 'ok') {
3257: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 3258: if (@codetitles > 0) {
3259: my $sel = $element;
3260: if ($element eq 'crosslist') {
3261: $sel .= '_'.$counter;
3262: }
3263: foreach my $title (@codetitles) {
1.24 raeburn 3264: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 3265: }
3266: }
3267: }
3268: }
3269: return;
1.2 raeburn 3270: }
3271:
1.16 raeburn 3272: sub generate_date_items {
3273: my ($currentval,$item) = @_;
3274: if ($currentval =~ /\d+/) {
3275: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3276: &Apache::lonhtmlcommon::get_timedates($currentval);
3277: $env{'form.'.$item.'_day'} = $mday;
3278: $env{'form.'.$item.'_month'} = $month+1;
3279: $env{'form.'.$item.'_year'} = $year;
3280: }
3281: return;
1.2 raeburn 3282: }
3283:
1.1 raeburn 3284: 1;
3285:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>