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