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