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