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