Annotation of loncom/interface/courseprefs.pm, revision 1.4
1.1 raeburn 1: # The LearningOnline Network with CAPA
1.2 raeburn 2: # Handler to set configuration settings for a course
1.1 raeburn 3: #
1.4 ! raeburn 4: # $Id: courseprefs.pm,v 1.3 2009/05/12 21:20:42 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: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
31: package Apache::courseprefs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::lonnet;
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::lonconfigsettings;
39: use Apache::lonlocal;
40: use LONCAPA qw(:DEFAULT :match);
41:
42: sub handler {
43: my $r=shift;
44: if ($r->header_only) {
45: &Apache::loncommon::content_type($r,'text/html');
46: $r->send_http_header;
47: return OK;
48: }
49: my $context = 'course';
50: my $cid = $env{'request.course.id'};
51: my ($cnum,$cdom) = &get_course($cid);
52: my $crstype = &Apache::loncommon::course_type();
53: my $parm_permission = &Apache::lonnet::allowed('opa',$cid);
54: my $navmap = Apache::lonnavmaps::navmap->new();
55: if ($parm_permission && $navmap) {
56: &Apache::loncommon::content_type($r,'text/html');
57: $r->send_http_header;
58: } else {
59: if ($navmap) {
60: $env{'user.error.msg'}=
1.2 raeburn 61: "/adm/courseprefs:opa:0:0:Cannot modify course settings";
1.1 raeburn 62: } else {
63: $env{'user.error.msg'}=
64: "/adm/courseprefs::0:1:Course environment gone, reinitialize the course";
65: }
66: return HTTP_NOT_ACCEPTABLE;
67: }
68:
1.4 ! raeburn 69: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
! 70: ['phase','actions','origin']);
1.1 raeburn 71: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.4 ! raeburn 72: if ($env{'form.origin'} eq 'params') {
! 73: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
! 74: text=>"Parameter Manager"});
! 75: }
1.1 raeburn 76: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/courseprefs',
77: text=>"Course Configuration"});
78: my $breadcrumbs =
79: &Apache::lonhtmlcommon::breadcrumbs('Edit Course Configuration');
80:
81: my $phase = 'pickactions';
82: if ( exists($env{'form.phase'}) ) {
83: $phase = $env{'form.phase'};
84: }
85:
86: if ($phase eq 'categorizecourse') {
87: &assign_course_categories($r);
88: return OK;
89: }
90:
91: my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
92: my @prefs_order = ('courseinfo','localization','feedback','discussion',
93: 'classlists','appearance','grading','printouts',
94: 'spreadsheet','bridgetasks','other');
95:
96: my %prefs = (
97: 'courseinfo' =>
98: { text => 'General course settings',
99: help => 'Course_Environment',
100: header => [{col1 => 'Setting',
101: col2 => 'Value'}],
102: ordered => ['description','courseid','categories',
103: 'hidefromcat','cloners','externalsyllabus',
104: 'url','rolenames'],
1.3 raeburn 105: itemtext => {
106: description => 'Course Description',
107: courseid => 'Course ID or number',
108: categories => 'Categorize course',
109: hidefromcat => 'Exclude from course catalog',
110: cloners => 'Users allowed to clone course',
111: externalsyllabus => 'URL of Syllabus',
112: url => 'Top Level Map',
113: rolenames => 'Replacement titles for standard course roles',
114: },
1.1 raeburn 115: },
116: 'localization' =>
117: { text => 'Language/TimeZone/Locale',
118: help => 'Course_Environment',
119: header => [{col1 => 'Setting',
120: col2 => 'Value',}],
121: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 122: itemtext => {
123: languages => 'Languages used',
124: timezone => 'Timezone in which the course takes place',
125: datelocale => 'Locale used for course calendar',
126: },
1.1 raeburn 127: },
128: 'feedback' =>
129: { text => 'Feedback messages',
130: help => 'Course_Environment',
131: header => [{col1 => 'Questions about:',
132: col2 => 'Recipients'},
133: {col1 => 'Questions about:',
134: col2 => 'Custom Text'}],
1.3 raeburn 135: ordered => ['question.email','comment.email','policy.email'],
136: itemtext => {
137: 'question.email' => 'Resource Content',
138: 'comment.email' => 'Course Content',
139: 'policy.email' => 'Course Policy',
140: },
1.1 raeburn 141: },
142: 'discussion' =>
143: { text => 'Discussion and Chat',
144: help => 'Course_Environment',
145: header => [{col1 => 'Setting',
146: col2 => 'Value',}],
147: ordered => ['plc.roles.denied','plc.users.denied',
148: 'pch.roles.denied','pch.users.denied',
149: 'allow_limited_html_in_feedback',
150: 'allow_discussion_post_editing'],
1.3 raeburn 151: itemtext => {
152: 'plc.roles.denied' => 'No Resource Discussion',
153: 'plc.users.denied' => 'No Resource Discussion',
154: 'pch.roles.denied' => 'No Chat room use',
155: 'pch.users.denied' => 'No Chat room use',
156: allow_limited_html_in_feedback => 'Allow limited HTML in discussion posts',
157: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
158: },
1.1 raeburn 159: },
160: 'classlists' =>
161: { text => 'Classlists and Staff Listing',
162: help => 'Course_Environment',
163: header => [{col1 => 'Type',
164: col2 => 'Default dates for student access'},
165: {col1 => 'Setting',
166: col2 => 'Privileged users (Domain Coordinators) in staff listing'},
167: {col1 => 'Setting',
168: col2 => 'Student-viewable classlist options'}],
169: ordered => ['default_enrollment_start_date',
170: 'default_enrollment_end_date',
171: 'nothideprivileged','student_classlist_view',
172: 'student_opt_in','student_classlist_portfiles'],
1.3 raeburn 173: itemtext => {
174: default_enrollment_start_date => 'Start date',
175: default_enrollment_end_date => 'End date',
176: nothideprivileged => 'Domain Coodinators in course',
177: student_classlist_view => 'Student-viewable classlist',
178: student_opt_in => 'Student agreement needed to be listed',
179: student_classlist_portfiles => 'Include link to accessible portfolio files',
180: },
1.1 raeburn 181: },
182: 'appearance' =>
183: { text => 'Display of resources ',
184: help => 'Course_Environment',
185: header => [{col1 => 'Setting',
186: col2 => 'Value'}],
187: ordered => ['default_xml_style','pageseparators',
188: 'disable_receipt_display','texengine',
189: 'tthoptions'],
1.3 raeburn 190: itemtext => {
191: default_xml_style => 'Default XML Style File',
192: pageseparators => 'Visibly Separate Items on Pages',
193: disable_receipt_display => 'Disable display of problem receipts',
194: texengine => 'Force use of a specific math rendering engine.',
195: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
196: },
1.1 raeburn 197: },
198: 'grading' =>
199: { text => 'Grading',
200: help => 'Course_Environment',
201: header => [{col1 => 'Setting',
202: col2 => 'Value',}],
203: ordered => ['grading','rndseed',
204: 'receiptalg','disablesigfigs'],
1.3 raeburn 205: itemtext => {
206: grading => 'Grading',
207: rndseed => 'Randomization algorithm used',
208: receiptalg => 'Receipt algorithm used',
209: disablesigfigs => 'Disable checking of Significant Figures',
210: },
211:
1.1 raeburn 212: },
213: 'printouts' =>
214: { text => 'Printout generation',
215: help => 'Course_Environment',
216: header => [{col1 => 'Setting',
217: col2 => 'Value',}],
218: ordered => ['problem_stream_switch','suppress_tries',
219: 'default_paper_size','print_header_format',
220: 'disableexampointprint'],
1.3 raeburn 221: itemtext => {
222: problem_stream_switch => 'Allow problems to be split over pages',
223: suppress_tries => 'Suppress number of tries in printing',
224: default_paper_size => 'Default paper type',
225: print_header_format => 'Print header format',
226: disableexampointprint => 'Disable automatically printing point values on exams',
227: },
1.1 raeburn 228: },
229: 'spreadsheet' =>
230: { text => 'Spreadsheets',
231: help => 'Course_Environment',
232: header => [{col1 => 'Setting',
233: col2 => 'Value'}],
234: ordered => ['spreadsheet_default_classcalc',
235: 'spreadsheet_default_studentcalc',
236: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 237: itemtext => {
238: spreadsheet_default_classcalc => 'Default Course Spreadsheet',
239: spreadsheet_default_studentcalc => 'Default Student Spreadsheet',
240: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
241: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
242: },
1.1 raeburn 243: },
244: 'bridgetasks' =>
245: { text => 'Bridge tasks',
246: help => 'Course_Environment',
247: header => [{col1 => 'Setting',
248: col2 => 'Value'}],
249: ordered => ['task_messages','task_grading',
250: 'suppress_embed_prompt'],
1.3 raeburn 251: itemtext => {
252: task_messages => 'Send message to student when clicking Done on Tasks',
253: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
254: suppress_embed_prompt => 'Hi$de upload references prompt if uploading file to portfolio',
255: },
1.1 raeburn 256: },
257: 'other' =>
258: { text => 'Other settings',
259: help => 'Course_Environment',
260: header => [ {col1 => 'Item',
261: col2 => 'Value',
262: }],
263: },
264: );
265: if ($phase eq 'process') {
1.3 raeburn 266: my @allitems = &get_allitems(%prefs);
1.1 raeburn 267: &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
1.3 raeburn 268: \@prefs_order,\%prefs,\%values,
269: $cnum,undef,\@allitems);
1.1 raeburn 270: } elsif ($phase eq 'display') {
1.3 raeburn 271: my $jscript = &get_jscript($cdom,$phase);
272: my @allitems = &get_allitems(%prefs);
1.1 raeburn 273: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
274: \@prefs_order,\%prefs,\%values,undef,$jscript,\@allitems);
275: } else {
276: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
277: \@prefs_order,\%prefs);
278: }
279: return OK;
280: }
281:
1.3 raeburn 282: sub get_allitems {
283: my (%prefs) = @_;
284: my @allitems;
285: foreach my $item (keys(%prefs)) {
286: if (ref($prefs{$item}) eq 'HASH') {
287: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
288: push(@allitems,@{$prefs{$item}{'ordered'}});
289: if ($item eq 'feedback') {
290: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
291: }
292: }
293: }
294: }
295: return @allitems;
296: }
297:
1.1 raeburn 298: sub print_config_box {
299: my ($r,$cdom,$phase,$action,$item,$settings,$allitems) = @_;
300: my $ordered = $item->{'ordered'};
1.3 raeburn 301: my $itemtext = $item->{'itemtext'};
1.1 raeburn 302: my $rowtotal = 0;
303: my $output =
304: '<table class="LC_nested_outer">
305: <tr>
306: <th align="left" valign="middle"><span class="LC_font_larger">'.
307: &mt($item->{text}).' '.
308: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
309: '</tr>';
310: if (($action eq 'feedback') || ($action eq 'classlists')) {
311: $output .= '
312: <tr>
313: <td>
314: <table class="LC_nested">
315: <tr class="LC_info_row">
316: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
317: <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
318: </tr>';
319: $rowtotal ++;
320: if ($action eq 'feedback') {
1.3 raeburn 321: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 322: } elsif ($action eq 'classlists') {
1.3 raeburn 323: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal);
1.1 raeburn 324: }
325: $output .= '
326: </table>
327: </td>
328: </tr>
329: <tr>
330: <td>
331: <table class="LC_nested">
332: <tr class="LC_info_row">
333: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
334: $output .= '
335: <td class="LC_right_item">'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
336: </tr>';
337: if ($action eq 'classlists') {
1.3 raeburn 338: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal).
1.1 raeburn 339: '
340: </table>
341: </td>
342: </tr>
343: <tr>
344: <td>
345: <table class="LC_nested">
346: <tr class="LC_info_row">
347: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
348: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
349: </tr>';
350: }
351: } else {
352: $output .= '
353: <tr>
354: <td>
355: <table class="LC_nested">
356: <tr class="LC_info_row">
357: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
358: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
359: </tr>';
360: }
361: $rowtotal ++;
362: if ($action eq 'courseinfo') {
1.3 raeburn 363: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 364: } elsif ($action eq 'localization') {
1.3 raeburn 365: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 366: } elsif ($action eq 'feedback') {
1.3 raeburn 367: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 368: } elsif ($action eq 'discussion') {
1.3 raeburn 369: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 370: } elsif ($action eq 'classlists') {
1.3 raeburn 371: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal);
1.1 raeburn 372: } elsif ($action eq 'appearance') {
1.3 raeburn 373: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 374: } elsif ($action eq 'grading') {
1.3 raeburn 375: $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 376: } elsif ($action eq 'printouts') {
1.3 raeburn 377: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 378: } elsif ($action eq 'spreadsheet') {
1.3 raeburn 379: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 380: } elsif ($action eq 'bridgetasks') {
1.3 raeburn 381: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal);
1.1 raeburn 382: } elsif ($action eq 'other') {
383: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal);
384: }
385: $output .= '
386: </table>
387: </td>
388: </tr>
389: </table><br />';
390: return ($output,$rowtotal);
391: }
392:
393: sub process_changes {
1.3 raeburn 394: my ($cdom,$action,$values,$item,$changes,$allitems,$disallowed) = @_;
395: my %newvalues;
396: if (ref($item) eq 'HASH') {
397: if (ref($changes) eq 'HASH') {
398: my @ordered;
399: if ($action eq 'other') {
400: @ordered = &get_other_items($cdom,$values,$allitems);
401: if ($env{'form.newp_name'} ne '') {
402: my $newp = $env{'form.newp_name'};
403: if ($env{'form.newp_value'} ne '') {
404: if (ref($allitems) eq 'ARRAY') {
405: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
406: (grep(/^\Q$newp\E$/,@{$allitems}))) {
407: $changes->{$newp} = $env{'form.newp_value'};
408: }
409: }
410: }
411: }
412: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
413: @ordered = @{$item->{'ordered'}};
414: }
415: if (@ordered > 0) {
416: if ($action eq 'feedback') {
417: foreach my $entry (@ordered) {
418: my $userstr = '';
419: my $total = $env{'form.'.$entry.'_total'};
420: if ($total) {
421: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
422: for (my $i=0; $i<$total; $i++) {
423: unless (grep(/^$i$/,@deletes)) {
424: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
425: &get_sec_str($entry,$i).',';
426: }
427: }
428: } else {
429: $total = 0;
430: }
431: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
432: my $uname = $env{'form.'.$entry.'_uname_'.$total};
433: my $udom = $env{'form.'.$entry.'_udom_'.$total};
434: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
435: $userstr =~ s/,$//;
436: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
437: } else {
438: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
439: }
440: } else {
441: $userstr =~ s/,$//;
442: }
443: $newvalues{$entry} = $userstr;
444: if ($newvalues{$entry} ne $values->{$entry}) {
445: $changes->{$entry} = $newvalues{$entry};
446: }
447: my $ext_entry = $entry.'.text';
448: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
449: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
450: $changes->{$ext_entry} = $newvalues{$ext_entry};
451: }
452: }
453: } else {
454: foreach my $entry (@ordered) {
455: if ($entry eq 'cloners') {
456: if ($env{'form.cloners_all'}) {
457: $newvalues{$entry} = '*';
458: } else {
459: my @clonedoms;
460: if (exists($env{'form.cloners_activate'})) {
461: my $actnum = $env{'form.cloners_activate'};
462: if ($actnum ne '') {
463: if ($env{'form.clonersdom_'.$actnum} ne '') {
464: my $clonedom = $env{'form.clonersdom_'.$actnum};
465: if (&check_clone($clonedom,$disallowed) eq 'ok') {
466: $newvalues{$entry} = '*:'.$clonedom;
467: push(@clonedoms,$newvalues{$entry});
468: }
469: }
470: }
471: } else {
472: my $num = $env{'form.cloners_total'};
473: my @deletes =
474: &Apache::loncommon::get_env_multiple('form.cloners_delete');
475: for (my $i=0; $i<$num; $i++) {
476: if (!grep(/^$i$/,@deletes)) {
477: my $clonedom = $env{'form.cloners_dom_'.$i};
478: if (&check_clone($clonedom,$disallowed) eq 'ok') {
479: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
480: push (@clonedoms,'*:'.$clonedom);
481: }
482: }
483: }
484: }
485: if (@clonedoms) {
486: $newvalues{$entry}=join(',',@clonedoms);
487: }
488: }
489: if ($env{'form.cloners_newdom'} ne '') {
490: my $clonedom = $env{'form.cloners_newdom'};
491: if (&check_clone($clonedom,$disallowed) eq 'ok') {
492: my $newdom = '*:'.$env{'form.cloners_newdom'};
493: if (@clonedoms) {
494: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
495: $newvalues{$entry} .= ','.$newdom;
496: }
497: } else {
498: $newvalues{$entry} = $newdom;
499: }
500: }
501: }
502: if ($env{'form.'.$entry} ne '') {
503: my @cloners = split(',',$env{'form.'.$entry});
504: my @okcloners;
505: foreach my $cloner (@cloners) {
506: my ($uname,$udom) = split(':',$cloner);
507: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
508: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
509: push(@okcloners,$cloner);
510: }
511: }
512: }
513: if (@okcloners) {
514: my $okclonestr = join(',',@okcloners);
515: if ($newvalues{$entry} ne '') {
516: $newvalues{$entry} .= ','.$okclonestr;
517: } else {
518: $newvalues{$entry} = $okclonestr;
519: }
520: }
521: }
522: }
523: if (ref($disallowed) eq 'HASH') {
524: if (ref($disallowed->{'cloners'}) eq 'HASH') {
525: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
526: $disallowed->{'cloners'}{$key} =~ s/,$//;
527: }
528: }
529: }
530: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
531: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
532: } elsif ($entry eq 'rolenames') {
533: my $crstype = &Apache::loncommon::course_type();
534: my %adv_roles =
535: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
536: my @stds = ('cc','in','ta','ep','ad','st');
537: my (@replacements,@regulars);
538: foreach my $role (@stds) {
539: if ($values->{$role.'.plaintext'} ne '') {
540: push(@replacements,$role);
541: } else {
542: push(@regulars,$role);
543: }
544: }
545: foreach my $stdrole (@stds) {
546: my $ext_entry = $entry.'_'.$stdrole;
547: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
548: $env{'request.course.id'},1);
549: if ($env{'form.'.$ext_entry} eq $stdname) {
550: $newvalues{$ext_entry} = '';
551: } else {
552: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
553: }
554: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
555: my $dupname = 0;
556: if ($newvalues{$ext_entry} ne '') {
557: my $dupname = 0;
558: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
559: $dupname = 1;
560: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
561: }
562: if (!$dupname) {
563: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
564: $dupname = 1;
565: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
566: }
567: }
568: if (!$dupname) {
569: foreach my $role (keys(%adv_roles)) {
570: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
571: $dupname = 1;
572: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
573: last;
574: }
575: }
576: }
577: }
578: if (!$dupname) {
579: $changes->{$ext_entry} = $newvalues{$ext_entry};
580: }
581: }
582: }
583: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied')) {
584: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
585: @denied = sort(@denied);
586: my $deniedstr = '';
587: if (@denied > 0) {
588: $deniedstr = join(',',@denied);
589: }
590: $newvalues{$entry} = $deniedstr;
591: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied')) {
592: my $total = $env{'form.'.$entry.'_total'};
593: my $userstr = '';
594: my @denied;
595: if ($total > 0) {
596: my @deletes =
597: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
598: for (my $i=0; $i<$total; $i++) {
599: unless (grep(/^$i$/,@deletes)) {
600: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
601: push(@denied,$env{'form.'.$entry.'_user_'.$i});
602: }
603: }
604: } else {
605: $total = 0;
606: }
607: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
608: my $uname = $env{'form.'.$entry.'_uname_'.$total};
609: my $udom = $env{'form.'.$entry.'_udom_'.$total};
610: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
611: $userstr =~ s/,$//;
612: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
613: } else {
614: my $newuser .= $uname.':'.$udom;
615: if (grep(/^\Q$newuser\E$/,@denied)) {
616: $userstr =~ s/,$//;
617: } else {
618: $userstr .= $newuser;
619: }
620: }
621: } else {
622: $userstr =~ s/,$//;
623: }
624: $newvalues{$entry} = $userstr;
625: } elsif ($entry eq 'allow_discussion_post_editing') {
626: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
627: @canedit = sort(@canedit);
628: foreach my $role (@canedit) {
629: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
630: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
631: $newvalues{$entry} .= $role.',';
632: } else {
633: foreach my $sec (@secs) {
634: $newvalues{$entry} .= $role.':'.$sec.',';
635: }
636: }
637: }
638: $newvalues{$entry} =~ s/,$//;
639: } elsif ($entry eq 'nothideprivileged') {
640: my @curr_nothide;
641: my @new_nothide;
642: if ($values->{$entry} ne '') {
643: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
644: my $nothide;
645: if ($user !~ /:/) {
646: $nothide = join(':',split(/[\@]/,$user));
647: } else {
648: $nothide = $user;
649: }
650: if ((defined($nothide)) &&
651: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
652: push(@curr_nothide,$nothide);
653: }
654: }
655: }
656: foreach my $key (keys(%env)) {
657: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
658: if ($env{'form.'.$key}) {
659: my $nothide = $1;
660: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
661: push(@new_nothide,$nothide);
662: }
663: }
664: }
665: }
666: @new_nothide = sort(@new_nothide);
667: my @differences =
668: &Apache::loncommon::compare_arrays(\@curr_nothide,
669: \@new_nothide);
670: if (@differences > 0) {
671: if (@new_nothide > 0) {
672: $newvalues{$entry} = join(',',@new_nothide);
673: } else {
674: $newvalues{$entry} = '';
675: }
676: } else {
677: $newvalues{$entry} = $values->{$entry};
678: }
679: } elsif ($entry eq 'print_header_format') {
680: my $maxnum = $env{'form.printfmthdr_maxnum'};
681: my @newhdr;
682: if ($maxnum > 2) {
683: for (my $i=0; $i<$maxnum-2; $i++) {
684: if ($env{'form.printfmthdr_del_'.$i}) {
685: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
686: } else {
687: my $hdr;
688: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
689: $hdr = '%';
690: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
691: $hdr .= $env{'form.printfmthdr_limit_'.$i};
692: }
693: $hdr .= $env{'form.printfmthdr_sub_'.$i};
694: } elsif ($env{'form.printfmthdr_sub_'.$i} ne '') {
695: $hdr = $env{'form.printfmthdr_sub_'.$i};
696: }
697: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
698: }
699: }
700: }
701: my $newsub = $maxnum-2;
702: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
703: my $hdr = '%';
704: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
705: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
706: }
707: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
708: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
709: }
710: my $newtext = $maxnum-1;
711: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
712: $newvalues{$entry} = join('',@newhdr);
713: } elsif ($entry eq 'languages') {
714: my $langstr;
715: my $total = $env{'form.'.$entry.'_total'};
716: if ($total) {
717: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
718: for (my $i=0; $i<$total; $i++) {
719: unless (grep(/^$i$/,@deletes)) {
720: $langstr .= $env{'form.'.$entry.'_'.$i}.',';
721: }
722: }
723: } else {
724: $total = 0;
725: }
726: if ($env{'form.'.$entry.'_'.$total} ne '') {
727: my $newlang = $env{'form.'.$entry.'_'.$total};
728: my %langchoices = &get_lang_choices();
729: if ($langchoices{$newlang}) {
730: $langstr .= $newlang;
731: } else {
732: $langstr =~ s/,$//;
733: $disallowed->{'localization'}{$entry} = $newlang;
734: }
735: } else {
736: $langstr =~ s/,$//;
737: }
738: $newvalues{$entry} = $langstr;
739: } else {
740: $newvalues{$entry} = $env{'form.'.$entry};
741: }
742: if ($newvalues{$entry} ne $values->{$entry}) {
743: $changes->{$entry} = $newvalues{$entry};
744: }
745: }
746: }
747: }
748: }
749: }
750: return;
751: }
752:
753: sub get_sec_str {
754: my ($entry,$num) = @_;
755: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
756: my $secstr;
757: if (grep(/^\s*$/,@secs)) {
758: $secstr = '';
759: } elsif (@secs > 0) {
760: $secstr = join(';',@secs);
761: }
762: if ($secstr ne '') {
763: return '('.$secstr.')';
764: }
765: return;
766: }
767:
768: sub check_clone {
769: my ($clonedom,$disallowed,$clonename) = @_;
770: return if (ref($disallowed) ne 'HASH');
771: if ($clonedom !~ /^$match_domain$/) {
772: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
773: return;
774: } elsif (!&Apache::lonnet::domain($clonedom)) {
775: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
776: return;
777: }
778: if ($clonename ne '') {
779: if ($clonename !~ /^$match_username$/) {
780: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
781: return;
782: } else {
783: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
784: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
785: return;
786: }
787: }
788: }
789: return 'ok';
790: }
791:
792: sub store_changes {
793: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes) = @_;
794: my ($chome,$output);
795: my (%storehash,@delkeys,@need_env_update);
796: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
797: %storehash = %{$values};
798: } else {
799: $output = &mt('No changes made to course settings.');
800: return;
801: }
802: my %yesno = (
803: hidefromcat => '1',
804: problem_stream_switch => '1',
805: suppress_tries => '1',
806: disableexampointprint => '1',
807: hideemptyrows => '1',
808: suppress_embed_prompt => '1',
809: );
810: foreach my $item (@{$prefs_order}) {
811: if (grep(/^\Q$item\E$/,@{$actions})) {
812: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
813: if (ref($changes->{$item}) eq 'HASH') {
814: if (keys(%{$changes->{$item}}) > 0) {
815: $output .= &mt('Changes made:').'<ul>';
816: if ($item eq 'other') {
817: foreach my $key (sort(keys(%{$changes->{$item}}))) {
818: $storehash{$key} = $changes->{$item}{$key};
819: if ($changes->{$item}{$key} eq '') {
820: push(@delkeys,$key);
821: $output .= '<li>'.&mt('Deleted setting for [_1]','<i>'.$key.'</i>').'</li>';
822: } else {
823: $output .= '<li>'.&mt('[_1] set to [_2]','<i>'.$key.'</i>',
824: "'$storehash{$key}'").'</li>';
825: }
826: }
827: } else {
828: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
829: my @settings = @{$prefs->{$item}->{'ordered'}};
830: if ($item eq 'feedback') {
831: push(@settings,(map { $_.'.text'; } @settings));
832: }
833: foreach my $key (@settings) {
834: if ($key eq 'rolenames') {
835: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
836: my $crstype = &Apache::loncommon::course_type();
837: my $msg;
838: foreach my $role ('cc','in','ta','ep','ad','st') {
839: next if (!exists($changes->{$item}{$key.'_'.$role}));
840: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
841: my $newname = $changes->{$item}{$key.'_'.$role};
842: $storehash{$role.'.plaintext'} = $newname;
843: if ($newname eq '') {
844: $newname = $stdname;
845: }
846: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
847: "'<b>".$newname."</b>'").'</li>';
848: }
849: if ($msg ne '') {
850: $output .= '<li>'.&mt($displayname).'<ul>'.$msg.'</ul></li>';
851: }
852: } else {
853: next if (!exists($changes->{$item}{$key}));
854: my ($displayname,$text);
855: $text = $prefs->{$item}->{'itemtext'}{$key};
856: my $displayval = $changes->{$item}{$key};
857: if ($item eq 'feedback') {
858: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
859: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
860: $displayname = &mt('Custom text for '.$text.' questions');
861: } else {
862: $displayname = &mt('Recipients of '.$text.' questions');
863: }
864: } elsif ($item eq 'discussion') {
865: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
866: $displayname = &mt("$text (role-based)");
867: if ($displayval ne '') {
868: my @roles = split(',',$displayval);
869: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
870: $displayval = join(', ',@roles);
871: }
872: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
873: $displayname = &mt("$text (specific user(s))");
874: } else {
875: if ($key eq 'allow_discussion_post_editing') {
876: if ($displayval ne '') {
877: my @roles = split(',',$displayval);
878: my @longroles;
879: foreach my $role (@roles) {
880: my ($trole,$sec) = split(':',$role);
881: my $rolename =
882: &Apache::lonnet::plaintext($trole);
883: if ($sec ne '') {
884: $rolename .= ':'.$sec;
885: }
886: push(@longroles,$rolename);
887: }
888: $displayval = join(', ',@longroles);
889: }
890: }
891: $displayname = &mt($text);
892: }
893: } elsif ($item eq 'spreadsheet') {
894: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
895: my $sheettype = $1;
896: if ($sheettype eq 'studentcalc') {
897: &Apache::lonnet::expirespread('','','studentcalc');
898: } else {
899: &Apache::lonnet::expirespread('','','assesscalc');
900: &Apache::lonnet::expirespread('','','studentcalc');
901: }
902: }
903: $displayname = &mt($text);
904: } else {
905: $displayname = &mt($text);
906: }
907: if (defined($yesno{$key})) {
908: $displayval = 'no';
909: if ($changes->{$item}{$key} eq 'yes') {
910: $displayval = 'yes';
911: }
912: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
913: $displayval = &Apache::lonlocal::locallocaltime($displayval);
914: } elsif ($key eq 'categories') {
915: $displayval = $env{'form.categories_display'};
916: }
917: if ($changes->{$item}{$key} eq '') {
918: push(@delkeys,$key);
919: $output .= '<li>'.&mt('Deleted setting for [_1]',
920: '<i>'.$displayname.'</i>').'</li>';
921: } else {
922: $output .= '<li>'.&mt('[_1] set to [_2]',
923: '<i>'.$displayname.'</i>',
924: "'<b>$displayval</b>'");
925: if ($key eq 'url') {
926: my $bkuptime=time;
927: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
928: $storehash{'top level map backup '.$bkuptime} => $values->{$key};
929: }
930: $output .= '</li>';
931: }
932: $storehash{$key} = $changes->{$item}{$key};
933: }
934: if (($key eq 'description') || ($key eq 'cloners') ||
935: ($key eq 'hidefromcat') || ($key eq 'categories')) {
936: push(@need_env_update,$key);
937: }
938: }
939: }
940: }
941: $output .= '</ul>';
942: } else {
943: $output = &mt('No changes made to course settings.');
944: }
945: }
946: }
947: }
948: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
949: if (@delkeys) {
950: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
951: $output .= '<br /><span class="LC_error">'.
952: &mt('An error occurred when removing course settings which are no longer in use.').'</span>';
953: }
954: }
955: if (@need_env_update) {
956: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
957: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
958: }
959: &Apache::lonnet::coursedescription($env{'request.course.id'},
960: {'freshen_cache' => 1});
961: } else {
962: $output = '<span class="LC_error">'.
963: &mt('An error occurred when saving changes to course settings, which remain unchanged.').'</span>';
964: }
965: return $output;
966: }
967:
968: sub update_env {
969: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
970: my $count = 0;
971: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
972: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
973: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
974: foreach my $key (@{$need_env_update}) {
975: if ($key eq 'description' && defined($storehash->{$key})) {
976: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
977: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
978: $count ++;
979: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
980: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
981: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
982: $count ++;
983: }
984: }
985: if ($count) {
986: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
987: }
988: }
989: }
990: return;
991: }
992:
993: sub display_disallowed {
994: my ($item,$disallowed,$prefs) = @_;
995: my $output;
996: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
997: if (keys(%{$disallowed})) {
998: if ($item eq 'cloners') {
999: my @fails;
1000: my %lt = &Apache::lonlocal::texthash (
1001: format => 'Invalid format',
1002: domain => 'Domain does not exist',
1003: newuser => 'LON-CAPA user(s) do(es) not exist.',
1004: );
1005: foreach my $error ('format','domain','newuser') {
1006: if (defined($disallowed->{$error})) {
1007: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
1008: $lt{$error};
1009: if ($error eq 'newuser') {
1010: $msg .= '<br />'.&mt('Please [_1]add the user(s)[_2] before returning to the [_3]Course Configuration[_2] to add as potential cloners.','<a href="/adm/createuser">','</a>','<a href="/adm/courseprefs">');
1011: }
1012: push(@fails,$msg);
1013: }
1014: }
1015: if (@fails) {
1016: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
1017: '</span>'.join('; ',@fails).'.<br />';
1018: }
1019: } elsif ($item eq 'rolenames') {
1020: my %lt = &Apache::lonlocal::texthash (
1021: replacements => 'Name already used to replace a different standard role name',
1022: regulars => 'Name already used as a standard role name',
1023: customrole => 'Name already used as the name of a custom role',
1024: );
1025: my @fails;
1026: foreach my $error ('replacements','regulars','customrole') {
1027: if (ref($disallowed->{$error}) eq 'ARRAY') {
1028: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
1029: '</b>, '.&mt('reason').' - '.$lt{'error'});
1030: }
1031: }
1032: if (@fails) {
1033: $output .= '<span class="LC_warning">'.
1034: &mt('Unable to include amongst replacements for role names: ').
1035: '</span>'.join('; ',@fails).'.<br />';
1036: }
1037:
1038: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
1039: $output .= '<span class="LC_warning">';
1040: if ($item eq 'feedback') {
1041: $output .= &mt('Unable to include as a recipient of course feedback for:');
1042: } elsif ($item eq 'discussion') {
1043: $output .= &mt('Unable to include in user-based access control for:');
1044: } elsif ($item eq 'localization') {
1045: $output .= &mt('Unable to include in course localization:');
1046: }
1047: $output .= '</span><ul>';
1048: foreach my $key (sort(keys(%{$disallowed}))) {
1049: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
1050: $output .= '<li><i>'.$itemtext.'</i> - ';
1051: if ($item eq 'localization') {
1052: $output .= &mt('reason - unsupported language: [_1]',
1053: '<b>'.$disallowed->{$key}.'</b>');
1054: } else {
1055: $output .= &mt('reason - invalid user: [_1]',
1056: '<b>'.$disallowed->{$key}.'</b>').'</li>';
1057: }
1058: }
1059: $output .= '</ul><br />';
1060: }
1061: }
1.1 raeburn 1062: }
1.3 raeburn 1063: return $output;
1.1 raeburn 1064: }
1065:
1066: sub get_course {
1067: my ($courseid) = @_;
1068: if (!defined($courseid)) {
1069: $courseid = $env{'request.course.id'};
1070: }
1071: my $cdom=$env{'course.'.$courseid.'.domain'};
1072: my $cnum=$env{'course.'.$courseid.'.num'};
1073: return ($cnum,$cdom);
1074: }
1075:
1076: sub get_jscript {
1.3 raeburn 1077: my ($cdom,$phase) = @_;
1.1 raeburn 1078: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom);
1079: my ($jscript,$categorize_js);
1080: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
1081: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 1082: my $cloners_js = &cloners_javascript($phase);
1.1 raeburn 1083: if ($can_categorize) {
1084: $categorize_js = <<ENDSCRIPT;
1085: function catsbrowser() {
1086: var catswin = null;
1087: var url = '/adm/courseprefs?phase=categorizecourse';
1088: if (!catswin || catswin.closed) {
1089: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1090: } else {
1091: catswin.focus();
1092: }
1093: }
1094: ENDSCRIPT
1095: }
1096: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.3 raeburn 1097: $browse_js."\n".$categorize_js."\n".$cloners_js."\n".'</script>'.
1098: "\n".$stubrowse_js."\n";
1.1 raeburn 1099: return $jscript;
1100: }
1101:
1.3 raeburn 1102: sub cloners_javascript {
1103: my ($formname) = @_;
1104: return <<"ENDSCRIPT";
1105:
1106: function update_cloners(caller,num) {
1107: var delidx = getIndexByName('cloners_delete');
1108: var actidx = getIndexByName('cloners_activate');
1109: if (caller == 'cloners_all') {
1110: var selall;
1111: for (var i=0; i<document.$formname.cloners_all.length; i++) {
1112: if (document.$formname.cloners_all[i].checked) {
1113: selall = document.$formname.cloners_all[i].value;
1114: }
1115: }
1116: if (selall == 1) {
1117: if (delidx != -1) {
1118: if (document.$formname.cloners_delete.length) {
1119: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
1120: document.$formname.cloners_delete[j].checked = true;
1121: }
1122: } else {
1123: document.$formname.elements[delidx].checked = true;
1124: }
1125: }
1126: if (actidx != -1) {
1127: if (document.$formname.cloners_activate.length) {
1128: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
1129: if (document.$formname.cloners_activate[i].value == '0') {
1130: document.$formname.cloners_activate[i].checked = false;
1131: }
1132: if (document.$formname.cloners_activate[i].value == '') {
1133: document.$formname.cloners_activate[i].checked = true;
1134: }
1135: }
1136: }
1137: }
1138: document.$formname.cloners_newdom.selectedIndex = 0;
1139: }
1140: }
1141: if (caller == 'cloners_activate') {
1142: if (document.$formname.cloners_activate.length) {
1143: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
1144: if (document.$formname.cloners_activate[j].value == num) {
1145: if (document.$formname.cloners_activate[j].checked) {
1146: for (var i=0; i<document.$formname.cloners_all.length; i++) {
1147: if (document.$formname.cloners_all[i].value == '1') {
1148: document.$formname.cloners_all[i].checked = false;
1149: }
1150: if (document.$formname.cloners_all[i].value == '0') {
1151: document.$formname.cloners_all[i].checked = true;
1152: }
1153: }
1154: }
1155: }
1156: }
1157: } else {
1158: for (var i=0; i<document.$formname.cloners_all.length; i++) {
1159: if (document.$formname.cloners_all[i].value == '1') {
1160: document.$formname.cloners_all[i].checked = false;
1161: }
1162: if (document.$formname.cloners_all[i].value == '0') {
1163: document.$formname.cloners_all[i].checked = true;
1164: }
1165: }
1166: }
1167: }
1168: return;
1169: }
1170:
1171: function getIndexByName(item) {
1172: for (var i=0;i<document.$formname.elements.length;i++) {
1173: if (document.$formname.elements[i].name == item) {
1174: return i;
1175: }
1176: }
1177: return -1;
1178: }
1179:
1180: ENDSCRIPT
1181: }
1182:
1183:
1.1 raeburn 1184: sub print_courseinfo {
1.3 raeburn 1185: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
1186: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 1187: return;
1188: }
1189: my ($cathash,$categoriesform);
1190: my $crstype = &Apache::loncommon::course_type();
1191: my %domconf =
1192: &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1193: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1194: $cathash = $domconf{'coursecategories'}{'cats'};
1195: if (ref($cathash) eq 'HASH') {
1196: $categoriesform =
1197: &Apache::loncommon::assign_categories_table($cathash,
1198: $settings->{'categories'})."\n";
1199: }
1200: }
1201: if (!defined($categoriesform)) {
1202: $categoriesform = &mt('No categories defined for this domain');
1203: }
1204:
1205: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom);
1206:
1207: my %items = (
1.3 raeburn 1208: 'url' => {
1209: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.(' 'x2).
1.1 raeburn 1210: '<a href="javascript:openbrowser'.
1211: "('display','url','sequence')\">".
1212: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
1213: &mt('Modification may make assessment data inaccessible!').
1214: '</span>',
1215: input => 'textbox',
1216: size => '40',
1217: },
1218: 'description' => {
1.3 raeburn 1219: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 1220: input => 'textbox',
1221: size => '25',
1222: },
1223: 'courseid' => {
1.3 raeburn 1224: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
1225: &mt('internal, optional').')',
1.1 raeburn 1226: input => 'textbox',
1227: size => '25',
1228: },
1229: 'cloners' => {
1.3 raeburn 1230: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.1 raeburn 1231: &mt('Course Coordinators included automatically'),
1232: input => 'textbox',
1233: size => '40',
1234: },
1235: 'rolenames' => {
1.3 raeburn 1236: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.1 raeburn 1237: '('.&mt('To replace the standard title for a course role, enter a title, otherwise leave blank').')',
1238: input => 'textbox',
1239: size => '20',
1240: },
1241: 'externalsyllabus' => {
1.3 raeburn 1242: text => '<b>'.&mt($itemtext->{'externalsyllabus'}).'</b><br />('.
1243: &mt('not using syllabus template)'),
1.1 raeburn 1244: input => 'textbox',
1245: size => '40',
1246: },
1247: 'hidefromcat' => {
1.3 raeburn 1248: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 1249: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
1250: input => 'radio',
1251: },
1252: 'categories' => {
1.3 raeburn 1253: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 1254: &mt('Display Categories').'</a>',
1255: input => 'textbox',
1256: size => '25',
1257: },
1258: );
1259: my $datatable;
1260: my $count = 0;
1261: foreach my $item (@{$ordered}) {
1262: if ($item eq 'hidefromcat') {
1263: next if (!$can_toggle_cat);
1264: } elsif ($item eq 'categories') {
1265: next if (!$can_categorize);
1266: }
1267: $count ++;
1268: $datatable .= &item_table_row_start($items{$item}{text},$count);
1269: if ($items{$item}{input} eq 'radio') {
1270: $datatable .= &yesno_radio($item,$settings);
1271: } elsif ($item eq 'cloners') {
1272: my $includeempty = 1;
1273: my $num = 0;
1274: $datatable .= &Apache::loncommon::start_data_table().
1275: &Apache::loncommon::start_data_table_row().
1276: '<td><span class="LC_nobreak"><label>'.
1277: &mt('Any user in any domain:').
1278: ' <input type="radio" name="cloners_all" value="1" ';
1279: if ($settings->{$item} eq '*') {
1280: $datatable .= ' checked="checked" ';
1281: }
1282: $datatable .= 'onchange="javascript:update_cloners('.
1283: "'cloners_all'".');" />'.&mt('Yes').'</label>'.
1284: (' 'x2).'<input type="radio" name="cloners_all" value="0" ';
1285: if ($settings->{$item} ne '*') {
1286: $datatable .= ' checked="checked" ';
1287: }
1288: $datatable .= ' onchange="javascript:update_cloners('.
1289: "'cloners_all'".');"/>'.&mt('No').'</label></td>'.
1290: &Apache::loncommon::end_data_table_row().
1291: &Apache::loncommon::end_data_table().
1292: '<table><tr><td align="left">'.&mt('Or').
1293: '</td></tr></table>'.
1294: &Apache::loncommon::start_data_table();
1295: my @cloners;
1296: if ($settings->{$item} eq '') {
1297: $datatable .= &new_cloners_dom_row($cdom,'0');
1298: } elsif ($settings->{$item} ne '*') {
1299: my @entries = split(/,/,$settings->{$item});
1300: if (@entries > 0) {
1301: foreach my $entry (@entries) {
1302: my ($uname,$udom) = split(/:/,$entry);
1303: if ($uname eq '*') {
1304: $datatable .=
1305: &Apache::loncommon::start_data_table_row().
1.3 raeburn 1306: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.1 raeburn 1307: &mt('Domain:').'<b> '.$udom.
1308: '</b><input type="hidden" name="cloners_dom_'.$num.
1309: '" value="'.$udom.'" /></span><br />'.
1310: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.3 raeburn 1311: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');" />'.
1.1 raeburn 1312: &mt('Delete').'</label></span></td>'.
1313: &Apache::loncommon::end_data_table_row();
1314: $num ++;
1315: } else {
1316: push(@cloners,$entry);
1317: }
1318: }
1319: }
1320: }
1321: my $add_domtitle = &mt('Any user in additional domain:');
1322: if ($settings->{$item} eq '*') {
1323: $add_domtitle = &mt('Any user in specific domain:');
1324: } elsif ($settings->{$item} eq '') {
1325: $add_domtitle = &mt('Any user in other domain:');
1326: }
1327: my $cloners_str = join(',',@cloners);
1328: $datatable .= &Apache::loncommon::start_data_table_row().
1329: '<td align="left"><span class="LC_nobreak">'.
1330: $add_domtitle.'</span><br />'.
1331: &Apache::loncommon::select_dom_form('','cloners_newdom',
1332: $includeempty).
1333: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
1334: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 1335: &Apache::loncommon::end_data_table().
1336: '<table><tr><td align="left">'.&mt('And').
1337: '</td></tr></table>'.
1.1 raeburn 1338: &Apache::loncommon::start_data_table().
1339: &Apache::loncommon::start_data_table_row().
1340: '<td align="left">'.
1341: &mt('Specific users').' (<tt>'.
1342: &mt('user:domain,user:domain').'</tt>)<br />'.
1343: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1344: $items{$item}{'size'}).
1345: '</td>'.&Apache::loncommon::end_data_table_row().
1346: &Apache::loncommon::end_data_table();
1347: } elsif ($item eq 'rolenames') {
1348: $datatable .= &Apache::loncommon::start_data_table();
1349: foreach my $role ('cc','in','ta','ep','ad','st') {
1350: $datatable .= &Apache::loncommon::start_data_table_row().
1351: '<td align="left"><span class="LC_nobreak">'.
1352: &Apache::lonnet::plaintext($role,$crstype,undef,1).
1353: '</span></td><td align="left">'.
1354: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
1355: $settings->{$role.'.plaintext'},
1356: $items{$item}{size}).'</td>'.
1357: &Apache::loncommon::end_data_table_row();
1358: }
1359: $datatable .= &Apache::loncommon::end_data_table().'</td>';
1360: } elsif ($item eq 'categories') {
1.3 raeburn 1361: my $launcher = 'onFocus="this.blur();javascript:catsbrowser();";';
1362: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
1363: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
1364: $items{$item}{size},$launcher);
1.1 raeburn 1365: } else {
1366: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size});
1367: }
1368: $datatable .= &item_table_row_end();
1369: }
1370: $$rowtotal += scalar(@{$ordered});
1371: return $datatable;
1372: }
1373:
1374: sub new_cloners_dom_row {
1375: my ($newdom,$num) = @_;
1376: my $output;
1377: if ($newdom ne '') {
1378: $output .= &Apache::loncommon::start_data_table_row().
1379: '<td valign="top"><span class="LC_nobreak">'.
1380: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
1381: (' 'x2).'<label><input type="radio" '.
1382: 'name="cloners_activate" value="'.$num.'" '.
1.3 raeburn 1383: 'onchange="javascript:update_cloners('.
1.1 raeburn 1384: "'cloners_activate','$num'".');" />'.
1385: &mt('Yes').'</label>'.(' 'x2).
1386: '<label><input type="radio" '.
1387: 'name="cloners_activate" value="" checked="checked" '.
1.3 raeburn 1388: 'onchange="javascript:update_cloners('.
1.1 raeburn 1389: "'cloners_activate','$num'".');" />'.
1.3 raeburn 1390: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
1391: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 1392: &Apache::loncommon::end_data_table_row();
1393: }
1394: return $output;
1395: }
1396:
1397: sub can_modify_catsettings {
1398: my ($dom) = @_;
1399: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
1400: my ($can_toggle_cat,$can_categorize);
1401: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1402: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
1403: $can_toggle_cat = 1;
1404: }
1405: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
1406: $can_categorize = 1;
1407: }
1408: }
1409: return ($can_toggle_cat,$can_categorize);
1410: }
1411:
1412: sub assign_course_categories {
1413: my ($r) = @_;
1414: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1415: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1416: my $hascats = 0;
1417: my $cathash;
1418: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1419: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1420: $cathash = $domconf{'coursecategories'}{'cats'};
1421: if (ref($cathash) eq 'HASH') {
1422: $hascats = 1;
1423: }
1424: }
1425: my $catwin_js;
1426: if ($hascats) {
1427: my $alert = &mt('Use \"Save\" in the main window to save course categories');
1428: $catwin_js = <<ENDSCRIPT;
1429: <script type="text/javascript">
1430:
1431: function updateCategories() {
1432: var newcategories = '';
1433: var unescapedcats = '';
1434: if (document.chgcats.usecategory.length) {
1435: for (var i=0; i<document.chgcats.usecategory.length; i++) {
1436: if (document.chgcats.usecategory[i].checked == true) {
1437: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
1438: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
1439: }
1440: }
1441: if (newcategories.length > 0) {
1442: newcategories = newcategories.slice(0,-1);
1443: }
1444: if (unescapedcats.length > 0) {
1445: unescapedcats = unescapedcats.slice(0,-3);
1446: }
1447: } else {
1448: if (document.chgcats.usecategory.checked == true) {
1449: newcategories = document.chgcats.usecategory.value;
1450: unescapedcats = document.chgcats.catname.value;
1451: }
1452: }
1453: opener.document.display.categories.value = newcategories;
1454: opener.document.display.categories_display.value = unescapedcats;
1455: alert("$alert");
1456: self.close();
1457: return;
1458: }
1459:
1460: </script>
1461: ENDSCRIPT
1462: } else {
1463: my $onload;
1464: }
1465: my $start_page =
1466: &Apache::loncommon::start_page('Course Categories',$catwin_js,
1467: {'only_body' => 1,});
1468: my $end_page = &Apache::loncommon::end_page();
1469: my $categoriesform = '<h3>'.&mt('Categorize Course').'</h3>';
1470: if ($hascats) {
1471: my %currsettings =
1472: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1473: $categoriesform .= &mt('Assign one or more categories to this course.').'<br /><br />'.
1474: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
1475: &Apache::loncommon::assign_categories_table($cathash,
1476: $currsettings{'categories'})."\n".
1477: '<br /><input type="button" name="changes" value="'.
1478: &mt('Copy to main window').'" '.
1479: 'onclick="javascript:updateCategories()" /></form><br />';
1480: } else {
1481: $categoriesform .= &mt('No categories defined for this domain');
1482: }
1483: $r->print($start_page.$categoriesform.$end_page);
1484: return;
1485: }
1486:
1487: sub print_localization {
1.3 raeburn 1488: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
1489: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 1490: return;
1491: }
1492: my %items = (
1493: languages => {
1.3 raeburn 1494: text => &mt($itemtext->{'languages'}).'<br />'.
1495: &mt("(will override user's preference)"),
1.1 raeburn 1496: input => 'selectbox',
1497: },
1498: timezone => {
1.3 raeburn 1499: text => &mt($itemtext->{'timezone'}),
1.1 raeburn 1500: input => 'selectbox',
1501: },
1502: datelocale => {
1.3 raeburn 1503: text => &mt($itemtext->{'datelocale'}),
1.1 raeburn 1504: input => 'selectbox',
1505: },
1506: );
1507: my $datatable;
1508: my $count = 0;
1509: foreach my $item (@{$ordered}) {
1510: $count ++;
1511: $datatable .= &item_table_row_start($items{$item}{text},$count);
1512: if ($item eq 'timezone') {
1513: my $includeempty = 1;
1514: my $timezone = &Apache::lonlocal::gettimezone();
1515: $datatable .=
1516: &Apache::loncommon::select_timezone($item,$timezone,undef,
1517: $includeempty);
1518: } elsif ($item eq 'datelocale') {
1519: my $includeempty = 1;
1520: my $locale_obj = &Apache::lonlocal::getdatelocale();
1521: my $currdatelocale;
1522: if (ref($locale_obj)) {
1523: $currdatelocale = $locale_obj->id();
1524: }
1525: $datatable .=
1526: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1527: undef,$includeempty);
1528: } else {
1529: if ($settings->{$item} eq '') {
1530: $datatable .=
1.3 raeburn 1531: &Apache::loncommon::select_language('languages_0','',1);
1.1 raeburn 1532: } else {
1533: my $num = 0;
1.3 raeburn 1534: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.1 raeburn 1535: $datatable .= &Apache::loncommon::start_data_table();
1536: if (@languages > 0) {
1.3 raeburn 1537: my %langchoices = &get_lang_choices();
1.1 raeburn 1538: foreach my $lang (@languages) {
1539: my $showlang = $lang;
1.3 raeburn 1540: if (exists($langchoices{$lang})) {
1541: $showlang = $langchoices{$lang};
1.1 raeburn 1542: }
1543: $datatable .=
1544: &Apache::loncommon::start_data_table_row().
1.3 raeburn 1545: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 1546: &mt('Language:').'<b> '.$showlang.
1547: '</b><input type="hidden" name="languages_'.$num.
1548: '" value="'.$lang.'" /></span><br />'.
1549: '<span class="LC_nobreak"><label><input type="checkbox" '.
1550: 'name="languages_delete" value="'.$num.'" />'.
1551: &mt('Delete').'</label></span></td>'.
1.3 raeburn 1552: &Apache::loncommon::end_data_table_row();
1.1 raeburn 1553: $num ++;
1554: }
1555: }
1556: $datatable .= &Apache::loncommon::start_data_table_row().
1.3 raeburn 1557: '<td align="left"><span class="LC_nobreak">'.
1558: &mt('Additional language:'). '</span><br />'.
1559: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 1560: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1561: '</td>'.&Apache::loncommon::end_data_table_row().
1562: &Apache::loncommon::end_data_table();
1563: }
1564: }
1565: $datatable .= &item_table_row_end();
1566: }
1567: $$rowtotal += scalar(@{$ordered});
1568: return $datatable;
1569: }
1570:
1.3 raeburn 1571: sub get_lang_choices {
1572: my %langchoices;
1573: foreach my $id (&Apache::loncommon::languageids()) {
1574: my $code = &Apache::loncommon::supportedlanguagecode($id);
1575: if ($code) {
1576: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
1577: }
1578: }
1579: return %langchoices;
1580: }
1581:
1.1 raeburn 1582: sub print_feedback {
1.3 raeburn 1583: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
1584: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 1585: return;
1586: }
1587: my %items = (
1.3 raeburn 1588: 'question.email' => {
1589: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 1590: input => 'textbox',
1591: size => '50',
1592: },
1593:
1.3 raeburn 1594: 'comment.email' => {
1595: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 1596: input => 'textbox',
1597: size => '50',
1598: },
1599:
1.3 raeburn 1600: 'policy.email' => {
1601: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 1602: input => 'textbox',
1603: size => '50',
1604: },
1605: );
1606: my $datatable;
1607: my $count = 0;
1608: my ($cnum) = &get_course();
1609: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1610: my @sections = sort( { $a <=> $b } keys(%sections));
1611: my %lt = &Apache::lonlocal::texthash (
1612: currone => 'Current recipient:',
1613: curmult => 'Current recipients:',
1614: add => 'Additional recipient:',
1615: del => 'Delete?',
1616: sec => 'Sections:',
1617: );
1618:
1619: foreach my $item (@{$ordered}) {
1620: $count ++;
1621: $datatable .= &item_table_row_start($items{$item}{text},$count);
1622: if ($position eq 'top') {
1623: my $includeempty = 0;
1624: $datatable .= &user_table($cdom,$item,\@sections,
1.3 raeburn 1625: $settings->{$item},\%lt);
1.1 raeburn 1626: } else {
1.3 raeburn 1627: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1628: $settings->{$item.'.text'},$items{$item}{size});
1.1 raeburn 1629: }
1630: $datatable .= &item_table_row_end();
1631: }
1632: $$rowtotal += scalar(@{$ordered});
1633: return $datatable;
1634: }
1635:
1636: sub user_table {
1637: my ($cdom,$item,$sections,$currvalue,$lt) = @_;
1638: my $output;
1639: if ($currvalue eq '') {
1640: $output .= &select_recipient($item,'0',$cdom,$sections);
1641: } else {
1642: my $num = 0;
1643: my @curr = split(/,/,$currvalue);
1644: $output .= &Apache::loncommon::start_data_table();
1645: my ($currusers);
1646: foreach my $val (@curr) {
1647: next if ($val eq '');
1648: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
1649: my @selsec;
1650: if ($seclist) {
1651: $seclist =~ s/(^\(|\)$)//g;
1652: @selsec = split(/\s*;\s*/,$seclist);
1653: }
1654: $currusers .= '<tr>'.
1655: '<td valign="top"><span class="LC_nobreak">'.
1656: '<label><input type="checkbox" '.
1657: 'name="'.$item.'_delete" value="'.$num.'" />'.
1658: $lt->{'del'}.'</label>'.
1659: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 1660: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 1661: &Apache::loncommon::aboutmewrapper(
1662: &Apache::loncommon::plainname($uname,$udom,'firstname'),
1663: $uname,$udom,'aboutuser');
1664: if (ref($sections) eq 'ARRAY') {
1665: if (@{$sections}) {
1666: $currusers.= (' 'x3).$lt->{'sec'}.' '.
1667: &select_sections($item,$num,$sections,
1668: \@selsec);
1669: }
1670: }
1671: $currusers .= '</span></td></tr>';
1672: $num ++;
1673: }
1674: if ($num) {
1675: $output .= &Apache::loncommon::start_data_table_row().
1676: '<td align="left"><i>';
1677: if ($num > 1) {
1678: $output .= $lt->{'currone'};
1679: } else {
1680: $output .= $lt->{'currmult'};
1681: }
1682: $output .= '</i><br />'.
1683: '<table>'.$currusers.'</table></td>'.
1684: &Apache::loncommon::end_data_table_row();
1685: }
1686: $output .= &Apache::loncommon::start_data_table_row().
1687: '<td align="left"><span class="LC_nobreak"><i>'.
1688: $lt->{'add'}.'</i></span><br />'.
1689: &select_recipient($item,$num,$cdom,$sections).
1690: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.3 raeburn 1691: '</td>'.&Apache::loncommon::end_data_table_row().
1692: &Apache::loncommon::end_data_table();
1.1 raeburn 1693: }
1694: return $output;
1695: }
1696:
1697: sub select_recipient {
1698: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
1699: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
1700: my $selectlink =
1701: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1702: $item.'_udom_'.$num,1);
1.3 raeburn 1703: my $css_class = ($num % 2)?'LC_even_row':'LC_odd_row';
1.1 raeburn 1704: my $output =
1.3 raeburn 1705: '<table><tr class="'.$css_class.'"><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 1706: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
1707: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
1708: if (ref($sections) eq 'ARRAY') {
1709: if (@{$sections}) {
1710: $output .= '<td align="center">'.&mt('Sections').'<br />'.
1711: &select_sections($item,$num,$sections,$selected).'</td>';
1712: }
1713: }
1714: $output .= '<td valign="top">'.
1715: $selectlink.'</td></tr></table>';
1716: return $output;
1717: }
1718:
1719: sub select_sections {
1720: my ($item,$num,$sections,$selected) = @_;
1721: my ($output,@currsecs,$allsec);
1722: if (ref($selected) eq 'ARRAY') {
1723: @currsecs = @{$selected};
1724: }
1725: if (!@currsecs) {
1726: $allsec = ' selected="selected"';
1727: }
1728: if (ref($sections) eq 'ARRAY') {
1729: if (@{$sections}) {
1730: my $mult;
1731: if (@{$sections} > 1) {
1732: $mult = ' multiple="multiple"';
1733: if (@{$sections} > 3) {
1734: $mult .= ' size="4"';
1735: }
1736: }
1737: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.'>'.
1738: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
1739: foreach my $sec (@{$sections}) {
1740: my $is_sel;
1741: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
1742: $is_sel = 'selected="selected"';
1743: }
1744: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
1745: }
1746: $output .= '</select>';
1747: }
1748: }
1749: return $output;
1750: }
1751:
1752: sub print_discussion {
1.3 raeburn 1753: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
1754: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 1755: return;
1756: }
1757: my %items = (
1758: 'plc.roles.denied' => {
1.3 raeburn 1759: text => '<b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
1760: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").
1761: &mt('(roles-based)'),
1.1 raeburn 1762: input => 'checkbox',
1763: },
1764:
1765: 'plc.users.denied' => {
1.3 raeburn 1766: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
1767: &mt('(specific user(s))'),
1.1 raeburn 1768: input => 'checkbox',
1769: },
1770:
1771: 'pch.roles.denied' => {
1.3 raeburn 1772: text => '<b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
1773: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'<br />'.
1774: &mt('(role-based)'),
1.1 raeburn 1775: input => 'checkbox',
1776: },
1777:
1778: 'pch.users.denied' => {
1.3 raeburn 1779: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
1780: &mt('(specific user(s))'),
1.1 raeburn 1781: input => 'checkbox',
1782: },
1783: 'allow_limited_html_in_feedback' => {
1.3 raeburn 1784: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 1785: input => 'radio',
1786: },
1787:
1788: 'allow_discussion_post_editing' => {
1.3 raeburn 1789: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 1790: input => 'checkbox',
1791: },
1792: );
1793: my $datatable;
1794: my $count;
1795: my ($cnum) = &get_course();
1796: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1797: my @sections = sort( { $a <=> $b } keys(%sections));
1798: my %lt = &Apache::lonlocal::texthash (
1799: currone => 'Disallowed:',
1800: curmult => 'Disallowed:',
1801: add => 'Disallow more:',
1802: del => 'Delete?',
1803: sec => 'Sections:',
1804: );
1805:
1806: foreach my $item (@{$ordered}) {
1807: $count ++;
1808: $datatable .= &item_table_row_start($items{$item}{text},$count);
1809: if ($item eq 'plc.roles.denied') {
1810: $datatable .= '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings).
1811: '</table>';
1812: } elsif ($item eq 'plc.users.denied') {
1813: $datatable .= &user_table($cdom,$item,undef,
1814: $settings->{$item},\%lt);
1815: } elsif ($item eq 'pch.roles.denied') {
1816: $datatable .= '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings).
1817: '</table>';
1818: } elsif ($item eq 'pch.users.denied') {
1819: $datatable .= &user_table($cdom,$item,undef,
1820: $settings->{$item},\%lt);
1821: } elsif ($item eq 'allow_limited_html_in_feedback') {
1822: $datatable .= &yesno_radio($item,$settings);
1823: } elsif ($item eq 'allow_discussion_post_editing') {
1824: $datatable .= &Apache::loncommon::start_data_table().
1825: &Apache::loncommon::start_data_table_row().
1826: '<th align="left">'.&mt('Role').'</th><th>'.
1827: &mt('Sections').'</th>'.
1828: &Apache::loncommon::end_data_table_row().
1829: &role_checkboxes($cdom,$cnum,$item,$settings,1).
1830: &Apache::loncommon::end_data_table();
1831: }
1832: $datatable .= &item_table_row_end();
1833: }
1834: $$rowtotal += scalar(@{$ordered});
1835: return $datatable;
1836: }
1837:
1838: sub role_checkboxes {
1839: my ($cdom,$cnum,$item,$settings,$showsections) = @_;
1840: my @roles = ('st','ad','ta','ep','in','cc');
1841: my $output;
1842: my (@current,@curr_roles,%currsec,@sections);
1843: if ($showsections) {
1844: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1845: @sections = sort( { $a <=> $b } keys(%sections));
1846: }
1847: if (ref($settings) eq 'HASH') {
1848: if ($settings->{$item}) {
1849: @current = split(',',$settings->{$item});
1850: if ($showsections) {
1851: foreach my $role (@current) {
1852: if ($role =~ /:/) {
1853: my ($trole,$sec) = split(':',$role);
1854: push(@curr_roles,$trole);
1855: if (ref($currsec{$trole}) eq 'ARRAY') {
1856: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
1857: push(@{$currsec{$trole}},$sec);
1858: }
1.3 raeburn 1859: } else {
1860: $currsec{$trole} = [$sec];
1.1 raeburn 1861: }
1862: } else {
1863: push(@curr_roles,$role);
1864: }
1865: }
1866: @current = @curr_roles;
1867: }
1868: }
1869: }
1870: my $numinrow = 3;
1871: my $count = 0;
1872: foreach my $role (@roles) {
1873: my $checked = '';
1874: if (grep(/^\Q$role\E$/,@current)) {
1875: $checked = ' checked="checked" ';
1876: }
1877: my $plrole=&Apache::lonnet::plaintext($role);
1878: if ($showsections) {
1879: $output .= &Apache::loncommon::start_data_table_row();
1880: } else {
1881: my $rem = $count%($numinrow);
1882: if ($rem == 0) {
1883: if ($count > 0) {
1884: $output .= '</tr>';
1885: }
1886: $output .= '<tr>';
1887: }
1888: }
1889: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name='.
1890: $item.'" value="'.$role.'"'.$checked.'/> '.
1891: $plrole.'</label></span></td>';
1892: if ($showsections) {
1893: $output .= '<td align="left">'.
1894: &select_sections($item,$role,\@sections,$currsec{$role}).
1895: '</td></tr>';
1896: }
1897: $count ++;
1898: }
1899: my %adv_roles =
1900: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1901: my $total = @roles;
1902: foreach my $role (sort(keys(%adv_roles))) {
1903: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
1904: my $rolename = $3;
1905: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
1906: my $checked = '';
1907: if (grep(/^\Q$value\E$/,@current)) {
1908: $checked = ' checked="checked" ';
1909: }
1910: if ($showsections) {
1911: $output .= &Apache::loncommon::start_data_table_row();
1912: } else {
1913: my $rem = $count%($numinrow);
1914: if ($rem == 0) {
1915: if ($count > 0) {
1916: $output .= '</tr>';
1917: }
1918: $output .= '<tr>';
1919: }
1920: }
1921: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name='.
1922: $item.'" value="'.$value.'"'.$checked.' /> '.$rolename.
1923: '</label></span></td>';
1924: if ($showsections) {
1925: $output .= '<td>'.
1926: &select_sections($item,$role,\@sections,$currsec{$role}).
1927: '</td>'.&Apache::loncommon::end_data_table_row();
1928: }
1929: $total ++;
1930: $count ++;
1931: }
1932: }
1933: if (!$showsections) {
1934: my $rem = $total%($numinrow);
1935: my $colsleft = $numinrow - $rem;
1936: if ($colsleft > 1 ) {
1937: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1938: ' </td>';
1939: } elsif ($colsleft == 1) {
1940: $output .= '<td class="LC_left_item"> </td>';
1941: }
1942: $output .= '</tr>';
1943: }
1944: return $output;
1945: }
1946:
1947: sub print_classlists {
1.3 raeburn 1948: my ($position,$cdom,$settings,$itemtext,$rowtotal) = @_;
1.1 raeburn 1949: my @ordered;
1950: if ($position eq 'top') {
1951: @ordered = ('default_enrollment_start_date',
1952: 'default_enrollment_end_date');
1953: } elsif ($position eq 'middle') {
1954: @ordered = ('nothideprivileged');
1955: } else {
1956: @ordered = ('student_classlist_view',
1957: 'student_opt_in','student_classlist_portfiles');
1958: }
1959: my %items = (
1960: 'default_enrollment_start_date' => {
1.3 raeburn 1961: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 1962: input => 'dates',
1963: },
1964: 'default_enrollment_end_date' => {
1.3 raeburn 1965: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 1966: input => 'dates',
1967: },
1968:
1969: 'nothideprivileged' => {
1.3 raeburn 1970: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 1971: input => 'checkbox',
1972: },
1973:
1974: 'student_classlist_view' => {
1.3 raeburn 1975: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 1976: input => 'selectbox',
1977: options => {
1978: disabled => &mt('No viewable classlist'),
1979: section => &mt("Classlist of viewer's section"),
1980: all => &mt('Classlist of all students'),
1981: },
1982: order => ['disabled','all','section'],
1983: },
1984: 'student_opt_in' => {
1.3 raeburn 1985: text => '<b>'.&mt($itemtext->{'student_opt_in'}).'</b>',
1.1 raeburn 1986: input => 'radio',
1987: },
1988:
1989: 'student_classlist_portfiles' => {
1.3 raeburn 1990: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 1991: input => 'radio',
1992: },
1993: );
1994: unless (($settings->{'student_classlist_view'} eq 'all') ||
1995: ($settings->{'student_classlist_view'} eq 'section')) {
1996: $settings->{'student_classlist_view'} = 'disabled';
1997: }
1998: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal);
1999: }
2000:
2001: sub print_appearance {
1.3 raeburn 2002: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
2003: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2004: return;
2005: }
2006: my %items = (
2007: 'default_xml_style' => {
1.3 raeburn 2008: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 2009: '<a href="javascript:openbrowser'.
2010: "('display','default_xml_style'".
2011: ",'sty')".'">'.&mt('Select Style File').'</a>',
2012: input => 'textbox',
2013: size => 35,
2014: },
2015:
2016: 'pageseparators' => {
1.3 raeburn 2017: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 2018: input => 'radio',
2019: },
2020: 'disable_receipt_display' => {
1.3 raeburn 2021: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 2022: input => 'radio',
2023: },
2024: 'texengine' => {
1.3 raeburn 2025: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 2026: input => 'selectbox',
2027: options => {
2028: jsMath => 'jsMath',
2029: mimetex => &mt('Convert to Images'),
2030: tth => &mt('TeX to HTML'),
2031: },
2032: order => ['jsMath','mimetex','tth'],
2033: nullval => &mt("None specified - use student's choice"),
2034: },
2035: 'tthoptions' => {
1.3 raeburn 2036: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 2037: input => 'textbox',
2038: size => 40,
2039: },
2040: );
2041: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal);
2042: }
2043:
2044: sub print_grading {
1.3 raeburn 2045: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
2046: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2047: return;
2048: }
2049: my %items = (
2050: 'grading' => {
1.3 raeburn 2051: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 2052: &Apache::loncommon::help_open_topic('GradingOptions'),
2053: input => 'selectbox',
2054: options => {
2055: standard => &mt('Standard: shows points'),
2056: external => &mt('External: shows number of completed parts'),
2057: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
2058: },
2059: order => ['standard','external','spreadsheet'],
2060: },
2061: 'rndseed' => {
1.3 raeburn 2062: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.1 raeburn 2063: '<span class="LC_error">'.'<br />'.
2064: &mt('Modifying this will make problems have different numbers and answers!').
2065: '</span>',
2066: input => 'selectbox',
2067: options => {
2068: '32bit' => '32bit',
2069: '64bit' => '64bit',
2070: '64bit2' => '64bit2',
2071: '64bit3' => '64bit3',
2072: '64bit4' => '64bit4',
2073: '64bit5' => '64bit5',
2074: },
2075: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
2076: },
2077: 'receiptalg' => {
1.3 raeburn 2078: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.1 raeburn 2079: &mt('This controls how receipt numbers are generated.'),
2080: input => 'selectbox',
2081: options => {
2082: receipt => 'receipt',
2083: receipt2 => 'receipt2',
2084: receipt3 => 'receipt3',
2085: },
2086: order => ['receipt','receipt2','receipt3'],
2087: },
2088: 'disablesigfigs' => {
1.3 raeburn 2089: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 2090: input => 'radio',
2091: },
2092: );
2093: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal);
2094: }
2095:
2096: sub print_printouts {
1.3 raeburn 2097: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
2098: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2099: return;
2100: }
2101: my %items = (
2102: problem_stream_switch => {
1.3 raeburn 2103: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 2104: input => 'radio',
2105: },
2106: suppress_tries => {
1.3 raeburn 2107: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 2108: input => 'radio',
2109: },
2110: default_paper_size => {
1.3 raeburn 2111: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 2112: input => 'selectbox',
2113: options => {
2114: Letter => &mt('Letter').' [8 1/2x11 in]',
2115: Legal => &mt('Legal').' [8 1/2x14 in]',
2116: Tabloid => &mt('Tabloid').' [11x17 in]',
2117: Executive => &mt('Executive').' [7 1/2x10 in]',
2118: A2 => &mt('A2').' [420x594 mm]',
2119: A3 => &mt('A3').' [297x420 mm]',
2120: A4 => &mt('A4').' [210x297 mm]',
2121: A5 => &mt('A5').' [148x210 mm]',
2122: A6 => &mt('A6').' [105x148 mm]',
2123: },
2124: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
2125: nullval => 'None specified',
2126: },
2127: print_header_format => {
1.3 raeburn 2128: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 2129: input => 'checkbox',
2130: },
2131: disableexampointprint => {
1.3 raeburn 2132: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 2133: input => 'radio',
2134: },
2135: );
2136: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal);
2137: }
2138:
2139: sub print_spreadsheet {
1.3 raeburn 2140: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
2141: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2142: return;
2143: }
2144: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
2145: my %items = (
2146: spreadsheet_default_classcalc => {
1.3 raeburn 2147: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 2148: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
2149: "('display','spreadsheet_default_classcalc'".
2150: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
2151: input => 'textbox',
2152: },
2153: spreadsheet_default_studentcalc => {
1.3 raeburn 2154: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 2155: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
2156: "('display','spreadsheet_default_calc'".
2157: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
2158: input => 'textbox',
2159: },
2160: spreadsheet_default_assesscalc => {
1.3 raeburn 2161: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 2162: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
2163: "('display','spreadsheet_default_assesscalc'".
2164: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
2165: input => 'textbox',
2166: },
2167: hideemptyrows => {
1.3 raeburn 2168: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 2169: input => 'radio',
2170: },
2171: );
2172: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal);
2173: }
2174:
2175: sub print_bridgetasks {
1.3 raeburn 2176: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
2177: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2178: return;
2179: }
2180: my %items = (
2181: task_messages => {
1.3 raeburn 2182: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 2183: input => 'selectbox',
2184: options => {
2185: only_student => &mt('Send message to student'),
2186: student_and_user_notes_screen => &mt('Message to student and add to user notes'),
2187: },
2188: order => ['only_student','student_and_user_notes_screen'],
2189: nullval => &mt('No message or record in user notes'),
2190: },
2191: task_grading => {
1.3 raeburn 2192: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 2193: input => 'selectbox',
2194: options => {
2195: any => &mt('Grade BTs in any section'),
2196: section => &mt('Grade BTs only in own section')
2197: },
2198: order => ['any','section'],
2199: },
2200: suppress_embed_prompt => {
1.3 raeburn 2201: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
2202: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 2203: input => 'radio',
2204: },
2205: );
2206: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal);
2207: }
2208:
2209: sub print_other {
2210: my ($cdom,$settings,$allitems,$rowtotal) = @_;
2211: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
2212: return;
2213: }
1.3 raeburn 2214: my @ordered = &get_other_items($cdom,$settings,$allitems);
2215: my %items;
2216: foreach my $parameter (@ordered) {
2217: $items{$parameter} = {
2218: text => '<b>'.$parameter.'</b>',
2219: input => 'textbox',
2220: size => '15',
2221: },
2222: }
2223: push (@ordered,'newp_value');
2224: $items{'newp_value'} = {
2225: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
2226: '<input type="textbox" name="newp_name"'.
2227: ' value="" size="30" />',
2228: input => 'textbox',
2229: size => '30',
2230: };
2231: my $output = &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal);
2232: }
2233:
2234: sub get_other_items {
2235: my ($cdom,$settings,$allitems) = @_;
2236: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
2237: return;
2238: }
1.1 raeburn 2239: my @ordered;
2240: if (ref($settings) eq 'HASH') {
2241: foreach my $parameter (sort(keys(%{$settings}))) {
2242: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 2243: next if (($parameter eq 'course.helper.not.run') &&
2244: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 2245: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
2246: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
2247: || ($parameter eq 'type') ||
2248: ($parameter =~ m/^(cc|in|ta|ep|ad|st)\.plaintext$/)) {
2249: push(@ordered,$parameter);
2250: }
2251: }
2252: }
1.3 raeburn 2253: return @ordered;
1.1 raeburn 2254: }
2255:
2256: sub item_table_row_start {
2257: my ($text,$count) = @_;
2258: my $output;
2259: if ($count%2) {
2260: $output .= '<tr class="LC_odd_row">';
2261: } else {
2262: $output .= '<tr>';
2263: }
2264: $output .= '<td class="LC_left_item">'.$text.
1.3 raeburn 2265: '</td><td class="LC_right_item" align="right">';
1.1 raeburn 2266: return $output;
2267: }
2268:
2269: sub item_table_row_end {
2270: return '</td></tr>';
2271: }
2272:
2273: sub yesno_radio {
2274: my ($item,$settings) = @_;
2275: my $itemon = ' ';
2276: my $itemoff = ' checked="checked" ';
2277: if (ref($settings) eq 'HASH') {
2278: if ($settings->{$item} eq 'yes') {
2279: $itemon = $itemoff;
2280: $itemoff = ' ';
2281: }
2282: }
2283: return '<span class="LC_nobreak"><label>'.
2284: '<input type="radio" name="'.$item.'"'.
2285: $itemon.' value="yes" />'.&mt('Yes').'</label> '.
2286: '<label><input type="radio" name="'.$item.'"'.
2287: $itemoff.' value="" />'.&mt('No').'</label></span>';
2288: }
2289:
2290: sub select_from_options {
2291: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange) = @_;
2292: my $output;
2293: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
2294: $output='<select name="'.$item.'" '.$onchange;
2295: if ($multiple) {
2296: $output .= ' multiple="multiple"';
2297: my $num = @{$order};
2298: $num ++ if ($nullval ne '');
2299: if (($maxsize) && ($maxsize < $num)) {
2300: $output .= ' size="'.$maxsize.'"';
2301: }
2302: }
2303: $output .= '>'."\n";
2304: if ($nullval ne '') {
2305: $output .= '<option value=""';
2306: if (ref($curr) eq 'ARRAY') {
2307: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
2308: $output .= ' selected="selected" ';
2309: }
2310: } else {
2311: if ($curr eq '') {
2312: $output .= ' selected="selected" ';
2313: }
2314: }
2315: $output .= '>'.$nullval.'</option>';
2316: }
2317: foreach my $option (@{$order}) {
2318: $output.= '<option value="'.$option.'"';
2319: if (ref($curr) eq 'ARRAY') {
2320: if (grep(/^\Q$option\E$/,@{$curr})) {
2321: $output .= ' selected="selected" ';
2322: }
2323: } else {
2324: if ($option eq $curr) {
2325: $output.=' selected="selected"';
2326: }
2327: }
2328: $output.=">$options->{$option}</option>\n";
2329: }
2330: $output.="</select>";
2331: }
2332: return $output;
2333: }
2334:
2335: sub make_item_rows {
2336: my ($cdom,$items,$ordered,$settings,$rowtotal) = @_;
2337: my $datatable;
2338: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
2339: my $count = 0;
2340: foreach my $item (@{$ordered}) {
2341: $count ++;
2342: $datatable .= &item_table_row_start($items->{$item}{text},$count);
2343: if ($item eq 'nothideprivileged') {
2344: $datatable .= ¬hidepriv_row($cdom,$item,$settings);
2345: } elsif ($item eq 'print_header_format') {
2346: $datatable .= &print_hdrfmt_row($item,$settings);
2347: } elsif ($items->{$item}{input} eq 'dates') {
2348: $datatable .=
2349: &Apache::lonhtmlcommon::date_setter('display',$item,
2350: $settings->{$item});
2351: } elsif ($items->{$item}{input} eq 'radio') {
2352: $datatable .= &yesno_radio($item,$settings);
2353: } elsif ($items->{$item}{input} eq 'selectbox') {
2354: my $curr = $settings->{$item};
2355: $datatable .=
2356: &select_from_options($item,$items->{$item}{'order'},
2357: $items->{$item}{'options'},$curr,
2358: $items->{$item}{'nullval'});
2359: } elsif ($items->{$item}{input} eq 'textbox') {
2360: $datatable .=
2361: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
2362: $items->{$item}{size});
2363: }
2364: $datatable .= &item_table_row_end();
2365: }
2366: if (ref($rowtotal)) {
2367: $$rowtotal += scalar(@{$ordered});
2368: }
2369: }
2370: return $datatable;
2371: }
2372:
2373: sub nothidepriv_row {
2374: my ($cdom,$item,$settings) = @_;
2375: my ($cnum) = &get_course();
2376: my %nothide;
2377: my $datatable;
2378: if (ref($settings) eq 'HASH') {
2379: if ($settings->{$item} ne '') {
2380: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
2381: if ($user !~ /:/) {
2382: $nothide{join(':',split(/[\@]/,$user))}=1;
2383: } else {
2384: $nothide{$user} = 1;
2385: }
2386: }
2387: }
2388: }
2389: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
2390: my $now = time;
2391: my @privusers;
1.3 raeburn 2392: my %privileged;
1.1 raeburn 2393: foreach my $person (keys(%coursepersonnel)) {
2394: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
2395: $user =~ s/:$//;
2396: my ($end,$start) = split(/:/,$coursepersonnel{$person});
2397: if ($end == -1 || $start == -1) {
2398: next;
2399: }
2400: my ($uname,$udom) = split(':',$user);
1.3 raeburn 2401: unless (ref($privileged{$udom}) eq 'HASH') {
2402: my %dompersonnel = &Apache::lonnet::get_domain_roles($udom,['dc'],undef,$now);
2403: $privileged{$udom} = {};
2404: if (keys(%dompersonnel)) {
2405: foreach my $server (keys(%dompersonnel)) {
2406: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
2407: my ($trole,$uname,$udom) = split(/:/,$user);
2408: $privileged{$udom}{$uname} = $trole;
2409: }
2410: }
2411: }
2412: }
2413: if (exists($privileged{$udom}{$uname})) {
1.1 raeburn 2414: push(@privusers,$user);
2415: }
2416: }
2417: if (@privusers) {
2418: $datatable .= '<table align="right">';
2419: foreach my $user (sort(@privusers)) {
2420: my $hideon = ' checked="checked" ';
2421: my $hideoff = '';
2422: if ($nothide{$user}) {
2423: $hideoff = $hideon;
2424: $hideon = '';
2425: }
2426: my ($uname,$udom) = split(':',$user);
2427: $datatable .= '<tr><td align="left">'.
2428: &Apache::loncommon::aboutmewrapper(
2429: &Apache::loncommon::plainname($uname,$udom,'firstname'),
2430: $uname,$udom,'aboutuser').
2431: '</td><td align="left">'.
2432: '<span class="LC_nobreak"><label>'.
2433: '<input type="radio" name="'.$item.'_'.$user.'"'.
2434: $hideon.' value="yes" />'.&mt('Hidden').'</label> '.
2435: '<label><input type="radio" name="'.$item.'_'.$user.'"'. $hideoff.' value="" />'.&mt('Shown').'</label></span></td>'.
2436: '</tr>';
2437: }
2438: $datatable .= '</table>';
2439: } else {
2440: $datatable .= &mt('No Domain Coordinators have course roles');
2441: }
2442: return $datatable;
2443: }
2444:
2445: sub print_hdrfmt_row {
2446: my ($item,$settings) = @_;
2447: my @curr;
2448: my $currnum = 0;
2449: my $maxnum = 2;
2450: my $currstr;
2451: if ($settings->{$item} ne '') {
2452: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
2453: $settings->{$item}.'</tt></span></b><br />';
2454: my @current = split(/(%\d*[nca])/,$settings->{$item});
2455: foreach my $item (@current) {
2456: unless ($item eq '') {
2457: push(@curr,$item);
2458: }
2459: }
2460: $currnum = @curr;
2461: $maxnum += $currnum;
2462: }
2463:
2464: my $output = <<ENDJS;
2465:
2466: <script type="text/javascript" language="Javascript">
2467:
2468: function reOrder(chgnum) {
2469: var maxnum = $maxnum;
2470: var oldidx = 'printfmthdr_oldpos_'+chgnum;
2471: var newidx = 'printfmthdr_pos_'+chgnum;
2472: oldidx = getIndexByName(oldidx);
2473: newidx = getIndexByName(newidx);
2474: var oldpos = document.display.elements[oldidx].value;
2475: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
2476: document.display.elements[oldidx].value = newpos;
2477: var chgtype = 'up';
2478: if (newpos < oldpos) {
2479: chgtype = 'down';
2480: }
2481: for (var j=0; j<maxnum; j++) {
2482: if (j != chgnum) {
2483: oldidx = 'printfmthdr_oldpos_'+j;
2484: newidx = 'printfmthdr_pos_'+j;
2485: oldidx = getIndexByName(oldidx);
2486: newidx = getIndexByName(newidx);
2487: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
2488: var currsel = document.display.elements[newidx].selectedIndex;
2489: if (chgtype == 'up') {
2490: if ((currpos > oldpos) && (currpos <= newpos)) {
2491: document.display.elements[newidx].selectedIndex = currsel-1;
2492: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
2493: }
2494: } else {
2495: if ((currpos >= newpos) && (currpos < oldpos)) {
2496: document.display.elements[newidx].selectedIndex = currsel+1;
2497: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
2498: }
2499: }
2500: }
2501: }
2502: return;
2503: }
2504:
2505: function getIndexByName(item) {
2506: for (var i=0;i<document.display.elements.length;i++) {
2507: if (document.display.elements[i].name == item) {
2508: return i;
2509: }
2510: }
2511: return -1;
2512: }
2513:
2514: </script>
2515:
2516: ENDJS
2517: $output .= $currstr.&Apache::loncommon::start_data_table();
2518: if (@curr > 0) {
2519: for (my $i=0; $i<@curr; $i++) {
2520: my $pos = $i+1;
2521: $output .= &Apache::loncommon::start_data_table_row().
2522: '<td align="left"><span class="LC_nobreak">'.
2523: &position_selector($pos,$i,$maxnum).&mt('Delete:').
2524: '<input type="checkbox" name="printfmthdr_del_'.$i.
2525: '" /></span></td>';
2526: if ($curr[$i] =~ /^%\d*[nca]$/) {
2527: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
2528: $output .= '<td align="left">'.
2529: &substitution_selector($i,$subst,$limit).'</td>';
2530: } else {
2531: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
2532: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
2533: ' value="'.$curr[$i].'" size="25" /></td>';
2534: }
2535: $output .= &Apache::loncommon::end_data_table_row();
2536: }
2537: }
2538: my $pos = $currnum+1;
2539: $output .= &Apache::loncommon::start_data_table_row().
2540: '<td align="left"><span class="LC_nobreak">'.
2541: &position_selector($pos,$currnum,$maxnum).
2542: '<b>'.&mt('New').'</b></span></td><td align="left">'.
2543: &substitution_selector($currnum).'</td>'.
2544: &Apache::loncommon::end_data_table_row();
2545: $pos ++;
2546: $currnum ++;
2547: $output .= &Apache::loncommon::start_data_table_row().
2548: '<td align="left"><span class="LC_nobreak">'.
2549: &position_selector($pos,$currnum,$maxnum).
2550: '<b>'.&mt('New').'</b></span></td>'.
2551: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
2552: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 2553: '" value="" size ="25" />'.
2554: '<input type="hidden" name="printfmthdr_maxnum" value="'.
2555: $maxnum.'" /></td>'.
1.1 raeburn 2556: &Apache::loncommon::end_data_table_row().
2557: &Apache::loncommon::end_data_table();
2558: return $output;
2559: }
2560:
2561: sub position_selector {
2562: my ($pos,$num,$maxnum) = @_;
2563: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');">';
2564: for (my $j=1; $j<=$maxnum; $j++) {
2565: my $sel = '';
2566: if ($pos == $j) {
2567: $sel = ' selected="selected"';
2568: }
2569: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
2570: }
2571: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
2572: '" value="'.$pos.'" />';
2573: return $output;
2574: }
2575:
2576: sub substitution_selector {
2577: my ($num,$subst,$limit) = @_;
2578: my %lt = &Apache::lonlocal::texthash(
2579: n => 'student name',
2580: c => 'course ID',
2581: a => 'assignment note',
2582: );
2583: my $output .= &mt('Substitution').'<br />'.
2584: '<select name=""printfmthdr_sub__'.$num.'">';
2585: if ($subst eq '') {
2586: $output .= '<option value="" selected="selected"> </option>';
2587: }
2588: foreach my $field ('n','c','a') {
2589: my $sel ='';
2590: if ($subst eq $field) {
2591: $sel = ' selected="selected"';
2592: }
2593: $output .= '<option value="'.$field.'"'.$sel.'>'.
2594: $lt{$field}.'</option>';
2595: }
2596: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
2597: '<input type="textbox" name="printfmthdr_limit_'.$num.
2598: '" value="'.$limit.'" size="5" /></span>';
2599: return $output;
2600: }
2601:
2602: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>