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