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