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