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