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