Annotation of loncom/interface/lonrequestcourse.pm, revision 1.47
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.47 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.46 2010/03/08 13:42:18 wenzelju 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 {
1.47 ! raeburn 1367: my $gentype = 'Course';
! 1368: if ($crstype eq 'community') {
! 1369: $gentype = 'Community';
! 1370: }
! 1371: $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1.16 raeburn 1372: }
1.4 raeburn 1373: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1374: \%cat_order,\@code_order);
1.40 raeburn 1375: if ($crstype eq 'community') {
1376: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1377: } else {
1378: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1379: }
1380: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1.16 raeburn 1381: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.40 raeburn 1382: if ($crstype eq 'community') {
1383: $navtxt{'next'} = &mt('Submit community request');
1384: } else {
1385: $navtxt{'next'} = &mt('Submit course request');
1386: }
1.10 raeburn 1387: } elsif ($state eq 'process') {
1388: if ($crstype eq 'official') {
1389: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1390: \%cat_order,\@code_order);
1391: }
1.27 raeburn 1392: my ($storeresult,$result) = &print_request_outcome($dom,\@codetitles,
1393: \@code_order);
1.13 raeburn 1394: $r->print($result);
1.27 raeburn 1395: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1396: $r->print('<p>');
1397: if ($storeresult eq 'ok') {
1398: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1399: &mt('Modify this request').'</a>'.(' 'x4));
1400: }
1401: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1402: return;
1403: }
1.1 raeburn 1404: }
1.16 raeburn 1405: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24 raeburn 1406: if ($state eq 'personnel') {
1407: push(@excluded,'persontotal');
1408: }
1.30 raeburn 1409: if ($state eq 'review') {
1410: if (@disallowed > 0) {
1411: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1412: my @currsecs = ¤t_lc_sections();
1413: if (@currsecs) {
1414: push(@items,'sec');
1415: }
1416: my $count = 0;
1417: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1418: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1419: if (grep(/^$i$/,@disallowed)) {
1420: foreach my $item (@items) {
1421: $env{'form.person_'.$i.'_'.$item} = '';
1422: }
1423: } else {
1424: foreach my $item (@items) {
1425: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1426: }
1427: }
1428: }
1429: $count ++;
1430: }
1431: $env{'form.persontotal'} = $count;
1432:
1433: }
1434: }
1.27 raeburn 1435: if ($state eq 'enrollment') {
1436: push(@excluded,'crosslisttotal');
1437: }
1.16 raeburn 1438: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1.31 raeburn 1439: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1440: $navtxt{'next'},$state);
1.16 raeburn 1441: return;
1442: }
1443:
1.30 raeburn 1444: sub get_cancreate_status {
1445: my ($persondom,$personname,$dom) = @_;
1446: my ($rules,$ruleorder) =
1447: &Apache::lonnet::inst_userrules($persondom,'username');
1448: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1449: $rules);
1450: return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
1451: }
1452:
1453: sub check_newuser_rules {
1454: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1455: $got_rules) = @_;
1456: my $allowed = 1;
1457: my $newuser = 1;
1458: my ($checkhash,$userchkmsg);
1459: my $checks = { 'username' => 1 };
1460: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1461: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1462: $inst_results,$curr_rules,$got_rules);
1463: if (ref($alerts->{'username'}) eq 'HASH') {
1464: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1465: my $domdesc =
1466: &Apache::lonnet::domain($persondom,'description');
1467: if ($alerts->{'username'}{$persondom}{$personname}) {
1468: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1469: $userchkmsg =
1470: &Apache::loncommon::instrule_disallow_msg('username',
1471: $domdesc,1).
1472: &Apache::loncommon::user_rule_formats($persondom,
1473: $domdesc,$curr_rules->{$persondom}{'username'},
1474: 'username');
1475: }
1476: $allowed = 0;
1477: }
1478: }
1479: }
1480: return ($allowed,$userchkmsg);
1481: }
1482:
1.16 raeburn 1483: sub get_excluded_elements {
1484: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 1485: my @excluded = ('counter');
1486: my %elements = &form_elements($dom);
1487: if (ref($states) eq 'HASH') {
1488: if (ref($states->{$action}) eq 'ARRAY') {
1489: my @items = @{$states->{$action}};
1490: my $numitems = scalar(@items);
1491: if ($numitems) {
1492: for (my $i=$numitems-1; $i>=0; $i--) {
1493: if (ref($elements{$action}) eq 'HASH') {
1494: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 1495: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 1496: push(@excluded,$key);
1497: }
1498: }
1499: }
1500: last if ($items[$i] eq $state);
1501: }
1502: }
1503: }
1504: }
1505: if (grep(/^instcode_/,@excluded)) {
1506: push(@excluded,'instcode');
1.1 raeburn 1507: }
1.16 raeburn 1508: return @excluded;
1.1 raeburn 1509: }
1510:
1.2 raeburn 1511: sub print_enrollment_menu {
1.27 raeburn 1512: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1513: $invalidcrosslist) =@_;
1.34 raeburn 1514: my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1.2 raeburn 1515: my $starttime = time;
1516: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1517:
1518: my %accesstitles = (
1519: 'start' => 'Default start access',
1.16 raeburn 1520: 'end' => 'Default end access',
1.2 raeburn 1521: );
1522: my %enrolltitles = (
1523: 'start' => 'Start auto-enrollment',
1524: 'end' => 'End auto-enrollment',
1525: );
1526: if ($env{'form.crstype'} eq 'official') {
1527: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1528: $output = &show_invalid_crosslists($invalidcrosslist);
1529: my ($section_form,$crosslist_form);
1.2 raeburn 1530: $section_form = &inst_section_selector($dom,$instcode);
1.27 raeburn 1531: if ($section_form) {
1532: $sections = &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1533: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1534: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1.27 raeburn 1535: &Apache::lonhtmlcommon::row_closure(1).
1536: $section_form;
1537: }
1.2 raeburn 1538: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1539: if (!$crosslisttotal) {
1.2 raeburn 1540: $crosslisttotal = 1;
1541: }
1542: if ($env{'form.addcrosslist'}) {
1543: $crosslisttotal ++;
1544: }
1545: for (my $i=0; $i<$crosslisttotal; $i++) {
1546: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1547: $cat_titles,$cat_order,$i);
1548: }
1549: if ($crosslist_form) {
1550: $crosslist_form .=
1.40 raeburn 1551: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 1552: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1553: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1554: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27 raeburn 1555: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1556: $sections .= &Apache::lonhtmlcommon::row_headline.
1557: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1558: &Apache::lonhtmlcommon::row_closure(1).
1559: $crosslist_form;
1.2 raeburn 1560: }
1.34 raeburn 1561: $hasauto = 1;
1.27 raeburn 1562: $autoenroll =
1.34 raeburn 1563: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1.2 raeburn 1564: '<span class="LC_nobreak"><label>'.
1565: '<input type="radio" name="autoadds" value="1">'.
1566: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1567: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1568: &mt('No').'</label></span>'.
1.27 raeburn 1569: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1570: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1.2 raeburn 1571: '<span class="LC_nobreak"><label>'.
1572: '<input type="radio" name="autodrops" value="1">'.
1573: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1574: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1575: &mt('No').'</label></span>'.
1.27 raeburn 1576: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1577: &date_setting_table($starttime,$endtime,$formname,'enroll',
1578: $hasauto,%enrolltitles);
1.2 raeburn 1579: }
1580: }
1.27 raeburn 1581: my $access_dates =
1.34 raeburn 1582: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1583: %accesstitles);
1.27 raeburn 1584: $output .= &Apache::lonhtmlcommon::start_pick_box();
1585: if ($sections) {
1586: $output .= $sections;
1587: }
1588: if ($autoenroll) {
1589: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1590: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1591: &Apache::lonhtmlcommon::row_closure(1).
1592: $autoenroll;
1593: }
1594: if ($access_dates) {
1595: my $header = &mt('Access dates for students');
1596: if ($env{'form.crstype'} eq 'community') {
1597: $header = &mt('Access dates for community members');
1598: }
1599: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1600: '<h3>'.$header.'</h3>'.
1601: &Apache::lonhtmlcommon::row_closure(1).
1602: $access_dates
1.2 raeburn 1603: }
1.27 raeburn 1604: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1605: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2 raeburn 1606: }
1607:
1.27 raeburn 1608: sub show_invalid_crosslists {
1609: my ($invalidcrosslist) = @_;
1610: my $output;
1611: if (ref($invalidcrosslist) eq 'ARRAY') {
1612: if (@{$invalidcrosslist} > 0) {
1613: $output = '<div class="LC_warning">'.
1614: &mt('The following crosslisted courses were invalid:').'<ul>';
1615: foreach my $item (@{$invalidcrosslist}) {
1616: $output .= '<li>'.$item.'</li>';
1617: }
1618: $output .= '</ul></div><br />';
1619: }
1620: }
1621: return $output;
1622: }
1623:
1624:
1.1 raeburn 1625: sub inst_section_selector {
1.2 raeburn 1626: my ($dom,$instcode) = @_;
1627: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1628: my $sectotal = scalar(@sections);
1.1 raeburn 1629: my $output;
1.2 raeburn 1630: if ($sectotal) {
1.27 raeburn 1631: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1632: &Apache::loncommon::start_data_table().
1633: &Apache::loncommon::start_data_table_row().
1634: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1635: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1636: '<th>'.&mt('Institutional Section').'</th>'.
1.34 raeburn 1637: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1638: ' '.&mt('LON-CAPA section').'</th>'.
1.2 raeburn 1639: &Apache::loncommon::end_data_table_row();
1640: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1641: my $colflag = $i%2;
1.31 raeburn 1642: my $secon = ' checked="checked"';
1643: my $secoff = '';
1.24 raeburn 1644: if ($env{'form.origcnum'}) {
1.31 raeburn 1645: $secoff = $secon;
1646: $secon='';
1.24 raeburn 1647: }
1.1 raeburn 1648: $output .= &Apache::loncommon::start_data_table_row().
1.31 raeburn 1649: '<td><label><input type="radio" name="sec_'.$i.
1650: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1651: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1652: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1653: '<td align="center">'.$sections[$i].
1.1 raeburn 1654: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1655: $sections[$i].'" /></td>'.
1.1 raeburn 1656: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1657: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1658: &Apache::loncommon::end_data_table_row();
1659: }
1.2 raeburn 1660: $output .= &Apache::loncommon::end_data_table().
1661: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1662: }
1663: return $output;
1664: }
1665:
1.2 raeburn 1666: sub date_setting_table {
1.34 raeburn 1667: my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
1.2 raeburn 1668: my ($perpetual,$table);
1.14 raeburn 1669: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 1670: $starttime,'','','',1,'','','',1);
1.14 raeburn 1671: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 1672: $endtime,'','','',1,'','','',1);
1.27 raeburn 1673: my $closure = '';
1.14 raeburn 1674: if ($prefix eq 'access') {
1.2 raeburn 1675: $perpetual = ' <span class="LC_nobreak"><label>'.
1676: '<input type="checkbox" name="no_end_date" />'.
1677: &mt('No end date').'</label></span>';
1.27 raeburn 1678: $closure = '1';
1.2 raeburn 1679: }
1.34 raeburn 1680:
1681: my %help_item = (
1682: access => {
1683: start => 'Course_Request_Access_Start',
1684: end => 'Course_Request_Access_End',
1685: },
1686: enroll => {
1687: start => 'Course_Request_Enroll_Start',
1688: end => 'Course_Request_Enroll_End',
1689: },
1690: );
1691: if ($hasauto) {
1692: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
1693: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
1694: }
1695:
1696: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1.46 wenzelju 1697: ' '.&mt($datetitles{'start'})).$startform.
1.27 raeburn 1698: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1699: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1.46 wenzelju 1700: ' '.&mt($datetitles{'end'})).$endform.$perpetual.
1.27 raeburn 1701: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 1702: return $table;
1703: }
1704:
1705: sub print_personnel_menu {
1.27 raeburn 1706: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
1707: my $output;
1708: if ($crstype eq 'official') {
1709: if (&Apache::lonnet::auto_run('',$dom)) {
1710: $output .= &show_invalid_crosslists($invalidcrosslist);
1711: }
1712: }
1713: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 1714: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1715: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1716: $persontotal = 1;
1717: }
1718: if ($env{'form.addperson'}) {
1719: $persontotal ++;
1720: }
1.13 raeburn 1721: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1722:
1.8 raeburn 1723: my $type = 'Course';
1724: if ($crstype eq 'community') {
1725: $type = 'Community';
1726: }
1.41 raeburn 1727: my $roleoptions;
1728: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.2 raeburn 1729: foreach my $role (@roles) {
1.28 raeburn 1730: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1731: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1732: }
1733: my %customroles=&Apache::lonuserutils::my_custom_roles();
1734: if (keys(%customroles) > 0) {
1735: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 1736: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 1737: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1738: }
1739: }
1740:
1.30 raeburn 1741: my @currsecs = ¤t_lc_sections();
1.2 raeburn 1742:
1743: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1744: if (@currsecs) {
1745: my $existsize = scalar(@currsecs);
1746: if ($existsize > 3) {
1747: $existsize = 3;
1748: }
1749: if ($existsize > 1) {
1750: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1751: }
1752: @currsecs = sort { $a <=> $b } (@currsecs);
1753: $existtitle = &mt('Official').': ';
1754: $existops = '<option value="">'.&mt('None').'</option>';
1755: foreach my $sec (@currsecs) {
1756: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1757: }
1758: $seccolspan = ' colspan="2"';
1759: $newtitle = &mt('Other').': ';
1760: }
1761:
1.27 raeburn 1762: if ($persontotal) {
1.32 raeburn 1763: my %lt = &Apache::lonlocal::texthash(
1764: community => 'Requestor is automatically assigned Coordinator role.',
1765: official => 'Requestor is automatically assigned Course Coordinator role.',
1766: );
1767: $lt{'unofficial'} = $lt{'official'};
1.27 raeburn 1768: $output .= &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1769: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27 raeburn 1770: }
1.2 raeburn 1771: for (my $i=0; $i<$persontotal; $i++) {
1772: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1773: my $linkargstr = join("','",@linkargs);
1.29 raeburn 1774: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 1775: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 1776: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 1777: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1778: 1,$onchange).
1.29 raeburn 1779: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 1780: my %form_elems;
1781: foreach my $item (@items) {
1782: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1783: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1784: 'value="" readonly="readonly" />';
1785: }
1786: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1787: $roleoptions.'</select>';
1788: my $sectionselector;
1789: if (@currsecs) {
1790: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1791: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1792: }
1793: $sectionselector .= $newtitle.
1.14 raeburn 1794: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29 raeburn 1795: my $usersrchlinktxt = &mt('Search for user');
1796: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1797: $usersrchlinktxt);
1798: my $userchklinktxt = &mt('Check username');
1799: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1800: $userchklinktxt,'checkusername');
1.2 raeburn 1801: $output .=
1.29 raeburn 1802: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1803: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1804: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1805: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1806: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1807: '</tr>'."\n".'<tr>'.
1.13 raeburn 1808: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1809: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1810: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34 raeburn 1811: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1812: '<td'.$seccolspan.' align="center" valign="top">'.
1813: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2 raeburn 1814: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
1815: }
1.40 raeburn 1816: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 1817: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
1818: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1819: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1820: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.40 raeburn 1821: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1822: if ($crstype eq 'community') {
1823: $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>';
1824: } else {
1825: $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>';
1826: }
1.2 raeburn 1827: return $output;
1828: }
1829:
1.30 raeburn 1830: sub current_lc_sections {
1831: my @currsecs;
1832: if ($env{'form.sectotal'}) {
1833: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 1834: if ($env{'form.sec_'.$i}) {
1835: if (defined($env{'form.loncapasec_'.$i})) {
1836: my $lcsec = $env{'form.loncapasec_'.$i};
1837: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
1838: push(@currsecs,$lcsec);
1839: }
1.30 raeburn 1840: }
1841: }
1842: }
1843: }
1844: return @currsecs;
1845: }
1846:
1.1 raeburn 1847: sub print_request_status {
1.11 raeburn 1848: my ($dom) = @_;
1.14 raeburn 1849: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
1850: $env{'user.name'},'^status:'.$dom);
1.35 raeburn 1851: my ($output,$formname,%queue_by_date);
1.37 raeburn 1852: my ($types,$typenames) = &Apache::loncommon::course_types();
1.14 raeburn 1853: foreach my $key (keys(%statusinfo)) {
1854: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
1855: (undef,my($cdom,$cnum)) = split(':',$key);
1856: next if ($cdom ne $dom);
1857: my $requestkey = $cdom.'_'.$cnum;
1858: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1859: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1860: $env{'user.domain'},$env{'user.name'});
1861: my $entry;
1862: my $timestamp = $history{'reqtime'};
1863: my $crstype = $history{'crstype'};
1864: my $disposition = $history{'disposition'};
1865: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1866: next unless (($env{'form.crstype'} eq 'any') ||
1867: ($env{'form.crstype'} eq $crstype));
1868: next unless (($disposition eq 'approval') ||
1869: ($disposition eq 'pending'));
1870: if (ref($history{'details'}) eq 'HASH') {
1871: $entry = $requestkey.':'.$crstype.':'.
1872: &escape($history{'details'}{'cdescr'});
1873: if ($crstype eq 'official') {
1874: $entry .= ':'.&escape($history{'details'}{'instcode'});
1875: }
1876: }
1877: if ($entry ne '') {
1878: if (exists($queue_by_date{$timestamp})) {
1879: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
1880: push(@{$queue_by_date{$timestamp}},$entry);
1881: }
1882: } else {
1883: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 1884: }
1885: }
1886: }
1887: }
1888: }
1.11 raeburn 1889: $formname = 'requestcrs';
1.10 raeburn 1890: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.16 raeburn 1891: $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1892:
1.10 raeburn 1893: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 1894: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
1895: '<input type="hidden" name="showdom" value="" />'."\n".
1896: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 1897: if (@sortedtimes > 0) {
1.40 raeburn 1898: my $desctitle;
1899: if ($env{'form.crstype'} eq 'any') {
1900: $desctitle = &mt('Course/Community Description')
1901: } elsif ($env{'form.crstype'} eq 'community') {
1902: $desctitle = &mt('Community Description')
1903: } else {
1904: $desctitle = &mt('Course Description');
1905: }
1.10 raeburn 1906: $output .= &Apache::loncommon::start_data_table().
1907: &Apache::loncommon::start_data_table_header_row().
1908: '<th>'.&mt('Action').'</th>'.
1.40 raeburn 1909: '<th>'.$desctitle.'</th>'.
1.14 raeburn 1910: '<th>'.&mt('Domain').'</th>';
1911: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 1912: $output .= '<th>'.&mt('Type').'</th>';
1913: }
1.14 raeburn 1914: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 1915: $output .= '<th>'.&mt('Institutional Code').'</th>';
1916: }
1917: $output .= '<th>'.&mt('Date requested').'</th>'.
1918: &Apache::loncommon::end_data_table_header_row();
1919: my $count = 0;
1920: foreach my $item (@sortedtimes) {
1921: my $showtime = &Apache::lonlocal::locallocaltime($item);
1922: if (ref($queue_by_date{$item}) eq 'ARRAY') {
1923: foreach my $request (sort(@{$queue_by_date{$item}})) {
1924: my ($key,$type,$desc,$instcode) = split(':',$request);
1925: my ($cdom,$cnum) = split('_',$key);
1926: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 1927: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 1928: '<td>'.&unescape($desc).'</td>'.
1929: '<td>'.$cdom.'</td>';
1930: if ($env{'form.crstype'} eq 'any') {
1.35 raeburn 1931: my $typename;
1932: if (ref($typenames) eq 'HASH') {
1933: $typename = &mt($typenames->{$type});
1934: }
1.14 raeburn 1935: if ($typename eq '') {
1936: $typename = &mt('Unknown type');
1937: }
1938: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 1939: }
1.14 raeburn 1940: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 1941: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 1942: my $showinstcode;
1943: if ($type eq 'official') {
1944: $showinstcode = &unescape($instcode);
1945: } else {
1946: $showinstcode = &mt('Not applicable');
1947: }
1948: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 1949: }
1950: $output .= '<td>'.$showtime.'</td>'.
1951: &Apache::loncommon::end_data_table_row();
1952: }
1953: }
1954: }
1955: $output .= &Apache::loncommon::end_data_table();
1956: } else {
1.40 raeburn 1957: if ($env{'form.crstype'} eq 'any') {
1958: $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>';
1959: } elsif ($env{'form.crstype'} eq 'community') {
1960: $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>';
1961: } else {
1962: $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>';
1963: }
1.10 raeburn 1964: }
1965: $output .= '
1.30 raeburn 1966: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 1967: return $output;
1.1 raeburn 1968: }
1969:
1.16 raeburn 1970: sub print_cancel_request {
1971: my ($dom,$cnum) = @_;
1972: my $requestkey = $dom.'_'.$cnum;
1973: my ($result,$output);
1974: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1975: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
1976: $env{'user.domain'},$env{'user.name'});
1977: my $timestamp = $history{'reqtime'};
1978: my $crstype = $history{'crstype'};
1979: my $status = $history{'status'};
1980: if (($status eq 'cancelled') || ($status eq 'created')) {
1981: if ($status eq 'cancelled') {
1982: $output = &mt('This request has already been cancelled.');
1983: } elsif ($status eq 'created') {
1984: $output = &mt('This request has already been processed, and a course created.');
1985: }
1986: $output = &mt('No further action will be taken');
1987: } elsif (ref($history{'details'}) eq 'HASH') {
1.37 raeburn 1988: my ($types,$typename) = &Apache::loncommon::course_types();
1.16 raeburn 1989: my $showtype = $crstype;
1990: if (defined($typename->{$crstype})) {
1991: $showtype = $typename->{$crstype};
1992: }
1993: $output = '<p>'.&Apache::loncommon::start_data_table().
1994: &Apache::loncommon::start_data_table_header_row().
1995: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
1996: '<th>'.&mt('Type').'</th>'.
1997: &Apache::loncommon::end_data_table_header_row().
1998: &Apache::loncommon::start_data_table_row().
1999: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2000: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2001: '<td>'.$showtype.'</td>'.
2002: &Apache::loncommon::end_data_table_row().
2003: &Apache::loncommon::end_data_table().
1.40 raeburn 2004: '<br /><div class="LC_warning">';
2005: if ($crstype eq 'community') {
2006: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2007: } else {
2008: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2009: }
1.16 raeburn 2010: $result = 'ok';
2011: } else {
2012: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2013: }
2014: } else {
2015: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2016: }
2017: return ($result,$output);
2018: }
2019:
2020: sub viewrequest_javascript {
2021: my ($formname,$next) = @_;
2022: return <<"ENDJS";
2023:
2024: function chooseRequest(cdom,cnum) {
2025: document.$formname.showdom.value = cdom;
2026: document.$formname.cnum.value = cnum;
2027: nextPage(document.$formname,'$next');
2028: }
2029:
2030: ENDJS
2031: }
2032:
2033: sub viewdetails_javascript {
2034: my ($formname) = @_;
2035: return << "ENDJS";
2036:
2037: function nextPage(formname,nextstate) {
2038: if (nextstate == "modify") {
2039: formname.state.value = "personnel";
2040: formname.action.value = "new";
2041: } else {
2042: formname.state.value = nextstate;
2043: }
2044: formname.submit();
2045: }
2046:
2047: function backPage(formname,prevstate) {
2048: formname.state.value = prevstate;
2049: formname.submit();
2050: }
2051:
2052: ENDJS
2053: }
2054:
2055: sub viewcancel_javascript {
2056: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
2057: 'Your request will be removed.');
2058: return << "ENDJS";
2059: function nextPage(formname,nextstate) {
2060: if (confirm('$alert')) {
2061: formname.state.value = nextstate;
2062: formname.submit();
2063: }
2064: return;
2065: }
2066:
2067: ENDJS
2068: }
2069:
1.1 raeburn 2070: sub print_request_logs {
1.10 raeburn 2071: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 2072: return;
2073: }
2074:
2075: sub print_review {
1.30 raeburn 2076: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
2077: $disallowed,$disallowmsg) = @_;
1.37 raeburn 2078: my ($types,$typename) = &Apache::loncommon::course_types();
1.4 raeburn 2079: my ($owner,$ownername,$owneremail);
1.26 raeburn 2080: if ($uname eq '' || $udom eq '') {
2081: $uname = $env{'user.name'};
2082: $udom = $env{'user.domain'};
2083: }
2084: $owner = $uname.':'.$udom;
2085: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2086: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 2087: foreach my $email ('permanentemail','critnotification','notification') {
2088: $owneremail = $emails{$email};
2089: last if ($owneremail ne '');
2090: }
2091: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2092: $section_headers,$section_values,$personnel_headers,$personnel_values);
2093:
2094: $crstypename = $env{'form.crstype'};
2095: if (ref($typename) eq 'HASH') {
2096: unless ($typename->{$env{'form.crstype'}} eq '') {
1.35 raeburn 2097: $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4 raeburn 2098: }
2099: }
1.16 raeburn 2100: my $category = 'Course';
2101: if ($env{'form.crstype'} eq 'community') {
2102: $category = 'Community';
2103: }
1.4 raeburn 2104:
2105: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2106: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2107:
1.16 raeburn 2108: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2109: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 2110: if ($env{'form.crstype'} eq 'official') {
2111: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2112: foreach my $title (@{$codetitles}) {
2113: if ($env{'form.instcode_'.$title} ne '') {
2114: $inst_headers .= '<th>'.$title.'</th>';
2115: my $longitem = $env{'form.instcode_'.$title};
2116: if (ref($cat_titles->{$title}) eq 'HASH') {
2117: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2118: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2119: }
2120: }
2121: $inst_values .= '<td>'.$longitem.'</td>';
2122: }
2123: }
2124: }
2125: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 2126: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 2127: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2128: '<th>'.&mt('Automatic Drops').'</th>'.
2129: '<th>'.&mt('Enrollment Starts').'</th>'.
2130: '<th>'.&mt('Enrollment Ends').'</th>';
2131: $section_headers = '<th>'.&mt('Sections').'</th>'.
2132: '<th>'.&mt('Crosslistings').'</th>';
2133:
1.13 raeburn 2134: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 2135: my @autoroster = (&mt('No'),&mt('Yes'));
2136: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2137: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 2138: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2139: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 2140: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2141: &mt('Institutional section').'</th>'.
2142: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2143: my $secinfo;
1.4 raeburn 2144: if ($env{'form.sectotal'} > 0) {
2145: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2146: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2147: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2148: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2149: $secinfo .= $env{'form.loncapasec_'.$i};
2150: } else {
2151: $secinfo .= &mt('None');
1.4 raeburn 2152: }
1.5 raeburn 2153: $secinfo .= '</td></tr>';
1.4 raeburn 2154: }
2155: }
2156: }
1.6 raeburn 2157: if ($secinfo eq '') {
2158: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2159: }
1.6 raeburn 2160: $section_values .= $secinfo.'</table></td><td>'.
2161: '<table class="LC_innerpickbox"><tr><th>'.
2162: &mt('Institutional course/section').'</th>'.
2163: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2164: my $xlistinfo;
1.24 raeburn 2165: my $crosslisttotal = $env{'form.crosslisttotal'};
2166: if (!$crosslisttotal) {
2167: $crosslisttotal = 1;
2168: }
2169: for (my $i=0; $i<$crosslisttotal; $i++) {
2170: if ($env{'form.crosslist_'.$i}) {
2171: $xlistinfo .= '<tr><td>';
2172: if (ref($code_order) eq 'ARRAY') {
2173: if (@{$code_order} > 0) {
2174: foreach my $item (@{$code_order}) {
2175: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2176: }
2177: }
2178: }
1.24 raeburn 2179: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2180: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2181: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2182: } else {
2183: $xlistinfo .= &mt('None');
2184: }
2185: $xlistinfo .= '</td></tr>';
1.4 raeburn 2186: }
2187: }
1.6 raeburn 2188: if ($xlistinfo eq '') {
2189: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2190: }
1.24 raeburn 2191: $section_values .= $xlistinfo;
1.4 raeburn 2192: }
1.24 raeburn 2193: $section_values .= '</table></td>';
1.4 raeburn 2194: }
2195:
2196: my %ctxt = &clone_text();
2197: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.45 raeburn 2198: if (($env{'form.cloning'}) &&
2199: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
1.13 raeburn 2200: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.15 raeburn 2201: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 2202: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
2203: $env{'form.crstype'});
1.15 raeburn 2204: if ($canclone) {
2205: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2206: $env{'form.clonecrs'},('description','internal.coursecode'));
2207: if (keys(%courseenv) > 0) {
2208: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2209: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2210: my $cloneinst = $courseenv{'internal.coursecode'};
2211: if ($cloneinst ne '') {
1.18 raeburn 2212: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 2213: } else {
1.18 raeburn 2214: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 2215: }
2216: $inst_values .= '</td><td>';
2217: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 2218: $inst_values .= $ctxt{'prd'};
1.15 raeburn 2219: } elsif ($env{'form.datemode'} eq 'shift') {
2220: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2221: } else {
2222: $inst_values .= $ctxt{'ncd'};
2223: }
2224: $inst_values .= '</td>';
2225: } else {
2226: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2227: }
2228: } else {
2229: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2230: }
1.4 raeburn 2231: } else {
2232: $inst_values .= '<td>'.&mt('None').'</td>';
2233: }
2234: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2235: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 2236: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2237: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2238: if ($accessend == 0) {
1.4 raeburn 2239: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2240: } else {
1.13 raeburn 2241: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 2242: }
2243:
2244: my $container = 'Course';
1.41 raeburn 2245: my $ccrole = 'cc';
1.4 raeburn 2246: if ($env{'form.crstype'} eq 'community') {
2247: $container = 'Community';
1.41 raeburn 2248: $ccrole = 'co';
1.4 raeburn 2249: }
2250:
2251: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2252: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2253: '</th>';
1.41 raeburn 2254:
1.4 raeburn 2255: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41 raeburn 2256: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4 raeburn 2257: '<td>'.&mt('None').'</td></tr>';
2258: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2259: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2260: if (ref($disallowed) eq 'ARRAY') {
2261: next if (grep(/^$i$/,@{$disallowed}));
2262: }
1.31 raeburn 2263: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2264: my @allsecs;
2265: foreach my $sec (@officialsecs) {
2266: next unless ($sec =~ /\w/);
2267: next if ($sec =~ /\W/);
2268: next if ($sec eq 'none');
2269: push(@allsecs,$sec);
2270: }
1.14 raeburn 2271: my $newsec = $env{'form.person_'.$i.'_newsec'};
2272: $newsec =~ s/^\s+//;
2273: $newsec =~s/\s+$//;
1.31 raeburn 2274: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2275: foreach my $sec (@newsecs) {
1.31 raeburn 2276: next unless ($sec =~ /\w/);
1.14 raeburn 2277: next if ($sec =~ /\W/);
1.31 raeburn 2278: next if ($sec eq 'none');
1.14 raeburn 2279: if ($sec ne '') {
2280: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2281: push(@allsecs,$sec);
2282: }
2283: }
2284: }
1.24 raeburn 2285: my $showsec;
1.14 raeburn 2286: if (@allsecs) {
2287: $showsec = join(', ',@allsecs);
2288: }
1.24 raeburn 2289: if ($showsec eq '') {
2290: $showsec = &mt('None');
2291: }
1.41 raeburn 2292: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24 raeburn 2293: $showsec = &mt('None');
2294: }
1.28 raeburn 2295: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2296: $personnel_values .=
1.13 raeburn 2297: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2298: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2299: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2300: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2301: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2302: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2303: }
2304: }
1.30 raeburn 2305: my $output;
2306: if (ref($disallowed) eq 'ARRAY') {
2307: if (@{$disallowed} > 0) {
2308: if (ref($disallowmsg) eq 'HASH') {
2309: $output = '<p class="LC_warning">'.
2310: &mt('Not all requested personnel could be included.').'<ul>';
2311: foreach my $item (@{$disallowed}) {
2312: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2313: }
2314: $output .= '</ul></p>';
2315: }
2316: }
2317: }
2318: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 2319: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 2320: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 2321: '<th>'.&mt('Name').'</th>'.
2322: '<th>'.&mt('Username:Domain').'</th>'.
2323: '<th>'.&mt('E-mail address').'</th>'.
2324: '</tr><tr>'."\n".
2325: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2326: '<td>'.$owneremail.'</td>'.
2327: '</tr></table>'."\n".
2328: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 2329: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 2330: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2331: '<tr>'.$inst_values.'</tr></table>'."\n".
2332: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2333: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 2334: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2335: '<tr>'.$enroll_values.'</tr></table>'."\n".
2336: &Apache::lonhtmlcommon::row_closure();
2337: if ($section_headers ne '') {
2338: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2339: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2340: '<tr>'.$section_values.'</tr></table>'."\n".
2341: &Apache::lonhtmlcommon::row_closure();
2342: }
2343: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2344: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2345: $personnel_values.'</table>'."\n".
2346: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 2347: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 2348: return $output;
2349: }
2350:
2351: sub dates_from_form {
2352: my ($startname,$endname) = @_;
2353: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2354: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 2355: if ($endname eq 'accessend') {
1.4 raeburn 2356: if (exists($env{'form.no_end_date'}) ) {
2357: $enddate = 0;
2358: }
2359: }
2360: return ($startdate,$enddate);
1.1 raeburn 2361: }
2362:
2363: sub courseinfo_form {
1.36 raeburn 2364: my ($dom,$formname,$crstype,$next,$description) = @_;
1.32 raeburn 2365: my %lt = &Apache::lonlocal::texthash(
2366: official => 'You must provide a (brief) course description.',
2367: community => 'You must provide a (brief) community description.'
2368: );
2369: $lt{'unofficial'} = $lt{'official'};
1.15 raeburn 2370: my $js_validate = <<"ENDJS";
2371: <script type="text/javascript">
2372: // <![CDATA['
2373:
2374: function validateForm() {
2375: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.32 raeburn 2376: alert('$lt{$crstype}');
1.15 raeburn 2377: return;
2378: }
2379: nextPage(document.$formname,'$next');
2380: }
1.45 raeburn 2381:
2382: function toggleCloning() {
2383: var willclone;
2384: if (document.$formname.cloning.length > 1) {
2385: for (var i=0; i<document.$formname.cloning.length; i++) {
2386: if (document.$formname.cloning[i].checked) {
2387: willclone = document.$formname.cloning[i].value;
2388: }
2389: }
2390: }
2391: if (willclone == 1) {
2392: document.getElementById('cloneoptions').style.display="block";
2393: } else {
2394: document.getElementById('cloneoptions').style.display="none";
2395: document.$formname.clonecrs.value = '';
2396: }
2397: }
2398:
1.15 raeburn 2399: // ]]
2400: </script>
2401:
2402: ENDJS
1.27 raeburn 2403: my $title = &mt('Brief Course Description');
1.40 raeburn 2404: my $clonetitle = &mt('Clone content and settings from an existing course?');
1.27 raeburn 2405: if ($crstype eq 'community') {
2406: $title = &mt('Brief Community Description');
1.40 raeburn 2407: $clonetitle = &mt('Clone content and settings from an existing community?');
1.27 raeburn 2408: }
1.45 raeburn 2409: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2410: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2411: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 2412: &Apache::lonhtmlcommon::row_closure(1).
2413: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.36 raeburn 2414: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.13 raeburn 2415: my ($home_server_pick,$numlib) =
2416: &Apache::loncommon::home_server_form_item($dom,'chome',
2417: 'default','hide');
2418: if ($numlib > 1) {
2419: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2420: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 2421: }
2422: $output .= $home_server_pick.
1.27 raeburn 2423: &Apache::lonhtmlcommon::row_closure().
2424: &Apache::lonhtmlcommon::row_headline().
1.45 raeburn 2425: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
1.46 wenzelju 2426: &Apache::lonhtmlcommon::row_closure(1).
2427: &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
1.45 raeburn 2428: '<label><input type="radio" name="cloning" value="1" '.
2429: 'onclick="javascript:toggleCloning()" />'.
2430: &mt('Yes').(' 'x2).'</label><label>'.
2431: '<input type="radio" name="cloning" value="0" '.
2432: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
2433: '</h3>'.
1.13 raeburn 2434: &Apache::lonhtmlcommon::row_closure(1).
1.45 raeburn 2435: &Apache::lonhtmlcommon::row_headline().
2436: '<div id="cloneoptions" style="display: none" >'.
2437: &Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2438: &clone_form($dom,$formname,$crstype).
1.45 raeburn 2439: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
2440: &Apache::lonhtmlcommon::end_pick_box()."\n";
1.1 raeburn 2441: return $output;
2442: }
2443:
2444: sub clone_form {
2445: my ($dom,$formname,$crstype) = @_;
2446: my $type = 'Course';
2447: if ($crstype eq 'community') {
2448: $type = 'Community';
2449: }
1.35 raeburn 2450: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').' '.
1.13 raeburn 2451: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 2452: my %lt = &clone_text();
1.2 raeburn 2453: my $output .=
2454: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.29 raeburn 2455: '<input type="text" size="25" name="clonecrs" value="" />'.
1.35 raeburn 2456: '</label>'.&Apache::lonhtmlcommon::row_closure(1).
2457: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
1.27 raeburn 2458: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2459: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2460: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2461: '</label><br /><label>'.
2462: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2463: '</label><br /><label>'.
2464: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2465: $lt{'shd'}.'</label>'.
2466: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 2467: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2468: return $output;
2469: }
2470:
1.16 raeburn 2471: sub clone_text {
1.4 raeburn 2472: return &Apache::lonlocal::texthash(
2473: 'cid' => 'Course ID',
2474: 'dmn' => 'Domain',
2475: 'dsh' => 'Date Shift',
2476: 'ncd' => 'Do not clone date parameters',
2477: 'prd' => 'Clone date parameters as-is',
2478: 'shd' => 'Shift date parameters by number of days',
2479: );
2480: }
2481:
1.1 raeburn 2482: sub coursecode_form {
1.2 raeburn 2483: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 2484: my $output;
1.46 wenzelju 2485: my %rowtitle = &Apache::lonlocal::texthash (
1.2 raeburn 2486: instcode => 'Course Category',
2487: crosslist => 'Cross Listed Course',
2488: );
1.34 raeburn 2489: my %helpitem = (
2490: instcode => 'Course_Request_Category',
2491: crosslist => 'Course_Request_Crosslist',
2492: );
1.1 raeburn 2493: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2494: (ref($cat_order))) {
1.2 raeburn 2495: my ($sel,$instsec,$lcsec);
2496: $sel = $context;
2497: if ($context eq 'crosslist') {
2498: $sel .= '_'.$num;
2499: $instsec = &mt('Institutional section').'<br />'.
2500: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2501: $lcsec = &mt('LON-CAPA section').'<br />'.
2502: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2503: }
1.1 raeburn 2504: if (@{$codetitles} > 0) {
2505: my $lastitem = pop(@{$codetitles});
1.2 raeburn 2506: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 2507: if (@{$codetitles} > 0) {
1.34 raeburn 2508: $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}).
1.2 raeburn 2509: '<table><tr>';
1.1 raeburn 2510: if ($context eq 'crosslist') {
1.2 raeburn 2511: $output .= '<td>'.&mt('Include?').'<br />'.
2512: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 2513: }
2514: foreach my $title (@{$codetitles}) {
2515: if (ref($cat_order->{$title}) eq 'ARRAY') {
2516: if (@{$cat_order->{$title}} > 0) {
2517: $output .= '<td align="center">'.$title.'<br />'."\n".
2518: '<select name="'.$sel.'_'.$title.'">'."\n".
2519: ' <option value="" selected="selected">'.
2520: &mt('Select').'</option>'."\n";
2521: foreach my $item (@{$cat_order->{$title}}) {
2522: my $longitem = $item;
2523: if (ref($cat_titles->{$title}) eq 'HASH') {
2524: if ($cat_titles->{$title}{$item} ne '') {
2525: $longitem = $cat_titles->{$title}{$item};
2526: }
2527: }
2528: $output .= '<option value="'.$item.'">'.$longitem.
2529: '</option>'."\n";
2530: }
2531: }
2532: $output .= '</select></td>'."\n";
2533: }
2534: }
2535: if ($context eq 'crosslist') {
2536: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 2537: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2538: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 2539: } else {
2540: $output .= '</tr></table>'.
2541: &Apache::lonhtmlcommon::row_closure().
2542: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2543: $lastinput;
2544: }
2545: } else {
2546: if ($context eq 'crosslist') {
2547: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 2548: '<table><tr>'.
2549: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2550: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2551: '</tr></table>';
1.1 raeburn 2552: } else {
2553: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2554: $lastinput;
2555: }
2556: }
1.2 raeburn 2557: $output .= &Apache::lonhtmlcommon::row_closure(1);
2558: push(@$codetitles,$lastitem);
2559: } elsif ($context eq 'crosslist') {
2560: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2561: '<table><tr><td align="center">'.
2562: '<span class="LC_nobreak">'.&mt('Include?').
2563: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2564: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2565: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2566: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2567: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2568: }
2569: }
2570: return $output;
2571: }
2572:
2573: sub get_course_dom {
2574: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 2575: if ($env{'form.showdom'} ne '') {
2576: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2577: return $env{'form.showdom'};
2578: }
2579: }
1.1 raeburn 2580: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37 raeburn 2581: my ($types,$typename) = &Apache::loncommon::course_types();
1.19 raeburn 2582: if (ref($types) eq 'ARRAY') {
2583: foreach my $type (@{$types}) {
2584: if (&Apache::lonnet::usertools_access($env{'user.name'},
2585: $env{'user.domain'},$type,
2586: undef,'requestcourses')) {
2587: return $env{'user.domain'};
2588: }
2589: }
2590: my @possible_doms;
2591: foreach my $type (@{$types}) {
2592: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2593: if ($dom_str ne '') {
2594: my @domains = split(',',$dom_str);
2595: foreach my $entry (@domains) {
2596: my ($extdom,$extopt) = split(':',$entry);
2597: if ($extdom eq $env{'request.role.domain'}) {
2598: return $extdom;
2599: }
2600: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2601: push(@possible_doms,$extdom);
2602: }
2603: }
2604: }
2605: }
2606: if (@possible_doms) {
2607: @possible_doms = sort(@possible_doms);
2608: return $possible_doms[0];
2609: }
2610: }
1.1 raeburn 2611: $codedom = $env{'user.domain'};
2612: if ($env{'request.role.domain'} ne '') {
2613: $codedom = $env{'request.role.domain'};
2614: }
2615: }
2616: return $codedom;
2617: }
2618:
2619: sub display_navbuttons {
1.31 raeburn 2620: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 2621: $r->print('<div class="LC_navbuttons">');
2622: if ($prev) {
1.16 raeburn 2623: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 2624: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 2625: (' 'x3));
1.1 raeburn 2626: } elsif ($prevtext) {
1.16 raeburn 2627: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2628: 'onclick="javascript:history.back()"/>'.(' 'x3));
2629: }
2630: if ($state eq 'details') {
2631: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 2632: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 2633: ')" />');
1.1 raeburn 2634: }
1.31 raeburn 2635: my $gotnext;
1.15 raeburn 2636: if ($state eq 'courseinfo') {
1.16 raeburn 2637: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2638: 'onclick="javascript:validateForm();" />');
1.31 raeburn 2639: $gotnext = 1;
2640: } elsif ($state eq 'enrollment') {
2641: if (($env{'form.crstype'} eq 'official') &&
2642: (&Apache::lonnet::auto_run('',$dom))) {
2643: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2644: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
2645: $gotnext = 1;
2646: }
2647: } elsif ($state eq 'personnel') {
2648: if ($env{'form.persontotal'} > 0) {
2649: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2650: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
2651: $gotnext = 1;
2652: }
2653: }
2654: unless ($gotnext) {
2655: if ($next) {
2656: $r->print('
2657: <input type="button" name="next" value="'.$nexttext.'" '.
2658: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
2659: }
1.1 raeburn 2660: }
2661: $r->print('</div>');
2662: }
2663:
2664: sub print_request_outcome {
1.10 raeburn 2665: my ($dom,$codetitles,$code_order) = @_;
1.13 raeburn 2666: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 2667: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 2668: my $sectotal = $env{'form.sectotal'};
2669: my $crosslisttotal = 0;
1.10 raeburn 2670: $cnum = $env{'form.cnum'};
1.8 raeburn 2671: unless ($cnum =~ /^$match_courseid$/) {
2672: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2673: return $output;
2674: }
1.11 raeburn 2675:
1.10 raeburn 2676: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 2677: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2678: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2679: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2680: }
2681: }
1.10 raeburn 2682: $now = time;
2683: $crstype = $env{'form.crstype'};
1.41 raeburn 2684: my $ccrole = 'cc';
2685: if ($crstype eq 'community') {
2686: $ccrole = 'co';
2687: }
1.17 raeburn 2688: my @instsections;
1.8 raeburn 2689: if ($crstype eq 'official') {
2690: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 2691: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 2692: }
1.10 raeburn 2693: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2694: if ($env{'form.sec_'.$i}) {
2695: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 2696: my $sec = $env{'form.secnum_'.$i};
2697: $sections{$i}{'inst'} = $sec;
2698: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2699: push(@instsections,$sec);
2700: }
1.13 raeburn 2701: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.10 raeburn 2702: }
2703: }
2704: }
2705: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2706: if ($env{'form.crosslist_'.$i}) {
2707: my $xlistinfo = '';
2708: if (ref($code_order) eq 'ARRAY') {
2709: if (@{$code_order} > 0) {
2710: foreach my $item (@{$code_order}) {
2711: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
2712: }
2713: }
2714: }
1.22 raeburn 2715: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 2716: if ($xlistinfo ne '') {
2717: $crosslisttotal ++;
2718: }
1.22 raeburn 2719: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 2720: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 2721: }
2722: }
1.14 raeburn 2723: } else {
2724: $enrollstart = '';
2725: $enrollend = '';
1.10 raeburn 2726: }
2727: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2728: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 2729: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 2730: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
2731: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 2732: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
2733: $personnel{$uname.':'.$udom} = {
2734: firstname => $env{'form.person_'.$i.'_firstname'},
2735: lastname => $env{'form.person_'.$i.'_lastname'},
2736: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
2737: };
2738: }
2739: my $role = $env{'form.person_'.$i.'_role'};
2740: unless ($role eq '') {
1.16 raeburn 2741: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 2742: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
2743: unless (grep(/^\Q$role\E$/,@curr_roles)) {
2744: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
2745: }
2746: } else {
2747: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
2748: }
1.41 raeburn 2749: if ($role eq $ccrole) {
1.13 raeburn 2750: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
2751: } else {
1.14 raeburn 2752: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 2753: my @allsecs;
2754: foreach my $sec (@currsec) {
2755: next unless ($sec =~ /\w/);
2756: next if ($sec =~ /\W/);
2757: next if ($sec eq 'none');
2758: push(@allsecs,$sec);
2759: }
1.14 raeburn 2760: my $newsec = $env{'form.person_'.$i.'_newsec'};
2761: $newsec =~ s/^\s+//;
2762: $newsec =~s/\s+$//;
2763: my @newsecs = split(/[\s,;]+/,$newsec);
2764: foreach my $sec (@newsecs) {
2765: next if ($sec =~ /\W/);
1.31 raeburn 2766: next if ($sec eq 'none');
1.14 raeburn 2767: if ($sec ne '') {
1.31 raeburn 2768: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2769: push(@allsecs,$sec);
1.13 raeburn 2770: }
2771: }
2772: }
1.31 raeburn 2773: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 2774: }
2775: }
1.10 raeburn 2776: } else {
2777: push(@missingdom,$uname.':'.$udom);
2778: }
2779: } else {
2780: push(@baduname,$uname.':'.$udom);
2781: }
1.8 raeburn 2782: }
1.13 raeburn 2783: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 2784: my $autodrops = 0;
2785: if ($env{'form.autodrops'}) {
2786: $autodrops = $env{'form.autodrops'};
2787: }
2788: my $autoadds = 0;
2789: if ($env{'form.autoadds'}) {
2790: $autodrops = $env{'form.autoadds'};
2791: }
2792: if ($env{'form.autoadds'}) {
2793: $autodrops = $env{'form.autoadds'};
2794: }
2795: my $instcode = '';
2796: if (exists($env{'form.instcode'})) {
2797: $instcode = $env{'form.instcode'};
2798: }
1.15 raeburn 2799: my $clonecrs = '';
2800: my $clonedom = '';
1.45 raeburn 2801: if (($env{'form.cloning'}) &&
2802: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
1.15 raeburn 2803: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 2804: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
2805: $env{'form.clonedom'});
1.15 raeburn 2806: if ($clonehome ne 'no_host') {
1.16 raeburn 2807: my $canclone =
2808: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 2809: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
2810: $crstype);
1.15 raeburn 2811: if ($canclone) {
2812: $clonecrs = $env{'form.clonecrs'};
2813: $clonedom = $env{'form.clonedom'};
2814: }
2815: }
2816: }
1.8 raeburn 2817: my $details = {
1.10 raeburn 2818: owner => $env{'user.name'},
2819: domain => $env{'user.domain'},
2820: cdom => $dom,
1.11 raeburn 2821: cnum => $cnum,
1.13 raeburn 2822: coursehome => $env{'form.chome'},
2823: cdescr => $env{'form.cdescr'},
1.10 raeburn 2824: crstype => $env{'form.crstype'},
1.14 raeburn 2825: instcode => $instcode,
1.15 raeburn 2826: clonedom => $clonedom,
2827: clonecrs => $clonecrs,
1.10 raeburn 2828: datemode => $env{'form.datemode'},
1.14 raeburn 2829: dateshift => $env{'form.dateshift'},
2830: sectotal => $sectotal,
1.10 raeburn 2831: sections => \%sections,
1.14 raeburn 2832: crosslisttotal => $crosslisttotal,
1.13 raeburn 2833: crosslists => \%crosslistings,
1.14 raeburn 2834: autoadds => $autoadds,
2835: autodrops => $autodrops,
1.13 raeburn 2836: enrollstart => $enrollstart,
2837: enrollend => $enrollend,
2838: accessstart => $accessstart,
2839: accessend => $accessend,
1.10 raeburn 2840: personnel => \%personnel,
1.8 raeburn 2841: };
1.27 raeburn 2842: my (@inststatuses,$storeresult,$creationresult);
1.43 raeburn 2843: my $val =
2844: &Apache::loncoursequeueadmin::get_processtype($env{'user.name'},$env{'user.domain'},
2845: $env{'user.adv'},$dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 2846: if ($val eq '') {
2847: if ($crstype eq 'official') {
1.19 raeburn 2848: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 2849: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 2850: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 2851: } elsif ($crstype eq 'community') {
2852: $output = &mt('You are not permitted to request creation of communities');
2853: } else {
2854: $output = &mt('Unrecognized course type: [_1]',$crstype);
2855: }
1.27 raeburn 2856: $storeresult = 'notpermitted';
1.8 raeburn 2857: } else {
1.14 raeburn 2858: my ($disposition,$message,$reqstatus);
1.8 raeburn 2859: my %reqhash = (
1.14 raeburn 2860: reqtime => $now,
1.10 raeburn 2861: crstype => $crstype,
2862: details => $details,
1.8 raeburn 2863: );
2864: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 2865: my $validationerror;
1.10 raeburn 2866: if ($val eq 'autolimit=') {
2867: $disposition = 'process';
2868: } elsif ($val =~ /^autolimit=(\d+)$/) {
2869: my $limit = $1;
1.8 raeburn 2870: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 2871: $dom,$crstype,$limit,\$message);
1.8 raeburn 2872: } elsif ($val eq 'validate') {
1.21 raeburn 2873: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 2874: if (@inststatuses > 0) {
2875: $inststatuslist = join(',',@inststatuses);
2876: }
2877: my $instseclist;
2878: if (@instsections > 0) {
2879: $instseclist = join(',',@instsections);
2880: }
1.21 raeburn 2881: $validationchk =
2882: &Apache::lonnet::auto_courserequest_validation($dom,
2883: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
2884: $inststatuslist,$instcode,$instseclist);
2885: if ($validationchk =~ /:/) {
2886: ($validation,$message) = split(':',$validationchk);
2887: } else {
2888: $validation = $validationchk;
2889: }
2890: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 2891: $disposition = 'approval';
2892: $validationerror = $1;
1.23 raeburn 2893: } else {
2894: $disposition = $validation;
1.17 raeburn 2895: }
1.8 raeburn 2896: } else {
2897: $disposition = 'approval';
2898: }
1.14 raeburn 2899: $reqhash{'disposition'} = $disposition;
2900: $reqstatus = $disposition;
1.16 raeburn 2901: my ($modified,$queued);
1.8 raeburn 2902: if ($disposition eq 'rejected') {
1.40 raeburn 2903: if ($crstype eq 'community') {
2904: $output = &mt('Your community request was rejected.');
2905: } else {
2906: $output = &mt('Your course request was rejected.');
2907: }
1.8 raeburn 2908: if ($message) {
2909: $output .= '<div class="LC_warning">'.$message.'</div>';
2910: }
1.27 raeburn 2911: $storeresult = 'rejected';
1.8 raeburn 2912: } elsif ($disposition eq 'process') {
1.14 raeburn 2913: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
2914: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
1.8 raeburn 2915: my $type = 'Course';
2916: if ($crstype eq 'community') {
2917: $type = 'Community';
2918: }
1.41 raeburn 2919: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8 raeburn 2920: foreach my $role (@roles) {
2921: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
2922: }
1.14 raeburn 2923: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
2924: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
2925: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
2926: if ($result eq 'created') {
1.8 raeburn 2927: $disposition = 'created';
1.14 raeburn 2928: $reqstatus = 'created';
1.28 raeburn 2929: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
2930: \%longroles);
1.40 raeburn 2931: if ($crstype eq 'community') {
2932: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
2933: } else {
2934: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
2935: }
2936: $output .= '<br />'.$role_result.'</p>';
1.27 raeburn 2937: $creationresult = 'created';
1.8 raeburn 2938: } else {
1.40 raeburn 2939: $output = '<span class="LC_error">';
2940: if ($crstype eq 'community') {
2941: $output .= &mt('An error occurred when processing your community request.');
2942: } else {
2943: $output .= &mt('An error occurred when processing your course request.');
2944: }
2945: $output .= '<br />'.
2946: &mt('You may want to review the request details and submit the request again.').
1.14 raeburn 2947: '</span>';
1.27 raeburn 2948: $creationresult = 'error';
1.8 raeburn 2949: }
2950: } else {
2951: my $requestid = $cnum.'_'.$disposition;
2952: my $request = {
2953: $requestid => {
2954: timestamp => $now,
2955: crstype => $crstype,
2956: ownername => $env{'user.name'},
2957: ownerdom => $env{'user.domain'},
1.13 raeburn 2958: description => $env{'form.cdescr'},
1.8 raeburn 2959: },
2960: };
1.16 raeburn 2961: my $statuskey = 'status:'.$dom.':'.$cnum;
2962: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
2963: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 2964: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 2965: $modified = 1;
1.25 raeburn 2966: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
2967: my %queuehash = &Apache::lonnet::get('courserequestqueue',
2968: [$cnum.'_approval',
2969: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 2970: if (($queuehash{$cnum.'_approval'} ne '') ||
2971: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 2972: $queued = 1;
2973: }
2974: }
2975: unless ($queued) {
2976: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
2977: $dom);
2978: if ($putresult eq 'ok') {
1.40 raeburn 2979: if ($crstype eq 'community') {
2980: $output .= &mt('Your community request has been recorded.');
2981: } else {
2982: $output .= &mt('Your course request has been recorded.')
2983: }
2984: $output .= '<br />'.
1.16 raeburn 2985: ¬ification_information($disposition,$req_notifylist,
2986: $cnum,$now);
1.8 raeburn 2987: } else {
1.16 raeburn 2988: $reqstatus = 'domainerror';
2989: $reqhash{'disposition'} = $disposition;
2990: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
2991: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 2992: }
2993: }
2994: }
1.44 raeburn 2995: ($storeresult,my $updateresult) =
2996: &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
2997: $cnum,$reqstatus,'request');
1.16 raeburn 2998: if ($modified && $queued && $storeresult eq 'ok') {
1.40 raeburn 2999: if ($crstype eq 'community') {
3000: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
3001: } else {
3002: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
3003: }
3004: $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
1.16 raeburn 3005: }
1.17 raeburn 3006: if ($validationerror ne '') {
1.44 raeburn 3007: $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
3008: }
3009: if ($updateresult) {
3010: $output .= $updateresult;
1.17 raeburn 3011: }
1.16 raeburn 3012: }
1.27 raeburn 3013: if ($creationresult ne '') {
3014: return ($creationresult,$output);
3015: } else {
3016: return ($storeresult,$output);
3017: }
1.16 raeburn 3018: }
3019:
1.28 raeburn 3020: sub update_requestors_roles {
3021: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3022: my $now = time;
3023: my ($active,$future,$numactive,$numfuture,$output);
3024: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3025: if (ref($details) eq 'HASH') {
3026: if (ref($details->{'personnel'}) eq 'HASH') {
1.41 raeburn 3027: my $ccrole = 'cc';
3028: if ($crstype eq 'community') {
3029: $ccrole = 'co';
3030: }
1.35 raeburn 3031: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3032: $details->{'personnel'}{$owner} = {
1.41 raeburn 3033: 'roles' => [$ccrole],
3034: $ccrole => { 'usec' => [] },
1.35 raeburn 3035: };
3036: }
3037: my @roles;
3038: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3039: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41 raeburn 3040: unless (grep(/^\Q$ccrole\E$/,@roles)) {
3041: push(@roles,$ccrole);
1.35 raeburn 3042: }
3043: } else {
1.41 raeburn 3044: @roles = ($ccrole);
1.35 raeburn 3045: }
3046: foreach my $role (@roles) {
1.42 raeburn 3047: my $refresh=$env{'user.refresh.time'};
3048: if ($refresh eq '') {
3049: $refresh = $env{'user.login.time'};
3050: }
3051: if ($refresh eq '') {
3052: $refresh = $now;
3053: }
3054: my $start = $refresh-1;
1.35 raeburn 3055: my $end = '0';
3056: if ($role eq 'st') {
3057: if ($details->{'accessstart'} ne '') {
3058: $start = $details->{'accessstart'};
3059: }
3060: if ($details->{'accessend'} ne '') {
3061: $end = $details->{'accessend'};
3062: }
3063: }
3064: my @usecs;
1.41 raeburn 3065: if ($role ne $ccrole) {
1.35 raeburn 3066: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3067: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3068: }
3069: }
3070: if ($role eq 'st') {
3071: if (@usecs > 1) {
3072: my $firstsec = $usecs[0];
3073: @usecs = ($firstsec);
3074: }
3075: }
3076: if (@usecs == 0) {
3077: push(@usecs,'');
3078: }
3079: foreach my $usec (@usecs) {
3080: my (%userroles,%newrole,%newgroups,$spec,$area);
3081: my $area = '/'.$dom.'/'.$cnum;
3082: my $spec = $role.'.'.$area;
3083: if ($usec ne '') {
3084: $spec .= '/'.$usec;
3085: $area .= '/'.$usec;
3086: }
3087: if ($role =~ /^cr\//) {
3088: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
3089: $cnum,$spec,$area);
3090: } else {
3091: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
3092: $spec,$cnum,$area);
1.28 raeburn 3093: }
1.35 raeburn 3094: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
3095: \%newgroups);
3096: $userroles{'user.role.'.$spec} = $start.'.'.$end;
3097: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
3098: if (($end == 0) || ($end > $now)) {
3099: my $showrole = $role;
1.28 raeburn 3100: if ($role =~ /^cr\//) {
1.35 raeburn 3101: $showrole = &Apache::lonnet::plaintext($role,$crstype);
3102: } elsif (ref($longroles) eq 'HASH') {
3103: if ($longroles->{$role} ne '') {
3104: $showrole = $longroles->{$role};
3105: }
1.28 raeburn 3106: }
1.35 raeburn 3107: if ($start <= $now) {
3108: $active .= '<li><a href="/adm/roles?selectrole=1&'.
3109: $spec.'=1">'.$showrole;
3110: if ($usec ne '') {
3111: $active .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3112: }
1.35 raeburn 3113: $active .= '</a></li>';
3114: $numactive ++;
3115: } else {
3116: $future .= '<li>'.$showrole;
3117: if ($usec ne '') {
3118: $future .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3119: }
1.35 raeburn 3120: $future .= '</li>';
3121: $numfuture ++;
1.28 raeburn 3122: }
3123: }
3124: }
3125: }
3126: }
3127: }
3128: if ($active) {
3129: if ($numactive == 1) {
1.41 raeburn 3130: if ($crstype eq 'Community') {
3131: $output = &mt('Use the following link to enter the community:');
3132: } else {
3133: $output = &mt('Use the following link to enter the course:');
3134: }
1.28 raeburn 3135: } else {
1.41 raeburn 3136: if ($crstype eq 'Community') {
3137: $output = &mt('Use the following links to your new roles to enter the community:');
3138: } else {
3139: $output = &mt('Use the following links to your new roles to enter the course:');
3140: }
1.28 raeburn 3141: }
3142: $output .= ' <ul>'.$active.'</ul><br />';
3143: }
3144: if ($future) {
1.41 raeburn 3145: if ($crstype eq 'Community') {
3146: $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'}))
3147: } else {
3148: $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'}));
3149: }
3150: $output .= ' <ul>'.$future.'</ul>';
1.28 raeburn 3151: }
3152: return $output;
3153: }
3154:
1.16 raeburn 3155: sub notification_information {
3156: my ($disposition,$req_notifylist,$cnum,$now) = @_;
3157: my %emails = &Apache::loncommon::getemails();
3158: my $address;
3159: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
3160: $address = $emails{'permanentemail'};
3161: if ($address eq '') {
3162: $address = $emails{'notification'};
3163: }
3164: }
3165: my $output;
3166: if ($disposition eq 'approval') {
3167: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
3168: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
3169: if ($address ne '') {
3170: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
3171: }
3172: if ($req_notifylist) {
3173: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3174: $env{'user.domain'});
3175: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3176: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
3177: }
1.17 raeburn 3178: } elsif ($disposition eq 'pending') {
1.16 raeburn 3179: $output .= '<div class="LC_info">'.
3180: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
3181: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
3182: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
3183: '</div>';
1.17 raeburn 3184: } else {
3185: $output .= '<div class="LC_warning">'.
1.44 raeburn 3186: &mt('Your request status is: [_1].',$disposition).
3187: '</div>';
1.8 raeburn 3188: }
3189: return $output;
3190: }
3191:
3192: sub check_autolimit {
1.10 raeburn 3193: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3194: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41 raeburn 3195: 'userroles',['active','future'],['cc','co'],[$dom]);
1.37 raeburn 3196: my ($types,$typename) = &Apache::loncommon::course_types();
1.10 raeburn 3197: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41 raeburn 3198: my $count = 0;
1.10 raeburn 3199: foreach my $key (keys(%requests)) {
3200: my ($cdom,$cnum) = split('_',$key);
1.41 raeburn 3201: if (ref($requests{$key}) eq 'HASH') {
3202: next if ($requests{$key}{'crstype'} ne $crstype);
3203: if (($crstype eq 'community') &&
3204: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
3205: $count ++;
3206: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
3207: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
3208: $count ++;
1.10 raeburn 3209: }
3210: }
3211: }
1.41 raeburn 3212: if ($count < $limit) {
1.10 raeburn 3213: return 'process';
3214: } else {
3215: if (ref($typename) eq 'HASH') {
1.41 raeburn 3216: if ($crstype eq 'community') {
3217: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
3218: '<br />'.&mt("Your limit is [_1].",$limit);
3219: } else {
3220: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
3221: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
3222: }
1.10 raeburn 3223: }
3224: return 'rejected';
3225: }
1.1 raeburn 3226: return;
3227: }
3228:
1.2 raeburn 3229: sub retrieve_settings {
1.26 raeburn 3230: my ($dom,$cnum,$udom,$uname) = @_;
3231: if ($udom eq '' || $uname eq '') {
3232: $udom = $env{'user.domain'};
3233: $uname = $env{'user.name'};
3234: }
3235: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 3236: if ($result eq 'ok') {
1.26 raeburn 3237: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 3238: $env{'form.chome'} = $reqinfo{'coursehome'};
3239: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3240: $env{'form.crstype'} = $reqinfo{'crstype'};
3241: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3242: &generate_date_items($reqinfo{'accessend'},'accessend');
3243: if ($reqinfo{'accessend'} == 0) {
3244: $env{'form.no_end_date'} = 1;
3245: }
3246: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3247: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3248: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3249: }
3250: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3251: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3252: $env{'form.datemode'} = $reqinfo{'datemode'};
3253: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3254: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
3255: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3256: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3257: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3258: $env{'form.autdrops'} = $reqinfo{'autodrops'};
3259: $env{'form.instcode'} = $reqinfo{'instcode'};
1.24 raeburn 3260: my $crscode = {
3261: $cnum => $reqinfo{'instcode'},
3262: };
3263: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16 raeburn 3264: }
3265: my @currsec;
3266: if (ref($reqinfo{'sections'}) eq 'HASH') {
3267: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3268: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 3269: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 3270: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 3271: $env{'form.sec_'.$i} = '1';
1.16 raeburn 3272: if (!grep(/^\Q$sec\E$/,@currsec)) {
3273: push(@currsec,$sec);
3274: }
3275: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3276: }
3277: }
3278: }
1.24 raeburn 3279: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3280: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3281: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3282: $env{'form.crosslist_'.$i} = '1';
3283: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3284: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3285: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3286: my $key = $cnum.$i;
3287: my $crscode = {
3288: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3289: };
3290: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3291: }
1.16 raeburn 3292: }
3293: }
3294: }
3295: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3296: my $i = 0;
3297: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3298: my ($uname,$udom) = split(':',$user);
3299: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3300: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3301: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3302: $env{'form.person_'.$i.'_role'} = $role;
3303: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3304: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3305: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3306: $env{'form.person_'.$i.'_uname'} = $uname;
3307: $env{'form.person_'.$i.'_dom'} = $udom;
3308: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3309: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3310: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3311: my @newsecs;
3312: if (@usecs > 0) {
3313: foreach my $sec (@usecs) {
3314: if (grep(/^\Q$sec\E/,@currsec)) {
3315: $env{'form.person_'.$i.'_sec'} = $sec;
3316: } else {
1.20 raeburn 3317: push(@newsecs,$sec);
1.16 raeburn 3318: }
3319: }
3320: }
3321: if (@newsecs > 0) {
3322: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3323: }
3324: }
3325: }
3326: $i ++;
3327: }
3328: }
3329: }
3330: }
3331: $env{'form.persontotal'} = $i;
3332: }
3333: }
3334: }
3335: return $result;
3336: }
3337:
3338: sub get_request_settings {
1.26 raeburn 3339: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 3340: my $requestkey = $dom.'_'.$cnum;
3341: my ($result,%reqinfo);
3342: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 3343: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 3344: my $disposition = $history{'disposition'};
3345: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3346: if (ref($history{'details'}) eq 'HASH') {
3347: %reqinfo = %{$history{'details'}};
3348: $result = 'ok';
3349: } else {
3350: $result = 'nothash';
3351: }
3352: } else {
3353: $result = 'notqueued';
3354: }
3355: } else {
3356: $result = 'invalid';
3357: }
3358: return ($result,%reqinfo);
3359: }
1.2 raeburn 3360:
1.16 raeburn 3361: sub extract_instcode {
1.24 raeburn 3362: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 3363: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 3364: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3365: \@codetitles,\%cat_titles,
3366: \%cat_order) eq 'ok') {
3367: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 3368: if (@codetitles > 0) {
3369: my $sel = $element;
3370: if ($element eq 'crosslist') {
3371: $sel .= '_'.$counter;
3372: }
3373: foreach my $title (@codetitles) {
1.24 raeburn 3374: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 3375: }
3376: }
3377: }
3378: }
3379: return;
1.2 raeburn 3380: }
3381:
1.16 raeburn 3382: sub generate_date_items {
3383: my ($currentval,$item) = @_;
3384: if ($currentval =~ /\d+/) {
3385: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
3386: &Apache::lonhtmlcommon::get_timedates($currentval);
3387: $env{'form.'.$item.'_day'} = $mday;
3388: $env{'form.'.$item.'_month'} = $month+1;
3389: $env{'form.'.$item.'_year'} = $year;
3390: }
3391: return;
1.2 raeburn 3392: }
3393:
1.1 raeburn 3394: 1;
3395:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>