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