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