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