Annotation of loncom/interface/lonrequestcourse.pm, revision 1.41
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.41 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.40 2009/11/18 19:15:44 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:
1.8 raeburn 1699: my $type = 'Course';
1700: if ($crstype eq 'community') {
1701: $type = 'Community';
1702: }
1.41 ! raeburn 1703: my $roleoptions;
! 1704: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
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';
1.41 ! raeburn 2220: my $ccrole = 'cc';
1.4 raeburn 2221: if ($env{'form.crstype'} eq 'community') {
2222: $container = 'Community';
1.41 ! raeburn 2223: $ccrole = 'co';
1.4 raeburn 2224: }
2225:
2226: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2227: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2228: '</th>';
1.41 ! raeburn 2229:
1.4 raeburn 2230: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41 ! raeburn 2231: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4 raeburn 2232: '<td>'.&mt('None').'</td></tr>';
2233: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2234: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2235: if (ref($disallowed) eq 'ARRAY') {
2236: next if (grep(/^$i$/,@{$disallowed}));
2237: }
1.31 raeburn 2238: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2239: my @allsecs;
2240: foreach my $sec (@officialsecs) {
2241: next unless ($sec =~ /\w/);
2242: next if ($sec =~ /\W/);
2243: next if ($sec eq 'none');
2244: push(@allsecs,$sec);
2245: }
1.14 raeburn 2246: my $newsec = $env{'form.person_'.$i.'_newsec'};
2247: $newsec =~ s/^\s+//;
2248: $newsec =~s/\s+$//;
1.31 raeburn 2249: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2250: foreach my $sec (@newsecs) {
1.31 raeburn 2251: next unless ($sec =~ /\w/);
1.14 raeburn 2252: next if ($sec =~ /\W/);
1.31 raeburn 2253: next if ($sec eq 'none');
1.14 raeburn 2254: if ($sec ne '') {
2255: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2256: push(@allsecs,$sec);
2257: }
2258: }
2259: }
1.24 raeburn 2260: my $showsec;
1.14 raeburn 2261: if (@allsecs) {
2262: $showsec = join(', ',@allsecs);
2263: }
1.24 raeburn 2264: if ($showsec eq '') {
2265: $showsec = &mt('None');
2266: }
1.41 ! raeburn 2267: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24 raeburn 2268: $showsec = &mt('None');
2269: }
1.28 raeburn 2270: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2271: $personnel_values .=
1.13 raeburn 2272: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2273: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2274: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2275: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2276: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2277: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2278: }
2279: }
1.30 raeburn 2280: my $output;
2281: if (ref($disallowed) eq 'ARRAY') {
2282: if (@{$disallowed} > 0) {
2283: if (ref($disallowmsg) eq 'HASH') {
2284: $output = '<p class="LC_warning">'.
2285: &mt('Not all requested personnel could be included.').'<ul>';
2286: foreach my $item (@{$disallowed}) {
2287: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2288: }
2289: $output .= '</ul></p>';
2290: }
2291: }
2292: }
2293: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 2294: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 2295: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 2296: '<th>'.&mt('Name').'</th>'.
2297: '<th>'.&mt('Username:Domain').'</th>'.
2298: '<th>'.&mt('E-mail address').'</th>'.
2299: '</tr><tr>'."\n".
2300: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2301: '<td>'.$owneremail.'</td>'.
2302: '</tr></table>'."\n".
2303: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 2304: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 2305: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2306: '<tr>'.$inst_values.'</tr></table>'."\n".
2307: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2308: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 2309: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2310: '<tr>'.$enroll_values.'</tr></table>'."\n".
2311: &Apache::lonhtmlcommon::row_closure();
2312: if ($section_headers ne '') {
2313: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2314: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2315: '<tr>'.$section_values.'</tr></table>'."\n".
2316: &Apache::lonhtmlcommon::row_closure();
2317: }
2318: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2319: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2320: $personnel_values.'</table>'."\n".
2321: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 2322: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 2323: return $output;
2324: }
2325:
2326: sub dates_from_form {
2327: my ($startname,$endname) = @_;
2328: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2329: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 2330: if ($endname eq 'accessend') {
1.4 raeburn 2331: if (exists($env{'form.no_end_date'}) ) {
2332: $enddate = 0;
2333: }
2334: }
2335: return ($startdate,$enddate);
1.1 raeburn 2336: }
2337:
2338: sub courseinfo_form {
1.36 raeburn 2339: my ($dom,$formname,$crstype,$next,$description) = @_;
1.32 raeburn 2340: my %lt = &Apache::lonlocal::texthash(
2341: official => 'You must provide a (brief) course description.',
2342: community => 'You must provide a (brief) community description.'
2343: );
2344: $lt{'unofficial'} = $lt{'official'};
1.15 raeburn 2345: my $js_validate = <<"ENDJS";
2346: <script type="text/javascript">
2347: // <![CDATA['
2348:
2349: function validateForm() {
2350: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.32 raeburn 2351: alert('$lt{$crstype}');
1.15 raeburn 2352: return;
2353: }
2354: nextPage(document.$formname,'$next');
2355: }
2356: // ]]
2357: </script>
2358:
2359: ENDJS
1.27 raeburn 2360: my $title = &mt('Brief Course Description');
1.40 raeburn 2361: my $clonetitle = &mt('Clone content and settings from an existing course?');
1.27 raeburn 2362: if ($crstype eq 'community') {
2363: $title = &mt('Brief Community Description');
1.40 raeburn 2364: $clonetitle = &mt('Clone content and settings from an existing community?');
1.27 raeburn 2365: }
1.15 raeburn 2366: my $output .= $js_validate."\n".'<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2367: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2368: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 2369: &Apache::lonhtmlcommon::row_closure(1).
2370: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.36 raeburn 2371: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.13 raeburn 2372: my ($home_server_pick,$numlib) =
2373: &Apache::loncommon::home_server_form_item($dom,'chome',
2374: 'default','hide');
2375: if ($numlib > 1) {
2376: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2377: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 2378: }
2379: $output .= $home_server_pick.
1.27 raeburn 2380: &Apache::lonhtmlcommon::row_closure().
2381: &Apache::lonhtmlcommon::row_headline().
1.40 raeburn 2382: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.'</h3>'.
1.13 raeburn 2383: &Apache::lonhtmlcommon::row_closure(1).
1.27 raeburn 2384: &clone_form($dom,$formname,$crstype).
2385: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n";
1.1 raeburn 2386: return $output;
2387: }
2388:
2389: sub clone_form {
2390: my ($dom,$formname,$crstype) = @_;
2391: my $type = 'Course';
2392: if ($crstype eq 'community') {
2393: $type = 'Community';
2394: }
1.35 raeburn 2395: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').' '.
1.13 raeburn 2396: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 2397: my %lt = &clone_text();
1.2 raeburn 2398: my $output .=
2399: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.29 raeburn 2400: '<input type="text" size="25" name="clonecrs" value="" />'.
1.35 raeburn 2401: '</label>'.&Apache::lonhtmlcommon::row_closure(1).
2402: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
1.27 raeburn 2403: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2404: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2405: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2406: '</label><br /><label>'.
2407: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2408: '</label><br /><label>'.
2409: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2410: $lt{'shd'}.'</label>'.
2411: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 2412: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2413: return $output;
2414: }
2415:
1.16 raeburn 2416: sub clone_text {
1.4 raeburn 2417: return &Apache::lonlocal::texthash(
2418: 'cid' => 'Course ID',
2419: 'dmn' => 'Domain',
2420: 'dsh' => 'Date Shift',
2421: 'ncd' => 'Do not clone date parameters',
2422: 'prd' => 'Clone date parameters as-is',
2423: 'shd' => 'Shift date parameters by number of days',
2424: );
2425: }
2426:
1.1 raeburn 2427: sub coursecode_form {
1.2 raeburn 2428: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 2429: my $output;
1.2 raeburn 2430: my %rowtitle = (
2431: instcode => 'Course Category',
2432: crosslist => 'Cross Listed Course',
2433: );
1.34 raeburn 2434: my %helpitem = (
2435: instcode => 'Course_Request_Category',
2436: crosslist => 'Course_Request_Crosslist',
2437: );
1.1 raeburn 2438: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2439: (ref($cat_order))) {
1.2 raeburn 2440: my ($sel,$instsec,$lcsec);
2441: $sel = $context;
2442: if ($context eq 'crosslist') {
2443: $sel .= '_'.$num;
2444: $instsec = &mt('Institutional section').'<br />'.
2445: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2446: $lcsec = &mt('LON-CAPA section').'<br />'.
2447: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2448: }
1.1 raeburn 2449: if (@{$codetitles} > 0) {
2450: my $lastitem = pop(@{$codetitles});
1.2 raeburn 2451: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 2452: if (@{$codetitles} > 0) {
1.34 raeburn 2453: $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}).
1.2 raeburn 2454: '<table><tr>';
1.1 raeburn 2455: if ($context eq 'crosslist') {
1.2 raeburn 2456: $output .= '<td>'.&mt('Include?').'<br />'.
2457: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 2458: }
2459: foreach my $title (@{$codetitles}) {
2460: if (ref($cat_order->{$title}) eq 'ARRAY') {
2461: if (@{$cat_order->{$title}} > 0) {
2462: $output .= '<td align="center">'.$title.'<br />'."\n".
2463: '<select name="'.$sel.'_'.$title.'">'."\n".
2464: ' <option value="" selected="selected">'.
2465: &mt('Select').'</option>'."\n";
2466: foreach my $item (@{$cat_order->{$title}}) {
2467: my $longitem = $item;
2468: if (ref($cat_titles->{$title}) eq 'HASH') {
2469: if ($cat_titles->{$title}{$item} ne '') {
2470: $longitem = $cat_titles->{$title}{$item};
2471: }
2472: }
2473: $output .= '<option value="'.$item.'">'.$longitem.
2474: '</option>'."\n";
2475: }
2476: }
2477: $output .= '</select></td>'."\n";
2478: }
2479: }
2480: if ($context eq 'crosslist') {
2481: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 2482: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2483: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 2484: } else {
2485: $output .= '</tr></table>'.
2486: &Apache::lonhtmlcommon::row_closure().
2487: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2488: $lastinput;
2489: }
2490: } else {
2491: if ($context eq 'crosslist') {
2492: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 2493: '<table><tr>'.
2494: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2495: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2496: '</tr></table>';
1.1 raeburn 2497: } else {
2498: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2499: $lastinput;
2500: }
2501: }
1.2 raeburn 2502: $output .= &Apache::lonhtmlcommon::row_closure(1);
2503: push(@$codetitles,$lastitem);
2504: } elsif ($context eq 'crosslist') {
2505: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2506: '<table><tr><td align="center">'.
2507: '<span class="LC_nobreak">'.&mt('Include?').
2508: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2509: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2510: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2511: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2512: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2513: }
2514: }
2515: return $output;
2516: }
2517:
2518: sub get_course_dom {
2519: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 2520: if ($env{'form.showdom'} ne '') {
2521: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2522: return $env{'form.showdom'};
2523: }
2524: }
1.1 raeburn 2525: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37 raeburn 2526: my ($types,$typename) = &Apache::loncommon::course_types();
1.19 raeburn 2527: if (ref($types) eq 'ARRAY') {
2528: foreach my $type (@{$types}) {
2529: if (&Apache::lonnet::usertools_access($env{'user.name'},
2530: $env{'user.domain'},$type,
2531: undef,'requestcourses')) {
2532: return $env{'user.domain'};
2533: }
2534: }
2535: my @possible_doms;
2536: foreach my $type (@{$types}) {
2537: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2538: if ($dom_str ne '') {
2539: my @domains = split(',',$dom_str);
2540: foreach my $entry (@domains) {
2541: my ($extdom,$extopt) = split(':',$entry);
2542: if ($extdom eq $env{'request.role.domain'}) {
2543: return $extdom;
2544: }
2545: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2546: push(@possible_doms,$extdom);
2547: }
2548: }
2549: }
2550: }
2551: if (@possible_doms) {
2552: @possible_doms = sort(@possible_doms);
2553: return $possible_doms[0];
2554: }
2555: }
1.1 raeburn 2556: $codedom = $env{'user.domain'};
2557: if ($env{'request.role.domain'} ne '') {
2558: $codedom = $env{'request.role.domain'};
2559: }
2560: }
2561: return $codedom;
2562: }
2563:
2564: sub display_navbuttons {
1.31 raeburn 2565: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 2566: $r->print('<div class="LC_navbuttons">');
2567: if ($prev) {
1.16 raeburn 2568: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 2569: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 2570: (' 'x3));
1.1 raeburn 2571: } elsif ($prevtext) {
1.16 raeburn 2572: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2573: 'onclick="javascript:history.back()"/>'.(' 'x3));
2574: }
2575: if ($state eq 'details') {
2576: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 2577: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 2578: ')" />');
1.1 raeburn 2579: }
1.31 raeburn 2580: my $gotnext;
1.15 raeburn 2581: if ($state eq 'courseinfo') {
1.16 raeburn 2582: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2583: 'onclick="javascript:validateForm();" />');
1.31 raeburn 2584: $gotnext = 1;
2585: } elsif ($state eq 'enrollment') {
2586: if (($env{'form.crstype'} eq 'official') &&
2587: (&Apache::lonnet::auto_run('',$dom))) {
2588: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2589: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
2590: $gotnext = 1;
2591: }
2592: } elsif ($state eq 'personnel') {
2593: if ($env{'form.persontotal'} > 0) {
2594: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2595: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
2596: $gotnext = 1;
2597: }
2598: }
2599: unless ($gotnext) {
2600: if ($next) {
2601: $r->print('
2602: <input type="button" name="next" value="'.$nexttext.'" '.
2603: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
2604: }
1.1 raeburn 2605: }
2606: $r->print('</div>');
2607: }
2608:
2609: sub print_request_outcome {
1.10 raeburn 2610: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 2611: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 2612: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 2613: my $sectotal = $env{'form.sectotal'};
2614: my $crosslisttotal = 0;
1.10 raeburn 2615: $cnum = $env{'form.cnum'};
1.8 raeburn 2616: unless ($cnum =~ /^$match_courseid$/) {
2617: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2618: return $output;
2619: }
1.11 raeburn 2620:
1.10 raeburn 2621: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 2622: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2623: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2624: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2625: }
2626: }
1.10 raeburn 2627: $now = time;
2628: $crstype = $env{'form.crstype'};
1.41 ! raeburn 2629: my $ccrole = 'cc';
! 2630: if ($crstype eq 'community') {
! 2631: $ccrole = 'co';
! 2632: }
1.17 raeburn 2633: my @instsections;
1.8 raeburn 2634: if ($crstype eq 'official') {
2635: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 2636: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 2637: }
1.10 raeburn 2638: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2639: if ($env{'form.sec_'.$i}) {
2640: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 2641: my $sec = $env{'form.secnum_'.$i};
2642: $sections{$i}{'inst'} = $sec;
2643: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2644: push(@instsections,$sec);
2645: }
1.13 raeburn 2646: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 2647: }
2648: }
2649: }
2650: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2651: if ($env{'form.crosslist_'.$i}) {
2652: my $xlistinfo = '';
2653: if (ref($code_order) eq 'ARRAY') {
2654: if (@{$code_order} > 0) {
2655: foreach my $item (@{$code_order}) {
2656: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2657: }
2658: }
2659: }
1.22 raeburn 2660: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 2661: if ($xlistinfo ne '') {
2662: $crosslisttotal ++;
2663: }
1.22 raeburn 2664: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 2665: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 2666: }
2667: }
1.14 raeburn 2668: } else {
2669: $enrollstart = '';
2670: $enrollend = '';
1.10 raeburn 2671: }
2672: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2673: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 2674: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 2675: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
2676: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 2677: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
2678: $personnel{$uname.':'.$udom} = {
2679: firstname => $env{'form.person_'.$i.'_firstname'},
2680: lastname => $env{'form.person_'.$i.'_lastname'},
2681: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
2682: };
2683: }
2684: my $role = $env{'form.person_'.$i.'_role'};
2685: unless ($role eq '') {
1.16 raeburn 2686: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 2687: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
2688: unless (grep(/^\Q$role\E$/,@curr_roles)) {
2689: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
2690: }
2691: } else {
2692: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
2693: }
1.41 ! raeburn 2694: if ($role eq $ccrole) {
1.13 raeburn 2695: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
2696: } else {
1.14 raeburn 2697: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 2698: my @allsecs;
2699: foreach my $sec (@currsec) {
2700: next unless ($sec =~ /\w/);
2701: next if ($sec =~ /\W/);
2702: next if ($sec eq 'none');
2703: push(@allsecs,$sec);
2704: }
1.14 raeburn 2705: my $newsec = $env{'form.person_'.$i.'_newsec'};
2706: $newsec =~ s/^\s+//;
2707: $newsec =~s/\s+$//;
2708: my @newsecs = split(/[\s,;]+/,$newsec);
2709: foreach my $sec (@newsecs) {
2710: next if ($sec =~ /\W/);
1.31 raeburn 2711: next if ($sec eq 'none');
1.14 raeburn 2712: if ($sec ne '') {
1.31 raeburn 2713: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2714: push(@allsecs,$sec);
1.13 raeburn 2715: }
2716: }
2717: }
1.31 raeburn 2718: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 2719: }
2720: }
1.10 raeburn 2721: } else {
2722: push(@missingdom,$uname.':'.$udom);
2723: }
2724: } else {
2725: push(@baduname,$uname.':'.$udom);
2726: }
1.8 raeburn 2727: }
1.13 raeburn 2728: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 2729: my $autodrops = 0;
2730: if ($env{'form.autodrops'}) {
2731: $autodrops = $env{'form.autodrops'};
2732: }
2733: my $autoadds = 0;
2734: if ($env{'form.autoadds'}) {
2735: $autodrops = $env{'form.autoadds'};
2736: }
2737: if ($env{'form.autoadds'}) {
2738: $autodrops = $env{'form.autoadds'};
2739: }
2740: my $instcode = '';
2741: if (exists($env{'form.instcode'})) {
2742: $instcode = $env{'form.instcode'};
2743: }
1.15 raeburn 2744: my $clonecrs = '';
2745: my $clonedom = '';
2746: if (($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
2747: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 2748: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2749: $env{'form.clonedom'});
1.15 raeburn 2750: if ($clonehome ne 'no_host') {
1.16 raeburn 2751: my $canclone =
2752: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 2753: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
2754: $crstype);
1.15 raeburn 2755: if ($canclone) {
2756: $clonecrs = $env{'form.clonecrs'};
2757: $clonedom = $env{'form.clonedom'};
2758: }
2759: }
2760: }
1.8 raeburn 2761: my $details = {
1.10 raeburn 2762: owner => $env{'user.name'},
2763: domain => $env{'user.domain'},
2764: cdom => $dom,
1.11 raeburn 2765: cnum => $cnum,
1.13 raeburn 2766: coursehome => $env{'form.chome'},
2767: cdescr => $env{'form.cdescr'},
1.10 raeburn 2768: crstype => $env{'form.crstype'},
1.14 raeburn 2769: instcode => $instcode,
1.15 raeburn 2770: clonedom => $clonedom,
2771: clonecrs => $clonecrs,
1.10 raeburn 2772: datemode => $env{'form.datemode'},
1.14 raeburn 2773: dateshift => $env{'form.dateshift'},
2774: sectotal => $sectotal,
1.10 raeburn 2775: sections => \%sections,
1.14 raeburn 2776: crosslisttotal => $crosslisttotal,
1.13 raeburn 2777: crosslists => \%crosslistings,
1.14 raeburn 2778: autoadds => $autoadds,
2779: autodrops => $autodrops,
1.13 raeburn 2780: enrollstart => $enrollstart,
2781: enrollend => $enrollend,
2782: accessstart => $accessstart,
2783: accessend => $accessend,
1.10 raeburn 2784: personnel => \%personnel,
1.8 raeburn 2785: };
1.27 raeburn 2786: my (@inststatuses,$storeresult,$creationresult);
1.9 raeburn 2787: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 2788: if ($val eq '') {
2789: if ($crstype eq 'official') {
1.19 raeburn 2790: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 2791: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 2792: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 2793: } elsif ($crstype eq 'community') {
2794: $output = &mt('You are not permitted to request creation of communities');
2795: } else {
2796: $output = &mt('Unrecognized course type: [_1]',$crstype);
2797: }
1.27 raeburn 2798: $storeresult = 'notpermitted';
1.8 raeburn 2799: } else {
1.14 raeburn 2800: my ($disposition,$message,$reqstatus);
1.8 raeburn 2801: my %reqhash = (
1.14 raeburn 2802: reqtime => $now,
1.10 raeburn 2803: crstype => $crstype,
2804: details => $details,
1.8 raeburn 2805: );
2806: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 2807: my $validationerror;
1.10 raeburn 2808: if ($val eq 'autolimit=') {
2809: $disposition = 'process';
2810: } elsif ($val =~ /^autolimit=(\d+)$/) {
2811: my $limit = $1;
1.8 raeburn 2812: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 2813: $dom,$crstype,$limit,\$message);
1.8 raeburn 2814: } elsif ($val eq 'validate') {
1.21 raeburn 2815: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 2816: if (@inststatuses > 0) {
2817: $inststatuslist = join(',',@inststatuses);
2818: }
2819: my $instseclist;
2820: if (@instsections > 0) {
2821: $instseclist = join(',',@instsections);
2822: }
1.21 raeburn 2823: $validationchk =
2824: &Apache::lonnet::auto_courserequest_validation($dom,
2825: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2826: $inststatuslist,$instcode,$instseclist);
2827: if ($validationchk =~ /:/) {
2828: ($validation,$message) = split(':',$validationchk);
2829: } else {
2830: $validation = $validationchk;
2831: }
2832: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 2833: $disposition = 'approval';
2834: $validationerror = $1;
1.23 raeburn 2835: } else {
2836: $disposition = $validation;
1.17 raeburn 2837: }
1.8 raeburn 2838: } else {
2839: $disposition = 'approval';
2840: }
1.14 raeburn 2841: $reqhash{'disposition'} = $disposition;
2842: $reqstatus = $disposition;
1.16 raeburn 2843: my ($modified,$queued);
1.8 raeburn 2844: if ($disposition eq 'rejected') {
1.40 raeburn 2845: if ($crstype eq 'community') {
2846: $output = &mt('Your community request was rejected.');
2847: } else {
2848: $output = &mt('Your course request was rejected.');
2849: }
1.8 raeburn 2850: if ($message) {
2851: $output .= '<div class="LC_warning">'.$message.'</div>';
2852: }
1.27 raeburn 2853: $storeresult = 'rejected';
1.8 raeburn 2854: } elsif ($disposition eq 'process') {
1.14 raeburn 2855: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2856: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
1.8 raeburn 2857: my $type = 'Course';
2858: if ($crstype eq 'community') {
2859: $type = 'Community';
2860: }
1.41 ! raeburn 2861: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8 raeburn 2862: foreach my $role (@roles) {
2863: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2864: }
1.14 raeburn 2865: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2866: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2867: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2868: if ($result eq 'created') {
1.8 raeburn 2869: $disposition = 'created';
1.14 raeburn 2870: $reqstatus = 'created';
1.28 raeburn 2871: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
2872: \%longroles);
1.40 raeburn 2873: if ($crstype eq 'community') {
2874: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
2875: } else {
2876: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
2877: }
2878: $output .= '<br />'.$role_result.'</p>';
1.27 raeburn 2879: $creationresult = 'created';
1.8 raeburn 2880: } else {
1.40 raeburn 2881: $output = '<span class="LC_error">';
2882: if ($crstype eq 'community') {
2883: $output .= &mt('An error occurred when processing your community request.');
2884: } else {
2885: $output .= &mt('An error occurred when processing your course request.');
2886: }
2887: $output .= '<br />'.
2888: &mt('You may want to review the request details and submit the request again.').
1.14 raeburn 2889: '</span>';
1.27 raeburn 2890: $creationresult = 'error';
1.8 raeburn 2891: }
2892: } else {
2893: my $requestid = $cnum.'_'.$disposition;
2894: my $request = {
2895: $requestid => {
2896: timestamp => $now,
2897: crstype => $crstype,
2898: ownername => $env{'user.name'},
2899: ownerdom => $env{'user.domain'},
1.13 raeburn 2900: description => $env{'form.cdescr'},
1.8 raeburn 2901: },
2902: };
1.16 raeburn 2903: my $statuskey = 'status:'.$dom.':'.$cnum;
2904: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2905: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 2906: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 2907: $modified = 1;
1.25 raeburn 2908: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2909: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2910: [$cnum.'_approval',
2911: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 2912: if (($queuehash{$cnum.'_approval'} ne '') ||
2913: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 2914: $queued = 1;
2915: }
2916: }
2917: unless ($queued) {
2918: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2919: $dom);
2920: if ($putresult eq 'ok') {
1.40 raeburn 2921: if ($crstype eq 'community') {
2922: $output .= &mt('Your community request has been recorded.');
2923: } else {
2924: $output .= &mt('Your course request has been recorded.')
2925: }
2926: $output .= '<br />'.
1.16 raeburn 2927: ¬ification_information($disposition,$req_notifylist,
2928: $cnum,$now);
1.8 raeburn 2929: } else {
1.16 raeburn 2930: $reqstatus = 'domainerror';
2931: $reqhash{'disposition'} = $disposition;
2932: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2933: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 2934: }
2935: }
2936: }
1.27 raeburn 2937: my ($statusresult);
1.10 raeburn 2938: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2939: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
2940: 'courserequests');
1.14 raeburn 2941: if ($storeresult eq 'ok') {
2942: my %status = (
2943: 'status:'.$dom.':'.$cnum => $reqstatus,
2944: );
1.27 raeburn 2945: $statusresult = &Apache::lonnet::put('courserequests',\%status);
1.14 raeburn 2946: }
1.10 raeburn 2947: } else {
2948: $storeresult = 'error: invalid requestkey format';
2949: }
1.8 raeburn 2950: if ($storeresult ne 'ok') {
1.13 raeburn 2951: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
2952: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 2953: } elsif ($statusresult ne 'ok') {
1.28 raeburn 2954: $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 2955: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 2956: }
1.16 raeburn 2957: if ($modified && $queued && $storeresult eq 'ok') {
1.40 raeburn 2958: if ($crstype eq 'community') {
2959: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
2960: } else {
2961: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
2962: }
2963: $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
1.16 raeburn 2964: }
1.17 raeburn 2965: if ($validationerror ne '') {
1.19 raeburn 2966: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17 raeburn 2967: }
1.16 raeburn 2968: }
1.27 raeburn 2969: if ($creationresult ne '') {
2970: return ($creationresult,$output);
2971: } else {
2972: return ($storeresult,$output);
2973: }
1.16 raeburn 2974: }
2975:
1.28 raeburn 2976: sub update_requestors_roles {
2977: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
2978: my $now = time;
2979: my ($active,$future,$numactive,$numfuture,$output);
2980: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
2981: if (ref($details) eq 'HASH') {
2982: if (ref($details->{'personnel'}) eq 'HASH') {
1.41 ! raeburn 2983: my $ccrole = 'cc';
! 2984: if ($crstype eq 'community') {
! 2985: $ccrole = 'co';
! 2986: }
1.35 raeburn 2987: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
2988: $details->{'personnel'}{$owner} = {
1.41 ! raeburn 2989: 'roles' => [$ccrole],
! 2990: $ccrole => { 'usec' => [] },
1.35 raeburn 2991: };
2992: }
2993: my @roles;
2994: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
2995: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41 ! raeburn 2996: unless (grep(/^\Q$ccrole\E$/,@roles)) {
! 2997: push(@roles,$ccrole);
1.35 raeburn 2998: }
2999: } else {
1.41 ! raeburn 3000: @roles = ($ccrole);
1.35 raeburn 3001: }
3002: foreach my $role (@roles) {
3003: my $start = $now;
3004: my $end = '0';
3005: if ($role eq 'st') {
3006: if ($details->{'accessstart'} ne '') {
3007: $start = $details->{'accessstart'};
3008: }
3009: if ($details->{'accessend'} ne '') {
3010: $end = $details->{'accessend'};
3011: }
3012: }
3013: my @usecs;
1.41 ! raeburn 3014: if ($role ne $ccrole) {
1.35 raeburn 3015: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3016: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3017: }
3018: }
3019: if ($role eq 'st') {
3020: if (@usecs > 1) {
3021: my $firstsec = $usecs[0];
3022: @usecs = ($firstsec);
3023: }
3024: }
3025: if (@usecs == 0) {
3026: push(@usecs,'');
3027: }
3028: foreach my $usec (@usecs) {
3029: my (%userroles,%newrole,%newgroups,$spec,$area);
3030: my $area = '/'.$dom.'/'.$cnum;
3031: my $spec = $role.'.'.$area;
3032: if ($usec ne '') {
3033: $spec .= '/'.$usec;
3034: $area .= '/'.$usec;
3035: }
3036: if ($role =~ /^cr\//) {
3037: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
3038: $cnum,$spec,$area);
3039: } else {
3040: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
3041: $spec,$cnum,$area);
1.28 raeburn 3042: }
1.35 raeburn 3043: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
3044: \%newgroups);
3045: $userroles{'user.role.'.$spec} = $start.'.'.$end;
3046: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
3047: if (($end == 0) || ($end > $now)) {
3048: my $showrole = $role;
1.28 raeburn 3049: if ($role =~ /^cr\//) {
1.35 raeburn 3050: $showrole = &Apache::lonnet::plaintext($role,$crstype);
3051: } elsif (ref($longroles) eq 'HASH') {
3052: if ($longroles->{$role} ne '') {
3053: $showrole = $longroles->{$role};
3054: }
1.28 raeburn 3055: }
1.35 raeburn 3056: if ($start <= $now) {
3057: $active .= '<li><a href="/adm/roles?selectrole=1&'.
3058: $spec.'=1">'.$showrole;
3059: if ($usec ne '') {
3060: $active .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3061: }
1.35 raeburn 3062: $active .= '</a></li>';
3063: $numactive ++;
3064: } else {
3065: $future .= '<li>'.$showrole;
3066: if ($usec ne '') {
3067: $future .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3068: }
1.35 raeburn 3069: $future .= '</li>';
3070: $numfuture ++;
1.28 raeburn 3071: }
3072: }
3073: }
3074: }
3075: }
3076: }
3077: if ($active) {
3078: if ($numactive == 1) {
1.41 ! raeburn 3079: if ($crstype eq 'Community') {
! 3080: $output = &mt('Use the following link to enter the community:');
! 3081: } else {
! 3082: $output = &mt('Use the following link to enter the course:');
! 3083: }
1.28 raeburn 3084: } else {
1.41 ! raeburn 3085: if ($crstype eq 'Community') {
! 3086: $output = &mt('Use the following links to your new roles to enter the community:');
! 3087: } else {
! 3088: $output = &mt('Use the following links to your new roles to enter the course:');
! 3089: }
1.28 raeburn 3090: }
3091: $output .= ' <ul>'.$active.'</ul><br />';
3092: }
3093: if ($future) {
1.41 ! raeburn 3094: if ($crstype eq 'Community') {
! 3095: $output .= &mt('The following community [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'<a href="/adm/roles">','</a>',&Apache::lonlocal::locallocaltime($details->{'accessstart'}))
! 3096: } else {
! 3097: $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'}));
! 3098: }
! 3099: $output .= ' <ul>'.$future.'</ul>';
1.28 raeburn 3100: }
3101: return $output;
3102: }
3103:
1.16 raeburn 3104: sub notification_information {
3105: my ($disposition,$req_notifylist,$cnum,$now) = @_;
3106: my %emails = &Apache::loncommon::getemails();
3107: my $address;
3108: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
3109: $address = $emails{'permanentemail'};
3110: if ($address eq '') {
3111: $address = $emails{'notification'};
3112: }
3113: }
3114: my $output;
3115: if ($disposition eq 'approval') {
3116: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
3117: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
3118: if ($address ne '') {
3119: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
3120: }
3121: if ($req_notifylist) {
3122: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3123: $env{'user.domain'});
3124: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3125: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
3126: }
1.17 raeburn 3127: } elsif ($disposition eq 'pending') {
1.16 raeburn 3128: $output .= '<div class="LC_info">'.
3129: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
3130: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
3131: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
3132: '</div>';
1.17 raeburn 3133: } else {
3134: $output .= '<div class="LC_warning">'.
3135: &mt('Your request status is: [_1].',$disposition).
3136: '</div>'
1.8 raeburn 3137: }
3138: return $output;
3139: }
3140:
3141: sub get_processtype {
1.9 raeburn 3142: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
3143: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 3144: my (%userenv,%settings,$val);
1.19 raeburn 3145: my @options = ('autolimit','validate','approval');
1.8 raeburn 3146: if ($dom eq $env{'user.domain'}) {
3147: %userenv =
3148: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
3149: 'requestcourses.'.$crstype,'inststatus');
3150: if ($userenv{'requestcourses.'.$crstype}) {
3151: $val = $userenv{'requestcourses.'.$crstype};
3152: @{$inststatuses} = ('_custom_');
3153: } else {
3154: my ($task,%alltasks);
1.9 raeburn 3155: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
3156: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 3157: if (ref($settings{$crstype}) eq 'HASH') {
1.23 raeburn 3158: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1.8 raeburn 3159: $val = $settings{$crstype}{'_LC_adv'};
3160: @{$inststatuses} = ('_LC_adv_');
3161: } else {
3162: if ($userenv{'inststatus'} ne '') {
3163: @{$inststatuses} = split(',',$userenv{'inststatus'});
3164: } else {
1.13 raeburn 3165: @{$inststatuses} = ('default');
1.8 raeburn 3166: }
3167: foreach my $status (@{$inststatuses}) {
3168: if (exists($settings{$crstype}{$status})) {
3169: my $value = $settings{$crstype}{$status};
3170: next unless ($value);
3171: unless (exists($alltasks{$value})) {
3172: if (ref($alltasks{$value}) eq 'ARRAY') {
3173: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
3174: push(@{$alltasks{$value}},$status);
3175: }
3176: } else {
3177: @{$alltasks{$value}} = ($status);
3178: }
3179: }
3180: }
3181: }
3182: my $maxlimit = 0;
1.13 raeburn 3183:
1.8 raeburn 3184: foreach my $key (sort(keys(%alltasks))) {
3185: if ($key =~ /^autolimit=(\d*)$/) {
3186: if ($1 eq '') {
3187: $val ='autolimit=';
3188: last;
3189: } elsif ($1 > $maxlimit) {
3190: $maxlimit = $1;
3191: }
3192: }
3193: }
3194: if ($maxlimit) {
3195: $val = 'autolimit='.$maxlimit;
3196: } else {
3197: foreach my $option (@options) {
3198: if ($alltasks{$option}) {
3199: $val = $option;
3200: last;
3201: }
3202: }
3203: }
3204: }
3205: }
3206: }
3207: }
3208: } else {
3209: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
3210: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19 raeburn 3211: if ($userenv{'reqcrsotherdom.'.$crstype}) {
3212: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
3213: my $optregex = join('|',@options);
3214: foreach my $item (@doms) {
3215: my ($extdom,$extopt) = split(':',$item);
3216: if ($extdom eq $dom) {
3217: if ($extopt =~ /^($optregex)(=?\d*)$/) {
3218: $val = $1.$2;
3219: }
3220: last;
3221: }
1.8 raeburn 3222: }
3223: @{$inststatuses} = ('_external_');
3224: }
3225: }
3226: return $val;
3227: }
3228:
3229: sub check_autolimit {
1.10 raeburn 3230: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3231: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41 ! raeburn 3232: 'userroles',['active','future'],['cc','co'],[$dom]);
1.37 raeburn 3233: my ($types,$typename) = &Apache::loncommon::course_types();
1.10 raeburn 3234: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41 ! raeburn 3235: my $count = 0;
1.10 raeburn 3236: foreach my $key (keys(%requests)) {
3237: my ($cdom,$cnum) = split('_',$key);
1.41 ! raeburn 3238: if (ref($requests{$key}) eq 'HASH') {
! 3239: next if ($requests{$key}{'crstype'} ne $crstype);
! 3240: if (($crstype eq 'community') &&
! 3241: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
! 3242: $count ++;
! 3243: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
! 3244: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
! 3245: $count ++;
1.10 raeburn 3246: }
3247: }
3248: }
1.41 ! raeburn 3249: if ($count < $limit) {
1.10 raeburn 3250: return 'process';
3251: } else {
3252: if (ref($typename) eq 'HASH') {
1.41 ! raeburn 3253: if ($crstype eq 'community') {
! 3254: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
! 3255: '<br />'.&mt("Your limit is [_1].",$limit);
! 3256: } else {
! 3257: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
! 3258: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
! 3259: }
1.10 raeburn 3260: }
3261: return 'rejected';
3262: }
1.1 raeburn 3263: return;
3264: }
3265:
1.2 raeburn 3266: sub retrieve_settings {
1.26 raeburn 3267: my ($dom,$cnum,$udom,$uname) = @_;
3268: if ($udom eq '' || $uname eq '') {
3269: $udom = $env{'user.domain'};
3270: $uname = $env{'user.name'};
3271: }
3272: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 3273: if ($result eq 'ok') {
1.26 raeburn 3274: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 3275: $env{'form.chome'} = $reqinfo{'coursehome'};
3276: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3277: $env{'form.crstype'} = $reqinfo{'crstype'};
3278: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3279: &generate_date_items($reqinfo{'accessend'},'accessend');
3280: if ($reqinfo{'accessend'} == 0) {
3281: $env{'form.no_end_date'} = 1;
3282: }
3283: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3284: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3285: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3286: }
3287: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3288: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3289: $env{'form.datemode'} = $reqinfo{'datemode'};
3290: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3291: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
3292: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3293: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3294: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3295: $env{'form.autdrops'} = $reqinfo{'autodrops'};
3296: $env{'form.instcode'} = $reqinfo{'instcode'};
1.24 raeburn 3297: my $crscode = {
3298: $cnum => $reqinfo{'instcode'},
3299: };
3300: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16 raeburn 3301: }
3302: my @currsec;
3303: if (ref($reqinfo{'sections'}) eq 'HASH') {
3304: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3305: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 3306: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 3307: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 3308: $env{'form.sec_'.$i} = '1';
1.16 raeburn 3309: if (!grep(/^\Q$sec\E$/,@currsec)) {
3310: push(@currsec,$sec);
3311: }
3312: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3313: }
3314: }
3315: }
1.24 raeburn 3316: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3317: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3318: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3319: $env{'form.crosslist_'.$i} = '1';
3320: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3321: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3322: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3323: my $key = $cnum.$i;
3324: my $crscode = {
3325: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3326: };
3327: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3328: }
1.16 raeburn 3329: }
3330: }
3331: }
3332: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3333: my $i = 0;
3334: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3335: my ($uname,$udom) = split(':',$user);
3336: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3337: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3338: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3339: $env{'form.person_'.$i.'_role'} = $role;
3340: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3341: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3342: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3343: $env{'form.person_'.$i.'_uname'} = $uname;
3344: $env{'form.person_'.$i.'_dom'} = $udom;
3345: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3346: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3347: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3348: my @newsecs;
3349: if (@usecs > 0) {
3350: foreach my $sec (@usecs) {
3351: if (grep(/^\Q$sec\E/,@currsec)) {
3352: $env{'form.person_'.$i.'_sec'} = $sec;
3353: } else {
1.20 raeburn 3354: push(@newsecs,$sec);
1.16 raeburn 3355: }
3356: }
3357: }
3358: if (@newsecs > 0) {
3359: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3360: }
3361: }
3362: }
3363: $i ++;
3364: }
3365: }
3366: }
3367: }
3368: $env{'form.persontotal'} = $i;
3369: }
3370: }
3371: }
3372: return $result;
3373: }
3374:
3375: sub get_request_settings {
1.26 raeburn 3376: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 3377: my $requestkey = $dom.'_'.$cnum;
3378: my ($result,%reqinfo);
3379: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 3380: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 3381: my $disposition = $history{'disposition'};
3382: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3383: if (ref($history{'details'}) eq 'HASH') {
3384: %reqinfo = %{$history{'details'}};
3385: $result = 'ok';
3386: } else {
3387: $result = 'nothash';
3388: }
3389: } else {
3390: $result = 'notqueued';
3391: }
3392: } else {
3393: $result = 'invalid';
3394: }
3395: return ($result,%reqinfo);
3396: }
1.2 raeburn 3397:
1.16 raeburn 3398: sub extract_instcode {
1.24 raeburn 3399: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 3400: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 3401: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3402: \@codetitles,\%cat_titles,
3403: \%cat_order) eq 'ok') {
3404: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 3405: if (@codetitles > 0) {
3406: my $sel = $element;
3407: if ($element eq 'crosslist') {
3408: $sel .= '_'.$counter;
3409: }
3410: foreach my $title (@codetitles) {
1.24 raeburn 3411: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 3412: }
3413: }
3414: }
3415: }
3416: return;
1.2 raeburn 3417: }
3418:
1.16 raeburn 3419: sub generate_date_items {
3420: my ($currentval,$item) = @_;
3421: if ($currentval =~ /\d+/) {
3422: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3423: &Apache::lonhtmlcommon::get_timedates($currentval);
3424: $env{'form.'.$item.'_day'} = $mday;
3425: $env{'form.'.$item.'_month'} = $month+1;
3426: $env{'form.'.$item.'_year'} = $year;
3427: }
3428: return;
1.2 raeburn 3429: }
3430:
1.1 raeburn 3431: 1;
3432:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>