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