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