Annotation of loncom/interface/courseprefs.pm, revision 1.18
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',
166: 'url','rolenames','cloners'],
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',
1312: },
1313: 'description' => {
1.3 raeburn 1314: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 1315: input => 'textbox',
1316: size => '25',
1317: },
1318: 'courseid' => {
1.3 raeburn 1319: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
1320: &mt('internal, optional').')',
1.1 raeburn 1321: input => 'textbox',
1322: size => '25',
1323: },
1324: 'cloners' => {
1.3 raeburn 1325: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.9 raeburn 1326: &mt('Coordinators included automatically'),
1.1 raeburn 1327: input => 'textbox',
1328: size => '40',
1329: },
1330: 'rolenames' => {
1.3 raeburn 1331: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 1332: '('.$replace.')',
1.1 raeburn 1333: input => 'textbox',
1334: size => '20',
1335: },
1336: 'externalsyllabus' => {
1.3 raeburn 1337: text => '<b>'.&mt($itemtext->{'externalsyllabus'}).'</b><br />('.
1338: &mt('not using syllabus template)'),
1.1 raeburn 1339: input => 'textbox',
1340: size => '40',
1341: },
1342: 'hidefromcat' => {
1.3 raeburn 1343: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 1344: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
1345: input => 'radio',
1346: },
1347: 'categories' => {
1.3 raeburn 1348: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 1349: &mt('Display Categories').'</a>',
1350: input => 'textbox',
1351: size => '25',
1352: },
1353: );
1354: my $datatable;
1355: my $count = 0;
1356: foreach my $item (@{$ordered}) {
1357: if ($item eq 'hidefromcat') {
1358: next if (!$can_toggle_cat);
1359: } elsif ($item eq 'categories') {
1360: next if (!$can_categorize);
1361: }
1362: $count ++;
1363: $datatable .= &item_table_row_start($items{$item}{text},$count);
1364: if ($items{$item}{input} eq 'radio') {
1365: $datatable .= &yesno_radio($item,$settings);
1366: } elsif ($item eq 'cloners') {
1367: my $includeempty = 1;
1368: my $num = 0;
1369: $datatable .= &Apache::loncommon::start_data_table().
1370: &Apache::loncommon::start_data_table_row().
1371: '<td><span class="LC_nobreak"><label>'.
1372: &mt('Any user in any domain:').
1373: ' <input type="radio" name="cloners_all" value="1" ';
1374: if ($settings->{$item} eq '*') {
1375: $datatable .= ' checked="checked" ';
1376: }
1377: $datatable .= 'onchange="javascript:update_cloners('.
1378: "'cloners_all'".');" />'.&mt('Yes').'</label>'.
1379: (' 'x2).'<input type="radio" name="cloners_all" value="0" ';
1380: if ($settings->{$item} ne '*') {
1381: $datatable .= ' checked="checked" ';
1382: }
1383: $datatable .= ' onchange="javascript:update_cloners('.
1384: "'cloners_all'".');"/>'.&mt('No').'</label></td>'.
1385: &Apache::loncommon::end_data_table_row().
1386: &Apache::loncommon::end_data_table().
1387: '<table><tr><td align="left">'.&mt('Or').
1388: '</td></tr></table>'.
1389: &Apache::loncommon::start_data_table();
1390: my @cloners;
1391: if ($settings->{$item} eq '') {
1392: $datatable .= &new_cloners_dom_row($cdom,'0');
1393: } elsif ($settings->{$item} ne '*') {
1394: my @entries = split(/,/,$settings->{$item});
1395: if (@entries > 0) {
1396: foreach my $entry (@entries) {
1397: my ($uname,$udom) = split(/:/,$entry);
1398: if ($uname eq '*') {
1399: $datatable .=
1400: &Apache::loncommon::start_data_table_row().
1.3 raeburn 1401: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.1 raeburn 1402: &mt('Domain:').'<b> '.$udom.
1403: '</b><input type="hidden" name="cloners_dom_'.$num.
1404: '" value="'.$udom.'" /></span><br />'.
1405: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.3 raeburn 1406: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');" />'.
1.1 raeburn 1407: &mt('Delete').'</label></span></td>'.
1408: &Apache::loncommon::end_data_table_row();
1409: $num ++;
1410: } else {
1411: push(@cloners,$entry);
1412: }
1413: }
1414: }
1415: }
1416: my $add_domtitle = &mt('Any user in additional domain:');
1417: if ($settings->{$item} eq '*') {
1418: $add_domtitle = &mt('Any user in specific domain:');
1419: } elsif ($settings->{$item} eq '') {
1420: $add_domtitle = &mt('Any user in other domain:');
1421: }
1422: my $cloners_str = join(',',@cloners);
1423: $datatable .= &Apache::loncommon::start_data_table_row().
1424: '<td align="left"><span class="LC_nobreak">'.
1425: $add_domtitle.'</span><br />'.
1426: &Apache::loncommon::select_dom_form('','cloners_newdom',
1427: $includeempty).
1428: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
1429: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 1430: &Apache::loncommon::end_data_table().
1431: '<table><tr><td align="left">'.&mt('And').
1432: '</td></tr></table>'.
1.1 raeburn 1433: &Apache::loncommon::start_data_table().
1434: &Apache::loncommon::start_data_table_row().
1435: '<td align="left">'.
1436: &mt('Specific users').' (<tt>'.
1437: &mt('user:domain,user:domain').'</tt>)<br />'.
1438: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1439: $items{$item}{'size'}).
1440: '</td>'.&Apache::loncommon::end_data_table_row().
1441: &Apache::loncommon::end_data_table();
1442: } elsif ($item eq 'rolenames') {
1443: $datatable .= &Apache::loncommon::start_data_table();
1.9 raeburn 1444: my @roles;
1445: if ($crstype eq 'Community') {
1446: @roles = ('co');
1447: } else {
1448: @roles = ('cc');
1449: }
1450: push (@roles,('in','ta','ep','ad','st'));
1451: foreach my $role (@roles) {
1.1 raeburn 1452: $datatable .= &Apache::loncommon::start_data_table_row().
1453: '<td align="left"><span class="LC_nobreak">'.
1454: &Apache::lonnet::plaintext($role,$crstype,undef,1).
1455: '</span></td><td align="left">'.
1456: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
1457: $settings->{$role.'.plaintext'},
1458: $items{$item}{size}).'</td>'.
1459: &Apache::loncommon::end_data_table_row();
1460: }
1461: $datatable .= &Apache::loncommon::end_data_table().'</td>';
1462: } elsif ($item eq 'categories') {
1.3 raeburn 1463: my $launcher = 'onFocus="this.blur();javascript:catsbrowser();";';
1464: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
1465: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
1466: $items{$item}{size},$launcher);
1.1 raeburn 1467: } else {
1468: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size});
1469: }
1470: $datatable .= &item_table_row_end();
1471: }
1472: $$rowtotal += scalar(@{$ordered});
1473: return $datatable;
1474: }
1475:
1476: sub new_cloners_dom_row {
1477: my ($newdom,$num) = @_;
1478: my $output;
1479: if ($newdom ne '') {
1480: $output .= &Apache::loncommon::start_data_table_row().
1481: '<td valign="top"><span class="LC_nobreak">'.
1482: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
1483: (' 'x2).'<label><input type="radio" '.
1484: 'name="cloners_activate" value="'.$num.'" '.
1.3 raeburn 1485: 'onchange="javascript:update_cloners('.
1.1 raeburn 1486: "'cloners_activate','$num'".');" />'.
1487: &mt('Yes').'</label>'.(' 'x2).
1488: '<label><input type="radio" '.
1489: 'name="cloners_activate" value="" checked="checked" '.
1.3 raeburn 1490: 'onchange="javascript:update_cloners('.
1.1 raeburn 1491: "'cloners_activate','$num'".');" />'.
1.3 raeburn 1492: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
1493: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 1494: &Apache::loncommon::end_data_table_row();
1495: }
1496: return $output;
1497: }
1498:
1499: sub can_modify_catsettings {
1.12 raeburn 1500: my ($dom,$crstype) = @_;
1.1 raeburn 1501: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
1502: my ($can_toggle_cat,$can_categorize);
1503: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 1504: if ($crstype eq 'Community') {
1505: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
1506: $can_toggle_cat = 1;
1507: }
1508: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
1509: $can_categorize = 1;
1510: }
1511: } else {
1512: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
1513: $can_toggle_cat = 1;
1514: }
1515: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
1516: $can_categorize = 1;
1517: }
1.1 raeburn 1518: }
1519: }
1520: return ($can_toggle_cat,$can_categorize);
1521: }
1522:
1523: sub assign_course_categories {
1.9 raeburn 1524: my ($r,$crstype) = @_;
1.1 raeburn 1525: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1526: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1527: my $hascats = 0;
1528: my $cathash;
1529: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1530: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1531: $cathash = $domconf{'coursecategories'}{'cats'};
1532: if (ref($cathash) eq 'HASH') {
1.12 raeburn 1533: foreach my $cat (keys(%{$cathash})) {
1534: next if ($cat eq 'instcode::0');
1535: unless ($crstype eq 'Community') {
1536: next if ($cat eq 'communities::0');
1537: }
1538: $hascats ++;
1539: }
1.1 raeburn 1540: }
1541: }
1542: my $catwin_js;
1543: if ($hascats) {
1.9 raeburn 1544: my $alert;
1545: if ($crstype eq 'Community') {
1546: $alert = &mt("Use 'Save' in the main window to save community categories");
1547: } else {
1548: $alert = &mt("Use 'Save' in the main window to save course categories");
1549: }
1.1 raeburn 1550: $catwin_js = <<ENDSCRIPT;
1551: <script type="text/javascript">
1552:
1553: function updateCategories() {
1554: var newcategories = '';
1555: var unescapedcats = '';
1556: if (document.chgcats.usecategory.length) {
1557: for (var i=0; i<document.chgcats.usecategory.length; i++) {
1558: if (document.chgcats.usecategory[i].checked == true) {
1559: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
1560: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
1561: }
1562: }
1563: if (newcategories.length > 0) {
1564: newcategories = newcategories.slice(0,-1);
1565: }
1566: if (unescapedcats.length > 0) {
1567: unescapedcats = unescapedcats.slice(0,-3);
1568: }
1569: } else {
1570: if (document.chgcats.usecategory.checked == true) {
1571: newcategories = document.chgcats.usecategory.value;
1572: unescapedcats = document.chgcats.catname.value;
1573: }
1574: }
1575: opener.document.display.categories.value = newcategories;
1576: opener.document.display.categories_display.value = unescapedcats;
1577: alert("$alert");
1578: self.close();
1579: return;
1580: }
1581:
1582: </script>
1583: ENDSCRIPT
1584: } else {
1585: my $onload;
1586: }
1.9 raeburn 1587: my ($crscat,$catcrs,$assign);
1588: if ($crstype eq 'Community') {
1589: $crscat = 'Community Categories';
1590: $catcrs = &mt('Categorize Community');
1591: $assign = &mt('Assign one or more categories to this community.')
1592: } else {
1593: $crscat = 'Course Categories';
1594: $catcrs = &mt('Categorize Course');
1595: $assign = &mt('Assign one or more categories to this course.')
1596: }
1.1 raeburn 1597: my $start_page =
1.9 raeburn 1598: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 1599: {'only_body' => 1,});
1600: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 1601: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 1602: if ($hascats) {
1603: my %currsettings =
1604: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 1605: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
1606: $currsettings{'categories'},$crstype);
1607: if ($cattable eq '') {
1608: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
1609: } else {
1610: $categoriesform .= $assign.'<br /><br />'.
1611: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
1612: $cattable."\n".
1613: '<br /><input type="button" name="changes" value="'.
1614: &mt('Copy to main window').'" '.
1615: 'onclick="javascript:updateCategories()" /></form><br />';
1616: }
1.1 raeburn 1617: } else {
1.12 raeburn 1618: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 1619: }
1620: $r->print($start_page.$categoriesform.$end_page);
1621: return;
1622: }
1623:
1624: sub print_localization {
1.3 raeburn 1625: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
1626: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 1627: return;
1628: }
1629: my %items = (
1630: languages => {
1.17 faziophi 1631: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
1632: &mt("(overrides individual user preference)"),
1.1 raeburn 1633: input => 'selectbox',
1634: },
1635: timezone => {
1.17 faziophi 1636: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 1637: input => 'selectbox',
1638: },
1639: datelocale => {
1.17 faziophi 1640: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 1641: input => 'selectbox',
1642: },
1643: );
1644: my $datatable;
1645: my $count = 0;
1646: foreach my $item (@{$ordered}) {
1647: $count ++;
1648: $datatable .= &item_table_row_start($items{$item}{text},$count);
1649: if ($item eq 'timezone') {
1650: my $includeempty = 1;
1651: my $timezone = &Apache::lonlocal::gettimezone();
1652: $datatable .=
1653: &Apache::loncommon::select_timezone($item,$timezone,undef,
1654: $includeempty);
1655: } elsif ($item eq 'datelocale') {
1656: my $includeempty = 1;
1657: my $locale_obj = &Apache::lonlocal::getdatelocale();
1658: my $currdatelocale;
1659: if (ref($locale_obj)) {
1660: $currdatelocale = $locale_obj->id();
1661: }
1662: $datatable .=
1663: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1664: undef,$includeempty);
1665: } else {
1666: if ($settings->{$item} eq '') {
1667: $datatable .=
1.3 raeburn 1668: &Apache::loncommon::select_language('languages_0','',1);
1.1 raeburn 1669: } else {
1670: my $num = 0;
1.3 raeburn 1671: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.1 raeburn 1672: $datatable .= &Apache::loncommon::start_data_table();
1673: if (@languages > 0) {
1.3 raeburn 1674: my %langchoices = &get_lang_choices();
1.1 raeburn 1675: foreach my $lang (@languages) {
1676: my $showlang = $lang;
1.3 raeburn 1677: if (exists($langchoices{$lang})) {
1678: $showlang = $langchoices{$lang};
1.1 raeburn 1679: }
1680: $datatable .=
1681: &Apache::loncommon::start_data_table_row().
1.3 raeburn 1682: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 1683: &mt('Language:').'<b> '.$showlang.
1684: '</b><input type="hidden" name="languages_'.$num.
1685: '" value="'.$lang.'" /></span><br />'.
1686: '<span class="LC_nobreak"><label><input type="checkbox" '.
1687: 'name="languages_delete" value="'.$num.'" />'.
1688: &mt('Delete').'</label></span></td>'.
1.3 raeburn 1689: &Apache::loncommon::end_data_table_row();
1.1 raeburn 1690: $num ++;
1691: }
1692: }
1693: $datatable .= &Apache::loncommon::start_data_table_row().
1.3 raeburn 1694: '<td align="left"><span class="LC_nobreak">'.
1695: &mt('Additional language:'). '</span><br />'.
1696: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 1697: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1698: '</td>'.&Apache::loncommon::end_data_table_row().
1699: &Apache::loncommon::end_data_table();
1700: }
1701: }
1702: $datatable .= &item_table_row_end();
1703: }
1704: $$rowtotal += scalar(@{$ordered});
1705: return $datatable;
1706: }
1707:
1.3 raeburn 1708: sub get_lang_choices {
1709: my %langchoices;
1710: foreach my $id (&Apache::loncommon::languageids()) {
1711: my $code = &Apache::loncommon::supportedlanguagecode($id);
1712: if ($code) {
1713: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
1714: }
1715: }
1716: return %langchoices;
1717: }
1718:
1.1 raeburn 1719: sub print_feedback {
1.3 raeburn 1720: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
1721: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 1722: return;
1723: }
1724: my %items = (
1.3 raeburn 1725: 'question.email' => {
1726: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 1727: input => 'textbox',
1728: size => '50',
1729: },
1730:
1.3 raeburn 1731: 'comment.email' => {
1732: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 1733: input => 'textbox',
1734: size => '50',
1735: },
1736:
1.3 raeburn 1737: 'policy.email' => {
1738: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 1739: input => 'textbox',
1740: size => '50',
1741: },
1742: );
1743: my $datatable;
1744: my $count = 0;
1745: my ($cnum) = &get_course();
1746: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1747: my @sections = sort( { $a <=> $b } keys(%sections));
1748: my %lt = &Apache::lonlocal::texthash (
1749: currone => 'Current recipient:',
1750: curmult => 'Current recipients:',
1751: add => 'Additional recipient:',
1752: del => 'Delete?',
1753: sec => 'Sections:',
1754: );
1755:
1756: foreach my $item (@{$ordered}) {
1757: $count ++;
1758: $datatable .= &item_table_row_start($items{$item}{text},$count);
1759: if ($position eq 'top') {
1760: my $includeempty = 0;
1761: $datatable .= &user_table($cdom,$item,\@sections,
1.3 raeburn 1762: $settings->{$item},\%lt);
1.1 raeburn 1763: } else {
1.3 raeburn 1764: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1765: $settings->{$item.'.text'},$items{$item}{size});
1.1 raeburn 1766: }
1767: $datatable .= &item_table_row_end();
1768: }
1769: $$rowtotal += scalar(@{$ordered});
1770: return $datatable;
1771: }
1772:
1773: sub user_table {
1774: my ($cdom,$item,$sections,$currvalue,$lt) = @_;
1775: my $output;
1776: if ($currvalue eq '') {
1777: $output .= &select_recipient($item,'0',$cdom,$sections);
1778: } else {
1779: my $num = 0;
1780: my @curr = split(/,/,$currvalue);
1.10 raeburn 1781: $output .= '<table class="LC_nested_outer">';
1.1 raeburn 1782: my ($currusers);
1783: foreach my $val (@curr) {
1784: next if ($val eq '');
1785: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
1786: my @selsec;
1787: if ($seclist) {
1788: $seclist =~ s/(^\(|\)$)//g;
1789: @selsec = split(/\s*;\s*/,$seclist);
1790: }
1791: $currusers .= '<tr>'.
1792: '<td valign="top"><span class="LC_nobreak">'.
1793: '<label><input type="checkbox" '.
1794: 'name="'.$item.'_delete" value="'.$num.'" />'.
1795: $lt->{'del'}.'</label>'.
1796: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 1797: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 1798: &Apache::loncommon::aboutmewrapper(
1799: &Apache::loncommon::plainname($uname,$udom,'firstname'),
1800: $uname,$udom,'aboutuser');
1801: if (ref($sections) eq 'ARRAY') {
1802: if (@{$sections}) {
1803: $currusers.= (' 'x3).$lt->{'sec'}.' '.
1804: &select_sections($item,$num,$sections,
1805: \@selsec);
1806: }
1807: }
1808: $currusers .= '</span></td></tr>';
1809: $num ++;
1810: }
1811: if ($num) {
1.10 raeburn 1812: $output .= '<tr>'.
1.1 raeburn 1813: '<td align="left"><i>';
1814: if ($num > 1) {
1815: $output .= $lt->{'currone'};
1816: } else {
1817: $output .= $lt->{'currmult'};
1818: }
1819: $output .= '</i><br />'.
1820: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 1821: '</tr>';
1.1 raeburn 1822: }
1.10 raeburn 1823: $output .= '<tr>'.
1.1 raeburn 1824: '<td align="left"><span class="LC_nobreak"><i>'.
1825: $lt->{'add'}.'</i></span><br />'.
1826: &select_recipient($item,$num,$cdom,$sections).
1827: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.10 raeburn 1828: '</td></tr></table>';
1.1 raeburn 1829: }
1830: return $output;
1831: }
1832:
1833: sub select_recipient {
1834: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
1835: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
1836: my $selectlink =
1837: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1838: $item.'_udom_'.$num,1);
1839: my $output =
1.10 raeburn 1840: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 1841: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
1842: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
1843: if (ref($sections) eq 'ARRAY') {
1844: if (@{$sections}) {
1845: $output .= '<td align="center">'.&mt('Sections').'<br />'.
1846: &select_sections($item,$num,$sections,$selected).'</td>';
1847: }
1848: }
1849: $output .= '<td valign="top">'.
1850: $selectlink.'</td></tr></table>';
1851: return $output;
1852: }
1853:
1854: sub select_sections {
1855: my ($item,$num,$sections,$selected) = @_;
1856: my ($output,@currsecs,$allsec);
1857: if (ref($selected) eq 'ARRAY') {
1858: @currsecs = @{$selected};
1859: }
1860: if (!@currsecs) {
1861: $allsec = ' selected="selected"';
1862: }
1863: if (ref($sections) eq 'ARRAY') {
1864: if (@{$sections}) {
1865: my $mult;
1866: if (@{$sections} > 1) {
1867: $mult = ' multiple="multiple"';
1868: if (@{$sections} > 3) {
1869: $mult .= ' size="4"';
1870: }
1871: }
1872: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.'>'.
1873: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
1874: foreach my $sec (@{$sections}) {
1875: my $is_sel;
1876: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
1877: $is_sel = 'selected="selected"';
1878: }
1879: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
1880: }
1881: $output .= '</select>';
1882: }
1883: }
1884: return $output;
1885: }
1886:
1887: sub print_discussion {
1.3 raeburn 1888: my ($cdom,$settings,$ordered,$itemtext,$rowtotal) = @_;
1889: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 1890: return;
1891: }
1892: my %items = (
1893: 'plc.roles.denied' => {
1.10 raeburn 1894: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
1895: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 1896: &mt('(role-based)'),
1.1 raeburn 1897: input => 'checkbox',
1898: },
1899:
1900: 'plc.users.denied' => {
1.3 raeburn 1901: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
1902: &mt('(specific user(s))'),
1.1 raeburn 1903: input => 'checkbox',
1904: },
1905:
1906: 'pch.roles.denied' => {
1.10 raeburn 1907: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
1908: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 1909: &mt('(role-based)'),
1.1 raeburn 1910: input => 'checkbox',
1911: },
1912:
1913: 'pch.users.denied' => {
1.3 raeburn 1914: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
1915: &mt('(specific user(s))'),
1.1 raeburn 1916: input => 'checkbox',
1917: },
1918: 'allow_limited_html_in_feedback' => {
1.3 raeburn 1919: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 1920: input => 'radio',
1921: },
1922:
1923: 'allow_discussion_post_editing' => {
1.3 raeburn 1924: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 1925: input => 'checkbox',
1926: },
1927: );
1928: my $datatable;
1929: my $count;
1930: my ($cnum) = &get_course();
1931: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1932: my @sections = sort( { $a <=> $b } keys(%sections));
1933: my %lt = &Apache::lonlocal::texthash (
1934: currone => 'Disallowed:',
1935: curmult => 'Disallowed:',
1936: add => 'Disallow more:',
1937: del => 'Delete?',
1938: sec => 'Sections:',
1939: );
1940:
1941: foreach my $item (@{$ordered}) {
1942: $count ++;
1943: $datatable .= &item_table_row_start($items{$item}{text},$count);
1944: if ($item eq 'plc.roles.denied') {
1945: $datatable .= '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings).
1946: '</table>';
1947: } elsif ($item eq 'plc.users.denied') {
1948: $datatable .= &user_table($cdom,$item,undef,
1949: $settings->{$item},\%lt);
1950: } elsif ($item eq 'pch.roles.denied') {
1951: $datatable .= '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings).
1952: '</table>';
1953: } elsif ($item eq 'pch.users.denied') {
1954: $datatable .= &user_table($cdom,$item,undef,
1955: $settings->{$item},\%lt);
1956: } elsif ($item eq 'allow_limited_html_in_feedback') {
1957: $datatable .= &yesno_radio($item,$settings);
1958: } elsif ($item eq 'allow_discussion_post_editing') {
1959: $datatable .= &Apache::loncommon::start_data_table().
1960: &Apache::loncommon::start_data_table_row().
1961: '<th align="left">'.&mt('Role').'</th><th>'.
1962: &mt('Sections').'</th>'.
1963: &Apache::loncommon::end_data_table_row().
1964: &role_checkboxes($cdom,$cnum,$item,$settings,1).
1965: &Apache::loncommon::end_data_table();
1966: }
1967: $datatable .= &item_table_row_end();
1968: }
1969: $$rowtotal += scalar(@{$ordered});
1970: return $datatable;
1971: }
1972:
1973: sub role_checkboxes {
1.9 raeburn 1974: my ($cdom,$cnum,$item,$settings,$showsections,$crstype) = @_;
1975: my @roles = ('st','ad','ta','ep','in');
1976: if ($crstype eq 'Community') {
1977: push(@roles,'co');
1978: } else {
1979: push(@roles,'cc');
1980: }
1.1 raeburn 1981: my $output;
1982: my (@current,@curr_roles,%currsec,@sections);
1983: if ($showsections) {
1984: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1985: @sections = sort( { $a <=> $b } keys(%sections));
1986: }
1987: if (ref($settings) eq 'HASH') {
1988: if ($settings->{$item}) {
1989: @current = split(',',$settings->{$item});
1990: if ($showsections) {
1991: foreach my $role (@current) {
1992: if ($role =~ /:/) {
1993: my ($trole,$sec) = split(':',$role);
1994: push(@curr_roles,$trole);
1995: if (ref($currsec{$trole}) eq 'ARRAY') {
1996: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
1997: push(@{$currsec{$trole}},$sec);
1998: }
1.3 raeburn 1999: } else {
2000: $currsec{$trole} = [$sec];
1.1 raeburn 2001: }
2002: } else {
2003: push(@curr_roles,$role);
2004: }
2005: }
2006: @current = @curr_roles;
2007: }
2008: }
2009: }
2010: my $numinrow = 3;
2011: my $count = 0;
2012: foreach my $role (@roles) {
2013: my $checked = '';
2014: if (grep(/^\Q$role\E$/,@current)) {
2015: $checked = ' checked="checked" ';
2016: }
1.9 raeburn 2017: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 2018: if ($showsections) {
2019: $output .= &Apache::loncommon::start_data_table_row();
2020: } else {
2021: my $rem = $count%($numinrow);
2022: if ($rem == 0) {
2023: if ($count > 0) {
2024: $output .= '</tr>';
2025: }
2026: $output .= '<tr>';
2027: }
2028: }
2029: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name='.
2030: $item.'" value="'.$role.'"'.$checked.'/> '.
2031: $plrole.'</label></span></td>';
2032: if ($showsections) {
2033: $output .= '<td align="left">'.
2034: &select_sections($item,$role,\@sections,$currsec{$role}).
2035: '</td></tr>';
2036: }
2037: $count ++;
2038: }
2039: my %adv_roles =
2040: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
2041: my $total = @roles;
2042: foreach my $role (sort(keys(%adv_roles))) {
2043: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
2044: my $rolename = $3;
2045: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
2046: my $checked = '';
2047: if (grep(/^\Q$value\E$/,@current)) {
2048: $checked = ' checked="checked" ';
2049: }
2050: if ($showsections) {
2051: $output .= &Apache::loncommon::start_data_table_row();
2052: } else {
2053: my $rem = $count%($numinrow);
2054: if ($rem == 0) {
2055: if ($count > 0) {
2056: $output .= '</tr>';
2057: }
2058: $output .= '<tr>';
2059: }
2060: }
2061: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name='.
2062: $item.'" value="'.$value.'"'.$checked.' /> '.$rolename.
2063: '</label></span></td>';
2064: if ($showsections) {
2065: $output .= '<td>'.
2066: &select_sections($item,$role,\@sections,$currsec{$role}).
2067: '</td>'.&Apache::loncommon::end_data_table_row();
2068: }
2069: $total ++;
2070: $count ++;
2071: }
2072: }
2073: if (!$showsections) {
2074: my $rem = $total%($numinrow);
2075: my $colsleft = $numinrow - $rem;
2076: if ($colsleft > 1 ) {
2077: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2078: ' </td>';
2079: } elsif ($colsleft == 1) {
2080: $output .= '<td class="LC_left_item"> </td>';
2081: }
2082: $output .= '</tr>';
2083: }
2084: return $output;
2085: }
2086:
2087: sub print_classlists {
1.9 raeburn 2088: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype) = @_;
1.1 raeburn 2089: my @ordered;
2090: if ($position eq 'top') {
2091: @ordered = ('default_enrollment_start_date',
2092: 'default_enrollment_end_date');
2093: } elsif ($position eq 'middle') {
2094: @ordered = ('nothideprivileged');
2095: } else {
2096: @ordered = ('student_classlist_view',
2097: 'student_opt_in','student_classlist_portfiles');
2098: }
1.9 raeburn 2099: my %lt;
2100:
2101: if ($crstype eq 'Community') {
2102: %lt = &Apache::lonlocal::texthash (
2103: disabled => 'No viewable membership list',
2104: section => "Membership of viewer's section",
2105: all => 'List of all members',
2106: );
2107: } else {
2108: %lt = &Apache::lonlocal::texthash (
2109: disabled => 'No viewable classlist',
2110: section => "Classlist of viewer's section",
2111: all => 'Classlist of all students',
2112: );
2113: }
2114:
1.1 raeburn 2115: my %items = (
2116: 'default_enrollment_start_date' => {
1.3 raeburn 2117: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 2118: input => 'dates',
2119: },
2120: 'default_enrollment_end_date' => {
1.3 raeburn 2121: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 2122: input => 'dates',
2123: },
2124:
2125: 'nothideprivileged' => {
1.3 raeburn 2126: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 2127: input => 'checkbox',
2128: },
2129:
2130: 'student_classlist_view' => {
1.3 raeburn 2131: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 2132: input => 'selectbox',
1.9 raeburn 2133: options => \%lt,
1.1 raeburn 2134: order => ['disabled','all','section'],
2135: },
2136: 'student_opt_in' => {
1.3 raeburn 2137: text => '<b>'.&mt($itemtext->{'student_opt_in'}).'</b>',
1.1 raeburn 2138: input => 'radio',
2139: },
2140:
2141: 'student_classlist_portfiles' => {
1.3 raeburn 2142: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 2143: input => 'radio',
2144: },
2145: );
2146: unless (($settings->{'student_classlist_view'} eq 'all') ||
2147: ($settings->{'student_classlist_view'} eq 'section')) {
2148: $settings->{'student_classlist_view'} = 'disabled';
2149: }
1.9 raeburn 2150: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype);
1.1 raeburn 2151: }
2152:
2153: sub print_appearance {
1.9 raeburn 2154: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype) = @_;
1.3 raeburn 2155: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2156: return;
2157: }
1.9 raeburn 2158: my $mathdef;
2159: if ($crstype eq 'Community') {
2160: $mathdef = &mt("None specified - use member's choice");
2161: } else {
2162: $mathdef = &mt("None specified - use student's choice");
2163: }
1.1 raeburn 2164: my %items = (
2165: 'default_xml_style' => {
1.3 raeburn 2166: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 2167: '<a href="javascript:openbrowser'.
2168: "('display','default_xml_style'".
2169: ",'sty')".'">'.&mt('Select Style File').'</a>',
2170: input => 'textbox',
2171: size => 35,
2172: },
2173:
2174: 'pageseparators' => {
1.3 raeburn 2175: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 2176: input => 'radio',
2177: },
2178: 'disable_receipt_display' => {
1.3 raeburn 2179: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 2180: input => 'radio',
2181: },
2182: 'texengine' => {
1.3 raeburn 2183: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 2184: input => 'selectbox',
2185: options => {
2186: jsMath => 'jsMath',
2187: mimetex => &mt('Convert to Images'),
2188: tth => &mt('TeX to HTML'),
2189: },
2190: order => ['jsMath','mimetex','tth'],
1.9 raeburn 2191: nullval => $mathdef,
1.1 raeburn 2192: },
2193: 'tthoptions' => {
1.3 raeburn 2194: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 2195: input => 'textbox',
2196: size => 40,
2197: },
2198: );
1.9 raeburn 2199: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype);
1.1 raeburn 2200: }
2201:
2202: sub print_grading {
1.9 raeburn 2203: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype) = @_;
1.3 raeburn 2204: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2205: return;
2206: }
2207: my %items = (
2208: 'grading' => {
1.3 raeburn 2209: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 2210: &Apache::loncommon::help_open_topic('GradingOptions'),
2211: input => 'selectbox',
2212: options => {
2213: standard => &mt('Standard: shows points'),
1.11 www 2214: external => &mt('External: shows number of completed parts and totals'),
2215: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 2216: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
2217: },
1.11 www 2218: order => ['standard','external','externalnototals','spreadsheet'],
1.1 raeburn 2219: },
2220: 'rndseed' => {
1.3 raeburn 2221: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 2222: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 2223: &mt('Modifying this will make problems have different numbers and answers!').
2224: '</span>',
2225: input => 'selectbox',
2226: options => {
2227: '32bit' => '32bit',
2228: '64bit' => '64bit',
2229: '64bit2' => '64bit2',
2230: '64bit3' => '64bit3',
2231: '64bit4' => '64bit4',
2232: '64bit5' => '64bit5',
2233: },
2234: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
2235: },
2236: 'receiptalg' => {
1.3 raeburn 2237: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 2238: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 2239: input => 'selectbox',
2240: options => {
2241: receipt => 'receipt',
2242: receipt2 => 'receipt2',
2243: receipt3 => 'receipt3',
2244: },
2245: order => ['receipt','receipt2','receipt3'],
2246: },
2247: 'disablesigfigs' => {
1.3 raeburn 2248: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 2249: input => 'radio',
2250: },
2251: );
1.9 raeburn 2252: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype);
1.1 raeburn 2253: }
2254:
2255: sub print_printouts {
1.9 raeburn 2256: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype) = @_;
1.3 raeburn 2257: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2258: return;
2259: }
2260: my %items = (
2261: problem_stream_switch => {
1.3 raeburn 2262: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 2263: input => 'radio',
2264: },
2265: suppress_tries => {
1.3 raeburn 2266: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 2267: input => 'radio',
2268: },
2269: default_paper_size => {
1.3 raeburn 2270: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 2271: input => 'selectbox',
2272: options => {
2273: Letter => &mt('Letter').' [8 1/2x11 in]',
2274: Legal => &mt('Legal').' [8 1/2x14 in]',
2275: Tabloid => &mt('Tabloid').' [11x17 in]',
2276: Executive => &mt('Executive').' [7 1/2x10 in]',
2277: A2 => &mt('A2').' [420x594 mm]',
2278: A3 => &mt('A3').' [297x420 mm]',
2279: A4 => &mt('A4').' [210x297 mm]',
2280: A5 => &mt('A5').' [148x210 mm]',
2281: A6 => &mt('A6').' [105x148 mm]',
2282: },
2283: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
2284: nullval => 'None specified',
2285: },
2286: print_header_format => {
1.3 raeburn 2287: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 2288: input => 'checkbox',
2289: },
2290: disableexampointprint => {
1.3 raeburn 2291: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 2292: input => 'radio',
2293: },
1.14 raeburn 2294: canuse_pdfforms => {
2295: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
2296: input => 'selectbox',
2297: options => {
2298: 1 => &mt('Yes'),
2299: 0 => &mt('No'),
2300: },
2301: order => ['1','0'],
2302: nullval => 'None specified - use domain default',
2303: }
1.1 raeburn 2304: );
1.9 raeburn 2305: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype);
1.1 raeburn 2306: }
2307:
2308: sub print_spreadsheet {
1.9 raeburn 2309: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype) = @_;
1.3 raeburn 2310: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2311: return;
2312: }
2313: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
2314: my %items = (
2315: spreadsheet_default_classcalc => {
1.3 raeburn 2316: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 2317: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
2318: "('display','spreadsheet_default_classcalc'".
2319: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
2320: input => 'textbox',
2321: },
2322: spreadsheet_default_studentcalc => {
1.3 raeburn 2323: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 2324: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
2325: "('display','spreadsheet_default_calc'".
2326: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
2327: input => 'textbox',
2328: },
2329: spreadsheet_default_assesscalc => {
1.3 raeburn 2330: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 2331: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
2332: "('display','spreadsheet_default_assesscalc'".
2333: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
2334: input => 'textbox',
2335: },
2336: hideemptyrows => {
1.3 raeburn 2337: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 2338: input => 'radio',
2339: },
2340: );
1.9 raeburn 2341: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype);
2342: }
1.1 raeburn 2343:
2344: sub print_bridgetasks {
1.9 raeburn 2345: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype) = @_;
1.3 raeburn 2346: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2347: return;
2348: }
1.9 raeburn 2349: my ($stumsg,$msgnote);
2350: if ($crstype eq 'Community') {
2351: $stumsg = &mt('Send message to member');
2352: $msgnote = &mt('Message to member and add to user notes');
2353: } else {
2354: $stumsg = &mt('Send message to student');
2355: $msgnote = &mt('Message to student and add to user notes');
2356: }
1.1 raeburn 2357: my %items = (
2358: task_messages => {
1.3 raeburn 2359: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 2360: input => 'selectbox',
2361: options => {
1.9 raeburn 2362: only_student => $stumsg,
2363: student_and_user_notes_screen => $msgnote,
1.1 raeburn 2364: },
2365: order => ['only_student','student_and_user_notes_screen'],
2366: nullval => &mt('No message or record in user notes'),
2367: },
2368: task_grading => {
1.3 raeburn 2369: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 2370: input => 'selectbox',
2371: options => {
2372: any => &mt('Grade BTs in any section'),
2373: section => &mt('Grade BTs only in own section')
2374: },
2375: order => ['any','section'],
2376: },
2377: suppress_embed_prompt => {
1.3 raeburn 2378: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
2379: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 2380: input => 'radio',
2381: },
2382: );
1.9 raeburn 2383: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype);
1.1 raeburn 2384: }
2385:
2386: sub print_other {
1.9 raeburn 2387: my ($cdom,$settings,$allitems,$rowtotal,$crstype) = @_;
1.1 raeburn 2388: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
2389: return;
2390: }
1.3 raeburn 2391: my @ordered = &get_other_items($cdom,$settings,$allitems);
2392: my %items;
2393: foreach my $parameter (@ordered) {
2394: $items{$parameter} = {
2395: text => '<b>'.$parameter.'</b>',
2396: input => 'textbox',
2397: size => '15',
2398: },
2399: }
2400: push (@ordered,'newp_value');
2401: $items{'newp_value'} = {
2402: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
2403: '<input type="textbox" name="newp_name"'.
2404: ' value="" size="30" />',
2405: input => 'textbox',
2406: size => '30',
2407: };
1.9 raeburn 2408: my $output = &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype);
1.3 raeburn 2409: }
2410:
2411: sub get_other_items {
2412: my ($cdom,$settings,$allitems) = @_;
2413: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
2414: return;
2415: }
1.1 raeburn 2416: my @ordered;
2417: if (ref($settings) eq 'HASH') {
2418: foreach my $parameter (sort(keys(%{$settings}))) {
2419: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 2420: next if (($parameter eq 'course.helper.not.run') &&
2421: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 2422: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
2423: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
2424: || ($parameter eq 'type') ||
1.9 raeburn 2425: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)) {
1.1 raeburn 2426: push(@ordered,$parameter);
2427: }
2428: }
2429: }
1.3 raeburn 2430: return @ordered;
1.1 raeburn 2431: }
2432:
2433: sub item_table_row_start {
2434: my ($text,$count) = @_;
2435: my $output;
2436: if ($count%2) {
2437: $output .= '<tr class="LC_odd_row">';
2438: } else {
2439: $output .= '<tr>';
2440: }
2441: $output .= '<td class="LC_left_item">'.$text.
1.3 raeburn 2442: '</td><td class="LC_right_item" align="right">';
1.1 raeburn 2443: return $output;
2444: }
2445:
2446: sub item_table_row_end {
2447: return '</td></tr>';
2448: }
2449:
2450: sub yesno_radio {
2451: my ($item,$settings) = @_;
2452: my $itemon = ' ';
2453: my $itemoff = ' checked="checked" ';
2454: if (ref($settings) eq 'HASH') {
2455: if ($settings->{$item} eq 'yes') {
2456: $itemon = $itemoff;
2457: $itemoff = ' ';
2458: }
2459: }
2460: return '<span class="LC_nobreak"><label>'.
2461: '<input type="radio" name="'.$item.'"'.
2462: $itemon.' value="yes" />'.&mt('Yes').'</label> '.
2463: '<label><input type="radio" name="'.$item.'"'.
2464: $itemoff.' value="" />'.&mt('No').'</label></span>';
2465: }
2466:
2467: sub select_from_options {
2468: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange) = @_;
2469: my $output;
2470: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
2471: $output='<select name="'.$item.'" '.$onchange;
2472: if ($multiple) {
2473: $output .= ' multiple="multiple"';
2474: my $num = @{$order};
2475: $num ++ if ($nullval ne '');
2476: if (($maxsize) && ($maxsize < $num)) {
2477: $output .= ' size="'.$maxsize.'"';
2478: }
2479: }
2480: $output .= '>'."\n";
2481: if ($nullval ne '') {
2482: $output .= '<option value=""';
2483: if (ref($curr) eq 'ARRAY') {
2484: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
2485: $output .= ' selected="selected" ';
2486: }
2487: } else {
2488: if ($curr eq '') {
2489: $output .= ' selected="selected" ';
2490: }
2491: }
2492: $output .= '>'.$nullval.'</option>';
2493: }
2494: foreach my $option (@{$order}) {
2495: $output.= '<option value="'.$option.'"';
2496: if (ref($curr) eq 'ARRAY') {
2497: if (grep(/^\Q$option\E$/,@{$curr})) {
2498: $output .= ' selected="selected" ';
2499: }
2500: } else {
2501: if ($option eq $curr) {
2502: $output.=' selected="selected"';
2503: }
2504: }
2505: $output.=">$options->{$option}</option>\n";
2506: }
2507: $output.="</select>";
2508: }
2509: return $output;
2510: }
2511:
2512: sub make_item_rows {
1.9 raeburn 2513: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype) = @_;
1.1 raeburn 2514: my $datatable;
2515: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
2516: my $count = 0;
2517: foreach my $item (@{$ordered}) {
2518: $count ++;
2519: $datatable .= &item_table_row_start($items->{$item}{text},$count);
2520: if ($item eq 'nothideprivileged') {
1.9 raeburn 2521: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype);
1.1 raeburn 2522: } elsif ($item eq 'print_header_format') {
2523: $datatable .= &print_hdrfmt_row($item,$settings);
2524: } elsif ($items->{$item}{input} eq 'dates') {
2525: $datatable .=
2526: &Apache::lonhtmlcommon::date_setter('display',$item,
2527: $settings->{$item});
2528: } elsif ($items->{$item}{input} eq 'radio') {
2529: $datatable .= &yesno_radio($item,$settings);
2530: } elsif ($items->{$item}{input} eq 'selectbox') {
2531: my $curr = $settings->{$item};
2532: $datatable .=
2533: &select_from_options($item,$items->{$item}{'order'},
2534: $items->{$item}{'options'},$curr,
2535: $items->{$item}{'nullval'});
2536: } elsif ($items->{$item}{input} eq 'textbox') {
2537: $datatable .=
2538: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
2539: $items->{$item}{size});
2540: }
2541: $datatable .= &item_table_row_end();
2542: }
2543: if (ref($rowtotal)) {
2544: $$rowtotal += scalar(@{$ordered});
2545: }
2546: }
2547: return $datatable;
2548: }
2549:
2550: sub nothidepriv_row {
1.9 raeburn 2551: my ($cdom,$item,$settings,$crstype) = @_;
1.1 raeburn 2552: my ($cnum) = &get_course();
2553: my %nothide;
2554: my $datatable;
2555: if (ref($settings) eq 'HASH') {
2556: if ($settings->{$item} ne '') {
2557: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
2558: if ($user !~ /:/) {
2559: $nothide{join(':',split(/[\@]/,$user))}=1;
2560: } else {
2561: $nothide{$user} = 1;
2562: }
2563: }
2564: }
2565: }
2566: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
2567: my $now = time;
2568: my @privusers;
1.3 raeburn 2569: my %privileged;
1.1 raeburn 2570: foreach my $person (keys(%coursepersonnel)) {
2571: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
2572: $user =~ s/:$//;
2573: my ($end,$start) = split(/:/,$coursepersonnel{$person});
2574: if ($end == -1 || $start == -1) {
2575: next;
2576: }
2577: my ($uname,$udom) = split(':',$user);
1.3 raeburn 2578: unless (ref($privileged{$udom}) eq 'HASH') {
2579: my %dompersonnel = &Apache::lonnet::get_domain_roles($udom,['dc'],undef,$now);
2580: $privileged{$udom} = {};
2581: if (keys(%dompersonnel)) {
2582: foreach my $server (keys(%dompersonnel)) {
2583: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
2584: my ($trole,$uname,$udom) = split(/:/,$user);
2585: $privileged{$udom}{$uname} = $trole;
2586: }
2587: }
2588: }
2589: }
2590: if (exists($privileged{$udom}{$uname})) {
1.7 raeburn 2591: unless (grep(/^\Q$user\E$/,@privusers)) {
2592: push(@privusers,$user);
2593: }
1.1 raeburn 2594: }
2595: }
2596: if (@privusers) {
2597: $datatable .= '<table align="right">';
2598: foreach my $user (sort(@privusers)) {
2599: my $hideon = ' checked="checked" ';
2600: my $hideoff = '';
2601: if ($nothide{$user}) {
2602: $hideoff = $hideon;
2603: $hideon = '';
2604: }
2605: my ($uname,$udom) = split(':',$user);
2606: $datatable .= '<tr><td align="left">'.
2607: &Apache::loncommon::aboutmewrapper(
2608: &Apache::loncommon::plainname($uname,$udom,'firstname'),
2609: $uname,$udom,'aboutuser').
2610: '</td><td align="left">'.
2611: '<span class="LC_nobreak"><label>'.
2612: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.7 raeburn 2613: $hideon.' value="" />'.&mt('Hidden').'</label> '.
2614: '<label><input type="radio" name="'.$item.'_'.$user.'"'. $hideoff.' value="yes" />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 2615: '</tr>';
2616: }
2617: $datatable .= '</table>';
2618: } else {
1.9 raeburn 2619: if ($crstype eq 'Community') {
2620: $datatable .= &mt('No Domain Coordinators have community roles');
2621: } else {
2622: $datatable .= &mt('No Domain Coordinators have course roles');
2623: }
1.1 raeburn 2624: }
2625: return $datatable;
2626: }
2627:
2628: sub print_hdrfmt_row {
2629: my ($item,$settings) = @_;
2630: my @curr;
2631: my $currnum = 0;
2632: my $maxnum = 2;
2633: my $currstr;
2634: if ($settings->{$item} ne '') {
2635: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
2636: $settings->{$item}.'</tt></span></b><br />';
2637: my @current = split(/(%\d*[nca])/,$settings->{$item});
2638: foreach my $item (@current) {
2639: unless ($item eq '') {
2640: push(@curr,$item);
2641: }
2642: }
2643: $currnum = @curr;
2644: $maxnum += $currnum;
2645: }
2646:
2647: my $output = <<ENDJS;
2648:
2649: <script type="text/javascript" language="Javascript">
2650:
2651: function reOrder(chgnum) {
2652: var maxnum = $maxnum;
2653: var oldidx = 'printfmthdr_oldpos_'+chgnum;
2654: var newidx = 'printfmthdr_pos_'+chgnum;
2655: oldidx = getIndexByName(oldidx);
2656: newidx = getIndexByName(newidx);
2657: var oldpos = document.display.elements[oldidx].value;
2658: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
2659: document.display.elements[oldidx].value = newpos;
2660: var chgtype = 'up';
2661: if (newpos < oldpos) {
2662: chgtype = 'down';
2663: }
2664: for (var j=0; j<maxnum; j++) {
2665: if (j != chgnum) {
2666: oldidx = 'printfmthdr_oldpos_'+j;
2667: newidx = 'printfmthdr_pos_'+j;
2668: oldidx = getIndexByName(oldidx);
2669: newidx = getIndexByName(newidx);
2670: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
2671: var currsel = document.display.elements[newidx].selectedIndex;
2672: if (chgtype == 'up') {
2673: if ((currpos > oldpos) && (currpos <= newpos)) {
2674: document.display.elements[newidx].selectedIndex = currsel-1;
2675: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
2676: }
2677: } else {
2678: if ((currpos >= newpos) && (currpos < oldpos)) {
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: }
2683: }
2684: }
2685: return;
2686: }
2687:
2688: function getIndexByName(item) {
2689: for (var i=0;i<document.display.elements.length;i++) {
2690: if (document.display.elements[i].name == item) {
2691: return i;
2692: }
2693: }
2694: return -1;
2695: }
2696:
2697: </script>
2698:
2699: ENDJS
1.10 raeburn 2700: $output .= $currstr.'<table class="LC_nested_outer">';
1.1 raeburn 2701: if (@curr > 0) {
2702: for (my $i=0; $i<@curr; $i++) {
2703: my $pos = $i+1;
1.10 raeburn 2704: $output .= '<tr>'.
1.1 raeburn 2705: '<td align="left"><span class="LC_nobreak">'.
2706: &position_selector($pos,$i,$maxnum).&mt('Delete:').
2707: '<input type="checkbox" name="printfmthdr_del_'.$i.
2708: '" /></span></td>';
2709: if ($curr[$i] =~ /^%\d*[nca]$/) {
2710: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
2711: $output .= '<td align="left">'.
2712: &substitution_selector($i,$subst,$limit).'</td>';
2713: } else {
2714: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
2715: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
2716: ' value="'.$curr[$i].'" size="25" /></td>';
2717: }
1.10 raeburn 2718: $output .= '</tr>';
1.1 raeburn 2719: }
2720: }
2721: my $pos = $currnum+1;
1.10 raeburn 2722: $output .= '<tr>'.
1.1 raeburn 2723: '<td align="left"><span class="LC_nobreak">'.
2724: &position_selector($pos,$currnum,$maxnum).
2725: '<b>'.&mt('New').'</b></span></td><td align="left">'.
2726: &substitution_selector($currnum).'</td>'.
1.10 raeburn 2727: '</tr>';
1.1 raeburn 2728: $pos ++;
2729: $currnum ++;
1.10 raeburn 2730: $output .= '<tr>'.
1.1 raeburn 2731: '<td align="left"><span class="LC_nobreak">'.
2732: &position_selector($pos,$currnum,$maxnum).
2733: '<b>'.&mt('New').'</b></span></td>'.
2734: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
2735: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 2736: '" value="" size ="25" />'.
2737: '<input type="hidden" name="printfmthdr_maxnum" value="'.
2738: $maxnum.'" /></td>'.
1.10 raeburn 2739: '</tr>'.
2740: '</table>';
1.1 raeburn 2741: return $output;
2742: }
2743:
2744: sub position_selector {
2745: my ($pos,$num,$maxnum) = @_;
2746: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');">';
2747: for (my $j=1; $j<=$maxnum; $j++) {
2748: my $sel = '';
2749: if ($pos == $j) {
2750: $sel = ' selected="selected"';
2751: }
2752: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
2753: }
2754: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
2755: '" value="'.$pos.'" />';
2756: return $output;
2757: }
2758:
2759: sub substitution_selector {
1.9 raeburn 2760: my ($num,$subst,$limit,$crstype) = @_;
2761: my ($stunametxt,$crsidtxt);
2762: if ($crstype eq 'Community') {
2763: $stunametxt = 'member name';
2764: $crsidtxt = 'community ID',
2765: } else {
2766: $stunametxt = 'student name';
2767: $crsidtxt = 'course ID',
2768: }
1.1 raeburn 2769: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 2770: n => $stunametxt,
2771: c => $crsidtxt,
1.1 raeburn 2772: a => 'assignment note',
2773: );
2774: my $output .= &mt('Substitution').'<br />'.
2775: '<select name=""printfmthdr_sub__'.$num.'">';
2776: if ($subst eq '') {
2777: $output .= '<option value="" selected="selected"> </option>';
2778: }
2779: foreach my $field ('n','c','a') {
2780: my $sel ='';
2781: if ($subst eq $field) {
2782: $sel = ' selected="selected"';
2783: }
2784: $output .= '<option value="'.$field.'"'.$sel.'>'.
2785: $lt{$field}.'</option>';
2786: }
2787: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
2788: '<input type="textbox" name="printfmthdr_limit_'.$num.
2789: '" value="'.$limit.'" size="5" /></span>';
2790: return $output;
2791: }
2792:
2793: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>