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