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