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