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