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