Annotation of loncom/interface/lonrequestcourse.pm, revision 1.86
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.86 ! raeburn 4: # $Id: lonrequestcourse.pm,v 1.85 2014/06/16 01:42:22 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: =head1 NAME
31:
32: Apache::lonrequestcourse.pm
33:
34: =head1 SYNOPSIS
35:
36: Allows users to request creation of new courses.
37:
38: This is part of the LearningOnline Network with CAPA project
39: described at http://www.lon-capa.org.
40:
41: =head1 SUBROUTINES
42:
43: =over
44:
45: =item handler()
46:
1.27 raeburn 47: =item get_breadcrumbs()
48:
1.12 raeburn 49: =item header()
50:
51: =item form_elements()
52:
53: =item onload_action()
54:
55: =item print_main_menu()
56:
57: =item request_administration()
58:
1.27 raeburn 59: =item close_popup_form()
60:
61: =item get_instcode()
62:
1.12 raeburn 63: =item print_request_form()
64:
65: =item print_enrollment_menu()
66:
1.27 raeburn 67: =item show_invalid_crosslists()
68:
1.12 raeburn 69: =item inst_section_selector()
70:
71: =item date_setting_table()
72:
73: =item print_personnel_menu()
74:
75: =item print_request_status()
76:
77: =item print_request_logs()
78:
79: =item print_review()
80:
81: =item dates_from_form()
82:
83: =item courseinfo_form()
84:
85: =item clone_form()
86:
87: =item clone_text()
88:
89: =item coursecode_form()
90:
91: =item get_course_dom()
92:
93: =item display_navbuttons()
94:
95: =item print_request_outcome()
96:
97: =item check_autolimit()
98:
99: =item retrieve_settings()
100:
101: =item get_request_settings()
102:
1.27 raeburn 103: =item extract_instcode()
104:
105: =item generate_date_items()
106:
1.1 raeburn 107: =back
108:
109: =cut
110:
111: package Apache::lonrequestcourse;
112:
113: use strict;
114: use Apache::Constants qw(:common :http);
115: use Apache::lonnet;
116: use Apache::loncommon;
117: use Apache::lonlocal;
1.8 raeburn 118: use Apache::loncoursequeueadmin;
1.30 raeburn 119: use Apache::lonuserutils;
1.4 raeburn 120: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 121:
122: sub handler {
123: my ($r) = @_;
1.20 raeburn 124: &Apache::loncommon::content_type($r,'text/html');
125: $r->send_http_header;
1.1 raeburn 126: if ($r->header_only) {
127: return OK;
128: }
129:
1.27 raeburn 130: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.73 raeburn 131: ['action','showdom','cnum','state','crstype','queue','tabs']);
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);
1.72 raeburn 137: my ($jscript,$uname,$udom,$result,$warning,$showcredits,$instcredits,%can_request,
138: %request_domains,@incdoms);
1.66 raeburn 139: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1.69 raeburn 140: if ($domdefs{'officialcredits'} || $domdefs{'unofficialcredits'} || $domdefs{'textbookcredits'}) {
1.66 raeburn 141: $showcredits = 1;
142: }
1.27 raeburn 143:
1.72 raeburn 144: my $canreq =
145: &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
146:
147: foreach my $item (keys(%request_domains)) {
148: if (ref($request_domains{$item}) eq 'ARRAY') {
149: foreach my $possdom (@{$request_domains{$item}}) {
150: unless(grep(/^\Q$possdom\E$/,@incdoms)) {
151: push(@incdoms,$possdom);
152: }
153: }
154: }
155: }
156:
157: if ($canreq) {
1.73 raeburn 158: if (($env{'form.crstype'} eq 'textbook') ||
159: (scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
1.72 raeburn 160: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
161: if ($action eq 'log') {
1.73 raeburn 162: my $usetabs;
163: if ((scalar(keys(%can_request)) == 1) && ($can_request{'textbook'})) {
164: $usetabs = 1;
165: } elsif ($env{'form.tabs'} eq 'on') {
166: $usetabs = 1;
167: }
1.72 raeburn 168: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
169: my $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests');
1.73 raeburn 170: &print_request_logs($r,$dom,undef,undef,$crumb,$usetabs);
1.72 raeburn 171: } elsif ($action eq 'process') {
1.73 raeburn 172: if ($can_request{'textbook'}) {
173: &process_textbook_request($r,$dom,$action,\%domdefs,\%domconfig,\%can_request);
174: } else {
1.85 raeburn 175: &textbook_request_disabled($r,$dom,$action,\%can_request);
1.73 raeburn 176: }
1.83 raeburn 177: } elsif ($action eq 'display') {
178: my ($uname,$udom,$result,$warning) = &domcoord_display($dom);
179: if ($warning ne '') {
180: my $args = { only_body => 1 };
181: $r->print(&header('Course/Community Requests','','' ,'',$args).
182: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
183: '<div class="LC_warning">'.$warning.'</div>'.
184: &close_popup_form());
185: } else {
186: $states{'display'} = ['details'];
187: my $loaditems = &onload_action($action,$state);
188: my $page = 0;
189: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
190: $loaditems,'','','','','',$showcredits,'','',
191: $uname,$udom);
192: }
1.72 raeburn 193: } else {
1.73 raeburn 194: if ($can_request{'textbook'}) {
195: &print_textbook_form($r,$dom,\@incdoms,\%domdefs,$domconfig{'requestcourses'},\%can_request);
196: } else {
1.85 raeburn 197: &textbook_request_disabled($r,$dom,$action,\%can_request);
1.73 raeburn 198: }
1.72 raeburn 199: }
200: return OK;
201: }
202: }
203:
1.27 raeburn 204: $states{'display'} = ['details'];
205: $states{'view'} = ['pick_request','details','cancel','removal'];
1.48 raeburn 206: $states{'log'} = ['display'];
1.27 raeburn 207: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
208:
209: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
210: unless ($env{'form.state'} eq 'crstype') {
211: unshift(@{$states{'new'}},'codepick');
212: }
213: }
214:
1.65 raeburn 215: if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) {
216: if (ref($states{$action}) eq 'ARRAY') {
217: push(@{$states{$action}},'reqauthor');
218: }
219: }
220:
1.27 raeburn 221: foreach my $key (keys(%states)) {
222: if (ref($states{$key}) eq 'ARRAY') {
223: unshift (@{$states{$key}},'crstype');
224: }
225: }
226:
227: my @invalidcrosslist;
228: my %trail = (
1.73 raeburn 229: crstype => 'Pick Action',
1.27 raeburn 230: codepick => 'Category',
231: courseinfo => 'Description',
232: enrollment => 'Access Dates',
233: personnel => 'Personnel',
234: review => 'Review',
235: process => 'Result',
1.65 raeburn 236: reqauthor => 'Authoring Space Result',
1.27 raeburn 237: pick_request => 'Display Summary',
238: details => 'Request Details',
239: cancel => 'Cancel Request',
240: removal => 'Outcome',
1.48 raeburn 241: display => 'Request Logs',
1.27 raeburn 242: );
243:
244: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
245: $trail{'enrollment'} = 'Enrollment';
246: }
247:
1.66 raeburn 248: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
1.27 raeburn 249: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26 raeburn 250: if ($action eq 'display') {
1.83 raeburn 251: ($uname,$udom,$result,$warning) = &domcoord_display($dom);
1.26 raeburn 252: } elsif ((defined($state)) && (defined($action))) {
1.16 raeburn 253: if (($action eq 'view') && ($state eq 'details')) {
254: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
255: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2 raeburn 256: }
1.27 raeburn 257: } elsif ($env{'form.crstype'} eq 'official') {
258: if (&Apache::lonnet::auto_run('',$dom)) {
259: if (($action eq 'new') && (($state eq 'enrollment') ||
260: ($state eq 'personnel'))) {
261: my $checkcrosslist = 0;
262: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
263: if ($env{'form.crosslist_'.$i}) {
264: $checkcrosslist ++;
265: }
266: }
267: if ($checkcrosslist) {
268: my %codechk;
269: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
270: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
271: \%cat_titles,
272: \%cat_order,
273: \@code_order);
274: my $numtitles = scalar(@codetitles);
275: if ($numtitles) {
276: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
277: if ($env{'form.crosslist_'.$i}) {
278: my $codecheck;
279: my $crosslistcode = '';
280: foreach my $item (@code_order) {
281: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
282: }
283: if ($crosslistcode ne '') {
1.36 raeburn 284: ($codechk{$i}, my $rest) =
1.27 raeburn 285: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
286: }
287: unless ($codechk{$i} eq 'valid') {
288: $env{'form.crosslist_'.$i} = '';
289: push(@invalidcrosslist,$crosslistcode);
290: }
291: }
292: }
293: }
294: }
295: }
296: }
1.2 raeburn 297: }
1.66 raeburn 298: (my $elements,$instcredits) = &form_elements($dom,$showcredits);
1.2 raeburn 299: my $elementsref = {};
1.66 raeburn 300: if ((ref($elements) eq 'HASH') && (ref($elements->{$action}) eq 'HASH')) {
301: if (ref($elements->{$action}{$state}) eq 'HASH') {
302: $elementsref = $elements->{$action}{$state};
1.2 raeburn 303: }
304: }
1.16 raeburn 305: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
306: $env{'form.clonedom'} = $dom;
307: }
1.30 raeburn 308: if ($state eq 'crstype') {
309: $jscript = &mainmenu_javascript();
310: } else {
311: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
1.45 raeburn 312: if ($state eq 'courseinfo') {
313: $jscript .= &cloning_javascript();
1.84 raeburn 314: } elsif ($state eq 'process') {
315: $jscript .= &processing_javascript();
1.45 raeburn 316: }
1.30 raeburn 317: }
1.2 raeburn 318: }
319:
320: if ($state eq 'personnel') {
321: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
322: }
323:
324: my $loaditems = &onload_action($action,$state);
325:
1.1 raeburn 326: if ($action eq 'new') {
327: if ($canreq) {
328: if ($state eq 'crstype') {
1.3 raeburn 329: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
1.72 raeburn 330: $crumb,\@incdoms);
1.1 raeburn 331: } else {
1.27 raeburn 332: &request_administration($r,$action,$state,$page,\%states,$dom,
333: $jscript,$loaditems,$crumb,$newinstcode,
1.36 raeburn 334: $codechk,$checkedcode,$description,
1.66 raeburn 335: $showcredits,$instcredits,\@invalidcrosslist);
1.1 raeburn 336: }
337: } else {
1.40 raeburn 338: $r->print(&header('Course/Community Requests').$crumb.
1.1 raeburn 339: '<div class="LC_warning">'.
1.40 raeburn 340: &mt('You do not have privileges to request creation of courses or communities.').
1.2 raeburn 341: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 342: }
343: } elsif ($action eq 'view') {
1.10 raeburn 344: if ($state eq 'crstype') {
1.72 raeburn 345: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\@incdoms);
1.26 raeburn 346: } else {
347: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.66 raeburn 348: $loaditems,$crumb,'','','','',$showcredits);
1.26 raeburn 349: }
350: } elsif ($action eq 'display') {
351: if ($warning ne '') {
352: my $args = { only_body => 1 };
1.49 raeburn 353: $r->print(&header('Course/Community Requests','','' ,'',$args).$crumb.
1.40 raeburn 354: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
1.26 raeburn 355: '<div class="LC_warning">'.$warning.'</div>'.
356: &close_popup_form());
1.11 raeburn 357: } else {
1.26 raeburn 358: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.66 raeburn 359: $loaditems,$crumb,'','','','',$showcredits,'','',
360: $uname,$udom);
1.10 raeburn 361: }
1.1 raeburn 362: } elsif ($action eq 'log') {
1.48 raeburn 363: if ($state eq 'crstype') {
1.72 raeburn 364: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
1.48 raeburn 365: } else {
366: $jscript .= <<ENDJS;
367:
368: function backPage(formname,prevstate) {
369: formname.state.value = prevstate;
370: formname.submit();
371: }
372:
373: function setPage(formname) {
374: formname.page.value = '1';
375: return;
376: }
377:
378: ENDJS
1.73 raeburn 379: &print_request_logs($r,$dom,$jscript,$loaditems,$crumb,\%can_request);
1.48 raeburn 380: }
1.1 raeburn 381: } else {
1.72 raeburn 382: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\@incdoms);
1.1 raeburn 383: }
384: return OK;
385: }
386:
1.30 raeburn 387: sub mainmenu_javascript {
388: return <<"END";
389: function setType(courseForm) {
390: for (var i=0; i<courseForm.crstype.length; i++) {
391: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
392: courseForm.crstype.options[i].selected = true;
393: } else {
394: courseForm.crstype.options[i].selected = false;
395: }
396: }
397: }
398:
399: function setAction(courseForm) {
400: for (var i=0; i<courseForm.action.length; i++) {
401: if (courseForm.action.options[i].value == "$env{'form.action'}") {
402: courseForm.action.options[i].selected = true;
403: } else {
404: courseForm.action.options[i].selected = false;
405: }
406: }
407: }
408: END
409: }
410:
1.45 raeburn 411: sub cloning_javascript {
412: return <<"END";
413: function setCloneDisplay(courseForm) {
414: if (courseForm.cloning.length > 1) {
415: for (var i=0; i<courseForm.cloning.length; i++) {
416: if (courseForm.cloning[i].checked) {
417: if (courseForm.cloning[i].value == 1) {
1.84 raeburn 418: document.getElementById('cloneoptions').style.display="block";
1.45 raeburn 419: }
420: }
421: }
422: }
423: }
424: END
425: }
426:
1.84 raeburn 427: sub processing_javascript {
428: return <<"END";
429: function hideProcessing() {
430: if (document.getElementById('processing')) {
431: document.getElementById('processing').style.display="none";
432: }
433: }
434:
435: END
436: }
437:
1.27 raeburn 438: sub get_breadcrumbs {
439: my ($dom,$action,$state,$states,$trail) = @_;
1.36 raeburn 440: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
1.27 raeburn 441: my $page = 0;
442: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
443: if (defined($action)) {
444: my $done = 0;
445: my $i=0;
446: if (ref($states->{$action}) eq 'ARRAY') {
447: while ($i<@{$states->{$action}} && !$done) {
448: if ($states->{$action}[$i] eq $$state) {
449: $page = $i;
450: $done = 1;
451: }
452: $i++;
453: }
454: }
455: if ($env{'form.crstype'} eq 'official') {
456: if ($page > 1) {
457: if ($states->{$action}[$page-1] eq 'codepick') {
458: if ($env{'form.instcode'} eq '') {
459: ($newinstcode,$numtitles) = &get_instcode($dom);
460: if ($numtitles) {
461: if ($newinstcode eq '') {
462: $$state = 'codepick';
463: $page --;
464: } else {
1.36 raeburn 465: ($codechk,$description) =
1.27 raeburn 466: &Apache::lonnet::auto_validate_instcode('',
467: $dom,$newinstcode);
468: if ($codechk ne 'valid') {
469: $$state = 'codepick';
470: $page --;
471: }
472: $checkedcode = 1;
473: }
474: }
475: }
476: }
477: }
478: }
1.85 raeburn 479: if (ref($states->{$action}) eq 'ARRAY') {
480: for (my $i=0; $i<@{$states->{$action}}; $i++) {
481: if ($$state eq $states->{$action}[$i]) {
1.27 raeburn 482: &Apache::lonhtmlcommon::add_breadcrumb(
1.85 raeburn 483: {text=>"$trail->{$$state}"});
484: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
485: last;
1.27 raeburn 486: } else {
1.85 raeburn 487: if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) {
488: &Apache::lonhtmlcommon::add_breadcrumb(
489: { href => '/adm/requestcourse',
490: text => "$trail->{$states->{$action}[$i]}",
491: }
492: );
493: } else {
494: &Apache::lonhtmlcommon::add_breadcrumb(
1.27 raeburn 495: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
496: text => "$trail->{$states->{$action}[$i]}", }
1.85 raeburn 497: );
498: }
499: }
500: }
501: }
1.27 raeburn 502: } else {
503: &Apache::lonhtmlcommon::add_breadcrumb(
504: {text=>'Pick Action'});
1.40 raeburn 505: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27 raeburn 506: }
507: } else {
508: &Apache::lonhtmlcommon::add_breadcrumb(
509: {text=>'Pick Action'});
1.40 raeburn 510: $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
1.27 raeburn 511: }
1.36 raeburn 512: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
1.27 raeburn 513: }
514:
1.2 raeburn 515: sub header {
1.26 raeburn 516: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2 raeburn 517: if ($jscript) {
1.6 raeburn 518: $jscript = '<script type="text/javascript">'."\n".
519: '// <![CDATA['."\n".
520: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 521: }
522: if ($loaditems) {
1.26 raeburn 523: if (ref($args) eq 'HASH') {
524: my %loadhash = (
525: 'add_entries' => $loaditems,
526: );
527: my %arghash = (%loadhash,%{$args});
528: $args = \%arghash;
529: } else {
530: $args = {'add_entries' => $loaditems,};
531: }
1.3 raeburn 532: }
1.26 raeburn 533: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2 raeburn 534: }
535:
536: sub form_elements {
1.66 raeburn 537: my ($dom,$showcredits) = @_;
538: my $instcredits;
1.2 raeburn 539: my %elements =
540: (
541: new => {
542: crstype => {
543: crstype => 'selectbox',
544: action => 'selectbox',
1.16 raeburn 545: origcnum => 'hidden',
1.2 raeburn 546: },
547: courseinfo => {
548: cdescr => 'text',
1.45 raeburn 549: cloning => 'radio',
1.13 raeburn 550: clonecrs => 'text',
551: clonedom => 'selectbox',
1.2 raeburn 552: datemode => 'radio',
553: dateshift => 'text',
554: },
555: enrollment => {
1.13 raeburn 556: accessstart_month => 'selectbox',
557: accessstart_hour => 'selectbox',
558: accessend_month => 'selectbox',
559: accessend_hour => 'selectbox',
560: accessstart_day => 'text',
561: accessstart_year => 'text',
562: accessstart_minute => 'text',
563: accessstart_second => 'text',
564: accessend_day => 'text',
565: accessend_year => 'text',
566: accessend_minute => 'text',
567: accessend_second => 'text',
1.2 raeburn 568: no_end_date => 'checkbox',
569: },
570: personnel => {
571: addperson => 'checkbox',
572: },
1.13 raeburn 573: review => {
574: cnum => 'hidden',
575: },
1.2 raeburn 576: },
577: view => {
578: crstype => {
579: crstype => 'selectbox',
580: action => 'selectbox',
581: },
582: },
583: );
1.13 raeburn 584: my %servers = &Apache::lonnet::get_servers($dom,'library');
585: my $numlib = keys(%servers);
586: if ($numlib > 1) {
587: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
588: } else {
589: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
590: }
1.2 raeburn 591: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
592: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
593: \%cat_order,\@code_order);
594: my $numtitles = scalar(@codetitles);
595: if ($numtitles) {
596: my %extras;
597: $lastitem = pop(@codetitles);
598: $extras{'instcode_'.$lastitem} = 'text';
599: foreach my $item (@codetitles) {
600: $extras{'instcode_'.$item} = 'selectbox';
601: }
602: $elements{'new'}{'codepick'} = \%extras;
603: }
604: if (&Apache::lonnet::auto_run('',$dom)) {
605: my %extras = (
1.13 raeburn 606: enrollstart_month => 'selectbox',
607: enrollstart_hour => 'selectbox',
608: enrollend_month => 'selectbox',
609: enrollend_hour => 'selectbox',
610: enrollstart_day => 'text',
611: enrollstart_year => 'text',
612: enrollstart_minute => 'text',
613: enrollstart_second => 'text',
614: enrollend_day => 'text',
615: enrollend_year => 'text',
616: enrollend_minute => 'text',
617: enrollend_second => 'text',
1.2 raeburn 618: addcrosslist => 'checkbox',
619: autoadds => 'radio',
620: autodrops => 'radio',
1.61 raeburn 621: );
622: my ($instcode,$titlescount) = &get_instcode($dom);
623: if ($instcode) {
624: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
625: if (@sections) {
626: $extras{'sectotal'} = 'hidden';
627: if ($env{'form.sectotal'} > 0) {
628: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
629: $extras{'sec_'.$i} = 'radio';
630: $extras{'secnum_'.$i} = 'text';
631: $extras{'loncapasec_'.$i} = 'text';
632: }
633: }
634: } else {
635: $extras{'addsection'} = 'checkbox';
636: my $sectotal = $env{'form.sectotal'};
637: if ($env{'form.addsection'}) {
638: $sectotal ++;
639: }
640: for (my $i=0; $i<$sectotal; $i++) {
641: $extras{'sec_'.$i} = 'checkbox';
642: $extras{'secnum_'.$i} = 'text',
643: $extras{'loncapasec_'.$i} = 'text',
644: }
1.2 raeburn 645: }
1.66 raeburn 646: (my $outcome,my $desc,$instcredits) =
647: &Apache::lonnet::auto_validate_instcode(undef,$dom,$instcode);
648: if ($showcredits && $instcredits eq '') {
649: $extras{'coursecredits'} = 'text';
650: }
1.69 raeburn 651: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66 raeburn 652: if ($showcredits) {
653: $extras{'coursecredits'} = 'text';
654: }
1.2 raeburn 655: }
656: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 657: if ($env{'form.addcrosslist'}) {
658: $crosslisttotal ++;
659: }
1.24 raeburn 660: if (!$crosslisttotal) {
1.2 raeburn 661: $crosslisttotal = 1;
662: }
1.24 raeburn 663: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
664: if ($numtitles) {
665: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
666: }
667: if (@codetitles > 0) {
668: foreach my $item (@codetitles) {
669: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2 raeburn 670: }
671: }
1.24 raeburn 672: $extras{'crosslist_'.$i} = 'checkbox';
673: $extras{'crosslist_'.$i.'_instsec'} = 'text',
674: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2 raeburn 675: }
676: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
677: %{$elements{'new'}{'enrollment'}} = %mergedhash;
678: }
679: my %people;
680: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 681: if ($env{'form.addperson'}) {
682: $persontotal ++;
683: }
684: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 685: $persontotal = 1;
686: }
687: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 688: $people{'person_'.$i.'_uname'} = 'text',
689: $people{'person_'.$i.'_dom'} = 'selectbox',
690: $people{'person_'.$i.'_hidedom'} = 'hidden',
691: $people{'person_'.$i.'_firstname'} = 'text',
692: $people{'person_'.$i.'_lastname'} = 'text',
693: $people{'person_'.$i.'_emailaddr'} = 'text',
694: $people{'person_'.$i.'_role'} = 'selectbox',
695: $people{'person_'.$i.'_sec'} = 'selectbox',
696: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 697: }
698: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
699: %{$elements{'new'}{'personnel'}} = %personnelhash;
1.66 raeburn 700: return (\%elements,$instcredits);;
1.2 raeburn 701: }
702:
703: sub onload_action {
704: my ($action,$state) = @_;
705: my %loaditems;
706: if (($action eq 'new') || ($action eq 'view')) {
1.30 raeburn 707: if ($state eq 'crstype') {
708: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
709: } else {
1.45 raeburn 710: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
711: }
712: if ($state eq 'courseinfo') {
713: $loaditems{'onload'} .= 'javascript:setCloneDisplay(document.requestcrs);';
1.30 raeburn 714: }
1.84 raeburn 715: if ($state eq 'process') {
716: $loaditems{'onload'} .= 'javascript:hideProcessing();';
717: }
1.2 raeburn 718: }
719: return \%loaditems;
720: }
721:
1.1 raeburn 722: sub print_main_menu {
1.72 raeburn 723: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$incdoms) = @_;
1.37 raeburn 724: my ($types,$typename) = &Apache::loncommon::course_types();
1.52 bisitz 725: my $onchange = 'this.form.submit()';
1.2 raeburn 726: my $nextstate_setter = "\n";
727: if (ref($states) eq 'HASH') {
728: foreach my $key (keys(%{$states})) {
729: if (ref($states->{$key}) eq 'ARRAY') {
730: $nextstate_setter .=
731: " if (actionchoice == '$key') {
732: nextstate = '".$states->{$key}[1]."';
733: }
734: ";
735: }
736: }
737: }
1.1 raeburn 738:
1.2 raeburn 739: my $js = <<"END";
1.1 raeburn 740:
1.2 raeburn 741: function nextPage(formname) {
1.27 raeburn 742: var crschoice = document.mainmenu_coursetype.crstype.value;
743: var actionchoice = document.mainmenu_action.action.value;
1.2 raeburn 744: if (check_can_request(crschoice,actionchoice) == true) {
745: if ((actionchoice == 'new') && (crschoice == 'official')) {
746: nextstate = 'codepick';
747: } else {
748: $nextstate_setter
1.27 raeburn 749: }
750: formname.crstype.value = crschoice;
751: formname.action.value = actionchoice;
1.1 raeburn 752: formname.state.value= nextstate;
753: formname.submit();
754: }
755: return;
756: }
757:
1.2 raeburn 758: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 759: var official = '';
760: var unofficial = '';
1.69 raeburn 761: var community = '';
762: var textbook = '';
1.1 raeburn 763: END
1.39 raeburn 764: if (ref($can_request) eq 'HASH') {
765: foreach my $item (keys(%{$can_request})) {
766: $js .= "
1.1 raeburn 767: $item = 1;
768: ";
1.39 raeburn 769: }
1.1 raeburn 770: }
771: my %lt = &Apache::lonlocal::texthash(
772: official => 'You are not permitted to request creation of an official course in this domain.',
773: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
1.69 raeburn 774: community => 'You are not permitted to request creation of a community in this domain.',
775: textbook => 'You are not permitted to request creation of a textbook course in this domain',
1.67 raeburn 776: all => 'You must choose a specific course type when making a new course request.',
777: allt => '"All types" is not allowed.',
1.1 raeburn 778: );
779: $js .= <<END;
780: if (crschoice == 'official') {
781: if (official != 1) {
782: alert("$lt{'official'}");
783: return false;
784: }
785: } else {
786: if (crschoice == 'unofficial') {
787: if (unofficial != 1) {
788: alert("$lt{'unofficial'}");
789: return false;
790: }
791: } else {
792: if (crschoice == 'community') {
793: if (community != 1) {
794: alert("$lt{'community'}");
795: return false;
796: }
797: } else {
1.69 raeburn 798: if (crschoice == 'textbook') {
799: if (textbook != 1) {
800: alert("$lt{'community'}");
801: return false;
802: }
803: } else {
804: if (actionchoice == 'new') {
805: alert('$lt{'all'}'+'\\n'+'$lt{'allt'}');
806: return false;
807: }
808: }
1.1 raeburn 809: }
810: }
811: }
812: return true;
813: }
814: END
1.75 raeburn 815: my ($pagetitle,$pageinfo,$domaintitle,$earlyout);
1.39 raeburn 816: if (ref($can_request) eq 'HASH') {
1.69 raeburn 817: if (($can_request->{'official'}) || ($can_request->{'unofficial'}) || $can_request->{'textbook'}) {
1.39 raeburn 818: if ($can_request->{'community'}) {
819: $pagetitle = 'Course/Community Requests';
820: $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
821: $domaintitle = &mt('Course/Community Domain');
822: } else {
823: $pagetitle = 'Course Requests';
824: $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
825: $domaintitle = &mt('Course Domain');
826: }
827: } elsif ($can_request->{'community'}) {
1.40 raeburn 828: $pagetitle = 'Community Requests';
829: $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
1.39 raeburn 830: $domaintitle = &mt('Community Domain');
1.75 raeburn 831: } elsif ((ref($incdoms) eq 'ARRAY') && ((@{$incdoms} > 1) ||
832: ((@{$incdoms} == 1) && ($incdoms->[0] ne $dom)))) {
1.39 raeburn 833: $pagetitle = 'Course/Community Requests';
834: $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
835: $domaintitle = &mt('Course/Community Domain');
1.75 raeburn 836: } else {
837: $pagetitle = 'Course/Community Requests';
838: $pageinfo = &mt('You do not have rights to request creation of courses or communities.');
839: $earlyout = 1;
1.39 raeburn 840: }
841: }
842: $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
1.75 raeburn 843: '<p>'.$pageinfo.'</p>');
844: if ($earlyout) {
845: $r->print(&Apache::loncommon::end_page());
846: return;
847: }
848: $r->print('<div>'.
1.27 raeburn 849: &Apache::lonhtmlcommon::start_pick_box().
1.39 raeburn 850: &Apache::lonhtmlcommon::row_title($domaintitle).
1.1 raeburn 851: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
1.72 raeburn 852: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms));
1.1 raeburn 853: if (!$onchange) {
854: $r->print(' <input type="submit" name="godom" value="'.
855: &mt('Change').'" />');
856: }
1.39 raeburn 857: unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
1.72 raeburn 858: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure(1)."\n".
1.39 raeburn 859: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
860: &Apache::loncommon::end_page());
861: return;
862: }
1.27 raeburn 863: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.2 raeburn 864: my $formname = 'requestcrs';
1.1 raeburn 865: my $nexttext = &mt('Next');
1.27 raeburn 866: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
867: <form name="mainmenu_action" method="post" action="">
1.1 raeburn 868: <select size="1" name="action" >
1.2 raeburn 869: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 870: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
871: <option value="log">'.&mt('View request history').'</option>
1.27 raeburn 872: </select></form>'.
1.46 wenzelju 873: &Apache::lonhtmlcommon::row_closure().
1.39 raeburn 874: &Apache::lonhtmlcommon::row_title(&mt('Type')).'
1.27 raeburn 875: <form name="mainmenu_coursetype" method="post" action="">
1.39 raeburn 876: <select size="1" name="crstype">');
877: if (ref($can_request) eq 'HASH') {
878: if (keys(%{$can_request}) > 1) {
879: $r->print(' <option value="any">'.&mt('All types').'</option>');
880: }
881: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
882: foreach my $type (@{$types}) {
883: next unless($can_request->{$type});
884: my $selected = '';
885: if ($env{'form.crstype'} eq '') {
886: if ($type eq 'official') {
887: $selected = ' selected="selected"';
888: }
889: } else {
890: if ($type eq $env{'form.crstype'}) {
891: $selected = ' selected="selected"';
892: }
893: }
894: $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
895: '</option>'."\n");
1.4 raeburn 896: }
897: }
898: }
1.27 raeburn 899: $r->print('</select></form>'."\n".
900: &Apache::lonhtmlcommon::row_closure(1)."\n".
901: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
1.38 raeburn 902: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
1.27 raeburn 903: '<input type="hidden" name="state" value="crstype" />'."\n".
904: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
905: '<input type="hidden" name="crstype" value="" />'."\n".
906: '<input type="hidden" name="action" value="" />'."\n".
907: '<input type="button" name="next" value="'.$nexttext.
908: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
909: '</form></div>');
1.1 raeburn 910: $r->print(&Apache::loncommon::end_page());
911: return;
912: }
913:
914: sub request_administration {
1.27 raeburn 915: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
1.66 raeburn 916: $newinstcode,$codechk,$checkedcode,$description,$showcredits,
917: $instcredits,$invalidcrosslist,$uname,$udom) = @_;
1.2 raeburn 918: my $js;
1.16 raeburn 919: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 920: $js = <<END;
1.1 raeburn 921:
922: function nextPage(formname,nextstate) {
923: formname.state.value= nextstate;
924: formname.submit();
925: }
1.16 raeburn 926:
927: END
928: }
929: if (($action eq 'new') || ($action eq 'view')) {
930: $js .= <<END;
931:
1.1 raeburn 932: function backPage(formname,prevstate) {
933: formname.state.value = prevstate;
934: formname.submit();
935: }
936:
937: END
1.2 raeburn 938: }
939: if ($action eq 'new') {
940: my $jsextra;
1.54 raeburn 941: if (($state eq 'courseinfo') || ($state eq 'codepick')) {
1.2 raeburn 942: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31 raeburn 943: } elsif ($state eq 'enrollment') {
944: if (($env{'form.crstype'} eq 'official') &&
945: (&Apache::lonnet::auto_run('',$dom))) {
946: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
947: }
948: } elsif ($state eq 'personnel') {
949: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
1.1 raeburn 950: }
1.40 raeburn 951: my $title;
952: if ($env{'form.crstype'} eq 'community') {
953: $title = 'Request a community';
954: } else {
955: $title = 'Request a course';
956: }
957: $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
1.27 raeburn 958: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
1.66 raeburn 959: $codechk,$checkedcode,$description,$showcredits,
960: $instcredits,$invalidcrosslist);
1.2 raeburn 961: } elsif ($action eq 'view') {
1.16 raeburn 962: my $jsextra;
963: my $formname = 'requestcrs';
964: my $prev = $states->{$action}[$page-1];
965: my $next = $states->{$action}[$page+1];
966: if ($state eq 'pick_request') {
967: $next = $states->{$action}[$page+1];
968: $jsextra = &viewrequest_javascript($formname,$next);
969: } elsif ($state eq 'details') {
970: $jsextra = &viewdetails_javascript($formname);
971:
972: } elsif ($state eq 'cancel') {
973: $jsextra = &viewcancel_javascript($formname);
974: }
1.40 raeburn 975: my $title;
976: if ($env{'form.crstype'} eq 'community') {
977: $title = 'Manage community requests';
978: } else {
979: $title = 'Manage course requests';
980: }
981: $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
1.16 raeburn 982: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 983: if ($state eq 'pick_request') {
1.40 raeburn 984: my $title;
985: if ($env{'form.crstype'} eq 'community') {
986: $title = &mt('Pending community requests');
987: } elsif ($env{'form.crstype'} eq 'official') {
988: $title = &mt('Pending requests for official courses');
989: } elsif ($env{'form.crstype'} eq 'unofficial') {
990: $title = &mt('Pending requests for unofficial courses');
1.69 raeburn 991: } elsif ($env{'form.crstype'} eq 'textbook') {
992: $title = &mt('Pending requests for textbook courses');
1.40 raeburn 993: } else {
994: $title = &mt('Pending course/community requests');
995: }
996: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.48 raeburn 997: &print_request_status($dom,$action).'</form></div>');
1.16 raeburn 998: } elsif ($state eq 'details') {
999: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1000: my $origcnum = $env{'form.cnum'};
1001: if ($origcnum eq '') {
1002: $origcnum = $env{'form.origcnum'};
1003: }
1004: if ($env{'form.crstype'} eq 'official') {
1005: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1006: \%cat_order,\@code_order);
1007: }
1.40 raeburn 1008: my $title;
1009: if ($env{'form.crstype'} eq 'community') {
1010: $title = &mt('Community Request Details');
1011: } else {
1012: $title = &mt('Course Request Details');
1013: }
1014: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.26 raeburn 1015: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.66 raeburn 1016: \@code_order,'','','','',$instcredits)."\n".
1.16 raeburn 1017: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
1.66 raeburn 1018: my @excluded = &get_excluded_elements($dom,$states,'new','review',
1019: $showcredits);
1.16 raeburn 1020: push(@excluded,'origcnum');
1021: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1022: my $other = 'modify';
1023: my %navtxt = &Apache::lonlocal::texthash (
1024: prev => 'Back',
1025: other => 'Modify Request',
1026: next => 'Cancel Request',
1027: );
1.31 raeburn 1028: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1029: $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16 raeburn 1030: $r->print('</form>');
1031: } elsif ($state eq 'cancel') {
1.40 raeburn 1032: my $title;
1033: if ($env{'form.crstype'} eq 'community') {
1034: $title = &mt('Cancel community request');
1035: } else {
1036: $title = &mt('Cancel course request');
1037: }
1.16 raeburn 1038: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1.40 raeburn 1039: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.16 raeburn 1040: $output);
1.66 raeburn 1041: my @excluded = &get_excluded_elements($dom,$states,'view','cancel',
1042: $showcredits);
1.16 raeburn 1043: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1044: my %navtxt = &Apache::lonlocal::texthash (
1045: prev => 'Back',
1046: next => 'Confirm Cancellation',
1047: );
1048: if ($result eq 'ok') {
1.31 raeburn 1049: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16 raeburn 1050: $navtxt{'next'},$state);
1051: } else {
1.31 raeburn 1052: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
1053: '',$state);
1.16 raeburn 1054: }
1055: $r->print('</form>');
1056: } elsif ($state eq 'removal') {
1057: my $cnum = $env{'form.origcnum'};
1058: my $statuskey = 'status:'.$dom.':'.$cnum;
1059: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
1060: $env{'user.domain'},$env{'user.name'});
1061: my $currstatus = $userreqhash{$statuskey};
1062: my ($result,$error);
1063: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
1064: my %status = (
1065: $statuskey => 'cancelled',
1066: );
1067: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
1068: if ($statusresult eq 'ok') {
1069: my $delresult =
1070: &Apache::lonnet::del_dom('courserequestqueue',
1071: [$cnum.'_'.$currstatus],$dom);
1072: if ($delresult eq 'ok') {
1073: $result = 'ok';
1074: } else {
1075: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
1076: }
1077: } else {
1078: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
1079: }
1080: } else {
1081: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
1082: }
1083: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
1084: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1085: '<input type="hidden" name="action" value="'.$action.'" />'."\n".
1086: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
1087: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
1088: if ($result eq 'ok') {
1.40 raeburn 1089: if ($env{'form.crstype'} eq 'community') {
1090: $r->print(&mt('Your community request has been cancelled.'));
1091: } else {
1092: $r->print(&mt('Your course request has been cancelled.'));
1093: }
1.16 raeburn 1094: } else {
1095: $r->print('<div class="LC_error">'.
1096: &mt('The request cancellation process was not complete.').
1097: '<br />'.$error.'</div>');
1098: }
1099: $r->print('</form>');
1.11 raeburn 1100: }
1.26 raeburn 1101: } elsif ($action eq 'display') {
1102: my $formname = 'requestcrs';
1103: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1104: if ($env{'form.crstype'} eq 'official') {
1105: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1106: \%cat_order,\@code_order);
1107: }
1.40 raeburn 1108: my ($title,$header);
1109: if ($env{'form.crstype'} eq 'community') {
1110: $title = 'Community Request';
1111: $header = &mt('Community Request');
1112: } else {
1113: $title = 'Course Request';
1114: $header = &mt('Course Request');
1115: }
1116: $r->print(&header($title,'','','',{ 'only_body' => 1}).
1117: $crumb."\n".'<h3>'.$header.'</h3>'.
1.26 raeburn 1118: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.66 raeburn 1119: \@code_order,$uname,$udom,'','',$instcredits)."\n".
1120: '</div>'.
1.26 raeburn 1121: &close_popup_form());
1.1 raeburn 1122: }
1.2 raeburn 1123: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 1124: return;
1125: }
1126:
1.83 raeburn 1127: sub domcoord_display {
1128: my ($dom) = @_;
1129: my ($uname,$udom,$result,$warning);
1130: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
1131: if ($env{'form.cnum'} ne '') {
1132: my $cnum = $env{'form.cnum'};
1133: my $queue = $env{'form.queue'};
1134: my $reqkey = $cnum.'_'.$queue;
1135: my $namespace = 'courserequestqueue';
1136: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
1137: my %queued =
1138: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
1139: if (ref($queued{$reqkey}) eq 'HASH') {
1140: $uname = $queued{$reqkey}{'ownername'};
1141: $udom = $queued{$reqkey}{'ownerdom'};
1142: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
1143: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
1144: } else {
1145: if ($env{'form.crstype'} eq 'community') {
1146: $warning = &mt('Invalid username or domain for community requestor');
1147: } else {
1148: $warning = &mt('Invalid username or domain for course requestor');
1149: }
1150: }
1151: } else {
1152: if ($env{'form.crstype'} eq 'community') {
1153: $warning = &mt('No information was found for this community request.');
1154: } else {
1155: $warning = &mt('No information was found for this course request.');
1156: }
1157: }
1158: } else {
1159: $warning = &mt('No course request ID provided.');
1160: }
1161: } else {
1162: if ($env{'form.crstype'} eq 'any') {
1163: $warning = &mt('You do not have rights to view course or community request information.');
1164: } elsif ($env{'form.crstype'} eq 'community') {
1165: $warning = &mt('You do not have rights to view community request information.');
1166: } else {
1167: $warning = &mt('You do not have rights to view course request information.');
1168: }
1169: }
1170: return ($uname,$udom,$result,$warning);
1171: }
1172:
1.31 raeburn 1173: sub enrollment_lcsec_js {
1174: my %alerts = §ion_check_alerts();
1175: my $secname = $alerts{'badsec'};
1176: my $secnone = $alerts{'reserved'};
1177: my $output = '
1178: function validateEnrollSections(formname,nextstate) {
1179: var badsectotal = 0;
1180: var reservedtotal = 0;
1181: var secTest = "";
1182: ';
1183: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1184: $output .= "
1185: var selSec = 0;
1186: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
1187: if (document.requestcrs.sec_".$i."[j].checked) {
1188: selSec = document.requestcrs.sec_".$i."[j].value;
1189: }
1190: if (selSec == 1) {
1191: secTest = validsection(document.requestcrs.loncapasec_".$i.");
1192: if (secTest == 'badsec') {
1193: badsectotal++;
1194: }
1195: if (secTest == 'reserved') {
1196: reservedtotal++;
1197: }
1198: }
1199: }
1200: ";
1201: }
1202: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1203: $output .= "
1204: if (document.requestcrs.crosslist_".$i.".checked) {
1205: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
1206: if (secTest == 'badsec') {
1207: badsectotal++;
1208: }
1209: if (secTest == 'reserved') {
1210: reservedtotal++;
1211: }
1212: }
1213: ";
1214: }
1215: $output .= "
1216: if (badsectotal>0) {
1217: alert('$secname');
1218: return false;
1219: }
1220: if (reservedtotal>0) {
1221: alert('$secnone');
1222: return false;
1223: }
1224: formname.state.value= nextstate;
1225: formname.submit();
1226: return;
1227: }
1228: ";
1229: return $output;
1230: }
1231:
1232: sub personnel_lcsec_js {
1233: my %alerts = §ion_check_alerts();
1234: my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
1235: my $secnone = $alerts{'reserved'};
1236: my $output = '
1237: function validatePersonnelSections(formname,nextstate) {
1238: var badsectotal = 0;
1239: var reservedtotal = 0;
1240: var secTest = "";
1241: ';
1242: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1243: $output .= "
1244: if (document.requestcrs.person_".$i."_uname.value != '') {
1245: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1246: if (secTest == 'badsec') {
1247: badsectotal++;
1248: }
1249: if (secTest == 'reserved') {
1250: reservedtotal++;
1251: }
1252: }
1253: ";
1254: }
1255: $output .= "
1256: if (badsectotal > 0) {
1257: alert('$secname');
1258: return false;
1259: } else {
1260: if (reservedtotal > 0) {
1261: alert('$secnone');
1262: return false;
1263: }
1264: }
1265: formname.state.value = nextstate;
1266: formname.submit();
1267: return;
1268: }
1269: ";
1270: return $output;
1271: }
1272:
1273: sub section_check_alerts {
1274: my %lt =
1275: &Apache::lonlocal::texthash(
1276: 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.",
1277: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1278: separate => 'Separate multiple sections with a comma.'
1279: );
1280: return %lt;
1281: }
1282:
1283: sub section_check_javascript {
1284: return <<"END";
1285: function validsection(field,mult) {
1286: var str = field.value;
1287: var badsec=0;
1288: var reserved=0;
1289: if (window.RegExp) {
1290: var badsecnum=0;
1291: var reservednum=0;
1292: var pattern=/[^a-zA-Z0-9]/;
1293: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1294: str = str.replace(/[ ]{2,}/gi," ");
1295: if (mult == '1') {
1296: var sections = new Array();
1297: sections = str.split(/\\s*[\\s,;:]\\s*/);
1298: var i;
1299: for (i=0; i<sections.length; i++) {
1300: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1301: if (pattern.test(sections[i])) {
1302: badsecnum++;
1303: } else {
1304: if (sections[i] == 'none') {
1305: reservednum++;
1306: }
1307: }
1308: }
1309: }
1310: } else {
1311: if ((str != '') && (str != undefined) && (str != null)) {
1312: if (pattern.test(str)) {
1313: badsecnum++;
1314: } else {
1315: if (str == 'none') {
1316: reservednum++;
1317: }
1318: }
1319: }
1320: }
1321: if (badsecnum > 0) {
1322: return 'badsec';
1323: }
1324: if (reservednum > 0) {
1325: return 'reserved';
1326: }
1327: }
1328: return;
1329: }
1330: END
1331: }
1332:
1.26 raeburn 1333: sub close_popup_form {
1334: my $close= &mt('Close Window');
1335: return << "END";
1336: <p><form name="displayreq" action="" method="post">
1337: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1338: </form></p>
1339: END
1340: }
1341:
1.27 raeburn 1342: sub get_instcode {
1343: my ($dom) = @_;
1344: my ($instcode,$numtitles);
1345: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1346: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1347: \%cat_order,\@code_order);
1348: $numtitles = scalar(@codetitles);
1349: if (@code_order > 0) {
1350: my $message;
1351: foreach my $item (@code_order) {
1352: $instcode .= $env{'form.instcode_'.$item};
1353: }
1354: }
1355: return ($instcode,$numtitles);
1356: }
1357:
1.1 raeburn 1358: sub print_request_form {
1.27 raeburn 1359: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1.66 raeburn 1360: $description,$showcredits,$instcredits,$invalidcrosslist) = @_;
1.1 raeburn 1361: my $formname = 'requestcrs';
1.2 raeburn 1362: my ($next,$prev,$message,$output,$codepicker,$crstype);
1363: $prev = $states->{$action}[$page-1];
1364: $next = $states->{$action}[$page+1];
1.4 raeburn 1365: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 1366: prev => 'Back',
1.4 raeburn 1367: next => 'Next',
1368: );
1.2 raeburn 1369: $crstype = $env{'form.crstype'};
1.34 raeburn 1370: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30 raeburn 1371: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1372: @disallowed);
1.1 raeburn 1373: if ($crstype eq 'official') {
1.2 raeburn 1374: if ($env{'form.instcode'} ne '') {
1375: $instcode = $env{'form.instcode'};
1.27 raeburn 1376: } elsif ($newinstcode ne '') {
1377: $instcode = $newinstcode;
1.2 raeburn 1378: }
1.27 raeburn 1379: if ($checkedcode) {
1380: if ($codechk eq 'valid') {
1381: $message = '<div class="LC_info">'.
1382: &mt('The chosen course category [_1] is valid.','<b>'.
1383: $instcode.'</b>').
1384: '<input type="hidden" name="instcode" value="'.
1385: $instcode.'" /></div>';
1.2 raeburn 1386: } else {
1387: $message = '<div class="LC_warning">'.
1.27 raeburn 1388: &mt('No course was found matching your choice of institutional course category.');
1389: if ($codechk ne '') {
1390: $message .= '<br />'.$codechk;
1391: }
1392: $message .= '</div>';
1.2 raeburn 1393: $prev = 'crstype';
1394: }
1395: $r->print($message);
1.1 raeburn 1396: }
1.2 raeburn 1397: }
1398: if ($prev eq 'crstype') {
1.4 raeburn 1399: if ($crstype eq 'official') {
1400: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1401: \%cat_order,\@code_order);
1402: }
1.2 raeburn 1403: if (@code_order > 0) {
1.1 raeburn 1404: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1405: \%cat_titles,\%cat_order);
1.2 raeburn 1406: if ($codepicker) {
1.34 raeburn 1407: $r->print(&mt('Specify the course to be created.').
1408: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1409: $codepicker.
1.2 raeburn 1410: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1411: } else {
1.20 raeburn 1412: $next = $states->{$action}[$page+2];
1.15 raeburn 1413: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.2 raeburn 1414: }
1415: } else {
1.20 raeburn 1416: if ($crstype eq 'official') {
1417: $next = $states->{$action}[$page+2];
1418: }
1.15 raeburn 1419: $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
1.1 raeburn 1420: }
1.2 raeburn 1421: } elsif ($prev eq 'codepick') {
1.27 raeburn 1422: if ($instcode eq '') {
1.20 raeburn 1423: $prev = $states->{$action}[$page-2];
1424: }
1.36 raeburn 1425: $r->print(&courseinfo_form($dom,$formname,$crstype,$next,$description));
1.2 raeburn 1426: } elsif ($state eq 'enrollment') {
1.4 raeburn 1427: if ($crstype eq 'official') {
1428: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1429: \%cat_order,\@code_order);
1430: }
1.2 raeburn 1431: $r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
1.27 raeburn 1432: \%cat_titles,\%cat_order,\@code_order,
1.66 raeburn 1433: $showcredits,$instcredits,$invalidcrosslist));
1.2 raeburn 1434: } elsif ($state eq 'personnel') {
1.27 raeburn 1435: $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
1.4 raeburn 1436: } elsif ($state eq 'review') {
1.30 raeburn 1437: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1438: my $now = time;
1439: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1440: my $personname = $env{'form.person_'.$i.'_uname'};
1441: my $persondom = $env{'form.person_'.$i.'_dom'};
1442: if (($personname =~ /^$match_username$/) &&
1443: ($persondom =~ /^$match_domain$/)) {
1444: if (&Apache::lonnet::domain($persondom)) {
1445: my $personhome =
1446: &Apache::lonnet::homeserver($personname,$persondom);
1447: if ($personhome eq 'no_host') {
1448: if ($persondom ne $dom) {
1449: my $skipuser = 1;
1450: if ($env{'user.role.dc./'.$persondom.'/'}) {
1451: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1452: if (((!$start) || ($start < $now)) &&
1453: ((!$end) || ($end > $now))) {
1454: $skipuser = 0;
1455: }
1456: }
1457: if ($skipuser) {
1458: push(@disallowed,$i);
1.60 raeburn 1459: $disallowmsg{$i} = &mt('[_1] was excluded because new users need to be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1.30 raeburn 1460: next;
1461: }
1462: }
1.60 raeburn 1463: my $usertype = &get_usertype($persondom,$personname,\%curr_rules,\%got_rules);
1464: if (&Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype)) {
1465: my ($allowed,$msg,$authtype,$authparam) =
1.30 raeburn 1466: &check_newuser_rules($persondom,$personname,
1467: \%alerts,\%rulematch,\%inst_results,
1468: \%curr_rules,\%got_rules);
1469: if ($allowed) {
1.60 raeburn 1470: my %domdefaults = &Apache::lonnet::get_domain_defaults($persondom);
1471: if ($usertype eq 'official') {
1472: if ($authtype eq '') {
1473: $authtype = $domdefaults{'auth_def'};
1474: $authparam = $domdefaults{'auth_arg_def'};
1475: }
1476: } elsif ($usertype eq 'unofficial') {
1477: if ($authtype eq '') {
1478: $authtype = 'internal';
1479: $authparam = '';
1480: }
1481: } else {
1482: $authtype = $domdefaults{'auth_def'};
1483: $authparam = $domdefaults{'auth_arg_def'};
1484: }
1485: if (($authtype eq '') ||
1486: (($authtype =~/^krb/) && ($authparam eq ''))) {
1487: push(@disallowed,$i);
1488: $disallowmsg{$i} = &mt('[_1] was excluded because institutional information is incomplete for this new user.','<tt>'.$personname.':'.$persondom.'</tt>');
1489: next;
1490: }
1.30 raeburn 1491: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1492: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1493: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1494: }
1495: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1496: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1497: }
1498: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1499: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1500: }
1501: }
1502: } else {
1503: push(@disallowed,$i);
1504: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1505: }
1506: } else {
1507: push(@disallowed,$i);
1508: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1509: }
1510: } else {
1511: my %userenv =
1512: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1513: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1514: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1515: }
1516: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1517: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1518: }
1519: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1520: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1521: }
1522: }
1523: } elsif ($personname ne '') {
1524: push(@disallowed,$i);
1525: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1526: }
1527: } elsif ($personname ne '') {
1528: push(@disallowed,$i);
1529: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1530: }
1531: }
1.16 raeburn 1532: my $cnum;
1533: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1534: $cnum = $env{'form.origcnum'};
1535: } else {
1.47 raeburn 1536: my $gentype = 'Course';
1537: if ($crstype eq 'community') {
1538: $gentype = 'Community';
1539: }
1540: $cnum = &Apache::lonnet::generate_coursenum($dom,$gentype);
1.16 raeburn 1541: }
1.4 raeburn 1542: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1543: \%cat_order,\@code_order);
1.40 raeburn 1544: if ($crstype eq 'community') {
1545: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1546: } else {
1547: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1548: }
1.66 raeburn 1549: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg,$instcredits).
1.16 raeburn 1550: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.73 raeburn 1551: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1552: $env{'user.domain'});
1553: my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'review',$env{'user.name'},
1554: $env{'user.domain'},$fullname,$env{'form.cdescr'});
1555: if (ref($postprocess) eq 'HASH') {
1556: if ($postprocess->{'reviewweb'}) {
1557: $r->print($postprocess->{'reviewweb'});
1558: }
1559: }
1.40 raeburn 1560: if ($crstype eq 'community') {
1561: $navtxt{'next'} = &mt('Submit community request');
1562: } else {
1563: $navtxt{'next'} = &mt('Submit course request');
1564: }
1.10 raeburn 1565: } elsif ($state eq 'process') {
1566: if ($crstype eq 'official') {
1567: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1568: \%cat_order,\@code_order);
1569: }
1.78 raeburn 1570: my $lonhost = $r->dir_config('lonHostID');
1.84 raeburn 1571: my ($storeresult,$result) = &print_request_outcome($r,$lonhost,$dom,\@codetitles,
1.66 raeburn 1572: \@code_order,$instcredits);
1.13 raeburn 1573: $r->print($result);
1.27 raeburn 1574: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1575: if ($storeresult eq 'ok') {
1.65 raeburn 1576: $r->print('<p><a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1577: &mt('Modify this request').'</a>'.(' 'x4).
1578: '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1579: }
1580: if (&Apache::loncoursequeueadmin::author_prompt()) {
1.72 raeburn 1581: &print_author_prompt($r,$env{'form.action'},$env{'form.cnum'},$env{'form.showdom'},
1582: $env{'form.crstype'},$storeresult);
1.65 raeburn 1583: } elsif ($storeresult eq 'created') {
1584: $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1585: }
1586: }
1587: } elsif ($state eq 'reqauthor') {
1588: my ($result,@links);
1589: if ($env{'form.requestauthor'}) {
1590: $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result));
1591: if ($result eq 'created') {
1592: my $role = 'au';
1593: my $spec = "$role./$env{'form.showdom'}/";
1.76 bisitz 1594: push(@links,&mt('Enter your Authoring Space with role: [_1]',
1.65 raeburn 1595: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.
1596: &Apache::lonnet::plaintext($role).'</a>'));
1.27 raeburn 1597: }
1.65 raeburn 1598: }
1599: if (($env{'form.disposition'} eq 'created') &&
1600: ($env{'form.cnum'} =~ /^$match_courseid$/) &&
1601: ($env{'form.showdom'} =~ /^$match_domain$/)) {
1602: my ($spec,$area,$role,$type);
1603: my $role = 'cc';
1604: my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}";
1605: my $type = 'Course';
1606: if ($env{'form.crstype'} eq 'community') {
1607: $type = 'Community';
1608: }
1609: my $showrole = &Apache::lonnet::plaintext($role,$type);
1610: unshift(@links,&mt('Enter new course with role: [_1]',
1611: '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.$showrole.'</a>'));
1612: }
1613: if (@links > 1) {
1614: $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.',
1615: '<a href="/adm/roles">','</a>').' '.&mt('Choose a role:').
1616: '<ul>');
1617: foreach my $link (@links) {
1618: $r->print('<li>'.$link.'</li>');
1619: }
1620: $r->print('</ul>');
1621: } elsif (@links == 1) {
1622: $r->print('<p>'.$links[0].'</p>');
1.27 raeburn 1623: }
1.1 raeburn 1624: }
1.66 raeburn 1625: my @excluded = &get_excluded_elements($dom,$states,$action,$state,$showcredits);
1.24 raeburn 1626: if ($state eq 'personnel') {
1627: push(@excluded,'persontotal');
1628: }
1.30 raeburn 1629: if ($state eq 'review') {
1630: if (@disallowed > 0) {
1631: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1632: my @currsecs = ¤t_lc_sections();
1633: if (@currsecs) {
1634: push(@items,'sec');
1635: }
1636: my $count = 0;
1637: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1638: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1639: if (grep(/^$i$/,@disallowed)) {
1640: foreach my $item (@items) {
1641: $env{'form.person_'.$i.'_'.$item} = '';
1642: }
1643: } else {
1644: foreach my $item (@items) {
1645: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1646: }
1647: }
1648: }
1649: $count ++;
1650: }
1651: $env{'form.persontotal'} = $count;
1652: }
1653: }
1.27 raeburn 1654: if ($state eq 'enrollment') {
1.61 raeburn 1655: push(@excluded,('sectotal','crosslisttotal'));
1.27 raeburn 1656: }
1.65 raeburn 1657: if (($state eq 'process') || ($state eq 'reqauthor')) {
1658: $r->print('</form>');
1659: } else {
1660: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
1661: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1662: $navtxt{'next'},$state);
1663: }
1.16 raeburn 1664: return;
1665: }
1666:
1.72 raeburn 1667: sub print_author_prompt {
1668: my ($r,$action,$cnum,$showdom,$crstype,$storeresult) = @_;
1.76 bisitz 1669: $r->print('<h3>'.&mt('Access to Authoring Space').'</h3>'.
1.72 raeburn 1670: '<p>'.
1671: &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
1672: '<br />'.
1.76 bisitz 1673: &mt('By contrast, items created in Authoring Space, then imported into a course, can use all of the features of the assessment engine.').'</p>'.
1674: '<p>'.&mt('Request Authoring Space access now?').
1.72 raeburn 1675: '<span class="LC_nobreak"> '.
1676: '<label><input type="radio" name="requestauthor" value="1" />'.&mt('Yes').'</label>'.
1677: (' 'x2).
1678: '<label><input type="radio" name="requestauthor" value="0" checked="checked"/>'.&mt('No').'</label>'.
1679: '</span></p>'.
1680: '<input type="submit" name="newauthor" value="'.&mt('Submit authoring request').'" />'.
1681: '<input type="hidden" name="state" value="reqauthor" />'.
1682: '<input type="hidden" name="action" value="'.$action.'" />'.
1683: '<input type="hidden" name="cnum" value="'.$cnum.'" />'.
1684: '<input type="hidden" name="showdom" value="'.$showdom.'" />'.
1685: '<input type="hidden" name="crstype" value="'.$crstype.'" />'.
1686: '<input type="hidden" name="disposition" value="'.$storeresult.'" />'.
1687: '<br />');
1688: }
1689:
1.60 raeburn 1690: sub get_usertype {
1691: my ($persondom,$personname,$curr_rules,$got_rules) = @_;
1.30 raeburn 1692: my ($rules,$ruleorder) =
1693: &Apache::lonnet::inst_userrules($persondom,'username');
1694: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1.60 raeburn 1695: $rules,$curr_rules,$got_rules);
1696: return $usertype;
1.30 raeburn 1697: }
1698:
1699: sub check_newuser_rules {
1700: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1701: $got_rules) = @_;
1702: my $allowed = 1;
1703: my $newuser = 1;
1.60 raeburn 1704: my ($checkhash,$userchkmsg,$authtype,$authparam);
1.30 raeburn 1705: my $checks = { 'username' => 1 };
1706: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1707: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1708: $inst_results,$curr_rules,$got_rules);
1709: if (ref($alerts->{'username'}) eq 'HASH') {
1710: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1711: my $domdesc =
1712: &Apache::lonnet::domain($persondom,'description');
1713: if ($alerts->{'username'}{$persondom}{$personname}) {
1714: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1715: $userchkmsg =
1716: &Apache::loncommon::instrule_disallow_msg('username',
1717: $domdesc,1).
1718: &Apache::loncommon::user_rule_formats($persondom,
1719: $domdesc,$curr_rules->{$persondom}{'username'},
1720: 'username');
1721: }
1722: $allowed = 0;
1723: }
1724: }
1725: }
1.60 raeburn 1726: if ($allowed) {
1727: if (ref($rulematch) eq 'HASH') {
1728: if (ref($rulematch->{$personname.':'.$persondom}) eq 'HASH') {
1729: my $matchedrule = $rulematch->{$personname.':'.$persondom}{'username'};
1730: my ($rules,$ruleorder) =
1731: &Apache::lonnet::inst_userrules($persondom,'username');
1732: if (ref($rules) eq 'HASH') {
1733: if (ref($rules->{$matchedrule}) eq 'HASH') {
1734: $authtype = $rules->{$matchedrule}{'authtype'};
1735: $authparam = $rules->{$matchedrule}{'authparm'};
1736: }
1737: }
1738: }
1739: }
1740: }
1741: return ($allowed,$userchkmsg,$authtype,$authparam);
1.30 raeburn 1742: }
1743:
1.16 raeburn 1744: sub get_excluded_elements {
1.66 raeburn 1745: my ($dom,$states,$action,$state,$showcredits) = @_;
1.2 raeburn 1746: my @excluded = ('counter');
1.66 raeburn 1747: my ($elements,$instcredits) = &form_elements($dom,$showcredits);
1.2 raeburn 1748: if (ref($states) eq 'HASH') {
1749: if (ref($states->{$action}) eq 'ARRAY') {
1750: my @items = @{$states->{$action}};
1751: my $numitems = scalar(@items);
1752: if ($numitems) {
1753: for (my $i=$numitems-1; $i>=0; $i--) {
1.66 raeburn 1754: if ((ref($elements) eq 'HASH') &&
1755: (ref($elements->{$action}) eq 'HASH')) {
1756: if (ref($elements->{$action}{$items[$i]}) eq 'HASH') {
1757: foreach my $key (keys(%{$elements->{$action}{$items[$i]}})) {
1.2 raeburn 1758: push(@excluded,$key);
1759: }
1760: }
1761: }
1762: last if ($items[$i] eq $state);
1763: }
1764: }
1765: }
1766: }
1767: if (grep(/^instcode_/,@excluded)) {
1768: push(@excluded,'instcode');
1.1 raeburn 1769: }
1.16 raeburn 1770: return @excluded;
1.1 raeburn 1771: }
1772:
1.2 raeburn 1773: sub print_enrollment_menu {
1.27 raeburn 1774: my ($formname,$instcode,$dom,$codetitles,$cat_titles,$cat_order,$code_order,
1.66 raeburn 1775: $showcredits,$instcredits,$invalidcrosslist) =@_;
1776: my ($sections,$autoenroll,$access_dates,$output,$hasauto,$hascredits,
1777: $creditsrow,$domdefcredits);
1.2 raeburn 1778: my $starttime = time;
1779: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1780:
1781: my %accesstitles = (
1782: 'start' => 'Default start access',
1.16 raeburn 1783: 'end' => 'Default end access',
1.2 raeburn 1784: );
1785: my %enrolltitles = (
1786: 'start' => 'Start auto-enrollment',
1787: 'end' => 'End auto-enrollment',
1788: );
1.66 raeburn 1789: if ($showcredits) {
1790: unless ($env{'form.crstype'} eq 'community') {
1791: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1792: $domdefcredits = $domdefs{$env{'form.crstype'}.'credits'};
1793: }
1794: }
1.2 raeburn 1795: if ($env{'form.crstype'} eq 'official') {
1796: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1797: $output = &show_invalid_crosslists($invalidcrosslist);
1798: my ($section_form,$crosslist_form);
1.61 raeburn 1799: if ($instcode ne '') {
1800: $section_form = &inst_section_selector($dom,$instcode);
1801: if ($section_form eq '') {
1802: my $sectotal = $env{'form.sectotal'};
1803: if (!$sectotal) {
1804: $sectotal = 1;
1805: }
1806: if ($env{'form.addsection'}) {
1807: $sectotal ++;
1808: }
1809: for (my $i=0; $i<$sectotal; $i++) {
1810: $section_form .= §ions_form($dom,$instcode,$i);
1811: }
1812: if ($section_form) {
1813: $section_form .=
1814: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1815: '<input name="sectotal" type="hidden" value="'.$sectotal.'" />'.
1816: '<input name="addsection" type="checkbox" value="'.$sectotal.'"'.
1817: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1818: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1819: }
1820: }
1821: }
1.27 raeburn 1822: if ($section_form) {
1823: $sections = &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1824: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1825: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1.27 raeburn 1826: &Apache::lonhtmlcommon::row_closure(1).
1827: $section_form;
1828: }
1.2 raeburn 1829: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1830: if (!$crosslisttotal) {
1.2 raeburn 1831: $crosslisttotal = 1;
1832: }
1833: if ($env{'form.addcrosslist'}) {
1834: $crosslisttotal ++;
1835: }
1836: for (my $i=0; $i<$crosslisttotal; $i++) {
1837: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1838: $cat_titles,$cat_order,$i);
1839: }
1840: if ($crosslist_form) {
1841: $crosslist_form .=
1.40 raeburn 1842: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 1843: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1844: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1845: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
1.27 raeburn 1846: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1847: $sections .= &Apache::lonhtmlcommon::row_headline.
1.61 raeburn 1848: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Crosslist').' '.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1.27 raeburn 1849: &Apache::lonhtmlcommon::row_closure(1).
1850: $crosslist_form;
1.2 raeburn 1851: }
1.34 raeburn 1852: $hasauto = 1;
1.27 raeburn 1853: $autoenroll =
1.34 raeburn 1854: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1.2 raeburn 1855: '<span class="LC_nobreak"><label>'.
1856: '<input type="radio" name="autoadds" value="1">'.
1857: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1858: '<input type="radio" name="autoadds" value="0" checked="checked">'.
1859: &mt('No').'</label></span>'.
1.27 raeburn 1860: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1861: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1.2 raeburn 1862: '<span class="LC_nobreak"><label>'.
1863: '<input type="radio" name="autodrops" value="1">'.
1864: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1865: '<input type="radio" name="autodrops" value="0" checked="checked">'.
1866: &mt('No').'</label></span>'.
1.27 raeburn 1867: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1868: &date_setting_table($starttime,$endtime,$formname,'enroll',
1.66 raeburn 1869: $hasauto,undef,%enrolltitles);
1870: if ($showcredits) {
1871: if ($instcredits) {
1872: $creditsrow = &mt('[quant,_1,credit]',$instcredits);
1873: } else {
1874: $creditsrow = '<span class="LC_nobreak">'.
1875: '<input type="text" size="3" name="coursecredits"'.
1876: ' value="'.$domdefcredits.'" />';
1877: }
1878: $hascredits = 1;
1879: }
1880: }
1.69 raeburn 1881: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66 raeburn 1882: if ($showcredits) {
1883: $creditsrow = '<span class="LC_nobreak">'.
1884: '<input type="text" size="3" name="coursecredits"'.
1885: ' value="'.$domdefcredits.'"/>';
1886: $hascredits = 1;
1.2 raeburn 1887: }
1888: }
1.27 raeburn 1889: my $access_dates =
1.34 raeburn 1890: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1.66 raeburn 1891: $hascredits,%accesstitles);
1.27 raeburn 1892: $output .= &Apache::lonhtmlcommon::start_pick_box();
1893: if ($sections) {
1894: $output .= $sections;
1895: }
1896: if ($autoenroll) {
1897: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1898: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1899: &Apache::lonhtmlcommon::row_closure(1).
1900: $autoenroll;
1901: }
1902: if ($access_dates) {
1903: my $header = &mt('Access dates for students');
1904: if ($env{'form.crstype'} eq 'community') {
1905: $header = &mt('Access dates for community members');
1906: }
1907: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1908: '<h3>'.$header.'</h3>'.
1909: &Apache::lonhtmlcommon::row_closure(1).
1.66 raeburn 1910: $access_dates;
1911: }
1912: if ($creditsrow) {
1913: $output .= &Apache::lonhtmlcommon::row_headline('Credits').
1914: '<h3>'.&mt('Credits earned by students').'</h3>'.
1915: &Apache::lonhtmlcommon::row_closure(1).
1916: &Apache::lonhtmlcommon::row_title(&mt('Default credits')).
1917: $creditsrow.
1918: &Apache::lonhtmlcommon::row_closure(1);
1.2 raeburn 1919: }
1.27 raeburn 1920: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1921: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.2 raeburn 1922: }
1923:
1.27 raeburn 1924: sub show_invalid_crosslists {
1925: my ($invalidcrosslist) = @_;
1926: my $output;
1927: if (ref($invalidcrosslist) eq 'ARRAY') {
1928: if (@{$invalidcrosslist} > 0) {
1929: $output = '<div class="LC_warning">'.
1930: &mt('The following crosslisted courses were invalid:').'<ul>';
1931: foreach my $item (@{$invalidcrosslist}) {
1932: $output .= '<li>'.$item.'</li>';
1933: }
1934: $output .= '</ul></div><br />';
1935: }
1936: }
1937: return $output;
1938: }
1939:
1940:
1.1 raeburn 1941: sub inst_section_selector {
1.2 raeburn 1942: my ($dom,$instcode) = @_;
1943: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1944: my $sectotal = scalar(@sections);
1.1 raeburn 1945: my $output;
1.2 raeburn 1946: if ($sectotal) {
1.27 raeburn 1947: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1948: &Apache::loncommon::start_data_table().
1949: &Apache::loncommon::start_data_table_row().
1950: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1951: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1952: '<th>'.&mt('Institutional Section').'</th>'.
1.34 raeburn 1953: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1954: ' '.&mt('LON-CAPA section').'</th>'.
1.2 raeburn 1955: &Apache::loncommon::end_data_table_row();
1956: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1957: my $colflag = $i%2;
1.31 raeburn 1958: my $secon = ' checked="checked"';
1959: my $secoff = '';
1.24 raeburn 1960: if ($env{'form.origcnum'}) {
1.31 raeburn 1961: $secoff = $secon;
1962: $secon='';
1.24 raeburn 1963: }
1.1 raeburn 1964: $output .= &Apache::loncommon::start_data_table_row().
1.31 raeburn 1965: '<td><label><input type="radio" name="sec_'.$i.
1966: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1967: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1968: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1969: '<td align="center">'.$sections[$i].
1.1 raeburn 1970: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1971: $sections[$i].'" /></td>'.
1.1 raeburn 1972: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1973: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1974: &Apache::loncommon::end_data_table_row();
1975: }
1.2 raeburn 1976: $output .= &Apache::loncommon::end_data_table().
1977: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1978: }
1979: return $output;
1980: }
1981:
1.2 raeburn 1982: sub date_setting_table {
1.66 raeburn 1983: my ($starttime,$endtime,$formname,$prefix,$hasauto,$hascredits,%datetitles)=@_;
1.2 raeburn 1984: my ($perpetual,$table);
1.14 raeburn 1985: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.2 raeburn 1986: $starttime,'','','',1,'','','',1);
1.14 raeburn 1987: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.2 raeburn 1988: $endtime,'','','',1,'','','',1);
1.27 raeburn 1989: my $closure = '';
1.14 raeburn 1990: if ($prefix eq 'access') {
1.2 raeburn 1991: $perpetual = ' <span class="LC_nobreak"><label>'.
1992: '<input type="checkbox" name="no_end_date" />'.
1993: &mt('No end date').'</label></span>';
1.66 raeburn 1994: unless ($hascredits) {
1995: $closure = '1';
1996: }
1.2 raeburn 1997: }
1.34 raeburn 1998:
1999: my %help_item = (
2000: access => {
2001: start => 'Course_Request_Access_Start',
2002: end => 'Course_Request_Access_End',
2003: },
2004: enroll => {
2005: start => 'Course_Request_Enroll_Start',
2006: end => 'Course_Request_Enroll_End',
2007: },
2008: );
2009: if ($hasauto) {
2010: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
2011: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
2012: }
2013:
2014: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1.46 wenzelju 2015: ' '.&mt($datetitles{'start'})).$startform.
1.27 raeburn 2016: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 2017: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1.46 wenzelju 2018: ' '.&mt($datetitles{'end'})).$endform.$perpetual.
1.27 raeburn 2019: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 2020: return $table;
2021: }
2022:
2023: sub print_personnel_menu {
1.27 raeburn 2024: my ($dom,$formname,$crstype,$invalidcrosslist) = @_;
2025: my $output;
2026: if ($crstype eq 'official') {
2027: if (&Apache::lonnet::auto_run('',$dom)) {
2028: $output .= &show_invalid_crosslists($invalidcrosslist);
2029: }
2030: }
2031: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 2032: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 2033: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 2034: $persontotal = 1;
2035: }
2036: if ($env{'form.addperson'}) {
2037: $persontotal ++;
2038: }
1.13 raeburn 2039: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 2040:
1.8 raeburn 2041: my $type = 'Course';
2042: if ($crstype eq 'community') {
2043: $type = 'Community';
2044: }
1.41 raeburn 2045: my $roleoptions;
2046: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.2 raeburn 2047: foreach my $role (@roles) {
1.28 raeburn 2048: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 2049: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
2050: }
2051: my %customroles=&Apache::lonuserutils::my_custom_roles();
2052: if (keys(%customroles) > 0) {
2053: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 2054: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 2055: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
2056: }
2057: }
2058:
1.30 raeburn 2059: my @currsecs = ¤t_lc_sections();
1.2 raeburn 2060:
2061: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
2062: if (@currsecs) {
2063: my $existsize = scalar(@currsecs);
2064: if ($existsize > 3) {
2065: $existsize = 3;
2066: }
2067: if ($existsize > 1) {
2068: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
2069: }
2070: @currsecs = sort { $a <=> $b } (@currsecs);
2071: $existtitle = &mt('Official').': ';
2072: $existops = '<option value="">'.&mt('None').'</option>';
2073: foreach my $sec (@currsecs) {
2074: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
2075: }
2076: $seccolspan = ' colspan="2"';
2077: $newtitle = &mt('Other').': ';
2078: }
2079:
1.27 raeburn 2080: if ($persontotal) {
1.32 raeburn 2081: my %lt = &Apache::lonlocal::texthash(
2082: community => 'Requestor is automatically assigned Coordinator role.',
2083: official => 'Requestor is automatically assigned Course Coordinator role.',
2084: );
2085: $lt{'unofficial'} = $lt{'official'};
1.69 raeburn 2086: $lt{'textbook'} = $lt{'textbook'};
1.27 raeburn 2087: $output .= &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2088: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27 raeburn 2089: }
1.2 raeburn 2090: for (my $i=0; $i<$persontotal; $i++) {
2091: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
2092: my $linkargstr = join("','",@linkargs);
1.29 raeburn 2093: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 2094: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 2095: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 2096: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
2097: 1,$onchange).
1.29 raeburn 2098: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 2099: my %form_elems;
2100: foreach my $item (@items) {
2101: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
2102: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
2103: 'value="" readonly="readonly" />';
2104: }
2105: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
2106: $roleoptions.'</select>';
2107: my $sectionselector;
2108: if (@currsecs) {
2109: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
2110: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
2111: }
2112: $sectionselector .= $newtitle.
1.14 raeburn 2113: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29 raeburn 2114: my $usersrchlinktxt = &mt('Search for user');
2115: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
2116: $usersrchlinktxt);
2117: my $userchklinktxt = &mt('Check username');
2118: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
2119: $userchklinktxt,'checkusername');
1.2 raeburn 2120: $output .=
1.29 raeburn 2121: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
2122: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
2123: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
2124: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
2125: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
2126: '</tr>'."\n".'<tr>'.
1.13 raeburn 2127: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
2128: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
2129: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34 raeburn 2130: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
2131: '<td'.$seccolspan.' align="center" valign="top">'.
2132: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2 raeburn 2133: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
2134: }
1.40 raeburn 2135: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 2136: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
2137: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
2138: ' onclick="javascript:nextPage(document.'.$formname.",'".$env{'form.state'}.
2139: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.40 raeburn 2140: &Apache::lonhtmlcommon::end_pick_box().'</div>';
2141: if ($crstype eq 'community') {
2142: $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>';
2143: } else {
2144: $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>';
2145: }
1.2 raeburn 2146: return $output;
2147: }
2148:
1.30 raeburn 2149: sub current_lc_sections {
2150: my @currsecs;
2151: if ($env{'form.sectotal'}) {
2152: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 2153: if ($env{'form.sec_'.$i}) {
2154: if (defined($env{'form.loncapasec_'.$i})) {
2155: my $lcsec = $env{'form.loncapasec_'.$i};
2156: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
2157: push(@currsecs,$lcsec);
2158: }
1.30 raeburn 2159: }
2160: }
2161: }
2162: }
2163: return @currsecs;
2164: }
2165:
1.48 raeburn 2166: sub sorted_request_history {
1.49 raeburn 2167: my ($dom,$action,$curr_req) = @_;
2168: my ($after,$before,$statusfilter,$crstypefilter);
2169: if ($env{'form.status'} ne '') {
2170: $statusfilter = $env{'form.status'};
2171: }
2172: if ($env{'form.crstype'} ne '') {
2173: $crstypefilter = $env{'form.crstype'};
2174: }
2175: if (ref($curr_req) eq 'HASH') {
2176: $after = $curr_req->{'requested_after_date'},
2177: $before = $curr_req->{'requested_before_date'};
2178: $statusfilter = $curr_req->{'status'};
2179: $crstypefilter = $curr_req->{'crstype'};
2180: }
1.14 raeburn 2181: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2182: $env{'user.name'},'^status:'.$dom);
1.48 raeburn 2183: my %queue_by_date;
1.37 raeburn 2184: my ($types,$typenames) = &Apache::loncommon::course_types();
1.14 raeburn 2185: foreach my $key (keys(%statusinfo)) {
1.48 raeburn 2186: if ($action eq 'view') {
2187: next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
2188: } else {
1.49 raeburn 2189: next unless (($statusfilter eq 'any') ||
2190: ($statusfilter eq $statusinfo{$key}));
1.48 raeburn 2191: }
2192: (undef,my($cdom,$cnum)) = split(':',$key);
2193: next if ($cdom ne $dom);
2194: my $requestkey = $cdom.'_'.$cnum;
2195: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2196: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2197: $env{'user.domain'},$env{'user.name'});
2198: my $entry;
2199: my $reqtime = $history{'reqtime'};
2200: my $lastupdate = $history{'timestamp'};
2201: my $crstype = $history{'crstype'};
2202: my $disposition = $history{'disposition'};
2203: my $status = $history{'status'};
1.73 raeburn 2204: my $uniquecode = $history{'code'};
1.48 raeburn 2205: if ($action eq 'view') {
1.14 raeburn 2206: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
1.48 raeburn 2207: } else {
2208: next if (($reqtime < $after) || ($reqtime > $before));
2209: }
1.49 raeburn 2210: next unless (($crstypefilter eq 'any') ||
2211: ($crstypefilter eq $crstype));
1.48 raeburn 2212: if ($action eq 'view') {
1.14 raeburn 2213: next unless (($disposition eq 'approval') ||
2214: ($disposition eq 'pending'));
1.48 raeburn 2215: }
2216: if (ref($history{'details'}) eq 'HASH') {
2217: $entry = $requestkey.':'.$crstype.':'.
2218: &escape($history{'details'}{'cdescr'});
2219: if ($action eq 'log') {
1.73 raeburn 2220: $entry .= ':'.$uniquecode.':'.$lastupdate.':';
1.48 raeburn 2221: if ($statusinfo{$key} ne '') {
2222: $entry .= $statusinfo{$key};
2223: } elsif ($status ne '') {
2224: $entry .= $status;
2225: } else {
2226: $entry .= $disposition;
1.14 raeburn 2227: }
2228: }
1.48 raeburn 2229: if ($crstype eq 'official') {
2230: $entry .= ':'.&escape($history{'details'}{'instcode'});
2231: }
2232: }
2233: if ($entry ne '') {
2234: if (exists($queue_by_date{$reqtime})) {
2235: if (ref($queue_by_date{$reqtime}) eq 'ARRAY') {
2236: push(@{$queue_by_date{$reqtime}},$entry);
1.10 raeburn 2237: }
1.48 raeburn 2238: } else {
2239: @{$queue_by_date{$reqtime}} = ($entry);
1.10 raeburn 2240: }
2241: }
2242: }
2243: }
1.48 raeburn 2244: return %queue_by_date;
2245: }
2246:
2247: sub print_request_status {
2248: my ($dom,$action) = @_;
2249: my %queue_by_date = &sorted_request_history($dom,$action);
1.10 raeburn 2250: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.48 raeburn 2251: my $formname = 'requestcrs';
2252: my ($types,$typenames) = &Apache::loncommon::course_types();
2253: my $output = '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.16 raeburn 2254:
1.10 raeburn 2255: '<input type="hidden" name="state" value="'.$env{'form.state'}.'" />'."\n".
1.16 raeburn 2256: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
2257: '<input type="hidden" name="showdom" value="" />'."\n".
2258: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 2259: if (@sortedtimes > 0) {
1.40 raeburn 2260: my $desctitle;
2261: if ($env{'form.crstype'} eq 'any') {
2262: $desctitle = &mt('Course/Community Description')
2263: } elsif ($env{'form.crstype'} eq 'community') {
2264: $desctitle = &mt('Community Description')
2265: } else {
2266: $desctitle = &mt('Course Description');
2267: }
1.10 raeburn 2268: $output .= &Apache::loncommon::start_data_table().
2269: &Apache::loncommon::start_data_table_header_row().
2270: '<th>'.&mt('Action').'</th>'.
1.40 raeburn 2271: '<th>'.$desctitle.'</th>'.
1.14 raeburn 2272: '<th>'.&mt('Domain').'</th>';
2273: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 2274: $output .= '<th>'.&mt('Type').'</th>';
2275: }
1.14 raeburn 2276: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 2277: $output .= '<th>'.&mt('Institutional Code').'</th>';
2278: }
2279: $output .= '<th>'.&mt('Date requested').'</th>'.
2280: &Apache::loncommon::end_data_table_header_row();
2281: my $count = 0;
2282: foreach my $item (@sortedtimes) {
2283: my $showtime = &Apache::lonlocal::locallocaltime($item);
2284: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2285: foreach my $request (sort(@{$queue_by_date{$item}})) {
2286: my ($key,$type,$desc,$instcode) = split(':',$request);
2287: my ($cdom,$cnum) = split('_',$key);
2288: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 2289: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 2290: '<td>'.&unescape($desc).'</td>'.
2291: '<td>'.$cdom.'</td>';
2292: if ($env{'form.crstype'} eq 'any') {
1.35 raeburn 2293: my $typename;
2294: if (ref($typenames) eq 'HASH') {
2295: $typename = &mt($typenames->{$type});
2296: }
1.14 raeburn 2297: if ($typename eq '') {
2298: $typename = &mt('Unknown type');
2299: }
2300: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 2301: }
1.14 raeburn 2302: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 2303: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 2304: my $showinstcode;
2305: if ($type eq 'official') {
2306: $showinstcode = &unescape($instcode);
2307: } else {
2308: $showinstcode = &mt('Not applicable');
2309: }
2310: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 2311: }
2312: $output .= '<td>'.$showtime.'</td>'.
2313: &Apache::loncommon::end_data_table_row();
2314: }
2315: }
2316: }
2317: $output .= &Apache::loncommon::end_data_table();
2318: } else {
1.40 raeburn 2319: if ($env{'form.crstype'} eq 'any') {
2320: $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>';
2321: } elsif ($env{'form.crstype'} eq 'community') {
2322: $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>';
2323: } else {
2324: $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>';
2325: }
1.10 raeburn 2326: }
2327: $output .= '
1.30 raeburn 2328: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 2329: return $output;
1.1 raeburn 2330: }
2331:
1.16 raeburn 2332: sub print_cancel_request {
2333: my ($dom,$cnum) = @_;
2334: my $requestkey = $dom.'_'.$cnum;
2335: my ($result,$output);
2336: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2337: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2338: $env{'user.domain'},$env{'user.name'});
2339: my $timestamp = $history{'reqtime'};
2340: my $crstype = $history{'crstype'};
2341: my $status = $history{'status'};
2342: if (($status eq 'cancelled') || ($status eq 'created')) {
2343: if ($status eq 'cancelled') {
2344: $output = &mt('This request has already been cancelled.');
2345: } elsif ($status eq 'created') {
2346: $output = &mt('This request has already been processed, and a course created.');
2347: }
2348: $output = &mt('No further action will be taken');
2349: } elsif (ref($history{'details'}) eq 'HASH') {
1.37 raeburn 2350: my ($types,$typename) = &Apache::loncommon::course_types();
1.16 raeburn 2351: my $showtype = $crstype;
2352: if (defined($typename->{$crstype})) {
2353: $showtype = $typename->{$crstype};
2354: }
2355: $output = '<p>'.&Apache::loncommon::start_data_table().
2356: &Apache::loncommon::start_data_table_header_row().
2357: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2358: '<th>'.&mt('Type').'</th>'.
2359: &Apache::loncommon::end_data_table_header_row().
2360: &Apache::loncommon::start_data_table_row().
2361: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2362: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2363: '<td>'.$showtype.'</td>'.
2364: &Apache::loncommon::end_data_table_row().
2365: &Apache::loncommon::end_data_table().
1.40 raeburn 2366: '<br /><div class="LC_warning">';
2367: if ($crstype eq 'community') {
2368: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2369: } else {
2370: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2371: }
1.16 raeburn 2372: $result = 'ok';
2373: } else {
2374: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2375: }
2376: } else {
2377: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2378: }
2379: return ($result,$output);
2380: }
2381:
2382: sub viewrequest_javascript {
2383: my ($formname,$next) = @_;
2384: return <<"ENDJS";
2385:
2386: function chooseRequest(cdom,cnum) {
2387: document.$formname.showdom.value = cdom;
2388: document.$formname.cnum.value = cnum;
2389: nextPage(document.$formname,'$next');
2390: }
2391:
2392: ENDJS
2393: }
2394:
2395: sub viewdetails_javascript {
2396: my ($formname) = @_;
2397: return << "ENDJS";
2398:
2399: function nextPage(formname,nextstate) {
2400: if (nextstate == "modify") {
2401: formname.state.value = "personnel";
2402: formname.action.value = "new";
2403: } else {
2404: formname.state.value = nextstate;
2405: }
2406: formname.submit();
2407: }
2408:
2409: function backPage(formname,prevstate) {
2410: formname.state.value = prevstate;
2411: formname.submit();
2412: }
2413:
2414: ENDJS
2415: }
2416:
2417: sub viewcancel_javascript {
1.68 bisitz 2418: my $alert = &mt('Are you sure you want to cancel this request?').'\\n'.
2419: &mt('Your request will be removed.');
1.16 raeburn 2420: return << "ENDJS";
2421: function nextPage(formname,nextstate) {
2422: if (confirm('$alert')) {
2423: formname.state.value = nextstate;
2424: formname.submit();
2425: }
2426: return;
2427: }
2428:
2429: ENDJS
2430: }
2431:
1.1 raeburn 2432: sub print_request_logs {
1.73 raeburn 2433: my ($r,$dom,$jscript,$loaditems,$crumb,$usetabs) = @_;
1.48 raeburn 2434: my $title;
2435: if ($env{'form.crstype'} eq 'community') {
2436: $title = 'Community Request Logs';
2437: } elsif ($env{'form.crstype'} eq 'any') {
2438: $title = 'Course/Community Request Logs';
2439: } else {
2440: $title = 'Course Request Logs';
2441: }
2442: $r->print(&header($title,$jscript,$loaditems).$crumb);
1.73 raeburn 2443: if ($usetabs) {
2444: &startContentScreen($r,'textbooklogs');
2445: }
1.48 raeburn 2446: my $formname = 'requestcrs';
2447: $r->print('<form action="/adm/requestcourse" method="post" name="'.$formname.'" onsubmit="javascript:setPage(this);">'."\n".
2448: '<input type="hidden" name="action" value="log" />'."\n".
2449: '<input type="hidden" name="state" value="display" />'."\n");
2450: # set defaults
2451: my $now = time();
2452: my $defstart = $now - (7*24*3600); #7 days ago
2453: my %defaults = (
2454: page => '1',
2455: show => '10',
2456: crstype => 'any',
2457: status => 'any',
2458: requested_before_date => $now,
2459: requested_after_date => $defstart,
2460: );
2461: my ($types,$typenames) = &Apache::loncommon::course_types();
2462: my $more_records = 0;
2463: my %curr;
2464: foreach my $item ('show','page','crstype','status') {
2465: $curr{$item} = $env{'form.'.$item};
2466: }
2467: $curr{'requested_after_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_after_date');
2468: $curr{'requested_before_date'} = &Apache::lonhtmlcommon::get_date_from_form('requested_before_date');
2469: foreach my $key (keys(%defaults)) {
2470: if ($curr{$key} eq '') {
2471: $curr{$key} = $defaults{$key};
2472: }
2473: }
2474: my ($statuses,$statusnames) = &reqstatus_names($curr{'crstype'});
2475: $r->print('<input type="hidden" name="page" value="'.$curr{'page'}.'" />'.
2476: &requestlog_display_filter($formname,\%curr));
1.49 raeburn 2477: my %queue_by_date = &sorted_request_history($dom,$env{'form.action'},\%curr);
1.48 raeburn 2478: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
2479: my $showntablehdr = 0;
2480: my $tablehdr = &Apache::loncommon::start_data_table().
2481: &Apache::loncommon::start_data_table_header_row().
2482: '<th> </th><th>'.&mt('Request Date').'</th>'.
2483: '<th>'.&mt('Description').'</th>';
2484: if ($curr{'crstype'} eq 'any') {
2485: $tablehdr .= '<th>'.&mt('Course Type').'</th>';
2486: }
2487: if (($curr{'crstype'} eq 'official') || ($curr{'crstype'} eq 'any')) {
2488: $tablehdr .= '<th>'.&mt('Institutional Code').'</th>';
2489: }
1.73 raeburn 2490: my $showuniquecode;
2491: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
2492: if (($curr{'status'} eq 'any') || ($curr{'status'} eq 'created')) {
2493: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2494: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
2495: if ($curr{'crstype'} eq 'any') {
2496: my @types = qw(official unofficial community textbook);
2497: foreach my $type (@types) {
2498: if ($domconfig{'requestcourses'}{'uniquecode'}{$type}) {
2499: $showuniquecode = 1;
2500: last;
2501: }
2502: }
2503: } elsif ($domconfig{'requestcourses'}{'uniquecode'}{$curr{'crstype'}}) {
2504: $showuniquecode = 1;
2505: }
2506: }
2507: }
2508: }
2509: if ($showuniquecode) {
2510: $tablehdr .= '<th>'.&mt('Unique Code').'</th>';
2511: }
1.48 raeburn 2512: if ($curr{'status'} eq 'any') {
2513: $tablehdr .= '<th>'.&mt('Status').'</th>';
2514: } elsif ($curr{'status'} eq 'created') {
2515: $tablehdr .= '<th>'.&mt('Creation Date').'</th>';
2516: } elsif ($curr{'status'} eq 'cancelled') {
2517: $tablehdr .= '<th>'.&mt('Cancellation Date').'</th>';
2518: } elsif ($curr{'status'} eq 'rejected') {
2519: $tablehdr .= '<th>'.&mt('Rejection Date').'</th>';
2520: }
2521: $tablehdr .= &Apache::loncommon::end_data_table_header_row();
2522: my ($minshown,$maxshown);
2523: $minshown = 1;
2524: my $count = 0;
2525: if ($curr{'show'} ne &mt('all')) {
2526: $maxshown = $curr{'page'} * $curr{'show'};
2527: if ($curr{'page'} > 1) {
2528: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
2529: }
2530: }
2531: my $norecords;
2532: if (@sortedtimes > 0) {
2533: foreach my $item (@sortedtimes) {
2534: if ($curr{'show'} ne &mt('all')) {
2535: if ($count >= $curr{'page'} * $curr{'show'}) {
2536: $more_records = 1;
2537: last;
2538: }
2539: }
2540: $count ++;
2541: next if ($count < $minshown);
2542: if (!$showntablehdr) {
2543: $r->print($tablehdr);
2544: $showntablehdr = 1;
2545: }
2546: my $showtime = &Apache::lonlocal::locallocaltime($item);
2547: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2548: foreach my $request (sort(@{$queue_by_date{$item}})) {
1.73 raeburn 2549: my ($key,$crstype,$desc,$uniquecode,$timestamp,$status,$instcode) = split(':',$request);
1.48 raeburn 2550: my ($cdom,$cnum) = split('_',$key);
2551: my $output = &Apache::loncommon::start_data_table_row().
2552: '<td>'.$count.'</td>'.
2553: '<td>'.$showtime.'</td>'.
2554: '<td>'.&unescape($desc).'</td>';
2555: if ($curr{'crstype'} eq 'any') {
2556: my $typename;
2557: if (ref($typenames) eq 'HASH') {
2558: $typename = &mt($typenames->{$crstype});
2559: }
2560: if ($typename eq '') {
2561: $typename = &mt('Unknown type');
2562: }
2563: $output .= '<td>'.$typename.'</td>';
2564: }
2565: if (($curr{'crstype'} eq 'any') ||
2566: ($curr{'crstype'} eq 'official')) {
2567: my $showinstcode;
2568: if ($crstype eq 'official') {
2569: $showinstcode = &unescape($instcode);
2570: } else {
2571: $showinstcode = &mt('Not applicable');
2572: }
2573: $output .= '<td>'.$showinstcode.'</td>';
2574: }
1.73 raeburn 2575: if ($showuniquecode) {
2576: if ($status eq 'created') {
2577: $output .= '<td>'.$uniquecode.'</td>';
2578: } else {
2579: $output .= '<td>'.&mt('Not applicable').'</td>';
2580: }
2581: }
1.48 raeburn 2582: if ($curr{'status'} eq 'any') {
2583: my $statusname = &mt('Unknown status');
2584: if (ref($statusnames) eq 'HASH') {
2585: if ($statusnames->{$status} ne '') {
2586: $statusname = $statusnames->{$status};
2587: }
2588: }
2589: if (($status eq 'created') || ($status eq 'cancelled') ||
2590: ($status eq 'rejected')) {
2591: $statusname .= ' '.&Apache::lonlocal::locallocaltime($timestamp);
2592: }
2593: $output .= '<td>'.$statusname.'</td>';
2594: } elsif (($status eq 'created') || ($status eq 'cancelled') ||
2595: ($status eq 'rejected')) {
2596: $output .= '<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>';
2597: }
2598: $output .= &Apache::loncommon::end_data_table_row();
2599: $r->print($output);
2600: }
2601: }
2602: }
2603: if ($showntablehdr) {
2604: $r->print(&Apache::loncommon::end_data_table());
2605: if (($curr{'page'} > 1) || ($more_records)) {
2606: $r->print('<table><tr>');
2607: if ($curr{'page'} > 1) {
2608: $r->print('<td><a href="javascript:chgPage('."'previous'".');">'.&mt('Previous [_1] changes',$curr{'show'}).'</a></td>');
2609: }
2610: if ($more_records) {
2611: $r->print('<td><a href="javascript:chgPage('."'next'".');">'.&mt('Next [_1] changes',$curr{'show'}).'</a></td>');
2612: }
2613: $r->print('</tr></table>');
2614: $r->print(<<"ENDSCRIPT");
2615: <script type="text/javascript">
2616: // <![CDATA[
2617: function chgPage(caller) {
2618: if (caller == 'previous') {
2619: document.$formname.page.value --;
2620: }
2621: if (caller == 'next') {
2622: document.$formname.page.value ++;
2623: }
2624: document.$formname.submit();
1.1 raeburn 2625: return;
2626: }
1.48 raeburn 2627: // ]]>
2628: </script>
2629: ENDSCRIPT
2630: }
2631: } else {
2632: $norecords = 1;
2633: }
2634: } else {
2635: $norecords = 1;
2636: }
2637: if ($norecords) {
2638: $r->print('<p class="LC_info">'.
2639: &mt('There are no records to display').
2640: '</p>');
2641: }
1.73 raeburn 2642: if ($usetabs) {
2643: $r->print('<input type="hidden" name="tabs" value="on" />');
2644: }
2645: $r->print('</form>');
2646: if ($usetabs) {
2647: &endContentScreen($r);
2648: }
2649: $r->print(&Apache::loncommon::end_page());
1.48 raeburn 2650: return;
2651: }
2652:
2653: sub reqstatus_names {
2654: my ($crstype) = @_;
2655: my @statuses = qw(created approval pending rejected cancelled);
2656: my %statusnames =
2657: &Apache::lonlocal::texthash (
1.50 raeburn 2658: created => 'Created',
1.48 raeburn 2659: approval => 'Queued pending approval',
2660: pending => 'Queued pending validation',
2661: rejected => 'Request rejected',
2662: cancelled => 'Request cancelled',
2663: );
1.69 raeburn 2664: if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) {
1.48 raeburn 2665: $statusnames{'created'} = &mt('Course created');
2666: } elsif ($crstype eq 'community') {
2667: $statusnames{'created'} = &mt('Community created');
2668: }
2669: return (\@statuses,\%statusnames);
2670: }
2671:
2672: sub requestlog_display_filter {
2673: my ($formname,$curr) = @_;
2674: my $nolink = 1;
2675: my $output = '<table><tr><td valign="top">'.
2676: '<span class="LC_nobreak"><b>'.&mt('Records/page:').'</b></span><br />'.
2677: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
2678: (&mt('all'),5,10,20,50,100,1000,10000)).
2679: '</td><td> </td>';
2680: my $startform =
2681: &Apache::lonhtmlcommon::date_setter($formname,'requested_after_date',
2682: $curr->{'requested_after_date'},undef,
2683: undef,undef,undef,undef,undef,undef,$nolink);
2684: my $endform =
2685: &Apache::lonhtmlcommon::date_setter($formname,'requested_before_date',
2686: $curr->{'requested_before_date'},undef,
2687: undef,undef,undef,undef,undef,undef,$nolink);
2688: $output .= '<td valign="top"><b>'.&mt('Window during which course/community was requested:').'</b><br />'.
2689: '<table><tr><td>'.&mt('After:').
2690: '</td><td>'.$startform.'</td></tr>'.
2691: '<tr><td>'.&mt('Before:').'</td>'.
2692: '<td>'.$endform.'</td></tr></table>'.
2693: '</td>'.
2694: '<td> </td>';
2695: my ($types,$typenames) = &Apache::loncommon::course_types();
2696: if (ref($types) eq 'ARRAY') {
2697: if (@{$types} > 1) {
2698: $output .= '<td valign="top"><b>'.
2699: &mt('Course Type:').'</b><br /><select name="crstype">';
2700: my $selstr = '';
2701: if ($curr->{'crstype'} eq 'any') {
2702: $selstr = ' selected="selected"';
2703: }
2704: $output .= '<option value="any"'.$selstr.'>'.&mt('All types').'</option>'."\n";
2705: foreach my $crstype (@{$types}) {
2706: my $selstr = '';
2707: if ($curr->{'crstype'} eq $crstype) {
2708: $selstr = ' selected="selected"';
2709: }
2710: my $typename = $crstype;
2711: if (ref($typenames) eq 'HASH') {
2712: if ($typenames->{$crstype} ne '') {
2713: $typename = $typenames->{$crstype};
2714: }
2715: }
2716: $output .= '<option value="'.$crstype.'"'.$selstr.'>'.$typename.'</option>'."\n";
2717: }
2718: $output .= '</select></td>';
2719: }
2720: }
2721: my ($statuses,$statusnames) = &reqstatus_names($curr->{'crstype'});
2722: if (ref($statuses) eq 'ARRAY') {
2723: if (@{$statuses} > 1) {
2724: $output .= '<td valign="top"><b>'.
2725: &mt('Request Status:').'</b><br /><select name="status">';
2726: my $selstr = '';
2727: if ($curr->{'status'} eq 'any') {
2728: $selstr = ' selected="selected"';
2729: }
2730: $output .= '<option value="any"'.$selstr.'>'.&mt('Any status').'</option>'."\n";
2731: foreach my $status (@{$statuses}) {
2732: my $selstr = '';
2733: if ($curr->{'status'} eq $status) {
2734: $selstr = ' selected="selected"';
2735: }
2736: my $statusname = $status;
2737: if (ref($statusnames) eq 'HASH') {
2738: if ($statusnames->{$status} ne '') {
2739: $statusname = $statusnames->{$status};
2740: }
2741: }
2742: $output .= '<option value="'.$status.'"'.$selstr.'>'.$statusname.'</option>'."\n";
2743: }
2744: $output .= '</select></td>';
2745: }
2746: }
2747: $output .= '</tr></table>';
2748:
2749: # Update Display button
2750: $output .= '<p>'.
2751: '<input type="submit" value="'.&mt('Update Display').'" />'.
2752: '</p><hr />';
2753: return $output;
2754: }
1.1 raeburn 2755:
2756: sub print_review {
1.30 raeburn 2757: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
1.66 raeburn 2758: $disallowed,$disallowmsg,$instcredits) = @_;
1.37 raeburn 2759: my ($types,$typename) = &Apache::loncommon::course_types();
1.4 raeburn 2760: my ($owner,$ownername,$owneremail);
1.26 raeburn 2761: if ($uname eq '' || $udom eq '') {
2762: $uname = $env{'user.name'};
2763: $udom = $env{'user.domain'};
2764: }
2765: $owner = $uname.':'.$udom;
2766: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2767: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 2768: foreach my $email ('permanentemail','critnotification','notification') {
2769: $owneremail = $emails{$email};
2770: last if ($owneremail ne '');
2771: }
2772: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2773: $section_headers,$section_values,$personnel_headers,$personnel_values);
2774:
2775: $crstypename = $env{'form.crstype'};
2776: if (ref($typename) eq 'HASH') {
2777: unless ($typename->{$env{'form.crstype'}} eq '') {
1.35 raeburn 2778: $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4 raeburn 2779: }
2780: }
1.16 raeburn 2781: my $category = 'Course';
2782: if ($env{'form.crstype'} eq 'community') {
2783: $category = 'Community';
2784: }
1.4 raeburn 2785:
2786: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2787: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2788:
1.16 raeburn 2789: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2790: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 2791: if ($env{'form.crstype'} eq 'official') {
2792: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2793: foreach my $title (@{$codetitles}) {
2794: if ($env{'form.instcode_'.$title} ne '') {
2795: $inst_headers .= '<th>'.$title.'</th>';
2796: my $longitem = $env{'form.instcode_'.$title};
2797: if (ref($cat_titles->{$title}) eq 'HASH') {
2798: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2799: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2800: }
2801: }
2802: $inst_values .= '<td>'.$longitem.'</td>';
2803: }
2804: }
2805: }
1.66 raeburn 2806: $inst_headers .= '<th>'.&mt('Credits').'</th>';
2807: if ($instcredits) {
2808: $inst_values .= '<td>'.$instcredits.'</td>';
2809: } else {
2810: $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
2811: }
1.4 raeburn 2812: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 2813: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 2814: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2815: '<th>'.&mt('Automatic Drops').'</th>'.
2816: '<th>'.&mt('Enrollment Starts').'</th>'.
2817: '<th>'.&mt('Enrollment Ends').'</th>';
2818: $section_headers = '<th>'.&mt('Sections').'</th>'.
2819: '<th>'.&mt('Crosslistings').'</th>';
2820:
1.13 raeburn 2821: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 2822: my @autoroster = (&mt('No'),&mt('Yes'));
2823: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2824: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 2825: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2826: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 2827: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2828: &mt('Institutional section').'</th>'.
2829: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2830: my $secinfo;
1.4 raeburn 2831: if ($env{'form.sectotal'} > 0) {
2832: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2833: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2834: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2835: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2836: $secinfo .= $env{'form.loncapasec_'.$i};
2837: } else {
2838: $secinfo .= &mt('None');
1.4 raeburn 2839: }
1.5 raeburn 2840: $secinfo .= '</td></tr>';
1.4 raeburn 2841: }
2842: }
2843: }
1.6 raeburn 2844: if ($secinfo eq '') {
2845: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2846: }
1.6 raeburn 2847: $section_values .= $secinfo.'</table></td><td>'.
2848: '<table class="LC_innerpickbox"><tr><th>'.
2849: &mt('Institutional course/section').'</th>'.
2850: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2851: my $xlistinfo;
1.24 raeburn 2852: my $crosslisttotal = $env{'form.crosslisttotal'};
2853: if (!$crosslisttotal) {
2854: $crosslisttotal = 1;
2855: }
2856: for (my $i=0; $i<$crosslisttotal; $i++) {
2857: if ($env{'form.crosslist_'.$i}) {
2858: $xlistinfo .= '<tr><td>';
2859: if (ref($code_order) eq 'ARRAY') {
2860: if (@{$code_order} > 0) {
2861: foreach my $item (@{$code_order}) {
2862: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2863: }
2864: }
2865: }
1.24 raeburn 2866: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2867: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2868: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2869: } else {
2870: $xlistinfo .= &mt('None');
2871: }
2872: $xlistinfo .= '</td></tr>';
1.4 raeburn 2873: }
2874: }
1.6 raeburn 2875: if ($xlistinfo eq '') {
2876: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2877: }
1.24 raeburn 2878: $section_values .= $xlistinfo;
1.4 raeburn 2879: }
1.24 raeburn 2880: $section_values .= '</table></td>';
1.69 raeburn 2881: } elsif (($env{'form.crstype'} eq 'unofficial') || ($env{'form.crstype'} eq 'textbook')) {
1.66 raeburn 2882: $inst_headers .= '<th>'.&mt('Credits').'</th>';
2883: $inst_values .= '<td>'.$env{'form.coursecredits'}.'</td>';
1.4 raeburn 2884: }
2885:
2886: my %ctxt = &clone_text();
2887: $inst_headers .= '<th>'.&mt('Clone From').'</th>';
1.45 raeburn 2888: if (($env{'form.cloning'}) &&
2889: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
1.13 raeburn 2890: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
1.56 raeburn 2891: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($uname,
2892: $udom,$env{'form.clonecrs'},$env{'form.clonedom'},
1.39 raeburn 2893: $env{'form.crstype'});
1.15 raeburn 2894: if ($canclone) {
2895: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
2896: $env{'form.clonecrs'},('description','internal.coursecode'));
2897: if (keys(%courseenv) > 0) {
2898: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2899: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2900: my $cloneinst = $courseenv{'internal.coursecode'};
2901: if ($cloneinst ne '') {
1.18 raeburn 2902: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
1.15 raeburn 2903: } else {
1.18 raeburn 2904: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
1.15 raeburn 2905: }
2906: $inst_values .= '</td><td>';
2907: if ($env{'form.datemode'} eq 'preserve') {
1.16 raeburn 2908: $inst_values .= $ctxt{'prd'};
1.15 raeburn 2909: } elsif ($env{'form.datemode'} eq 'shift') {
2910: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2911: } else {
2912: $inst_values .= $ctxt{'ncd'};
2913: }
2914: $inst_values .= '</td>';
2915: } else {
2916: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2917: }
2918: } else {
2919: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
2920: }
1.4 raeburn 2921: } else {
2922: $inst_values .= '<td>'.&mt('None').'</td>';
2923: }
2924: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2925: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 2926: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2927: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2928: if ($accessend == 0) {
1.4 raeburn 2929: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2930: } else {
1.13 raeburn 2931: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 2932: }
2933:
2934: my $container = 'Course';
1.41 raeburn 2935: my $ccrole = 'cc';
1.4 raeburn 2936: if ($env{'form.crstype'} eq 'community') {
2937: $container = 'Community';
1.41 raeburn 2938: $ccrole = 'co';
1.4 raeburn 2939: }
2940:
2941: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2942: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2943: '</th>';
1.41 raeburn 2944:
1.4 raeburn 2945: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41 raeburn 2946: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4 raeburn 2947: '<td>'.&mt('None').'</td></tr>';
2948: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2949: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2950: if (ref($disallowed) eq 'ARRAY') {
2951: next if (grep(/^$i$/,@{$disallowed}));
2952: }
1.31 raeburn 2953: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2954: my @allsecs;
2955: foreach my $sec (@officialsecs) {
2956: next unless ($sec =~ /\w/);
2957: next if ($sec =~ /\W/);
2958: next if ($sec eq 'none');
2959: push(@allsecs,$sec);
2960: }
1.14 raeburn 2961: my $newsec = $env{'form.person_'.$i.'_newsec'};
2962: $newsec =~ s/^\s+//;
2963: $newsec =~s/\s+$//;
1.31 raeburn 2964: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2965: foreach my $sec (@newsecs) {
1.31 raeburn 2966: next unless ($sec =~ /\w/);
1.14 raeburn 2967: next if ($sec =~ /\W/);
1.31 raeburn 2968: next if ($sec eq 'none');
1.14 raeburn 2969: if ($sec ne '') {
2970: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2971: push(@allsecs,$sec);
2972: }
2973: }
2974: }
1.24 raeburn 2975: my $showsec;
1.14 raeburn 2976: if (@allsecs) {
2977: $showsec = join(', ',@allsecs);
2978: }
1.24 raeburn 2979: if ($showsec eq '') {
2980: $showsec = &mt('None');
2981: }
1.41 raeburn 2982: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24 raeburn 2983: $showsec = &mt('None');
2984: }
1.28 raeburn 2985: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2986: $personnel_values .=
1.13 raeburn 2987: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2988: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2989: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2990: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2991: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2992: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2993: }
2994: }
1.30 raeburn 2995: my $output;
2996: if (ref($disallowed) eq 'ARRAY') {
2997: if (@{$disallowed} > 0) {
2998: if (ref($disallowmsg) eq 'HASH') {
2999: $output = '<p class="LC_warning">'.
3000: &mt('Not all requested personnel could be included.').'<ul>';
3001: foreach my $item (@{$disallowed}) {
3002: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
3003: }
3004: $output .= '</ul></p>';
3005: }
3006: }
3007: }
3008: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 3009: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 3010: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 3011: '<th>'.&mt('Name').'</th>'.
3012: '<th>'.&mt('Username:Domain').'</th>'.
3013: '<th>'.&mt('E-mail address').'</th>'.
3014: '</tr><tr>'."\n".
3015: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
3016: '<td>'.$owneremail.'</td>'.
3017: '</tr></table>'."\n".
3018: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 3019: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 3020: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
3021: '<tr>'.$inst_values.'</tr></table>'."\n".
3022: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 3023: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 3024: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
3025: '<tr>'.$enroll_values.'</tr></table>'."\n".
3026: &Apache::lonhtmlcommon::row_closure();
3027: if ($section_headers ne '') {
3028: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
3029: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
3030: '<tr>'.$section_values.'</tr></table>'."\n".
3031: &Apache::lonhtmlcommon::row_closure();
3032: }
3033: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
3034: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
3035: $personnel_values.'</table>'."\n".
3036: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 3037: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 3038: return $output;
3039: }
3040:
3041: sub dates_from_form {
3042: my ($startname,$endname) = @_;
3043: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
3044: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 3045: if ($endname eq 'accessend') {
1.4 raeburn 3046: if (exists($env{'form.no_end_date'}) ) {
3047: $enddate = 0;
3048: }
3049: }
3050: return ($startdate,$enddate);
1.1 raeburn 3051: }
3052:
3053: sub courseinfo_form {
1.36 raeburn 3054: my ($dom,$formname,$crstype,$next,$description) = @_;
1.32 raeburn 3055: my %lt = &Apache::lonlocal::texthash(
3056: official => 'You must provide a (brief) course description.',
3057: community => 'You must provide a (brief) community description.'
3058: );
3059: $lt{'unofficial'} = $lt{'official'};
1.69 raeburn 3060: $lt{'textbook'} = $lt{'official'};
1.15 raeburn 3061: my $js_validate = <<"ENDJS";
3062: <script type="text/javascript">
3063: // <![CDATA['
3064:
3065: function validateForm() {
3066: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.32 raeburn 3067: alert('$lt{$crstype}');
1.15 raeburn 3068: return;
3069: }
3070: nextPage(document.$formname,'$next');
3071: }
1.45 raeburn 3072:
3073: function toggleCloning() {
3074: var willclone;
3075: if (document.$formname.cloning.length > 1) {
3076: for (var i=0; i<document.$formname.cloning.length; i++) {
3077: if (document.$formname.cloning[i].checked) {
3078: willclone = document.$formname.cloning[i].value;
3079: }
3080: }
3081: }
3082: if (willclone == 1) {
3083: document.getElementById('cloneoptions').style.display="block";
3084: } else {
3085: document.getElementById('cloneoptions').style.display="none";
3086: document.$formname.clonecrs.value = '';
3087: }
3088: }
3089:
1.15 raeburn 3090: // ]]
3091: </script>
3092:
3093: ENDJS
1.27 raeburn 3094: my $title = &mt('Brief Course Description');
1.40 raeburn 3095: my $clonetitle = &mt('Clone content and settings from an existing course?');
1.27 raeburn 3096: if ($crstype eq 'community') {
3097: $title = &mt('Brief Community Description');
1.40 raeburn 3098: $clonetitle = &mt('Clone content and settings from an existing community?');
1.27 raeburn 3099: }
1.45 raeburn 3100: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 3101: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 3102: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 3103: &Apache::lonhtmlcommon::row_closure(1).
3104: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.36 raeburn 3105: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.13 raeburn 3106: my ($home_server_pick,$numlib) =
3107: &Apache::loncommon::home_server_form_item($dom,'chome',
3108: 'default','hide');
3109: if ($numlib > 1) {
3110: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 3111: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 3112: }
3113: $output .= $home_server_pick.
1.27 raeburn 3114: &Apache::lonhtmlcommon::row_closure().
3115: &Apache::lonhtmlcommon::row_headline().
1.45 raeburn 3116: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
1.46 wenzelju 3117: &Apache::lonhtmlcommon::row_closure(1).
3118: &Apache::lonhtmlcommon::row_title(&mt('Clone?')).
1.45 raeburn 3119: '<label><input type="radio" name="cloning" value="1" '.
3120: 'onclick="javascript:toggleCloning()" />'.
3121: &mt('Yes').(' 'x2).'</label><label>'.
1.49 raeburn 3122: '<input type="radio" name="cloning" value="0" checked="checked" '.
1.45 raeburn 3123: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
3124: '</h3>'.
1.13 raeburn 3125: &Apache::lonhtmlcommon::row_closure(1).
1.45 raeburn 3126: &Apache::lonhtmlcommon::row_headline().
3127: '<div id="cloneoptions" style="display: none" >'.
3128: &Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 3129: &clone_form($dom,$formname,$crstype).
1.45 raeburn 3130: &Apache::lonhtmlcommon::end_pick_box().'</div>'.
3131: &Apache::lonhtmlcommon::end_pick_box()."\n";
1.1 raeburn 3132: return $output;
3133: }
3134:
3135: sub clone_form {
3136: my ($dom,$formname,$crstype) = @_;
3137: my $type = 'Course';
3138: if ($crstype eq 'community') {
3139: $type = 'Community';
3140: }
1.4 raeburn 3141: my %lt = &clone_text();
1.2 raeburn 3142: my $output .=
1.53 raeburn 3143: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
3144: &Apache::loncommon::select_dom_form($dom,'clonedom').'</label>'.
3145: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 3146: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.53 raeburn 3147: '<input type="text" size="25" name="clonecrs" value="" onfocus="this.blur();opencrsbrowser('."'$formname','clonecrs','clonedom','','','','','$type'".')" />'.
3148: '</label> '.
3149: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type).
3150: &Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 3151: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
3152: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
3153: '</label><br /><label>'.
3154: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
3155: '</label><br /><label>'.
3156: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
3157: $lt{'shd'}.'</label>'.
3158: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 3159: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 3160: return $output;
3161: }
3162:
1.16 raeburn 3163: sub clone_text {
1.4 raeburn 3164: return &Apache::lonlocal::texthash(
3165: 'cid' => 'Course ID',
3166: 'dmn' => 'Domain',
3167: 'dsh' => 'Date Shift',
3168: 'ncd' => 'Do not clone date parameters',
3169: 'prd' => 'Clone date parameters as-is',
3170: 'shd' => 'Shift date parameters by number of days',
3171: );
3172: }
3173:
1.1 raeburn 3174: sub coursecode_form {
1.2 raeburn 3175: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 3176: my $output;
1.46 wenzelju 3177: my %rowtitle = &Apache::lonlocal::texthash (
1.2 raeburn 3178: instcode => 'Course Category',
3179: crosslist => 'Cross Listed Course',
3180: );
1.34 raeburn 3181: my %helpitem = (
3182: instcode => 'Course_Request_Category',
3183: );
1.1 raeburn 3184: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
3185: (ref($cat_order))) {
1.2 raeburn 3186: my ($sel,$instsec,$lcsec);
3187: $sel = $context;
3188: if ($context eq 'crosslist') {
3189: $sel .= '_'.$num;
3190: $instsec = &mt('Institutional section').'<br />'.
3191: '<input type="text" size="10" name="'.$sel.'_instsec" />';
3192: $lcsec = &mt('LON-CAPA section').'<br />'.
3193: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
3194: }
1.1 raeburn 3195: if (@{$codetitles} > 0) {
3196: my $lastitem = pop(@{$codetitles});
1.2 raeburn 3197: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 3198: if (@{$codetitles} > 0) {
1.61 raeburn 3199: my $helplink;
3200: if (defined($helpitem{$context})) {
3201: $helplink = &Apache::loncommon::help_open_topic($helpitem{$context}).' ';
3202: }
3203: $output = &Apache::lonhtmlcommon::row_title($helplink.$rowtitle{$context}).
1.2 raeburn 3204: '<table><tr>';
1.1 raeburn 3205: if ($context eq 'crosslist') {
1.2 raeburn 3206: $output .= '<td>'.&mt('Include?').'<br />'.
3207: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 3208: }
3209: foreach my $title (@{$codetitles}) {
3210: if (ref($cat_order->{$title}) eq 'ARRAY') {
3211: if (@{$cat_order->{$title}} > 0) {
3212: $output .= '<td align="center">'.$title.'<br />'."\n".
3213: '<select name="'.$sel.'_'.$title.'">'."\n".
3214: ' <option value="" selected="selected">'.
3215: &mt('Select').'</option>'."\n";
3216: foreach my $item (@{$cat_order->{$title}}) {
3217: my $longitem = $item;
3218: if (ref($cat_titles->{$title}) eq 'HASH') {
3219: if ($cat_titles->{$title}{$item} ne '') {
3220: $longitem = $cat_titles->{$title}{$item};
3221: }
3222: }
3223: $output .= '<option value="'.$item.'">'.$longitem.
3224: '</option>'."\n";
3225: }
3226: }
3227: $output .= '</select></td>'."\n";
3228: }
3229: }
3230: if ($context eq 'crosslist') {
3231: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 3232: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
3233: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 3234: } else {
3235: $output .= '</tr></table>'.
3236: &Apache::lonhtmlcommon::row_closure().
3237: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3238: $lastinput;
3239: }
3240: } else {
3241: if ($context eq 'crosslist') {
3242: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 3243: '<table><tr>'.
3244: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
3245: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
3246: '</tr></table>';
1.1 raeburn 3247: } else {
3248: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
3249: $lastinput;
3250: }
3251: }
1.2 raeburn 3252: $output .= &Apache::lonhtmlcommon::row_closure(1);
3253: push(@$codetitles,$lastitem);
3254: } elsif ($context eq 'crosslist') {
3255: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
3256: '<table><tr><td align="center">'.
3257: '<span class="LC_nobreak">'.&mt('Include?').
3258: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
3259: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
3260: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
3261: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
3262: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 3263: }
3264: }
3265: return $output;
3266: }
3267:
1.61 raeburn 3268: sub sections_form {
3269: my ($dom,$instcode,$num) = @_;
3270: my $rowtitle;
3271: if ($instcode eq '') {
3272: $rowtitle = &mt('Sections');
3273: } else {
3274: $rowtitle = &mt('Sections of [_1]',$instcode);
3275: }
3276: return &Apache::lonhtmlcommon::row_title($rowtitle).
3277: '<table><tr><td align="center">'.
3278: '<span class="LC_nobreak">'.&mt('Include?').
3279: '<input type="checkbox" name="sec_'.$num.'" value="1" /></span>'.
3280: '</td><td align="center">'.&mt('Institutional section').'<br />'.
3281: '<input type="text" size="10" name="secnum_'.$num.'" />'.
3282: '</td><td align="center">'.&mt('LON-CAPA section').'<br />'.
3283: '<input type="text" size="10" name="loncapasec_'.$num.'" />'.
3284: '</td></tr></table>'.
3285: &Apache::lonhtmlcommon::row_closure(1);
3286: }
3287:
1.1 raeburn 3288: sub get_course_dom {
3289: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 3290: if ($env{'form.showdom'} ne '') {
3291: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
3292: return $env{'form.showdom'};
3293: }
3294: }
1.1 raeburn 3295: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37 raeburn 3296: my ($types,$typename) = &Apache::loncommon::course_types();
1.19 raeburn 3297: if (ref($types) eq 'ARRAY') {
3298: foreach my $type (@{$types}) {
3299: if (&Apache::lonnet::usertools_access($env{'user.name'},
3300: $env{'user.domain'},$type,
3301: undef,'requestcourses')) {
3302: return $env{'user.domain'};
3303: }
3304: }
3305: my @possible_doms;
3306: foreach my $type (@{$types}) {
3307: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
3308: if ($dom_str ne '') {
3309: my @domains = split(',',$dom_str);
3310: foreach my $entry (@domains) {
3311: my ($extdom,$extopt) = split(':',$entry);
3312: if ($extdom eq $env{'request.role.domain'}) {
3313: return $extdom;
3314: }
3315: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
3316: push(@possible_doms,$extdom);
3317: }
3318: }
3319: }
3320: }
3321: if (@possible_doms) {
3322: @possible_doms = sort(@possible_doms);
3323: return $possible_doms[0];
3324: }
3325: }
1.1 raeburn 3326: $codedom = $env{'user.domain'};
3327: if ($env{'request.role.domain'} ne '') {
3328: $codedom = $env{'request.role.domain'};
3329: }
3330: }
3331: return $codedom;
3332: }
3333:
3334: sub display_navbuttons {
1.31 raeburn 3335: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 3336: $r->print('<div class="LC_navbuttons">');
3337: if ($prev) {
1.16 raeburn 3338: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 3339: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 3340: (' 'x3));
1.1 raeburn 3341: } elsif ($prevtext) {
1.16 raeburn 3342: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
3343: 'onclick="javascript:history.back()"/>'.(' 'x3));
3344: }
3345: if ($state eq 'details') {
3346: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 3347: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 3348: ')" />');
1.1 raeburn 3349: }
1.31 raeburn 3350: my $gotnext;
1.15 raeburn 3351: if ($state eq 'courseinfo') {
1.16 raeburn 3352: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3353: 'onclick="javascript:validateForm();" />');
1.31 raeburn 3354: $gotnext = 1;
3355: } elsif ($state eq 'enrollment') {
3356: if (($env{'form.crstype'} eq 'official') &&
3357: (&Apache::lonnet::auto_run('',$dom))) {
3358: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3359: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
3360: $gotnext = 1;
3361: }
3362: } elsif ($state eq 'personnel') {
3363: if ($env{'form.persontotal'} > 0) {
3364: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
3365: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
3366: $gotnext = 1;
3367: }
3368: }
3369: unless ($gotnext) {
3370: if ($next) {
3371: $r->print('
3372: <input type="button" name="next" value="'.$nexttext.'" '.
3373: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
3374: }
1.1 raeburn 3375: }
3376: $r->print('</div>');
3377: }
3378:
3379: sub print_request_outcome {
1.84 raeburn 3380: my ($r,$lonhost,$dom,$codetitles,$code_order,$instcredits) = @_;
1.13 raeburn 3381: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.70 raeburn 3382: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,
3383: $uniquecode);
1.24 raeburn 3384: my $sectotal = $env{'form.sectotal'};
3385: my $crosslisttotal = 0;
1.10 raeburn 3386: $cnum = $env{'form.cnum'};
1.8 raeburn 3387: unless ($cnum =~ /^$match_courseid$/) {
3388: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
3389: return $output;
3390: }
1.73 raeburn 3391: $crstype = $env{'form.crstype'};
3392: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 3393: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
3394: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
3395: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
3396: }
1.73 raeburn 3397: if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') {
3398: $uniquecode = $domconfig{'requestcourses'}{'uniquecode'}{$crstype};
3399: }
1.9 raeburn 3400: }
1.10 raeburn 3401: $now = time;
1.41 raeburn 3402: my $ccrole = 'cc';
3403: if ($crstype eq 'community') {
3404: $ccrole = 'co';
3405: }
1.17 raeburn 3406: my @instsections;
1.8 raeburn 3407: if ($crstype eq 'official') {
3408: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 3409: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 3410: }
1.10 raeburn 3411: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
3412: if ($env{'form.sec_'.$i}) {
3413: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 3414: my $sec = $env{'form.secnum_'.$i};
3415: $sections{$i}{'inst'} = $sec;
3416: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
3417: push(@instsections,$sec);
3418: }
1.13 raeburn 3419: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.58 raeburn 3420: $sections{$i}{'loncapa'} =~ s/\W//g;
3421: if ($sections{$i}{'loncapa'} eq 'none') {
3422: $sections{$i}{'loncapa'} = '';
3423: }
1.10 raeburn 3424: }
3425: }
3426: }
3427: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
3428: if ($env{'form.crosslist_'.$i}) {
3429: my $xlistinfo = '';
3430: if (ref($code_order) eq 'ARRAY') {
3431: if (@{$code_order} > 0) {
3432: foreach my $item (@{$code_order}) {
3433: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
3434: }
3435: }
3436: }
1.22 raeburn 3437: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 3438: if ($xlistinfo ne '') {
3439: $crosslisttotal ++;
3440: }
1.22 raeburn 3441: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 3442: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 3443: }
3444: }
1.14 raeburn 3445: } else {
3446: $enrollstart = '';
3447: $enrollend = '';
1.10 raeburn 3448: }
1.62 raeburn 3449: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg,%skipped);
1.10 raeburn 3450: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3451: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 3452: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 3453: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
3454: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 3455: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
3456: $personnel{$uname.':'.$udom} = {
3457: firstname => $env{'form.person_'.$i.'_firstname'},
3458: lastname => $env{'form.person_'.$i.'_lastname'},
3459: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
3460: };
1.62 raeburn 3461: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
3462: my $usertype = &get_usertype($udom,$uname,\%curr_rules,\%got_rules);
3463: if (&Apache::lonuserutils::can_create_user($udom,'requestcrs',$usertype)) {
3464: my ($allowed,$msg,$authtype,$authparam) =
3465: &check_newuser_rules($udom,$uname,\%alerts,\%rulematch,
3466: \%inst_results,\%curr_rules,\%got_rules);
3467: if ($allowed) {
3468: my %domdefaults = &Apache::lonnet::get_domain_defaults($udom);
3469: if ($usertype eq 'official') {
3470: if ($authtype eq '') {
1.60 raeburn 3471: $authtype = $domdefaults{'auth_def'};
3472: $authparam = $domdefaults{'auth_arg_def'};
1.62 raeburn 3473: } else {
3474: if ($authtype eq 'loc') {
3475: $authtype = 'localauth';
3476: } elsif ($authtype eq 'int') {
3477: $authtype = 'internal';
3478: }
3479: if ($authtype !~ /^(krb4|krb5|internal|localauth)$/) {
3480: $authtype = $domdefaults{'auth_def'};
3481: $authparam = $domdefaults{'auth_arg_def'};
3482: }
3483: }
3484: } elsif ($usertype eq 'unofficial') {
3485: if ($authtype eq '') {
3486: $authtype = 'internal';
3487: $authparam = '';
1.60 raeburn 3488: }
1.62 raeburn 3489: } else {
3490: $authtype = $domdefaults{'auth_def'};
3491: $authparam = $domdefaults{'auth_arg_def'};
1.60 raeburn 3492: }
1.62 raeburn 3493: if (($authtype eq '') ||
3494: (($authtype =~/^krb(4|5)$/) && ($authparam eq '')) ||
3495: ($authtype !~ /^(krb4|krb5|internal|localauth)$/)) {
3496: $skipped{$uname.':'.$udom} = 1;
3497: next;
3498: } else {
3499: $personnel{$uname.':'.$udom}{'authtype'} = $authtype;
3500: $personnel{$uname.':'.$udom}{'autharg'} = $authparam;
1.60 raeburn 3501: }
3502: } else {
1.62 raeburn 3503: $skipped{$uname.':'.$udom} = 1;
1.60 raeburn 3504: next;
3505: }
3506: } else {
1.62 raeburn 3507: $skipped{$uname.':'.$udom} = 1;
1.60 raeburn 3508: next;
3509: }
3510: }
1.13 raeburn 3511: }
3512: my $role = $env{'form.person_'.$i.'_role'};
3513: unless ($role eq '') {
1.16 raeburn 3514: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 3515: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
3516: unless (grep(/^\Q$role\E$/,@curr_roles)) {
3517: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
3518: }
3519: } else {
3520: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
3521: }
1.41 raeburn 3522: if ($role eq $ccrole) {
1.13 raeburn 3523: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
3524: } else {
1.14 raeburn 3525: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 3526: my @allsecs;
3527: foreach my $sec (@currsec) {
3528: next unless ($sec =~ /\w/);
3529: next if ($sec =~ /\W/);
3530: next if ($sec eq 'none');
3531: push(@allsecs,$sec);
3532: }
1.14 raeburn 3533: my $newsec = $env{'form.person_'.$i.'_newsec'};
3534: $newsec =~ s/^\s+//;
3535: $newsec =~s/\s+$//;
3536: my @newsecs = split(/[\s,;]+/,$newsec);
3537: foreach my $sec (@newsecs) {
3538: next if ($sec =~ /\W/);
1.31 raeburn 3539: next if ($sec eq 'none');
1.14 raeburn 3540: if ($sec ne '') {
1.31 raeburn 3541: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3542: push(@allsecs,$sec);
1.13 raeburn 3543: }
3544: }
3545: }
1.31 raeburn 3546: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 3547: }
3548: }
1.10 raeburn 3549: } else {
3550: push(@missingdom,$uname.':'.$udom);
3551: }
3552: } else {
3553: push(@baduname,$uname.':'.$udom);
3554: }
1.8 raeburn 3555: }
1.62 raeburn 3556: if (keys(%skipped)) {
3557: foreach my $key (keys(%skipped)) {
3558: delete($personnel{$key});
3559: }
3560: }
1.13 raeburn 3561: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 3562: my $autodrops = 0;
3563: if ($env{'form.autodrops'}) {
3564: $autodrops = $env{'form.autodrops'};
3565: }
3566: my $autoadds = 0;
3567: if ($env{'form.autoadds'}) {
1.57 raeburn 3568: $autoadds = $env{'form.autoadds'};
1.14 raeburn 3569: }
3570: my $instcode = '';
3571: if (exists($env{'form.instcode'})) {
3572: $instcode = $env{'form.instcode'};
3573: }
1.66 raeburn 3574: my $credits;
3575: if ($instcredits) {
3576: $credits = $instcredits;
3577: } elsif (exists($env{'form.coursecredits'})) {
3578: $credits = $env{'form.coursecredits'};
3579: }
1.15 raeburn 3580: my $clonecrs = '';
3581: my $clonedom = '';
1.45 raeburn 3582: if (($env{'form.cloning'}) &&
3583: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
1.15 raeburn 3584: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.16 raeburn 3585: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
3586: $env{'form.clonedom'});
1.15 raeburn 3587: if ($clonehome ne 'no_host') {
1.16 raeburn 3588: my $canclone =
3589: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 3590: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
3591: $crstype);
1.15 raeburn 3592: if ($canclone) {
3593: $clonecrs = $env{'form.clonecrs'};
3594: $clonedom = $env{'form.clonedom'};
3595: }
3596: }
3597: }
1.8 raeburn 3598: my $details = {
1.10 raeburn 3599: owner => $env{'user.name'},
3600: domain => $env{'user.domain'},
3601: cdom => $dom,
1.11 raeburn 3602: cnum => $cnum,
1.13 raeburn 3603: coursehome => $env{'form.chome'},
3604: cdescr => $env{'form.cdescr'},
1.10 raeburn 3605: crstype => $env{'form.crstype'},
1.14 raeburn 3606: instcode => $instcode,
1.66 raeburn 3607: defaultcredits => $credits,
1.70 raeburn 3608: uniquecode => $uniquecode,
1.15 raeburn 3609: clonedom => $clonedom,
3610: clonecrs => $clonecrs,
1.10 raeburn 3611: datemode => $env{'form.datemode'},
1.14 raeburn 3612: dateshift => $env{'form.dateshift'},
3613: sectotal => $sectotal,
1.10 raeburn 3614: sections => \%sections,
1.14 raeburn 3615: crosslisttotal => $crosslisttotal,
1.13 raeburn 3616: crosslists => \%crosslistings,
1.14 raeburn 3617: autoadds => $autoadds,
3618: autodrops => $autodrops,
1.13 raeburn 3619: enrollstart => $enrollstart,
3620: enrollend => $enrollend,
3621: accessstart => $accessstart,
3622: accessend => $accessend,
1.10 raeburn 3623: personnel => \%personnel,
1.8 raeburn 3624: };
1.84 raeburn 3625: my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,
1.72 raeburn 3626: $req_notifylist,\@instsections,\%domconfig);
3627: return ($result,$output);
3628: }
3629:
3630: sub process_request {
1.84 raeburn 3631: my ($r,$lonhost,$dom,$cnum,$crstype,$now,$details,$instcode,$req_notifylist,$instsections,
1.78 raeburn 3632: $domconfig) = @_;
1.72 raeburn 3633: my (@inststatuses,$storeresult,$creationresult,$output);
1.43 raeburn 3634: my $val =
1.64 raeburn 3635: &Apache::loncoursequeueadmin::get_processtype('course',$env{'user.name'},
3636: $env{'user.domain'},$env{'user.adv'},
1.72 raeburn 3637: $dom,$crstype,\@inststatuses,$domconfig);
1.8 raeburn 3638: if ($val eq '') {
3639: if ($crstype eq 'official') {
1.19 raeburn 3640: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 3641: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 3642: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 3643: } elsif ($crstype eq 'community') {
3644: $output = &mt('You are not permitted to request creation of communities');
1.69 raeburn 3645: } elsif ($crstype eq 'textbook') {
3646: $output = &mt('You are not permitted to request creation of textbook courses');
1.8 raeburn 3647: } else {
3648: $output = &mt('Unrecognized course type: [_1]',$crstype);
3649: }
1.27 raeburn 3650: $storeresult = 'notpermitted';
1.8 raeburn 3651: } else {
1.78 raeburn 3652: my ($disposition,$message,$reqstatus,$coursedesc);
1.8 raeburn 3653: my %reqhash = (
1.14 raeburn 3654: reqtime => $now,
1.10 raeburn 3655: crstype => $crstype,
3656: details => $details,
1.8 raeburn 3657: );
3658: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 3659: my $validationerror;
1.78 raeburn 3660: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3661: $env{'user.domain'});
3662: if (ref($details) eq 'HASH') {
3663: $coursedesc = $details->{'cdescr'};
3664: }
1.10 raeburn 3665: if ($val eq 'autolimit=') {
3666: $disposition = 'process';
3667: } elsif ($val =~ /^autolimit=(\d+)$/) {
3668: my $limit = $1;
1.8 raeburn 3669: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 3670: $dom,$crstype,$limit,\$message);
1.8 raeburn 3671: } elsif ($val eq 'validate') {
1.78 raeburn 3672: my ($inststatuslist,$validationchk,$validation,%custominfo);
1.86 ! raeburn 3673: if (ref($details) eq 'HASH') {
! 3674: if ($details->{'clonecrs'}) {
! 3675: $custominfo{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
! 3676: }
! 3677: }
1.17 raeburn 3678: if (@inststatuses > 0) {
3679: $inststatuslist = join(',',@inststatuses);
3680: }
3681: my $instseclist;
1.72 raeburn 3682: if (ref($instsections) eq 'ARRAY') {
3683: if (@{$instsections} > 0) {
3684: $instseclist = join(',',@{$instsections});
3685: }
1.17 raeburn 3686: }
1.78 raeburn 3687: my $preprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'prevalidate',$env{'user.name'},
3688: $env{'user.domain'},$fullname,$coursedesc);
3689: if (ref($preprocess) eq 'HASH') {
3690: if (ref($preprocess->{'formitems'}) eq 'HASH') {
3691: foreach my $key (keys(%{$preprocess->{'formitems'}})) {
3692: if ($preprocess->{'formitems'}->{$key} eq 'multiple') {
3693: if (exists($env{'form.'.$key})) {
3694: @{$custominfo{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
3695: }
3696: } else {
3697: if (exists($env{'form.'.$key})) {
3698: $custominfo{$key} = $env{'form.'.$key};
3699: }
3700: }
3701: }
3702: }
3703: }
1.21 raeburn 3704: $validationchk =
3705: &Apache::lonnet::auto_courserequest_validation($dom,
3706: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
1.78 raeburn 3707: $inststatuslist,$instcode,$instseclist,\%custominfo);
1.21 raeburn 3708: if ($validationchk =~ /:/) {
3709: ($validation,$message) = split(':',$validationchk);
3710: } else {
3711: $validation = $validationchk;
3712: }
3713: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 3714: $disposition = 'approval';
3715: $validationerror = $1;
1.23 raeburn 3716: } else {
3717: $disposition = $validation;
1.17 raeburn 3718: }
1.8 raeburn 3719: } else {
3720: $disposition = 'approval';
3721: }
1.14 raeburn 3722: $reqhash{'disposition'} = $disposition;
3723: $reqstatus = $disposition;
1.78 raeburn 3724: my ($modified,$queued,$coursedesc,$token,%customitems);
1.73 raeburn 3725: unless ($disposition eq 'rejected') {
3726: my $inprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,'process',$env{'user.name'},
3727: $env{'user.domain'},$fullname,$coursedesc);
3728: if (ref($inprocess) eq 'HASH') {
3729: if (ref($inprocess->{'formitems'}) eq 'HASH') {
3730: foreach my $key (keys(%{$inprocess->{'formitems'}})) {
3731: if ($inprocess->{'formitems'}->{$key} eq 'multiple') {
3732: if (exists($env{'form.'.$key})) {
3733: @{$customitems{$key}} = &Apache::loncommon::get_env_multiple($env{'form.'.$key});
3734: }
3735: } else {
3736: if (exists($env{'form.'.$key})) {
3737: $customitems{$key} = $env{'form.'.$key};
3738: $reqhash{'custom'}{$key} = $customitems{$key};
3739: }
3740: }
3741: }
3742: }
3743: }
3744: }
1.8 raeburn 3745: if ($disposition eq 'rejected') {
1.40 raeburn 3746: if ($crstype eq 'community') {
3747: $output = &mt('Your community request was rejected.');
3748: } else {
3749: $output = &mt('Your course request was rejected.');
3750: }
1.8 raeburn 3751: if ($message) {
3752: $output .= '<div class="LC_warning">'.$message.'</div>';
3753: }
1.27 raeburn 3754: $storeresult = 'rejected';
1.8 raeburn 3755: } elsif ($disposition eq 'process') {
1.14 raeburn 3756: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
1.70 raeburn 3757: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles,$code);
1.8 raeburn 3758: my $type = 'Course';
3759: if ($crstype eq 'community') {
3760: $type = 'Community';
3761: }
1.41 raeburn 3762: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8 raeburn 3763: foreach my $role (@roles) {
3764: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
3765: }
1.84 raeburn 3766: $r->print('<div id="processing" style="display:block;">'."\n".
3767: &mt('Your request is being processed; this page will update when processing is complete.').
3768: '</div>');
3769: $r->rflush();
1.86 ! raeburn 3770: if (ref($details) eq 'HASH') {
! 3771: if ($details->{'clonecrs'}) {
! 3772: $customitems{'_LC_clonefrom'} = $details->{'clonedom'}.'_'.$details->{'clonecrs'};
! 3773: }
! 3774: }
1.73 raeburn 3775: my ($result,$postprocess) = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
3776: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
3777: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,
3778: \$code,\%customitems);
1.14 raeburn 3779: if ($result eq 'created') {
1.8 raeburn 3780: $disposition = 'created';
1.14 raeburn 3781: $reqstatus = 'created';
1.28 raeburn 3782: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
3783: \%longroles);
1.40 raeburn 3784: if ($crstype eq 'community') {
3785: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
3786: } else {
3787: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
3788: }
1.73 raeburn 3789: if (($code) || ((ref($postprocess) eq 'HASH') &&
3790: (($postprocess->{'createdweb'}) || ($postprocess->{'createdmsg'})))) {
3791: $output .= ¬ification_information($disposition,$env{'user.name'}.':'.$env{'user.domain'},
1.74 raeburn 3792: $dom,$cnum,$now,$code,$postprocess);
1.73 raeburn 3793: }
1.70 raeburn 3794: if ($code) {
1.73 raeburn 3795: $reqhash{'code'} = $code;
1.70 raeburn 3796: }
1.79 raeburn 3797: if (ref($postprocess) eq 'HASH') {
3798: if (ref($postprocess->{'createdactions'}) eq 'HASH') {
1.80 raeburn 3799: if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') {
3800: &Apache::loncoursequeueadmin::postprocess_crsenv($dom,$cnum,
3801: $postprocess->{'createdactions'}{'environment'});
1.79 raeburn 3802: }
3803: }
3804: }
1.40 raeburn 3805: $output .= '<br />'.$role_result.'</p>';
1.27 raeburn 3806: $creationresult = 'created';
1.8 raeburn 3807: } else {
1.40 raeburn 3808: $output = '<span class="LC_error">';
3809: if ($crstype eq 'community') {
3810: $output .= &mt('An error occurred when processing your community request.');
3811: } else {
3812: $output .= &mt('An error occurred when processing your course request.');
3813: }
3814: $output .= '<br />'.
3815: &mt('You may want to review the request details and submit the request again.').
1.14 raeburn 3816: '</span>';
1.27 raeburn 3817: $creationresult = 'error';
1.8 raeburn 3818: }
3819: } else {
3820: my $requestid = $cnum.'_'.$disposition;
1.73 raeburn 3821: my $request = {
1.8 raeburn 3822: $requestid => {
3823: timestamp => $now,
3824: crstype => $crstype,
3825: ownername => $env{'user.name'},
3826: ownerdom => $env{'user.domain'},
1.78 raeburn 3827: description => $env{'form.cdescr'},
3828: lonhost => $lonhost,
1.8 raeburn 3829: },
3830: };
1.49 raeburn 3831: if ($crstype eq 'official') {
3832: $request->{$requestid}->{'instcode'} = $instcode;
3833: }
1.16 raeburn 3834: my $statuskey = 'status:'.$dom.':'.$cnum;
3835: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
3836: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 3837: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 3838: $modified = 1;
1.25 raeburn 3839: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
3840: my %queuehash = &Apache::lonnet::get('courserequestqueue',
3841: [$cnum.'_approval',
3842: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 3843: if (($queuehash{$cnum.'_approval'} ne '') ||
3844: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 3845: $queued = 1;
1.78 raeburn 3846: if (ref($queuehash{$cnum.'_pending'}) eq 'HASH') {
3847: $token = $queuehash{$cnum.'_pending'}{'token'};
3848: }
1.16 raeburn 3849: }
3850: }
3851: unless ($queued) {
1.78 raeburn 3852: if (($disposition eq 'pending') && ($crstype ne 'official')) {
3853: my %reqinfo = (
3854: $cnum.':'.$dom => $now.':'.$env{'user.name'}.':'.$env{'user.domain'},
3855: );
3856: $token = &Apache::lonnet::tmpput(\%reqinfo,$lonhost);
3857: $request->{$requestid}->{'token'} = $token;
3858: }
1.16 raeburn 3859: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
3860: $dom);
3861: if ($putresult eq 'ok') {
1.40 raeburn 3862: if ($crstype eq 'community') {
3863: $output .= &mt('Your community request has been recorded.');
3864: } else {
3865: $output .= &mt('Your course request has been recorded.')
3866: }
1.78 raeburn 3867: unless ($disposition eq 'pending') {
3868: $output .= '<br />'.
3869: ¬ification_information($disposition,$req_notifylist,
3870: $dom,$cnum,$now);
3871: }
1.8 raeburn 3872: } else {
1.16 raeburn 3873: $reqstatus = 'domainerror';
3874: $reqhash{'disposition'} = $disposition;
3875: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
3876: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 3877: }
3878: }
3879: }
1.44 raeburn 3880: ($storeresult,my $updateresult) =
3881: &Apache::loncoursequeueadmin::update_coursereq_status(\%reqhash,$dom,
1.63 raeburn 3882: $cnum,$reqstatus,'request',$env{'user.domain'},$env{'user.name'});
1.78 raeburn 3883: if ($storeresult eq 'ok') {
3884: my $postprocess;
3885: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3886: my $updateaction = $disposition;
3887: if ($disposition eq 'approval') {
3888: $updateaction = 'queued';
3889: }
1.73 raeburn 3890: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3891: $env{'user.domain'});
1.78 raeburn 3892: $postprocess =
3893: &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$updateaction,$env{'user.name'},
1.73 raeburn 3894: $env{'user.domain'},$fullname,$env{'form.cdescr'});
1.78 raeburn 3895: }
3896: if ($modified && $queued) {
3897: if ($crstype eq 'community') {
3898: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
3899: } else {
3900: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
3901: }
3902: if ($disposition eq 'approval') {
3903: $output .= ¬ification_information($disposition,$req_notifylist,$dom,$cnum,$now);
3904: }
3905: }
3906: if ($disposition eq 'approval') {
1.73 raeburn 3907: if ((ref($postprocess) eq 'HASH') &&
3908: ((ref($postprocess->{'queuedmsg'}) eq 'HASH') || ($postprocess->{'queuedweb'}))) {
1.77 raeburn 3909: ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
1.73 raeburn 3910: }
1.78 raeburn 3911: } elsif ($disposition eq 'pending') {
3912: my $pendingform;
3913: if ($crstype ne 'official') {
3914: $pendingform = &pending_validation_form($dom,$cnum,$crstype,$now,$token,
3915: $lonhost,$env{'form.cdescr'});
3916: }
3917: if ($pendingform) {
3918: $output .= $pendingform;
3919: } else {
3920: $output .= ¬ification_information($disposition,undef,$dom,$cnum,$now,undef,$postprocess);
3921: }
1.73 raeburn 3922: }
1.16 raeburn 3923: }
1.17 raeburn 3924: if ($validationerror ne '') {
1.44 raeburn 3925: $output .= '<p class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
3926: }
3927: if ($updateresult) {
3928: $output .= $updateresult;
1.17 raeburn 3929: }
1.16 raeburn 3930: }
1.27 raeburn 3931: if ($creationresult ne '') {
3932: return ($creationresult,$output);
3933: } else {
3934: return ($storeresult,$output);
3935: }
1.16 raeburn 3936: }
3937:
1.28 raeburn 3938: sub update_requestors_roles {
3939: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3940: my $now = time;
3941: my ($active,$future,$numactive,$numfuture,$output);
3942: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3943: if (ref($details) eq 'HASH') {
3944: if (ref($details->{'personnel'}) eq 'HASH') {
1.41 raeburn 3945: my $ccrole = 'cc';
3946: if ($crstype eq 'community') {
3947: $ccrole = 'co';
3948: }
1.35 raeburn 3949: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3950: $details->{'personnel'}{$owner} = {
1.41 raeburn 3951: 'roles' => [$ccrole],
3952: $ccrole => { 'usec' => [] },
1.35 raeburn 3953: };
3954: }
3955: my @roles;
3956: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3957: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41 raeburn 3958: unless (grep(/^\Q$ccrole\E$/,@roles)) {
3959: push(@roles,$ccrole);
1.35 raeburn 3960: }
3961: } else {
1.41 raeburn 3962: @roles = ($ccrole);
1.35 raeburn 3963: }
3964: foreach my $role (@roles) {
1.42 raeburn 3965: my $refresh=$env{'user.refresh.time'};
3966: if ($refresh eq '') {
3967: $refresh = $env{'user.login.time'};
3968: }
3969: if ($refresh eq '') {
3970: $refresh = $now;
3971: }
3972: my $start = $refresh-1;
1.35 raeburn 3973: my $end = '0';
3974: if ($role eq 'st') {
3975: if ($details->{'accessstart'} ne '') {
3976: $start = $details->{'accessstart'};
3977: }
3978: if ($details->{'accessend'} ne '') {
3979: $end = $details->{'accessend'};
3980: }
3981: }
3982: my @usecs;
1.41 raeburn 3983: if ($role ne $ccrole) {
1.35 raeburn 3984: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3985: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3986: }
3987: }
3988: if ($role eq 'st') {
3989: if (@usecs > 1) {
3990: my $firstsec = $usecs[0];
3991: @usecs = ($firstsec);
3992: }
3993: }
3994: if (@usecs == 0) {
3995: push(@usecs,'');
3996: }
3997: foreach my $usec (@usecs) {
3998: my (%userroles,%newrole,%newgroups,$spec,$area);
3999: my $area = '/'.$dom.'/'.$cnum;
4000: my $spec = $role.'.'.$area;
4001: if ($usec ne '') {
4002: $spec .= '/'.$usec;
4003: $area .= '/'.$usec;
4004: }
4005: if ($role =~ /^cr\//) {
4006: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
4007: $cnum,$spec,$area);
4008: } else {
4009: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
4010: $spec,$cnum,$area);
1.28 raeburn 4011: }
1.35 raeburn 4012: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
4013: \%newgroups);
4014: $userroles{'user.role.'.$spec} = $start.'.'.$end;
4015: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
4016: if (($end == 0) || ($end > $now)) {
4017: my $showrole = $role;
1.28 raeburn 4018: if ($role =~ /^cr\//) {
1.35 raeburn 4019: $showrole = &Apache::lonnet::plaintext($role,$crstype);
4020: } elsif (ref($longroles) eq 'HASH') {
4021: if ($longroles->{$role} ne '') {
4022: $showrole = $longroles->{$role};
4023: }
1.28 raeburn 4024: }
1.35 raeburn 4025: if ($start <= $now) {
4026: $active .= '<li><a href="/adm/roles?selectrole=1&'.
4027: $spec.'=1">'.$showrole;
4028: if ($usec ne '') {
4029: $active .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 4030: }
1.35 raeburn 4031: $active .= '</a></li>';
4032: $numactive ++;
4033: } else {
4034: $future .= '<li>'.$showrole;
4035: if ($usec ne '') {
4036: $future .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 4037: }
1.35 raeburn 4038: $future .= '</li>';
4039: $numfuture ++;
1.28 raeburn 4040: }
4041: }
4042: }
4043: }
4044: }
4045: }
4046: if ($active) {
4047: if ($numactive == 1) {
1.41 raeburn 4048: if ($crstype eq 'Community') {
4049: $output = &mt('Use the following link to enter the community:');
4050: } else {
4051: $output = &mt('Use the following link to enter the course:');
4052: }
1.28 raeburn 4053: } else {
1.41 raeburn 4054: if ($crstype eq 'Community') {
4055: $output = &mt('Use the following links to your new roles to enter the community:');
4056: } else {
4057: $output = &mt('Use the following links to your new roles to enter the course:');
4058: }
1.28 raeburn 4059: }
4060: $output .= ' <ul>'.$active.'</ul><br />';
4061: }
4062: if ($future) {
1.41 raeburn 4063: if ($crstype eq 'Community') {
4064: $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'}))
4065: } else {
4066: $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'}));
4067: }
4068: $output .= ' <ul>'.$future.'</ul>';
1.28 raeburn 4069: }
4070: return $output;
4071: }
4072:
1.16 raeburn 4073: sub notification_information {
1.74 raeburn 4074: my ($disposition,$req_notifylist,$dom,$cnum,$now,$code,$postprocess) = @_;
1.16 raeburn 4075: my %emails = &Apache::loncommon::getemails();
4076: my $address;
4077: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
4078: $address = $emails{'permanentemail'};
4079: if ($address eq '') {
4080: $address = $emails{'notification'};
4081: }
4082: }
4083: my $output;
4084: if ($disposition eq 'approval') {
4085: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
4086: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
4087: if ($address ne '') {
4088: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
4089: }
4090: if ($req_notifylist) {
4091: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
1.73 raeburn 4092: $env{'user.domain'});
1.16 raeburn 4093: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
1.74 raeburn 4094: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",
4095: 'undef',$env{'form.cdescr'},$now,'coursereq',$sender);
1.16 raeburn 4096: }
1.73 raeburn 4097: if (ref($postprocess) eq 'HASH') {
4098: if (ref($postprocess->{'queuedmsg'}) eq 'ARRAY') {
4099: if (scalar(@{$postprocess->{'queuedmsg'}}) > 0) {
4100: my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
4101: my $sender = $recipient;
4102: my $addmsg = [];
4103: foreach my $item (@{$postprocess->{'queuedmsg'}}) {
4104: if (ref($item) eq 'HASH') {
4105: if ($item->{'mt'} ne '') {
4106: push(@{$addmsg},$item);
4107: }
4108: }
4109: }
4110: if (scalar(@{$addmsg}) > 0) {
1.74 raeburn 4111: &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,undef,
1.73 raeburn 4112: $env{'form.cdescr'},$now,
1.77 raeburn 4113: 'queuedcrsreq',$sender);
1.73 raeburn 4114: }
4115: }
4116: }
4117: if ($postprocess->{'queuedweb'}) {
4118: $output .= $postprocess->{'queuedweb'};
4119: }
4120: }
1.17 raeburn 4121: } elsif ($disposition eq 'pending') {
1.78 raeburn 4122: my $pending_default = '<div class="LC_info">'.
1.16 raeburn 4123: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
4124: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
4125: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
1.78 raeburn 4126: '</div>';
4127: if (ref($postprocess) eq 'HASH') {
4128: if ($postprocess->{'pendingweb'}) {
4129: $output .= $postprocess->{'pendingweb'};
4130: } else {
4131: $output .= $pending_default;
4132: }
4133: } else {
4134: $output .= $pending_default;
4135: }
1.73 raeburn 4136: } elsif ($disposition eq 'created') {
4137: if (($code) || ((ref($postprocess) eq 'HASH') &&
4138: ((ref($postprocess->{'createdmsg'}) eq 'ARRAY') || ($postprocess->{'createdweb'})))) {
4139: my $addmsg = [];
4140: my $recipient = $env{'user.name'}.':'.$env{'user.domain'};
4141: my $sender = $recipient;
4142: if ($code) {
4143: push(@{$addmsg},{
1.74 raeburn 4144: mt => 'Students can automatically select your course: "[_1]" by entering this code: [_2]',
4145: args => [$env{'form.cdescr'},$code],
1.73 raeburn 4146: });
4147: $output .= '<p>'.
4148: &mt('Students can automatically select your course by entering this code: [_1].','<b>'.$code.'</b>').
4149: '<br />'.
4150: &mt('A message has been sent to your LON-CAPA account with this information.');
4151: if ($address ne '') {
4152: $output.= '<br />'.&mt('An e-mail has also been sent to: [_1] with this code.',$address);
4153: }
4154: $output .= '</p>';
4155: }
4156: if (ref($postprocess) eq 'HASH') {
4157: if (ref($postprocess->{'createdmsg'}) eq 'ARRAY') {
4158: foreach my $item (@{$postprocess->{'createdmsg'}}) {
4159: if (ref($item) eq 'HASH') {
4160: if ($item->{'mt'} ne '') {
4161: push(@{$addmsg},$item);
4162: }
4163: }
4164: }
4165: }
4166: if ($postprocess->{'createdweb'}) {
4167: $output .= $postprocess->{'createdweb'}
4168: }
4169: }
4170: if (scalar(@{$addmsg}) > 0) {
1.77 raeburn 4171: my $type = 'createdcrsreq';
1.73 raeburn 4172: if ($code) {
4173: $type = 'uniquecode';
4174: }
1.74 raeburn 4175: &Apache::loncoursequeueadmin::send_selfserve_notification($recipient,$addmsg,$dom.'_'.$cnum,$env{'form.cdescr'},
1.73 raeburn 4176: $now,$type,$sender);
4177: }
1.70 raeburn 4178: }
1.17 raeburn 4179: } else {
4180: $output .= '<div class="LC_warning">'.
1.44 raeburn 4181: &mt('Your request status is: [_1].',$disposition).
4182: '</div>';
1.8 raeburn 4183: }
4184: return $output;
4185: }
4186:
1.78 raeburn 4187: sub pending_validation_form {
4188: my ($cdom,$cnum,$crstype,$now,$token,$lonhost,$cdesc) = @_;
4189: my $output;
4190: my %postvalues = (
4191: 'owner' => $env{'user.name'}.':'.$env{'user.domain'},
4192: 'course' => $cdom.'_'.$cnum,
4193: 'coursetype' => $crstype,
4194: );
4195: my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
4196:
4197: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
4198: my ($url,$buttontext,$code,@fields);
4199: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
4200: $postvalues{'description'} = $cdesc;
4201: $url = $domconfig{'requestcourses'}{'validation'}{'url'};
4202: if (ref($domconfig{'requestcourses'}{'validation'}{'fields'}) eq 'ARRAY') {
4203: @fields = @{$domconfig{'requestcourses'}{'validation'}{'fields'}};
4204: }
4205: $buttontext = $domconfig{'requestcourses'}{'validation'}{'button'};
4206: $output .= $domconfig{'requestcourses'}{'validation'}{'markup'};
4207: if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
4208: $output .= '<form name="crsreqvalidation" action="'.$url.'" method="post">'."\n";
4209: foreach my $field (@fields) {
4210: if ($postvalues{$field}) {
4211: $output .= '<input type="hidden" name="'.$field.'" value="'.$postvalues{$field}.'" />'."\n";
4212: }
4213: }
4214: if ($buttontext eq '') {
4215: if ($crstype eq 'community') {
4216: $buttontext = &mt('Create community');
4217: } else {
4218: $buttontext = &mt('Create course');
4219: }
4220: }
4221: my $protocol = $Apache::lonnet::protocol{$lonhost};
4222: $protocol = 'http' if ($protocol ne 'https');
4223: my $crscreator = $protocol.'://'.&Apache::lonnet::hostname($lonhost).'/cgi-bin/createpending.pl';
4224: $output .= '<input type="hidden" name="crscreator" value="'.$crscreator.'" />'."\n".
4225: '<input type="hidden" name="token" value="'.$token.'" />'."\n".
4226: '<input type="submit" name="validate" value="'.$buttontext.'" />'."\n".
4227: '</form>'."\n";
4228: }
4229: }
4230: }
4231: return $output;
4232: }
4233:
1.8 raeburn 4234: sub check_autolimit {
1.10 raeburn 4235: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
4236: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41 raeburn 4237: 'userroles',['active','future'],['cc','co'],[$dom]);
1.37 raeburn 4238: my ($types,$typename) = &Apache::loncommon::course_types();
1.10 raeburn 4239: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41 raeburn 4240: my $count = 0;
1.10 raeburn 4241: foreach my $key (keys(%requests)) {
4242: my ($cdom,$cnum) = split('_',$key);
1.41 raeburn 4243: if (ref($requests{$key}) eq 'HASH') {
4244: next if ($requests{$key}{'crstype'} ne $crstype);
4245: if (($crstype eq 'community') &&
4246: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
4247: $count ++;
1.69 raeburn 4248: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'textbook')) &&
1.41 raeburn 4249: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
4250: $count ++;
1.10 raeburn 4251: }
4252: }
4253: }
1.41 raeburn 4254: if ($count < $limit) {
1.10 raeburn 4255: return 'process';
4256: } else {
4257: if (ref($typename) eq 'HASH') {
1.41 raeburn 4258: if ($crstype eq 'community') {
4259: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
4260: '<br />'.&mt("Your limit is [_1].",$limit);
4261: } else {
4262: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
4263: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
4264: }
1.10 raeburn 4265: }
4266: return 'rejected';
4267: }
1.1 raeburn 4268: return;
4269: }
4270:
1.2 raeburn 4271: sub retrieve_settings {
1.26 raeburn 4272: my ($dom,$cnum,$udom,$uname) = @_;
4273: if ($udom eq '' || $uname eq '') {
4274: $udom = $env{'user.domain'};
4275: $uname = $env{'user.name'};
4276: }
4277: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 4278: if ($result eq 'ok') {
1.26 raeburn 4279: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 4280: $env{'form.chome'} = $reqinfo{'coursehome'};
4281: $env{'form.cdescr'} = $reqinfo{'cdescr'};
4282: $env{'form.crstype'} = $reqinfo{'crstype'};
4283: &generate_date_items($reqinfo{'accessstart'},'accessstart');
4284: &generate_date_items($reqinfo{'accessend'},'accessend');
4285: if ($reqinfo{'accessend'} == 0) {
4286: $env{'form.no_end_date'} = 1;
4287: }
4288: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
4289: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
4290: &generate_date_items($reqinfo{'enrollend'},'enrollend');
4291: }
4292: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
4293: $env{'form.clonedom'} = $reqinfo{'clonedom'};
1.55 raeburn 4294: if (($reqinfo{'clonecrs'} ne '') && ($reqinfo{'clonedom'} ne '')) {
4295: $env{'form.cloning'} = 1;
4296: }
1.16 raeburn 4297: $env{'form.datemode'} = $reqinfo{'datemode'};
4298: $env{'form.dateshift'} = $reqinfo{'dateshift'};
1.59 raeburn 4299: if ($reqinfo{'crstype'} eq 'official') {
4300: $env{'form.autoadds'} = $reqinfo{'autoadds'};
4301: $env{'form.autodrops'} = $reqinfo{'autodrops'};
4302: if ($reqinfo{'instcode'} ne '') {
4303: $env{'form.sectotal'} = $reqinfo{'sectotal'};
4304: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
4305: $env{'form.instcode'} = $reqinfo{'instcode'};
4306: my $crscode = {
4307: $cnum => $reqinfo{'instcode'},
4308: };
4309: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.66 raeburn 4310: (undef,undef,my $instcredits) =
4311: &Apache::lonnet::auto_validate_instcode(undef,$dom,
4312: $reqinfo{'instcode'});
4313: if ($instcredits ne $reqinfo{'defaultcredits'}) {
4314: $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
4315: }
1.59 raeburn 4316: }
1.69 raeburn 4317: } elsif (($reqinfo{'crstype'} eq 'unofficial') || ($reqinfo{'crstype'} eq 'textbook')) {
1.66 raeburn 4318: $env{'form.coursecredits'} = $reqinfo{'defaultcredits'};
1.16 raeburn 4319: }
4320: my @currsec;
4321: if (ref($reqinfo{'sections'}) eq 'HASH') {
4322: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
4323: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 4324: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 4325: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 4326: $env{'form.sec_'.$i} = '1';
1.16 raeburn 4327: if (!grep(/^\Q$sec\E$/,@currsec)) {
4328: push(@currsec,$sec);
4329: }
4330: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
4331: }
4332: }
4333: }
1.24 raeburn 4334: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
4335: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
4336: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
4337: $env{'form.crosslist_'.$i} = '1';
4338: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
4339: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
4340: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
4341: my $key = $cnum.$i;
4342: my $crscode = {
4343: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
4344: };
4345: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
4346: }
1.16 raeburn 4347: }
4348: }
4349: }
4350: if (ref($reqinfo{'personnel'}) eq 'HASH') {
4351: my $i = 0;
4352: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
4353: my ($uname,$udom) = split(':',$user);
4354: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
4355: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
4356: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
4357: $env{'form.person_'.$i.'_role'} = $role;
4358: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
4359: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
4360: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
4361: $env{'form.person_'.$i.'_uname'} = $uname;
4362: $env{'form.person_'.$i.'_dom'} = $udom;
4363: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
4364: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
4365: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
4366: my @newsecs;
4367: if (@usecs > 0) {
4368: foreach my $sec (@usecs) {
4369: if (grep(/^\Q$sec\E/,@currsec)) {
4370: $env{'form.person_'.$i.'_sec'} = $sec;
4371: } else {
1.20 raeburn 4372: push(@newsecs,$sec);
1.16 raeburn 4373: }
4374: }
4375: }
4376: if (@newsecs > 0) {
4377: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
4378: }
4379: }
4380: }
4381: $i ++;
4382: }
4383: }
4384: }
4385: }
4386: $env{'form.persontotal'} = $i;
4387: }
4388: }
4389: }
4390: return $result;
4391: }
4392:
4393: sub get_request_settings {
1.26 raeburn 4394: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 4395: my $requestkey = $dom.'_'.$cnum;
4396: my ($result,%reqinfo);
4397: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 4398: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 4399: my $disposition = $history{'disposition'};
4400: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
4401: if (ref($history{'details'}) eq 'HASH') {
4402: %reqinfo = %{$history{'details'}};
4403: $result = 'ok';
4404: } else {
4405: $result = 'nothash';
4406: }
4407: } else {
4408: $result = 'notqueued';
4409: }
4410: } else {
4411: $result = 'invalid';
4412: }
4413: return ($result,%reqinfo);
4414: }
1.2 raeburn 4415:
1.16 raeburn 4416: sub extract_instcode {
1.24 raeburn 4417: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 4418: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 4419: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
4420: \@codetitles,\%cat_titles,
4421: \%cat_order) eq 'ok') {
4422: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 4423: if (@codetitles > 0) {
4424: my $sel = $element;
4425: if ($element eq 'crosslist') {
4426: $sel .= '_'.$counter;
4427: }
4428: foreach my $title (@codetitles) {
1.24 raeburn 4429: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 4430: }
4431: }
4432: }
4433: }
4434: return;
1.2 raeburn 4435: }
4436:
1.16 raeburn 4437: sub generate_date_items {
4438: my ($currentval,$item) = @_;
4439: if ($currentval =~ /\d+/) {
4440: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
4441: &Apache::lonhtmlcommon::get_timedates($currentval);
4442: $env{'form.'.$item.'_day'} = $mday;
4443: $env{'form.'.$item.'_month'} = $month+1;
4444: $env{'form.'.$item.'_year'} = $year;
4445: }
4446: return;
1.2 raeburn 4447: }
4448:
1.72 raeburn 4449: sub print_textbook_form {
1.73 raeburn 4450: my ($r,$dom,$incdoms,$domdefs,$settings,$can_request) = @_;
1.81 raeburn 4451: my (%prefab,%ordered,%numprefab);
1.72 raeburn 4452: my $crstype = 'textbook';
4453: #
1.81 raeburn 4454: # Retrieve list of prefabricated courses (textbook courses and templates) cloneable by user
1.72 raeburn 4455: #
1.81 raeburn 4456: foreach my $type ('textbooks','templates') {
4457: $numprefab{$type} = 0;
4458: if (ref($settings) eq 'HASH') {
4459: $prefab{$type} = $settings->{$type};
4460: if (ref($prefab{$type}) eq 'HASH') {
4461: foreach my $item (keys(%{$prefab{$type}})) {
1.72 raeburn 4462: my ($clonedom,$clonecrs) = split(/_/,$item);
1.81 raeburn 4463: if (ref($prefab{$type}{$item}) eq 'HASH') {
4464: if (&Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
4465: $env{'user.domain'},$clonecrs,$clonedom,$crstype)) {
4466:
4467: my $num = $prefab{$type}{$item}{'order'};
4468: $ordered{$type}{$num} = $item;
4469: $numprefab{$type} ++;
4470: }
1.72 raeburn 4471: }
4472: }
4473: }
4474: }
4475: }
4476:
4477: #
4478: # Check if domain has multiple library servers
4479: #
4480: my ($home_server_pick,$numlib) =
4481: &Apache::loncommon::home_server_form_item($dom,'chome',
4482: 'default','hide');
4483: if ($numlib > 1) {
4484: $home_server_pick = &mt('Home Server for Course').': '.$home_server_pick.'<br />';
4485: }
4486:
4487: #
4488: # Retrieve information about courses owned by user, or in which user has an active or future
4489: # Course Coordinator role
4490: #
4491: my $numcurrent;
4492: my %cloneable = &Apache::lonnet::courseiddump($dom,'.',1,'.',$env{'user.name'}.':'.$env{'user.domain'},
4493: undef,undef,undef,'Course');
4494: my %ccroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
4495: ['active','future'],['cc']);
4496: foreach my $role (keys(%ccroles)) {
4497: my ($cnum,$cdom,$rest) = split(/:/,$role,3);
4498: unless (exists($cloneable{$cdom.'_'.$cnum})) {
4499: my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{'one_time' => 1});
4500: $cloneable{$cdom.'_'.$cnum} = \%courseinfo;
4501: }
4502: }
4503:
4504: my $numcurrent = scalar(keys(%cloneable));
4505:
1.81 raeburn 4506: my $jscript = &textbook_request_javascript(\%numprefab,$numcurrent);
1.72 raeburn 4507: my %loaditems;
4508: $loaditems{'onload'} = 'javascript:uncheckAllRadio();';
4509: $r->print(&header('Course Request',$jscript,\%loaditems));
4510:
1.73 raeburn 4511: if (ref($can_request) eq 'HASH') {
4512: unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
4513: &Apache::lonhtmlcommon::add_breadcrumb(
4514: { href => '/adm/requestcourse',
4515: text => 'Pick action',
4516: });
4517: }
4518: }
1.72 raeburn 4519: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
4520: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
4521:
1.73 raeburn 4522: &startContentScreen($r,'textbookrequests');
1.72 raeburn 4523: #
4524: # Show domain selector form, if required.
4525: #
4526: if (@{$incdoms} > 1) {
4527: my $onchange = 'this.form.submit()';
4528: $r->print('<form name="domforcourse" method="post" action="/adm/requestcourse">'.
4529: '<div><fieldset><legend>'.&mt('Domain').'</legend>'.
4530: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,$incdoms).
4531: '</fieldset></form>');
4532: }
4533:
4534: #
4535: # Course request form
4536: #
4537:
4538: #
4539: # Course Title
4540: #
4541: $r->print('<form name="requestcourse" method="post" action="/adm/requestcourse" onsubmit="return validTextbookReq();">'.
4542: '<div>'.
4543: '<fieldset>'.
4544: '<legend>'.&mt('Course Information').'</legend>'.
4545: '<span class="LC_nobreak">'.&mt('Title').': '.
4546: '<input type="text" size="60" name="cdescr" value="" /></span><br />'.
4547: $home_server_pick.'<br /></fieldset>'.
4548: '</div>');
4549:
4550: #
4551: # Content source selection, if more than one available
4552: #
4553: if (keys(%cloneable) || keys(%ordered)) {
4554: $r->print('<div>'.
4555: '<fieldset><legend>'.&mt('Course Content').'</legend>');
4556: if (keys(%ordered)) {
1.81 raeburn 4557: if (ref($ordered{'textbooks'}) eq 'HASH') {
4558: $r->print('<span class="LC_nobreak"><label>'.
4559: '<input type="radio" name="cloning" value="textbook" onclick="javascript:cloneChoice();" />'.
4560: &mt('Load textbook content').'</span>'.(' 'x2).' ');
4561: }
4562: if (ref($ordered{'templates'}) eq 'HASH') {
4563: $r->print('<span class="LC_nobreak"><label>'.
4564: '<input type="radio" name="cloning" value="template" onclick="javascript:cloneChoice();" />'.
1.83 raeburn 4565: &mt('Load pre-existing template').'</span>'.(' 'x2).' ');
1.81 raeburn 4566: }
1.72 raeburn 4567: }
4568: if (keys(%cloneable)) {
4569: $r->print('<span class="LC_nobreak"><label>'.
4570: '<input type="radio" name="cloning" value="existing" onclick="javascript:cloneChoice();" />'.
4571: &mt('Copy one of your courses').'</label></span>'.(' 'x2).' ');
4572: }
4573: $r->print('<span class="LC_nobreak"><label>'.
4574: '<input type="radio" name="cloning" value="none" checked="checked" onclick="javascript:cloneChoice();" />'.
4575: &mt('Empty course shell').'</label></span>');
4576: } else {
4577: $r->print('<input type="hidden" name="cloning" value="none" />');
4578: }
4579:
4580: #
4581: # Table of cloneable textbook courses
4582: #
4583: if (keys(%ordered)) {
1.81 raeburn 4584: foreach my $type ('textbooks','templates') {
4585: my $divid = 'showtextbook';
4586: my $radioid = 'book';
4587: if ($type eq 'templates') {
4588: $divid = 'showtemplate';
4589: $radioid = 'template';
4590: }
4591: if (ref($ordered{$type}) eq 'HASH') {
4592: $r->print('<div id="'.$divid.'" style="display:none">'.
4593: &Apache::loncommon::start_data_table().
4594: &Apache::loncommon::start_data_table_header_row().
4595: '<th>'.&mt('Title').'</th>');
4596: if ($type eq 'textbooks') {
4597: $r->print('<th>'.&mt('Author(s)').'</th>');
4598: }
4599: $r->print('<th>'.&mt('Subject').'</th>');
4600: if ($type eq 'textbooks') {
1.82 raeburn 4601: $r->print('<th>'.&mt('Publisher').'</th>'.
4602: '<th>'.&mt('Book').'</th>');
1.81 raeburn 4603: }
4604: $r->print(&Apache::loncommon::end_data_table_header_row());
4605: my @items = sort { $a <=> $b } keys(%{$ordered{$type}});
4606: foreach my $num (@items) {
4607: my $item = $ordered{$type}{$num};
4608: my $cleantitle=&HTML::Entities::encode($prefab{$type}{$item}{'title'},'<>&"');
4609: $cleantitle=~s/'/\\'/g;
4610: $cleantitle =~ s/^\s+//;
4611: $r->print(&Apache::loncommon::start_data_table_row().
4612: '<td><label><input type="radio" name="'.$radioid.'" value="'.$item.'" />'.
4613: $cleantitle.'</label></td>');
4614: if ($type eq 'textbooks') {
4615: $r->print('<td>'.$prefab{$type}{$item}{'author'}.'</td>');
4616: }
4617: $r->print('<td>'.$prefab{$type}{$item}{'subject'}.'</td>');
4618: if ($type eq 'textbooks') {
1.82 raeburn 4619: $r->print('<td>'.$prefab{$type}{$item}{'publisher'}.'</td>'.
4620: '<td><img border="0" src="'.$prefab{$type}{$item}{'image'}.
1.81 raeburn 4621: '" alt="'.$cleantitle.'" /></td>');
4622: }
4623: $r->print(&Apache::loncommon::end_data_table_row());
4624: }
4625: $r->print(&Apache::loncommon::end_data_table().
4626: '</div>');
4627: }
1.72 raeburn 4628: }
4629: }
4630:
4631: #
4632: # Table of user's current courses (owner and/or course coordinator)
4633: #
4634: if (keys(%cloneable)) {
4635: my %lt = &clone_text();
4636: $r->print('<div id="showexisting" style="display:none">'.
4637: &Apache::loncommon::start_data_table().
4638: &Apache::loncommon::start_data_table_header_row().
4639: '<th>'.&mt('Title').'</th>'.
4640: '<th>'.&mt('Owner/co-owner(s)').'</th>'.
4641: &Apache::loncommon::end_data_table_header_row());
4642: my %allownernames;
4643: my %sortbytitle;
4644: foreach my $cid (sort(keys(%cloneable))) {
4645: if (ref($cloneable{$cid}) eq 'HASH') {
4646: my $cdesc = $cloneable{$cid}{'description'};
4647: $cdesc =~ s/`/'/g;
4648: if ($cdesc ne '') {
4649: push(@{$sortbytitle{$cdesc}},$cid);
4650: }
4651: }
4652: }
4653: foreach my $title (sort(keys(%sortbytitle))) {
4654: if (ref($sortbytitle{$title}) eq 'ARRAY') {
4655: foreach my $cid (sort(@{$sortbytitle{$title}})) {
4656: my $cleantitle=&HTML::Entities::encode($title,'<>&"');
4657: $cleantitle=~s/'/\\'/g;
4658: $cleantitle =~ s/^\s+//;
4659: my ($namestr,@owners,%ownernames);
4660: my $singleowner = $cloneable{$cid}{'internal.courseowner'};
4661: push(@owners,$singleowner);
4662: if ($cloneable{$cid}{'co-owners'} ne '') {
4663: foreach my $item (split(/,/,$cloneable{$cid}{'internal.co-owners'})) {
4664: push(@owners,$item);
4665: }
4666: }
4667: foreach my $owner (@owners) {
4668: my ($ownername,$ownerdom);
4669: if ($owner =~ /:/) {
4670: ($ownername,$ownerdom) = split(/:/,$owner);
4671: } else {
4672: $ownername = $owner;
4673: if ($owner ne '') {
4674: $ownerdom = $dom;
4675: }
4676: }
4677: if ($ownername ne '' && $ownerdom ne '') {
4678: if (exists($allownernames{$ownername.':'.$ownerdom})) {
4679: $ownernames{$ownername.':'.$ownerdom} = $allownernames{$ownername.':'.$ownerdom};
4680: } else {
4681: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
4682: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
4683: $allownernames{$ownername.':'.$ownerdom} = $ownernames{$ownername.':'.$ownerdom};
4684: }
4685: }
4686: }
4687: my @lastnames;
4688: foreach my $owner (keys(%ownernames)) {
4689: if (ref($ownernames{$owner}) eq 'HASH') {
4690: push(@lastnames,$ownernames{$owner}{'lastname'});
4691: }
4692: }
4693: if (@lastnames) {
4694: $namestr = join(', ',sort(@lastnames));
4695: }
4696: $r->print(&Apache::loncommon::start_data_table_row().
4697: '<td><label><input type="radio" name="owned" value="'.$cid.'" />'.
4698: ' '.$cleantitle.'</label></td>'.
4699: '<td>'.$namestr.'</td>'.
4700: &Apache::loncommon::end_data_table_row());
4701: }
4702: }
4703: }
4704: $r->print(&Apache::loncommon::end_data_table().
4705: '<p><input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
4706: '</label><br /><label>'.
4707: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
4708: '</label><br /><label>'.
4709: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
4710: $lt{'shd'}.'</label>'.
4711: '<input type="text" size="5" name="dateshift" value="365" />'.
4712: '</div>');
4713: }
4714: #
4715: # End of content selector
4716: #
4717: if (keys(%cloneable) || keys(%ordered)) {
4718: $r->print('</fieldset></div>');
4719: }
4720:
4721: my %accesstitles = (
4722: 'start' => 'Default start access',
4723: 'end' => 'Default end access',
4724: );
4725: my %help_item = (
4726: start => 'Course_Request_Access_Start',
4727: end => 'Course_Request_Access_End',
4728: );
4729: my $starttime = time;
4730: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
4731: my $startform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessstart',
4732: $starttime,'','','',1,'','','',1);
4733: my $endform = &Apache::lonhtmlcommon::date_setter('requestcourse','accessend',
4734: $endtime,'','','',1,'','','',1);
4735: #
4736: # Set default start and end dates for student access
4737: #
4738: $r->print('<div>'.
4739: '<fieldset><legend>'.&mt('Student Access Dates').'</legend>'.
4740: &Apache::loncommon::help_open_topic($help_item{'start'}).
4741: ' '.&mt($accesstitles{'start'}).$startform.'<br />'.
4742: &Apache::loncommon::help_open_topic($help_item{'end'}).
4743: ' '.&mt($accesstitles{'end'}).$endform.'<br /></div>');
4744:
4745: #
1.73 raeburn 4746: # Display any custom fields for this course type
4747: #
4748: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
4749: $env{'user.domain'});
4750: my $postprocess = &Apache::lonnet::auto_crsreq_update($dom,undef,$crstype,'review',
4751: $env{'user.name'},
4752: $env{'user.domain'},$fullname);
4753: if (ref($postprocess) eq 'HASH') {
4754: if ($postprocess->{'reviewweb'}) {
4755: $r->print($postprocess->{'reviewweb'});
4756: }
4757: }
4758:
4759: #
1.72 raeburn 4760: # Submit button
4761: #
1.73 raeburn 4762: $r->print('<input type="hidden" name="crstype" value="textbook" />'.
4763: '<input type="hidden" name="action" value="process" />'.
1.72 raeburn 4764: '<input type="submit" value="'.&mt('Create course').'" />');
4765:
4766: #
4767: # End request form
4768: #
1.73 raeburn 4769: $r->print('</form>');
4770: &endContentScreen($r).
4771: $r->print(&Apache::loncommon::end_page());
1.72 raeburn 4772: return;
4773: }
4774:
4775: sub process_textbook_request {
1.73 raeburn 4776: my ($r,$dom,$action,$domdefs,$domconfig,$can_request) = @_;
1.72 raeburn 4777: my ($uniquecode,$req_notifylist);
4778: my $crstype = 'textbook';
4779: if (ref($domconfig) eq 'HASH') {
4780: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
4781: if (ref($domconfig->{'requestcourses'}{'notify'}) eq 'HASH') {
4782: $req_notifylist = $domconfig->{'requestcourses'}{'notify'}{'approval'};
4783: }
4784: if (ref($domconfig->{'requestcourses'}{'uniquecode'}) eq 'HASH') {
4785: $uniquecode = $domconfig->{'requestcourses'}{'uniquecode'}{$crstype};
4786: }
4787: }
4788: }
4789: my $now = time;
4790: my $reqtype = $env{'form.cloning'};
4791: my (@inststatuses,$storeresult,$creationresult);
4792: my $cnum = &Apache::lonnet::generate_coursenum($dom,'Course');
4793: my ($clonefrom,$clonedom,$clonecrs);
4794: if ($reqtype eq 'textbook') {
4795: $clonefrom = $env{'form.book'};
1.81 raeburn 4796: } elsif ($reqtype eq 'template') {
4797: $clonefrom = $env{'form.template'};
1.72 raeburn 4798: } elsif ($reqtype eq 'existing') {
4799: $clonefrom = $env{'form.owned'};
4800: }
4801: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
4802: if ($clonefrom) {
4803: ($clonedom,$clonecrs) = split(/_/,$clonefrom);
4804: if (&Apache::lonnet::homeserver($clonecrs,$clonedom) ne 'no_host') {
4805: my $canclone =
4806: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
4807: $env{'user.domain'},$clonecrs,$clonedom,$crstype);
4808: unless ($canclone) {
4809: undef($clonecrs);
4810: undef($clonedom);
4811: }
4812: } else {
4813: undef($clonecrs);
4814: undef($clonedom);
4815: }
4816: }
1.84 raeburn 4817: my $js = &processing_javascript();
4818: my $loaditems = {
4819: onload => 'javascript:hideProcessing();',
4820: };
4821: $r->print(&header('Course Creation',$js,$loaditems));
1.72 raeburn 4822:
1.73 raeburn 4823: if (ref($can_request) eq 'HASH') {
4824: unless ((scalar(keys(%{$can_request})) == 1) && ($can_request->{'textbook'})) {
4825: &Apache::lonhtmlcommon::add_breadcrumb(
4826: { href => '/adm/requestcourse',
4827: text => 'Pick action',
4828: });
4829: }
4830: }
1.72 raeburn 4831: &Apache::lonhtmlcommon::add_breadcrumb(
4832: { href => '/adm/requestcourse',
4833: text => "Create Course",
4834: }
4835: );
4836: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Request Processed'});
4837: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests'));
1.73 raeburn 4838: &startContentScreen($r,'textbookrequests');
1.72 raeburn 4839:
4840: my $details = {
4841: owner => $env{'user.name'},
4842: domain => $env{'user.domain'},
4843: cdom => $dom,
4844: cnum => $cnum,
4845: coursehome => $env{'form.chome'},
4846: cdescr => $env{'form.cdescr'},
4847: crstype => $crstype,
4848: uniquecode => $uniquecode,
4849: clonedom => $clonedom,
4850: clonecrs => $clonecrs,
4851: accessstart => $accessstart,
4852: accessend => $accessend,
4853: personnel => {},
4854: };
4855: if ($reqtype eq 'existing') {
4856: $details->{datemode} = $env{'form.datemode'};
4857: $details->{dateshift} = $env{'form.dateshift'};
4858: }
1.78 raeburn 4859: my $lonhost = $r->dir_config('lonHostID');
1.84 raeburn 4860: $r->rflush();
4861: my ($result,$output) = &process_request($r,$lonhost,$dom,$cnum,$crstype,$now,$details,'',
1.78 raeburn 4862: $req_notifylist,[],$domconfig);
1.72 raeburn 4863: $r->print($output);
4864: if (&Apache::loncoursequeueadmin::author_prompt()) {
4865: &print_author_prompt($r,$action,$cnum,$dom,$crstype,$result);
4866: } elsif ($result eq 'created') {
4867: $r->print('<p><a href="/adm/requestcourse">'.&mt('Create another course').'</a></p>');
4868: }
1.73 raeburn 4869: &endContentScreen($r);
1.72 raeburn 4870: $r->print(&Apache::loncommon::end_page());
4871: }
4872:
4873: sub textbook_request_javascript {
1.81 raeburn 4874: my ($numprefab,$numcurrent) = @_;
4875: return unless (ref($numprefab) eq 'HASH');
4876: return if (!$numprefab->{'textbooks'} && !$numprefab->{'templates'} && !$numcurrent);
1.72 raeburn 4877: my %lt = &Apache::lonlocal::texthash(
4878: choose => 'Please select a content option.',
4879: textbook => 'Please select a textbook, or choose a different option.',
1.81 raeburn 4880: template => 'Please select a template, or choose a different option.',
1.72 raeburn 4881: existing => 'Please select one of your existing courses to copy, or choose a different option.',
4882: title => 'Please enter a course title.',
4883: );
4884: return <<"ENDSCRIPT";
4885: function cloneChoice() {
4886: if (document.requestcourse.cloning) {
4887: var radioLength = document.requestcourse.cloning.length;
4888: if (radioLength == undefined) {
4889: var val = document.requestcourse.cloning.value;
1.81 raeburn 4890: if ((val == 'textbook') || (val == 'template') || (val == 'existing')) {
1.72 raeburn 4891: var elem = document.getElementById('show'+val);
4892: if (document.requestcourse.cloning.checked) {
4893: elem.style.display = 'block';
4894: } else {
4895: uncheckRadio(val);
4896: elem.style.display = 'none';
4897: }
4898: }
4899: } else {
4900: for (var i=0; i<radioLength; i++) {
4901: var val = document.requestcourse.cloning[i].value;
1.81 raeburn 4902: if ((val == 'textbook') || (val == 'template') || (val == 'existing')) {
1.72 raeburn 4903: var elem = document.getElementById('show'+val);
4904: if (document.requestcourse.cloning[i].checked) {
4905: elem.style.display = 'block';
4906: } else {
4907: if (val == 'textbook') {
4908: uncheckRadio('book');
4909: }
1.81 raeburn 4910: if (val == 'template') {
4911: uncheckRadio('template');
4912: }
1.72 raeburn 4913: if (val == 'existing') {
4914: uncheckRadio('owned');
4915: }
4916: elem.style.display = 'none';
4917: }
4918: }
4919: }
4920: }
4921: }
4922: return;
4923: }
4924:
4925: function uncheckRadio(radioGroupName) {
4926: var group = document.getElementsByName(radioGroupName);
4927: var radioLength = group.length;
4928: if (radioLength == undefined) {
4929: group.checked = false;
4930: } else {
4931: for (var i=0; i<radioLength; i++) {
4932: group[i].checked = false;
4933: }
4934: }
4935: return;
4936: }
4937:
4938: function uncheckAllRadio() {
4939: uncheckRadio('cloning');
1.81 raeburn 4940: var numbook = $numprefab->{'textbooks'};
4941: var numtemplate = $numprefab->{'templates'};
1.72 raeburn 4942: var numcurrent = $numcurrent;
4943: if (numbook > 0) {
4944: uncheckRadio('textbook');
4945: }
1.81 raeburn 4946: if (nutemplate > 0) {
4947: uncheckRadio('template');
4948: }m
1.72 raeburn 4949: if (numcurrent > 0) {
4950: uncheckRadio('existing');
4951: }
4952: return;
4953: }
4954:
4955: function validTextbookReq() {
4956: if (document.requestcourse.cloning) {
4957: var cloneChoice = 0;
4958: var radioLength = document.requestcourse.cloning.length;
4959: if (radioLength == undefined) {
4960: if (document.requestcourse.cloning.checked == false) {
4961: alert("$lt{'choose'}");
4962: return false;
4963: } else {
4964: cloneChoice = document.requestcourse.cloning.value;
4965: }
4966: } else {
4967: for (var i=0; i<radioLength; i++) {
4968: if (document.requestcourse.cloning[i].checked) {
4969: cloneChoice = document.requestcourse.cloning[i].value;
4970: break;
4971: }
4972: }
4973: if (cloneChoice == 0) {
4974: alert("$lt{'choose'}");
4975: return false;
4976: }
4977: }
4978: var group;
1.81 raeburn 4979: if ((cloneChoice == 'textbook') || (cloneChoice == 'template') || (cloneChoice == 'existing')) {
1.72 raeburn 4980: var group;
4981: if (cloneChoice == 'textbook') {
4982: group = document.getElementsByName('book');
4983: } else {
1.81 raeburn 4984: if (cloneChoice == 'template') {
4985: group = document.getElementsByName('template');
4986: } else {
4987: group = document.getElementsByName('owned');
4988: }
1.72 raeburn 4989: }
4990: var groupLength = group.length;
4991: var chosen = 0;
4992: if (groupLength == undefined) {
4993: if (group.checked) {
4994: chosen = 1;
4995: }
4996: } else {
4997: for (var j=0; j<groupLength; j++) {
4998: if (group[j].checked) {
4999: chosen = 1;
5000: break;
5001: }
5002: }
5003: }
5004: if (chosen == 0) {
5005: if (cloneChoice == 'textbook') {
5006: alert("$lt{'textbook'}");
5007: } else {
1.81 raeburn 5008: if (cloneChoice == 'template') {
5009: alert("$lt{'template'}");
5010: } else {
5011: alert("$lt{'existing'}");
5012: }
1.72 raeburn 5013: }
5014: return false;
5015: }
5016: }
5017: }
5018: if (document.requestcourse.cdescr.value == '') {
5019: alert("$lt{'title'}");
5020: return false;
5021: }
5022: return true;
5023: }
5024:
5025: ENDSCRIPT
5026:
5027: }
1.73 raeburn 5028:
1.85 raeburn 5029: sub textbook_request_disabled {
5030: my ($r,$dom,$action,$can_request) = @_;
5031: if (ref($can_request) eq 'HASH') {
5032: if ($action eq 'process') {
5033: unless ((scalar(keys(%{$can_request})) == 1)) {
5034: &Apache::lonhtmlcommon::add_breadcrumb(
5035: { href => '/adm/requestcourse',
5036: text => 'Pick action',
5037: });
5038: }
5039: }
5040: }
5041: $r->print(&header('Course Request'));
5042: &Apache::lonhtmlcommon::add_breadcrumb({text=>'Course Request'});
5043: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Requests','Course_Requests').
5044: '<div>'.
5045: '<p class="LC_info">'.&mt('You do not have privileges to request creation of textbook courses.').'</p>');
5046: if (ref($can_request) eq 'HASH') {
5047: if (scalar(keys(%{$can_request})) > 1) {
5048: $r->print('<a href="/adm/requestcourse">'.&mt('Go back').'</a>');
5049: }
5050: }
5051: $r->print('</div>'.
5052: &Apache::loncommon::end_page());
5053: return;
5054: }
5055:
1.73 raeburn 5056: sub startContentScreen {
5057: my ($r,$mode)=@_;
5058: $r->print("\n".'<ul class="LC_TabContentBigger" id="textbookreq">'."\n");
5059: $r->print('<li'.(($mode eq 'textbookrequests')?' class="active"':'').'><a href="/adm/requestcourse"><b> '.&mt('Request a Course').' </b></a></li>'."\n");
5060: $r->print('<li'.(($mode eq 'textbooklogs')?' class="active"':'').'><a href="/adm/requestcourse?action=log&crstype=textbook&tabs=on"><b> '.&mt('Course Request History').' </b></a></li>'."\n");
5061: $r->print("\n".'</ul>'."\n");
5062: $r->print('<div class="LC_Box" style="clear:both;margin:0;"><div id="mainbox" style="margin:0 0;padding:0 0;"><div class="LC_ContentBox" id="maincontentbox" style="display: block;">');
5063: }
5064:
5065: sub endContentScreen {
5066: my ($r)=@_;
5067: $r->print('</div></div></div>');
5068: }
1.72 raeburn 5069:
1.1 raeburn 5070: 1;
5071:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>