Annotation of loncom/interface/lonrequestcourse.pm, revision 1.41.2.8
1.1 raeburn 1: # The LearningOnline Network
2: # Request a course
3: #
1.41.2.8! raeburn 4: # $Id: lonrequestcourse.pm,v 1.41.2.7 2010/11/08 21:16:24 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 get_processtype()
98:
99: =item check_autolimit()
100:
101: =item retrieve_settings()
102:
103: =item get_request_settings()
104:
1.27 raeburn 105: =item extract_instcode()
106:
107: =item generate_date_items()
108:
1.1 raeburn 109: =back
110:
111: =cut
112:
113: package Apache::lonrequestcourse;
114:
115: use strict;
116: use Apache::Constants qw(:common :http);
117: use Apache::lonnet;
118: use Apache::loncommon;
119: use Apache::lonlocal;
1.8 raeburn 120: use Apache::loncoursequeueadmin;
1.30 raeburn 121: use Apache::lonuserutils;
1.4 raeburn 122: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 123:
124: sub handler {
125: my ($r) = @_;
1.20 raeburn 126: &Apache::loncommon::content_type($r,'text/html');
127: $r->send_http_header;
1.1 raeburn 128: if ($r->header_only) {
129: return OK;
130: }
1.27 raeburn 131: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.38 raeburn 132: ['action','showdom','cnum','state','crstype']);
1.2 raeburn 133: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.41.2.8! raeburn 134: my $action = $env{'form.reqaction'};
1.1 raeburn 135: my $state = $env{'form.state'};
1.41.2.8! raeburn 136: my $context;
! 137: &generate_page($r,$action,$state,$context);
! 138: return OK;
! 139: }
! 140:
! 141: sub generate_page {
! 142: my ($r,$action,$state,$context) = @_;
! 143: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
! 144: ['action','showdom','cnum','state','crstype']);
! 145: my $dom = &get_course_dom();
1.27 raeburn 146: my (%states,%stored);
147: my ($jscript,$uname,$udom,$result,$warning);
148:
149: $states{'display'} = ['details'];
150: $states{'view'} = ['pick_request','details','cancel','removal'];
151: $states{'log'} = ['filter','display'];
152: $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
153:
1.41.2.1 raeburn 154: if ($dom eq 'gcitest') {
155: $states{'new'} = ['courseinfo','review','process'];
1.41.2.8! raeburn 156: if ($env{'form.concepttest'} eq 'editmyown') {
! 157: push(@{$states{'new'}},'chooseitems','uploadroster','enrolling');
! 158: } elsif (($env{'form.concepttest'} eq 'defchosen') ||
! 159: (($env{'form.concepttest'} eq 'cloning') && (!$env{'form.cloneroster'}))) {
! 160: push(@{$states{'new'}},'uploadroster','enrolling');
! 161: } else {
! 162: push(@{$states{'new'}},'done');
! 163: }
1.41.2.1 raeburn 164: }
1.27 raeburn 165: if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
1.41.2.8! raeburn 166: unless ($state eq 'crstype') {
1.27 raeburn 167: unshift(@{$states{'new'}},'codepick');
168: }
169: }
170:
171: foreach my $key (keys(%states)) {
172: if (ref($states{$key}) eq 'ARRAY') {
173: unshift (@{$states{$key}},'crstype');
174: }
175: }
176:
177: my @invalidcrosslist;
178: my %trail = (
1.40 raeburn 179: crstype => 'Request Action',
1.27 raeburn 180: codepick => 'Category',
181: courseinfo => 'Description',
182: enrollment => 'Access Dates',
183: personnel => 'Personnel',
184: review => 'Review',
185: process => 'Result',
186: pick_request => 'Display Summary',
187: details => 'Request Details',
188: cancel => 'Cancel Request',
189: removal => 'Outcome',
1.41.2.8! raeburn 190: chooseitems => 'Saved Test',
! 191: uploadroster => 'Upload Roster',
! 192: enrolling => 'Completed',
! 193: done => 'Completed',
1.27 raeburn 194: );
1.41.2.1 raeburn 195: if ($dom eq 'gcitest') {
196: $trail{'crstype'} = 'Building a Test';
197: $trail{'courseinfo'} = 'Test Information';
198: }
1.27 raeburn 199:
200: if (($env{'form.crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
201: $trail{'enrollment'} = 'Enrollment';
202: }
203:
1.36 raeburn 204: my ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description) =
1.27 raeburn 205: &get_breadcrumbs($dom,$action,\$state,\%states,\%trail);
1.26 raeburn 206: if ($action eq 'display') {
207: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
208: my $namespace = 'courserequestqueue';
209: if ($env{'form.cnum'} ne '') {
210: my $cnum = $env{'form.cnum'};
211: my $reqkey = $cnum.'_approval';
212: my $namespace = 'courserequestqueue';
213: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
214: my %queued =
215: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
216: if (ref($queued{$reqkey}) eq 'HASH') {
217: $uname = $queued{$reqkey}{'ownername'};
218: $udom = $queued{$reqkey}{'ownerdom'};
219: if (($udom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/)) {
220: $result = &retrieve_settings($dom,$cnum,$udom,$uname);
221: } else {
1.40 raeburn 222: if ($env{'form.crstype'} eq 'community') {
223: $warning = &mt('Invalid username or domain for community requestor');
224: } else {
225: $warning = &mt('Invalid username or domain for course requestor');
226: }
1.26 raeburn 227: }
228: } else {
1.40 raeburn 229: if ($env{'form.crstype'} eq 'community') {
230: $warning = &mt('No information was found for this community request.');
231: } else {
232: $warning = &mt('No information was found for this course request.');
233: }
1.26 raeburn 234: }
235: } else {
236: $warning = &mt('No course request ID provided.');
237: }
238: } else {
1.40 raeburn 239: if ($env{'form.crstype'} eq 'any') {
240: $warning = &mt('You do not have rights to view course or community request information.');
241: } elsif ($env{'form.crstype'} eq 'community') {
242: $warning = &mt('You do not have rights to view community request information.');
243: } else {
244: $warning = &mt('You do not have rights to view course request information.');
245: }
1.26 raeburn 246: }
247: } elsif ((defined($state)) && (defined($action))) {
1.16 raeburn 248: if (($action eq 'view') && ($state eq 'details')) {
249: if ((defined($env{'form.showdom'})) && (defined($env{'form.cnum'}))) {
250: my $result = &retrieve_settings($env{'form.showdom'},$env{'form.cnum'});
1.2 raeburn 251: }
1.27 raeburn 252: } elsif ($env{'form.crstype'} eq 'official') {
253: if (&Apache::lonnet::auto_run('',$dom)) {
254: if (($action eq 'new') && (($state eq 'enrollment') ||
255: ($state eq 'personnel'))) {
256: my $checkcrosslist = 0;
257: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
258: if ($env{'form.crosslist_'.$i}) {
259: $checkcrosslist ++;
260: }
261: }
262: if ($checkcrosslist) {
263: my %codechk;
264: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
265: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,
266: \%cat_titles,
267: \%cat_order,
268: \@code_order);
269: my $numtitles = scalar(@codetitles);
270: if ($numtitles) {
271: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
272: if ($env{'form.crosslist_'.$i}) {
273: my $codecheck;
274: my $crosslistcode = '';
275: foreach my $item (@code_order) {
276: $crosslistcode .= $env{'form.crosslist_'.$i.'_'.$item};
277: }
278: if ($crosslistcode ne '') {
1.36 raeburn 279: ($codechk{$i}, my $rest) =
1.27 raeburn 280: &Apache::lonnet::auto_validate_instcode('',$dom,$crosslistcode);
281: }
282: unless ($codechk{$i} eq 'valid') {
283: $env{'form.crosslist_'.$i} = '';
284: push(@invalidcrosslist,$crosslistcode);
285: }
286: }
287: }
288: }
289: }
290: }
291: }
1.2 raeburn 292: }
1.16 raeburn 293: my %elements = &form_elements($dom);
1.2 raeburn 294: my $elementsref = {};
295: if (ref($elements{$action}) eq 'HASH') {
296: if (ref($elements{$action}{$state}) eq 'HASH') {
297: $elementsref = $elements{$action}{$state};
298: }
299: }
1.16 raeburn 300: if (($state eq 'courseinfo') && ($env{'form.clonedom'} eq '')) {
301: $env{'form.clonedom'} = $dom;
302: }
1.30 raeburn 303: if ($state eq 'crstype') {
1.41.2.8! raeburn 304: $jscript = &mainmenu_javascript($action);
1.30 raeburn 305: } else {
306: $jscript = &Apache::lonhtmlcommon::set_form_elements($elementsref,\%stored);
1.41.2.6 raeburn 307: if ($state eq 'courseinfo') {
308: $jscript .= &cloning_javascript();
309: }
1.30 raeburn 310: }
1.2 raeburn 311: }
312:
313: if ($state eq 'personnel') {
314: $jscript .= "\n".&Apache::loncommon::userbrowser_javascript();
315: }
316:
1.41.2.6 raeburn 317: my $loaditems = &onload_action($action,$state,$dom);
1.2 raeburn 318:
1.39 raeburn 319: my (%can_request,%request_domains);
320: my $canreq =
321: &Apache::lonnet::check_can_request($dom,\%can_request,\%request_domains);
1.1 raeburn 322: if ($action eq 'new') {
323: if ($canreq) {
324: if ($state eq 'crstype') {
1.3 raeburn 325: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,
1.39 raeburn 326: $crumb,\%request_domains);
1.1 raeburn 327: } else {
1.27 raeburn 328: &request_administration($r,$action,$state,$page,\%states,$dom,
329: $jscript,$loaditems,$crumb,$newinstcode,
1.36 raeburn 330: $codechk,$checkedcode,$description,
331: \@invalidcrosslist);
1.41.2.8! raeburn 332: if ($state eq 'chooseitems' || $state eq 'uploadroster' ||
! 333: $state eq 'enrolling') {
! 334: return $canreq;
! 335: }
1.1 raeburn 336: }
337: } else {
1.40 raeburn 338: $r->print(&header('Course/Community Requests').$crumb.
1.1 raeburn 339: '<div class="LC_warning">'.
1.40 raeburn 340: &mt('You do not have privileges to request creation of courses or communities.').
1.2 raeburn 341: '</div>'.&Apache::loncommon::end_page());
1.1 raeburn 342: }
343: } elsif ($action eq 'view') {
1.10 raeburn 344: if ($state eq 'crstype') {
1.39 raeburn 345: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,$loaditems,$crumb,\%request_domains);
1.26 raeburn 346: } else {
347: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
348: $loaditems,$crumb);
349: }
350: } elsif ($action eq 'display') {
351: if ($warning ne '') {
352: my $args = { only_body => 1 };
1.40 raeburn 353: $r->print(&header('Course/Community Requests','','',$args).$crumb.
354: '<h3>'.&mt('Course/Community Request Details').'</h3>'.
1.26 raeburn 355: '<div class="LC_warning">'.$warning.'</div>'.
356: &close_popup_form());
1.11 raeburn 357: } else {
1.26 raeburn 358: &request_administration($r,$action,$state,$page,\%states,$dom,$jscript,
1.36 raeburn 359: $loaditems,$crumb,'','','','','',$uname,$udom);
1.10 raeburn 360: }
1.1 raeburn 361: } elsif ($action eq 'log') {
1.3 raeburn 362: &print_request_logs($jscript,$loaditems,$crumb);
1.1 raeburn 363: } else {
1.39 raeburn 364: &print_main_menu($r,\%can_request,\%states,$dom,$jscript,'',$crumb,\%request_domains);
1.1 raeburn 365: }
1.41.2.8! raeburn 366: return;
1.1 raeburn 367: }
368:
1.30 raeburn 369: sub mainmenu_javascript {
1.41.2.8! raeburn 370: my ($action) = @_;
1.30 raeburn 371: return <<"END";
372: function setType(courseForm) {
373: for (var i=0; i<courseForm.crstype.length; i++) {
374: if (courseForm.crstype.options[i].value == "$env{'form.crstype'}") {
375: courseForm.crstype.options[i].selected = true;
376: } else {
377: courseForm.crstype.options[i].selected = false;
378: }
379: }
380: }
381:
382: function setAction(courseForm) {
1.41.2.8! raeburn 383: for (var i=0; i<courseForm.reqaction.length; i++) {
! 384: if (courseForm.reqaction.options[i].value == "$action") {
! 385: courseForm.reqaction.options[i].selected = true;
1.30 raeburn 386: } else {
1.41.2.8! raeburn 387: courseForm.reqaction.options[i].selected = false;
1.30 raeburn 388: }
389: }
390: }
391: END
392: }
393:
1.41.2.6 raeburn 394: sub cloning_javascript {
395: return <<"END";
396: function setCloneDisplay(courseForm) {
397: if (courseForm.cloning.length > 1) {
398: for (var i=0; i<courseForm.cloning.length; i++) {
399: if (courseForm.cloning[i].checked) {
400: if (courseForm.cloning[i].value == 1) {
401: document.getElementById('cloneoptions').style.display="block";;
402: }
403: }
404: }
405: }
406: }
407: END
408: }
409:
1.27 raeburn 410: sub get_breadcrumbs {
411: my ($dom,$action,$state,$states,$trail) = @_;
1.36 raeburn 412: my ($crumb,$newinstcode,$codechk,$checkedcode,$numtitles,$description);
1.27 raeburn 413: my $page = 0;
1.41.2.1 raeburn 414: my $firstcrumb = 'Pick Action';
415: my $crumbtitle = 'Course/Community Requests';
416: my $crumbhelp = 'Course_Requests';
417: if ($dom eq 'gcitest') {
418: $firstcrumb = 'Building a Test';
419: $crumbtitle = 'Create Concept Test';
420: $crumbhelp = 'Concept_Test_Creation';
421: }
1.27 raeburn 422: if ((ref($states) eq 'HASH') && (ref($trail) eq 'HASH') && (ref($state))) {
423: if (defined($action)) {
424: my $done = 0;
425: my $i=0;
426: if (ref($states->{$action}) eq 'ARRAY') {
427: while ($i<@{$states->{$action}} && !$done) {
428: if ($states->{$action}[$i] eq $$state) {
429: $page = $i;
430: $done = 1;
431: }
432: $i++;
433: }
434: }
435: if ($env{'form.crstype'} eq 'official') {
436: if ($page > 1) {
437: if ($states->{$action}[$page-1] eq 'codepick') {
438: if ($env{'form.instcode'} eq '') {
439: ($newinstcode,$numtitles) = &get_instcode($dom);
440: if ($numtitles) {
441: if ($newinstcode eq '') {
442: $$state = 'codepick';
443: $page --;
444: } else {
1.36 raeburn 445: ($codechk,$description) =
1.27 raeburn 446: &Apache::lonnet::auto_validate_instcode('',
447: $dom,$newinstcode);
448: if ($codechk ne 'valid') {
449: $$state = 'codepick';
450: $page --;
451: }
452: $checkedcode = 1;
453: }
454: }
455: }
456: }
457: }
458: }
1.41.2.8! raeburn 459: my %forms = (
! 460: chooseitems => 'requestcrs',
! 461: uploadroster => 'studentform',
! 462: enrolling => 'requestcrs',
! 463: done => 'requestcrs',
! 464: );
! 465: my $lastidx;
! 466: for (my $i=0; $i<@{$states->{$action}}; $i++) {
! 467: if ($$state eq $states->{$action}[$i]) {
! 468: $lastidx = $i;
! 469: last;
! 470: }
! 471: }
1.27 raeburn 472: for (my $i=0; $i<@{$states->{$action}}; $i++) {
473: if ($$state eq $states->{$action}[$i]) {
474: &Apache::lonhtmlcommon::add_breadcrumb(
475: {text=>"$trail->{$$state}"});
1.41.2.1 raeburn 476: $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
1.27 raeburn 477: last;
478: } else {
479: if (($$state eq 'process') || ($$state eq 'removal')) {
480: &Apache::lonhtmlcommon::add_breadcrumb(
481: { href => '/adm/requestcourse',
482: text => "$trail->{$states->{$action}[$i]}",
483: }
484: );
485: } else {
1.41.2.8! raeburn 486: if (($$state eq 'chooseitems') || ($$state eq 'uploadroster') ||
! 487: ($$state eq 'enrolling') || ($$state eq 'done')) {
! 488: if (($states->{$action}[$i] ne 'process') &&
! 489: ($states->{$action}[$i] ne 'chooseitems') &&
! 490: ($states->{$action}[$i] ne 'uploadroster') &&
! 491: ($states->{$action}[$i] ne 'enrolling') &&
! 492: ($states->{$action}[$i] ne 'done')) {
! 493: &Apache::lonhtmlcommon::add_breadcrumb(
! 494: { href => '/adm/requestcourse',
! 495: text => "$trail->{$states->{$action}[$i]}",
! 496: }
! 497: );
! 498: } else {
! 499: my $diff = $i-$lastidx;
! 500: &Apache::lonhtmlcommon::add_breadcrumb(
! 501: { href => "javascript:history.go($diff)",
! 502: text => "$trail->{$states->{$action}[$i]}", }
! 503: );
! 504: }
! 505: } else {
! 506: &Apache::lonhtmlcommon::add_breadcrumb(
1.27 raeburn 507: { href => "javascript:backPage(document.requestcrs,'$states->{$action}[$i]')",
508: text => "$trail->{$states->{$action}[$i]}", }
1.41.2.8! raeburn 509: );
! 510: }
! 511: }
! 512: }
! 513: }
1.27 raeburn 514: } else {
515: &Apache::lonhtmlcommon::add_breadcrumb(
1.41.2.1 raeburn 516: {text=>$firstcrumb});
517: $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
1.27 raeburn 518: }
519: } else {
520: &Apache::lonhtmlcommon::add_breadcrumb(
1.41.2.1 raeburn 521: {text=>$firstcrumb});
522: $crumb = &Apache::lonhtmlcommon::breadcrumbs($crumbtitle,$crumbhelp);
1.27 raeburn 523: }
1.36 raeburn 524: return ($page,$crumb,$newinstcode,$codechk,$checkedcode,$description);
1.27 raeburn 525: }
526:
1.2 raeburn 527: sub header {
1.26 raeburn 528: my ($bodytitle,$jscript,$loaditems,$jsextra,$args) = @_;
1.2 raeburn 529: if ($jscript) {
1.6 raeburn 530: $jscript = '<script type="text/javascript">'."\n".
531: '// <![CDATA['."\n".
532: $jscript."\n".'// ]]>'."\n".'</script>'."\n";
1.2 raeburn 533: }
534: if ($loaditems) {
1.26 raeburn 535: if (ref($args) eq 'HASH') {
536: my %loadhash = (
537: 'add_entries' => $loaditems,
1.41.2.8! raeburn 538: 'function' => 'norole',
1.26 raeburn 539: );
540: my %arghash = (%loadhash,%{$args});
1.41.2.8! raeburn 541: $args = \%arghash;
1.26 raeburn 542: } else {
1.41.2.8! raeburn 543: $args = {'add_entries' => $loaditems,
! 544: 'function' => 'norole'};
1.26 raeburn 545: }
1.3 raeburn 546: }
1.26 raeburn 547: return &Apache::loncommon::start_page($bodytitle,$jscript.$jsextra,$args);
1.2 raeburn 548: }
549:
550: sub form_elements {
551: my ($dom) = @_;
552: my %elements =
553: (
554: new => {
555: crstype => {
556: crstype => 'selectbox',
557: action => 'selectbox',
1.16 raeburn 558: origcnum => 'hidden',
1.2 raeburn 559: },
560: courseinfo => {
561: cdescr => 'text',
1.41.2.6 raeburn 562: cloning => 'radio',
1.13 raeburn 563: clonecrs => 'text',
564: clonedom => 'selectbox',
1.2 raeburn 565: datemode => 'radio',
566: dateshift => 'text',
567: },
568: enrollment => {
1.13 raeburn 569: accessstart_month => 'selectbox',
570: accessstart_hour => 'selectbox',
571: accessend_month => 'selectbox',
572: accessend_hour => 'selectbox',
573: accessstart_day => 'text',
574: accessstart_year => 'text',
575: accessstart_minute => 'text',
576: accessstart_second => 'text',
577: accessend_day => 'text',
578: accessend_year => 'text',
579: accessend_minute => 'text',
580: accessend_second => 'text',
1.2 raeburn 581: no_end_date => 'checkbox',
582: },
583: personnel => {
584: addperson => 'checkbox',
585: },
1.13 raeburn 586: review => {
587: cnum => 'hidden',
588: },
1.2 raeburn 589: },
590: view => {
591: crstype => {
592: crstype => 'selectbox',
593: action => 'selectbox',
594: },
595: },
596: );
1.13 raeburn 597: my %servers = &Apache::lonnet::get_servers($dom,'library');
1.41.2.1 raeburn 598: if ($dom eq 'gcitest') {
599: %{$elements{'new'}{'courseinfo'}} = (
600: cdescr => 'text',
1.41.2.6 raeburn 601: concepttest => 'radio',
1.41.2.1 raeburn 602: );
1.41.2.6 raeburn 603: if (&show_cloneable()) {
604: $elements{'new'}{'courseinfo'}{'clonecrs'} = 'selectbox';
605: $elements{'new'}{'courseinfo'}{'clonedom'} = 'hidden';
606: $elements{'new'}{'courseinfo'}{'cloneroster'} = 'checkbox';
607: }
1.41.2.1 raeburn 608: }
1.13 raeburn 609: my $numlib = keys(%servers);
610: if ($numlib > 1) {
611: $elements{'new'}{'courseinfo'}{'chome'} = 'selectbox';
612: } else {
613: $elements{'new'}{'courseinfo'}{'chome'} = 'hidden';
614: }
1.41.2.1 raeburn 615: if ($dom eq 'gcitest') {
616: my %mergedhash = (%{$elements{'new'}{'courseinfo'}},%{$elements{'new'}{'enrollment'}});
617: %{$elements{'new'}{'courseinfo'}} = %mergedhash;
618: }
1.2 raeburn 619: my (@codetitles,%cat_titles,%cat_order,@code_order,$lastitem);
620: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
621: \%cat_order,\@code_order);
622: my $numtitles = scalar(@codetitles);
623: if ($numtitles) {
624: my %extras;
625: $lastitem = pop(@codetitles);
626: $extras{'instcode_'.$lastitem} = 'text';
627: foreach my $item (@codetitles) {
628: $extras{'instcode_'.$item} = 'selectbox';
629: }
630: $elements{'new'}{'codepick'} = \%extras;
631: }
632: if (&Apache::lonnet::auto_run('',$dom)) {
633: my %extras = (
634: sectotal => 'hidden',
1.13 raeburn 635: enrollstart_month => 'selectbox',
636: enrollstart_hour => 'selectbox',
637: enrollend_month => 'selectbox',
638: enrollend_hour => 'selectbox',
639: enrollstart_day => 'text',
640: enrollstart_year => 'text',
641: enrollstart_minute => 'text',
642: enrollstart_second => 'text',
643: enrollend_day => 'text',
644: enrollend_year => 'text',
645: enrollend_minute => 'text',
646: enrollend_second => 'text',
1.2 raeburn 647: addcrosslist => 'checkbox',
648: autoadds => 'radio',
649: autodrops => 'radio',
650: );
651: if ($env{'form.sectotal'} > 0) {
652: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 653: $extras{'sec_'.$i} = 'radio';
654: $extras{'secnum_'.$i} = 'text';
655: $extras{'loncapasec_'.$i} = 'text';
1.2 raeburn 656: }
657: }
658: my $crosslisttotal = $env{'form.crosslisttotal'};
1.16 raeburn 659: if ($env{'form.addcrosslist'}) {
660: $crosslisttotal ++;
661: }
1.24 raeburn 662: if (!$crosslisttotal) {
1.2 raeburn 663: $crosslisttotal = 1;
664: }
1.27 raeburn 665:
1.24 raeburn 666: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
667: if ($numtitles) {
668: $extras{'crosslist_'.$i.'_'.$lastitem} = 'text';
669: }
670: if (@codetitles > 0) {
671: foreach my $item (@codetitles) {
672: $extras{'crosslist_'.$i.'_'.$item} = 'selectbox';
1.2 raeburn 673: }
674: }
1.24 raeburn 675: $extras{'crosslist_'.$i} = 'checkbox';
676: $extras{'crosslist_'.$i.'_instsec'} = 'text',
677: $extras{'crosslist_'.$i.'_lcsec'} = 'text',
1.2 raeburn 678: }
679: my %mergedhash = (%{$elements{'new'}{'enrollment'}},%extras);
680: %{$elements{'new'}{'enrollment'}} = %mergedhash;
681: }
682: my %people;
683: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 684: if ($env{'form.addperson'}) {
685: $persontotal ++;
686: }
687: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 688: $persontotal = 1;
689: }
690: for (my $i=0; $i<$persontotal; $i++) {
1.13 raeburn 691: $people{'person_'.$i.'_uname'} = 'text',
692: $people{'person_'.$i.'_dom'} = 'selectbox',
693: $people{'person_'.$i.'_hidedom'} = 'hidden',
694: $people{'person_'.$i.'_firstname'} = 'text',
695: $people{'person_'.$i.'_lastname'} = 'text',
696: $people{'person_'.$i.'_emailaddr'} = 'text',
697: $people{'person_'.$i.'_role'} = 'selectbox',
698: $people{'person_'.$i.'_sec'} = 'selectbox',
699: $people{'person_'.$i.'_newsec'} = 'text',
1.2 raeburn 700: }
701: my %personnelhash = (%{$elements{'new'}{'personnel'}},%people);
702: %{$elements{'new'}{'personnel'}} = %personnelhash;
703: return %elements;
704: }
705:
706: sub onload_action {
707: my ($action,$state) = @_;
708: my %loaditems;
709: if (($action eq 'new') || ($action eq 'view')) {
1.30 raeburn 710: if ($state eq 'crstype') {
711: $loaditems{'onload'} = 'javascript:setAction(document.mainmenu_action);javascript:setType(document.mainmenu_coursetype)';
712: } else {
1.41.2.6 raeburn 713: $loaditems{'onload'} = 'javascript:setFormElements(document.requestcrs);';
714: }
1.2 raeburn 715: }
716: return \%loaditems;
717: }
718:
1.1 raeburn 719: sub print_main_menu {
1.39 raeburn 720: my ($r,$can_request,$states,$dom,$jscript,$loaditems,$crumb,$request_domains) = @_;
1.37 raeburn 721: my ($types,$typename) = &Apache::loncommon::course_types();
1.1 raeburn 722: my $onchange;
723: unless ($env{'form.interface'} eq 'textual') {
1.39 raeburn 724: $onchange = 'this.form.submit()';
1.1 raeburn 725: }
726:
1.2 raeburn 727: my $nextstate_setter = "\n";
728: if (ref($states) eq 'HASH') {
729: foreach my $key (keys(%{$states})) {
730: if (ref($states->{$key}) eq 'ARRAY') {
731: $nextstate_setter .=
732: " if (actionchoice == '$key') {
733: nextstate = '".$states->{$key}[1]."';
734: }
735: ";
736: }
737: }
738: }
1.1 raeburn 739:
1.41.2.1 raeburn 740: my $js;
741: unless ($dom eq 'gcitest') {
742: $js = <<"END";
1.1 raeburn 743:
1.2 raeburn 744: function nextPage(formname) {
1.27 raeburn 745: var crschoice = document.mainmenu_coursetype.crstype.value;
1.41.2.8! raeburn 746: var actionchoice = document.mainmenu_action.reqaction.value;
1.2 raeburn 747: if (check_can_request(crschoice,actionchoice) == true) {
748: if ((actionchoice == 'new') && (crschoice == 'official')) {
749: nextstate = 'codepick';
750: } else {
751: $nextstate_setter
1.27 raeburn 752: }
753: formname.crstype.value = crschoice;
1.41.2.8! raeburn 754: formname.reqaction.value = actionchoice;
1.1 raeburn 755: formname.state.value= nextstate;
756: formname.submit();
757: }
758: return;
759: }
760:
1.2 raeburn 761: function check_can_request(crschoice,actionchoice) {
1.1 raeburn 762: var official = '';
763: var unofficial = '';
764: var community = '';
765: END
1.41.2.1 raeburn 766: if (ref($can_request) eq 'HASH') {
767: foreach my $item (keys(%{$can_request})) {
768: $js .= "
769: $item = 1;
1.1 raeburn 770: ";
1.41.2.1 raeburn 771: }
1.39 raeburn 772: }
1.41.2.1 raeburn 773: my %lt = &Apache::lonlocal::texthash(
774: official => 'You are not permitted to request creation of an official course in this domain.',
775: unofficial => 'You are not permitted to request creation of an unofficial course in this domain.',
776: community => 'You are not permitted to request creation of a community this domain.',
777: all => 'You must choose a specific course type when making a new course request.\\nAll types is not allowed.',
778: );
779: $js .= <<END;
1.1 raeburn 780: if (crschoice == 'official') {
781: if (official != 1) {
782: alert("$lt{'official'}");
783: return false;
784: }
785: } else {
786: if (crschoice == 'unofficial') {
1.41.2.1 raeburn 787: if (unofficial != 1) {
788: alert("$lt{'unofficial'}");
789: return false;
1.1 raeburn 790: }
791: } else {
792: if (crschoice == 'community') {
793: if (community != 1) {
794: alert("$lt{'community'}");
795: return false;
796: }
797: } else {
798: if (actionchoice == 'new') {
799: alert("$lt{'all'}");
800: return false;
1.41.2.1 raeburn 801: }
1.1 raeburn 802: }
803: }
804: }
805: return true;
806: }
807: END
1.41.2.1 raeburn 808: }
1.39 raeburn 809: my ($pagetitle,$pageinfo,$domaintitle);
810: if (ref($can_request) eq 'HASH') {
811: if (($can_request->{'official'}) || ($can_request->{'unofficial'})) {
812: if ($can_request->{'community'}) {
813: $pagetitle = 'Course/Community Requests';
814: $pageinfo = &mt('Request creation of a new course or community, or review your pending requests.');
815: $domaintitle = &mt('Course/Community Domain');
816: } else {
817: $pagetitle = 'Course Requests';
818: $pageinfo = &mt('Request creation of a new course, or review your pending course requests.');
819: $domaintitle = &mt('Course Domain');
820: }
821: } elsif ($can_request->{'community'}) {
1.40 raeburn 822: $pagetitle = 'Community Requests';
823: $pageinfo = &mt('Request creation of a new course, or review your pending requests.');
1.39 raeburn 824: $domaintitle = &mt('Community Domain');
825: } else {
826: $pagetitle = 'Course/Community Requests';
827: $pageinfo = &mt('You do not have rights to request creation of courses in this domain; please choose a different domain.');
828: $domaintitle = &mt('Course/Community Domain');
829: }
830: }
1.41.2.1 raeburn 831:
832: if ($dom eq 'gcitest') {
833: my $formname = 'requestcrs';
834: my $nexttext = &mt('Continue');
835: $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
836: '<p>'.&mt('Deployment of a Concept Test requires completion of the following three steps:').'<ol>'.
837: '<li>'.&mt('Creation of a course "container" and setting of access dates').'</li>'.
838: '<li>'.&mt('Assembly of a valid test from Concept Inventory questions').'</li>'.
839: '<li>'.&mt('Enrollment of students').'</li>'.
1.41.2.6 raeburn 840: '</ol></p><p>'.&mt('When assembling a test you may:').
841: '<br />'.&mt('(a) have a valid test built automatically by the WebCenter, or').'<br />'.&mt('(b) select the questions to include by combining questions chosen from eleven bins with four mandatory questions, or').
1.41.2.8! raeburn 842: '<br />'.&mt('(c) copy one of your existing tests (including optional copying of the student roster)').'</p><p>'.&mt('The most efficient way to enroll students is to upload a text file containing usernames and passwords.').'<br />'.&mt("Students' e-mail addresses must be used as their usernames to ensure uniqueness.").'</p><div>'.
1.41.2.1 raeburn 843: '<form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
844: '<input type="hidden" name="state" value="courseinfo" />'."\n".
845: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
846: '<input type="hidden" name="crstype" value="unofficial" />'."\n".
1.41.2.8! raeburn 847: '<input type="hidden" name="reqaction" value="new" />'."\n".
1.41.2.1 raeburn 848: '<input type="button" name="next" value="'.$nexttext.
849: '" onclick="this.form.submit();" />'."\n".
850: '</form></div>'.
851: &Apache::loncommon::end_page());
852: return;
853: }
854:
855: if (!$onchange) {
856: $r->print(' <input type="submit" name="godom" value="'.
857: &mt('Change').'" />');
858: }
859: unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
860: $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n".
861: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
862: &Apache::loncommon::end_page());
863: return;
864: }
865:
1.39 raeburn 866: my @incdoms;
867: if (ref($request_domains) eq 'HASH') {
868: foreach my $item (keys(%{$request_domains})) {
869: if (ref($request_domains->{$item}) eq 'ARRAY') {
870: foreach my $possdom (@{$request_domains->{$item}}) {
871: unless(grep(/^\Q$possdom\E$/,@incdoms)) {
872: push(@incdoms,$possdom);
873: }
874: }
875: }
876: }
877: }
878: $r->print(&header($pagetitle,$js.$jscript,$loaditems).$crumb.
879: '<p>'.$pageinfo.'</p>'.
1.34 raeburn 880: '<div>'.
1.27 raeburn 881: &Apache::lonhtmlcommon::start_pick_box().
1.39 raeburn 882: &Apache::lonhtmlcommon::row_title($domaintitle).
1.1 raeburn 883: '<form name="domforcourse" method="post" action="/adm/requestcourse">'.
1.39 raeburn 884: &Apache::loncommon::select_dom_form($dom,'showdom','',1,$onchange,\@incdoms));
1.1 raeburn 885: if (!$onchange) {
886: $r->print(' <input type="submit" name="godom" value="'.
887: &mt('Change').'" />');
888: }
1.39 raeburn 889: unless ((ref($can_request) eq 'HASH') && (keys(%{$can_request}) > 0)) {
890: $r->print(&Apache::lonhtmlcommon::row_closure(1)."\n".
891: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
892: &Apache::loncommon::end_page());
893: return;
894: }
1.27 raeburn 895: $r->print('</form>'.&Apache::lonhtmlcommon::row_closure());
1.2 raeburn 896: my $formname = 'requestcrs';
1.1 raeburn 897: my $nexttext = &mt('Next');
1.27 raeburn 898: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Action')).'
899: <form name="mainmenu_action" method="post" action="">
1.41.2.8! raeburn 900: <select size="1" name="reqaction" >
1.2 raeburn 901: <option value="new">'.&mt('New request').'</option>
1.1 raeburn 902: <option value="view">'.&mt('View/Modify/Cancel pending requests').'</option>
903: <option value="log">'.&mt('View request history').'</option>
1.27 raeburn 904: </select></form>'.
905: &Apache::lonhtmlcommon::row_closure(1).
1.39 raeburn 906: &Apache::lonhtmlcommon::row_title(&mt('Type')).'
1.27 raeburn 907: <form name="mainmenu_coursetype" method="post" action="">
1.39 raeburn 908: <select size="1" name="crstype">');
909: if (ref($can_request) eq 'HASH') {
910: if (keys(%{$can_request}) > 1) {
911: $r->print(' <option value="any">'.&mt('All types').'</option>');
912: }
913: if ((ref($types) eq 'ARRAY') && (ref($typename) eq 'HASH')) {
914: foreach my $type (@{$types}) {
915: next unless($can_request->{$type});
916: my $selected = '';
917: if ($env{'form.crstype'} eq '') {
918: if ($type eq 'official') {
919: $selected = ' selected="selected"';
920: }
921: } else {
922: if ($type eq $env{'form.crstype'}) {
923: $selected = ' selected="selected"';
924: }
925: }
926: $r->print('<option value="'.$type.'"'.$selected.'>'.&mt($typename->{$type}).
927: '</option>'."\n");
1.4 raeburn 928: }
929: }
930: }
1.27 raeburn 931: $r->print('</select></form>'."\n".
932: &Apache::lonhtmlcommon::row_closure(1)."\n".
933: &Apache::lonhtmlcommon::end_pick_box().'</div>'."\n".
1.38 raeburn 934: '<div><form name="'.$formname.'" method="post" action="/adm/requestcourse">'."\n".
1.27 raeburn 935: '<input type="hidden" name="state" value="crstype" />'."\n".
936: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
937: '<input type="hidden" name="crstype" value="" />'."\n".
1.41.2.8! raeburn 938: '<input type="hidden" name="reqaction" value="" />'."\n".
1.27 raeburn 939: '<input type="button" name="next" value="'.$nexttext.
940: '" onclick="javascript:nextPage(document.'.$formname.')" />'."\n".
941: '</form></div>');
1.1 raeburn 942: $r->print(&Apache::loncommon::end_page());
943: return;
944: }
945:
946: sub request_administration {
1.27 raeburn 947: my ($r,$action,$state,$page,$states,$dom,$jscript,$loaditems,$crumb,
1.36 raeburn 948: $newinstcode,$codechk,$checkedcode,$description,$invalidcrosslist,
949: $uname,$udom) = @_;
1.2 raeburn 950: my $js;
1.16 raeburn 951: if (($action eq 'new') || (($action eq 'view') && ($state eq 'pick_request'))) {
1.2 raeburn 952: $js = <<END;
1.1 raeburn 953:
954: function nextPage(formname,nextstate) {
955: formname.state.value= nextstate;
956: formname.submit();
957: }
1.16 raeburn 958:
959: END
960: }
961: if (($action eq 'new') || ($action eq 'view')) {
962: $js .= <<END;
963:
1.41.2.8! raeburn 964: function backPage(formname,prevstate,currstate) {
1.1 raeburn 965: formname.state.value = prevstate;
1.41.2.8! raeburn 966: if (currstate == "enrolling") {
! 967: if (prevstate == "chooseitems" || prevstate == "uploadroster") {
! 968: formname.action = "/adm/createuser";
! 969: }
! 970: }
1.1 raeburn 971: formname.submit();
972: }
973:
974: END
1.2 raeburn 975: }
976: if ($action eq 'new') {
977: my $jsextra;
1.31 raeburn 978: if ($state eq 'courseinfo') {
1.2 raeburn 979: $jsextra = "\n".&Apache::loncommon::coursebrowser_javascript($dom);
1.31 raeburn 980: } elsif ($state eq 'enrollment') {
981: if (($env{'form.crstype'} eq 'official') &&
982: (&Apache::lonnet::auto_run('',$dom))) {
983: $js .= "\n".§ion_check_javascript()."\n".&enrollment_lcsec_js();
984: }
985: } elsif ($state eq 'personnel') {
986: $js .= "\n".§ion_check_javascript()."\n".&personnel_lcsec_js();
1.41.2.2 raeburn 987: } elsif (($state eq 'process') && ($env{'form.concepttest'} eq 'editmyown')) {
988: $js .= "\n".&Apache::londocsgci::builder_javascript()."\n";
1.1 raeburn 989: }
1.40 raeburn 990: my $title;
991: if ($env{'form.crstype'} eq 'community') {
992: $title = 'Request a community';
1.41.2.8! raeburn 993: } elsif (&Apache::loncommon::needs_gci_custom()) {
! 994: $title = 'Create a new Concept Test';
1.40 raeburn 995: } else {
996: $title = 'Request a course';
997: }
998: $r->print(&header($title,$js.$jscript,$loaditems,$jsextra).$crumb);
1.41.2.8! raeburn 999: return if (($state eq 'chooseitems') || ($state eq 'uploadroster') ||
! 1000: ($state eq 'enrolling'));
1.27 raeburn 1001: &print_request_form($r,$action,$state,$page,$states,$dom,$newinstcode,
1.36 raeburn 1002: $codechk,$checkedcode,$description,$invalidcrosslist);
1.2 raeburn 1003: } elsif ($action eq 'view') {
1.16 raeburn 1004: my $jsextra;
1005: my $formname = 'requestcrs';
1006: my $prev = $states->{$action}[$page-1];
1007: my $next = $states->{$action}[$page+1];
1008: if ($state eq 'pick_request') {
1009: $next = $states->{$action}[$page+1];
1010: $jsextra = &viewrequest_javascript($formname,$next);
1011: } elsif ($state eq 'details') {
1012: $jsextra = &viewdetails_javascript($formname);
1013:
1014: } elsif ($state eq 'cancel') {
1015: $jsextra = &viewcancel_javascript($formname);
1016: }
1.40 raeburn 1017: my $title;
1018: if ($env{'form.crstype'} eq 'community') {
1019: $title = 'Manage community requests';
1020: } else {
1021: $title = 'Manage course requests';
1022: }
1023: $r->print(&header($title,$js.$jscript.$jsextra,$loaditems).$crumb);
1.16 raeburn 1024: my $form = '<form method="post" name="'.$formname.'" action="/adm/requestcourse" />';
1.11 raeburn 1025: if ($state eq 'pick_request') {
1.40 raeburn 1026: my $title;
1027: if ($env{'form.crstype'} eq 'community') {
1028: $title = &mt('Pending community requests');
1029: } elsif ($env{'form.crstype'} eq 'official') {
1030: $title = &mt('Pending requests for official courses');
1031: } elsif ($env{'form.crstype'} eq 'unofficial') {
1032: $title = &mt('Pending requests for unofficial courses');
1033: } else {
1034: $title = &mt('Pending course/community requests');
1035: }
1036: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.41.2.8! raeburn 1037: &print_request_status($dom,$action,$state).'</form></div>');
1.16 raeburn 1038: } elsif ($state eq 'details') {
1039: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1040: my $origcnum = $env{'form.cnum'};
1041: if ($origcnum eq '') {
1042: $origcnum = $env{'form.origcnum'};
1043: }
1044: if ($env{'form.crstype'} eq 'official') {
1045: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1046: \%cat_order,\@code_order);
1047: }
1.40 raeburn 1048: my $title;
1049: if ($env{'form.crstype'} eq 'community') {
1050: $title = &mt('Community Request Details');
1051: } else {
1052: $title = &mt('Course Request Details');
1053: }
1054: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.26 raeburn 1055: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1.16 raeburn 1056: \@code_order)."\n".
1057: '<input name="origcnum" value="'.$origcnum.'" type="hidden" />'."\n");
1058: my @excluded = &get_excluded_elements($dom,$states,'new','review');
1059: push(@excluded,'origcnum');
1060: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1061: my $other = 'modify';
1062: my %navtxt = &Apache::lonlocal::texthash (
1063: prev => 'Back',
1064: other => 'Modify Request',
1065: next => 'Cancel Request',
1066: );
1.31 raeburn 1067: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1068: $navtxt{'next'},$state,$other,$navtxt{'other'});
1.16 raeburn 1069: $r->print('</form>');
1070: } elsif ($state eq 'cancel') {
1.40 raeburn 1071: my $title;
1072: if ($env{'form.crstype'} eq 'community') {
1073: $title = &mt('Cancel community request');
1074: } else {
1075: $title = &mt('Cancel course request');
1076: }
1.16 raeburn 1077: my ($result,$output) = &print_cancel_request($dom,$env{'form.origcnum'});
1.40 raeburn 1078: $r->print('<h3>'.$title.'</h3><div>'."\n".$form."\n".
1.16 raeburn 1079: $output);
1080: my @excluded = &get_excluded_elements($dom,$states,'view','cancel');
1081: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</div>');
1082: my %navtxt = &Apache::lonlocal::texthash (
1083: prev => 'Back',
1084: next => 'Confirm Cancellation',
1085: );
1086: if ($result eq 'ok') {
1.31 raeburn 1087: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
1.16 raeburn 1088: $navtxt{'next'},$state);
1089: } else {
1.31 raeburn 1090: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},undef,
1091: '',$state);
1.16 raeburn 1092: }
1093: $r->print('</form>');
1094: } elsif ($state eq 'removal') {
1095: my $cnum = $env{'form.origcnum'};
1096: my $statuskey = 'status:'.$dom.':'.$cnum;
1097: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
1098: $env{'user.domain'},$env{'user.name'});
1099: my $currstatus = $userreqhash{$statuskey};
1100: my ($result,$error);
1101: if (($currstatus eq 'approval') || ($currstatus eq 'pending')) {
1102: my %status = (
1103: $statuskey => 'cancelled',
1104: );
1105: my $statusresult = &Apache::lonnet::put('courserequests',\%status);
1106: if ($statusresult eq 'ok') {
1107: my $delresult =
1108: &Apache::lonnet::del_dom('courserequestqueue',
1109: [$cnum.'_'.$currstatus],$dom);
1110: if ($delresult eq 'ok') {
1111: $result = 'ok';
1112: } else {
1113: $error = &mt('An error occurred when updating the pending requests queue: [_1]',$delresult);
1114: }
1115: } else {
1116: $error = &mt("An error occurred when updating the status of this request in the requestor's records: [_1]",$statusresult);
1117: }
1118: } else {
1119: $error = &mt('The current status of this request could not be verified as pending approval/institutional action.');
1120: }
1121: $r->print('<h3>'.&mt('Request Cancellation').'</h3><div>'."\n".$form."\n".
1122: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1.41.2.8! raeburn 1123: '<input type="hidden" name="reqaction" value="'.$action.'" />'."\n".
1.16 raeburn 1124: '<input type="hidden" name="showdom" value="'.$dom.'" />'."\n".
1125: '<input type="hidden" name="orignum" value="'.$cnum.'" />'."\n");
1126: if ($result eq 'ok') {
1.40 raeburn 1127: if ($env{'form.crstype'} eq 'community') {
1128: $r->print(&mt('Your community request has been cancelled.'));
1129: } else {
1130: $r->print(&mt('Your course request has been cancelled.'));
1131: }
1.16 raeburn 1132: } else {
1133: $r->print('<div class="LC_error">'.
1134: &mt('The request cancellation process was not complete.').
1135: '<br />'.$error.'</div>');
1136: }
1137: $r->print('</form>');
1.11 raeburn 1138: }
1.26 raeburn 1139: } elsif ($action eq 'display') {
1140: my $formname = 'requestcrs';
1141: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1142: if ($env{'form.crstype'} eq 'official') {
1143: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1144: \%cat_order,\@code_order);
1145: }
1.40 raeburn 1146: my ($title,$header);
1147: if ($env{'form.crstype'} eq 'community') {
1148: $title = 'Community Request';
1149: $header = &mt('Community Request');
1150: } else {
1151: $title = 'Course Request';
1152: $header = &mt('Course Request');
1153: }
1154: $r->print(&header($title,'','','',{ 'only_body' => 1}).
1155: $crumb."\n".'<h3>'.$header.'</h3>'.
1.26 raeburn 1156: &print_review($dom,\@codetitles,\%cat_titles,\%cat_order,
1157: \@code_order,$uname,$udom)."\n".'</div>'.
1158: &close_popup_form());
1.1 raeburn 1159: } elsif ($action eq 'log') {
1.11 raeburn 1160: $r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
1.1 raeburn 1161: }
1.2 raeburn 1162: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 1163: return;
1164: }
1165:
1.31 raeburn 1166: sub enrollment_lcsec_js {
1167: my %alerts = §ion_check_alerts();
1168: my $secname = $alerts{'badsec'};
1169: my $secnone = $alerts{'reserved'};
1170: my $output = '
1171: function validateEnrollSections(formname,nextstate) {
1172: var badsectotal = 0;
1173: var reservedtotal = 0;
1174: var secTest = "";
1175: ';
1176: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1177: $output .= "
1178: var selSec = 0;
1179: for (var j=0; j<document.requestcrs.sec_".$i.".length; j++) {
1180: if (document.requestcrs.sec_".$i."[j].checked) {
1181: selSec = document.requestcrs.sec_".$i."[j].value;
1182: }
1183: if (selSec == 1) {
1184: secTest = validsection(document.requestcrs.loncapasec_".$i.");
1185: if (secTest == 'badsec') {
1186: badsectotal++;
1187: }
1188: if (secTest == 'reserved') {
1189: reservedtotal++;
1190: }
1191: }
1192: }
1193: ";
1194: }
1195: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
1196: $output .= "
1197: if (document.requestcrs.crosslist_".$i.".checked) {
1198: secTest = validsection(document.requestcrs.crosslist_".$i."_lcsec);
1199: if (secTest == 'badsec') {
1200: badsectotal++;
1201: }
1202: if (secTest == 'reserved') {
1203: reservedtotal++;
1204: }
1205: }
1206: ";
1207: }
1208: $output .= "
1209: if (badsectotal>0) {
1210: alert('$secname');
1211: return false;
1212: }
1213: if (reservedtotal>0) {
1214: alert('$secnone');
1215: return false;
1216: }
1217: formname.state.value= nextstate;
1218: formname.submit();
1219: return;
1220: }
1221: ";
1222: return $output;
1223: }
1224:
1225: sub personnel_lcsec_js {
1226: my %alerts = §ion_check_alerts();
1227: my $secname = $alerts{'badsec'}.'\\n'.$alerts{'separate'};
1228: my $secnone = $alerts{'reserved'};
1229: my $output = '
1230: function validatePersonnelSections(formname,nextstate) {
1231: var badsectotal = 0;
1232: var reservedtotal = 0;
1233: var secTest = "";
1234: ';
1235: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1236: $output .= "
1237: if (document.requestcrs.person_".$i."_uname.value != '') {
1238: secTest = validsection(document.requestcrs.person_".$i."_newsec,'1');
1239: if (secTest == 'badsec') {
1240: badsectotal++;
1241: }
1242: if (secTest == 'reserved') {
1243: reservedtotal++;
1244: }
1245: }
1246: ";
1247: }
1248: $output .= "
1249: if (badsectotal > 0) {
1250: alert('$secname');
1251: return false;
1252: } else {
1253: if (reservedtotal > 0) {
1254: alert('$secnone');
1255: return false;
1256: }
1257: }
1258: formname.state.value = nextstate;
1259: formname.submit();
1260: return;
1261: }
1262: ";
1263: return $output;
1264: }
1265:
1266: sub section_check_alerts {
1267: my %lt =
1268: &Apache::lonlocal::texthash(
1269: 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.",
1270: badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
1271: separate => 'Separate multiple sections with a comma.'
1272: );
1273: return %lt;
1274: }
1275:
1276: sub section_check_javascript {
1277: return <<"END";
1278: function validsection(field,mult) {
1279: var str = field.value;
1280: var badsec=0;
1281: var reserved=0;
1282: if (window.RegExp) {
1283: var badsecnum=0;
1284: var reservednum=0;
1285: var pattern=/[^a-zA-Z0-9]/;
1286: str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
1287: str = str.replace(/[ ]{2,}/gi," ");
1288: if (mult == '1') {
1289: var sections = new Array();
1290: sections = str.split(/\\s*[\\s,;:]\\s*/);
1291: var i;
1292: for (i=0; i<sections.length; i++) {
1293: if ((sections[i] != '') && (sections[i] != undefined) && (sections[i] != null)) {
1294: if (pattern.test(sections[i])) {
1295: badsecnum++;
1296: } else {
1297: if (sections[i] == 'none') {
1298: reservednum++;
1299: }
1300: }
1301: }
1302: }
1303: } else {
1304: if ((str != '') && (str != undefined) && (str != null)) {
1305: if (pattern.test(str)) {
1306: badsecnum++;
1307: } else {
1308: if (str == 'none') {
1309: reservednum++;
1310: }
1311: }
1312: }
1313: }
1314: if (badsecnum > 0) {
1315: return 'badsec';
1316: }
1317: if (reservednum > 0) {
1318: return 'reserved';
1319: }
1320: }
1321: return;
1322: }
1323: END
1324: }
1325:
1.26 raeburn 1326: sub close_popup_form {
1327: my $close= &mt('Close Window');
1328: return << "END";
1329: <p><form name="displayreq" action="" method="post">
1330: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
1331: </form></p>
1332: END
1333: }
1334:
1.27 raeburn 1335: sub get_instcode {
1336: my ($dom) = @_;
1337: my ($instcode,$numtitles);
1338: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
1339: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1340: \%cat_order,\@code_order);
1341: $numtitles = scalar(@codetitles);
1342: if (@code_order > 0) {
1343: my $message;
1344: foreach my $item (@code_order) {
1345: $instcode .= $env{'form.instcode_'.$item};
1346: }
1347: }
1348: return ($instcode,$numtitles);
1349: }
1350:
1.1 raeburn 1351: sub print_request_form {
1.27 raeburn 1352: my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
1.36 raeburn 1353: $description,$invalidcrosslist) = @_;
1.1 raeburn 1354: my $formname = 'requestcrs';
1.2 raeburn 1355: my ($next,$prev,$message,$output,$codepicker,$crstype);
1356: $prev = $states->{$action}[$page-1];
1357: $next = $states->{$action}[$page+1];
1.4 raeburn 1358: my %navtxt = &Apache::lonlocal::texthash (
1.10 raeburn 1359: prev => 'Back',
1.4 raeburn 1360: next => 'Next',
1361: );
1.2 raeburn 1362: $crstype = $env{'form.crstype'};
1.34 raeburn 1363: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
1.30 raeburn 1364: my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
1365: @disallowed);
1.1 raeburn 1366: if ($crstype eq 'official') {
1.2 raeburn 1367: if ($env{'form.instcode'} ne '') {
1368: $instcode = $env{'form.instcode'};
1.27 raeburn 1369: } elsif ($newinstcode ne '') {
1370: $instcode = $newinstcode;
1.2 raeburn 1371: }
1.27 raeburn 1372: if ($checkedcode) {
1373: if ($codechk eq 'valid') {
1374: $message = '<div class="LC_info">'.
1375: &mt('The chosen course category [_1] is valid.','<b>'.
1376: $instcode.'</b>').
1377: '<input type="hidden" name="instcode" value="'.
1378: $instcode.'" /></div>';
1.2 raeburn 1379: } else {
1380: $message = '<div class="LC_warning">'.
1.27 raeburn 1381: &mt('No course was found matching your choice of institutional course category.');
1382: if ($codechk ne '') {
1383: $message .= '<br />'.$codechk;
1384: }
1385: $message .= '</div>';
1.2 raeburn 1386: $prev = 'crstype';
1387: }
1388: $r->print($message);
1.1 raeburn 1389: }
1.2 raeburn 1390: }
1391: if ($prev eq 'crstype') {
1.4 raeburn 1392: if ($crstype eq 'official') {
1393: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1394: \%cat_order,\@code_order);
1395: }
1.2 raeburn 1396: if (@code_order > 0) {
1.1 raeburn 1397: $codepicker = &coursecode_form($dom,'instcode',\@codetitles,
1398: \%cat_titles,\%cat_order);
1.2 raeburn 1399: if ($codepicker) {
1.34 raeburn 1400: $r->print(&mt('Specify the course to be created.').
1401: '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1402: $codepicker.
1.2 raeburn 1403: &Apache::lonhtmlcommon::end_pick_box().'</div>');
1404: } else {
1.20 raeburn 1405: $next = $states->{$action}[$page+2];
1.41.2.8! raeburn 1406: $r->print(&courseinfo_form($dom,$formname,$state,$crstype,$next));
1.2 raeburn 1407: }
1408: } else {
1.20 raeburn 1409: if ($crstype eq 'official') {
1410: $next = $states->{$action}[$page+2];
1411: }
1.41.2.8! raeburn 1412: $r->print(&courseinfo_form($dom,$formname,$state,$crstype,$next));
1.1 raeburn 1413: }
1.2 raeburn 1414: } elsif ($prev eq 'codepick') {
1.27 raeburn 1415: if ($instcode eq '') {
1.20 raeburn 1416: $prev = $states->{$action}[$page-2];
1417: }
1.41.2.8! raeburn 1418: $r->print(&courseinfo_form($dom,$formname,$state,$crstype,$next,$description));
1.2 raeburn 1419: } elsif ($state eq 'enrollment') {
1.4 raeburn 1420: if ($crstype eq 'official') {
1421: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1422: \%cat_order,\@code_order);
1423: }
1.41.2.8! raeburn 1424: $r->print(&print_enrollment_menu($formname,$state,$instcode,$dom,\@codetitles,
1.27 raeburn 1425: \%cat_titles,\%cat_order,\@code_order,
1426: $invalidcrosslist));
1.2 raeburn 1427: } elsif ($state eq 'personnel') {
1.41.2.8! raeburn 1428: $r->print(&print_personnel_menu($dom,$formname,$state,$crstype,$invalidcrosslist));
1.4 raeburn 1429: } elsif ($state eq 'review') {
1.30 raeburn 1430: my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
1431: my $now = time;
1432: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1433: my $personname = $env{'form.person_'.$i.'_uname'};
1434: my $persondom = $env{'form.person_'.$i.'_dom'};
1435: if (($personname =~ /^$match_username$/) &&
1436: ($persondom =~ /^$match_domain$/)) {
1437: if (&Apache::lonnet::domain($persondom)) {
1438: my $personhome =
1439: &Apache::lonnet::homeserver($personname,$persondom);
1440: if ($personhome eq 'no_host') {
1441: if ($persondom ne $dom) {
1442: my $skipuser = 1;
1443: if ($env{'user.role.dc./'.$persondom.'/'}) {
1444: my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
1445: if (((!$start) || ($start < $now)) &&
1446: ((!$end) || ($end > $now))) {
1447: $skipuser = 0;
1448: }
1449: }
1450: if ($skipuser) {
1451: push(@disallowed,$i);
1452: $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain','<tt>'.$personname.':'.$persondom.'</tt>');
1453: next;
1454: }
1455: }
1456: if (&get_cancreate_status($persondom,$personname,$dom)) {
1457: my ($allowed,$msg) =
1458: &check_newuser_rules($persondom,$personname,
1459: \%alerts,\%rulematch,\%inst_results,
1460: \%curr_rules,\%got_rules);
1461: if ($allowed) {
1462: if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
1463: if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
1464: $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
1465: }
1466: if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
1467: $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
1468: }
1469: if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
1470: $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
1471: }
1472: }
1473: } else {
1474: push(@disallowed,$i);
1475: $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1476: }
1477: } else {
1478: push(@disallowed,$i);
1479: $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain','<tt>'.$personname.':'.$persondom.'</tt>');
1480: }
1481: } else {
1482: my %userenv =
1483: &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
1484: if ($env{'form.person_'.$i.'_lastname'} eq '') {
1485: $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
1486: }
1487: if ($env{'form.person_'.$i.'_firstname'} eq '') {
1488: $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
1489: }
1490: if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
1491: $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
1492: }
1493: }
1494: } elsif ($personname ne '') {
1495: push(@disallowed,$i);
1496: $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid','<tt>'.$personname.':'.$persondom.'</tt>');
1497: }
1498: } elsif ($personname ne '') {
1499: push(@disallowed,$i);
1500: $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.','<tt>'.$personname.':'.$persondom.'</tt>');
1501: }
1502: }
1.16 raeburn 1503: my $cnum;
1504: if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
1505: $cnum = $env{'form.origcnum'};
1506: } else {
1507: $cnum = &Apache::lonnet::generate_coursenum($dom);
1508: }
1.4 raeburn 1509: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1510: \%cat_order,\@code_order);
1.40 raeburn 1511: if ($crstype eq 'community') {
1512: $r->print('<h3>'.&mt('Review community request details before submission').'</h3>');
1513: } else {
1514: $r->print('<h3>'.&mt('Review course request details before submission').'</h3>');
1515: }
1516: $r->print(&print_review($dom,\@codetitles,\%cat_titles,\%cat_order,\@code_order,'','',\@disallowed,\%disallowmsg).
1.16 raeburn 1517: '<input type="hidden" name="cnum" value="'.$cnum.'" />');
1.40 raeburn 1518: if ($crstype eq 'community') {
1519: $navtxt{'next'} = &mt('Submit community request');
1520: } else {
1521: $navtxt{'next'} = &mt('Submit course request');
1522: }
1.41.2.8! raeburn 1523: } elsif ($state eq 'process') {
1.10 raeburn 1524: if ($crstype eq 'official') {
1525: &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
1526: \%cat_order,\@code_order);
1527: }
1.41.2.1 raeburn 1528: my ($storeresult,$result) = &print_request_outcome($r,$dom,\@codetitles,
1.41.2.8! raeburn 1529: \@code_order,$formname);
1.13 raeburn 1530: $r->print($result);
1.27 raeburn 1531: if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
1532: $r->print('<p>');
1533: if ($storeresult eq 'ok') {
1534: $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
1535: &mt('Modify this request').'</a>'.(' 'x4));
1536: }
1.41.2.2 raeburn 1537: unless ($env{'form.concepttest'}) {
1538: $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
1539: }
1.27 raeburn 1540: return;
1541: }
1.41.2.8! raeburn 1542: } elsif ($state eq 'uploadroster') {
! 1543: &roster_upload_form($r,$output,$formname);
1.1 raeburn 1544: }
1.16 raeburn 1545: my @excluded = &get_excluded_elements($dom,$states,$action,$state);
1.24 raeburn 1546: if ($state eq 'personnel') {
1547: push(@excluded,'persontotal');
1548: }
1.30 raeburn 1549: if ($state eq 'review') {
1550: if (@disallowed > 0) {
1551: my @items = qw(uname dom lastname firstname emailaddr hidedom role newsec);
1552: my @currsecs = ¤t_lc_sections();
1553: if (@currsecs) {
1554: push(@items,'sec');
1555: }
1556: my $count = 0;
1557: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
1558: unless ($env{'form.person_'.$i.'_uname'} eq '') {
1559: if (grep(/^$i$/,@disallowed)) {
1560: foreach my $item (@items) {
1561: $env{'form.person_'.$i.'_'.$item} = '';
1562: }
1563: } else {
1564: foreach my $item (@items) {
1565: $env{'form.person_'.$count.'_'.$item} = $env{'form.person_'.$i.'_'.$item};
1566: }
1567: }
1568: }
1569: $count ++;
1570: }
1571: $env{'form.persontotal'} = $count;
1572:
1573: }
1574: }
1.27 raeburn 1575: if ($state eq 'enrollment') {
1576: push(@excluded,'crosslisttotal');
1577: }
1.41.2.8! raeburn 1578: if ($state eq 'done') {
! 1579: $r->print(&done_display());
! 1580: } else {
! 1581: $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded));
! 1582: &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
! 1583: $navtxt{'next'},$state);
! 1584: }
! 1585: $r->print('</form>');
1.16 raeburn 1586: return;
1587: }
1588:
1.41.2.8! raeburn 1589: sub done_display {
! 1590: return '<h3>'.&mt('Concept Test creation is complete').'</h3>'.
! 1591: '<p>'.&mt('The following management tools are available via the "[_1]Manage Tests[_2]" tab, or from the toolbar on the [_3]Concept Test Contents[_4] page.[_5]',
! 1592: '<a href="/adm/menu">','</a>','<a href="/adm/navmaps">','</a>','<br />').
! 1593: '<dl class="LC_GCI_Menu">'.
! 1594: '<dt>'.&mt('Concept Test Contents').'</dt>'.
! 1595: '<dd style="background-image:url(\'/res/adm/pages/nav.png\');">'.&mt('Display the Table of Contents for your Concept Test.').'</dd>'.
! 1596: '<dt>'.&mt('Assemble Concept Test').'</dt>'.
! 1597: '<dd style="background-image:url(\'/res/adm/pages/docs.png\');">'.&mt('If no students have attempted the Concept Test you will be able to modify it. You can also change the start and end date of the test itself.').'</dd></dl>'.
! 1598: '<dl class="LC_GCI_Menu">'.
! 1599: '<dt>'.&mt('Enrollment and Student Activity').'</dt>'.
! 1600: '<dd style="background-image:url(\'/res/adm/pages/cprv.png\');">'.&mt('Display or download a course roster, and view information about completion status and last login. You can also add new students, or change access dates for existing students.').'</dd>'.
! 1601: '<dt>'.&mt("What's New?").'</dt>'.
! 1602: '<dd style="background-image:url(\'/res/adm/pages/new.png\');">'.&mt('View information about changes in your Concept Test course.').'</dd></dl>'.
! 1603: '<dl class="LC_GCI_Menu">'.
! 1604: '<dt>'.&mt('Prepare Printable Concept Test').'</dt>'.
! 1605: '<dd style="background-image:url(\'/res/adm/pages/prnt.png\');">'.&mt('Create a PDF which you can send to a printer to create a hardcopy of the Concept Test.').'</dd>'.
! 1606: '<dt>'.&mt('Concept Test Statistics').'</dt>'.
! 1607: '<dd style="background-image:url(\'/res/adm/pages/chrt.png\');">'.&mt('After the closing date of the Concept Test you can view and download statistics for the test, as well as anonymized submission data.').'</dd>'.
! 1608: '</dl></p>';
! 1609: }
! 1610:
1.30 raeburn 1611: sub get_cancreate_status {
1612: my ($persondom,$personname,$dom) = @_;
1613: my ($rules,$ruleorder) =
1614: &Apache::lonnet::inst_userrules($persondom,'username');
1615: my $usertype = &Apache::lonuserutils::check_usertype($persondom,$personname,
1616: $rules);
1617: return &Apache::lonuserutils::can_create_user($dom,'requestcrs',$usertype);
1618: }
1619:
1620: sub check_newuser_rules {
1621: my ($persondom,$personname,$alerts,$rulematch,$inst_results,$curr_rules,
1622: $got_rules) = @_;
1623: my $allowed = 1;
1624: my $newuser = 1;
1625: my ($checkhash,$userchkmsg);
1626: my $checks = { 'username' => 1 };
1627: $checkhash->{$personname.':'.$persondom} = { 'newuser' => $newuser };
1628: &Apache::loncommon::user_rule_check($checkhash,$checks,$alerts,$rulematch,
1629: $inst_results,$curr_rules,$got_rules);
1630: if (ref($alerts->{'username'}) eq 'HASH') {
1631: if (ref($alerts->{'username'}{$persondom}) eq 'HASH') {
1632: my $domdesc =
1633: &Apache::lonnet::domain($persondom,'description');
1634: if ($alerts->{'username'}{$persondom}{$personname}) {
1635: if (ref($curr_rules->{$persondom}) eq 'HASH') {
1636: $userchkmsg =
1637: &Apache::loncommon::instrule_disallow_msg('username',
1638: $domdesc,1).
1639: &Apache::loncommon::user_rule_formats($persondom,
1640: $domdesc,$curr_rules->{$persondom}{'username'},
1641: 'username');
1642: }
1643: $allowed = 0;
1644: }
1645: }
1646: }
1647: return ($allowed,$userchkmsg);
1648: }
1649:
1.16 raeburn 1650: sub get_excluded_elements {
1651: my ($dom,$states,$action,$state) = @_;
1.2 raeburn 1652: my @excluded = ('counter');
1653: my %elements = &form_elements($dom);
1654: if (ref($states) eq 'HASH') {
1655: if (ref($states->{$action}) eq 'ARRAY') {
1656: my @items = @{$states->{$action}};
1657: my $numitems = scalar(@items);
1658: if ($numitems) {
1659: for (my $i=$numitems-1; $i>=0; $i--) {
1660: if (ref($elements{$action}) eq 'HASH') {
1661: if (ref($elements{$action}{$items[$i]}) eq 'HASH') {
1.16 raeburn 1662: foreach my $key (keys(%{$elements{$action}{$items[$i]}})) {
1.2 raeburn 1663: push(@excluded,$key);
1664: }
1665: }
1666: }
1667: last if ($items[$i] eq $state);
1668: }
1669: }
1670: }
1671: }
1672: if (grep(/^instcode_/,@excluded)) {
1673: push(@excluded,'instcode');
1.1 raeburn 1674: }
1.41.2.8! raeburn 1675: if ($env{'form.initmap'}) {
! 1676: push(@excluded,'initmap');
! 1677: }
! 1678: if ($env{'form.output'}) {
! 1679: push(@excluded,'output');
! 1680: }
1.16 raeburn 1681: return @excluded;
1.1 raeburn 1682: }
1683:
1.2 raeburn 1684: sub print_enrollment_menu {
1.41.2.8! raeburn 1685: my ($formname,$state,$instcode,$dom,$codetitles,$cat_titles,$cat_order,
! 1686: $code_order,$invalidcrosslist) =@_;
1.34 raeburn 1687: my ($sections,$autoenroll,$access_dates,$output,$hasauto);
1.2 raeburn 1688: my $starttime = time;
1.41.2.8! raeburn 1689: my $diff = 6*30*24*60*60; # 6 months from now, approx
! 1690: if (&Apache::loncommon::needs_gci_custom()) {
! 1691: $diff = 7*24*60*60; # 7 days from now, approx
! 1692: }
! 1693: my $endtime = $starttime+$diff;
1.2 raeburn 1694: my %accesstitles = (
1695: 'start' => 'Default start access',
1.16 raeburn 1696: 'end' => 'Default end access',
1.2 raeburn 1697: );
1698: my %enrolltitles = (
1699: 'start' => 'Start auto-enrollment',
1700: 'end' => 'End auto-enrollment',
1701: );
1702: if ($env{'form.crstype'} eq 'official') {
1703: if (&Apache::lonnet::auto_run('',$dom)) {
1.27 raeburn 1704: $output = &show_invalid_crosslists($invalidcrosslist);
1705: my ($section_form,$crosslist_form);
1.2 raeburn 1706: $section_form = &inst_section_selector($dom,$instcode);
1.27 raeburn 1707: if ($section_form) {
1708: $sections = &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1709: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Sections').
1710: ' '.&mt('Sections for auto-enrollment').'</h3>'.
1.27 raeburn 1711: &Apache::lonhtmlcommon::row_closure(1).
1712: $section_form;
1713: }
1.2 raeburn 1714: my $crosslisttotal = $env{'form.crosslisttotal'};
1.24 raeburn 1715: if (!$crosslisttotal) {
1.2 raeburn 1716: $crosslisttotal = 1;
1717: }
1718: if ($env{'form.addcrosslist'}) {
1719: $crosslisttotal ++;
1720: }
1721: for (my $i=0; $i<$crosslisttotal; $i++) {
1722: $crosslist_form .= &coursecode_form($dom,'crosslist',$codetitles,
1723: $cat_titles,$cat_order,$i);
1724: }
1725: if ($crosslist_form) {
1726: $crosslist_form .=
1.40 raeburn 1727: &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 1728: '<input name="crosslisttotal" type="hidden" value="'.$crosslisttotal.'" />'.
1729: '<input name="addcrosslist" type="checkbox" value="'.$crosslisttotal.'"'.
1.41.2.8! raeburn 1730: ' onclick="javascript:nextPage(document.'.$formname.",'".$state.
1.27 raeburn 1731: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure();
1732: $sections .= &Apache::lonhtmlcommon::row_headline.
1733: '<h3>'.&mt('Crosslisted courses for auto-enrollment').'</h3>'.
1734: &Apache::lonhtmlcommon::row_closure(1).
1735: $crosslist_form;
1.2 raeburn 1736: }
1.34 raeburn 1737: $hasauto = 1;
1.27 raeburn 1738: $autoenroll =
1.34 raeburn 1739: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autoadd').' '.&mt('Add registered students automatically')).
1.2 raeburn 1740: '<span class="LC_nobreak"><label>'.
1.41.2.8! raeburn 1741: '<input type="radio" name="autoadds" value="1" />'.
1.2 raeburn 1742: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1.41.2.8! raeburn 1743: '<input type="radio" name="autoadds" value="0" checked="checked" />'.
1.2 raeburn 1744: &mt('No').'</label></span>'.
1.27 raeburn 1745: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1746: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic('Course_Request_Autodrop').' '.&mt('Drop unregistered students automatically')).
1.2 raeburn 1747: '<span class="LC_nobreak"><label>'.
1.41.2.8! raeburn 1748: '<input type="radio" name="autodrops" value="1" />'.
1.2 raeburn 1749: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1.41.2.8! raeburn 1750: '<input type="radio" name="autodrops" value="0" checked="checked" />'.
1.2 raeburn 1751: &mt('No').'</label></span>'.
1.27 raeburn 1752: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1753: &date_setting_table($starttime,$endtime,$formname,'enroll',
1754: $hasauto,%enrolltitles);
1.2 raeburn 1755: }
1756: }
1.27 raeburn 1757: my $access_dates =
1.34 raeburn 1758: &date_setting_table($starttime,$endtime,$formname,'access',$hasauto,
1759: %accesstitles);
1.27 raeburn 1760: if ($sections) {
1761: $output .= $sections;
1762: }
1763: if ($autoenroll) {
1764: $output .= &Apache::lonhtmlcommon::row_headline('Auto-enroll').
1765: '<h3>'.&mt('Auto-enrollment settings').'</h3>'.
1766: &Apache::lonhtmlcommon::row_closure(1).
1767: $autoenroll;
1768: }
1769: if ($access_dates) {
1770: my $header = &mt('Access dates for students');
1771: if ($env{'form.crstype'} eq 'community') {
1772: $header = &mt('Access dates for community members');
1773: }
1774: $output .= &Apache::lonhtmlcommon::row_headline('Access').
1775: '<h3>'.$header.'</h3>'.
1776: &Apache::lonhtmlcommon::row_closure(1).
1.41.2.8! raeburn 1777: $access_dates;
1.2 raeburn 1778: }
1.41.2.1 raeburn 1779: if ($dom eq 'gcitest') {
1780: return $output;
1781: } else {
1782: return '<div>'.&Apache::lonhtmlcommon::start_pick_box().$output.
1783: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1784: }
1.2 raeburn 1785: }
1786:
1.27 raeburn 1787: sub show_invalid_crosslists {
1788: my ($invalidcrosslist) = @_;
1789: my $output;
1790: if (ref($invalidcrosslist) eq 'ARRAY') {
1791: if (@{$invalidcrosslist} > 0) {
1792: $output = '<div class="LC_warning">'.
1793: &mt('The following crosslisted courses were invalid:').'<ul>';
1794: foreach my $item (@{$invalidcrosslist}) {
1795: $output .= '<li>'.$item.'</li>';
1796: }
1797: $output .= '</ul></div><br />';
1798: }
1799: }
1800: return $output;
1801: }
1802:
1803:
1.1 raeburn 1804: sub inst_section_selector {
1.2 raeburn 1805: my ($dom,$instcode) = @_;
1806: my @sections = &Apache::lonnet::auto_get_sections(undef,$dom,$instcode);
1807: my $sectotal = scalar(@sections);
1.1 raeburn 1808: my $output;
1.2 raeburn 1809: if ($sectotal) {
1.27 raeburn 1810: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections of [_1]',$instcode)).
1.2 raeburn 1811: &Apache::loncommon::start_data_table().
1812: &Apache::loncommon::start_data_table_row().
1813: '<th>'.&mt('Include?').'<input type="hidden" name="sectotal" '.
1.24 raeburn 1814: 'value="'.$sectotal.'" /></th>'.
1.2 raeburn 1815: '<th>'.&mt('Institutional Section').'</th>'.
1.34 raeburn 1816: '<th>'.&Apache::loncommon::help_open_topic('Course_Request_LCSection').
1817: ' '.&mt('LON-CAPA section').'</th>'.
1.2 raeburn 1818: &Apache::loncommon::end_data_table_row();
1819: for (my $i=0; $i<@sections; $i++) {
1.1 raeburn 1820: my $colflag = $i%2;
1.31 raeburn 1821: my $secon = ' checked="checked"';
1822: my $secoff = '';
1.24 raeburn 1823: if ($env{'form.origcnum'}) {
1.31 raeburn 1824: $secoff = $secon;
1825: $secon='';
1.24 raeburn 1826: }
1.1 raeburn 1827: $output .= &Apache::loncommon::start_data_table_row().
1.31 raeburn 1828: '<td><label><input type="radio" name="sec_'.$i.
1829: '"'.$secon.' value="1" />'.&mt('Yes').'</label>'.
1830: (' 'x2).'<label><input type="radio" name="sec_'.$i.
1831: '"'.$secoff.' value="0" />'.&mt('No').'</label></td>'.
1832: '<td align="center">'.$sections[$i].
1.1 raeburn 1833: '<input type="hidden" name="secnum_'.$i.'" value="'.
1.2 raeburn 1834: $sections[$i].'" /></td>'.
1.1 raeburn 1835: '<td><input type="text" size="10" name="loncapasec_'.$i.
1.2 raeburn 1836: '" value="'.$sections[$i].'" /></td>'.
1.1 raeburn 1837: &Apache::loncommon::end_data_table_row();
1838: }
1.2 raeburn 1839: $output .= &Apache::loncommon::end_data_table().
1840: &Apache::lonhtmlcommon::row_closure();
1.1 raeburn 1841: }
1842: return $output;
1843: }
1844:
1.2 raeburn 1845: sub date_setting_table {
1.34 raeburn 1846: my ($starttime,$endtime,$formname,$prefix,$hasauto,%datetitles) = @_;
1.2 raeburn 1847: my ($perpetual,$table);
1.41.2.8! raeburn 1848: my $no_hh_mm_ss = 1;
! 1849: if (&Apache::loncommon::needs_gci_custom()) {
! 1850: $no_hh_mm_ss = '';
! 1851: }
1.14 raeburn 1852: my $startform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'start',
1.41.2.8! raeburn 1853: $starttime,'','','',$no_hh_mm_ss,'','','',1);
1.14 raeburn 1854: my $endform = &Apache::lonhtmlcommon::date_setter($formname,$prefix.'end',
1.41.2.8! raeburn 1855: $endtime,'','','',$no_hh_mm_ss,'','','',1);
1.27 raeburn 1856: my $closure = '';
1.14 raeburn 1857: if ($prefix eq 'access') {
1.41.2.8! raeburn 1858: unless (&Apache::loncommon::needs_gci_custom()) {
! 1859: $perpetual = ' <span class="LC_nobreak"><label>'.
! 1860: '<input type="checkbox" name="no_end_date" />'.
! 1861: &mt('No end date').'</label></span>';
! 1862: }
1.27 raeburn 1863: $closure = '1';
1.2 raeburn 1864: }
1.34 raeburn 1865:
1866: my %help_item = (
1867: access => {
1868: start => 'Course_Request_Access_Start',
1869: end => 'Course_Request_Access_End',
1870: },
1871: enroll => {
1872: start => 'Course_Request_Enroll_Start',
1873: end => 'Course_Request_Enroll_End',
1874: },
1875: );
1876: if ($hasauto) {
1877: $help_item{'access'}{'start'} = 'Course_Request_RegAccess_Start';
1878: $help_item{'access'}{'end'} = 'Course_Request_RegAccess_End';
1879: }
1880:
1881: $table = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'start'}).
1882: ' '.$datetitles{'start'}).$startform.
1.27 raeburn 1883: &Apache::lonhtmlcommon::row_closure(1).
1.34 raeburn 1884: &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($help_item{$prefix}{'end'}).
1885: ' '.$datetitles{'end'}).$endform.$perpetual.
1.27 raeburn 1886: &Apache::lonhtmlcommon::row_closure($closure);
1.2 raeburn 1887: return $table;
1888: }
1889:
1890: sub print_personnel_menu {
1.41.2.8! raeburn 1891: my ($dom,$formname,$state,$crstype,$invalidcrosslist) = @_;
1.27 raeburn 1892: my $output;
1893: if ($crstype eq 'official') {
1894: if (&Apache::lonnet::auto_run('',$dom)) {
1895: $output .= &show_invalid_crosslists($invalidcrosslist);
1896: }
1897: }
1898: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box();
1.2 raeburn 1899: my $persontotal = $env{'form.persontotal'};
1.16 raeburn 1900: if ((!defined($persontotal)) || (!$persontotal)) {
1.2 raeburn 1901: $persontotal = 1;
1902: }
1903: if ($env{'form.addperson'}) {
1904: $persontotal ++;
1905: }
1.13 raeburn 1906: my @items = ('uname','dom','lastname','firstname','emailaddr','hidedom');
1.2 raeburn 1907:
1.8 raeburn 1908: my $type = 'Course';
1909: if ($crstype eq 'community') {
1910: $type = 'Community';
1911: }
1.41 raeburn 1912: my $roleoptions;
1913: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.2 raeburn 1914: foreach my $role (@roles) {
1.28 raeburn 1915: my $plrole = &Apache::lonnet::plaintext($role,$type);
1.2 raeburn 1916: $roleoptions .= ' <option value="'.$role.'">'.$plrole.'</option>'."\n";
1917: }
1918: my %customroles=&Apache::lonuserutils::my_custom_roles();
1919: if (keys(%customroles) > 0) {
1920: foreach my $cust (sort(keys(%customroles))) {
1.28 raeburn 1921: my $custrole="cr/$env{'user.domain'}/$env{'user.name'}/$cust";
1.2 raeburn 1922: $roleoptions .= ' <option value="'.$custrole.'">'.$cust.'</option>'."\n";
1923: }
1924: }
1925:
1.30 raeburn 1926: my @currsecs = ¤t_lc_sections();
1.2 raeburn 1927:
1928: my ($existtitle,$existops,$existmult,$newtitle,$seccolspan);
1929: if (@currsecs) {
1930: my $existsize = scalar(@currsecs);
1931: if ($existsize > 3) {
1932: $existsize = 3;
1933: }
1934: if ($existsize > 1) {
1935: $existmult = ' multiple="multiple" size="'.$existsize.'" ';
1936: }
1937: @currsecs = sort { $a <=> $b } (@currsecs);
1938: $existtitle = &mt('Official').': ';
1939: $existops = '<option value="">'.&mt('None').'</option>';
1940: foreach my $sec (@currsecs) {
1941: $existops .= '<option value="'.$sec.'">'.$sec.'</option>'."\n";
1942: }
1943: $seccolspan = ' colspan="2"';
1944: $newtitle = &mt('Other').': ';
1945: }
1946:
1.27 raeburn 1947: if ($persontotal) {
1.32 raeburn 1948: my %lt = &Apache::lonlocal::texthash(
1949: community => 'Requestor is automatically assigned Coordinator role.',
1950: official => 'Requestor is automatically assigned Course Coordinator role.',
1951: );
1952: $lt{'unofficial'} = $lt{'official'};
1.27 raeburn 1953: $output .= &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 1954: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Personnel').' '.$lt{$crstype}.' '.&mt('Include other personnel?').'</h3>';
1.27 raeburn 1955: }
1.2 raeburn 1956: for (my $i=0; $i<$persontotal; $i++) {
1957: my @linkargs = map { 'person_'.$i.'_'.$_ } (@items);
1958: my $linkargstr = join("','",@linkargs);
1.29 raeburn 1959: my $uname_form = '<input type="text" name="person_'.$i.'_uname" value="" size="20" />';
1.2 raeburn 1960: my $onchange = 'javascript:fix_domain('."'$formname','person_".$i."_dom',".
1.29 raeburn 1961: "'person_".$i."_hidedom','person_".$i."_uname'".');';
1.2 raeburn 1962: my $udom_form = &Apache::loncommon::select_dom_form($dom,'person_'.$i.'_dom','',
1963: 1,$onchange).
1.29 raeburn 1964: '<input type="hidden" name="person_'.$i.'_hidedom" value="" />';
1.2 raeburn 1965: my %form_elems;
1966: foreach my $item (@items) {
1967: next if (($item eq 'dom') || ($item eq 'uname') || ($item eq 'hidedom'));
1968: $form_elems{$item} = '<input type="text" name="person_'.$i.'_'.$item.'" '.
1969: 'value="" readonly="readonly" />';
1970: }
1971: my $roleselector = '<select name="person_'.$i.'_role">'."\n".
1972: $roleoptions.'</select>';
1973: my $sectionselector;
1974: if (@currsecs) {
1975: $sectionselector = $existtitle.'<select name="person_'.$i.'_sec"'.
1976: $existmult.'>'."\n".$existops.'</select>'.(' ' x3);
1977: }
1978: $sectionselector .= $newtitle.
1.14 raeburn 1979: '<input type="text" name="person_'.$i.'_newsec" size="15" value="" />'."\n";
1.29 raeburn 1980: my $usersrchlinktxt = &mt('Search for user');
1981: my $usersrchlink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1982: $usersrchlinktxt);
1983: my $userchklinktxt = &mt('Check username');
1984: my $userchklink = &Apache::loncommon::selectuser_link($formname,@linkargs,$dom,
1985: $userchklinktxt,'checkusername');
1.2 raeburn 1986: $output .=
1.29 raeburn 1987: &Apache::lonhtmlcommon::row_title(&mt('Additional Personnel')).
1988: '<table><tr><td align="center" valign="middle"><b>'.$usersrchlink.'</b></td>'."\n".
1989: '<td align="left" valign="top" colspan="2"><span class="LC_nobreak">'.
1990: &mt('Username').': '.$uname_form.' '.$userchklink.'</span><br />'."\n".
1991: '<span class="LC_nobreak">'.&mt('Domain').': '.$udom_form.'</span></td>'.
1992: '</tr>'."\n".'<tr>'.
1.13 raeburn 1993: '<td align="center" valign="top">'.&mt('First Name').'<br />'.$form_elems{'firstname'}.'</td>'."\n".
1994: '<td align="center" valign="top">'.&mt('Last Name').'<br />'.$form_elems{'lastname'}.'</td>'."\n".
1995: '<td align="center" valign="top">'.&mt('E-mail').'<br />'.$form_elems{'emailaddr'}.'</td></tr>'."\n".
1.34 raeburn 1996: '<tr><td align="center" valign="top">'.&Apache::loncommon::help_open_topic('Course_Roles').' '.&mt('Role').'<br />'.$roleselector.'</td>'."\n".
1997: '<td'.$seccolspan.' align="center" valign="top">'.
1998: &Apache::loncommon::help_open_topic('Course_Request_Rolesection').' '.&mt('LON-CAPA Section(s)').'<br />'.$sectionselector.'</td>'."\n".
1.2 raeburn 1999: '</tr></table>'.&Apache::lonhtmlcommon::row_closure();
2000: }
1.40 raeburn 2001: $output .= &Apache::lonhtmlcommon::row_title(&mt('Add another')).
1.2 raeburn 2002: '<input name="persontotal" type="hidden" value="'.$persontotal.'" />'.
2003: '<input name="addperson" type="checkbox" value="'.$persontotal.'"'.
1.41.2.8! raeburn 2004: ' onclick="javascript:nextPage(document.'.$formname.",'".$state.
1.2 raeburn 2005: "'".');" />'.&mt('Add?').&Apache::lonhtmlcommon::row_closure(1).
1.40 raeburn 2006: &Apache::lonhtmlcommon::end_pick_box().'</div>';
2007: if ($crstype eq 'community') {
2008: $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>';
2009: } else {
2010: $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>';
2011: }
1.2 raeburn 2012: return $output;
2013: }
2014:
1.30 raeburn 2015: sub current_lc_sections {
2016: my @currsecs;
2017: if ($env{'form.sectotal'}) {
2018: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
1.31 raeburn 2019: if ($env{'form.sec_'.$i}) {
2020: if (defined($env{'form.loncapasec_'.$i})) {
2021: my $lcsec = $env{'form.loncapasec_'.$i};
2022: unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
2023: push(@currsecs,$lcsec);
2024: }
1.30 raeburn 2025: }
2026: }
2027: }
2028: }
2029: return @currsecs;
2030: }
2031:
1.1 raeburn 2032: sub print_request_status {
1.41.2.8! raeburn 2033: my ($dom,$action,$state) = @_;
1.14 raeburn 2034: my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
2035: $env{'user.name'},'^status:'.$dom);
1.35 raeburn 2036: my ($output,$formname,%queue_by_date);
1.37 raeburn 2037: my ($types,$typenames) = &Apache::loncommon::course_types();
1.14 raeburn 2038: foreach my $key (keys(%statusinfo)) {
2039: if (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending')) {
2040: (undef,my($cdom,$cnum)) = split(':',$key);
2041: next if ($cdom ne $dom);
2042: my $requestkey = $cdom.'_'.$cnum;
2043: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2044: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2045: $env{'user.domain'},$env{'user.name'});
2046: my $entry;
2047: my $timestamp = $history{'reqtime'};
2048: my $crstype = $history{'crstype'};
2049: my $disposition = $history{'disposition'};
2050: next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
2051: next unless (($env{'form.crstype'} eq 'any') ||
2052: ($env{'form.crstype'} eq $crstype));
2053: next unless (($disposition eq 'approval') ||
2054: ($disposition eq 'pending'));
2055: if (ref($history{'details'}) eq 'HASH') {
2056: $entry = $requestkey.':'.$crstype.':'.
2057: &escape($history{'details'}{'cdescr'});
2058: if ($crstype eq 'official') {
2059: $entry .= ':'.&escape($history{'details'}{'instcode'});
2060: }
2061: }
2062: if ($entry ne '') {
2063: if (exists($queue_by_date{$timestamp})) {
2064: if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
2065: push(@{$queue_by_date{$timestamp}},$entry);
2066: }
2067: } else {
2068: @{$queue_by_date{$timestamp}} = ($entry);
1.10 raeburn 2069: }
2070: }
2071: }
2072: }
2073: }
1.11 raeburn 2074: $formname = 'requestcrs';
1.10 raeburn 2075: my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
1.41.2.8! raeburn 2076: $output = '<input type="hidden" name="reqaction" value="'.$action.'" />'."\n".
1.16 raeburn 2077:
1.41.2.8! raeburn 2078: '<input type="hidden" name="state" value="'.$state.'" />'."\n".
1.16 raeburn 2079: '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'."\n".
2080: '<input type="hidden" name="showdom" value="" />'."\n".
2081: '<input type="hidden" name="cnum" value="" />'."\n";
1.10 raeburn 2082: if (@sortedtimes > 0) {
1.40 raeburn 2083: my $desctitle;
2084: if ($env{'form.crstype'} eq 'any') {
2085: $desctitle = &mt('Course/Community Description')
2086: } elsif ($env{'form.crstype'} eq 'community') {
2087: $desctitle = &mt('Community Description')
2088: } else {
2089: $desctitle = &mt('Course Description');
2090: }
1.10 raeburn 2091: $output .= &Apache::loncommon::start_data_table().
2092: &Apache::loncommon::start_data_table_header_row().
2093: '<th>'.&mt('Action').'</th>'.
1.40 raeburn 2094: '<th>'.$desctitle.'</th>'.
1.14 raeburn 2095: '<th>'.&mt('Domain').'</th>';
2096: if ($env{'form.crstype'} eq 'any') {
1.10 raeburn 2097: $output .= '<th>'.&mt('Type').'</th>';
2098: }
1.14 raeburn 2099: if (($env{'form.crstype'} eq 'any') || ($env{'form.crstype'} eq 'official')) {
1.10 raeburn 2100: $output .= '<th>'.&mt('Institutional Code').'</th>';
2101: }
2102: $output .= '<th>'.&mt('Date requested').'</th>'.
2103: &Apache::loncommon::end_data_table_header_row();
2104: my $count = 0;
2105: foreach my $item (@sortedtimes) {
2106: my $showtime = &Apache::lonlocal::locallocaltime($item);
2107: if (ref($queue_by_date{$item}) eq 'ARRAY') {
2108: foreach my $request (sort(@{$queue_by_date{$item}})) {
2109: my ($key,$type,$desc,$instcode) = split(':',$request);
2110: my ($cdom,$cnum) = split('_',$key);
2111: $output .= &Apache::loncommon::start_data_table_row().
1.16 raeburn 2112: '<td><input type="button" value="'.&mt('Select').'" onclick="javascript:chooseRequest('."'$cdom','$cnum'".')" /></td>'.
1.14 raeburn 2113: '<td>'.&unescape($desc).'</td>'.
2114: '<td>'.$cdom.'</td>';
2115: if ($env{'form.crstype'} eq 'any') {
1.35 raeburn 2116: my $typename;
2117: if (ref($typenames) eq 'HASH') {
2118: $typename = &mt($typenames->{$type});
2119: }
1.14 raeburn 2120: if ($typename eq '') {
2121: $typename = &mt('Unknown type');
2122: }
2123: $output .= '<td>'.$typename.'</td>';
1.10 raeburn 2124: }
1.14 raeburn 2125: if (($env{'form.crstype'} eq 'any') ||
1.10 raeburn 2126: ($env{'form.crstype'} eq 'official')) {
1.14 raeburn 2127: my $showinstcode;
2128: if ($type eq 'official') {
2129: $showinstcode = &unescape($instcode);
2130: } else {
2131: $showinstcode = &mt('Not applicable');
2132: }
2133: $output .= '<td>'.$showinstcode.'</td>';
1.10 raeburn 2134: }
2135: $output .= '<td>'.$showtime.'</td>'.
2136: &Apache::loncommon::end_data_table_row();
2137: }
2138: }
2139: }
2140: $output .= &Apache::loncommon::end_data_table();
2141: } else {
1.40 raeburn 2142: if ($env{'form.crstype'} eq 'any') {
2143: $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>';
2144: } elsif ($env{'form.crstype'} eq 'community') {
2145: $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>';
2146: } else {
2147: $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>';
2148: }
1.10 raeburn 2149: }
2150: $output .= '
1.30 raeburn 2151: <br /><input type="button" name="prev" value="'.&mt('Back').'" onclick="javascript:backPage(document.'.$formname.",'crstype'".')" />';
1.10 raeburn 2152: return $output;
1.1 raeburn 2153: }
2154:
1.16 raeburn 2155: sub print_cancel_request {
2156: my ($dom,$cnum) = @_;
2157: my $requestkey = $dom.'_'.$cnum;
2158: my ($result,$output);
2159: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
2160: my %history = &Apache::lonnet::restore($requestkey,'courserequests',
2161: $env{'user.domain'},$env{'user.name'});
2162: my $timestamp = $history{'reqtime'};
2163: my $crstype = $history{'crstype'};
2164: my $status = $history{'status'};
2165: if (($status eq 'cancelled') || ($status eq 'created')) {
2166: if ($status eq 'cancelled') {
2167: $output = &mt('This request has already been cancelled.');
2168: } elsif ($status eq 'created') {
2169: $output = &mt('This request has already been processed, and a course created.');
2170: }
2171: $output = &mt('No further action will be taken');
2172: } elsif (ref($history{'details'}) eq 'HASH') {
1.37 raeburn 2173: my ($types,$typename) = &Apache::loncommon::course_types();
1.16 raeburn 2174: my $showtype = $crstype;
2175: if (defined($typename->{$crstype})) {
2176: $showtype = $typename->{$crstype};
2177: }
2178: $output = '<p>'.&Apache::loncommon::start_data_table().
2179: &Apache::loncommon::start_data_table_header_row().
2180: '<th>'.&mt('Description').'</th><th>'.&mt('Requested').'</th>'.
2181: '<th>'.&mt('Type').'</th>'.
2182: &Apache::loncommon::end_data_table_header_row().
2183: &Apache::loncommon::start_data_table_row().
2184: '<td>'.$history{details}{'cdescr'}.'</td><td>'.
2185: &Apache::lonlocal::locallocaltime($timestamp).'</td>'.
2186: '<td>'.$showtype.'</td>'.
2187: &Apache::loncommon::end_data_table_row().
2188: &Apache::loncommon::end_data_table().
1.40 raeburn 2189: '<br /><div class="LC_warning">';
2190: if ($crstype eq 'community') {
2191: $output .= &mt('Cancelling the request will remove it from the queue of pending community requests').'</div>';
2192: } else {
2193: $output .= &mt('Cancelling the request will remove it from the queue of pending course requests').'</div>';
2194: }
1.16 raeburn 2195: $result = 'ok';
2196: } else {
2197: $output = '<div class="LC_error">'.&mt('No record exists for the course ID').'</div>';
2198: }
2199: } else {
2200: $output = '<div class="LC_error">'.&mt('Invalid course ID').'</div>';
2201: }
2202: return ($result,$output);
2203: }
2204:
2205: sub viewrequest_javascript {
2206: my ($formname,$next) = @_;
2207: return <<"ENDJS";
2208:
2209: function chooseRequest(cdom,cnum) {
2210: document.$formname.showdom.value = cdom;
2211: document.$formname.cnum.value = cnum;
2212: nextPage(document.$formname,'$next');
2213: }
2214:
2215: ENDJS
2216: }
2217:
2218: sub viewdetails_javascript {
2219: my ($formname) = @_;
2220: return << "ENDJS";
2221:
2222: function nextPage(formname,nextstate) {
2223: if (nextstate == "modify") {
2224: formname.state.value = "personnel";
1.41.2.8! raeburn 2225: formname.reqaction.value = "new";
1.16 raeburn 2226: } else {
2227: formname.state.value = nextstate;
2228: }
2229: formname.submit();
2230: }
2231:
2232: function backPage(formname,prevstate) {
2233: formname.state.value = prevstate;
2234: formname.submit();
2235: }
2236:
2237: ENDJS
2238: }
2239:
2240: sub viewcancel_javascript {
2241: my $alert = &mt('Are you sure you want to cancel this request?\\n'.
2242: 'Your request will be removed.');
2243: return << "ENDJS";
2244: function nextPage(formname,nextstate) {
2245: if (confirm('$alert')) {
2246: formname.state.value = nextstate;
2247: formname.submit();
2248: }
2249: return;
2250: }
2251:
2252: ENDJS
2253: }
2254:
1.1 raeburn 2255: sub print_request_logs {
1.10 raeburn 2256: my ($jscript,$loaditems,$crumb) = @_;
1.1 raeburn 2257: return;
2258: }
2259:
2260: sub print_review {
1.30 raeburn 2261: my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
2262: $disallowed,$disallowmsg) = @_;
1.37 raeburn 2263: my ($types,$typename) = &Apache::loncommon::course_types();
1.4 raeburn 2264: my ($owner,$ownername,$owneremail);
1.26 raeburn 2265: if ($uname eq '' || $udom eq '') {
2266: $uname = $env{'user.name'};
2267: $udom = $env{'user.domain'};
2268: }
2269: $owner = $uname.':'.$udom;
2270: $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
2271: my %emails = &Apache::loncommon::getemails($uname,$udom);
1.4 raeburn 2272: foreach my $email ('permanentemail','critnotification','notification') {
2273: $owneremail = $emails{$email};
2274: last if ($owneremail ne '');
2275: }
2276: my ($inst_headers,$inst_values,$crstypename,$enroll_headers,$enroll_values,
2277: $section_headers,$section_values,$personnel_headers,$personnel_values);
2278:
2279: $crstypename = $env{'form.crstype'};
2280: if (ref($typename) eq 'HASH') {
2281: unless ($typename->{$env{'form.crstype'}} eq '') {
1.35 raeburn 2282: $crstypename = &mt($typename->{$env{'form.crstype'}});
1.4 raeburn 2283: }
2284: }
1.16 raeburn 2285: my $category = 'Course';
2286: if ($env{'form.crstype'} eq 'community') {
2287: $category = 'Community';
2288: }
1.4 raeburn 2289:
2290: $inst_headers = '<th>'.&mt('Description').'</th><th>'.&mt('Type').'</th>';
2291: $inst_values = '<td>'.$env{'form.cdescr'}.'</td><td>'.$crstypename.'</td>';
2292:
1.16 raeburn 2293: my $enrollrow_title = &mt('Default Access Dates').'<br />'.
2294: '('.&Apache::lonnet::plaintext('st',$category).')';
1.4 raeburn 2295: if ($env{'form.crstype'} eq 'official') {
2296: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH')) {
2297: foreach my $title (@{$codetitles}) {
2298: if ($env{'form.instcode_'.$title} ne '') {
2299: $inst_headers .= '<th>'.$title.'</th>';
2300: my $longitem = $env{'form.instcode_'.$title};
2301: if (ref($cat_titles->{$title}) eq 'HASH') {
2302: if ($cat_titles->{$title}{$env{'form.instcode_'.$title}} ne '') {
2303: $longitem = $cat_titles->{$title}{$env{'form.instcode_'.$title}};
2304: }
2305: }
2306: $inst_values .= '<td>'.$longitem.'</td>';
2307: }
2308: }
2309: }
2310: if (&Apache::lonnet::auto_run('',$dom)) {
1.16 raeburn 2311: $enrollrow_title = &mt('Enrollment');
1.4 raeburn 2312: $enroll_headers = '<th>'.&mt('Automatic Adds').'</th>'.
2313: '<th>'.&mt('Automatic Drops').'</th>'.
2314: '<th>'.&mt('Enrollment Starts').'</th>'.
2315: '<th>'.&mt('Enrollment Ends').'</th>';
2316: $section_headers = '<th>'.&mt('Sections').'</th>'.
2317: '<th>'.&mt('Crosslistings').'</th>';
2318:
1.13 raeburn 2319: my ($enrollstart,$enrollend) = &dates_from_form('enrollstart','enrollend');
1.4 raeburn 2320: my @autoroster = (&mt('No'),&mt('Yes'));
2321: $enroll_values = '<td>'.$autoroster[$env{'form.autoadds'}].'</td>'.
2322: '<td>'.$autoroster[$env{'form.autodrops'}].'</td>'.
1.13 raeburn 2323: '<td>'.&Apache::lonlocal::locallocaltime($enrollstart).'</td>'.
2324: '<td>'.&Apache::lonlocal::locallocaltime($enrollend).'</td>';
1.6 raeburn 2325: $section_values = '<td><table class="LC_innerpickbox"><tr><th>'.
2326: &mt('Institutional section').'</th>'.
2327: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2328: my $secinfo;
1.4 raeburn 2329: if ($env{'form.sectotal'} > 0) {
2330: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2331: if ($env{'form.sec_'.$i}) {
1.5 raeburn 2332: $secinfo .= '<tr><td>'.$env{'form.secnum_'.$i}.'</td><td>';
1.4 raeburn 2333: if ($env{'form.loncapasec_'.$i} ne '') {
1.5 raeburn 2334: $secinfo .= $env{'form.loncapasec_'.$i};
2335: } else {
2336: $secinfo .= &mt('None');
1.4 raeburn 2337: }
1.5 raeburn 2338: $secinfo .= '</td></tr>';
1.4 raeburn 2339: }
2340: }
2341: }
1.6 raeburn 2342: if ($secinfo eq '') {
2343: $secinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2344: }
1.6 raeburn 2345: $section_values .= $secinfo.'</table></td><td>'.
2346: '<table class="LC_innerpickbox"><tr><th>'.
2347: &mt('Institutional course/section').'</th>'.
2348: '<th>'.&mt('LON-CAPA section').'</th></tr>';
1.5 raeburn 2349: my $xlistinfo;
1.24 raeburn 2350: my $crosslisttotal = $env{'form.crosslisttotal'};
2351: if (!$crosslisttotal) {
2352: $crosslisttotal = 1;
2353: }
2354: for (my $i=0; $i<$crosslisttotal; $i++) {
2355: if ($env{'form.crosslist_'.$i}) {
2356: $xlistinfo .= '<tr><td>';
2357: if (ref($code_order) eq 'ARRAY') {
2358: if (@{$code_order} > 0) {
2359: foreach my $item (@{$code_order}) {
2360: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
1.4 raeburn 2361: }
2362: }
2363: }
1.24 raeburn 2364: $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'}.'</td><td>';
2365: if ($env{'form.crosslist_'.$i.'_lcsec'}) {
2366: $xlistinfo .= $env{'form.crosslist_'.$i.'_lcsec'};
2367: } else {
2368: $xlistinfo .= &mt('None');
2369: }
2370: $xlistinfo .= '</td></tr>';
1.4 raeburn 2371: }
2372: }
1.6 raeburn 2373: if ($xlistinfo eq '') {
2374: $xlistinfo = '<tr><td colspan="2">'.&mt('None').'</td></tr>';
1.5 raeburn 2375: }
1.24 raeburn 2376: $section_values .= $xlistinfo;
1.4 raeburn 2377: }
1.24 raeburn 2378: $section_values .= '</table></td>';
1.4 raeburn 2379: }
2380:
2381: my %ctxt = &clone_text();
1.41.2.1 raeburn 2382: if ($dom eq 'gcitest') {
2383: $inst_headers .= '<th>'.&mt('Test Questions').'</th>';
2384: my $concepttest;
2385: if ($env{'form.concepttest'} eq 'defchosen') {
2386: $concepttest = 'Auto-generated';
2387: } elsif ($env{'form.concepttest'} eq 'editmyown') {
2388: $concepttest = 'Manually selected';
1.41.2.6 raeburn 2389: } elsif ($env{'form.concepttest'} eq 'cloning') {
2390: $concepttest = 'Copied from existing test';
1.41.2.1 raeburn 2391: }
1.41.2.6 raeburn 2392: $inst_values .= '<td>'.$concepttest.(' 'x2).'</td>';
2393: }
2394: if (&show_cloneable()) {
2395: $inst_headers .= '<th>'.&mt('Copy From').'</th>';
2396: if ((($env{'form.cloning'}) ||
2397: (($dom eq 'gcitest') && ($env{'form.concepttest'} eq 'cloning'))) &&
2398: ($env{'form.clonecrs'} =~ /^$match_name$/) &&
1.41.2.1 raeburn 2399: ($env{'form.clonedom'} =~ /^$match_domain$/)) {
2400: my $canclone = &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 2401: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
2402: $env{'form.crstype'});
1.41.2.1 raeburn 2403: if ($canclone) {
2404: my %courseenv = &Apache::lonnet::userenvironment($env{'form.clonedom'},
1.15 raeburn 2405: $env{'form.clonecrs'},('description','internal.coursecode'));
1.41.2.1 raeburn 2406: if (keys(%courseenv) > 0) {
1.41.2.6 raeburn 2407: if ($dom eq 'gcitest') {
2408: $inst_headers .= '<th>'.$ctxt{'ros'}.'</th>';
2409: } else {
2410: $inst_headers .= '<th>'.$ctxt{'dsh'}.'</th>';
2411: }
1.41.2.1 raeburn 2412: $inst_values .= '<td>'.$courseenv{'description'}.' ';
2413: my $cloneinst = $courseenv{'internal.coursecode'};
2414: if ($cloneinst ne '') {
2415: $inst_values .= $cloneinst.' '.&mt('in').' '.$env{'form.clonedom'};
2416: } else {
1.41.2.6 raeburn 2417: unless ($dom eq 'gcitest') {
2418: $inst_values .= &mt('from').' '.$env{'form.clonedom'};
2419: }
1.41.2.1 raeburn 2420: }
1.41.2.6 raeburn 2421: $inst_values .= (' 'x2).'</td><td>';
2422: if ($dom eq 'gcitest') {
2423: if ($env{'form.cloneroster'}) {
2424: $inst_values .= &mt('Yes');
2425: } else {
2426: $inst_values .= &mt('No');
2427: }
1.41.2.1 raeburn 2428: } else {
1.41.2.6 raeburn 2429: if ($env{'form.datemode'} eq 'preserve') {
2430: $inst_values .= $ctxt{'prd'};
2431: } elsif ($env{'form.datemode'} eq 'shift') {
2432: $inst_values .= &mt('Shift dates by [_1] days',$env{'form.dateshift'});
2433: } else {
2434: $inst_values .= $ctxt{'ncd'};
2435: }
1.41.2.1 raeburn 2436: }
2437: $inst_values .= '</td>';
2438: } else {
2439: $inst_values .= '<td>'.&mt('Unknown').'</td>';
2440: }
1.15 raeburn 2441: } else {
1.41.2.1 raeburn 2442: $inst_values .= '<td>'.&mt('Not permitted'),'</td>';
1.15 raeburn 2443: }
1.41.2.1 raeburn 2444: } else {
2445: $inst_values .= '<td>'.&mt('None').'</td>';
2446: }
1.4 raeburn 2447: }
2448: $enroll_headers .= '<th>'.&mt('Access Starts').'</th>'.
2449: '<th>'.&mt('Access Ends').'</th>';
1.13 raeburn 2450: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
2451: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessstart).'</td>';
2452: if ($accessend == 0) {
1.4 raeburn 2453: $enroll_values .= '<td>'.&mt('No end date').'</td>';
2454: } else {
1.13 raeburn 2455: $enroll_values .= '<td>'.&Apache::lonlocal::locallocaltime($accessend).'</td>';
1.4 raeburn 2456: }
2457:
2458: my $container = 'Course';
1.41 raeburn 2459: my $ccrole = 'cc';
1.4 raeburn 2460: if ($env{'form.crstype'} eq 'community') {
2461: $container = 'Community';
1.41 raeburn 2462: $ccrole = 'co';
1.4 raeburn 2463: }
2464:
2465: $personnel_headers = '<th>'.&mt('Name').'</th><th>'.&mt('Username:Domain').
2466: '</th><th>'.&mt('Role').'</th><th>'.&mt('LON-CAPA Sections').
2467: '</th>';
1.41 raeburn 2468:
1.4 raeburn 2469: $personnel_values .= '<tr><td>'.$ownername.'</td><td>'.$owner.'</td>'.
1.41 raeburn 2470: '<td>'.&Apache::lonnet::plaintext($ccrole,$container).'</td>'.
1.4 raeburn 2471: '<td>'.&mt('None').'</td></tr>';
2472: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
2473: if ($env{'form.person_'.$i.'_uname'} ne '') {
1.30 raeburn 2474: if (ref($disallowed) eq 'ARRAY') {
2475: next if (grep(/^$i$/,@{$disallowed}));
2476: }
1.31 raeburn 2477: my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
2478: my @allsecs;
2479: foreach my $sec (@officialsecs) {
2480: next unless ($sec =~ /\w/);
2481: next if ($sec =~ /\W/);
2482: next if ($sec eq 'none');
2483: push(@allsecs,$sec);
2484: }
1.14 raeburn 2485: my $newsec = $env{'form.person_'.$i.'_newsec'};
2486: $newsec =~ s/^\s+//;
2487: $newsec =~s/\s+$//;
1.31 raeburn 2488: my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
1.14 raeburn 2489: foreach my $sec (@newsecs) {
1.31 raeburn 2490: next unless ($sec =~ /\w/);
1.14 raeburn 2491: next if ($sec =~ /\W/);
1.31 raeburn 2492: next if ($sec eq 'none');
1.14 raeburn 2493: if ($sec ne '') {
2494: unless (grep(/^\Q$sec\E$/,@allsecs)) {
2495: push(@allsecs,$sec);
2496: }
2497: }
2498: }
1.24 raeburn 2499: my $showsec;
1.14 raeburn 2500: if (@allsecs) {
2501: $showsec = join(', ',@allsecs);
2502: }
1.24 raeburn 2503: if ($showsec eq '') {
2504: $showsec = &mt('None');
2505: }
1.41 raeburn 2506: if ($env{'form.person_'.$i.'_role'} eq $ccrole) {
1.24 raeburn 2507: $showsec = &mt('None');
2508: }
1.28 raeburn 2509: my $role = $env{'form.person_'.$i.'_role'};
1.4 raeburn 2510: $personnel_values .=
1.13 raeburn 2511: '<tr><td>'.$env{'form.person_'.$i.'_firstname'}.' '.
2512: $env{'form.person_'.$i.'_lastname'}.'</td>'.
1.4 raeburn 2513: '<td>'.$env{'form.person_'.$i.'_uname'}.':'.
2514: $env{'form.person_'.$i.'_dom'}.'</td>'.
1.28 raeburn 2515: '<td>'.&Apache::lonnet::plaintext($role,$container).'</td>'.
1.14 raeburn 2516: '<td>'.$showsec.'</td></tr>';
1.4 raeburn 2517: }
2518: }
1.30 raeburn 2519: my $output;
2520: if (ref($disallowed) eq 'ARRAY') {
2521: if (@{$disallowed} > 0) {
2522: if (ref($disallowmsg) eq 'HASH') {
2523: $output = '<p class="LC_warning">'.
2524: &mt('Not all requested personnel could be included.').'<ul>';
2525: foreach my $item (@{$disallowed}) {
2526: $output .= '<li>'.$disallowmsg->{$item}.'</li>';
2527: }
2528: $output .= '</ul></p>';
2529: }
2530: }
2531: }
2532: $output .= '<div>'.&Apache::lonhtmlcommon::start_pick_box().
1.4 raeburn 2533: &Apache::lonhtmlcommon::row_title(&mt('Owner')).
1.6 raeburn 2534: '<table class="LC_innerpickbox"><tr>'.
1.4 raeburn 2535: '<th>'.&mt('Name').'</th>'.
2536: '<th>'.&mt('Username:Domain').'</th>'.
2537: '<th>'.&mt('E-mail address').'</th>'.
2538: '</tr><tr>'."\n".
2539: '<td>'.$ownername.'</td><td>'.$owner.'</td>'.
2540: '<td>'.$owneremail.'</td>'.
2541: '</tr></table>'."\n".
2542: &Apache::lonhtmlcommon::row_closure().
1.5 raeburn 2543: &Apache::lonhtmlcommon::row_title(&mt('Description')).
1.4 raeburn 2544: '<table class="LC_innerpickbox"><tr>'.$inst_headers.'</tr>'."\n".
2545: '<tr>'.$inst_values.'</tr></table>'."\n".
2546: &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2547: &Apache::lonhtmlcommon::row_title($enrollrow_title).
1.4 raeburn 2548: '<table class="LC_innerpickbox"><tr>'.$enroll_headers.'</tr>'."\n".
2549: '<tr>'.$enroll_values.'</tr></table>'."\n".
2550: &Apache::lonhtmlcommon::row_closure();
2551: if ($section_headers ne '') {
2552: $output .= &Apache::lonhtmlcommon::row_title(&mt('Sections')).
2553: '<table class="LC_innerpickbox"><tr>'.$section_headers.'</tr>'."\n".
2554: '<tr>'.$section_values.'</tr></table>'."\n".
2555: &Apache::lonhtmlcommon::row_closure();
2556: }
2557: $output .= &Apache::lonhtmlcommon::row_title(&mt('Personnel')).
2558: '<table class="LC_innerpickbox"><tr>'.$personnel_headers.'</tr>'."\n".
2559: $personnel_values.'</table>'."\n".
2560: &Apache::lonhtmlcommon::row_closure(1).
1.26 raeburn 2561: &Apache::lonhtmlcommon::end_pick_box().'</div>';
1.4 raeburn 2562: return $output;
2563: }
2564:
2565: sub dates_from_form {
2566: my ($startname,$endname) = @_;
2567: my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
2568: my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
1.13 raeburn 2569: if ($endname eq 'accessend') {
1.4 raeburn 2570: if (exists($env{'form.no_end_date'}) ) {
2571: $enddate = 0;
2572: }
2573: }
2574: return ($startdate,$enddate);
1.1 raeburn 2575: }
2576:
2577: sub courseinfo_form {
1.41.2.8! raeburn 2578: my ($dom,$formname,$state,$crstype,$next,$description) = @_;
1.32 raeburn 2579: my %lt = &Apache::lonlocal::texthash(
2580: official => 'You must provide a (brief) course description.',
2581: community => 'You must provide a (brief) community description.'
2582: );
2583: $lt{'unofficial'} = $lt{'official'};
1.15 raeburn 2584: my $js_validate = <<"ENDJS";
2585: <script type="text/javascript">
2586: // <![CDATA['
2587:
2588: function validateForm() {
2589: if ((document.$formname.cdescr.value == "") || (document.$formname.cdescr.value == "undefined")) {
1.32 raeburn 2590: alert('$lt{$crstype}');
1.15 raeburn 2591: return;
2592: }
2593: nextPage(document.$formname,'$next');
2594: }
1.41.2.6 raeburn 2595:
2596: function toggleCloning() {
2597: var willclone;
2598: if (document.$formname.cloning.length > 1) {
2599: for (var i=0; i<document.$formname.cloning.length; i++) {
2600: if (document.$formname.cloning[i].checked) {
2601: willclone = document.$formname.cloning[i].value;
2602: }
2603: }
2604: }
2605: if (willclone == 1) {
2606: document.getElementById('cloneoptions').style.display="block";
2607: } else {
2608: document.getElementById('cloneoptions').style.display="none";
2609: document.$formname.clonecrs.value = '';
2610: }
2611: }
2612:
1.15 raeburn 2613: // ]]
2614: </script>
2615:
2616: ENDJS
1.27 raeburn 2617: my $title = &mt('Brief Course Description');
1.41.2.1 raeburn 2618: my $desctitle = &mt('Description');
2619: if ($dom eq 'gcitest') {
2620: $title = &mt('Concept Test Course Information');
2621: $desctitle = &mt('Concept Test Title');
2622: }
1.41.2.6 raeburn 2623: my $clonetitle = &mt('Copy content and settings from an existing course?');
1.27 raeburn 2624: if ($crstype eq 'community') {
2625: $title = &mt('Brief Community Description');
1.41.2.6 raeburn 2626: $clonetitle = &mt('Copy content and settings from an existing community?');
1.27 raeburn 2627: }
1.41.2.6 raeburn 2628: my $output .= $js_validate."\n".&Apache::lonhtmlcommon::start_pick_box().
1.27 raeburn 2629: &Apache::lonhtmlcommon::row_headline().
1.34 raeburn 2630: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Description').' '.$title.'</h3>'.
1.27 raeburn 2631: &Apache::lonhtmlcommon::row_closure(1).
1.41.2.1 raeburn 2632: &Apache::lonhtmlcommon::row_title($desctitle).
1.36 raeburn 2633: '<input type="text" size="60" name="cdescr" value="'.$description.'" />';
1.41.2.6 raeburn 2634: my $showclone;
2635: if ($dom eq 'gcitest') {
2636: $showclone = &show_cloneable();
2637: } else {
2638: $showclone = 1;
2639: }
1.41.2.1 raeburn 2640: if ($dom eq 'gcitest') {
2641: $output .= &Apache::lonhtmlcommon::row_closure(1).
1.41.2.6 raeburn 2642: &concepttest_form($showclone);
1.41.2.1 raeburn 2643: }
1.13 raeburn 2644: my ($home_server_pick,$numlib) =
2645: &Apache::loncommon::home_server_form_item($dom,'chome',
2646: 'default','hide');
2647: if ($numlib > 1) {
2648: $output .= &Apache::lonhtmlcommon::row_closure().
1.16 raeburn 2649: &Apache::lonhtmlcommon::row_title(&mt('Home Server for Course'));
1.13 raeburn 2650: }
2651: $output .= $home_server_pick.
1.41.2.1 raeburn 2652: &Apache::lonhtmlcommon::row_closure();
1.41.2.6 raeburn 2653: if ($showclone && $dom ne 'gcitest') {
2654: $output .= &Apache::lonhtmlcommon::row_headline().
2655: '<h3>'.&Apache::loncommon::help_open_topic('Course_Request_Clone').' '.$clonetitle.
2656: '<label><input type="radio" name="cloning" value="1" '.
2657: 'onclick="javascript:toggleCloning()" />'.
2658: &mt('Yes').(' 'x2).'</label><label>'.
2659: '<input type="radio" name="cloning" value="0" checked="checked"'.
2660: 'onclick="javascript:toggleCloning()" />'.&mt('No').'</label>'.
2661: '</h3>'.
2662: &Apache::lonhtmlcommon::row_closure(1).
2663: &Apache::lonhtmlcommon::row_headline().
2664: '<div id="cloneoptions" style="display: none" >'.
2665: &Apache::lonhtmlcommon::start_pick_box().
2666: &clone_form($dom,$formname,$crstype).
2667: &Apache::lonhtmlcommon::end_pick_box().'</div>';
2668: }
1.41.2.1 raeburn 2669: if ($dom eq 'gcitest') {
2670: my ($instcode,@codetitles,%cat_titles,%cat_order,@code_order);
2671: my $invalidcrosslist = [];
1.41.2.8! raeburn 2672: $output .= &print_enrollment_menu($formname,$state,$instcode,$dom,
1.41.2.1 raeburn 2673: \@codetitles,\%cat_titles,\%cat_order,
2674: \@code_order,$invalidcrosslist);
2675: }
1.41.2.6 raeburn 2676: $output .= &Apache::lonhtmlcommon::end_pick_box()."\n";
1.1 raeburn 2677: return $output;
2678: }
2679:
1.41.2.1 raeburn 2680: sub concepttest_form {
1.41.2.6 raeburn 2681: my ($showclone) = @_;
2682: my $output = &Apache::lonhtmlcommon::row_title(&mt('Questions included in Concept Test')).
2683: '<label>'.
2684: '<input type="radio" name="concepttest" value="editmyown" checked="checked" /> '.
2685: &mt('Chosen by you from Concept Inventory').
2686: '</label><br />'.
2687: '<label>'.
2688: '<input type="radio" name="concepttest" value="defchosen" /> '.
2689: &mt('Automatically selected by WebCenter').
2690: '</label>';
2691: if ($showclone) {
2692: $output .= '<br /><span class="LC_nobreak"><label>'.
2693: '<input type="radio" name="concepttest" value="cloning" /> '.
2694: &mt('Copied from existing Test: ').
2695: '</label>'.&select_oldtest().(' ' x2).
2696: '<input type="hidden" name="clonedom" value="gcitest" />'.
2697: '<label><input type="checkbox" value="1" name="cloneroster" />'.
2698: &mt('Copy roster').'</label>';
2699: }
2700: return $output;
2701: }
2702:
2703: sub select_oldtest {
2704: my $output = '<select name="clonecrs"><option value="" selected="selected">'.
2705: '</option>';
2706: my %courses = &Apache::loncommon::existing_gcitest_courses('cc');
2707: my %Sortby;
2708: foreach my $course (sort(keys(%courses))) {
2709: next unless (ref($courses{$course}) eq 'HASH');
2710: my $clean_title = $courses{$course}{'description'};
2711: $clean_title =~ s/\W+//g;
2712: if ($clean_title eq '') {
2713: $clean_title = $courses{$course}{'description'};
2714: }
2715: push(@{$Sortby{$clean_title}},$course);
2716: }
2717: my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
2718: foreach my $item (@sorted_courses) {
2719: foreach my $course (@{$Sortby{$item}}) {
2720: my ($cdom,$cnum) = split('_',$course);
2721: if (($cdom eq 'gcitest') && (ref($courses{$course}) eq 'HASH')) {
2722: my $cdesc = $courses{$course}{'description'};
2723: $output .= '<option value="'.$cnum.'">'.$cdesc.'</option>';
2724: }
2725: }
2726: }
2727: $output .= '</select>';
2728: return $output;
1.41.2.1 raeburn 2729: }
2730:
1.1 raeburn 2731: sub clone_form {
2732: my ($dom,$formname,$crstype) = @_;
2733: my $type = 'Course';
2734: if ($crstype eq 'community') {
2735: $type = 'Community';
2736: }
1.35 raeburn 2737: my $cloneform = &Apache::loncommon::select_dom_form($dom,'clonedom').' '.
1.13 raeburn 2738: &Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
1.4 raeburn 2739: my %lt = &clone_text();
1.2 raeburn 2740: my $output .=
2741: &Apache::lonhtmlcommon::row_title($lt{'cid'}).'<label>'.
1.29 raeburn 2742: '<input type="text" size="25" name="clonecrs" value="" />'.
1.35 raeburn 2743: '</label>'.&Apache::lonhtmlcommon::row_closure(1).
2744: &Apache::lonhtmlcommon::row_title($lt{'dmn'}).'<label>'.
1.27 raeburn 2745: $cloneform.'</label>'.&Apache::lonhtmlcommon::row_closure(1).
1.2 raeburn 2746: &Apache::lonhtmlcommon::row_title($lt{'dsh'}).'<label>'.
2747: '<input type="radio" name="datemode" value="delete" /> '.$lt{'ncd'}.
2748: '</label><br /><label>'.
2749: '<input type="radio" name="datemode" value="preserve" /> '.$lt{'prd'}.
2750: '</label><br /><label>'.
2751: '<input type="radio" name="datemode" value="shift" checked="checked" /> '.
2752: $lt{'shd'}.'</label>'.
2753: '<input type="text" size="5" name="dateshift" value="365" />'.
1.27 raeburn 2754: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2755: return $output;
2756: }
2757:
1.16 raeburn 2758: sub clone_text {
1.4 raeburn 2759: return &Apache::lonlocal::texthash(
2760: 'cid' => 'Course ID',
2761: 'dmn' => 'Domain',
2762: 'dsh' => 'Date Shift',
2763: 'ncd' => 'Do not clone date parameters',
1.41.2.6 raeburn 2764: 'prd' => 'Copy date parameters as-is',
1.4 raeburn 2765: 'shd' => 'Shift date parameters by number of days',
1.41.2.6 raeburn 2766: 'ros' => 'Copy Roster',
1.4 raeburn 2767: );
2768: }
2769:
1.1 raeburn 2770: sub coursecode_form {
1.2 raeburn 2771: my ($dom,$context,$codetitles,$cat_titles,$cat_order,$num) = @_;
1.1 raeburn 2772: my $output;
1.2 raeburn 2773: my %rowtitle = (
2774: instcode => 'Course Category',
2775: crosslist => 'Cross Listed Course',
2776: );
1.34 raeburn 2777: my %helpitem = (
2778: instcode => 'Course_Request_Category',
2779: crosslist => 'Course_Request_Crosslist',
2780: );
1.1 raeburn 2781: if ((ref($codetitles) eq 'ARRAY') && (ref($cat_titles) eq 'HASH') &&
2782: (ref($cat_order))) {
1.2 raeburn 2783: my ($sel,$instsec,$lcsec);
2784: $sel = $context;
2785: if ($context eq 'crosslist') {
2786: $sel .= '_'.$num;
2787: $instsec = &mt('Institutional section').'<br />'.
2788: '<input type="text" size="10" name="'.$sel.'_instsec" />';
2789: $lcsec = &mt('LON-CAPA section').'<br />'.
2790: '<input type="text" size="10" name="'.$sel.'_lcsec" />';
2791: }
1.1 raeburn 2792: if (@{$codetitles} > 0) {
2793: my $lastitem = pop(@{$codetitles});
1.2 raeburn 2794: my $lastinput = '<input type="text" size="5" name="'.$sel.'_'. $lastitem.'" />';
1.1 raeburn 2795: if (@{$codetitles} > 0) {
1.34 raeburn 2796: $output = &Apache::lonhtmlcommon::row_title(&Apache::loncommon::help_open_topic($helpitem{$context}).' '.$rowtitle{$context}).
1.2 raeburn 2797: '<table><tr>';
1.1 raeburn 2798: if ($context eq 'crosslist') {
1.2 raeburn 2799: $output .= '<td>'.&mt('Include?').'<br />'.
2800: '<input type="checkbox" name="'.$sel.'" value="1" /></td>';
1.1 raeburn 2801: }
2802: foreach my $title (@{$codetitles}) {
2803: if (ref($cat_order->{$title}) eq 'ARRAY') {
2804: if (@{$cat_order->{$title}} > 0) {
2805: $output .= '<td align="center">'.$title.'<br />'."\n".
2806: '<select name="'.$sel.'_'.$title.'">'."\n".
2807: ' <option value="" selected="selected">'.
2808: &mt('Select').'</option>'."\n";
2809: foreach my $item (@{$cat_order->{$title}}) {
2810: my $longitem = $item;
2811: if (ref($cat_titles->{$title}) eq 'HASH') {
2812: if ($cat_titles->{$title}{$item} ne '') {
2813: $longitem = $cat_titles->{$title}{$item};
2814: }
2815: }
2816: $output .= '<option value="'.$item.'">'.$longitem.
2817: '</option>'."\n";
2818: }
2819: }
2820: $output .= '</select></td>'."\n";
2821: }
2822: }
2823: if ($context eq 'crosslist') {
2824: $output .= '<td align="center">'.$lastitem.'<br />'."\n".
1.2 raeburn 2825: $lastinput.'</td><td align="center">'.$instsec.'</td>'.
2826: '<td align="center">'.$lcsec.'</td></tr></table>';
1.1 raeburn 2827: } else {
2828: $output .= '</tr></table>'.
2829: &Apache::lonhtmlcommon::row_closure().
2830: &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2831: $lastinput;
2832: }
2833: } else {
2834: if ($context eq 'crosslist') {
2835: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
1.2 raeburn 2836: '<table><tr>'.
2837: '<td align="center">'.$lastitem.'<br />'.$lastinput.'</td>'.
2838: '<td align="center">'.$instsec.'</td><td>'.$lcsec.'</td>'.
2839: '</tr></table>';
1.1 raeburn 2840: } else {
2841: $output .= &Apache::lonhtmlcommon::row_title('Course '.$lastitem).
2842: $lastinput;
2843: }
2844: }
1.2 raeburn 2845: $output .= &Apache::lonhtmlcommon::row_closure(1);
2846: push(@$codetitles,$lastitem);
2847: } elsif ($context eq 'crosslist') {
2848: $output .= &Apache::lonhtmlcommon::row_title($rowtitle{$context}).
2849: '<table><tr><td align="center">'.
2850: '<span class="LC_nobreak">'.&mt('Include?').
2851: '<input type="checkbox" name="'.$sel.'" value="1" /></span>'.
2852: '</td><td align="center">'.&mt('Institutional ID').'<br />'.
2853: '<input type="text" size="10" name="'.$sel.'_instsec" />'.
2854: '</td><td align="center">'.$lcsec.'</td></tr></table>'.
2855: &Apache::lonhtmlcommon::row_closure(1);
1.1 raeburn 2856: }
2857: }
2858: return $output;
2859: }
2860:
2861: sub get_course_dom {
2862: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 2863: if ($env{'form.showdom'} ne '') {
2864: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
2865: return $env{'form.showdom'};
2866: }
2867: }
1.1 raeburn 2868: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
1.37 raeburn 2869: my ($types,$typename) = &Apache::loncommon::course_types();
1.19 raeburn 2870: if (ref($types) eq 'ARRAY') {
2871: foreach my $type (@{$types}) {
2872: if (&Apache::lonnet::usertools_access($env{'user.name'},
2873: $env{'user.domain'},$type,
2874: undef,'requestcourses')) {
2875: return $env{'user.domain'};
2876: }
2877: }
2878: my @possible_doms;
2879: foreach my $type (@{$types}) {
2880: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
2881: if ($dom_str ne '') {
2882: my @domains = split(',',$dom_str);
2883: foreach my $entry (@domains) {
2884: my ($extdom,$extopt) = split(':',$entry);
2885: if ($extdom eq $env{'request.role.domain'}) {
2886: return $extdom;
2887: }
2888: unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
2889: push(@possible_doms,$extdom);
2890: }
2891: }
2892: }
2893: }
2894: if (@possible_doms) {
2895: @possible_doms = sort(@possible_doms);
2896: return $possible_doms[0];
2897: }
2898: }
1.1 raeburn 2899: $codedom = $env{'user.domain'};
2900: if ($env{'request.role.domain'} ne '') {
2901: $codedom = $env{'request.role.domain'};
2902: }
2903: }
2904: return $codedom;
2905: }
2906:
2907: sub display_navbuttons {
1.31 raeburn 2908: my ($r,$dom,$formname,$prev,$prevtext,$next,$nexttext,$state,$other,$othertext) = @_;
1.1 raeburn 2909: $r->print('<div class="LC_navbuttons">');
2910: if ($prev) {
1.16 raeburn 2911: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
1.31 raeburn 2912: 'onclick="javascript:backPage('."document.$formname,'$prev'".')"/>'.
1.16 raeburn 2913: (' 'x3));
1.1 raeburn 2914: } elsif ($prevtext) {
1.16 raeburn 2915: $r->print('<input type="button" name="previous" value = "'.$prevtext.'" '.
2916: 'onclick="javascript:history.back()"/>'.(' 'x3));
2917: }
2918: if ($state eq 'details') {
2919: $r->print(' <input type="button" name="other" value="'.$othertext.'" '.
1.31 raeburn 2920: 'onclick="javascript:nextPage('."document.$formname,'$other'".
1.16 raeburn 2921: ')" />');
1.1 raeburn 2922: }
1.31 raeburn 2923: my $gotnext;
1.15 raeburn 2924: if ($state eq 'courseinfo') {
1.16 raeburn 2925: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2926: 'onclick="javascript:validateForm();" />');
1.31 raeburn 2927: $gotnext = 1;
2928: } elsif ($state eq 'enrollment') {
2929: if (($env{'form.crstype'} eq 'official') &&
2930: (&Apache::lonnet::auto_run('',$dom))) {
2931: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2932: 'onclick="javascript:validateEnrollSections('."document.$formname,'$next'".');" />');
2933: $gotnext = 1;
2934: }
2935: } elsif ($state eq 'personnel') {
2936: if ($env{'form.persontotal'} > 0) {
2937: $r->print('<input type="button" name="next" value="'.$nexttext.'" '.
2938: 'onclick="javascript:validatePersonnelSections('."document.$formname,'$next'".');" />');
2939: $gotnext = 1;
2940: }
2941: }
2942: unless ($gotnext) {
2943: if ($next) {
2944: $r->print('
2945: <input type="button" name="next" value="'.$nexttext.'" '.
2946: 'onclick="javascript:nextPage('."document.$formname,'$next'".')" />');
2947: }
1.1 raeburn 2948: }
2949: $r->print('</div>');
2950: }
2951:
2952: sub print_request_outcome {
1.41.2.8! raeburn 2953: my ($r,$dom,$codetitles,$code_order,$formname) = @_;
1.13 raeburn 2954: my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
1.10 raeburn 2955: %sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
1.24 raeburn 2956: my $sectotal = $env{'form.sectotal'};
2957: my $crosslisttotal = 0;
1.10 raeburn 2958: $cnum = $env{'form.cnum'};
1.8 raeburn 2959: unless ($cnum =~ /^$match_courseid$/) {
2960: $output = &mt('Invalid LON-CAPA course number for the new course')."\n";
2961: return $output;
2962: }
1.11 raeburn 2963:
1.10 raeburn 2964: %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom);
1.9 raeburn 2965: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
2966: if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
2967: $req_notifylist = $domconfig{'requestcourses'}{'notify'}{'approval'};
2968: }
2969: }
1.10 raeburn 2970: $now = time;
2971: $crstype = $env{'form.crstype'};
1.41 raeburn 2972: my $ccrole = 'cc';
2973: if ($crstype eq 'community') {
2974: $ccrole = 'co';
2975: }
1.17 raeburn 2976: my @instsections;
1.8 raeburn 2977: if ($crstype eq 'official') {
2978: if (&Apache::lonnet::auto_run('',$dom)) {
1.13 raeburn 2979: ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
1.8 raeburn 2980: }
1.10 raeburn 2981: for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
2982: if ($env{'form.sec_'.$i}) {
2983: if ($env{'form.secnum_'.$i} ne '') {
1.17 raeburn 2984: my $sec = $env{'form.secnum_'.$i};
2985: $sections{$i}{'inst'} = $sec;
2986: if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
2987: push(@instsections,$sec);
2988: }
1.13 raeburn 2989: $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
1.41.2.7 raeburn 2990: $sections{$i}{'loncapa'} =~ s/\W//g;
2991: if ($sections{$i}{'loncapa'} eq 'none') {
2992: $sections{$i}{'loncapa'} = '';
2993: }
1.10 raeburn 2994: }
2995: }
2996: }
2997: for (my $i=0; $i<$env{'form.crosslisttotal'}; $i++) {
2998: if ($env{'form.crosslist_'.$i}) {
2999: my $xlistinfo = '';
3000: if (ref($code_order) eq 'ARRAY') {
3001: if (@{$code_order} > 0) {
3002: foreach my $item (@{$code_order}) {
3003: $xlistinfo .= $env{'form.crosslist_'.$i.'_'.$item};
3004: }
3005: }
3006: }
1.22 raeburn 3007: $crosslistings{$i}{'instcode'} = $xlistinfo;
1.24 raeburn 3008: if ($xlistinfo ne '') {
3009: $crosslisttotal ++;
3010: }
1.22 raeburn 3011: $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
1.13 raeburn 3012: $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
1.10 raeburn 3013: }
3014: }
1.14 raeburn 3015: } else {
3016: $enrollstart = '';
3017: $enrollend = '';
1.10 raeburn 3018: }
3019: for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
3020: my $uname = $env{'form.person_'.$i.'_uname'};
1.16 raeburn 3021: my $udom = $env{'form.person_'.$i.'_dom'};
1.10 raeburn 3022: if (($uname =~ /^$match_username$/) && ($udom =~ /^$match_domain$/)) {
3023: if (&Apache::lonnet::domain($udom) ne '') {
1.13 raeburn 3024: unless (ref($personnel{$uname.':'.$udom}) eq 'HASH') {
3025: $personnel{$uname.':'.$udom} = {
3026: firstname => $env{'form.person_'.$i.'_firstname'},
3027: lastname => $env{'form.person_'.$i.'_lastname'},
3028: emailaddr => $env{'form.person_'.$i.'_emailaddr'},
3029: };
3030: }
3031: my $role = $env{'form.person_'.$i.'_role'};
3032: unless ($role eq '') {
1.16 raeburn 3033: if (ref($personnel{$uname.':'.$udom}{'roles'}) eq 'ARRAY') {
1.13 raeburn 3034: my @curr_roles = @{$personnel{$uname.':'.$udom}{'roles'}};
3035: unless (grep(/^\Q$role\E$/,@curr_roles)) {
3036: push(@{$personnel{$uname.':'.$udom}{'roles'}},$role);
3037: }
3038: } else {
3039: @{$personnel{$uname.':'.$udom}{'roles'}} = ($role);
3040: }
1.41 raeburn 3041: if ($role eq $ccrole) {
1.13 raeburn 3042: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
3043: } else {
1.14 raeburn 3044: my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
1.31 raeburn 3045: my @allsecs;
3046: foreach my $sec (@currsec) {
3047: next unless ($sec =~ /\w/);
3048: next if ($sec =~ /\W/);
3049: next if ($sec eq 'none');
3050: push(@allsecs,$sec);
3051: }
1.14 raeburn 3052: my $newsec = $env{'form.person_'.$i.'_newsec'};
3053: $newsec =~ s/^\s+//;
3054: $newsec =~s/\s+$//;
3055: my @newsecs = split(/[\s,;]+/,$newsec);
3056: foreach my $sec (@newsecs) {
3057: next if ($sec =~ /\W/);
1.31 raeburn 3058: next if ($sec eq 'none');
1.14 raeburn 3059: if ($sec ne '') {
1.31 raeburn 3060: unless (grep(/^\Q$sec\E$/,@allsecs)) {
3061: push(@allsecs,$sec);
1.13 raeburn 3062: }
3063: }
3064: }
1.31 raeburn 3065: @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
1.13 raeburn 3066: }
3067: }
1.10 raeburn 3068: } else {
3069: push(@missingdom,$uname.':'.$udom);
3070: }
3071: } else {
3072: push(@baduname,$uname.':'.$udom);
3073: }
1.8 raeburn 3074: }
1.13 raeburn 3075: my ($accessstart,$accessend) = &dates_from_form('accessstart','accessend');
1.14 raeburn 3076: my $autodrops = 0;
3077: if ($env{'form.autodrops'}) {
3078: $autodrops = $env{'form.autodrops'};
3079: }
3080: my $autoadds = 0;
3081: if ($env{'form.autoadds'}) {
3082: $autodrops = $env{'form.autoadds'};
3083: }
3084: if ($env{'form.autoadds'}) {
3085: $autodrops = $env{'form.autoadds'};
3086: }
3087: my $instcode = '';
3088: if (exists($env{'form.instcode'})) {
3089: $instcode = $env{'form.instcode'};
3090: }
1.15 raeburn 3091: my $clonecrs = '';
3092: my $clonedom = '';
1.41.2.6 raeburn 3093: if ((($env{'form.cloning'}) ||
3094: (($dom eq 'gcitest') && ($env{'form.concepttest'} eq 'cloning'))) &&
3095: ($env{'form.clonecrs'} =~ /^($match_courseid)$/) &&
1.15 raeburn 3096: ($env{'form.clonedom'} =~ /^($match_domain)$/)) {
1.41.2.6 raeburn 3097: if ($dom eq 'gcitest') {
3098: $env{'form.clonedom'} = 'gcitest';
3099: }
1.16 raeburn 3100: my $clonehome = &Apache::lonnet::homeserver($env{'form.clonecrs'},
3101: $env{'form.clonedom'});
1.41.2.6 raeburn 3102: if ($clonehome ne 'no_host') {
1.16 raeburn 3103: my $canclone =
3104: &Apache::loncoursequeueadmin::can_clone_course($env{'user.name'},
1.39 raeburn 3105: $env{'user.domain'},$env{'form.clonecrs'},$env{'form.clonedom'},
3106: $crstype);
1.15 raeburn 3107: if ($canclone) {
3108: $clonecrs = $env{'form.clonecrs'};
3109: $clonedom = $env{'form.clonedom'};
3110: }
3111: }
3112: }
1.8 raeburn 3113: my $details = {
1.10 raeburn 3114: owner => $env{'user.name'},
3115: domain => $env{'user.domain'},
3116: cdom => $dom,
1.11 raeburn 3117: cnum => $cnum,
1.13 raeburn 3118: coursehome => $env{'form.chome'},
3119: cdescr => $env{'form.cdescr'},
1.10 raeburn 3120: crstype => $env{'form.crstype'},
1.14 raeburn 3121: instcode => $instcode,
1.15 raeburn 3122: clonedom => $clonedom,
3123: clonecrs => $clonecrs,
1.10 raeburn 3124: datemode => $env{'form.datemode'},
1.14 raeburn 3125: dateshift => $env{'form.dateshift'},
3126: sectotal => $sectotal,
1.10 raeburn 3127: sections => \%sections,
1.14 raeburn 3128: crosslisttotal => $crosslisttotal,
1.13 raeburn 3129: crosslists => \%crosslistings,
1.14 raeburn 3130: autoadds => $autoadds,
3131: autodrops => $autodrops,
1.13 raeburn 3132: enrollstart => $enrollstart,
3133: enrollend => $enrollend,
3134: accessstart => $accessstart,
3135: accessend => $accessend,
1.10 raeburn 3136: personnel => \%personnel,
1.8 raeburn 3137: };
1.41.2.2 raeburn 3138: if ($dom eq 'gcitest') {
3139: if ($env{'form.concepttest'} eq 'editmyown') {
3140: $details->{'firstres'} = 'nav';
3141: } else {
3142: $details->{'firstres'} = 'blank';
3143: }
1.41.2.6 raeburn 3144: if ($env{'form.concepttest'} eq 'cloning') {
3145: if (($clonecrs) && ($clonedom eq 'gcitest')) {
3146: $details->{'cloneroster'} = $env{'form.cloneroster'};
3147: } else {
3148: $details->{'clonedom'} = 'gci';
3149: $details->{'clonecrs'} = '8v226795a882b4bcagcil1';
3150: }
3151: } else {
3152: $details->{'clonedom'} = 'gci';
3153: $details->{'clonecrs'} = '8v226795a882b4bcagcil1';
3154: }
1.41.2.2 raeburn 3155: $details->{'datemode'} = 'delete';
3156: }
1.41.2.8! raeburn 3157: my (@inststatuses,$storeresult,$creationresult,$donedisplay);
1.9 raeburn 3158: my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
1.8 raeburn 3159: if ($val eq '') {
3160: if ($crstype eq 'official') {
1.19 raeburn 3161: $output = &mt('You are not permitted to request creation of official courses.');
1.8 raeburn 3162: } elsif ($crstype eq 'unofficial') {
1.19 raeburn 3163: $output = &mt('You are not permitted to request creation of unofficial courses.');
1.8 raeburn 3164: } elsif ($crstype eq 'community') {
3165: $output = &mt('You are not permitted to request creation of communities');
3166: } else {
3167: $output = &mt('Unrecognized course type: [_1]',$crstype);
3168: }
1.27 raeburn 3169: $storeresult = 'notpermitted';
1.8 raeburn 3170: } else {
1.14 raeburn 3171: my ($disposition,$message,$reqstatus);
1.8 raeburn 3172: my %reqhash = (
1.14 raeburn 3173: reqtime => $now,
1.10 raeburn 3174: crstype => $crstype,
3175: details => $details,
1.8 raeburn 3176: );
3177: my $requestkey = $dom.'_'.$cnum;
1.17 raeburn 3178: my $validationerror;
1.10 raeburn 3179: if ($val eq 'autolimit=') {
3180: $disposition = 'process';
3181: } elsif ($val =~ /^autolimit=(\d+)$/) {
3182: my $limit = $1;
1.8 raeburn 3183: $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
1.10 raeburn 3184: $dom,$crstype,$limit,\$message);
1.8 raeburn 3185: } elsif ($val eq 'validate') {
1.21 raeburn 3186: my ($inststatuslist,$validationchk,$validation);
1.17 raeburn 3187: if (@inststatuses > 0) {
3188: $inststatuslist = join(',',@inststatuses);
3189: }
3190: my $instseclist;
3191: if (@instsections > 0) {
3192: $instseclist = join(',',@instsections);
3193: }
1.21 raeburn 3194: $validationchk =
3195: &Apache::lonnet::auto_courserequest_validation($dom,
3196: $env{'user.name'}.':'.$env{'user.domain'},$crstype,
3197: $inststatuslist,$instcode,$instseclist);
3198: if ($validationchk =~ /:/) {
3199: ($validation,$message) = split(':',$validationchk);
3200: } else {
3201: $validation = $validationchk;
3202: }
3203: if ($validation =~ /^error(.*)$/) {
1.17 raeburn 3204: $disposition = 'approval';
3205: $validationerror = $1;
1.23 raeburn 3206: } else {
3207: $disposition = $validation;
1.17 raeburn 3208: }
1.8 raeburn 3209: } else {
3210: $disposition = 'approval';
3211: }
1.14 raeburn 3212: $reqhash{'disposition'} = $disposition;
3213: $reqstatus = $disposition;
1.16 raeburn 3214: my ($modified,$queued);
1.8 raeburn 3215: if ($disposition eq 'rejected') {
1.40 raeburn 3216: if ($crstype eq 'community') {
3217: $output = &mt('Your community request was rejected.');
3218: } else {
3219: $output = &mt('Your course request was rejected.');
3220: }
1.8 raeburn 3221: if ($message) {
3222: $output .= '<div class="LC_warning">'.$message.'</div>';
3223: }
1.27 raeburn 3224: $storeresult = 'rejected';
1.8 raeburn 3225: } elsif ($disposition eq 'process') {
1.14 raeburn 3226: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
3227: my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
1.8 raeburn 3228: my $type = 'Course';
3229: if ($crstype eq 'community') {
3230: $type = 'Community';
3231: }
1.41 raeburn 3232: my @roles = &Apache::lonuserutils::roles_by_context('course','',$type);
1.8 raeburn 3233: foreach my $role (@roles) {
3234: $longroles{$role}=&Apache::lonnet::plaintext($role,$type);
3235: }
1.14 raeburn 3236: my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,
3237: 'autocreate',$details,\$logmsg,\$newusermsg,\$addresult,
3238: \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
3239: if ($result eq 'created') {
1.8 raeburn 3240: $disposition = 'created';
1.14 raeburn 3241: $reqstatus = 'created';
1.28 raeburn 3242: my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
3243: \%longroles);
1.40 raeburn 3244: if ($crstype eq 'community') {
3245: $output = '<p>'.&mt('Your community request has been processed and the community has been created.');
3246: } else {
3247: $output = '<p>'.&mt('Your course request has been processed and the course has been created.');
3248: }
1.41.2.2 raeburn 3249: if ($dom eq 'gcitest') {
3250: my $caller = 'requestcrs';
3251: &acquire_cc_role($dom,$cnum,'cc./'.$dom.'/'.$cnum);
3252: my %parmresult =
3253: &store_crsparms($dom,$cnum,$now,$accessstart,$accessend);
3254: &Apache::londocsgci::setdefaults();
1.41.2.5 raeburn 3255: my %crsenvhash = (
3256: suppress_tries => 'yes',
3257: );
3258: my $putresult = &Apache::lonnet::put('environment',\%crsenvhash,$dom,$cnum);
1.41.2.6 raeburn 3259: if ($env{'form.concepttest'} eq 'cloning') {
3260: &Apache::lonuserstate::readmap($dom.'/'.$cnum);
3261: if (($clonecrs) && ($clonedom eq 'gcitest')) {
3262: my $cloneid = $clonedom.'/'.$clonecrs;
3263: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
3264: my $oldcdesc = $clonedesc{'description'};
3265: $output .= '<br />'.&mt('A concept test has been copied from your existing test: [_1].','<b>'.$oldcdesc.'</b>').'</p>';
3266: if ($env{'form.cloneroster'}) {
3267: $output .= '<br />'.&mt('You requested copying of the old student roster to the new course.');
3268: if ($logmsg =~ /\Q\0\E/) {
3269: my @logging = split("\0",$logmsg);
3270: if (@logging) {
3271: $output .= '<p>'.$logging[-1].'</p>';
3272: }
3273: }
3274: $output .= '<ul>'.
3275: '<li>'.&mt('Access starts:').' '.
3276: &Apache::lonlocal::locallocaltime($accessstart).'</li>'.
3277: '<li>'.&mt('Access ends:').' '.&Apache::lonlocal::locallocaltime($accessend).'</li>'.
1.41.2.8! raeburn 3278: '</ul><br />';
1.41.2.6 raeburn 3279: $r->print($output);
3280: $output = '';
1.41.2.8! raeburn 3281: $donedisplay = 1;
1.41.2.6 raeburn 3282: } else {
1.41.2.8! raeburn 3283: &roster_upload_form($r,$output,$formname);
1.41.2.6 raeburn 3284: $output = '';
3285: }
3286: } else {
3287: $output .= '</p>';
1.41.2.8! raeburn 3288: &roster_upload_form($r,$output,$formname);
1.41.2.6 raeburn 3289: $output = '';
3290: }
3291: } elsif ($env{'form.concepttest'} eq 'defchosen') {
1.41.2.2 raeburn 3292: $output .= '<br />';
3293: my $error = &Apache::londocsgci::store($caller,$dom,$cnum);
3294: if ($error) {
3295: $output .= '<span class="LC_error">'.
3296: &mt('An error occurred saving an auto-generated concept test: [_1].',$error).
3297: '</span>';
3298: } else {
3299: &Apache::lonuserstate::readmap($dom.'/'.$cnum);
3300: $output .= &mt('A concept test has also been generated.');
3301: }
1.41.2.6 raeburn 3302: $output .= '</p>';
1.41.2.8! raeburn 3303: &roster_upload_form($r,$output,$formname);
1.41.2.2 raeburn 3304: $output = '';
3305: } else {
1.41.2.8! raeburn 3306: $output .= '</p></form><br />'.&mt('The next step is to chose which questions are to be included in the Concept Test.').'<br /></p>';
1.41.2.2 raeburn 3307: $r->print($output);
3308: &Apache::londocsgci::editor($r,'requestcrs',$dom,$cnum);
3309: $output = '';
3310: }
3311: } else {
3312: $output .= '<br />'.$role_result.'</p>';
3313: }
1.27 raeburn 3314: $creationresult = 'created';
1.8 raeburn 3315: } else {
1.40 raeburn 3316: $output = '<span class="LC_error">';
3317: if ($crstype eq 'community') {
3318: $output .= &mt('An error occurred when processing your community request.');
3319: } else {
3320: $output .= &mt('An error occurred when processing your course request.');
3321: }
3322: $output .= '<br />'.
3323: &mt('You may want to review the request details and submit the request again.').
1.14 raeburn 3324: '</span>';
1.27 raeburn 3325: $creationresult = 'error';
1.8 raeburn 3326: }
3327: } else {
3328: my $requestid = $cnum.'_'.$disposition;
3329: my $request = {
3330: $requestid => {
3331: timestamp => $now,
3332: crstype => $crstype,
3333: ownername => $env{'user.name'},
3334: ownerdom => $env{'user.domain'},
1.13 raeburn 3335: description => $env{'form.cdescr'},
1.8 raeburn 3336: },
3337: };
1.16 raeburn 3338: my $statuskey = 'status:'.$dom.':'.$cnum;
3339: my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
3340: $env{'user.domain'},$env{'user.name'});
1.17 raeburn 3341: if ($userreqhash{$statuskey} ne '') {
1.16 raeburn 3342: $modified = 1;
1.25 raeburn 3343: my $uname = &Apache::lonnet::get_domainconfiguser($dom);
3344: my %queuehash = &Apache::lonnet::get('courserequestqueue',
3345: [$cnum.'_approval',
3346: $cnum.'_pending'],$dom,$uname);
1.17 raeburn 3347: if (($queuehash{$cnum.'_approval'} ne '') ||
3348: ($queuehash{$cnum.'_pending'} ne '')) {
1.16 raeburn 3349: $queued = 1;
3350: }
3351: }
3352: unless ($queued) {
3353: my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,
3354: $dom);
3355: if ($putresult eq 'ok') {
1.40 raeburn 3356: if ($crstype eq 'community') {
3357: $output .= &mt('Your community request has been recorded.');
3358: } else {
3359: $output .= &mt('Your course request has been recorded.')
3360: }
3361: $output .= '<br />'.
1.16 raeburn 3362: ¬ification_information($disposition,$req_notifylist,
3363: $cnum,$now);
1.8 raeburn 3364: } else {
1.16 raeburn 3365: $reqstatus = 'domainerror';
3366: $reqhash{'disposition'} = $disposition;
3367: my $warning = &mt('An error occurred saving your request in the pending requests queue.');
3368: $output = '<span class"LC_warning">'.$warning.'</span><br />';
1.8 raeburn 3369: }
3370: }
3371: }
1.27 raeburn 3372: my ($statusresult);
1.10 raeburn 3373: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
3374: $storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
3375: 'courserequests');
1.14 raeburn 3376: if ($storeresult eq 'ok') {
3377: my %status = (
3378: 'status:'.$dom.':'.$cnum => $reqstatus,
3379: );
1.27 raeburn 3380: $statusresult = &Apache::lonnet::put('courserequests',\%status);
1.14 raeburn 3381: }
1.10 raeburn 3382: } else {
3383: $storeresult = 'error: invalid requestkey format';
3384: }
1.8 raeburn 3385: if ($storeresult ne 'ok') {
1.13 raeburn 3386: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).'</span><br />';
3387: &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
1.14 raeburn 3388: } elsif ($statusresult ne 'ok') {
1.28 raeburn 3389: $output .= '<span class="LC_warning">'.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).'</span><br />';
1.14 raeburn 3390: &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
1.8 raeburn 3391: }
1.16 raeburn 3392: if ($modified && $queued && $storeresult eq 'ok') {
1.40 raeburn 3393: if ($crstype eq 'community') {
3394: $output .= '<p>'.&mt('Your community request has been updated').'</p>';
3395: } else {
3396: $output .= '<p>'.&mt('Your course request has been updated').'</p>';
3397: }
3398: $output .= ¬ification_information($disposition,$req_notifylist,$cnum,$now);
1.16 raeburn 3399: }
1.17 raeburn 3400: if ($validationerror ne '') {
1.19 raeburn 3401: $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
1.17 raeburn 3402: }
1.16 raeburn 3403: }
1.27 raeburn 3404: if ($creationresult ne '') {
1.41.2.8! raeburn 3405: if ($donedisplay) {
! 3406: $r->print('<br />'.&done_display());
! 3407: }
1.27 raeburn 3408: return ($creationresult,$output);
3409: } else {
3410: return ($storeresult,$output);
3411: }
1.16 raeburn 3412: }
3413:
1.28 raeburn 3414: sub update_requestors_roles {
3415: my ($dom,$cnum,$crstype,$details,$longroles) = @_;
3416: my $now = time;
3417: my ($active,$future,$numactive,$numfuture,$output);
3418: my $owner = $env{'user.name'}.':'.$env{'user.domain'};
3419: if (ref($details) eq 'HASH') {
3420: if (ref($details->{'personnel'}) eq 'HASH') {
1.41 raeburn 3421: my $ccrole = 'cc';
3422: if ($crstype eq 'community') {
3423: $ccrole = 'co';
3424: }
1.35 raeburn 3425: unless (ref($details->{'personnel'}{$owner}) eq 'HASH') {
3426: $details->{'personnel'}{$owner} = {
1.41 raeburn 3427: 'roles' => [$ccrole],
3428: $ccrole => { 'usec' => [] },
1.35 raeburn 3429: };
3430: }
3431: my @roles;
3432: if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
3433: @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
1.41 raeburn 3434: unless (grep(/^\Q$ccrole\E$/,@roles)) {
3435: push(@roles,$ccrole);
1.35 raeburn 3436: }
3437: } else {
1.41 raeburn 3438: @roles = ($ccrole);
1.35 raeburn 3439: }
3440: foreach my $role (@roles) {
1.41.2.3 raeburn 3441: my $refresh=$env{'user.refresh.time'};
3442: if ($refresh eq '') {
3443: $refresh = $env{'user.login.time'};
3444: }
3445: if ($refresh eq '') {
3446: $refresh = $now;
3447: }
3448: my $start = $refresh-1;
1.35 raeburn 3449: my $end = '0';
3450: if ($role eq 'st') {
3451: if ($details->{'accessstart'} ne '') {
3452: $start = $details->{'accessstart'};
3453: }
3454: if ($details->{'accessend'} ne '') {
3455: $end = $details->{'accessend'};
3456: }
3457: }
3458: my @usecs;
1.41 raeburn 3459: if ($role ne $ccrole) {
1.35 raeburn 3460: if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
3461: @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
3462: }
3463: }
3464: if ($role eq 'st') {
3465: if (@usecs > 1) {
3466: my $firstsec = $usecs[0];
3467: @usecs = ($firstsec);
3468: }
3469: }
3470: if (@usecs == 0) {
3471: push(@usecs,'');
3472: }
3473: foreach my $usec (@usecs) {
3474: my (%userroles,%newrole,%newgroups,$spec,$area);
3475: my $area = '/'.$dom.'/'.$cnum;
3476: my $spec = $role.'.'.$area;
3477: if ($usec ne '') {
3478: $spec .= '/'.$usec;
3479: $area .= '/'.$usec;
3480: }
3481: if ($role =~ /^cr\//) {
3482: &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
3483: $cnum,$spec,$area);
3484: } else {
3485: &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
3486: $spec,$cnum,$area);
1.28 raeburn 3487: }
1.35 raeburn 3488: &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
3489: \%newgroups);
3490: $userroles{'user.role.'.$spec} = $start.'.'.$end;
3491: &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
3492: if (($end == 0) || ($end > $now)) {
3493: my $showrole = $role;
1.28 raeburn 3494: if ($role =~ /^cr\//) {
1.35 raeburn 3495: $showrole = &Apache::lonnet::plaintext($role,$crstype);
3496: } elsif (ref($longroles) eq 'HASH') {
3497: if ($longroles->{$role} ne '') {
3498: $showrole = $longroles->{$role};
3499: }
1.28 raeburn 3500: }
1.35 raeburn 3501: if ($start <= $now) {
3502: $active .= '<li><a href="/adm/roles?selectrole=1&'.
3503: $spec.'=1">'.$showrole;
3504: if ($usec ne '') {
3505: $active .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3506: }
1.35 raeburn 3507: $active .= '</a></li>';
3508: $numactive ++;
3509: } else {
3510: $future .= '<li>'.$showrole;
3511: if ($usec ne '') {
3512: $future .= ' - '.&mt('section:').' '.$usec;
1.28 raeburn 3513: }
1.35 raeburn 3514: $future .= '</li>';
3515: $numfuture ++;
1.28 raeburn 3516: }
3517: }
3518: }
3519: }
3520: }
3521: }
3522: if ($active) {
3523: if ($numactive == 1) {
1.41 raeburn 3524: if ($crstype eq 'Community') {
3525: $output = &mt('Use the following link to enter the community:');
3526: } else {
3527: $output = &mt('Use the following link to enter the course:');
3528: }
1.28 raeburn 3529: } else {
1.41 raeburn 3530: if ($crstype eq 'Community') {
3531: $output = &mt('Use the following links to your new roles to enter the community:');
3532: } else {
3533: $output = &mt('Use the following links to your new roles to enter the course:');
3534: }
1.28 raeburn 3535: }
3536: $output .= ' <ul>'.$active.'</ul><br />';
3537: }
3538: if ($future) {
1.41 raeburn 3539: if ($crstype eq 'Community') {
3540: $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'}))
3541: } else {
3542: $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'}));
3543: }
3544: $output .= ' <ul>'.$future.'</ul>';
1.28 raeburn 3545: }
3546: return $output;
3547: }
3548:
1.41.2.2 raeburn 3549: sub acquire_cc_role {
3550: my ($cdom,$cnum,$trolecode,$csec) = @_;
3551: my %coursegroups = &Apache::lonnet::get_active_groups(
3552: $env{'user.domain'},$env{'user.name'},$cdom, $cnum);
3553: my $cgrps = join(':',keys(%coursegroups));
3554: if ($env{'environment.recentroles'}) {
3555: my %frozen_roles =
3556: &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
3557: &Apache::lonhtmlcommon::store_recent('roles',$trolecode,' ',
3558: $frozen_roles{$trolecode});
3559: }
3560:
3561: &Apache::lonnet::appenv({"request.course.id" => '',
3562: "request.course.fn" => '',
3563: "request.course.uri" => '',
3564: "request.course.sec" => '',
3565: "request.role" => 'cm',
3566: "request.role.adv" => $env{'user.adv'},
3567: "request.role.domain" => $env{'user.domain'}});
3568:
3569: &Apache::lonnet::log($env{'user.domain'},
3570: $env{'user.name'},
3571: $env{'user.home'},
3572: "Role ".$trolecode);
3573:
3574: &Apache::lonnet::appenv(
3575: {'request.role' => $trolecode,
3576: 'request.role.domain' => $cdom,
3577: 'request.course.sec' => $csec,
3578: 'request.course.groups' => $cgrps});
3579: my ($furl,$ferr) = &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3580: my $tadv;
3581: if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
3582: &Apache::lonnet::appenv({'request.role.adv'=>$tadv});
3583: return;
3584: }
3585:
1.41.2.1 raeburn 3586: sub store_crsparms {
3587: my ($cdom,$cnum,$now,$accessstart,$accessend) = @_;
3588: my $topsymb = '___0___uploaded/'.$cdom.'/'.$cnum.'/default.sequence';
3589: my %crsparms = (
3590: buttonshide => {
3591: value => 'yes',
3592: type => 'string_yesno',
3593: },
3594: opendate => {
3595: value => $accessstart,
3596: type => 'date_start',
3597: },
3598: duedate => {
3599: value => $accessend,
3600: type => 'date_end',
3601: },
3602: problemstatus => {
1.41.2.4 raeburn 3603: value => 'no',
1.41.2.1 raeburn 3604: type => 'string_problemstatus',
3605: },
3606: maxtries => {
3607: value => '1',
3608: type => 'intpos',
3609: },
3610: discussend => {
3611: value => $now,
3612: type => 'date_end',
3613: },
3614: discusshide => {
3615: value => 'yes',
3616: type => 'string_yesno',
3617: }
3618: );
3619: my %parmresult;
3620: foreach my $item (keys(%crsparms)) {
3621: $parmresult{$item} =
3622: &Apache::lonparmset::storeparm_by_symb($topsymb,
3623: '0_'.$item,14,$crsparms{$item}{'value'},
3624: $crsparms{$item}{'type'},undef,$cdom);
3625: }
3626: return %parmresult;
3627: }
3628:
1.41.2.6 raeburn 3629: sub roster_upload_form {
1.41.2.8! raeburn 3630: my ($r,$output,$formname,$titletext) = @_;
! 3631: my $title = &mt('Request Processed');
! 3632: if ($titletext ne '') {
! 3633: $title = $titletext;
! 3634: }
! 3635: $r->print(<<"ENDJS");
! 3636: <script type="text/javascript">
! 3637: // <![CDATA['
! 3638:
! 3639: function toggleRosterUpload() {
! 3640: var willupload;
! 3641: if (document.$formname.roster.length > 1) {
! 3642: for (var i=0; i<document.$formname.roster.length; i++) {
! 3643: if (document.$formname.roster[i].checked) {
! 3644: willupload = document.$formname.roster[i].value;
! 3645: }
! 3646: }
! 3647: }
! 3648: if (willupload == 1) {
! 3649: document.getElementById('rosterupload').style.display="block";
! 3650: document.getElementById('norosterupload').style.display="none";
! 3651: } else {
! 3652: document.getElementById('rosterupload').style.display="none";
! 3653: document.getElementById('norosterupload').style.display="block";
! 3654: }
! 3655: return;
! 3656: }
! 3657: // ]]
! 3658: </script>
! 3659:
! 3660: ENDJS
! 3661: $r->print('<h3>'.$title.'</h3>'.$output.
! 3662: '<h4>'.&mt('Course roster file upload').'</h4>');
1.41.2.6 raeburn 3663: $r->print('<p>'.&mt('If you have a text file available containing student e-mail addresses and initial passwords, you may upload it now.').'<br />'.
1.41.2.8! raeburn 3664: &mt('You may also enroll students later with the [_1]"Enrollment/Activity"[_2] utility in the management toolbar.','<i>','</i>').'</p>'.
! 3665: &mt('Upload roster file now?').' '.
! 3666: '<label><input type="radio" name="roster" value="1" '.
! 3667: 'onclick="javascript:toggleRosterUpload()" />'.
! 3668: &mt('Yes').(' 'x2).'</label><label>'.
! 3669: '<input type="radio" name="roster" value="0" checked="checked"'.
! 3670: 'onclick="javascript:toggleRosterUpload()" />'.&mt('No').'</label><br />'.
! 3671: '<div id="norosterupload"><input type="submit" value="'.&mt('Next').'" name="norostersub" />'.
! 3672: '<input type="hidden" name="reqaction" value="new" />'.
! 3673: '<input type="hidden" name="state" value="done" /></div></form>'.
! 3674: '<div id="rosterupload" style="display: none"><form name="studentform" method="post" enctype="multipart/form-data" '.
1.41.2.6 raeburn 3675: ' action="/adm/createuser">'."\n");
1.41.2.8! raeburn 3676: &Apache::lonuserutils::print_first_users_upload_form($r,'course','noheader','requestcrs');
! 3677: $r->print('<input type="hidden" name="concepttest" value="'.$env{'form.concepttest'}.'" />'.
! 3678: '</div></form>');
1.41.2.6 raeburn 3679: }
3680:
1.16 raeburn 3681: sub notification_information {
3682: my ($disposition,$req_notifylist,$cnum,$now) = @_;
3683: my %emails = &Apache::loncommon::getemails();
3684: my $address;
3685: if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) {
3686: $address = $emails{'permanentemail'};
3687: if ($address eq '') {
3688: $address = $emails{'notification'};
3689: }
3690: }
3691: my $output;
3692: if ($disposition eq 'approval') {
3693: $output .= &mt('A message will be sent to your LON-CAPA account when a domain coordinator takes action on your request.').'<br />'.
3694: &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
3695: if ($address ne '') {
3696: $output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />';
3697: }
3698: if ($req_notifylist) {
3699: my $fullname = &Apache::loncommon::plainname($env{'user.name'},
3700: $env{'user.domain'});
3701: my $sender = $env{'user.name'}.':'.$env{'user.domain'};
3702: &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
3703: }
1.17 raeburn 3704: } elsif ($disposition eq 'pending') {
1.16 raeburn 3705: $output .= '<div class="LC_info">'.
3706: &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
3707: &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
3708: &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
3709: '</div>';
1.17 raeburn 3710: } else {
3711: $output .= '<div class="LC_warning">'.
3712: &mt('Your request status is: [_1].',$disposition).
3713: '</div>'
1.8 raeburn 3714: }
3715: return $output;
3716: }
3717:
3718: sub get_processtype {
1.9 raeburn 3719: my ($dom,$crstype,$inststatuses,$domconfig) = @_;
3720: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
1.8 raeburn 3721: my (%userenv,%settings,$val);
1.19 raeburn 3722: my @options = ('autolimit','validate','approval');
1.8 raeburn 3723: if ($dom eq $env{'user.domain'}) {
3724: %userenv =
3725: &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
3726: 'requestcourses.'.$crstype,'inststatus');
3727: if ($userenv{'requestcourses.'.$crstype}) {
3728: $val = $userenv{'requestcourses.'.$crstype};
3729: @{$inststatuses} = ('_custom_');
3730: } else {
3731: my ($task,%alltasks);
1.9 raeburn 3732: if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
3733: %settings = %{$domconfig->{'requestcourses'}};
1.8 raeburn 3734: if (ref($settings{$crstype}) eq 'HASH') {
1.23 raeburn 3735: if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
1.8 raeburn 3736: $val = $settings{$crstype}{'_LC_adv'};
3737: @{$inststatuses} = ('_LC_adv_');
3738: } else {
3739: if ($userenv{'inststatus'} ne '') {
3740: @{$inststatuses} = split(',',$userenv{'inststatus'});
3741: } else {
1.13 raeburn 3742: @{$inststatuses} = ('default');
1.8 raeburn 3743: }
3744: foreach my $status (@{$inststatuses}) {
3745: if (exists($settings{$crstype}{$status})) {
3746: my $value = $settings{$crstype}{$status};
3747: next unless ($value);
3748: unless (exists($alltasks{$value})) {
3749: if (ref($alltasks{$value}) eq 'ARRAY') {
3750: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
3751: push(@{$alltasks{$value}},$status);
3752: }
3753: } else {
3754: @{$alltasks{$value}} = ($status);
3755: }
3756: }
3757: }
3758: }
3759: my $maxlimit = 0;
1.13 raeburn 3760:
1.8 raeburn 3761: foreach my $key (sort(keys(%alltasks))) {
3762: if ($key =~ /^autolimit=(\d*)$/) {
3763: if ($1 eq '') {
3764: $val ='autolimit=';
3765: last;
3766: } elsif ($1 > $maxlimit) {
3767: $maxlimit = $1;
3768: }
3769: }
3770: }
3771: if ($maxlimit) {
3772: $val = 'autolimit='.$maxlimit;
3773: } else {
3774: foreach my $option (@options) {
3775: if ($alltasks{$option}) {
3776: $val = $option;
3777: last;
3778: }
3779: }
3780: }
3781: }
3782: }
3783: }
3784: }
3785: } else {
3786: %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
3787: $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
1.19 raeburn 3788: if ($userenv{'reqcrsotherdom.'.$crstype}) {
3789: my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
3790: my $optregex = join('|',@options);
3791: foreach my $item (@doms) {
3792: my ($extdom,$extopt) = split(':',$item);
3793: if ($extdom eq $dom) {
3794: if ($extopt =~ /^($optregex)(=?\d*)$/) {
3795: $val = $1.$2;
3796: }
3797: last;
3798: }
1.8 raeburn 3799: }
3800: @{$inststatuses} = ('_external_');
3801: }
3802: }
3803: return $val;
3804: }
3805:
3806: sub check_autolimit {
1.10 raeburn 3807: my ($uname,$udom,$dom,$crstype,$limit,$message) = @_;
3808: my %crsroles = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},
1.41 raeburn 3809: 'userroles',['active','future'],['cc','co'],[$dom]);
1.37 raeburn 3810: my ($types,$typename) = &Apache::loncommon::course_types();
1.10 raeburn 3811: my %requests = &Apache::lonnet::dumpstore('courserequests',$udom,$uname);
1.41 raeburn 3812: my $count = 0;
1.10 raeburn 3813: foreach my $key (keys(%requests)) {
3814: my ($cdom,$cnum) = split('_',$key);
1.41 raeburn 3815: if (ref($requests{$key}) eq 'HASH') {
3816: next if ($requests{$key}{'crstype'} ne $crstype);
3817: if (($crstype eq 'community') &&
3818: (exists($crsroles{$cnum.':'.$cdom.':co'}))) {
3819: $count ++;
3820: } elsif ((($crstype eq 'official') || ($crstype eq 'unofficial')) &&
3821: (exists($crsroles{$cnum.':'.$cdom.':cc'}))) {
3822: $count ++;
1.10 raeburn 3823: }
3824: }
3825: }
1.41 raeburn 3826: if ($count < $limit) {
1.10 raeburn 3827: return 'process';
3828: } else {
3829: if (ref($typename) eq 'HASH') {
1.41 raeburn 3830: if ($crstype eq 'community') {
3831: $$message = &mt('Your request has not been processed because you have reached the limit for the number of communities.').
3832: '<br />'.&mt("Your limit is [_1].",$limit);
3833: } else {
3834: $$message = &mt('Your request has not been processed because you have reached the limit for the number of courses of this type.').
3835: '<br />'.&mt("Your $typename->{$crstype} limit is [_1].",$limit);
3836: }
1.10 raeburn 3837: }
3838: return 'rejected';
3839: }
1.1 raeburn 3840: return;
3841: }
3842:
1.2 raeburn 3843: sub retrieve_settings {
1.26 raeburn 3844: my ($dom,$cnum,$udom,$uname) = @_;
3845: if ($udom eq '' || $uname eq '') {
3846: $udom = $env{'user.domain'};
3847: $uname = $env{'user.name'};
3848: }
3849: my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
1.16 raeburn 3850: if ($result eq 'ok') {
1.26 raeburn 3851: if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
1.16 raeburn 3852: $env{'form.chome'} = $reqinfo{'coursehome'};
3853: $env{'form.cdescr'} = $reqinfo{'cdescr'};
3854: $env{'form.crstype'} = $reqinfo{'crstype'};
3855: &generate_date_items($reqinfo{'accessstart'},'accessstart');
3856: &generate_date_items($reqinfo{'accessend'},'accessend');
3857: if ($reqinfo{'accessend'} == 0) {
3858: $env{'form.no_end_date'} = 1;
3859: }
3860: if (($reqinfo{'crstype'} eq 'official') && (&Apache::lonnet::auto_run('',$dom))) {
3861: &generate_date_items($reqinfo{'enrollstart'},'enrollstart');
3862: &generate_date_items($reqinfo{'enrollend'},'enrollend');
3863: }
3864: $env{'form.clonecrs'} = $reqinfo{'clonecrs'};
3865: $env{'form.clonedom'} = $reqinfo{'clonedom'};
3866: $env{'form.datemode'} = $reqinfo{'datemode'};
3867: $env{'form.dateshift'} = $reqinfo{'dateshift'};
3868: if (($reqinfo{'crstype'} eq 'official') && ($reqinfo{'instcode'} ne '')) {
3869: $env{'form.sectotal'} = $reqinfo{'sectotal'};
3870: $env{'form.crosslisttotal'} = $reqinfo{'crosslisttotal'};
3871: $env{'form.autoadds'} = $reqinfo{'autoadds'};
3872: $env{'form.autdrops'} = $reqinfo{'autodrops'};
3873: $env{'form.instcode'} = $reqinfo{'instcode'};
1.24 raeburn 3874: my $crscode = {
3875: $cnum => $reqinfo{'instcode'},
3876: };
3877: &extract_instcode($dom,'instcode',$crscode,$cnum);
1.16 raeburn 3878: }
3879: my @currsec;
3880: if (ref($reqinfo{'sections'}) eq 'HASH') {
3881: foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
3882: if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
1.24 raeburn 3883: my $sec = $reqinfo{'sections'}{$i}{'inst'};
1.16 raeburn 3884: $env{'form.secnum_'.$i} = $sec;
1.24 raeburn 3885: $env{'form.sec_'.$i} = '1';
1.16 raeburn 3886: if (!grep(/^\Q$sec\E$/,@currsec)) {
3887: push(@currsec,$sec);
3888: }
3889: $env{'form.loncapasec_'.$i} = $reqinfo{'sections'}{$i}{'loncapa'};
3890: }
3891: }
3892: }
1.24 raeburn 3893: if (ref($reqinfo{'crosslists'}) eq 'HASH') {
3894: foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
3895: if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
3896: $env{'form.crosslist_'.$i} = '1';
3897: $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
3898: $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
3899: if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
3900: my $key = $cnum.$i;
3901: my $crscode = {
3902: $key => $reqinfo{'crosslists'}{$i}{'instcode'},
3903: };
3904: &extract_instcode($dom,'crosslist',$crscode,$key,$i);
3905: }
1.16 raeburn 3906: }
3907: }
3908: }
3909: if (ref($reqinfo{'personnel'}) eq 'HASH') {
3910: my $i = 0;
3911: foreach my $user (sort(keys(%{$reqinfo{'personnel'}}))) {
3912: my ($uname,$udom) = split(':',$user);
3913: if (ref($reqinfo{'personnel'}{$user}) eq 'HASH') {
3914: if (ref($reqinfo{'personnel'}{$user}{'roles'}) eq 'ARRAY') {
3915: foreach my $role (sort(@{$reqinfo{'personnel'}{$user}{'roles'}})) {
3916: $env{'form.person_'.$i.'_role'} = $role;
3917: $env{'form.person_'.$i.'_firstname'} = $reqinfo{'personnel'}{$user}{'firstname'};
3918: $env{'form.person_'.$i.'_lastname'} = $reqinfo{'personnel'}{$user}{'lastname'}; ;
3919: $env{'form.person_'.$i.'_emailaddr'} = $reqinfo{'personnel'}{$user}{'emailaddr'};
3920: $env{'form.person_'.$i.'_uname'} = $uname;
3921: $env{'form.person_'.$i.'_dom'} = $udom;
3922: if (ref($reqinfo{'personnel'}{$user}{$role}) eq 'HASH') {
3923: if (ref($reqinfo{'personnel'}{$user}{$role}{'usec'}) eq 'ARRAY') {
3924: my @usecs = @{$reqinfo{'personnel'}{$user}{$role}{'usec'}};
3925: my @newsecs;
3926: if (@usecs > 0) {
3927: foreach my $sec (@usecs) {
3928: if (grep(/^\Q$sec\E/,@currsec)) {
3929: $env{'form.person_'.$i.'_sec'} = $sec;
3930: } else {
1.20 raeburn 3931: push(@newsecs,$sec);
1.16 raeburn 3932: }
3933: }
3934: }
3935: if (@newsecs > 0) {
3936: $env{'form.person_'.$i.'_newsec'} = join(',',@newsecs);
3937: }
3938: }
3939: }
3940: $i ++;
3941: }
3942: }
3943: }
3944: }
3945: $env{'form.persontotal'} = $i;
3946: }
3947: }
3948: }
3949: return $result;
3950: }
3951:
3952: sub get_request_settings {
1.26 raeburn 3953: my ($dom,$cnum,$udom,$uname) = @_;
1.16 raeburn 3954: my $requestkey = $dom.'_'.$cnum;
3955: my ($result,%reqinfo);
3956: if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
1.26 raeburn 3957: my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
1.16 raeburn 3958: my $disposition = $history{'disposition'};
3959: if (($disposition eq 'approval') || ($disposition eq 'pending')) {
3960: if (ref($history{'details'}) eq 'HASH') {
3961: %reqinfo = %{$history{'details'}};
3962: $result = 'ok';
3963: } else {
3964: $result = 'nothash';
3965: }
3966: } else {
3967: $result = 'notqueued';
3968: }
3969: } else {
3970: $result = 'invalid';
3971: }
3972: return ($result,%reqinfo);
3973: }
1.2 raeburn 3974:
1.16 raeburn 3975: sub extract_instcode {
1.24 raeburn 3976: my ($cdom,$element,$crscode,$crskey,$counter) = @_;
1.16 raeburn 3977: my (%codes,@codetitles,%cat_titles,%cat_order);
1.24 raeburn 3978: if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
3979: \@codetitles,\%cat_titles,
3980: \%cat_order) eq 'ok') {
3981: if (ref($codes{$crskey}) eq 'HASH') {
1.16 raeburn 3982: if (@codetitles > 0) {
3983: my $sel = $element;
3984: if ($element eq 'crosslist') {
3985: $sel .= '_'.$counter;
3986: }
3987: foreach my $title (@codetitles) {
1.24 raeburn 3988: $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
1.16 raeburn 3989: }
3990: }
3991: }
3992: }
3993: return;
1.2 raeburn 3994: }
3995:
1.16 raeburn 3996: sub generate_date_items {
3997: my ($currentval,$item) = @_;
3998: if ($currentval =~ /\d+/) {
3999: my ($tzname,$sec,$min,$hour,$mday,$month,$year) =
4000: &Apache::lonhtmlcommon::get_timedates($currentval);
4001: $env{'form.'.$item.'_day'} = $mday;
4002: $env{'form.'.$item.'_month'} = $month+1;
4003: $env{'form.'.$item.'_year'} = $year;
4004: }
4005: return;
1.2 raeburn 4006: }
4007:
1.41.2.6 raeburn 4008: sub show_cloneable {
4009: my $showclone;
4010: if (&Apache::loncommon::needs_gci_custom()) {
4011: my %courses = &Apache::loncommon::existing_gcitest_courses('cc');
4012: my $numcourses = scalar(keys(%courses));
4013: return $numcourses;
4014: } else {
4015: return 1;
4016: }
4017: }
4018:
1.1 raeburn 4019: 1;
4020:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>