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