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