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