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