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