Annotation of loncom/interface/courseprefs.pm, revision 1.99
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.99 ! raeburn 4: # $Id: courseprefs.pm,v 1.98 2022/02/01 18:23:24 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.23 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: courseprefs- Handler to set/modify course configuration
36:
37: =head1 SYNOPSIS
38:
39: courseprefs provides an interface for setting general course configuration
40:
41: =head1 DESCRIPTION
42:
43: This module is used for configuration of a course
44:
45: =head1 INTERNAL SUBROUTINES
46:
47: =over
48:
49: =item get_allitems()
50:
51: =item print_config_box()
52:
53: =item process_changes()
54:
55: =item get_sec_str()
56:
57: =item check_clone()
58:
59: =item store_changes()
60:
61: =item update_env()
62:
63: =item display_disallowed()
64:
65: =item get_course()
66:
67: =item get_jscript()
68:
69: =item cloners_javascript()
70:
71: =item print_courseinfo()
72:
73: =item new_cloners_dom_row()
74:
75: =item can_modify_catsettings()
76:
77: =item assign_course_categories()
78:
79: =item print_localization()
80:
81: =item get_lang_choices()
82:
83: =item print_feedback()
84:
85: =item user_table()
86:
87: =item select_recipient()
88:
89: =item select_sections()
90:
91: =item print_discussion()
92:
93: =item role_checkboxes()
94:
95: =item print_classlists()
96:
97: =item print_appearance()
98:
99: =item print_grading()
100:
101: =item print_printouts()
102:
103: =item print_spreadsheet()
104:
105: =item print_bridgetasks()
106:
107: =item print_other()
108:
109: =item get_other_items()
110:
111: =item item_table_row_start()
112:
113: =item item_table_row_end()
114:
115: =item yes_no_radio()
116:
117: =item select_from_options()
118:
119: =item make_item_rows()
120:
121: Creates table used to display and set course configuration items.
122:
123: Inputs: $cdom,$items,$ordered,$settings,$rowtotal,$crstype
124: where $cdom is course's domain, $items is HASH ref for current config
125: item, $ordered is ARRAY ref of items to include in row in
126: display order, $settings is HASH ref of current values forrow,
127: $rowtotal is SCALAR ref used to accumulate row count, $crstype is
128: course type.
129:
130: Returns: $datatable
131: HTML mark-up of data table which accumulates individual rows.
132:
133: =item nothidepriv_row()
134:
135: Creates row containing form elements used to display and set
136: whether Domain coordinators who are currently included in
137: advanced course user .db file for a course are to be hidden (e.g.,
138: in syllabus, or from course user lists).
139:
1.80 raeburn 140: Inputs: $cdom,$item,$settings,$crstype,$noedit
1.23 raeburn 141: where $cdom is course domain, item is nothideprivileged, $settings is
142: HASH ref of the current values for nothideprivileged, $crstype is
143: course type (Course or Community).
144:
145: Return: $datatable
146: HTML mark-up for Privileged users (Domain Coordinators) in staff listing.
147:
148: =item print_hdrfmt_row()
149:
150: Creates row containing form elements used to display and set
151: substitution items and text to be used in the header included
152: on printouts.
153:
154: Inputs: $item,$settings
155: where $item is print_header_format, and $settings is a HASH ref
156: of the current values stored for print_header_format.
157:
158: Returns: $output
159: HTML mark-up containing Javascript functions: reOrder() and getIndexByName()
160: used to dynamically update position selectboxes, and HTML table elements
161: for the "Print header format" row.
162:
163: =item position_selector()
164:
165: Creates a select box which can be used to reorder substitutions
166: and text included in a printout header.
167:
168: Inputs: $pos,$num,$maxnum
169: where $pos is current position, $num is the unique identifier,
170: and $maxnum is the total number of items (both substitutions
171: and text in the printout header.
172:
173: Returns: $output
174: HTML mark-up for the selectbox and a hidden form element containing
175: the current position.
176:
177: =item substitution_selector()
178:
179: Creates a combination of select box for choosing an item
180: (student name, course ID or assignment note) to substitute,
181: and a corresponding size limit in the header used for printouts.
182:
183: Inputs: $num,$subst,$limit,$crstype
184: where $num is the unique identifier, $subst is the current
185: substitution (n,c or a, for name, course or note respectively,
186: $limit is the current size limit (integer), and $crstype is
187: course type - course or community.
188:
189: Returns: $output
190: HTML mark-up for selectbox and textbox (separate table cells).
191:
192: =item change_clone()
193:
194: Modifies the list of courses a user can clone (stored
195: in the user's environment.db file), called when a
196: change is made to the list of users allowed to clone
197: a course.
198:
199: Inputs: $action,$cloner
200: where $action is add or drop, and $cloner is identity of
201: user for whom cloning ability is to be changed in course.
202:
203: Returns: nothing
204:
205: =back
206:
207: =cut
208:
209:
1.1 raeburn 210: package Apache::courseprefs;
211:
212: use strict;
213: use Apache::Constants qw(:common :http);
214: use Apache::lonnet;
215: use Apache::loncommon();
216: use Apache::lonhtmlcommon();
217: use Apache::lonconfigsettings;
1.66 raeburn 218: use Apache::lonrelrequtils;
1.36 raeburn 219: use Apache::lonparmset;
1.71 raeburn 220: use Apache::courseclassifier;
1.1 raeburn 221: use Apache::lonlocal;
222: use LONCAPA qw(:DEFAULT :match);
223:
1.66 raeburn 224: my $registered_cleanup;
225: my $modified_courses;
226:
1.1 raeburn 227: sub handler {
228: my $r=shift;
229: if ($r->header_only) {
230: &Apache::loncommon::content_type($r,'text/html');
231: $r->send_http_header;
232: return OK;
233: }
234: my $context = 'course';
235: my $cid = $env{'request.course.id'};
1.66 raeburn 236: my ($cnum,$cdom,$chome) = &get_course($cid);
1.1 raeburn 237: my $crstype = &Apache::loncommon::course_type();
1.80 raeburn 238: my ($parm_permission,$allowed) = &get_permission($cid);
1.1 raeburn 239: my $navmap = Apache::lonnavmaps::navmap->new();
1.80 raeburn 240: if ($allowed && $navmap) {
1.1 raeburn 241: &Apache::loncommon::content_type($r,'text/html');
242: $r->send_http_header;
243: } else {
244: if ($navmap) {
1.9 raeburn 245: if ($crstype eq 'Community') {
246: $env{'user.error.msg'}=
247: "/adm/courseprefs:opa:0:0:Cannot modify community settings";
248: } else {
249: $env{'user.error.msg'}=
250: "/adm/courseprefs:opa:0:0:Cannot modify course settings";
251: }
1.1 raeburn 252: } else {
1.9 raeburn 253: if ($crstype eq 'Community') {
254: $env{'user.error.msg'}=
255: "/adm/courseprefs::0:1:Course environment gone, reinitialize the community";
256: } else {
257: $env{'user.error.msg'}=
258: "/adm/courseprefs::0:1:Course environment gone, reinitialize the course";
259:
260: }
1.1 raeburn 261: }
262: return HTTP_NOT_ACCEPTABLE;
263: }
264:
1.66 raeburn 265: $registered_cleanup=0;
266: @{$modified_courses}=();
267:
1.4 raeburn 268: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
269: ['phase','actions','origin']);
1.1 raeburn 270: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.4 raeburn 271: if ($env{'form.origin'} eq 'params') {
272: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
273: text=>"Parameter Manager"});
274: }
1.9 raeburn 275: my ($brtext,$brtitle,$crsinfotext,$crsinfodesc,$crscateg,$crshide);
276: my %lt;
277: if ($crstype eq 'Community') {
278: %lt = (
1.40 www 279: conf => 'Community Settings',
280: edit => 'Edit Community Settings',
1.9 raeburn 281: gens => 'General community settings',
282: idnu => 'Community ID or number',
1.64 raeburn 283: unco => 'Unique code',
1.9 raeburn 284: desc => 'Community Description',
1.24 raeburn 285: ownr => 'Community Owner',
1.25 raeburn 286: cown => 'Community Co-owners',
1.9 raeburn 287: catg => 'Categorize community',
288: excc => 'Exclude from community catalog',
289: clon => 'Users allowed to clone community',
290: rept => 'Replacement titles for standard community roles',
291: time => 'Timezone where the community is located',
292: date => 'Locale used for community calendar',
293: coco => 'Community Content',
294: copo => 'Community Policy',
1.13 bisitz 295: priv => 'Domain Coordinators in community',
1.9 raeburn 296: defd => 'Default dates for member access',
297: stuv => 'Member-viewable membership list options',
298: stul => 'Member agreement needed to be listed',
1.42 www 299: clas => 'Membership and facilitator listing',
1.57 raeburn 300: prus => 'Privileged users (Domain Coordinators) in facilitator listing',
1.9 raeburn 301: defc => 'Default Community Spreadsheet',
302: defs => 'Default User Spreadsheet',
303: seme => 'Send message to member when clicking Done on Tasks'
304: );
305: } else {
306: %lt = (
1.40 www 307: conf => 'Course Settings',
308: edit => 'Edit Course Settings',
1.20 faziophi 309: gens => 'General course settings',
310: idnu => 'Course ID or number',
1.64 raeburn 311: unco => 'Unique code',
1.20 faziophi 312: desc => 'Course Description',
1.55 raeburn 313: cred => 'Student credits',
1.24 raeburn 314: ownr => 'Course Owner',
1.25 raeburn 315: cown => 'Course Co-owners',
1.9 raeburn 316: catg => 'Categorize course',
317: excc => 'Exclude from course catalog',
318: clon => 'Users allowed to clone course',
319: rept => 'Replacement titles for standard course roles',
1.20 faziophi 320: time => 'Timezone in which the course takes place',
321: date => 'Locale used for course calendar',
1.9 raeburn 322: coco => 'Course Content',
323: copo => 'Course Policy',
1.13 bisitz 324: priv => 'Domain Coordinators in course',
1.9 raeburn 325: defd => 'Default dates for student access',
326: stuv => 'Student-viewable classlist options',
327: stul => 'Student agreement needed to be listed',
1.42 www 328: clas => 'Classlists and staff listing',
1.57 raeburn 329: prus => 'Privileged users (Domain Coordinators) in staff listing',
1.56 raeburn 330: prdo => "Domains to check for privileged users (besides course's domain)",
1.9 raeburn 331: defc => 'Default Course Spreadsheet',
332: defs => 'Default Student Spreadsheet',
333: seme => 'Send message to student when clicking Done on Tasks',
334: );
335: }
1.35 raeburn 336: $lt{'lcrv'} = 'Required LON-CAPA version';
1.1 raeburn 337: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/courseprefs',
1.9 raeburn 338: text=>$lt{'conf'}});
1.1 raeburn 339: my $breadcrumbs =
1.9 raeburn 340: &Apache::lonhtmlcommon::breadcrumbs($lt{'edit'});
1.1 raeburn 341:
342: my $phase = 'pickactions';
343: if ( exists($env{'form.phase'}) ) {
344: $phase = $env{'form.phase'};
345: }
346:
1.80 raeburn 347: if (($phase eq 'categorizecourse') && ($parm_permission->{'categorizecourse'})) {
1.9 raeburn 348: &assign_course_categories($r,$crstype);
1.1 raeburn 349: return OK;
350: }
351:
1.80 raeburn 352: if (($phase eq 'releaseinfo') && ($parm_permission->{'releaseinfo'})) {
1.36 raeburn 353: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
354: if ($loncaparev) {
1.66 raeburn 355: if (&display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype)) {
356: push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
357: unless ($registered_cleanup) {
358: my $handlers = $r->get_handlers('PerlCleanupHandler');
359: $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
360: $registered_cleanup=1;
361: }
362: }
1.36 raeburn 363: return OK;
364: }
365: }
366:
1.1 raeburn 367: my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.99 ! raeburn 368: my %lti=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
! 369: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
! 370: foreach my $id (keys(%lti)) {
! 371: if (ref($lti{$id}) eq 'HASH') {
! 372: if (ref($ltienc{$id}) eq 'HASH') {
! 373: $values{'linkprotection'}{$id} = { %{$lti{$id}}, %{$ltienc{$id}} };
! 374: } else {
! 375: $values{'linkprotection'}{$id} = $lti{$id};
! 376: }
! 377: }
! 378: unless ($phase eq 'process') {
! 379: if (ref($values{'linkprotection'}{$id}) eq 'HASH') {
! 380: delete($values{'linkprotection'}{$id}{'secret'});
! 381: }
! 382: }
! 383: }
! 384: if ($lti{'lock'}) {
! 385: delete($lti{'lock'});
1.93 raeburn 386: }
1.1 raeburn 387: my @prefs_order = ('courseinfo','localization','feedback','discussion',
388: 'classlists','appearance','grading','printouts',
1.93 raeburn 389: 'menuitems','linkprotection','spreadsheet','bridgetasks',
390: 'lti','other');
1.1 raeburn 391:
392: my %prefs = (
393: 'courseinfo' =>
1.9 raeburn 394: { text => $lt{'gens'},
1.44 www 395: help => 'Course_Prefs_General',
1.35 raeburn 396: ordered => ['owner','co-owners','loncaparev','description',
1.64 raeburn 397: 'clonedfrom','courseid','uniquecode','categories',
1.88 raeburn 398: 'hidefromcat','syllabus','cloners','url',
1.64 raeburn 399: 'rolenames'],
1.3 raeburn 400: itemtext => {
1.25 raeburn 401: 'owner' => $lt{'ownr'},
402: 'co-owners' => $lt{'cown'},
403: 'description' => $lt{'desc'},
404: 'courseid' => $lt{'idnu'},
1.64 raeburn 405: 'uniquecode' => $lt{'unco'},
1.25 raeburn 406: 'categories' => $lt{'catg'},
407: 'hidefromcat' => $lt{'excc'},
408: 'cloners' => $lt{'clon'},
1.88 raeburn 409: 'syllabus' => 'Syllabus status',
1.25 raeburn 410: 'url' => 'Top Level Map',
411: 'rolenames' => $lt{'rept'},
1.35 raeburn 412: 'loncaparev' => $lt{'lcrv'},
1.63 raeburn 413: 'clonedfrom' => 'Cloned from',
1.3 raeburn 414: },
1.1 raeburn 415: },
416: 'localization' =>
1.42 www 417: { text => 'Language and time localization',
1.44 www 418: help => 'Course_Prefs_Language',
1.1 raeburn 419: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 420: itemtext => {
1.20 faziophi 421: languages => 'Languages used',
1.9 raeburn 422: timezone => $lt{'time'},
423: datelocale => $lt{'date'},
1.3 raeburn 424: },
1.1 raeburn 425: },
426: 'feedback' =>
1.20 faziophi 427: { text => 'Feedback messages',
1.44 www 428: help => 'Course_Prefs_Feedback',
1.1 raeburn 429: header => [{col1 => 'Questions about:',
1.20 faziophi 430: col2 => 'Recipients'}],
1.3 raeburn 431: ordered => ['question.email','comment.email','policy.email'],
432: itemtext => {
433: 'question.email' => 'Resource Content',
1.9 raeburn 434: 'comment.email' => $lt{'coco'},
435: 'policy.email' => $lt{'copo'},
1.3 raeburn 436: },
1.1 raeburn 437: },
438: 'discussion' =>
439: { text => 'Discussion and Chat',
1.44 www 440: help => 'Course_Prefs_Discussions',
1.31 raeburn 441: ordered => ['pch.roles.denied','pch.users.denied',
1.77 raeburn 442: 'pac.roles.denied','pac.users.denied',
1.31 raeburn 443: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 444: 'allow_limited_html_in_feedback',
1.50 raeburn 445: 'allow_discussion_post_editing',
446: 'discussion_post_fonts'],
1.3 raeburn 447: itemtext => {
1.31 raeburn 448: 'pch.roles.denied' => 'No Resource Discussion',
449: 'pch.users.denied' => 'No Resource Discussion',
450: 'plc.roles.denied' => 'No Chat room use',
451: 'plc.users.denied' => 'No Chat room use',
1.77 raeburn 452: 'pac.roles.denied' => 'No Anonymous Resource Discussion',
453: 'pac.users.denied' => 'No Anonymous Resource Discussion',
1.20 faziophi 454: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
455: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.77 raeburn 456: discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 457: },
1.1 raeburn 458: },
459: 'classlists' =>
1.9 raeburn 460: { text => $lt{'clas'},
1.44 www 461: help => 'Course_Prefs_Classlists',
1.1 raeburn 462: header => [{col1 => 'Type',
1.9 raeburn 463: col2 => $lt{'defd'}},
1.1 raeburn 464: {col1 => 'Setting',
1.9 raeburn 465: col2 => $lt{'priv'}},
1.1 raeburn 466: {col1 => 'Setting',
1.9 raeburn 467: col2 => $lt{'stuv'}}],
1.1 raeburn 468: ordered => ['default_enrollment_start_date',
469: 'default_enrollment_end_date',
1.55 raeburn 470: 'defaultcredits',
1.56 raeburn 471: 'nothideprivileged','checkforpriv',
472: 'student_classlist_view',
1.26 raeburn 473: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 474: itemtext => {
475: default_enrollment_start_date => 'Start date',
476: default_enrollment_end_date => 'End date',
1.57 raeburn 477: nothideprivileged => $lt{'prus'},
1.56 raeburn 478: checkforpriv => $lt{'prdo'},
1.9 raeburn 479: student_classlist_view => $lt{'stuv'},
1.26 raeburn 480: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 481: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.55 raeburn 482: defaultcredits => $lt{'cred'},
1.3 raeburn 483: },
1.1 raeburn 484: },
485: 'appearance' =>
1.20 faziophi 486: { text => 'Display of resources ',
1.44 www 487: help => 'Course_Prefs_Display',
1.1 raeburn 488: ordered => ['default_xml_style','pageseparators',
489: 'disable_receipt_display','texengine',
1.95 raeburn 490: 'tthoptions','uselcmath','usejsme','inline_chem'],
1.3 raeburn 491: itemtext => {
1.17 faziophi 492: default_xml_style => 'Default XML style file',
1.20 faziophi 493: pageseparators => 'Visibly Separate Items on Pages',
494: disable_receipt_display => 'Disable display of problem receipts',
495: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 496: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.69 raeburn 497: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
498: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.95 raeburn 499: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.3 raeburn 500: },
1.1 raeburn 501: },
502: 'grading' =>
503: { text => 'Grading',
1.44 www 504: help => 'Course_Prefs_Grading',
1.1 raeburn 505: ordered => ['grading','rndseed',
506: 'receiptalg','disablesigfigs'],
1.3 raeburn 507: itemtext => {
1.20 faziophi 508: grading => 'Grading',
509: rndseed => 'Randomization algorithm used',
510: receiptalg => 'Receipt algorithm used',
511: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 512: },
513:
1.1 raeburn 514: },
515: 'printouts' =>
1.20 faziophi 516: { text => 'Printout generation',
1.44 www 517: help => 'Course_Prefs_Printouts',
1.1 raeburn 518: ordered => ['problem_stream_switch','suppress_tries',
519: 'default_paper_size','print_header_format',
1.14 raeburn 520: 'disableexampointprint','canuse_pdfforms'],
1.3 raeburn 521: itemtext => {
522: problem_stream_switch => 'Allow problems to be split over pages',
523: suppress_tries => 'Suppress number of tries in printing',
524: default_paper_size => 'Default paper type',
525: print_header_format => 'Print header format',
1.51 bisitz 526: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 527: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 528: },
1.1 raeburn 529: },
530: 'spreadsheet' =>
531: { text => 'Spreadsheets',
1.44 www 532: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 533: ordered => ['spreadsheet_default_classcalc',
534: 'spreadsheet_default_studentcalc',
535: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 536: itemtext => {
1.9 raeburn 537: spreadsheet_default_classcalc => $lt{'defc'},
538: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 539: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
540: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
541: },
1.1 raeburn 542: },
543: 'bridgetasks' =>
544: { text => 'Bridge tasks',
1.44 www 545: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 546: ordered => ['task_messages','task_grading',
547: 'suppress_embed_prompt'],
1.3 raeburn 548: itemtext => {
1.9 raeburn 549: task_messages => $lt{'seme'},
1.3 raeburn 550: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 551: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 552: },
1.1 raeburn 553: },
1.87 raeburn 554: 'lti' =>
555: {
556: text => 'LTI provider settings',
557: help => 'Course_Prefs_LTIProvider',
558: ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'],
559: itemtext => {
560: 'lti.override' => 'Override domain defaults',
561: 'lti.topmenu' => 'Display LON-CAPA page header',
562: 'lti.inlinemenu' => 'Display LON-CAPA inline menu',
563: 'lti.lcmenu' => 'Menu items',
564: },
565: },
1.91 raeburn 566: 'menuitems' =>
567: {
568: text => 'Menu display',
569: help => 'Course_Prefs_Menus',
570: header => [{col1 => 'Default Menu',
571: col2 => 'Value',},
572: {col1 => 'Menu collections',
573: col2 => 'Settings',
574: }],
575: ordered => ['menudefault','menucollections'],
576: itemtext => {
577: menudefault => 'Choose default collection of menu items for course',
578: menucollections => 'Menu collections',
579: },
580: },
1.93 raeburn 581: 'linkprotection' =>
582: {
583: text => 'Link protection',
584: help => 'Course_Prefs_Linkprotection',
585: header => [{col1 => 'Item',
586: col2 => 'Settings',
587: }],
588: },
1.1 raeburn 589: 'other' =>
590: { text => 'Other settings',
1.44 www 591: help => 'Course_Prefs_Other',
1.1 raeburn 592: header => [ {col1 => 'Item',
593: col2 => 'Value',
594: }],
595: },
596: );
1.80 raeburn 597: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 598: my @allitems = &get_allitems(%prefs);
1.1 raeburn 599: &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
1.3 raeburn 600: \@prefs_order,\%prefs,\%values,
1.80 raeburn 601: $cnum,undef,\@allitems,
602: 'coursepref',$parm_permission);
603: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.91 raeburn 604: my $noedit;
605: if (ref($parm_permission) eq 'HASH') {
606: unless ($parm_permission->{'process'}) {
607: $noedit = 1;
608: }
609: }
610: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 611: my @allitems = &get_allitems(%prefs);
1.1 raeburn 612: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.99 ! raeburn 613: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.80 raeburn 614: 'coursepref',$parm_permission);
1.1 raeburn 615: } else {
616: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.80 raeburn 617: \@prefs_order,\%prefs,
618: 'coursepref',$parm_permission);
1.1 raeburn 619: }
620: return OK;
621: }
622:
1.80 raeburn 623: sub get_permission {
624: my ($cid) = @_;
625: my %permission;
626: my $allowed = 0;
627: return (\%permission,$allowed) unless ($cid);
628: if (&Apache::lonnet::allowed('opa',$cid)) {
629: %permission= (
630: 'pickactions' => 1,
631: 'categorizecourse' => 1,
632: 'releaseinfo' => 1,
633: 'process' => 1,
634: 'display' => 1,
635: );
636: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
637: %permission = (
638: 'pickactions' => 1,
639: 'releaseinfo' => 1,
640: 'display' => 1,
641: );
642: }
643: foreach my $perm (values(%permission)) {
644: if ($perm) { $allowed=1; last; }
645: }
646: return (\%permission,$allowed);
647: }
648:
1.3 raeburn 649: sub get_allitems {
650: my (%prefs) = @_;
651: my @allitems;
652: foreach my $item (keys(%prefs)) {
653: if (ref($prefs{$item}) eq 'HASH') {
654: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
655: push(@allitems,@{$prefs{$item}{'ordered'}});
656: if ($item eq 'feedback') {
657: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
658: }
659: }
660: }
661: }
662: return @allitems;
663: }
664:
1.1 raeburn 665: sub print_config_box {
1.99 ! raeburn 666: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 667: my $ordered = $item->{'ordered'};
1.3 raeburn 668: my $itemtext = $item->{'itemtext'};
1.80 raeburn 669: my $noedit;
670: if (ref($parm_permission) eq 'HASH') {
671: unless ($parm_permission->{'process'}) {
672: $noedit = 1;
673: }
674: }
1.1 raeburn 675: my $rowtotal = 0;
676: my $output =
1.45 www 677: '<table class="LC_nested_outer">
678: <tr>
679: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 680: &mt($item->{text});
681: if ($item->{'help'}) {
1.53 raeburn 682: $output .= ' '.
1.52 raeburn 683: &Apache::loncommon::help_open_topic($item->{'help'});
684: }
685: $output .= '</span></th>'."\n".
686: '</tr>';
1.91 raeburn 687: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 688: $output .= '
1.45 www 689: <tr>
690: <td>
1.18 faziophi 691: <table class="LC_nested">';
692: if (exists $item->{'header'}->[0]->{'col1'} ||
693: exists $item->{'header'}->[0]->{'col2'}) {
694: $output .= '
695: <tr class="LC_info_row">
1.56 raeburn 696: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
697: if ($action eq 'feedback') {
698: $output .= '
699: <td class="LC_right_item" colspan="2">';
700: } else {
701: $output .= '
702: <td class="LC_right_item">';
703: }
704: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 705: </tr>';
706: }
1.1 raeburn 707: $rowtotal ++;
708: if ($action eq 'feedback') {
1.80 raeburn 709: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 710: } elsif ($action eq 'classlists') {
1.80 raeburn 711: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 712: } elsif ($action eq 'menuitems') {
713: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 714: }
715: $output .= '
716: </table>
1.45 www 717: </td>
718: </tr>
719: <tr>
720: <td>
1.1 raeburn 721: <table class="LC_nested">
722: <tr class="LC_info_row">
723: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 724: if ($action eq 'classlists') {
725: $output .= '
726: <td class="LC_right_item" colspan="2">';
727: } else {
728: $output .= '
729: <td class="LC_right_item">';
730: }
731: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 732: </tr>';
733: if ($action eq 'classlists') {
1.80 raeburn 734: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 735: '
736: </table>
1.45 www 737: </td>
738: </tr>
739: <tr>
740: <td>
1.18 faziophi 741: <table class="LC_nested">';
1.43 www 742: if (exists $item->{'header'}->[2]->{'col1'} ||
743: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 744: $output .= '
745: <tr class="LC_info_row">
1.43 www 746: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
747: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 748: </tr>';
749: }
1.1 raeburn 750: }
751: } else {
752: $output .= '
1.45 www 753: <tr>
754: <td>
1.18 faziophi 755: <table class="LC_nested">';
756: if (exists $item->{'header'}->[0]->{'col1'} ||
757: exists $item->{'header'}->[0]->{'col2'}) {
758: $output .= '
759: <tr class="LC_info_row">
1.56 raeburn 760: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
761: if (($action eq 'courseinfo') || ($action eq 'localization') ||
762: ($action eq 'print_discussion')) {
763: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
764: } else {
765: $output .= '<td class="LC_right_item" valign="top">';
766: }
767: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 768: </tr>';
769: }
1.1 raeburn 770: }
771: $rowtotal ++;
772: if ($action eq 'courseinfo') {
1.80 raeburn 773: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 774: } elsif ($action eq 'localization') {
1.80 raeburn 775: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 776: } elsif ($action eq 'feedback') {
1.80 raeburn 777: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 778: } elsif ($action eq 'discussion') {
1.80 raeburn 779: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 780: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 781: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 782: } elsif ($action eq 'appearance') {
1.80 raeburn 783: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 784: } elsif ($action eq 'grading') {
1.80 raeburn 785: $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 786: } elsif ($action eq 'printouts') {
1.80 raeburn 787: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 788: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 789: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 790: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 791: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.87 raeburn 792: } elsif ($action eq 'lti') {
793: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 794: } elsif ($action eq 'menuitems') {
795: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.93 raeburn 796: } elsif ($action eq 'linkprotection') {
1.99 ! raeburn 797: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit);
1.1 raeburn 798: } elsif ($action eq 'other') {
1.80 raeburn 799: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 800: }
801: $output .= '
802: </table>
1.45 www 803: </td>
804: </tr>
805: </table><br />';
1.1 raeburn 806: return ($output,$rowtotal);
807: }
808:
809: sub process_changes {
1.93 raeburn 810: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype) = @_;
1.99 ! raeburn 811: my (%newvalues,%lti,%ltienc,$errors);
1.3 raeburn 812: if (ref($item) eq 'HASH') {
813: if (ref($changes) eq 'HASH') {
814: my @ordered;
815: if ($action eq 'other') {
816: @ordered = &get_other_items($cdom,$values,$allitems);
817: if ($env{'form.newp_name'} ne '') {
818: my $newp = $env{'form.newp_name'};
819: if ($env{'form.newp_value'} ne '') {
820: if (ref($allitems) eq 'ARRAY') {
821: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
822: (grep(/^\Q$newp\E$/,@{$allitems}))) {
823: $changes->{$newp} = $env{'form.newp_value'};
824: }
825: }
826: }
827: }
1.93 raeburn 828: } elsif ($action eq 'linkprotection') {
1.99 ! raeburn 829: if (ref($values->{$action}) eq 'HASH') {
! 830: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 831: if ($id =~ /^\d+$/) {
832: push(@ordered,$id);
1.99 ! raeburn 833: unless (ref($values->{$action}->{$id}) eq 'HASH') {
! 834: $lti{$id} = '';
1.93 raeburn 835: }
836: }
837: }
838: }
839: @ordered = sort { $a <=> $b } @ordered;
840: if (($env{'form.linkprot_add'}) && ($env{'form.linkprot_maxnum'} =~ /^\d+$/)) {
841: push(@ordered,$env{'form.linkprot_maxnum'});
842: }
1.3 raeburn 843: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 844: if ($action eq 'courseinfo') {
845: my ($can_toggle_cat,$can_categorize) =
846: &can_modify_catsettings($cdom,$crstype);
847: foreach my $entry (@{$item->{'ordered'}}) {
848: next if (($entry eq 'hidefromcat') &&
849: (!$can_toggle_cat));
850: next if (($entry eq 'categories') &&
851: (!$can_categorize));
852: next if (($entry eq 'loncaparev') ||
1.63 raeburn 853: ($entry eq 'owner') ||
1.88 raeburn 854: ($entry eq 'clonedfrom') ||
855: ($entry eq 'syllabus'));
1.49 raeburn 856: push(@ordered,$entry);
857: }
1.55 raeburn 858: } elsif ($action eq 'classlists') {
859: foreach my $entry (@{$item->{'ordered'}}) {
860: next if ($entry eq 'defaultcredits');
861: push(@ordered,$entry);
862: }
1.49 raeburn 863: } else {
864: @ordered = @{$item->{'ordered'}};
865: }
1.3 raeburn 866: }
867: if (@ordered > 0) {
868: if ($action eq 'feedback') {
869: foreach my $entry (@ordered) {
870: my $userstr = '';
871: my $total = $env{'form.'.$entry.'_total'};
872: if ($total) {
873: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
874: for (my $i=0; $i<$total; $i++) {
875: unless (grep(/^$i$/,@deletes)) {
876: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
877: &get_sec_str($entry,$i).',';
878: }
879: }
880: } else {
881: $total = 0;
882: }
883: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
884: my $uname = $env{'form.'.$entry.'_uname_'.$total};
885: my $udom = $env{'form.'.$entry.'_udom_'.$total};
886: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
887: $userstr =~ s/,$//;
888: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
889: } else {
890: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
891: }
892: } else {
893: $userstr =~ s/,$//;
894: }
895: $newvalues{$entry} = $userstr;
896: if ($newvalues{$entry} ne $values->{$entry}) {
897: $changes->{$entry} = $newvalues{$entry};
898: }
899: my $ext_entry = $entry.'.text';
900: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
901: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
902: $changes->{$ext_entry} = $newvalues{$ext_entry};
903: }
904: }
1.91 raeburn 905: } elsif ($action eq 'menuitems') {
906: my (%current,@colls);
907: my $next = 1;
908: if ($values->{'menucollections'}) {
909: foreach my $item (split(/;/,$values->{'menucollections'})) {
910: my ($num,$value) = split(/\%/,$item);
911: if ($num =~ /^\d+$/) {
912: unless (grep(/^$num$/,@colls)) {
913: push(@colls,$num);
914: }
915: my @entries = split(/\&/,$value);
916: foreach my $entry (@entries) {
917: my ($name,$fields) = split(/=/,$entry);
918: $current{$num}{$name} = $fields;
919: }
920: }
921: }
922: }
923: if (@colls) {
924: @colls = sort { $a <=> $b } @colls;
925: $next += $colls[-1];
926: }
927: if ($env{'form.menucollections_add'} eq $next) {
928: push(@colls,$next);
929: }
930: my $currdef = $values->{'menudefault'};
931: my $possdef = $env{'form.menudefault'};
932: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 933: if ($currdef ne $possdef) {
1.91 raeburn 934: $changes->{'menudefault'} = $possdef;
935: }
1.92 raeburn 936: } elsif ($currdef) {
1.91 raeburn 937: $changes->{'menudefault'} = '';
938: }
939: my $menucoll;
940: if (@colls) {
941: my ($ordered,$cats) = &menuitems_categories();
942: my %shortcats = &menuitems_abbreviations();
943: foreach my $num (@colls) {
944: my ($entry,%include);
945: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
946: foreach my $item (@{$ordered}) {
947: if ($item eq 'shown') {
948: foreach my $type (@{$cats->{$item}}) {
949: $entry .= $type.'=';
950: if ($include{$type}) {
951: $entry .= 'y';
952: } else {
953: $entry .= 'n';
954: }
955: $entry .= '&';
956: }
957: } else {
958: $entry .= $shortcats{$item}.'=';
959: foreach my $type (@{$cats->{$item}}) {
960: if ($include{$type}) {
961: $entry .= $type.',';
962: }
963: }
964: $entry =~ s/,$//;
965: $entry .= '&';
966: }
967: }
968: $entry =~ s/\&$//;
969: if ($menucoll) {
970: $menucoll .= ';';
971: }
972: $menucoll .= $num.'%'.$entry;
973: }
974: if ($menucoll ne $values->{'menucollections'}) {
975: $changes->{'menucollections'} = $menucoll;
976: }
977: } elsif ($values->{'menucollections'}) {
978: $changes->{'menucollections'} = '';
979: }
1.93 raeburn 980: } elsif ($action eq 'linkprotection') {
981: my %menutitles = <imenu_titles();
1.99 ! raeburn 982: my $switchserver = &check_switchserver($cdom,$cnum);
1.93 raeburn 983: my (@items,%deletions,%itemids,%haschanges);
984: if ($env{'form.linkprot_add'}) {
985: my $name = $env{'form.linkprot_name_add'};
986: $name =~ s/(`)/'/g;
987: my ($newid,$error) = &get_courselti_id($cdom,$cnum,$name);
988: if ($newid) {
989: $itemids{'add'} = $newid;
990: push(@items,'add');
991: $haschanges{$newid} = 1;
992: } else {
993: $errors .= '<span class="LC_error">'.
994: &mt('Failed to acquire unique ID for link protection').
995: '</span>';
996: }
997: }
1.99 ! raeburn 998: if (ref($values->{$action}) eq 'HASH') {
1.93 raeburn 999: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1000: my $maxnum = $env{'form.linkprot_maxnum'};
1001: for (my $i=0; $i<=$maxnum; $i++) {
1002: my $itemid = $env{'form.linkprot_id_'.$i};
1003: $itemid =~ s/\D+//g;
1004: if ($itemid) {
1.99 ! raeburn 1005: if (ref($values->{$action}->{$itemid}) eq 'HASH') {
1.93 raeburn 1006: push(@items,$i);
1007: $itemids{$i} = $itemid;
1008: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1.99 ! raeburn 1009: $deletions{$itemid} = $values->{$action}->{$itemid}->{'name'};
1.93 raeburn 1010: }
1011: }
1012: }
1013: }
1.94 raeburn 1014: }
1.93 raeburn 1015:
1016: foreach my $idx (@items) {
1017: my $itemid = $itemids{$idx};
1018: next unless ($itemid);
1019: if (exists($deletions{$itemid})) {
1.99 ! raeburn 1020: $lti{$itemid} = $deletions{$itemid};
1.93 raeburn 1021: $haschanges{$itemid} = 1;
1022: next;
1023: }
1024: my %current;
1.99 ! raeburn 1025: if (ref($values->{$action}) eq 'HASH') {
! 1026: if (ref($values->{$action}->{$itemid}) eq 'HASH') {
! 1027: foreach my $key (keys(%{$values->{$action}->{$itemid}})) {
! 1028: $current{$key} = $values->{$action}->{$itemid}->{$key};
1.93 raeburn 1029: }
1030: }
1031: }
1.99 ! raeburn 1032: foreach my $inner ('name','lifetime','version') {
1.93 raeburn 1033: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1034: $env{$formitem} =~ s/(`)/'/g;
1035: if ($inner eq 'lifetime') {
1036: $env{$formitem} =~ s/[^\d.]//g;
1037: }
1038: unless ($idx eq 'add') {
1039: if ($current{$inner} ne $env{$formitem}) {
1040: $haschanges{$itemid} = 1;
1041: }
1042: }
1043: if ($env{$formitem} ne '') {
1.99 ! raeburn 1044: $lti{$itemid}{$inner} = $env{$formitem};
! 1045: }
! 1046: }
! 1047: unless ($switchserver) {
! 1048: my $keyitem = 'form.linkprot_key_'.$idx;
! 1049: $env{$keyitem} =~ s/(`)/'/g;
! 1050: unless ($idx eq 'add') {
! 1051: if ($current{'key'} ne $env{$keyitem}) {
! 1052: $haschanges{$itemid} = 1;
! 1053: }
! 1054: }
! 1055: if ($env{$keyitem} ne '') {
! 1056: $lti{$itemid}{'key'} = $env{$keyitem};
! 1057: }
! 1058: my $secretitem = 'form.linkprot_secret_'.$idx;
! 1059: $env{$secretitem} =~ s/(`)/'/g;
! 1060: if ($current{'usable'}) {
! 1061: if ($env{'form.linkprot_changesecret_'.$idx}) {
! 1062: if ($env{$secretitem} ne '') {
! 1063: $lti{$itemid}{'secret'} = $env{$secretitem};
! 1064: $haschanges{$itemid} = 1;
! 1065: }
! 1066: } else {
! 1067: $lti{$itemid}{'secret'} = $current{'secret'};
! 1068: }
! 1069: } elsif ($env{$secretitem} ne '') {
! 1070: $lti{$itemid}{'secret'} = $env{$secretitem};
! 1071: $haschanges{$itemid} = 1;
1.93 raeburn 1072: }
1073: }
1074: }
1075: if (keys(%haschanges)) {
1076: foreach my $entry (keys(%haschanges)) {
1.99 ! raeburn 1077: $changes->{$entry} = $lti{$entry};
1.93 raeburn 1078: }
1079: }
1.3 raeburn 1080: } else {
1081: foreach my $entry (@ordered) {
1082: if ($entry eq 'cloners') {
1083: if ($env{'form.cloners_all'}) {
1084: $newvalues{$entry} = '*';
1085: } else {
1086: my @clonedoms;
1087: if (exists($env{'form.cloners_activate'})) {
1088: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1089: if ($actnum ne '-1') {
1.33 raeburn 1090: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1091: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1092: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1093: $newvalues{$entry} = '*:'.$clonedom;
1094: push(@clonedoms,$newvalues{$entry});
1095: }
1096: }
1097: }
1098: } else {
1099: my $num = $env{'form.cloners_total'};
1100: my @deletes =
1101: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1102: for (my $i=0; $i<$num; $i++) {
1103: if (!grep(/^$i$/,@deletes)) {
1104: my $clonedom = $env{'form.cloners_dom_'.$i};
1105: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1106: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1107: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1108: }
1109: }
1110: }
1111: }
1112: if (@clonedoms) {
1113: $newvalues{$entry}=join(',',@clonedoms);
1114: }
1115: }
1116: if ($env{'form.cloners_newdom'} ne '') {
1117: my $clonedom = $env{'form.cloners_newdom'};
1118: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1119: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1120: if (@clonedoms) {
1.3 raeburn 1121: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1122: $newvalues{$entry} .= ','.$newdom;
1123: }
1124: } else {
1125: $newvalues{$entry} = $newdom;
1126: }
1127: }
1128: }
1129: if ($env{'form.'.$entry} ne '') {
1130: my @cloners = split(',',$env{'form.'.$entry});
1131: my @okcloners;
1132: foreach my $cloner (@cloners) {
1.23 raeburn 1133: $cloner =~ s/^\s+//;
1134: $cloner =~ s/\s+$//;
1135: unless ($cloner eq '') {
1136: my ($uname,$udom) = split(':',$cloner);
1137: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1138: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1139: push(@okcloners,$cloner);
1140: }
1.3 raeburn 1141: }
1142: }
1143: }
1144: if (@okcloners) {
1145: my $okclonestr = join(',',@okcloners);
1146: if ($newvalues{$entry} ne '') {
1147: $newvalues{$entry} .= ','.$okclonestr;
1148: } else {
1149: $newvalues{$entry} = $okclonestr;
1150: }
1151: }
1152: }
1.71 raeburn 1153: if (ref($values) eq 'HASH') {
1154: my (@code_order,%codedefaults);
1155: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1156: \@code_order);
1157: my $clonebycode;
1158: if ($env{'form.cloners_instcode'}) {
1159: if (@code_order > 0) {
1160: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1161: my %local_to_standard;
1162: for (my $i=0; $i<@code_order; $i++) {
1163: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1164: }
1165: foreach my $item (@code_order) {
1166: my $key = $local_to_standard{$item};
1167: if ($key ne '') {
1168: if ($env{'form.'.$key}) {
1169: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1170: }
1171: }
1172: }
1173: $clonebycode =~ s/\&$//;
1174: }
1175: }
1176: if ($clonebycode) {
1177: if ($newvalues{$entry}) {
1178: $newvalues{$entry} .= ','.$clonebycode;
1179: } else {
1180: $newvalues{$entry} = $clonebycode;
1181: }
1182: }
1183: }
1.3 raeburn 1184: }
1185: if (ref($disallowed) eq 'HASH') {
1186: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1187: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1188: $disallowed->{'cloners'}{$key} =~ s/,$//;
1189: }
1190: }
1191: }
1.25 raeburn 1192: } elsif ($entry eq 'co-owners') {
1193: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1194: my $coowners = $values->{'internal.co-owners'};
1195: my @currcoown;
1196: if ($coowners) {
1197: @currcoown = split(',',$coowners);
1198: }
1199: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1200: my $autocoowner;
1201: if (($crstype eq 'Course') &&
1202: ($values->{'internal.coursecode'})) {
1203: my %domconf =
1204: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1205: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1206: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1207: }
1208: }
1.96 raeburn 1209: if ($autocoowner) {
1210: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1211: } else {
1.25 raeburn 1212: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1213: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1214: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1215: if (@invitecoowners) {
1216: push(@pendingcoowners,@invitecoowners);
1217: }
1218: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1219: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1220: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1221: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1222: push(@{$changes->{$entry}{'changed'}},'co-owners');
1223: }
1224: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1225: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1226: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1227: }
1228: }
1229: } else {
1230: my (@newpending,@newcoown);
1231: my $uname = $env{'user.name'};
1232: my $udom = $env{'user.domain'};
1233: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1234: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1235: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1236: foreach my $item (@pendingcoown) {
1237: unless ($item eq $uname.':'.$udom) {
1238: push(@newpending,$item);
1239: }
1240: }
1241: @newcoown = @currcoown;
1.90 raeburn 1242: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1243: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1244: push(@newcoown,$uname.':'.$udom);
1245: }
1246: }
1.90 raeburn 1247: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1248: foreach my $item (@currcoown) {
1249: unless ($item eq $uname.':'.$udom) {
1250: push(@newcoown,$item);
1251: }
1252: }
1253: if ($pendingcoowners ne '') {
1254: @newpending = @pendingcoown;
1255: }
1.96 raeburn 1256: } else {
1257: @newcoown = @currcoown;
1.25 raeburn 1258: }
1259: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1260: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1261: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1262: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1263: push(@{$changes->{$entry}{'changed'}},'co-owners');
1264: }
1265: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1266: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1267: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1268: }
1269: }
1.3 raeburn 1270: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1271: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1272: } elsif ($entry eq 'rolenames') {
1273: my %adv_roles =
1274: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1275: my @stds;
1276: if ($crstype eq 'Community') {
1277: @stds = ('co');
1278: } else {
1279: @stds = ('cc');
1280: }
1281: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1282: my (@replacements,@regulars);
1283: foreach my $role (@stds) {
1284: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1285: push(@replacements,$role);
1.3 raeburn 1286: } else {
1287: push(@regulars,$role);
1288: }
1.9 raeburn 1289: }
1.3 raeburn 1290: foreach my $stdrole (@stds) {
1291: my $ext_entry = $entry.'_'.$stdrole;
1292: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1293: $env{'request.course.id'},1);
1294: if ($env{'form.'.$ext_entry} eq $stdname) {
1295: $newvalues{$ext_entry} = '';
1296: } else {
1297: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1298: }
1299: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1300: my $dupname = 0;
1301: if ($newvalues{$ext_entry} ne '') {
1302: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1303: $dupname = 1;
1304: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1305: }
1306: if (!$dupname) {
1307: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1308: $dupname = 1;
1309: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1310: }
1311: }
1312: if (!$dupname) {
1313: foreach my $role (keys(%adv_roles)) {
1314: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1315: $dupname = 1;
1316: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1317: last;
1318: }
1319: }
1320: }
1321: }
1322: if (!$dupname) {
1323: $changes->{$ext_entry} = $newvalues{$ext_entry};
1324: }
1325: }
1326: }
1.77 raeburn 1327: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1328: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1329: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1330: @denied = sort(@denied);
1331: my $deniedstr = '';
1332: if (@denied > 0) {
1333: $deniedstr = join(',',@denied);
1334: }
1335: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1336: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1337: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1338: my $total = $env{'form.'.$entry.'_total'};
1339: my $userstr = '';
1340: my @denied;
1341: if ($total > 0) {
1342: my @deletes =
1343: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1344: for (my $i=0; $i<$total; $i++) {
1345: unless (grep(/^$i$/,@deletes)) {
1346: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1347: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1348: }
1349: }
1350: } else {
1351: $total = 0;
1352: }
1353: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1354: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1355: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1356: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1357: $userstr =~ s/,$//;
1358: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1359: } else {
1360: my $newuser .= $uname.':'.$udom;
1361: if (grep(/^\Q$newuser\E$/,@denied)) {
1362: $userstr =~ s/,$//;
1363: } else {
1364: $userstr .= $newuser;
1365: }
1366: }
1367: } else {
1368: $userstr =~ s/,$//;
1369: }
1370: $newvalues{$entry} = $userstr;
1371: } elsif ($entry eq 'allow_discussion_post_editing') {
1372: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1373: @canedit = sort(@canedit);
1374: foreach my $role (@canedit) {
1375: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1376: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1377: $newvalues{$entry} .= $role.',';
1378: } else {
1379: foreach my $sec (@secs) {
1380: $newvalues{$entry} .= $role.':'.$sec.',';
1381: }
1382: }
1383: }
1384: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1385: } elsif ($entry eq 'discussion_post_fonts') {
1386: my ($classorder,$classtitles) = &discussion_vote_classes();
1387: my $fontchange = 0;
1388: foreach my $class (@{$classorder}) {
1389: my $ext_entry = $entry.'_'.$class;
1390: my $size = $env{'form.'.$ext_entry.'_size'};
1391: my $unit = $env{'form.'.$ext_entry.'_unit'};
1392: my $weight = $env{'form.'.$ext_entry.'_weight'};
1393: my $style = $env{'form.'.$ext_entry.'_style'};
1394: my $other = $env{'form.'.$ext_entry.'_other'};
1395: $size =~ s/,//g;
1396: $unit =~ s/,//g;
1397: $weight =~ s/,//g;
1398: $style =~ s/,//g;
1399: $other =~ s/[^\w;:\s\-\%.]//g;
1400: $other =~ s/(^\s+|\s+$)//g;
1401: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1402: my $current = $values->{$ext_entry};
1403: if ($values->{$ext_entry} eq '') {
1404: $current = ',,,';
1405: }
1406: if ($newvalues{$ext_entry} ne $current) {
1407: $changes->{$ext_entry} = $newvalues{$ext_entry};
1408: $fontchange ++;
1409: }
1410: }
1411: if ($fontchange) {
1412: $changes->{$entry} = 1;
1413: }
1.3 raeburn 1414: } elsif ($entry eq 'nothideprivileged') {
1415: my @curr_nothide;
1416: my @new_nothide;
1417: if ($values->{$entry} ne '') {
1418: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1419: my $nothide;
1420: if ($user !~ /:/) {
1421: $nothide = join(':',split(/[\@]/,$user));
1422: } else {
1423: $nothide = $user;
1424: }
1425: if ((defined($nothide)) &&
1426: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1427: push(@curr_nothide,$nothide);
1428: }
1429: }
1430: }
1431: foreach my $key (keys(%env)) {
1432: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1433: if ($env{$key}) {
1.3 raeburn 1434: my $nothide = $1;
1435: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1436: push(@new_nothide,$nothide);
1437: }
1438: }
1439: }
1440: }
1441: @new_nothide = sort(@new_nothide);
1442: my @differences =
1443: &Apache::loncommon::compare_arrays(\@curr_nothide,
1444: \@new_nothide);
1445: if (@differences > 0) {
1446: if (@new_nothide > 0) {
1447: $newvalues{$entry} = join(',',@new_nothide);
1448: } else {
1449: $newvalues{$entry} = '';
1450: }
1451: } else {
1452: $newvalues{$entry} = $values->{$entry};
1453: }
1454: } elsif ($entry eq 'print_header_format') {
1455: my $maxnum = $env{'form.printfmthdr_maxnum'};
1456: my @newhdr;
1457: if ($maxnum > 2) {
1458: for (my $i=0; $i<$maxnum-2; $i++) {
1459: if ($env{'form.printfmthdr_del_'.$i}) {
1460: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1461: } else {
1462: my $hdr;
1463: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1464: $hdr = '%';
1465: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1466: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1467: }
1468: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1469: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1470: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1471: }
1472: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1473: }
1474: }
1475: }
1476: my $newsub = $maxnum-2;
1477: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1478: my $hdr = '%';
1479: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1480: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1481: }
1482: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1483: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1484: }
1485: my $newtext = $maxnum-1;
1486: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1487: $newvalues{$entry} = join('',@newhdr);
1.56 raeburn 1488: } elsif (($entry eq 'languages') ||
1489: ($entry eq 'checkforpriv')) {
1490: my $settings;
1.3 raeburn 1491: my $total = $env{'form.'.$entry.'_total'};
1492: if ($total) {
1493: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1494: for (my $i=0; $i<$total; $i++) {
1495: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1496: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1497: }
1498: }
1499: } else {
1500: $total = 0;
1501: }
1502: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1503: my $new = $env{'form.'.$entry.'_'.$total};
1504: if ($entry eq 'languages') {
1505: my %langchoices = &get_lang_choices();
1506: if ($langchoices{$new}) {
1507: $settings .= $new;
1508: } else {
1509: $settings =~ s/,$//;
1510: $disallowed->{'localization'}{$entry} = $new;
1511: }
1.3 raeburn 1512: } else {
1.56 raeburn 1513: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1514: if ($domains{$new}) {
1515: $settings .= $new;
1516: } else {
1517: $settings =~ s/,$//;
1518: $disallowed->{'classlists'}{$entry} = $new;
1519: }
1.3 raeburn 1520: }
1521: } else {
1.56 raeburn 1522: $settings =~ s/,$//;
1.3 raeburn 1523: }
1.56 raeburn 1524: $newvalues{$entry} = $settings;
1.87 raeburn 1525: } elsif ($action eq 'lti') {
1526: if ($entry eq 'lti.override') {
1527: $newvalues{$entry} = $env{'form.'.$entry};
1528: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1529: if ($env{'form.lti.override'}) {
1530: $newvalues{$entry} = $env{'form.'.$entry};
1531: } else {
1532: $newvalues{$entry} = '';
1533: }
1534: } elsif ($entry eq 'lti.lcmenu') {
1535: if (($env{'form.lti.override'}) &&
1536: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1537: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1538: my @newlcmenu;
1539: if (@lcmenu) {
1540: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1541: foreach my $item (@menuitems) {
1542: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1543: if (grep(/^\Q$item\E$/,@lcmenu)) {
1544: push(@newlcmenu,$item);
1545: }
1546: }
1547: }
1548: if (@newlcmenu) {
1549: $newvalues{$entry} = join(',',@newlcmenu);
1550: } else {
1551: $newvalues{$entry} = 'none';
1552: }
1553: } else {
1554: $newvalues{$entry} = '';
1555: }
1556: }
1.3 raeburn 1557: } else {
1558: $newvalues{$entry} = $env{'form.'.$entry};
1559: }
1.50 raeburn 1560: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts')) {
1.25 raeburn 1561: if ($newvalues{$entry} ne $values->{$entry}) {
1562: $changes->{$entry} = $newvalues{$entry};
1563: }
1.3 raeburn 1564: }
1565: }
1566: }
1567: }
1568: }
1569: }
1.93 raeburn 1570: return $errors;
1571: }
1572:
1573: sub get_courselti_id {
1574: my ($cdom,$cnum,$name) = @_;
1575: # get lock on lti db in course
1576: my $lockhash = {
1577: lock => $env{'user.name'}.
1578: ':'.$env{'user.domain'},
1579: };
1580: my $tries = 0;
1581: my $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1582: my ($id,$error);
1583: while (($gotlock ne 'ok') && ($tries<10)) {
1584: $tries ++;
1585: sleep (0.1);
1586: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1587: }
1588: if ($gotlock eq 'ok') {
1589: my %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1590: if ($currids{'lock'}) {
1591: delete($currids{'lock'});
1592: if (keys(%currids)) {
1593: my @curr = sort { $a <=> $b } keys(%currids);
1594: if ($curr[-1] =~ /^\d+$/) {
1595: $id = 1 + $curr[-1];
1596: } else {
1597: $id = 1;
1598: }
1599: } else {
1600: $id = 1;
1601: }
1602: if ($id) {
1603: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1604: $error = 'nostore';
1605: }
1606: } else {
1607: $error = 'nonumber';
1608: }
1609: }
1610: my $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1611: } else {
1612: $error = 'nolock';
1613: }
1614: return ($id,$error);
1.3 raeburn 1615: }
1616:
1617: sub get_sec_str {
1618: my ($entry,$num) = @_;
1619: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
1620: my $secstr;
1621: if (grep(/^\s*$/,@secs)) {
1622: $secstr = '';
1623: } elsif (@secs > 0) {
1624: $secstr = join(';',@secs);
1625: }
1626: if ($secstr ne '') {
1627: return '('.$secstr.')';
1628: }
1629: return;
1630: }
1631:
1632: sub check_clone {
1633: my ($clonedom,$disallowed,$clonename) = @_;
1634: return if (ref($disallowed) ne 'HASH');
1635: if ($clonedom !~ /^$match_domain$/) {
1636: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
1637: return;
1638: } elsif (!&Apache::lonnet::domain($clonedom)) {
1639: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
1640: return;
1641: }
1642: if ($clonename ne '') {
1643: if ($clonename !~ /^$match_username$/) {
1644: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
1645: return;
1646: } else {
1647: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
1648: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
1649: return;
1650: }
1651: }
1652: }
1653: return 'ok';
1654: }
1655:
1656: sub store_changes {
1.9 raeburn 1657: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 1658: my ($chome,$output);
1.93 raeburn 1659: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot);
1.3 raeburn 1660: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.93 raeburn 1661: if (ref($values->{'linkprotection'}) eq 'HASH') {
1662: %oldlinkprot = %{$values->{'linkprotection'}};
1663: }
1664: delete($values->{'linkprotection'});
1.3 raeburn 1665: %storehash = %{$values};
1666: } else {
1.9 raeburn 1667: if ($crstype eq 'Community') {
1668: $output = &mt('No changes made to community settings.');
1669: } else {
1670: $output = &mt('No changes made to course settings.');
1671: }
1672: return $output;
1.3 raeburn 1673: }
1.93 raeburn 1674: my ($numchanges,$skipstore);
1675: if (ref($changes) eq 'HASH') {
1676: $numchanges = scalar(keys(%{$changes}));
1677: if (($numchanges == 1) && (exists($changes->{'linkprotection'}))) {
1678: $skipstore = 1;
1679: } elsif (!$numchanges) {
1680: if ($crstype eq 'Community') {
1681: $output = &mt('No changes made to community settings.');
1682: } else {
1683: $output = &mt('No changes made to course settings.');
1684: }
1685: return $output;
1686: }
1687: }
1.3 raeburn 1688: my %yesno = (
1689: hidefromcat => '1',
1690: problem_stream_switch => '1',
1691: suppress_tries => '1',
1692: disableexampointprint => '1',
1693: hideemptyrows => '1',
1694: suppress_embed_prompt => '1',
1695: );
1696: foreach my $item (@{$prefs_order}) {
1697: if (grep(/^\Q$item\E$/,@{$actions})) {
1698: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
1699: if (ref($changes->{$item}) eq 'HASH') {
1.99 ! raeburn 1700: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 1701: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 1702: if ($item eq 'other') {
1703: foreach my $key (sort(keys(%{$changes->{$item}}))) {
1704: $storehash{$key} = $changes->{$item}{$key};
1705: if ($changes->{$item}{$key} eq '') {
1706: push(@delkeys,$key);
1.22 wenzelju 1707: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 1708: } else {
1.22 wenzelju 1709: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
1710: "'$storehash{$key}'")).'</li>';
1.3 raeburn 1711: }
1712: }
1.93 raeburn 1713: } elsif ($item eq 'linkprotection') {
1.99 ! raeburn 1714: my (%ltienc,$lti_save_error);
! 1715: if (ref($changes->{$item}) eq 'HASH') {
! 1716: foreach my $id (sort { $a <=> $b } keys(%{$changes->{$item}})) {
! 1717: if (ref($changes->{$item}->{$id}) eq 'HASH') {
! 1718: if (exists($changes->{$item}->{$id}->{'key'})) {
! 1719: $ltienc{$id}{'key'} = $changes->{$item}->{$id}->{'key'};
! 1720: delete($changes->{$item}->{$id}->{'key'});
! 1721: }
! 1722: if (exists($changes->{$item}->{$id}->{'secret'})) {
! 1723: $ltienc{$id}{'secret'} = $changes->{$item}->{$id}->{'secret'};
! 1724: delete($changes->{$item}->{$id}->{'secret'});
! 1725: } elsif (ref($oldlinkprot{$id}) eq 'HASH') {
! 1726: if (exists($oldlinkprot{$id}{'usable'})) {
! 1727: $changes->{$item}->{$id}->{'usable'} = 1;
! 1728: }
! 1729: }
! 1730: }
! 1731: }
! 1732: }
! 1733: if (keys(%ltienc) > 0) {
! 1734: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
! 1735: foreach my $id (keys(%ltienc)) {
! 1736: if (exists($ltienc{$id}{'secret'})) {
! 1737: $changes->{$item}->{$id}->{'usable'} = 1;
! 1738: }
! 1739: }
! 1740: } else {
! 1741: $lti_save_error = 1;
! 1742: }
! 1743: }
! 1744: unless ($lti_save_error) {
! 1745: if (&Apache::lonnet::put('lti',$changes->{$item},$cdom,$cnum,1) eq 'ok') {
! 1746: my $hashid=$cdom.'_'.$cnum;
! 1747: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
! 1748: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
! 1749: unless (($chome eq 'no_host') || ($chome eq '')) {
! 1750: my @ids=&Apache::lonnet::current_machine_ids();
! 1751: unless (grep(/^\Q$chome\E$/,@ids)) {
! 1752: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
! 1753: }
! 1754: }
! 1755: foreach my $id (sort { $a <=> $b } %{$changes->{$item}}) {
! 1756: if (ref($changes->{$item}->{$id}) eq 'HASH') {
! 1757: my %values = %{$changes->{$item}->{$id}};
! 1758: my %desc = &linkprot_names();
! 1759: my $display;
! 1760: foreach my $title ('name','lifetime','version','key','secret') {
! 1761: if (($title eq 'key') || ($title eq 'secret')) {
! 1762: if (ref($ltienc{$id}) eq 'HASH') {
! 1763: if (exists($ltienc{$id}{$title})) {
! 1764: if ($title eq 'secret') {
! 1765: my $length = length($ltienc{$id}{$title});
! 1766: $display .= $desc{$title}.': '.('*' x $length);
! 1767: } else {
! 1768: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
! 1769: }
! 1770: }
! 1771: }
! 1772: } elsif ($title eq 'version') {
! 1773: if ($values{$title} eq 'LTI-1p0') {
! 1774: $display .= $desc{$title}.': 1.1, ';
! 1775: }
! 1776: } else {
! 1777: $display .= $desc{$title}.': '.$values{$title}.', ';
1.93 raeburn 1778: }
1779: }
1.99 ! raeburn 1780: $display =~ s/, $//;
! 1781: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
! 1782: "'$display'")).'</li>';
! 1783: } elsif (ref($oldlinkprot{$id}) eq 'HASH') {
! 1784: my $oldname = $oldlinkprot{$id}{'name'};
! 1785: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
1.93 raeburn 1786: }
1787: }
1.99 ! raeburn 1788: } else {
! 1789: $lti_save_error = 1;
1.93 raeburn 1790: }
1.99 ! raeburn 1791: }
! 1792: unless ($lti_save_error) {
! 1793: my @deletions;
! 1794: foreach my $id (sort { $a <=> $b } keys(%{$changes->{$item}})) {
! 1795: unless (ref($changes->{$item}->{$id}) eq 'HASH') {
! 1796: push (@deletions,$id);
! 1797: }
! 1798: }
! 1799: if (@deletions) {
! 1800: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
! 1801: }
! 1802: }
! 1803: if ($lti_save_error) {
1.93 raeburn 1804: $output .= '<li>'.
1805: '<span class="LC_error">'.
1806: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
1807: '</span>'.
1808: '</li>';
1809: }
1.3 raeburn 1810: } else {
1811: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
1812: my @settings = @{$prefs->{$item}->{'ordered'}};
1813: if ($item eq 'feedback') {
1814: push(@settings,(map { $_.'.text'; } @settings));
1815: }
1816: foreach my $key (@settings) {
1817: if ($key eq 'rolenames') {
1818: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
1819: my $msg;
1.9 raeburn 1820: my @roles;
1821: if ($crstype eq 'Community') {
1822: @roles = ('co');
1823: } else {
1824: @roles = ('cc');
1825: }
1826: push(@roles,('in','ta','ep','ad','st'));
1827: foreach my $role (@roles) {
1.3 raeburn 1828: next if (!exists($changes->{$item}{$key.'_'.$role}));
1829: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
1830: my $newname = $changes->{$item}{$key.'_'.$role};
1831: $storehash{$role.'.plaintext'} = $newname;
1832: if ($newname eq '') {
1833: $newname = $stdname;
1834: }
1835: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
1836: "'<b>".$newname."</b>'").'</li>';
1837: }
1838: if ($msg ne '') {
1.22 wenzelju 1839: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 1840: }
1841: } else {
1842: next if (!exists($changes->{$item}{$key}));
1843: my ($displayname,$text);
1844: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 1845: my $displayval;
1.50 raeburn 1846: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts')) {
1.25 raeburn 1847: $displayval = $changes->{$item}{$key};
1848: }
1.3 raeburn 1849: if ($item eq 'feedback') {
1850: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
1851: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
1852: $displayname = &mt('Custom text for '.$text.' questions');
1853: } else {
1854: $displayname = &mt('Recipients of '.$text.' questions');
1855: }
1856: } elsif ($item eq 'discussion') {
1857: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
1858: $displayname = &mt("$text (role-based)");
1859: if ($displayval ne '') {
1860: my @roles = split(',',$displayval);
1861: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
1862: $displayval = join(', ',@roles);
1863: }
1864: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
1865: $displayname = &mt("$text (specific user(s))");
1866: } else {
1867: if ($key eq 'allow_discussion_post_editing') {
1868: if ($displayval ne '') {
1869: my @roles = split(',',$displayval);
1870: my @longroles;
1871: foreach my $role (@roles) {
1872: my ($trole,$sec) = split(':',$role);
1873: my $rolename =
1874: &Apache::lonnet::plaintext($trole);
1875: if ($sec ne '') {
1876: $rolename .= ':'.$sec;
1877: }
1878: push(@longroles,$rolename);
1879: }
1880: $displayval = join(', ',@longroles);
1881: }
1.50 raeburn 1882: } elsif ($key eq 'discussion_post_fonts') {
1883: my ($classorder,$classtitles)=&discussion_vote_classes();
1884: my ($styleorder,$styleitems)=&discussion_vote_styles();
1885: my $count = 1;
1886: my $total = scalar(keys(%{$changes->{$item}}));
1887: foreach my $class (@{$classorder}) {
1888: $count ++;
1889: next unless ($changes->{$item}{$key.'_'.$class});
1890: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
1891: my $showval = '';
1892: for (my $i=0; $i<@{$styleorder}; $i++) {
1893: if ($vals[$i] ne '') {
1894: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
1895: }
1896: }
1897: if ($vals[3] ne '') {
1898: $showval .= $vals[3];
1899: }
1900: if ($showval ne '') {
1901: $displayval .= $classtitles->{$class}.':{ '.
1902: $showval.'}';
1903: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
1904: } else {
1905: $displayval .= $classtitles->{$class}.': '.&mt('None');
1906: push(@delkeys,$key.'_'.$class);
1907: }
1908: unless ($count == $total) {
1909: $displayval .= (' 'x2);
1910: }
1911: }
1.3 raeburn 1912: }
1913: $displayname = &mt($text);
1914: }
1915: } elsif ($item eq 'spreadsheet') {
1916: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
1917: my $sheettype = $1;
1918: if ($sheettype eq 'studentcalc') {
1919: &Apache::lonnet::expirespread('','','studentcalc');
1920: } else {
1921: &Apache::lonnet::expirespread('','','assesscalc');
1922: &Apache::lonnet::expirespread('','','studentcalc');
1923: }
1924: }
1925: $displayname = &mt($text);
1.87 raeburn 1926: } elsif ($item eq 'lti') {
1927: if ($key eq 'lti.lcmenu') {
1928: if ($changes->{$item}{$key} eq 'none') {
1929: $displayval = &mt('None of the configurable menu items displayed');
1930: } else {
1931: my %ltititles = <imenu_titles();
1932: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
1933: }
1934: } else {
1935: if ($changes->{$item}{$key} eq '1') {
1936: $displayval = &mt('Yes');
1937: } elsif ($changes->{$item}{$key} eq '') {
1938: $displayval = &mt('No');
1939: }
1940: }
1941: $displayname = &mt($text);
1.91 raeburn 1942: } elsif ($item eq 'menuitems') {
1943: unless ($changes->{$item}{$key} eq '') {
1944: if ($key eq 'menudefault') {
1945: $displayname = &mt('Default collection of menu items');
1946: $displayval = &mt('Collection: [_1]',
1947: $changes->{$item}{$key});
1948: } elsif ($key eq 'menucollections') {
1949: $displayval = &menucollections_display($changes->{$item}{$key});
1950: }
1951: }
1.3 raeburn 1952: } else {
1953: $displayname = &mt($text);
1954: }
1955: if (defined($yesno{$key})) {
1.14 raeburn 1956: $displayval = &mt('No');
1.3 raeburn 1957: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 1958: $displayval = &mt('Yes');
1.3 raeburn 1959: }
1960: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
1961: $displayval = &Apache::lonlocal::locallocaltime($displayval);
1962: } elsif ($key eq 'categories') {
1963: $displayval = $env{'form.categories_display'};
1.95 raeburn 1964: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
1965: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 1966: if ($changes->{$item}{$key} eq '1') {
1967: $displayval = &mt('Yes');
1968: } elsif ($changes->{$item}{$key} eq '0') {
1969: $displayval = &mt('No');
1970: }
1971: }
1.25 raeburn 1972: if ($key eq 'co-owners') {
1973: if (ref($changes->{$item}{$key}) eq 'HASH') {
1974: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
1975: foreach my $type ('co-owners','pendingco-owners') {
1976: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
1977: if ($type eq 'pendingco-owners') {
1978: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1979: $displayname = &mt('Invited as co-owners, pending acceptance');
1980: }
1981: }
1982: if ($changes->{$item}{$key}{$type} eq '') {
1983: push(@delkeys,'internal.'.$type);
1984: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1985: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
1986: '<i>'.$displayname.'</i>')).'</li>';
1987: }
1988: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1989: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
1990: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1991: '<i>'.$displayname.'</i>',
1992: "'<b>$displayval</b>'")).'</li>';
1993: }
1994: }
1995: }
1996: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 1997: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1998: $displayval = &mt('on');
1.90 raeburn 1999: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2000: $displayval = '';
2001: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2002: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2003: $displayval = &mt('off');
2004: }
2005: if ($displayval) {
2006: $displayname = &mt('Your co-ownership status');
2007: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2008: '<i>'.$displayname.'</i>',
2009: "'<b>$displayval</b>'")).'</li>';
2010: }
2011: }
2012: }
2013: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2014: push(@delkeys,$key);
1.87 raeburn 2015: if ($item eq 'lti') {
2016: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2017: if (($key eq 'lti.lcmenu') &&
2018: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2019: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2020: } else {
2021: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2022: '<i>'.$displayname.'</i>',
2023: "'<b>$displayval</b>'")).'</li>';
2024: }
2025: } elsif (!exists($changes->{$item}{'lti.override'})) {
2026: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2027: }
1.91 raeburn 2028: } elsif ($item eq 'menuitems') {
2029: if ($key eq 'menudefault') {
2030: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2031: } elsif ($key eq 'menucollections') {
2032: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2033: }
1.87 raeburn 2034: } else {
2035: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2036: '<i>'.$displayname.'</i>')).'</li>';
2037: }
1.91 raeburn 2038: } elsif ($key eq 'menucollections') {
2039: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2040: $displayval.'</li>';
1.3 raeburn 2041: } else {
1.22 wenzelju 2042: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.3 raeburn 2043: '<i>'.$displayname.'</i>',
1.22 wenzelju 2044: "'<b>$displayval</b>'"));
1.3 raeburn 2045: if ($key eq 'url') {
2046: my $bkuptime=time;
2047: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2048: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2049: }
2050: $output .= '</li>';
2051: }
1.25 raeburn 2052: if ($key eq 'co-owners') {
2053: if (ref($changes->{$item}{$key}) eq 'HASH') {
2054: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2055: foreach my $type ('co-owners','pendingco-owners') {
2056: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2057: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2058: }
2059: }
2060: }
2061: } else {
1.50 raeburn 2062: unless ($key eq 'discussion_post_fonts') {
2063: $storehash{$key} = $changes->{$item}{$key};
2064: }
1.25 raeburn 2065: }
1.3 raeburn 2066: }
1.23 raeburn 2067: if ($key eq 'cloners') {
2068: # Get existing cloners
2069: my %clonenames =
2070: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2071: if ($clonenames{'cloners'} =~ /,/) {
2072: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2073: } else {
2074: $oldcloner[0] = $clonenames{'cloners'};
2075: }
2076: }
1.3 raeburn 2077: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2078: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2079: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2080: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2081: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2082: push(@need_env_update,$key);
2083: }
2084: }
2085: }
2086: }
2087: $output .= '</ul>';
2088: } else {
1.9 raeburn 2089: if ($crstype eq 'Community') {
1.46 raeburn 2090: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2091: } else {
1.46 raeburn 2092: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2093: }
1.3 raeburn 2094: }
2095: }
2096: }
2097: }
1.93 raeburn 2098: if ($skipstore) {
2099: return $output;
2100: }
1.3 raeburn 2101: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2102: if (ref($changes) eq 'HASH') {
2103: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2104: if (exists($changes->{'courseinfo'}{'cloners'})) {
2105: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2106: \@oldcloner);
2107: }
2108: }
2109: }
1.3 raeburn 2110: if (@delkeys) {
2111: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2112: $output .= '<br /><span class="LC_error">';
2113: if ($crstype eq 'Community') {
2114: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2115: } else {
2116: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2117: }
2118: $output .= '</span>';
1.14 raeburn 2119: } else {
2120: foreach my $key (@delkeys) {
2121: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
2122: }
1.3 raeburn 2123: }
2124: }
2125: if (@need_env_update) {
2126: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2127: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
2128: }
2129: &Apache::lonnet::coursedescription($env{'request.course.id'},
2130: {'freshen_cache' => 1});
2131: } else {
1.9 raeburn 2132: $output = '<span class="LC_error">';
2133: if ($crstype eq 'Community') {
2134: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
2135: } else {
2136: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
2137: }
2138: $output .= '</span>';
1.3 raeburn 2139: }
2140: return $output;
2141: }
2142:
2143: sub update_env {
2144: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
2145: my $count = 0;
2146: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
2147: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
2148: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
2149: foreach my $key (@{$need_env_update}) {
2150: if ($key eq 'description' && defined($storehash->{$key})) {
2151: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
2152: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
2153: $count ++;
2154: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
2155: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
2156: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
2157: $count ++;
1.25 raeburn 2158: } elsif ($key eq 'co-owners') {
2159: if ($storehash->{'internal.co-owners'} ne '') {
2160: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
2161: }
2162: if ($storehash->{'internal.pendingco-owners'} ne '') {
2163: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
2164: }
2165: my @coowners = split(',',$storehash->{'internal.'.$key});
2166: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
2167: $count ++;
1.87 raeburn 2168: } elsif ($key =~ /^lti\./) {
2169: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 2170: }
2171: }
2172: if ($count) {
2173: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
2174: }
2175: }
2176: }
2177: return;
2178: }
2179:
2180: sub display_disallowed {
1.9 raeburn 2181: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 2182: my $output;
2183: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
2184: if (keys(%{$disallowed})) {
2185: if ($item eq 'cloners') {
2186: my @fails;
2187: my %lt = &Apache::lonlocal::texthash (
2188: format => 'Invalid format',
2189: domain => 'Domain does not exist',
2190: newuser => 'LON-CAPA user(s) do(es) not exist.',
2191: );
2192: foreach my $error ('format','domain','newuser') {
2193: if (defined($disallowed->{$error})) {
2194: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
2195: $lt{$error};
2196: if ($error eq 'newuser') {
1.9 raeburn 2197: $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 2198: }
2199: push(@fails,$msg);
2200: }
2201: }
2202: if (@fails) {
2203: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
2204: '</span>'.join('; ',@fails).'.<br />';
2205: }
2206: } elsif ($item eq 'rolenames') {
2207: my %lt = &Apache::lonlocal::texthash (
2208: replacements => 'Name already used to replace a different standard role name',
2209: regulars => 'Name already used as a standard role name',
2210: customrole => 'Name already used as the name of a custom role',
2211: );
2212: my @fails;
2213: foreach my $error ('replacements','regulars','customrole') {
2214: if (ref($disallowed->{$error}) eq 'ARRAY') {
2215: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
2216: '</b>, '.&mt('reason').' - '.$lt{'error'});
2217: }
2218: }
2219: if (@fails) {
2220: $output .= '<span class="LC_warning">'.
2221: &mt('Unable to include amongst replacements for role names: ').
2222: '</span>'.join('; ',@fails).'.<br />';
2223: }
2224:
2225: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
2226: $output .= '<span class="LC_warning">';
2227: if ($item eq 'feedback') {
1.9 raeburn 2228: if ($crstype eq 'Community') {
2229: $output .= &mt('Unable to include as a recipient of community feedback for:');
2230: } else {
2231: $output .= &mt('Unable to include as a recipient of course feedback for:');
2232: }
1.3 raeburn 2233: } elsif ($item eq 'discussion') {
2234: $output .= &mt('Unable to include in user-based access control for:');
2235: } elsif ($item eq 'localization') {
1.9 raeburn 2236: if ($crstype eq 'Community') {
2237: $output .= &mt('Unable to include in community localization:');
2238: } else {
2239: $output .= &mt('Unable to include in course localization:');
2240: }
1.3 raeburn 2241: }
2242: $output .= '</span><ul>';
2243: foreach my $key (sort(keys(%{$disallowed}))) {
2244: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
2245: $output .= '<li><i>'.$itemtext.'</i> - ';
2246: if ($item eq 'localization') {
2247: $output .= &mt('reason - unsupported language: [_1]',
2248: '<b>'.$disallowed->{$key}.'</b>');
2249: } else {
2250: $output .= &mt('reason - invalid user: [_1]',
2251: '<b>'.$disallowed->{$key}.'</b>').'</li>';
2252: }
2253: }
2254: $output .= '</ul><br />';
2255: }
2256: }
1.1 raeburn 2257: }
1.3 raeburn 2258: return $output;
1.1 raeburn 2259: }
2260:
2261: sub get_course {
2262: my ($courseid) = @_;
2263: if (!defined($courseid)) {
2264: $courseid = $env{'request.course.id'};
2265: }
2266: my $cdom=$env{'course.'.$courseid.'.domain'};
2267: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 2268: my $chome=$env{'course.'.$courseid.'.home'};
2269: return ($cnum,$cdom,$chome);
1.1 raeburn 2270: }
2271:
2272: sub get_jscript {
1.91 raeburn 2273: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 2274: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.71 raeburn 2275: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js);
1.1 raeburn 2276: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
2277: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 2278: my $cloners_js = &cloners_javascript($phase);
1.71 raeburn 2279: my @code_order;
2280: if ($crstype ne 'Community') {
2281: if (ref($settings) eq 'HASH') {
2282: my %codedefaults;
2283: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
2284: \@code_order);
2285: if (@code_order > 0) {
2286: if ($phase eq 'display') {
2287: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
2288: if (grep(/^courseinfo$/,@actions)) {
2289: if ($settings->{'cloners'} ne '') {
2290: unless ($settings->{'cloners'} eq '*') {
2291: my @cloners = split(/,/,$settings->{'cloners'});
2292: my @standardnames = &Apache::loncommon::get_standard_codeitems();
2293: my %local_to_standard;
2294: for (my $i=0; $i<@code_order; $i++) {
2295: $local_to_standard{$code_order[$i]} = $standardnames[$i];
2296: }
2297: foreach my $cloner (@cloners) {
2298: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
2299: ($cloner !~ /^$match_username\:$match_domain$/)) {
2300: foreach my $item (split(/\&/,$cloner)) {
2301: my ($key,$val) = split(/\=/,$item);
2302: $val = &unescape($val);
2303: foreach my $code (@code_order) {
2304: if ($key eq $local_to_standard{$code}) {
2305: $env{'form.'.$key} = $val;
2306: }
2307: }
2308: }
2309: }
2310: }
2311: }
2312: }
2313: }
2314: }
2315: my @codetitles;
2316: (undef,$instcode_js) =
2317: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
2318: \@codetitles);
2319: $instcode_js .= <<ENDSCRIPT;
2320: function toggleCloners(callerradio) {
2321: if (document.getElementById('LC_cloners_instcode')) {
2322: if (callerradio.value == 1) {
2323: document.getElementById('LC_cloners_instcode').style.display = "block";
2324: } else {
2325: uncheckOfficialLists();
2326: document.getElementById('LC_cloners_instcode').style.display = "none";
2327: }
2328: }
2329: }
2330:
2331: if (!document.getElementsByClassName) {
2332: function getElementsByClassName(node, classname) {
2333: var a = [];
2334: var re = new RegExp('(^| )'+classname+'( |$)');
2335: var els = node.getElementsByTagName("*");
2336: for(var i=0,j=els.length; i<j; i++)
2337: if(re.test(els[i].className))a.push(els[i]);
2338: return a;
2339: }
2340: }
2341:
2342: function uncheckOfficialLists() {
2343: var codepicks;
2344: if (document.getElementsByClassName) {
2345: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
2346: } else {
2347: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
2348: }
2349: if (codepicks.length) {
2350: for (var i=0; i<codepicks.length; i++) {
2351: codepicks[i].selectedIndex = 0;
2352: }
2353: }
2354: }
2355:
2356: ENDSCRIPT
2357: }
2358: }
2359: }
1.1 raeburn 2360: if ($can_categorize) {
2361: $categorize_js = <<ENDSCRIPT;
2362: function catsbrowser() {
2363: var catswin = null;
2364: var url = '/adm/courseprefs?phase=categorizecourse';
2365: if (!catswin || catswin.closed) {
2366: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2367: } else {
2368: catswin.focus();
2369: }
2370: }
2371: ENDSCRIPT
2372: }
1.36 raeburn 2373: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
2374: if ($loncaparev) {
2375: $loncaparev_js = <<ENDSCRIPT;
2376: function loncaparevinfo() {
2377: var lcrevwin = null;
2378: var url = '/adm/courseprefs?phase=releaseinfo';
2379: if (!lcrevwin || lcrevwin.closed) {
2380: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2381: } else {
2382: lcrevwin.focus();
2383: }
2384: }
2385: ENDSCRIPT
2386: }
1.60 raeburn 2387: my $cnum = $env{'course.'.$cid.'.num'};
2388: my $syllabus_js = <<ENDSCRIPT;
2389: function syllabusinfo() {
2390: var syllwin = null;
2391: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
2392: if (!syllwin || syllwin.closed) {
2393: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2394: } else {
2395: syllwin.focus();
2396: }
2397: }
2398: ENDSCRIPT
1.91 raeburn 2399: my $menuitems_js;
2400: unless ($noedit) {
2401: my $collections;
2402: my $next = 1;
2403: if (ref($settings) eq 'HASH') {
2404: if ($settings->{'menucollections'} ne '') {
2405: my @current;
2406: foreach my $item (split(/;/,$settings->{'menucollections'})) {
2407: my ($num) = split(/\%/,$item);
2408: if ($num =~ /^\d+$/) {
2409: push(@current,$num);
2410: }
2411: }
2412: $collections = join("','",sort { $a <=> $b } @current);
2413: if ($collections) {
2414: $collections = "'$collections'";
2415: }
2416: $next += $current[-1];
2417: }
2418: }
2419: my $deftext = &mt('Standard (all menus shown)');
2420: $menuitems_js = <<ENDSCRIPT;
2421: function toggleAddmenucoll() {
2422: if (document.getElementById('menucollections_add')) {
2423: var state = 'none';
2424: var add = document.getElementById('menucollections_add').checked;
2425: if (add) {
2426: state = 'inline-block';
2427: }
2428: var fieldsets = new Array('shown','text','links','list','inline');
2429: for (var i=0; i<fieldsets.length; i++) {
2430: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
2431: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
2432: }
2433: }
2434: var box = document.getElementsByClassName('LC_menucoll_add');
2435: if (box.length) {
2436: for (var i=0; i<box.length; i++) {
2437: if (add) {
2438: box[i].checked = true;
2439: } else {
2440: box[i].checked = false;
2441: }
2442: }
2443: }
2444: if (document.getElementById('menudefault')) {
2445: var menudef = document.getElementById('menudefault');
2446: var currsel = menudef.selectedIndex;
2447: var colls = new Array($collections);
2448: menudef.options.length = 0;
2449: if (!add) {
2450: if (currsel == 1 + colls.length) {
2451: currsel = 0;
2452: }
2453: }
2454: if (currsel == 0) {
2455: menudef.options[0] = new Option('$deftext','',true,true);
2456: } else {
2457: menudef.options[0] = new Option('$deftext','',false,false);
2458: }
2459: if (colls.length) {
2460: for (var i=0; i<colls.length; i++) {
2461: var idx = i+1;
2462: if (currsel == colls[i]) {
2463: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
2464: } else {
2465: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
2466: }
2467: }
2468: }
2469: if (add) {
2470: var addidx = 1 + colls.length;
2471: if (currsel == addidx) {
2472: menudef.options[addidx] = new Option('$next','$next',true,true);
2473: } else {
2474: menudef.options[addidx] = new Option('$next','$next',false,false);
2475: }
2476: }
2477: }
2478: }
2479: }
2480: ENDSCRIPT
2481: }
1.99 ! raeburn 2482: my $linkprotector_js = <<"ENDSCRIPT";
! 2483: function toggleLTI(form,num,item) {
! 2484: var radioname = '';
! 2485: var currdivid = '';
! 2486: var newdivid = '';
! 2487: if ((document.getElementById('linkprot_divcurr'+item+'_'+num)) &&
! 2488: (document.getElementById('linkprot_divchg'+item+'_'+num))) {
! 2489: currdivid = document.getElementById('linkprot_divcurr'+item+'_'+num);
! 2490: newdivid = document.getElementById('linkprot_divchg'+item+'_'+num);
! 2491: radioname = form.elements['linkprot_change'+item+'_'+num];
! 2492: if (radioname) {
! 2493: if (radioname.length > 0) {
! 2494: var setvis;
! 2495: for (var i=0; i<radioname.length; i++) {
! 2496: if (radioname[i].checked == true) {
! 2497: if (radioname[i].value == 1) {
! 2498: newdivid.style.display = 'inline-block';
! 2499: currdivid.style.display = 'none';
! 2500: setvis = 1;
! 2501: }
! 2502: break;
! 2503: }
! 2504: }
! 2505: if (!setvis) {
! 2506: newdivid.style.display = 'none';
! 2507: currdivid.style.display = 'inline-block';
! 2508: }
! 2509: }
! 2510: }
! 2511: }
! 2512: return;
! 2513: }
! 2514: ENDSCRIPT
1.1 raeburn 2515: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.56 raeburn 2516: '// <![CDATA['."\n".
1.36 raeburn 2517: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.71 raeburn 2518: $cloners_js."\n".$instcode_js.
1.99 ! raeburn 2519: $syllabus_js."\n".$menuitems_js."\n".
! 2520: $linkprotector_js."\n".'//]]>'."\n".
1.56 raeburn 2521: '</script>'."\n".$stubrowse_js."\n";
1.1 raeburn 2522: return $jscript;
2523: }
2524:
1.3 raeburn 2525: sub cloners_javascript {
2526: my ($formname) = @_;
2527: return <<"ENDSCRIPT";
2528:
2529: function update_cloners(caller,num) {
2530: var delidx = getIndexByName('cloners_delete');
2531: var actidx = getIndexByName('cloners_activate');
2532: if (caller == 'cloners_all') {
2533: var selall;
2534: for (var i=0; i<document.$formname.cloners_all.length; i++) {
2535: if (document.$formname.cloners_all[i].checked) {
2536: selall = document.$formname.cloners_all[i].value;
2537: }
2538: }
2539: if (selall == 1) {
2540: if (delidx != -1) {
2541: if (document.$formname.cloners_delete.length) {
2542: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
2543: document.$formname.cloners_delete[j].checked = true;
2544: }
2545: } else {
2546: document.$formname.elements[delidx].checked = true;
2547: }
2548: }
2549: if (actidx != -1) {
2550: if (document.$formname.cloners_activate.length) {
2551: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
2552: if (document.$formname.cloners_activate[i].value == '0') {
2553: document.$formname.cloners_activate[i].checked = false;
2554: }
1.71 raeburn 2555: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 2556: document.$formname.cloners_activate[i].checked = true;
2557: }
2558: }
2559: }
2560: }
2561: document.$formname.cloners_newdom.selectedIndex = 0;
2562: }
2563: }
2564: if (caller == 'cloners_activate') {
2565: if (document.$formname.cloners_activate.length) {
2566: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
2567: if (document.$formname.cloners_activate[j].value == num) {
2568: if (document.$formname.cloners_activate[j].checked) {
2569: for (var i=0; i<document.$formname.cloners_all.length; i++) {
2570: if (document.$formname.cloners_all[i].value == '1') {
2571: document.$formname.cloners_all[i].checked = false;
2572: }
2573: if (document.$formname.cloners_all[i].value == '0') {
2574: document.$formname.cloners_all[i].checked = true;
2575: }
2576: }
2577: }
2578: }
2579: }
2580: } else {
2581: for (var i=0; i<document.$formname.cloners_all.length; i++) {
2582: if (document.$formname.cloners_all[i].value == '1') {
2583: document.$formname.cloners_all[i].checked = false;
2584: }
2585: if (document.$formname.cloners_all[i].value == '0') {
2586: document.$formname.cloners_all[i].checked = true;
2587: }
2588: }
2589: }
2590: }
2591: return;
2592: }
2593:
2594: function getIndexByName(item) {
2595: for (var i=0;i<document.$formname.elements.length;i++) {
2596: if (document.$formname.elements[i].name == item) {
2597: return i;
2598: }
2599: }
2600: return -1;
2601: }
2602:
2603: ENDSCRIPT
2604: }
2605:
2606:
1.1 raeburn 2607: sub print_courseinfo {
1.80 raeburn 2608: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 2609: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 2610: return;
2611: }
1.83 raeburn 2612: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
2613: if ($noedit) {
2614: $disabled = ' disabled="disabled"';
2615: }
1.1 raeburn 2616: my %domconf =
1.71 raeburn 2617: &Apache::lonnet::get_dom('configuration',
2618: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 2619: if (ref($domconf{'coursecategories'}) eq 'HASH') {
2620: $cathash = $domconf{'coursecategories'}{'cats'};
2621: if (ref($cathash) eq 'HASH') {
2622: $categoriesform =
2623: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 2624: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 2625: }
2626: }
1.25 raeburn 2627: if (ref($domconf{'autoenroll'}) eq 'HASH') {
2628: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
2629: }
1.71 raeburn 2630: my ($currcanclone,@code_order,$cloner_instcode);
2631: my %codedefaults;
2632: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
2633: \@code_order);
2634: if ($settings->{'cloners'}) {
2635: unless ($settings->{'cloners'} eq '*') {
2636: my @currclone = split(/,/,$settings->{'cloners'});
2637: foreach my $item (@currclone) {
2638: unless ($item eq '*') {
2639: if (($item !~ /\:/) && ($item =~ /=/)) {
2640: $cloner_instcode = 1;
2641: }
2642: }
2643: }
2644: }
2645: }
2646: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
2647: my $canclone = $domconf{'coursedefaults'}{'canclone'};
2648: if (ref($canclone) eq 'HASH') {
2649: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
2650: if ($settings->{'internal.coursecode'}) {
2651: my @posscodes;
2652: if (@code_order > 0) {
2653: $currcanclone = 'instcode';
2654: foreach my $item (@{$canclone->{'instcode'}}) {
2655: if (grep(/^\Q$item\E$/,@code_order)) {
2656: push(@posscodes,$item);
2657: }
2658: }
2659: my $codestr = join(' + ',@posscodes);
2660: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
2661: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
2662: }
2663: }
2664: }
2665: } elsif ($canclone eq 'domain') {
2666: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
2667: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
2668: $currcanclone = 'domain';
2669: }
2670: if ($clonedefaults) {
2671: if ($settings->{'cloners'} ne '') {
2672: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
2673: } else {
2674: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
2675: }
2676: $clonedefaults = '<br /><br />'.$clonedefaults;
2677: }
2678: }
1.1 raeburn 2679: if (!defined($categoriesform)) {
1.15 raeburn 2680: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 2681: }
1.12 raeburn 2682: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 2683: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 2684:
1.9 raeburn 2685: my $replace;
2686: if ($crstype eq 'Community') {
2687: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
2688: } else {
2689: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
2690: }
1.84 raeburn 2691: my ($editmap,$editsyllabus);
2692: unless ($noedit) {
2693: $editmap = (' 'x2).
2694: '<a href="javascript:openbrowser'.
2695: "('display','url','sequence')\">".
2696: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
2697: &mt('Modification may make assessment data inaccessible!').
2698: '</span>';
2699: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
2700: '</a>');
2701: }
1.1 raeburn 2702: my %items = (
1.3 raeburn 2703: 'url' => {
1.84 raeburn 2704: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 2705: input => 'textbox',
1.55 raeburn 2706: size => '55',
1.19 faziophi 2707: advanced => 1
1.1 raeburn 2708: },
2709: 'description' => {
1.3 raeburn 2710: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 2711: input => 'textbox',
1.55 raeburn 2712: size => '55',
1.1 raeburn 2713: },
1.24 raeburn 2714: 'owner' => {
2715: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
2716: },
1.25 raeburn 2717: 'co-owners' => {
2718: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
2719: },
1.63 raeburn 2720: 'clonedfrom' => {
2721: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
2722: },
1.1 raeburn 2723: 'courseid' => {
1.3 raeburn 2724: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
2725: &mt('internal, optional').')',
1.1 raeburn 2726: input => 'textbox',
2727: size => '25',
2728: },
1.64 raeburn 2729: 'uniquecode' => {
2730: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
2731: },
1.1 raeburn 2732: 'cloners' => {
1.3 raeburn 2733: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 2734: &mt('Owner and Coordinators included automatically').
2735: $clonedefaults,
1.1 raeburn 2736: input => 'textbox',
1.41 www 2737: size => '40'
1.1 raeburn 2738: },
2739: 'rolenames' => {
1.3 raeburn 2740: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 2741: '('.$replace.')',
1.1 raeburn 2742: input => 'textbox',
2743: size => '20',
1.19 faziophi 2744: advanced => 1
1.1 raeburn 2745: },
1.88 raeburn 2746: 'syllabus' => {
2747: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 2748: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 2749: $editsyllabus,
1.1 raeburn 2750: },
2751: 'hidefromcat' => {
1.3 raeburn 2752: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 2753: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
2754: input => 'radio',
2755: },
2756: 'categories' => {
1.3 raeburn 2757: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 2758: &mt('Display Categories').'</a>',
2759: input => 'textbox',
2760: size => '25',
2761: },
1.35 raeburn 2762: 'loncaparev' => {
2763: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
2764: },
1.55 raeburn 2765: 'defaultcredits' => {
2766: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
2767: },
1.1 raeburn 2768: );
2769: my $datatable;
2770: my $count = 0;
2771: foreach my $item (@{$ordered}) {
1.56 raeburn 2772: my $colspan;
1.1 raeburn 2773: if ($item eq 'hidefromcat') {
2774: next if (!$can_toggle_cat);
2775: } elsif ($item eq 'categories') {
2776: next if (!$can_categorize);
1.64 raeburn 2777: } elsif ($item eq 'uniquecode') {
2778: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 2779: }
1.56 raeburn 2780: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
2781: $colspan = 2;
2782: }
1.1 raeburn 2783: $count ++;
1.19 faziophi 2784: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 2785: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 2786: } else {
1.56 raeburn 2787: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 2788: }
1.1 raeburn 2789: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 2790: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 2791: } elsif ($item eq 'cloners') {
2792: my $includeempty = 1;
2793: my $num = 0;
1.56 raeburn 2794: $datatable .= '</td><td align="right">'.
2795: &Apache::loncommon::start_data_table().
1.1 raeburn 2796: &Apache::loncommon::start_data_table_row().
2797: '<td><span class="LC_nobreak"><label>'.
2798: &mt('Any user in any domain:').
2799: ' <input type="radio" name="cloners_all" value="1" ';
2800: if ($settings->{$item} eq '*') {
2801: $datatable .= ' checked="checked" ';
2802: }
2803: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 2804: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 2805: (' 'x2).'<label>'.
2806: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 2807: if ($settings->{$item} ne '*') {
2808: $datatable .= ' checked="checked" ';
2809: }
2810: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 2811: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 2812: &Apache::loncommon::end_data_table_row().
2813: &Apache::loncommon::end_data_table().
1.56 raeburn 2814: '<table><tr><td align="left"><b>'.&mt('Or').
2815: '</b></td></tr></table>'.
1.1 raeburn 2816: &Apache::loncommon::start_data_table();
2817: my @cloners;
2818: if ($settings->{$item} eq '') {
1.80 raeburn 2819: unless ($noedit) {
2820: my $default;
2821: if ($currcanclone eq 'domain') {
2822: $default = '0';
2823: }
2824: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 2825: }
1.1 raeburn 2826: } elsif ($settings->{$item} ne '*') {
2827: my @entries = split(/,/,$settings->{$item});
2828: if (@entries > 0) {
2829: foreach my $entry (@entries) {
2830: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 2831: if ($udom =~ /^$match_domain$/) {
2832: unless (&Apache::lonnet::domain($udom)) {
2833: next;
2834: }
2835: } else {
2836: next;
2837: }
1.1 raeburn 2838: if ($uname eq '*') {
2839: $datatable .=
2840: &Apache::loncommon::start_data_table_row().
1.3 raeburn 2841: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 2842: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 2843: '</b><input type="hidden" name="cloners_dom_'.$num.
2844: '" value="'.$udom.'" /></span><br />'.
2845: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 2846: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 2847: &mt('Delete').'</label></span></td>'.
2848: &Apache::loncommon::end_data_table_row();
2849: $num ++;
1.23 raeburn 2850: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
2851: unless (grep(/^\Q$entry\E$/,@cloners)) {
2852: push(@cloners,$entry);
2853: }
1.1 raeburn 2854: }
2855: }
2856: }
2857: }
2858: my $add_domtitle = &mt('Any user in additional domain:');
2859: if ($settings->{$item} eq '*') {
2860: $add_domtitle = &mt('Any user in specific domain:');
2861: } elsif ($settings->{$item} eq '') {
2862: $add_domtitle = &mt('Any user in other domain:');
2863: }
2864: my $cloners_str = join(',',@cloners);
2865: $datatable .= &Apache::loncommon::start_data_table_row().
2866: '<td align="left"><span class="LC_nobreak">'.
2867: $add_domtitle.'</span><br />'.
2868: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 2869: $includeempty,undef,undef,
2870: undef,undef,$noedit).
1.1 raeburn 2871: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
2872: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 2873: &Apache::loncommon::end_data_table().
1.56 raeburn 2874: '<table><tr><td align="left"><b>'.&mt('And').
2875: '</b></td></tr></table>'.
1.1 raeburn 2876: &Apache::loncommon::start_data_table().
2877: &Apache::loncommon::start_data_table_row().
2878: '<td align="left">'.
2879: &mt('Specific users').' (<tt>'.
2880: &mt('user:domain,user:domain').'</tt>)<br />'.
2881: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 2882: $items{$item}{'size'},$disabled).
1.1 raeburn 2883: '</td>'.&Apache::loncommon::end_data_table_row().
2884: &Apache::loncommon::end_data_table();
1.71 raeburn 2885: if (@code_order > 0) {
2886: my (%cat_items,@codetitles,%cat_titles,%cat_order);
2887: my ($jscript,$totcodes,$numtitles,$lasttitle) =
2888: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
2889: \%cat_items,\@codetitles,
2890: \%cat_titles,\%cat_order);
2891: my $showncodes = 'off';
2892: my $checkedoff = ' checked="checked"';
2893: my $checkedon = '';
2894: if ($cloner_instcode) {
2895: $checkedon = $checkedoff;
2896: $checkedoff = '';
2897: $showncodes = 'on';
2898: }
2899: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
2900: '</b></td></tr></table>'.
2901: &Apache::loncommon::start_data_table().
2902: &Apache::loncommon::start_data_table_row().
2903: '<td align="left"><span class="LC_nobreak">'.
2904: &mt('Cloning by official course(s) based on course category').(' 'x2).
2905: '<label>'.
1.80 raeburn 2906: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 2907: (' ').
2908: '<label>'.
1.80 raeburn 2909: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 2910: &Apache::courseclassifier::build_instcode_selectors($numtitles,
2911: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 2912: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 2913: '</td>'.&Apache::loncommon::end_data_table_row().
2914: &Apache::loncommon::end_data_table();
2915: }
1.1 raeburn 2916: } elsif ($item eq 'rolenames') {
1.56 raeburn 2917: $datatable .= '</td><td align="right">'.
2918: &Apache::loncommon::start_data_table();
1.9 raeburn 2919: my @roles;
2920: if ($crstype eq 'Community') {
2921: @roles = ('co');
2922: } else {
2923: @roles = ('cc');
2924: }
2925: push (@roles,('in','ta','ep','ad','st'));
2926: foreach my $role (@roles) {
1.1 raeburn 2927: $datatable .= &Apache::loncommon::start_data_table_row().
2928: '<td align="left"><span class="LC_nobreak">'.
2929: &Apache::lonnet::plaintext($role,$crstype,undef,1).
2930: '</span></td><td align="left">'.
2931: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
2932: $settings->{$role.'.plaintext'},
1.80 raeburn 2933: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 2934: &Apache::loncommon::end_data_table_row();
2935: }
2936: $datatable .= &Apache::loncommon::end_data_table().'</td>';
2937: } elsif ($item eq 'categories') {
1.80 raeburn 2938: my $launcher;
2939: if ($noedit) {
2940: $launcher = $disabled;
2941: } else {
2942: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
2943: }
1.3 raeburn 2944: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
2945: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
2946: $items{$item}{size},$launcher);
1.24 raeburn 2947: } elsif ($item eq 'owner') {
2948: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
2949: if ($owner =~ /:/) {
2950: my ($ownername,$ownerdom) = split(':',$owner);
2951: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
2952: } elsif ($owner ne '') {
2953: $owner = &Apache::loncommon::plainname($owner,$cdom);
2954: } else {
2955: $owner = &mt('None specified');
2956: }
2957: $datatable .= $owner;
1.63 raeburn 2958: } elsif ($item eq 'clonedfrom') {
2959: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
2960: my $clonedfrom = &mt('None');
2961: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 2962: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 2963: if ($clonesrcinfo{'description'}) {
2964: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
2965: }
2966: }
2967: $datatable .= $clonedfrom;
1.64 raeburn 2968: } elsif ($item eq 'uniquecode') {
2969: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
2970: if ($code) {
2971: $datatable .= $code;
2972: }
1.25 raeburn 2973: } elsif ($item eq 'co-owners') {
2974: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
2975: my @currcoown;
2976: if ($coowners) {
2977: @currcoown = split(',',$coowners);
2978: }
2979: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2980: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
2981: $datatable .= &show_autocoowners(@currcoown);
2982: } else {
1.80 raeburn 2983: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 2984: }
2985: } else {
2986: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
2987: $datatable .= &show_autocoowners(@currcoown);
2988: } else {
1.80 raeburn 2989: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 2990: }
2991: }
1.88 raeburn 2992: } elsif ($item eq 'syllabus') {
1.60 raeburn 2993: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
2994: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
2995: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
2996: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
2997: if ($minimal =~/\w/) {
2998: if ($external =~ m{\Q$minimal\E$}) {
2999: undef($external);
3000: }
3001: } elsif ($uploaded =~/\w/) {
3002: if ($external =~ m{\Q$uploaded\E$}) {
3003: undef($external);
3004: }
3005: }
3006: } elsif ($external!~/\w/) {
3007: undef($external);
3008: }
3009: if ($external) {
3010: $datatable .= &mt('External URL');
3011: } elsif ($minimal) {
3012: $datatable .= &mt('Minimal template');
3013: } elsif ($uploaded) {
3014: $datatable .= &mt('Uploaded file');
3015: } else {
3016: $datatable .= &mt('Standard template');
3017: }
3018: $datatable .= (' ' x 2).
3019: &mt('[_1]View[_2]',
3020: '<a href="javascript:syllabusinfo();">',
3021: '</a>');
1.35 raeburn 3022: } elsif ($item eq 'loncaparev') {
3023: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
3024: my $showreqd;
3025: if ($loncaparev) {
1.36 raeburn 3026: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 3027: &mt('Details').'</a>';
1.35 raeburn 3028: } else {
3029: $showreqd = &mt('No specific version required');
3030: }
3031: $datatable .= $showreqd;
1.1 raeburn 3032: } else {
1.80 raeburn 3033: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 3034: }
3035: $datatable .= &item_table_row_end();
3036: }
3037: $$rowtotal += scalar(@{$ordered});
3038: return $datatable;
3039: }
3040:
3041: sub new_cloners_dom_row {
1.71 raeburn 3042: my ($newdom,$num,$default) = @_;
3043: my ($output,$checkedon,$checkedoff);
1.1 raeburn 3044: if ($newdom ne '') {
1.71 raeburn 3045: if ($num eq $default) {
3046: $checkedon = 'checked="checked" ';
3047: } else {
3048: $checkedoff = 'checked="checked" ';
3049: }
1.1 raeburn 3050: $output .= &Apache::loncommon::start_data_table_row().
3051: '<td valign="top"><span class="LC_nobreak">'.
3052: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
3053: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 3054: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 3055: 'onchange="javascript:update_cloners('.
1.1 raeburn 3056: "'cloners_activate','$num'".');" />'.
3057: &mt('Yes').'</label>'.(' 'x2).
3058: '<label><input type="radio" '.
1.71 raeburn 3059: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 3060: 'onchange="javascript:update_cloners('.
1.1 raeburn 3061: "'cloners_activate','$num'".');" />'.
1.3 raeburn 3062: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
3063: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 3064: &Apache::loncommon::end_data_table_row();
3065: }
3066: return $output;
3067: }
3068:
3069: sub can_modify_catsettings {
1.12 raeburn 3070: my ($dom,$crstype) = @_;
1.1 raeburn 3071: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
3072: my ($can_toggle_cat,$can_categorize);
3073: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 3074: if ($crstype eq 'Community') {
3075: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
3076: $can_toggle_cat = 1;
3077: }
3078: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
3079: $can_categorize = 1;
3080: }
3081: } else {
3082: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
3083: $can_toggle_cat = 1;
3084: }
3085: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
3086: $can_categorize = 1;
3087: }
1.1 raeburn 3088: }
3089: }
3090: return ($can_toggle_cat,$can_categorize);
3091: }
3092:
3093: sub assign_course_categories {
1.9 raeburn 3094: my ($r,$crstype) = @_;
1.1 raeburn 3095: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3096: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3097: my $hascats = 0;
3098: my $cathash;
3099: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
3100: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3101: $cathash = $domconf{'coursecategories'}{'cats'};
3102: if (ref($cathash) eq 'HASH') {
1.12 raeburn 3103: foreach my $cat (keys(%{$cathash})) {
3104: next if ($cat eq 'instcode::0');
3105: unless ($crstype eq 'Community') {
3106: next if ($cat eq 'communities::0');
3107: }
3108: $hascats ++;
3109: }
1.1 raeburn 3110: }
3111: }
3112: my $catwin_js;
3113: if ($hascats) {
1.9 raeburn 3114: my $alert;
3115: if ($crstype eq 'Community') {
3116: $alert = &mt("Use 'Save' in the main window to save community categories");
3117: } else {
3118: $alert = &mt("Use 'Save' in the main window to save course categories");
3119: }
1.72 damieng 3120: &js_escape(\$alert);
1.1 raeburn 3121: $catwin_js = <<ENDSCRIPT;
3122: <script type="text/javascript">
3123:
3124: function updateCategories() {
3125: var newcategories = '';
3126: var unescapedcats = '';
3127: if (document.chgcats.usecategory.length) {
3128: for (var i=0; i<document.chgcats.usecategory.length; i++) {
3129: if (document.chgcats.usecategory[i].checked == true) {
3130: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
3131: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
3132: }
3133: }
3134: if (newcategories.length > 0) {
3135: newcategories = newcategories.slice(0,-1);
3136: }
3137: if (unescapedcats.length > 0) {
3138: unescapedcats = unescapedcats.slice(0,-3);
3139: }
3140: } else {
3141: if (document.chgcats.usecategory.checked == true) {
3142: newcategories = document.chgcats.usecategory.value;
3143: unescapedcats = document.chgcats.catname.value;
3144: }
3145: }
3146: opener.document.display.categories.value = newcategories;
3147: opener.document.display.categories_display.value = unescapedcats;
3148: alert("$alert");
3149: self.close();
3150: return;
3151: }
3152:
3153: </script>
3154: ENDSCRIPT
3155: } else {
3156: my $onload;
3157: }
1.9 raeburn 3158: my ($crscat,$catcrs,$assign);
3159: if ($crstype eq 'Community') {
3160: $crscat = 'Community Categories';
3161: $catcrs = &mt('Categorize Community');
3162: $assign = &mt('Assign one or more categories to this community.')
3163: } else {
3164: $crscat = 'Course Categories';
3165: $catcrs = &mt('Categorize Course');
3166: $assign = &mt('Assign one or more categories to this course.')
3167: }
1.1 raeburn 3168: my $start_page =
1.9 raeburn 3169: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 3170: {'only_body' => 1,});
3171: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 3172: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 3173: if ($hascats) {
3174: my %currsettings =
3175: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 3176: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
3177: $currsettings{'categories'},$crstype);
3178: if ($cattable eq '') {
3179: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
3180: } else {
3181: $categoriesform .= $assign.'<br /><br />'.
3182: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
3183: $cattable."\n".
3184: '<br /><input type="button" name="changes" value="'.
3185: &mt('Copy to main window').'" '.
3186: 'onclick="javascript:updateCategories()" /></form><br />';
3187: }
1.1 raeburn 3188: } else {
1.12 raeburn 3189: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 3190: }
3191: $r->print($start_page.$categoriesform.$end_page);
3192: return;
3193: }
3194:
1.36 raeburn 3195: sub display_loncaparev_constraints {
3196: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.66 raeburn 3197: my ($reqdmajor,$reqdminor);
1.36 raeburn 3198: my $cid = $env{'request.course.id'};
3199: my $cdom = $env{'course.'.$cid.'.domain'};
3200: my $cnum = $env{'course.'.$cid.'.num'};
3201: my $output;
1.39 raeburn 3202: my %lt = &Apache::lonlocal::texthash (
3203: 'all' => 'all',
3204: 'section/group' => 'section/group',
3205: 'user' => 'user',
3206: );
1.66 raeburn 3207: &Apache::lonrelrequtils::init_global_hashes();
3208: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
3209: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 3210: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 3211: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 3212: }
3213: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 3214: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 3215: @scopeorder = ('all','section/group','user');
1.67 raeburn 3216: my $now = time;
1.36 raeburn 3217: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
3218: if (ref($resourcedata) eq 'HASH') {
3219: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 3220: my %found;
1.66 raeburn 3221: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 3222: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 3223: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
3224: my $value = $resourcedata->{$key};
3225: if ($item eq 'examcode') {
3226: if (&Apache::lonnet::validCODE($value)) {
3227: $value = 'valid';
3228: } else {
3229: $value = '';
3230: }
3231: } elsif ($item eq 'printstartdate') {
1.67 raeburn 3232: if ($value =~ /^\d+$/) {
1.70 raeburn 3233: if ($value > $now) {
3234: $value = 'future';
3235: }
3236: }
3237: } elsif ($item eq 'printenddate') {
3238: if ($value =~ /^\d+$/) {
3239: if ($value < $now) {
3240: $value = 'past';
3241: }
3242: }
3243: }
3244: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
3245: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
3246: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 3247: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 3248: }
3249: }
3250: }
3251: }
1.79 raeburn 3252: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
3253: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 3254: my $value = $resourcedata->{$key};
1.79 raeburn 3255: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 3256: if ($value =~ /$valuematch/) {
3257: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 3258: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 3259: $found{$item}{'rev'} =
1.76 raeburn 3260: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 3261: last;
3262: }
3263: }
3264: }
3265: }
1.76 raeburn 3266: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
3267: my $regexp;
3268: if ($item eq 'maplevelrecurse') {
3269: $regexp = '\.(?:sequence|page)___\(rec\)\.';
3270: }
3271: if ($regexp ne '') {
3272: if ($key =~ /$regexp.*\.(\w+)$/) {
3273: my $name = $1;
3274: my $value = $resourcedata->{$key};
3275: if ($name eq 'type') {
3276: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
3277: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
3278: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
3279: }
3280: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
3281: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
3282: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
3283: $found{$name}{'rev'} =
3284: $Apache::lonnet::needsrelease{'parameter::::'.$item};
3285: }
3286: }
3287: }
1.70 raeburn 3288: foreach my $item (keys(%found)) {
3289: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
3290: my $rev = $found{$item}{'rev'};
3291: my $valname = $found{$item}{'valname'};
1.76 raeburn 3292: my $extra = $found{$item}{'extra'};
1.70 raeburn 3293: my ($middle,$scope,$which,$level,$map,$resource);
3294: my $start = $cid.'.';
3295: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
3296: $middle = $1;
3297: $which = $2;
3298: $scope = 'user';
3299: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
3300: $middle = $1;
3301: $which = $2;
3302: $scope = 'section/group';
3303: } else {
3304: $scope = 'all';
3305: }
3306: my $what="$stdname=$valname";
1.76 raeburn 3307: if ($extra) {
3308: $what .= "<br/>$extra<br />";
3309: }
1.70 raeburn 3310: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
3311: $level = 'general';
3312: if ($scope eq 'all') {
3313: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
3314: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
3315: push(@{$fromparam{$rev}{$scope}},$what);
3316: }
3317: } else {
3318: push(@{$fromparam{$rev}{$scope}},$what);
3319: }
3320: } else {
3321: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
3322: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
3323: push(@{$fromparam{$rev}{$scope}{$which}},$what);
3324: }
3325: } else {
3326: push(@{$fromparam{$rev}{$scope}{$which}},$what);
3327: }
3328: }
3329: $rowspan{$rev} ++;
1.76 raeburn 3330: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 3331: $level = 'folder';
3332: $map = $1;
3333: if ($scope eq 'all') {
3334: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
3335: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
3336: push(@{$bymap{$map}{$rev}{$scope}},$what);
3337: }
3338: } else {
3339: push(@{$bymap{$map}{$rev}{$scope}},$what);
3340: }
3341: } else {
3342: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
3343: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
3344: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
3345: }
3346: } else {
3347: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
3348: }
3349: }
3350: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
3351: $level = 'resource';
3352: $resource = $1;
3353: if ($scope eq 'all') {
3354: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
3355: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
3356: push(@{$byresource{$resource}{$rev}{$scope}},$what);
3357: }
3358: } else {
3359: push(@{$byresource{$resource}{$rev}{$scope}},$what);
3360: }
3361: } else {
3362: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
3363: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
3364: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
3365: }
3366: } else {
3367: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 3368: }
3369: }
3370: }
3371: }
3372: }
3373: if (keys(%fromparam)) {
3374: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
3375: &Apache::loncommon::start_data_table().
3376: &Apache::loncommon::start_data_table_header_row().
3377: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
3378: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
3379: &Apache::loncommon::end_data_table_header_row();
3380: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 3381: my ($major,$minor) = split(/\./,$rev);
3382: ($reqdmajor,$reqdminor) =
3383: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 3384: $output .= &Apache::loncommon::start_data_table_row().
3385: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
3386: my $newrow;
3387: foreach my $scope (@scopeorder) {
3388: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
3389: if ($newrow) {
3390: $output .= &Apache::loncommon::continue_data_table_row();
3391: }
1.39 raeburn 3392: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 3393: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
3394: $output .= '<td>'.$which.'</td><td>'.
3395: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
3396: }
3397: $output .= &Apache::loncommon::end_data_table_row();
3398: $newrow = 1;
3399: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
3400: if ($newrow) {
3401: $output .= &Apache::loncommon::continue_data_table_row();
3402: }
1.39 raeburn 3403: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 3404: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
3405: &Apache::loncommon::end_data_table_row();
3406: $newrow = 1;
3407: }
3408: }
3409: }
3410: $output .= &Apache::loncommon::end_data_table().'<br />';
3411: }
3412: }
3413:
1.66 raeburn 3414: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3415: my $now = time;
3416: if (keys(%comm_blocks) > 0) {
3417: foreach my $block (keys(%comm_blocks)) {
3418: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 3419: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 3420: if (ref($comm_blocks{$block}) eq 'HASH') {
3421: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
3422: ' '.&mt('set by [_1]',
3423: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
3424: }
3425: next;
3426: } elsif ($block =~ /^(\d+)____(\d+)$/) {
3427: my ($start,$end) = ($1,$2);
3428: next if ($end < $now);
3429: }
3430: if (ref($comm_blocks{$block}) eq 'HASH') {
3431: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
3432: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
3433: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 3434: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 3435: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
3436: ' '.
3437: &mt('set by [_1]',
3438: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
3439: }
3440: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 3441: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 3442: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
3443: ' '.
3444: &mt('set by [_1]',
3445: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
3446:
3447: }
3448: }
3449: }
3450: }
3451: if (keys(%fromblocks)) {
3452: my %lt = (
3453: docs => 'Content blocking',
3454: printout => 'Printout generation',
3455: timer => 'Timed quiz trigger',
3456: );
3457: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
3458: &Apache::loncommon::start_data_table().
3459: &Apache::loncommon::start_data_table_header_row().
3460: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
3461: '<th>'.&mt('Event(s)').'</th>'.
3462: &Apache::loncommon::end_data_table_header_row();
3463: foreach my $type ('docs','printout','timer') {
3464: if (ref($fromblocks{$type}) eq 'HASH') {
3465: foreach my $rev (keys(%{$fromblocks{$type}})) {
3466: my ($major,$minor) = split(/\./,$rev);
3467: ($reqdmajor,$reqdminor) =
3468: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
3469: $output .= &Apache::loncommon::start_data_table_row().
3470: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
3471: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
3472: $output .= $event.'<br />';
3473: }
3474: $output =~ s{\Q<br />\E$}{};
3475: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
3476: }
3477: }
3478: }
3479: $output .= &Apache::loncommon::end_data_table().'<br />';
3480: }
3481: }
3482:
1.36 raeburn 3483: if (defined($navmap)) {
3484: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 3485: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 3486: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 3487: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 3488: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 3489: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
3490: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
3491: my $valanon=&get_param_description($stdtype,'anonsurvey');
3492: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 3493: my %checkedrev;
1.85 raeburn 3494: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 3495: my @parts = @{$res->parts()};
3496: my $symb = $res->symb();
3497: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 3498: if ($res->is_tool()) {
3499: my $rev = $rev_exttool;
3500: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
3501: $allmaps{$enclosing_map} = 1;
3502: next;
3503: }
1.36 raeburn 3504: foreach my $part (@parts) {
3505: if (exists($anonsubms{$symb."\0".$part})) {
3506: my $rev = $rev_anonsurv;
3507: my $what="$stdname=$valanon";
3508: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
3509: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
3510: push(@{$bysubmission{$symb}{$rev}},$what);
3511: }
3512: } else {
3513: push(@{$bysubmission{$symb}{$rev}},$what);
3514: }
3515: $allmaps{$enclosing_map} = 1;
1.66 raeburn 3516: unless ($checkedrev{'anonsurvey'}) {
3517: my ($major,$minor) = split(/\./,$rev);
3518: ($reqdmajor,$reqdminor) =
3519: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
3520: $reqdmajor,$reqdminor);
3521: $checkedrev{'anonsurvey'} = 1;
3522: }
1.36 raeburn 3523: }
3524: if (exists($randtrysubms{$symb."\0".$part})) {
3525: my $rev = $rev_randtry;
3526: my $what="$stdname=$valrandtry";
3527: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
3528: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
3529: push(@{$bysubmission{$symb}{$rev}},$what);
3530: }
3531: } else {
3532: push(@{$bysubmission{$symb}{$rev}},$what);
3533: }
3534: $allmaps{$enclosing_map} = 1;
1.66 raeburn 3535: unless ($checkedrev{'randomizetry'}) {
3536: my ($major,$minor) = split(/\./,$rev);
3537: ($reqdmajor,$reqdminor) =
3538: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
3539: $reqdmajor,$reqdminor);
3540: $checkedrev{'randomizetry'} = 1;
3541: }
1.36 raeburn 3542: }
3543: }
3544: my %responses = $res->responseTypes();
3545: foreach my $key (keys(%responses)) {
1.66 raeburn 3546: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
3547: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
3548: unless ($checkedrev{$key}) {
3549: my ($major,$minor) = split(/\./,$rev);
3550: ($reqdmajor,$reqdminor) =
3551: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
3552: $reqdmajor,$reqdminor);
3553: $checkedrev{$key} = 1;
3554: }
3555: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 3556: $allmaps{$enclosing_map} = 1;
3557: }
3558: }
3559: }
3560: if (keys(%byresource) > 0) {
3561: foreach my $symb (keys(%byresource)) {
3562: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
3563: $allmaps{$map} = 1;
3564: }
3565: }
3566: if (keys(%bymap) > 0) {
3567: foreach my $map (keys(%bymap)) {
3568: $allmaps{$map} = 1;
3569: }
3570: }
3571: foreach my $map (keys(%allmaps)) {
3572: my $mapres = $navmap->getResourceByUrl($map);
3573: if (ref($mapres)) {
1.68 raeburn 3574: my $mapsymb = $mapres->symb();
3575: $toshow{$mapsymb} = 1;
1.36 raeburn 3576: my $pcslist = $mapres->map_hierarchy();
3577: if ($pcslist ne '') {
3578: foreach my $pc (split(/,/,$pcslist)) {
3579: my $res = $navmap->getByMapPc($pc);
3580: if (ref($res)) {
3581: my $symb = $res->symb();
3582: unless ($symb eq '______') {
3583: $toshow{$symb} = 1;
3584: }
3585: }
3586: }
3587: }
3588: }
3589: }
3590: }
1.86 raeburn 3591: my $suppmap = 'supplemental.sequence';
3592: my ($suppcount,$supptools,$errors) = (0,0,0);
3593: ($suppcount,$supptools,$errors) = &Apache::loncommon::recurse_supplemental($cnum,$cdom,
3594: $suppmap,$suppcount,$supptools,$errors);
1.36 raeburn 3595: my $mapres_header = '<h4>'.
3596: &mt('Requirements for specific folders or resources').
3597: '</h4>';
3598: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
3599: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
3600: $output .= $mapres_header;
3601: }
3602: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
3603: my $title = 'Version Constraints';
3604: my $start_page =
3605: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
3606: $r->print($start_page.$top_header);
3607: if ($output) {
3608: $r->print($output);
1.86 raeburn 3609: if (defined($navmap) || $supptools) {
1.36 raeburn 3610: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 3611: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 3612: }
3613: $r->print('<br /><br />');
3614: } else {
3615: $r->print('<p class="LC_info">'.
3616: &mt('No version requirements from resource content or settings.').
3617: '</p>');
3618: }
3619: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 3620: my ($currmajor,$currminor) = split(/\./,$loncaparev);
3621: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
3622: return 1;
3623: }
1.36 raeburn 3624: return;
3625: }
3626:
3627: sub show_contents_view {
1.39 raeburn 3628: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 3629: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
3630: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
3631: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
3632: my $showmaincontent;
3633: if ((ref($navmap)) &&
3634: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
3635: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
3636: (keys(%{$bycrsrestype}) > 0))) {
3637: $showmaincontent = 1;
3638: }
3639: if ($showmaincontent || $supptools) {
3640: $r->print(&Apache::loncommon::start_data_table());
3641: }
3642: if ($showmaincontent) {
3643: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 3644: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 3645: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 3646: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
3647: '<th>'.&mt('Attribute/Setting').'</th>'.
3648: &Apache::loncommon::end_data_table_header_row().
3649: &Apache::loncommon::start_data_table_row().
1.58 raeburn 3650: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 3651: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
3652: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 3653: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
3654: my $curRes;
3655: my $depth = 0;
3656: my %parent = ();
3657: my $startcount = 5;
3658: my $lastcontainer = $startcount;
3659: while ($curRes = $it->next()) {
3660: if ($curRes == $it->BEGIN_MAP()) {
3661: $depth++;
3662: $parent{$depth}= $lastcontainer;
3663: }
3664: if ($curRes == $it->END_MAP()) {
3665: $depth--;
3666: $lastcontainer = $parent{$depth};
3667: }
3668: my $indent;
3669: for (my $i=0; $i<$depth; $i++) {
3670: $indent.= $whitespace;
3671: }
3672: if (ref($curRes)) {
3673: my $symb = $curRes->symb();
3674: my $ressymb = $symb;
3675: my $srcf = $curRes->src();
3676: my $title = &Apache::lonnet::gettitle($srcf);
3677: if (($curRes->is_sequence()) || ($curRes->is_page())) {
3678: next unless($toshow->{$symb});
3679: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
3680: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
3681: if ($curRes->is_page()) {
3682: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
3683: }
3684: my $rowspan = 1;
3685: if (ref($bymap->{$url}) eq 'HASH') {
3686: $rowspan = scalar(keys(%{$bymap->{$url}}));
3687: }
3688: $r->print(&Apache::loncommon::start_data_table_row().
3689: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 3690: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 3691: $r->print(&Apache::loncommon::end_data_table_row());
3692: } else {
3693: my $rowspan;
3694: if (ref($byresource->{$symb}) eq 'HASH') {
3695: $rowspan += scalar(keys(%{$byresource->{$symb}}));
3696: }
3697: if (ref($bysubmission->{$symb}) eq 'HASH') {
3698: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
3699: }
3700: if (ref($byresponsetype->{$symb}) eq 'HASH') {
3701: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
3702: }
1.85 raeburn 3703: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
3704: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
3705: }
1.36 raeburn 3706: next if (!$rowspan);
3707: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
3708: &mt('Problem').'" />';
3709: $r->print(&Apache::loncommon::start_data_table_row().
3710: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
3711: my $newrow;
3712: if (ref($byresource->{$symb}) eq 'HASH') {
3713: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
3714: if ($newrow) {
3715: $r->print(&Apache::loncommon::continue_data_table_row());
3716: }
3717: $r->print('<td valign="middle">'.$rev.'</td><td>');
3718: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
3719: $r->print('<table border="0">');
3720: foreach my $scope (@{$scopeorder}) {
3721: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 3722: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 3723: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
3724: $r->print('<td>'.$which.'</td><td>'.
3725: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
3726: '</td>');
3727: }
3728: $r->print('</tr>');
3729: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 3730: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 3731: '<td> </td><td>'.
3732: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
3733: }
3734: }
3735: $r->print('</table>');
3736: }
3737: $r->print('</td>');
3738: $r->print(&Apache::loncommon::end_data_table_row());
3739: $newrow = 1;
3740: }
3741: }
3742: if (ref($bysubmission->{$symb}) eq 'HASH') {
3743: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
3744: if ($newrow) {
3745: $r->print(&Apache::loncommon::continue_data_table_row());
3746: }
3747: $r->print('<td>'.$rev.'</td><td>');
3748: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
3749: $r->print(&mt('Submissions to: ').' '.
3750: join(', ',@{$bysubmission->{$symb}{$rev}}));
3751: }
3752: $r->print('</td>');
3753: $r->print(&Apache::loncommon::end_data_table_row());
3754: $newrow = 1;
3755: }
3756: }
3757: if (ref($byresponsetype->{$symb}) eq 'HASH') {
3758: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
3759: if ($newrow) {
3760: $r->print(&Apache::loncommon::continue_data_table_row());
3761: }
3762: $r->print('<td>'.$rev.'</td><td>');
3763: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
3764: $r->print(&mt('Response Type(s): ').' '.
3765: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
3766: }
3767: $r->print('</td>');
3768: }
3769: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 3770: $newrow = 1;
3771: }
3772: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
3773: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
3774: if ($newrow) {
3775: $r->print(&Apache::loncommon::continue_data_table_row());
3776: }
3777: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
3778: }
1.86 raeburn 3779: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 3780: }
3781: }
3782: }
3783: }
1.86 raeburn 3784: }
3785: if ($supptools) {
3786: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
3787: $r->print(&Apache::loncommon::start_data_table_header_row().
3788: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
3789: '<th>'.&mt('Resource Type').'</th>'.
3790: &Apache::loncommon::end_data_table_header_row().
3791: &Apache::loncommon::start_data_table_row().
3792: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
3793: '<td valign="middle">'.
3794: $Apache::lonrelrequtils::exttool{'major'}.'.'.
3795: $Apache::lonrelrequtils::exttool{'minor'}.
3796: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
3797: $supptools).'</td>'.
3798: &Apache::loncommon::end_data_table_row());
3799: }
3800: if ($showmaincontent || $supptools) {
1.36 raeburn 3801: $r->print(&Apache::loncommon::end_data_table());
3802: }
1.66 raeburn 3803: return;
1.36 raeburn 3804: }
3805:
3806: sub releases_by_map {
1.39 raeburn 3807: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 3808: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.73 raeburn 3809: my $newrow = 0;
1.36 raeburn 3810: if (ref($bymap->{$url}) eq 'HASH') {
3811: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 3812: if ($newrow) {
3813: $r->print(&Apache::loncommon::end_data_table_row().
3814: &Apache::loncommon::continue_data_table_row());
3815: }
1.36 raeburn 3816: $r->print('<td valign="middle">'.$rev.'</td><td>');
3817: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
3818: $r->print('<table border="0">');
3819: foreach my $scope (@{$scopeorder}) {
3820: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 3821: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 3822: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
3823: $r->print('<td>'.$which.'</td><td>'.
3824: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
3825: '</td>');
3826: }
3827: $r->print('</tr>');
3828: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 3829: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 3830: '</td><td> </td><td>'.
3831: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
3832: }
3833: }
3834: $r->print('</table>');
3835: }
3836: $r->print('</td>');
1.73 raeburn 3837: $newrow = 1;
1.36 raeburn 3838: }
3839: } else {
3840: $r->print('<td colspan="2"> </td>');
3841: }
3842: return;
3843: }
3844:
3845: sub get_param_description {
1.70 raeburn 3846: my ($stdtype,$value,$regexp) = @_;
3847: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 3848: if ($stdtype =~ /^string/) {
3849: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
3850: } elsif ($stdtype eq 'date_interval') {
3851: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
3852: }
1.70 raeburn 3853: if ($regexp) {
1.74 raeburn 3854: if ($stdtype =~ /^string/) {
3855: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
3856: } elsif ($stdtype eq 'date_interval') {
3857: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
3858: }
1.70 raeburn 3859: if (ref($parammatches) eq 'ARRAY') {
3860: @possibles = @{$parammatches};
3861: } else {
3862: undef($regexp);
3863: $name = $value;
3864: }
3865: }
3866: unless ($regexp) {
3867: $name = $value;
3868: if (ref($paramstrings) eq 'ARRAY') {
3869: @possibles = @{$paramstrings};
3870: } else {
1.76 raeburn 3871: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
3872: if ($name == 0) {
3873: $name = &mt('Never');
3874: } elsif (($name ne '') && ($name !~ /\D/)) {
3875: $name = &Apache::lonlocal::locallocaltime($name);
3876: }
3877: }
1.70 raeburn 3878: return $name;
3879: }
1.36 raeburn 3880: }
1.70 raeburn 3881: foreach my $possibilities (@possibles) {
1.36 raeburn 3882: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 3883: my $gotregexmatch = '';
3884: if ($regexp) {
3885: last if ($gotregexmatch);
3886: my ($item,$pattern) = @{ $possibilities };
3887: if ($value =~ /$pattern/) {
3888: if (ref($paramstrings) eq 'ARRAY') {
3889: foreach my $possibles (@{$paramstrings}) {
3890: next unless (ref($possibles) eq 'ARRAY');
3891: my ($thing,$description) = @{$possibles};
3892: if ($thing eq $item) {
3893: $name = $description;
3894: $gotregexmatch = 1;
3895: last;
3896: }
3897: }
3898: last if ($gotregexmatch);
3899: }
3900: }
3901: } else {
3902: my ($thing,$description) = @{ $possibilities };
3903: if ($thing eq $value) {
3904: $name = $description;
3905: last;
3906: }
1.36 raeburn 3907: }
3908: }
3909: return $name;
3910: }
3911:
1.66 raeburn 3912: sub update_releasereq {
3913: my $readmap = 1;
3914: my $getrelreq = 1;
3915: if (ref($modified_courses) eq 'ARRAY') {
3916: foreach my $item (@{$modified_courses}) {
3917: if (ref($item) eq 'ARRAY') {
3918: my ($cdom,$cnum,$chome,$crstype) = @{$item};
3919: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
3920: $chome,$crstype,$cdom.'_'.$cnum,
3921: $readmap,$getrelreq);
3922: }
3923: }
3924: $modified_courses = [];
3925: }
3926: undef($registered_cleanup);
3927: return;
3928: }
3929:
1.25 raeburn 3930: sub show_autocoowners {
3931: my (@currcoown) = @_;
1.56 raeburn 3932: my $output = '<i><span class="LC_nobreak">'.&mt('Co-ownership is set automatically when a Course Coordinator role[_1] is assigned to official course personnel (from institutional data).','</span><br /><span class="LC_nobreak">').'</span></i>';
1.25 raeburn 3933: if (@currcoown > 0) {
3934: $output .= '<br />'.&mt('Current co-owners are:').' '.
3935: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
3936: } else {
3937: $output .= '<br />'.&mt('Currently no co-owners.');
3938: }
3939: return $output;
3940: }
3941:
3942: sub coowner_invitations {
1.80 raeburn 3943: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
3944: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 3945: my $pendingcoowners =
3946: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
3947: if ($pendingcoowners) {
3948: @pendingcoown = split(',',$pendingcoowners);
3949: }
1.80 raeburn 3950: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 3951: @currcoown = @{$currcoownref};
1.80 raeburn 3952: }
3953: my $disabled;
3954: if ($noedit) {
3955: $disabled = ' disabled="disabled"';
3956: }
1.25 raeburn 3957: my $ccrole = 'cc';
3958: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
3959: foreach my $key (sort(keys(%ccroles))) {
3960: my ($ccname,$ccdom,$role) = split(':',$key);
3961: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
3962: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
3963: push(@othercoords,$ccname.':'.$ccdom);
3964: }
3965: }
3966: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
3967: if ($coowner_rows) {
3968: $output .= &Apache::loncommon::start_data_table();
3969: if (@currcoown) {
3970: $output .= &Apache::loncommon::start_data_table_row().
3971: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
3972: foreach my $person (@currcoown) {
3973: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 3974: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="coowners" checked="checked" value="'.$person.'"'.$disabled.' />'.&Apache::loncommon::plainname($co_uname,$co_dom).'</label></span>'.(' 'x2).' ';
1.25 raeburn 3975: }
3976: $output .= '</td>'.
3977: &Apache::loncommon::end_data_table_row();
3978: }
3979: if ($pendingcoowners) {
3980: $output .= &Apache::loncommon::start_data_table_row().
3981: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
3982: foreach my $person (@pendingcoown) {
3983: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 3984: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="pendingcoowners" checked="checked" value="'.$person.'"'.$disabled.' />'.&Apache::loncommon::plainname($co_uname,$co_dom).'</label></span>'.(' 'x2).' ';
1.25 raeburn 3985: }
3986: $output .= '</td>'.
3987: &Apache::loncommon::end_data_table_row();
3988: }
3989: if (@othercoords) {
3990: $output .= &Apache::loncommon::start_data_table_row().
3991: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
3992: foreach my $person (@othercoords) {
3993: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 3994: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="invitecoowners" value="'.$person.'"'.$disabled.' />'.&Apache::loncommon::plainname($co_uname,$co_dom).'</label></span>'.(' 'x2).' ';
1.25 raeburn 3995: }
3996: $output .= '</td>'.
3997: &Apache::loncommon::end_data_table_row();
3998: }
3999: $output .= &Apache::loncommon::end_data_table();
4000: } else {
4001: $output = &mt('There are no coordinators to select as co-owners');
4002: }
4003: return $output;
4004: }
4005:
4006: sub manage_coownership {
1.80 raeburn 4007: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
4008: my (@pendingcoown,@currcoown);
1.25 raeburn 4009: my $pendingcoowners =
4010: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
4011: if ($pendingcoowners) {
4012: @pendingcoown = split(',',$pendingcoowners);
4013: }
1.80 raeburn 4014: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 4015: @currcoown = @{$currcoownref};
1.80 raeburn 4016: }
4017: my $disabled;
4018: if ($noedit) {
4019: $disabled = ' disabled="disabled"';
4020: }
1.25 raeburn 4021: my ($is_coowner,$is_pending,$output);
4022: my $uname = $env{'user.name'};
4023: my $udom = $env{'user.domain'};
4024: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
4025: $is_coowner = 1;
4026: }
4027: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
4028: $is_pending = 1;
4029: }
4030: if (@currcoown && ($is_coowner || $is_pending)) {
4031: $output = &Apache::loncommon::start_data_table();
4032: }
4033: if (@currcoown) {
4034: if ($is_coowner || $is_pending) {
4035: $output .= &Apache::loncommon::start_data_table().
4036: &Apache::loncommon::start_data_table_row().'<td>';
4037: }
4038: $output .= &mt('Current co-owners are:').' '.
4039: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
4040: if ($is_coowner || $is_pending) {
4041: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4042: }
4043: }
4044: if ($is_coowner || $is_pending) {
4045: if (@currcoown) {
4046: $output .= &Apache::loncommon::start_data_table_row().'<td>';
4047: }
4048: $output .= '<span class="LC_nobreak">';
4049: if ($is_coowner) {
1.90 raeburn 4050: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 4051: } else {
1.90 raeburn 4052: $output .= &mt('The course owner has invited you to become a co-owner:').' <label><input type="radio" name="pending_coowner" value="accept"'.$disabled.' />'.&mt('Accept?').'</label>'.(' 'x2).
4053: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 4054: }
4055: $output .= '</span>';
4056: if (@currcoown) {
4057: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4058: }
4059: }
4060: if (@currcoown && ($is_coowner || $is_pending)) {
4061: $output .= &Apache::loncommon::end_data_table();
4062: }
4063: return $output;
4064: }
4065:
1.1 raeburn 4066: sub print_localization {
1.80 raeburn 4067: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 4068: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4069: return;
4070: }
4071: my %items = (
4072: languages => {
1.17 faziophi 4073: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
4074: &mt("(overrides individual user preference)"),
1.1 raeburn 4075: input => 'selectbox',
4076: },
4077: timezone => {
1.17 faziophi 4078: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 4079: input => 'selectbox',
4080: },
4081: datelocale => {
1.17 faziophi 4082: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 4083: input => 'selectbox',
4084: },
4085: );
1.80 raeburn 4086: my ($datatable,$disabled);
1.1 raeburn 4087: my $count = 0;
1.80 raeburn 4088: if ($noedit) {
4089: $disabled = ' disabled="disabled"';
4090: }
1.1 raeburn 4091: foreach my $item (@{$ordered}) {
4092: $count ++;
1.56 raeburn 4093: my $colspan;
4094: unless ($item eq 'languages') {
1.80 raeburn 4095: $colspan = 2;
1.56 raeburn 4096: }
4097: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 4098: if ($item eq 'timezone') {
4099: my $includeempty = 1;
4100: my $timezone = &Apache::lonlocal::gettimezone();
4101: $datatable .=
4102: &Apache::loncommon::select_timezone($item,$timezone,undef,
1.80 raeburn 4103: $includeempty,$disabled);
1.1 raeburn 4104: } elsif ($item eq 'datelocale') {
4105: my $includeempty = 1;
4106: my $locale_obj = &Apache::lonlocal::getdatelocale();
4107: my $currdatelocale;
4108: if (ref($locale_obj)) {
4109: $currdatelocale = $locale_obj->id();
4110: }
4111: $datatable .=
4112: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 4113: undef,$includeempty,$disabled);
1.1 raeburn 4114: } else {
4115: if ($settings->{$item} eq '') {
1.80 raeburn 4116: unless ($noedit) {
4117: $datatable .= '</td><td align="right">'.
4118: &Apache::loncommon::select_language('languages_0','',1);
4119: }
1.1 raeburn 4120: } else {
4121: my $num = 0;
1.3 raeburn 4122: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 4123: $datatable .= '</td><td align="right"><br />'.
4124: &Apache::loncommon::start_data_table();
1.1 raeburn 4125: if (@languages > 0) {
1.3 raeburn 4126: my %langchoices = &get_lang_choices();
1.1 raeburn 4127: foreach my $lang (@languages) {
4128: my $showlang = $lang;
1.3 raeburn 4129: if (exists($langchoices{$lang})) {
4130: $showlang = $langchoices{$lang};
1.1 raeburn 4131: }
4132: $datatable .=
4133: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4134: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 4135: &mt('Language:').'<b> '.$showlang.
4136: '</b><input type="hidden" name="languages_'.$num.
4137: '" value="'.$lang.'" /></span><br />'.
4138: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4139: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 4140: &mt('Delete').'</label></span></td>'.
1.3 raeburn 4141: &Apache::loncommon::end_data_table_row();
1.1 raeburn 4142: $num ++;
4143: }
4144: }
1.80 raeburn 4145: unless ($noedit) {
4146: $datatable .=
4147: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4148: '<td align="left"><span class="LC_nobreak">'.
4149: &mt('Additional language:'). '</span><br />'.
4150: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 4151: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 4152: '</td>'.&Apache::loncommon::end_data_table_row();
4153: }
4154: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 4155: }
4156: }
4157: $datatable .= &item_table_row_end();
4158: }
4159: $$rowtotal += scalar(@{$ordered});
4160: return $datatable;
4161: }
4162:
1.3 raeburn 4163: sub get_lang_choices {
4164: my %langchoices;
4165: foreach my $id (&Apache::loncommon::languageids()) {
4166: my $code = &Apache::loncommon::supportedlanguagecode($id);
4167: if ($code) {
4168: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4169: }
4170: }
4171: return %langchoices;
4172: }
4173:
1.1 raeburn 4174: sub print_feedback {
1.80 raeburn 4175: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 4176: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4177: return;
4178: }
4179: my %items = (
1.3 raeburn 4180: 'question.email' => {
4181: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 4182: input => 'textbox',
4183: size => '50',
4184: },
4185:
1.3 raeburn 4186: 'comment.email' => {
4187: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 4188: input => 'textbox',
4189: size => '50',
4190: },
4191:
1.3 raeburn 4192: 'policy.email' => {
4193: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 4194: input => 'textbox',
4195: size => '50',
4196: },
4197: );
4198: my $datatable;
4199: my $count = 0;
4200: my ($cnum) = &get_course();
4201: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
4202: my @sections = sort( { $a <=> $b } keys(%sections));
4203: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 4204: currone => 'Current recipient:',
4205: currmult => 'Current recipients:',
4206: add => 'Additional recipient:',
4207: del => 'Delete?',
4208: sec => 'Sections:',
1.1 raeburn 4209: );
1.80 raeburn 4210: my $disabled;
4211: if ($noedit) {
4212: $disabled = ' disabled="disabled"';
4213: }
1.1 raeburn 4214: foreach my $item (@{$ordered}) {
4215: $count ++;
1.20 faziophi 4216: if ($position eq 'top') {
4217: $datatable .= &item_table_row_start($items{$item}{text},$count);
4218: } else {
1.56 raeburn 4219: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 4220: }
1.1 raeburn 4221: if ($position eq 'top') {
4222: my $includeempty = 0;
1.94 raeburn 4223: $datatable .= '</td><td align="right">'.
4224: &user_table($cdom,$item,\@sections,
1.80 raeburn 4225: $settings->{$item},\%lt,$noedit);
1.1 raeburn 4226: } else {
1.3 raeburn 4227: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 4228: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 4229: }
4230: $datatable .= &item_table_row_end();
4231: }
4232: $$rowtotal += scalar(@{$ordered});
4233: return $datatable;
4234: }
4235:
4236: sub user_table {
1.80 raeburn 4237: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 4238: my $output;
4239: if ($currvalue eq '') {
1.80 raeburn 4240: unless ($noedit) {
4241: $output .= &select_recipient($item,'0',$cdom,$sections);
4242: }
1.1 raeburn 4243: } else {
4244: my $num = 0;
4245: my @curr = split(/,/,$currvalue);
1.56 raeburn 4246: $output .= '<table class="LC_data_table">';
1.1 raeburn 4247: my ($currusers);
1.80 raeburn 4248: my $disabled;
4249: if ($noedit) {
4250: $disabled = ' disabled="disabled"';
4251: }
1.1 raeburn 4252: foreach my $val (@curr) {
4253: next if ($val eq '');
4254: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
4255: my @selsec;
4256: if ($seclist) {
4257: $seclist =~ s/(^\(|\)$)//g;
4258: @selsec = split(/\s*;\s*/,$seclist);
4259: }
4260: $currusers .= '<tr>'.
4261: '<td valign="top"><span class="LC_nobreak">'.
4262: '<label><input type="checkbox" '.
1.80 raeburn 4263: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 4264: $lt->{'del'}.'</label>'.
4265: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 4266: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 4267: &Apache::loncommon::aboutmewrapper(
4268: &Apache::loncommon::plainname($uname,$udom,'firstname'),
4269: $uname,$udom,'aboutuser');
4270: if (ref($sections) eq 'ARRAY') {
4271: if (@{$sections}) {
4272: $currusers.= (' 'x3).$lt->{'sec'}.' '.
4273: &select_sections($item,$num,$sections,
1.80 raeburn 4274: \@selsec,$noedit);
1.1 raeburn 4275: }
4276: }
4277: $currusers .= '</span></td></tr>';
4278: $num ++;
4279: }
4280: if ($num) {
1.10 raeburn 4281: $output .= '<tr>'.
1.1 raeburn 4282: '<td align="left"><i>';
1.20 faziophi 4283: if ($num == 1) {
1.1 raeburn 4284: $output .= $lt->{'currone'};
4285: } else {
1.21 raeburn 4286: $output .= $lt->{'currmult'};
1.1 raeburn 4287: }
4288: $output .= '</i><br />'.
4289: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 4290: '</tr>';
1.1 raeburn 4291: }
1.80 raeburn 4292: unless ($noedit) {
4293: $output .=
4294: '<tr>'.
1.1 raeburn 4295: '<td align="left"><span class="LC_nobreak"><i>'.
4296: $lt->{'add'}.'</i></span><br />'.
4297: &select_recipient($item,$num,$cdom,$sections).
4298: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 4299: '</td></tr>';
4300: }
4301: $output .= '</table>';
1.1 raeburn 4302: }
4303: return $output;
4304: }
4305:
4306: sub select_recipient {
4307: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
4308: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
4309: my $selectlink =
4310: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 4311: $item.'_udom_'.$num,'only');
1.1 raeburn 4312: my $output =
1.10 raeburn 4313: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 4314: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
4315: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
4316: if (ref($sections) eq 'ARRAY') {
4317: if (@{$sections}) {
4318: $output .= '<td align="center">'.&mt('Sections').'<br />'.
4319: &select_sections($item,$num,$sections,$selected).'</td>';
4320: }
4321: }
4322: $output .= '<td valign="top">'.
4323: $selectlink.'</td></tr></table>';
4324: return $output;
4325: }
4326:
4327: sub select_sections {
1.80 raeburn 4328: my ($item,$num,$sections,$selected,$noedit) = @_;
4329: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 4330: if (ref($selected) eq 'ARRAY') {
4331: @currsecs = @{$selected};
4332: }
4333: if (!@currsecs) {
4334: $allsec = ' selected="selected"';
4335: }
1.80 raeburn 4336: if ($noedit) {
4337: $disabled = ' disabled="disabled"';
4338: }
1.1 raeburn 4339: if (ref($sections) eq 'ARRAY') {
4340: if (@{$sections}) {
4341: my $mult;
4342: if (@{$sections} > 1) {
4343: $mult = ' multiple="multiple"';
4344: if (@{$sections} > 3) {
4345: $mult .= ' size="4"';
4346: }
4347: }
1.80 raeburn 4348: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
1.1 raeburn 4349: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
4350: foreach my $sec (@{$sections}) {
4351: my $is_sel;
4352: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
4353: $is_sel = 'selected="selected"';
4354: }
4355: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
4356: }
4357: $output .= '</select>';
4358: }
4359: }
4360: return $output;
4361: }
4362:
4363: sub print_discussion {
1.80 raeburn 4364: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 4365: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4366: return;
4367: }
4368: my %items = (
4369: 'plc.roles.denied' => {
1.10 raeburn 4370: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
4371: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 4372: &mt('(role-based)'),
1.1 raeburn 4373: input => 'checkbox',
4374: },
4375:
4376: 'plc.users.denied' => {
1.3 raeburn 4377: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
4378: &mt('(specific user(s))'),
1.1 raeburn 4379: input => 'checkbox',
4380: },
4381:
4382: 'pch.roles.denied' => {
1.10 raeburn 4383: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
4384: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 4385: &mt('(role-based)'),
1.1 raeburn 4386: input => 'checkbox',
4387: },
4388:
4389: 'pch.users.denied' => {
1.3 raeburn 4390: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
4391: &mt('(specific user(s))'),
1.1 raeburn 4392: input => 'checkbox',
4393: },
1.77 raeburn 4394:
4395: 'pac.roles.denied' => {
4396: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
4397: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
4398: &mt('(role-based)'),
4399: input => 'checkbox',
4400: },
4401:
4402: 'pac.users.denied' => {
4403: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
4404: &mt('(specific user(s))'),
4405: input => 'checkbox',
4406: },
4407:
1.1 raeburn 4408: 'allow_limited_html_in_feedback' => {
1.3 raeburn 4409: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 4410: input => 'radio',
4411: },
4412:
4413: 'allow_discussion_post_editing' => {
1.3 raeburn 4414: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 4415: input => 'checkbox',
4416: },
1.50 raeburn 4417: 'discussion_post_fonts' => {
4418: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
4419: input => 'textbox',
4420: size => '20',
4421: },
1.1 raeburn 4422: );
4423: my $datatable;
4424: my $count;
4425: my ($cnum) = &get_course();
4426: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
4427: my @sections = sort( { $a <=> $b } keys(%sections));
4428: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 4429: currone => 'Disallowed:',
4430: currmult => 'Disallowed:',
4431: add => 'Disallow more:',
4432: del => 'Delete?',
4433: sec => 'Sections:',
1.1 raeburn 4434: );
4435: foreach my $item (@{$ordered}) {
4436: $count ++;
1.56 raeburn 4437: my $colspan;
4438: if ($item eq 'allow_limited_html_in_feedback') {
4439: $colspan = 2;
4440: }
4441: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 4442: if ($item eq 'plc.roles.denied') {
1.56 raeburn 4443: $datatable .= '</td><td align="right">'.
1.80 raeburn 4444: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 4445: '</table>';
4446: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 4447: $datatable .= '</td><td align="right">'.
4448: &user_table($cdom,$item,undef,
1.80 raeburn 4449: $settings->{$item},\%lt,$noedit);
1.1 raeburn 4450: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 4451: $datatable .= '</td><td align="right">'.
1.80 raeburn 4452: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 4453: '</table>';
4454: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 4455: $datatable .= '</td><td align="right">'.
4456: &user_table($cdom,$item,undef,
1.80 raeburn 4457: $settings->{$item},\%lt,$noedit);
1.77 raeburn 4458: } elsif ($item eq 'pac.roles.denied') {
4459: $datatable .= '</td><td align="right">'.
1.80 raeburn 4460: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 4461: '</table>';
4462: } elsif ($item eq 'pac.users.denied') {
4463: $datatable .= '</td><td align="right">'.
4464: &user_table($cdom,$item,undef,
1.80 raeburn 4465: $settings->{$item},\%lt,$noedit);
1.1 raeburn 4466: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 4467: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4468: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 4469: $datatable .= '</td><td align="right"><br />'.
4470: &Apache::loncommon::start_data_table().
1.1 raeburn 4471: &Apache::loncommon::start_data_table_row().
4472: '<th align="left">'.&mt('Role').'</th><th>'.
4473: &mt('Sections').'</th>'.
4474: &Apache::loncommon::end_data_table_row().
1.80 raeburn 4475: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 4476: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 4477: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 4478: $datatable .= '</td><td align="right"><br />'.
4479: &Apache::loncommon::start_data_table().
1.50 raeburn 4480: &Apache::loncommon::start_data_table_row().
4481: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
4482: '<th align="center">'.&mt('font-size').'</th>'.
4483: '<th align="center">'.&mt('font-weight').'</th>'.
4484: '<th align="center">'.&mt('font-style').'</th>'.
4485: '<th align="center">'.&mt('Other css').'</th>'.
4486: &Apache::loncommon::end_data_table_row().
1.80 raeburn 4487: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 4488: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 4489: }
4490: $datatable .= &item_table_row_end();
4491: }
4492: $$rowtotal += scalar(@{$ordered});
4493: return $datatable;
4494: }
4495:
4496: sub role_checkboxes {
1.80 raeburn 4497: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 4498: my @roles = ('st','ad','ta','ep','in');
4499: if ($crstype eq 'Community') {
4500: push(@roles,'co');
4501: } else {
4502: push(@roles,'cc');
4503: }
1.1 raeburn 4504: my $output;
4505: my (@current,@curr_roles,%currsec,@sections);
4506: if ($showsections) {
4507: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
4508: @sections = sort( { $a <=> $b } keys(%sections));
4509: }
4510: if (ref($settings) eq 'HASH') {
4511: if ($settings->{$item}) {
4512: @current = split(',',$settings->{$item});
4513: if ($showsections) {
4514: foreach my $role (@current) {
4515: if ($role =~ /:/) {
4516: my ($trole,$sec) = split(':',$role);
4517: push(@curr_roles,$trole);
4518: if (ref($currsec{$trole}) eq 'ARRAY') {
4519: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
4520: push(@{$currsec{$trole}},$sec);
4521: }
1.3 raeburn 4522: } else {
4523: $currsec{$trole} = [$sec];
1.1 raeburn 4524: }
4525: } else {
4526: push(@curr_roles,$role);
4527: }
4528: }
4529: @current = @curr_roles;
4530: }
4531: }
4532: }
4533: my $numinrow = 3;
4534: my $count = 0;
1.80 raeburn 4535: my $disabled;
4536: if ($noedit) {
4537: $disabled = ' disabled="disabled"';
4538: }
1.1 raeburn 4539: foreach my $role (@roles) {
4540: my $checked = '';
4541: if (grep(/^\Q$role\E$/,@current)) {
4542: $checked = ' checked="checked" ';
4543: }
1.9 raeburn 4544: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 4545: if ($showsections) {
4546: $output .= &Apache::loncommon::start_data_table_row();
4547: } else {
4548: my $rem = $count%($numinrow);
4549: if ($rem == 0) {
4550: if ($count > 0) {
4551: $output .= '</tr>';
4552: }
4553: $output .= '<tr>';
4554: }
4555: }
1.30 raeburn 4556: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 4557: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 4558: $plrole.'</label></span></td>';
4559: if ($showsections) {
4560: $output .= '<td align="left">'.
1.80 raeburn 4561: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 4562: '</td></tr>';
4563: }
4564: $count ++;
4565: }
4566: my %adv_roles =
4567: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
4568: my $total = @roles;
4569: foreach my $role (sort(keys(%adv_roles))) {
4570: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
4571: my $rolename = $3;
4572: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
4573: my $checked = '';
4574: if (grep(/^\Q$value\E$/,@current)) {
4575: $checked = ' checked="checked" ';
4576: }
4577: if ($showsections) {
4578: $output .= &Apache::loncommon::start_data_table_row();
4579: } else {
4580: my $rem = $count%($numinrow);
4581: if ($rem == 0) {
4582: if ($count > 0) {
4583: $output .= '</tr>';
4584: }
4585: $output .= '<tr>';
4586: }
4587: }
1.30 raeburn 4588: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 4589: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 4590: '</label></span></td>';
4591: if ($showsections) {
4592: $output .= '<td>'.
1.80 raeburn 4593: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 4594: '</td>'.&Apache::loncommon::end_data_table_row();
4595: }
4596: $total ++;
4597: $count ++;
4598: }
4599: }
4600: if (!$showsections) {
4601: my $rem = $total%($numinrow);
4602: my $colsleft = $numinrow - $rem;
4603: if ($colsleft > 1 ) {
4604: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4605: ' </td>';
4606: } elsif ($colsleft == 1) {
4607: $output .= '<td class="LC_left_item"> </td>';
4608: }
4609: $output .= '</tr>';
4610: }
4611: return $output;
4612: }
4613:
1.50 raeburn 4614: sub set_discussion_fonts {
1.80 raeburn 4615: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 4616: my ($classorder,$classtitles) = &discussion_vote_classes();
4617: my ($styleorder,$styleitems) = &discussion_vote_styles();
4618: my $output;
4619: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 4620: my $disabled;
4621: if ($noedit) {
4622: $disabled = ' disabled="disabled"';
4623: }
1.50 raeburn 4624: foreach my $cat (@{$classorder}) {
4625: my %curr = ();
4626: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
4627: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
4628: $output .= &Apache::loncommon::start_data_table_row().
4629: '<td>'.$classtitles->{$cat}.'</td>';
4630: if (ref($styleorder) eq 'ARRAY') {
4631: foreach my $item (@{$styleorder}) {
4632: $output .= '<td><span class="LC_nobreak">';
4633: my $selitem = $item;
4634: if ($item eq 'size') {
4635: my ($currsize,$currunit);
4636: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
4637: ($currsize,$currunit) = ($1,$2);
4638: $curr{'size'} = $currunit;
4639: }
1.81 raeburn 4640: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 4641: ' ';
4642: $selitem = 'unit';
4643: }
4644: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 4645: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 4646: foreach my $val (@{$styleitems->{$item}}) {
4647: my $sel;
4648: if ($val eq $curr{$item}) {
4649: $sel = ' selected="selected"';
4650: }
4651: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
4652: }
4653: }
4654: }
4655: }
1.80 raeburn 4656: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 4657: }
4658: $output .= &Apache::loncommon::end_data_table_row();
4659: }
4660: return $output;
4661: }
4662:
4663: sub discussion_vote_classes {
4664: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
4665: my %classtitles = &Apache::lonlocal::texthash(
4666: 'twoplus' => 'Two sigma above mean',
4667: 'oneplus' => 'One sigma above mean',
4668: 'zero' => 'Within one sigma of mean',
4669: 'oneminus' => 'One sigma below mean',
4670: 'twominus' => 'Two sigma below mean',
4671: );
4672: return ($classorder,\%classtitles);
4673: }
4674:
4675: sub discussion_vote_styles {
4676: my $styleorder = ['size','weight','style'];
4677: my $styleitems = {
4678: size => ['','px','%','xx-small','x-small','small','medium','large',
4679: 'x-large','xx-large','smaller','larger'],
4680: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
4681: '500','600','700','800','900'],
4682: style => ['','normal','italic','oblique'],
4683: };
4684: return ($styleorder,$styleitems);
4685: }
4686:
1.1 raeburn 4687: sub print_classlists {
1.80 raeburn 4688: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 4689: my @ordered;
4690: if ($position eq 'top') {
4691: @ordered = ('default_enrollment_start_date',
4692: 'default_enrollment_end_date');
1.55 raeburn 4693: if ($crstype eq 'Course') {
4694: push(@ordered,'defaultcredits');
4695: }
1.1 raeburn 4696: } elsif ($position eq 'middle') {
1.56 raeburn 4697: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 4698: } else {
4699: @ordered = ('student_classlist_view',
1.26 raeburn 4700: 'student_classlist_opt_in',
4701: 'student_classlist_portfiles');
1.1 raeburn 4702: }
1.9 raeburn 4703: my %lt;
4704:
4705: if ($crstype eq 'Community') {
4706: %lt = &Apache::lonlocal::texthash (
4707: disabled => 'No viewable membership list',
4708: section => "Membership of viewer's section",
4709: all => 'List of all members',
4710: );
4711: } else {
4712: %lt = &Apache::lonlocal::texthash (
4713: disabled => 'No viewable classlist',
4714: section => "Classlist of viewer's section",
4715: all => 'Classlist of all students',
4716: );
4717: }
4718:
1.1 raeburn 4719: my %items = (
4720: 'default_enrollment_start_date' => {
1.3 raeburn 4721: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 4722: input => 'dates',
4723: },
4724: 'default_enrollment_end_date' => {
1.3 raeburn 4725: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 4726: input => 'dates',
4727: },
1.55 raeburn 4728: 'defaultcredits' => {
4729: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4730: },
4731:
1.1 raeburn 4732: 'nothideprivileged' => {
1.3 raeburn 4733: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 4734: input => 'checkbox',
4735: },
4736:
1.56 raeburn 4737: 'checkforpriv' => {
4738: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
4739: input => 'selectbox',
4740: },
4741:
1.1 raeburn 4742: 'student_classlist_view' => {
1.3 raeburn 4743: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 4744: input => 'selectbox',
1.9 raeburn 4745: options => \%lt,
1.1 raeburn 4746: order => ['disabled','all','section'],
4747: },
1.26 raeburn 4748: 'student_classlist_opt_in' => {
4749: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 4750: input => 'radio',
4751: },
4752:
4753: 'student_classlist_portfiles' => {
1.3 raeburn 4754: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 4755: input => 'radio',
4756: },
4757: );
4758: unless (($settings->{'student_classlist_view'} eq 'all') ||
4759: ($settings->{'student_classlist_view'} eq 'section')) {
4760: $settings->{'student_classlist_view'} = 'disabled';
4761: }
1.80 raeburn 4762: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 4763: }
4764:
4765: sub print_appearance {
1.80 raeburn 4766: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 4767: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4768: return;
4769: }
1.9 raeburn 4770: my $mathdef;
4771: if ($crstype eq 'Community') {
4772: $mathdef = &mt("None specified - use member's choice");
4773: } else {
4774: $mathdef = &mt("None specified - use student's choice");
4775: }
1.1 raeburn 4776: my %items = (
4777: 'default_xml_style' => {
1.3 raeburn 4778: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 4779: '<a href="javascript:openbrowser'.
4780: "('display','default_xml_style'".
4781: ",'sty')".'">'.&mt('Select Style File').'</a>',
4782: input => 'textbox',
4783: size => 35,
4784: },
4785:
4786: 'pageseparators' => {
1.3 raeburn 4787: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 4788: input => 'radio',
4789: },
4790: 'disable_receipt_display' => {
1.3 raeburn 4791: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 4792: input => 'radio',
4793: },
4794: 'texengine' => {
1.3 raeburn 4795: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 4796: input => 'selectbox',
4797: options => {
1.61 raeburn 4798: MathJax => 'MathJax',
1.1 raeburn 4799: mimetex => &mt('Convert to Images'),
4800: tth => &mt('TeX to HTML'),
4801: },
1.75 raeburn 4802: order => ['MathJax','mimetex','tth'],
1.9 raeburn 4803: nullval => $mathdef,
1.1 raeburn 4804: },
4805: 'tthoptions' => {
1.3 raeburn 4806: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 4807: input => 'textbox',
4808: size => 40,
4809: },
1.69 raeburn 4810: 'uselcmath' => {
4811: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
4812: input => 'radio',
4813: },
4814: 'usejsme' => {
4815: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
4816: input => 'radio',
4817: },
1.95 raeburn 4818: 'inline_chem' => {
4819: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
4820: input => 'radio',
4821: },
1.1 raeburn 4822: );
1.80 raeburn 4823: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 4824: }
4825:
4826: sub print_grading {
1.80 raeburn 4827: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 4828: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4829: return;
4830: }
4831: my %items = (
4832: 'grading' => {
1.3 raeburn 4833: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 4834: &Apache::loncommon::help_open_topic('GradingOptions'),
4835: input => 'selectbox',
4836: options => {
4837: standard => &mt('Standard: shows points'),
1.34 www 4838: categories => &mt('Categories: shows points according to categories'),
1.11 www 4839: external => &mt('External: shows number of completed parts and totals'),
4840: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 4841: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
4842: },
1.34 www 4843: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 4844: },
4845: 'rndseed' => {
1.3 raeburn 4846: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 4847: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 4848: &mt('Modifying this will make problems have different numbers and answers!').
4849: '</span>',
4850: input => 'selectbox',
4851: options => {
4852: '32bit' => '32bit',
4853: '64bit' => '64bit',
4854: '64bit2' => '64bit2',
4855: '64bit3' => '64bit3',
4856: '64bit4' => '64bit4',
4857: '64bit5' => '64bit5',
4858: },
4859: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 4860: advanced => 1
1.1 raeburn 4861: },
4862: 'receiptalg' => {
1.3 raeburn 4863: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 4864: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 4865: input => 'selectbox',
4866: options => {
4867: receipt => 'receipt',
4868: receipt2 => 'receipt2',
4869: receipt3 => 'receipt3',
4870: },
4871: order => ['receipt','receipt2','receipt3'],
1.41 www 4872: advanced => 1
1.1 raeburn 4873: },
4874: 'disablesigfigs' => {
1.3 raeburn 4875: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 4876: input => 'radio',
4877: },
4878: );
1.80 raeburn 4879: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
1.1 raeburn 4880: }
4881:
4882: sub print_printouts {
1.80 raeburn 4883: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 4884: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4885: return;
4886: }
4887: my %items = (
4888: problem_stream_switch => {
1.3 raeburn 4889: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 4890: input => 'radio',
4891: },
4892: suppress_tries => {
1.3 raeburn 4893: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 4894: input => 'radio',
4895: },
4896: default_paper_size => {
1.3 raeburn 4897: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 4898: input => 'selectbox',
4899: options => {
4900: Letter => &mt('Letter').' [8 1/2x11 in]',
4901: Legal => &mt('Legal').' [8 1/2x14 in]',
4902: Tabloid => &mt('Tabloid').' [11x17 in]',
4903: Executive => &mt('Executive').' [7 1/2x10 in]',
4904: A2 => &mt('A2').' [420x594 mm]',
4905: A3 => &mt('A3').' [297x420 mm]',
4906: A4 => &mt('A4').' [210x297 mm]',
4907: A5 => &mt('A5').' [148x210 mm]',
4908: A6 => &mt('A6').' [105x148 mm]',
4909: },
4910: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 4911: nullval => &mt('None specified'),
1.1 raeburn 4912: },
4913: print_header_format => {
1.3 raeburn 4914: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 4915: input => 'checkbox',
4916: },
4917: disableexampointprint => {
1.3 raeburn 4918: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 4919: input => 'radio',
4920: },
1.14 raeburn 4921: canuse_pdfforms => {
4922: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
4923: input => 'selectbox',
4924: options => {
4925: 1 => &mt('Yes'),
4926: 0 => &mt('No'),
4927: },
4928: order => ['1','0'],
1.54 bisitz 4929: nullval => &mt('None specified - use domain default'),
1.14 raeburn 4930: }
1.1 raeburn 4931: );
1.80 raeburn 4932: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 4933: }
4934:
4935: sub print_spreadsheet {
1.80 raeburn 4936: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 4937: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4938: return;
4939: }
4940: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
4941: my %items = (
4942: spreadsheet_default_classcalc => {
1.3 raeburn 4943: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 4944: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
4945: "('display','spreadsheet_default_classcalc'".
4946: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
4947: input => 'textbox',
4948: },
4949: spreadsheet_default_studentcalc => {
1.3 raeburn 4950: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 4951: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
4952: "('display','spreadsheet_default_calc'".
4953: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
4954: input => 'textbox',
4955: },
4956: spreadsheet_default_assesscalc => {
1.3 raeburn 4957: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 4958: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
4959: "('display','spreadsheet_default_assesscalc'".
4960: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
4961: input => 'textbox',
4962: },
4963: hideemptyrows => {
1.3 raeburn 4964: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 4965: input => 'radio',
4966: },
4967: );
1.80 raeburn 4968: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 4969: }
1.1 raeburn 4970:
4971: sub print_bridgetasks {
1.80 raeburn 4972: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 4973: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4974: return;
4975: }
1.9 raeburn 4976: my ($stumsg,$msgnote);
4977: if ($crstype eq 'Community') {
4978: $stumsg = &mt('Send message to member');
4979: $msgnote = &mt('Message to member and add to user notes');
4980: } else {
4981: $stumsg = &mt('Send message to student');
4982: $msgnote = &mt('Message to student and add to user notes');
4983: }
1.1 raeburn 4984: my %items = (
4985: task_messages => {
1.3 raeburn 4986: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 4987: input => 'selectbox',
4988: options => {
1.9 raeburn 4989: only_student => $stumsg,
4990: student_and_user_notes_screen => $msgnote,
1.1 raeburn 4991: },
4992: order => ['only_student','student_and_user_notes_screen'],
4993: nullval => &mt('No message or record in user notes'),
4994: },
4995: task_grading => {
1.3 raeburn 4996: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 4997: input => 'selectbox',
4998: options => {
4999: any => &mt('Grade BTs in any section'),
5000: section => &mt('Grade BTs only in own section')
5001: },
5002: order => ['any','section'],
5003: },
5004: suppress_embed_prompt => {
1.3 raeburn 5005: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
5006: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 5007: input => 'radio',
5008: },
5009: );
1.80 raeburn 5010: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 5011: }
5012:
1.87 raeburn 5013: sub print_lti {
5014: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
5015: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
5016: return;
5017: }
5018: my @menuitems = ('fullname','coursetitle','role','logout','grades');
5019: my %menutitles = <imenu_titles();
5020: my ($domdefs,$displaydefs);
5021: if ($env{'request.lti.login'}) {
5022: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
5023: my @domdefsmenu;
5024: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
5025: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
5026: $domdefs = &mt('Header shown').', ';
5027: }
5028: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
5029: $domdefs .= &mt('Inline menu shown');
5030: }
5031: $domdefs =~ s/,\s$//;
5032: if (!$domdefs) {
5033: $domdefs = &mt('No header or inline menu shown');
5034: }
5035: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
5036: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
5037: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
5038: }
5039: }
5040: $displaydefs = &mt('Domain defaults');
5041: if (@domdefsmenu) {
5042: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
5043: if (@diffs) {
5044: my $missing;
5045: foreach my $item (@menuitems) {
5046: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
5047: $missing .= ' '.$menutitles{$item}.',';
5048: }
5049: }
5050: $missing =~ s/,$//;
5051: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
5052: } else {
5053: $displaydefs .= ': '.&mt('All shown');
5054: }
5055: } else {
5056: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
5057: }
5058: } else {
5059: $displaydefs = &mt('Domain defaults only available in LTI context');
5060: }
5061: my %items = (
5062: 'lti.override' => {
5063: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
5064: input => 'radio',
5065: },
5066: 'lti.topmenu' => {
5067: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
5068: input => 'radio',
5069: },
5070: 'lti.inlinemenu' => {
5071: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
5072: input => 'radio',
5073: },
5074: 'lti.lcmenu' => {
5075: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
5076: input => 'custom',
5077: },
5078: );
5079: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
5080: }
5081:
5082: sub lcmenu_checkboxes {
5083: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
5084: my @menuitems = ('fullname','coursetitle','role','logout','grades');
5085: my %menutitles = <imenu_titles();
5086: my (@current,@domdefs);
5087: if ($env{'request.lti.login'}) {
5088: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
5089: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
5090: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
5091: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
5092: }
5093: }
5094: }
5095: if (ref($settings) eq 'HASH') {
5096: if ($settings->{'lti.lcmenu'}) {
5097: unless ($settings->{'lti.lcmenu'} eq 'none') {
5098: @current = split(',',$settings->{'lti.lcmenu'});
5099: }
5100: } else {
5101: @current = @domdefs;
5102: }
5103: } else {
5104: @current = @domdefs;
5105: }
5106: my $numinrow = 3;
5107: my $count = 0;
5108: my $disabled;
5109: if ($noedit) {
5110: $disabled = ' disabled="disabled"';
5111: }
5112: my $output = '<table>';
5113: foreach my $item (@menuitems) {
5114: my $checked = '';
5115: if (grep(/^\Q$item\E$/,@current)) {
5116: $checked = ' checked="checked" ';
5117: }
5118: my $rem = $count%($numinrow);
5119: if ($rem == 0) {
5120: if ($count > 0) {
5121: $output .= '</tr>';
5122: }
5123: $output .= '<tr>';
5124: }
5125: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
5126: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
5127: $menutitles{$item}.'</label></span></td>';
5128: $count ++;
5129: }
5130: my $rem = $count%($numinrow);
5131: my $colsleft = $numinrow - $rem;
5132: if ($colsleft > 1 ) {
5133: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5134: ' </td>';
5135: } elsif ($colsleft == 1) {
5136: $output .= '<td class="LC_left_item"> </td>';
5137: }
5138: $output .= '</tr></table>';
5139: }
5140:
5141: sub ltimenu_titles {
5142: return &Apache::lonlocal::texthash(
5143: fullname => 'Full name',
5144: coursetitle => 'Course title',
5145: role => 'Role',
5146: logout => 'Logout',
5147: grades => 'Grades',
5148: );
5149: }
5150:
1.91 raeburn 5151: sub print_menuitems {
5152: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
5153: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
5154: return;
5155: }
5156: if ($position eq 'top') {
5157: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
5158: if ($settings->{'menucollections'} ne '') {
5159: foreach my $item (split(/;/,$settings->{'menucollections'})) {
5160: my ($num,$value) = split(/\%/,$item);
5161: if ($num =~ /^\d+$/) {
5162: $defaultmenu_options{$num} = $num;
5163: }
5164: }
5165: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
5166: $addcollection = $defaultmenu_order[-1] + 1;
5167: } else {
5168: $addcollection = 1;
5169: }
5170: $defaultmenu_options{$addcollection} = $addcollection;
5171: my %items = (
5172: 'menudefault' => {
5173: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
5174: &mt("(can be overriden in deep-link context)"),
5175: input => 'selectbox',
5176: options => \%defaultmenu_options,
5177: order => \@defaultmenu_order,
5178: nullval => &mt('Standard (all menus shown)'),
5179: },
5180: );
5181: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
5182: } else {
5183: my %menu;
5184: my $count = 0;
5185: my $next = 1;
5186: my ($datatable,$disabled);
5187: if ($noedit) {
5188: $disabled = ' disabled="disabled"';
5189: }
5190:
5191: my ($ordered,$cats) = &menuitems_categories();
5192: my @order = @{$ordered};
5193: my %categories = %{$cats};
5194: my %menutitles = &menuitems_titles();
5195: my %menufields = &menuitems_fields();
5196:
5197: if ($settings->{'menucollections'} ne '') {
5198: foreach my $item (split(/;/,$settings->{'menucollections'})) {
5199: my ($num,$value) = split(/\%/,$item);
5200: if ($num =~ /^\d+$/) {
5201: my @entries = split(/\&/,$value);
5202: foreach my $entry (@entries) {
5203: my ($name,$fields) = split(/=/,$entry);
5204: $menu{$num}{$name} = $fields;
5205: }
5206: }
5207: }
5208: if (keys(%menu)) {
5209: my @current = sort { $a <=> $b } keys(%menu);
5210: $next += $current[-1];
5211: foreach my $num (@current) {
5212: my %checked;
5213: my $on = ' checked="checked"';
5214: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 5215: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 5216: if ($menu{$num}{$key} eq 'y') {
5217: $checked{$key} = $on;
5218: }
5219: } else {
5220: foreach my $field (split(/,/,$menu{$num}{$key})) {
5221: if (exists($menufields{$field})) {
5222: $checked{$field} = $on;
5223: }
5224: }
5225: }
5226: }
5227: if (ref($menu{$num}) eq 'HASH') {
5228: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
5229: foreach my $category (@order) {
5230: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
5231: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 5232: if ($category eq 'text') {
5233: $datatable .= '<i>'.&mt('Header').'</i><br />';
5234: }
1.91 raeburn 5235: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 5236: if ($field eq 'disc') {
5237: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
5238: }
1.91 raeburn 5239: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
5240: $menufields{$field}.'</label><br />';
5241: }
5242: $datatable .= '</fieldset>';
5243: }
5244: }
5245: $datatable .= &item_table_row_end();
5246: $count ++;
5247: }
5248: }
5249: }
5250: } elsif ($noedit) {
5251: my $text = &mt('No menu collections defined for this course.');
5252: $datatable .= &item_table_row_start($text,$count);
5253: }
5254: unless ($noedit) {
5255: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
5256: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
5257: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
5258: foreach my $category (@order) {
5259: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
5260: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
5261: foreach my $field (@{$categories{$category}}) {
5262: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
5263: $menufields{$field}.'</label><br />';
5264: }
5265: $datatable .= '</fieldset>';
5266: }
5267: }
5268: $datatable .= &item_table_row_end();
5269: $count ++;
5270: }
5271: return $datatable;
5272: }
5273: }
5274:
5275: sub menuitems_abbreviations {
5276: my %briefcats = (
5277: text => 'pt',
5278: links => 'p',
5279: list => 'ps',
5280: inline => 's',
5281: );
5282: return %briefcats;
5283: }
5284:
5285: sub menuitems_categories {
5286: my @order = ('shown','text','links','list','inline');
5287: my %categories = (
1.94 raeburn 5288: shown => ['top','inline','foot','main'],
5289: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 5290: links => ['pers','logo','menu','comm','roles','help','logout'],
1.91 raeburn 5291: list => ['about','prefs','port','wish','anno','rss'],
5292: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
5293: );
5294: return (\@order,\%categories);
5295: }
5296:
5297: sub menuitems_titles {
5298: return &Apache::lonlocal::texthash (
5299: shown => 'Hierarchy',
1.94 raeburn 5300: text => 'Text',
1.91 raeburn 5301: links => 'Header links',
5302: list => 'Drop-down list',
5303: inline => 'Inline links',
5304: );
5305: }
5306:
5307: sub menuitems_fields {
5308: return &Apache::lonlocal::texthash (
5309: top => 'Display header',
5310: inline => 'Display inline menu',
1.94 raeburn 5311: foot => 'Display footer',
1.91 raeburn 5312: main => 'Access to main menu',
1.92 raeburn 5313: pers => 'Personal',
5314: logo => 'LON-CAPA',
1.91 raeburn 5315: menu => 'Home',
5316: comm => 'Messages',
5317: roles => 'Roles/Courses',
5318: help => 'Help',
5319: logout => 'Logout',
5320: name => 'Fullname',
5321: crs => 'Course Title',
5322: role => 'Current Role',
1.94 raeburn 5323: disc => 'Discussion',
5324: fdbk => 'Feedback',
1.91 raeburn 5325: about => 'Information',
5326: prefs => 'Preferences',
5327: port => 'Portfolio',
5328: wish => 'Stored Links',
5329: anno => 'Calendar',
5330: rss => 'RSS Feeds',
5331: cont => 'Contents',
5332: grades => 'Grades',
5333: chat => 'Chat',
5334: people => 'People',
5335: groups => 'Groups',
5336: resv => 'Reservations',
5337: syll => 'Syllabus',
5338: feeds => 'Feeds',
5339: );
5340: }
5341:
5342: sub menucollections_display {
5343: my ($collections) = @_;
5344: my %menu;
5345: my ($ordered,$cats) = &menuitems_categories();
5346: my @order = @{$ordered};
5347: my %categories = %{$cats};
5348: my %menutitles = &menuitems_titles();
5349: my %menufields = &menuitems_fields();
5350: foreach my $item (split(/;/,$collections)) {
5351: my ($num,$value) = split(/\%/,$item);
5352: if ($num =~ /^\d+$/) {
5353: my @entries = split(/\&/,$value);
5354: foreach my $entry (@entries) {
5355: my ($name,$fields) = split(/=/,$entry);
5356: $menu{$num}{$name} = $fields;
5357: }
5358: }
5359: }
5360: my $output = '';
5361: if (keys(%menu)) {
5362: my @current = sort { $a <=> $b } keys(%menu);
5363: foreach my $num (@current) {
5364: my %checked;
5365: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 5366: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 5367: if ($menu{$num}{$key} eq 'y') {
5368: $checked{$key} = 1;
5369: }
5370: } else {
5371: foreach my $field (split(/,/,$menu{$num}{$key})) {
5372: if (exists($menufields{$field})) {
5373: $checked{$field} = 1;
5374: }
5375: }
5376: }
5377: }
5378: if (ref($menu{$num}) eq 'HASH') {
5379: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
5380: foreach my $category (@order) {
5381: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
5382: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
5383: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 5384: if ($category eq 'text') {
5385: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
5386: }
1.91 raeburn 5387: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 5388: if ($field eq 'disc') {
5389: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
5390: }
1.91 raeburn 5391: if ($checked{$field}) {
5392: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
5393: } else {
5394: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
5395: }
5396: $output .= '<br />';
5397: }
5398: $output .= '</fieldset>';
5399: }
5400: }
5401: $output .= '</fieldset>';
5402: }
5403: }
5404: }
5405: return $output;
5406: }
5407:
1.93 raeburn 5408: sub print_linkprotection {
1.99 ! raeburn 5409: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit) = @_;
1.93 raeburn 5410: unless (ref($settings) eq 'HASH') {
5411: return;
5412: }
5413:
5414: my %linkprotection;
5415: my $count = 0;
5416: my $next = 1;
5417: my ($datatable,$disabled,$css_class);
5418: if ($noedit) {
5419: $disabled = ' disabled="disabled"';
5420: }
5421: my %lt = &linkprot_names();
5422: my $itemcount = 0;
5423:
1.99 ! raeburn 5424: my $switchserver = &check_switchserver($cdom,$cnum);
! 5425:
1.93 raeburn 5426: if (ref($settings->{'linkprotection'}) eq 'HASH') {
5427: if (keys(%{$settings->{'linkprotection'}})) {
5428: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprotection'}});
5429: $next += $current[-1];
5430: for (my $i=0; $i<@current; $i++) {
5431: my $num = $current[$i];
5432: my %values;
5433: if (ref($settings->{'linkprotection'}->{$num}) eq 'HASH') {
5434: %values = %{$settings->{'linkprotection'}->{$num}};
5435: } else {
5436: next;
5437: }
5438: my $selected;
5439: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
5440: $selected = ' selected="selected"';
5441: }
5442: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5443: $datatable .=
5444: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
5445: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
5446: &mt('Delete?').'</label></span></td>'.
5447: '<td><span class="LC_nobreak">'.$lt{'name'}.
1.98 raeburn 5448: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 5449: (' 'x2).
1.99 ! raeburn 5450: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 5451: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
5452: (' 'x2).
5453: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
5454: 'value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span>'.
1.99 ! raeburn 5455: '<br /><br />';
! 5456: if ($values{'key'} ne '') {
! 5457: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
! 5458: if ($noedit) {
! 5459: $datatable .= ': ['.&mt('not shown').']';
! 5460: } elsif ($switchserver) {
! 5461: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
! 5462: } else {
! 5463: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
! 5464: }
! 5465: $datatable .= '</span> '.(' 'x2);
! 5466: } elsif (!$switchserver) {
! 5467: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
! 5468: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
! 5469: '</span> '.(' 'x2);
! 5470: }
! 5471: if ($switchserver) {
! 5472: if ($values{'usable'} ne '') {
! 5473: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
! 5474: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
! 5475: '<span class="LC_nobreak">'.&mt('Change secret?').
! 5476: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLTI(this.form,'."'$i','secret'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
! 5477: (' 'x2).
! 5478: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLTI(this.form,'."'$i','secret'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
! 5479: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
! 5480: '<span class="LC_nobreak"> - '.&mt("submit from course's home server: [_1].",$switchserver).'</span>'.
! 5481: '</div>';
! 5482: } elsif ($values{'key'} eq '') {
! 5483: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.&mt("submit from course's home server: [_1].",$switchserver).'</span>'."\n";
! 5484: } else {
! 5485: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.&mt("submit from course's home server: [_1].",$switchserver).'</span>'."\n";
! 5486: }
! 5487: } else {
! 5488: if ($values{'usable'} ne '') {
! 5489: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
! 5490: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
! 5491: '<span class="LC_nobreak">'.&mt('Change?').
! 5492: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLTI(this.form,'."'$i','secret'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
! 5493: (' 'x2).
! 5494: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLTI(this.form,'."'$i','secret'".');"'.$disabled.' />'.&mt('Yes').
! 5495: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
! 5496: '<span class="LC_nobreak">'.&mt('New Secret').':'.
! 5497: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="off"'.$disabled.' />'.
! 5498: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.linkprot_secret_'.$i.'.type='."'text'".' } else { this.form.linkprot_secret_'.$i.'.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>'.
! 5499: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
! 5500: } else {
! 5501: $datatable .=
! 5502: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
! 5503: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="off"'.$disabled.' />'.
! 5504: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.linkprot_secret_'.$i.'.type='."'text'".' } else { this.form.linkprot_secret_'.$i.'.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>'.
! 5505: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
! 5506: }
! 5507: }
! 5508: $datatable .= '</td></tr>';
1.93 raeburn 5509: $itemcount ++;
5510: }
5511: }
5512: }
5513: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5514: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5515: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 5516: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.93 raeburn 5517: '<td>'.
5518: '<span class="LC_nobreak">'.$lt{'name'}.
1.98 raeburn 5519: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 5520: (' 'x2).
1.98 raeburn 5521: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 5522: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5523: (' 'x2).
1.98 raeburn 5524: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
1.99 ! raeburn 5525: '<br /><br />';
! 5526: if ($switchserver) {
! 5527: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.&mt("submit from course's home server: [_1].",$switchserver).'</span>'."\n";
! 5528: } else {
! 5529: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="linkprot_key_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
! 5530: (' 'x2).
! 5531: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="off"'.$disabled.' />'.
! 5532: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.linkprot_secret_add.type='."'text'".' } else { this.form.linkprot_secret_add.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label></span> '."\n";
! 5533: }
! 5534: $datatable .= '</td></tr>';
1.93 raeburn 5535: $$rowtotal ++;
5536: return $datatable;;
5537: }
5538:
5539: sub linkprot_names {
5540: my %lt = &Apache::lonlocal::texthash(
5541: 'version' => 'LTI Version',
5542: 'key' => 'Key',
5543: 'lifetime' => 'Nonce lifetime (s)',
5544: 'name' => 'Launcher Application Name',
5545: 'secret' => 'Secret',
5546: );
5547: return %lt;
5548: }
5549:
1.99 ! raeburn 5550: sub check_switchserver {
! 5551: my ($cdom,$cnum) = @_;
! 5552: my ($allowed,$switchserver);
! 5553: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
! 5554: unless ($home eq 'no_host') {
! 5555: my @ids=&Apache::lonnet::current_machine_ids();
! 5556: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
! 5557: if (!$allowed) {
! 5558: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
! 5559: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
! 5560: '&destinationurl=/adm/courseprefs">'.&mt('Switch Server').'</a>';
! 5561: }
! 5562: }
! 5563: return $switchserver;
! 5564: }
! 5565:
1.1 raeburn 5566: sub print_other {
1.80 raeburn 5567: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5568: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
5569: return;
5570: }
1.3 raeburn 5571: my @ordered = &get_other_items($cdom,$settings,$allitems);
5572: my %items;
5573: foreach my $parameter (@ordered) {
5574: $items{$parameter} = {
5575: text => '<b>'.$parameter.'</b>',
5576: input => 'textbox',
5577: size => '15',
5578: },
5579: }
5580: push (@ordered,'newp_value');
5581: $items{'newp_value'} = {
5582: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
5583: '<input type="textbox" name="newp_name"'.
5584: ' value="" size="30" />',
5585: input => 'textbox',
5586: size => '30',
5587: };
1.93 raeburn 5588: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 5589: }
5590:
5591: sub get_other_items {
5592: my ($cdom,$settings,$allitems) = @_;
5593: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
5594: return;
5595: }
1.1 raeburn 5596: my @ordered;
5597: if (ref($settings) eq 'HASH') {
5598: foreach my $parameter (sort(keys(%{$settings}))) {
5599: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 5600: next if (($parameter eq 'course.helper.not.run') &&
5601: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 5602: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
5603: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
5604: || ($parameter eq 'type') ||
1.50 raeburn 5605: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 5606: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 5607: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
5608: ($parameter eq 'clonedfrom')) {
1.1 raeburn 5609: push(@ordered,$parameter);
5610: }
5611: }
5612: }
1.3 raeburn 5613: return @ordered;
1.1 raeburn 5614: }
5615:
5616: sub item_table_row_start {
1.91 raeburn 5617: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 5618: my $output;
1.56 raeburn 5619: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
5620: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 5621: if ($leftclass eq '') {
5622: $leftclass = 'LC_left_item';
5623: }
5624: if ($rightclass eq '') {
5625: $rightclass = 'LC_right_item';
5626: }
1.56 raeburn 5627: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 5628: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 5629: '</td>';
1.91 raeburn 5630: if ($colspan > 1) {
5631: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 5632: } else {
1.91 raeburn 5633: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 5634: }
1.1 raeburn 5635: return $output;
5636: }
5637:
5638: sub item_table_row_end {
5639: return '</td></tr>';
5640: }
5641:
5642: sub yesno_radio {
1.80 raeburn 5643: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
1.1 raeburn 5644: my $itemon = ' ';
5645: my $itemoff = ' checked="checked" ';
1.69 raeburn 5646: if (($valueyes eq '') && ($valueno eq '')) {
5647: $valueyes = 'yes';
5648: $valueno = '';
5649: }
1.1 raeburn 5650: if (ref($settings) eq 'HASH') {
1.69 raeburn 5651: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 5652: $itemon = $itemoff;
5653: $itemoff = ' ';
5654: }
1.69 raeburn 5655: unless (exists($settings->{$item})) {
5656: if ($unsetdefault eq $valueyes) {
5657: $itemon = $itemoff;
5658: $itemoff = ' ';
5659: }
5660: }
1.1 raeburn 5661: }
1.80 raeburn 5662: my $disabled;
5663: if ($noedit) {
5664: $disabled = ' disabled="disabled"';
5665: }
1.1 raeburn 5666: return '<span class="LC_nobreak"><label>'.
5667: '<input type="radio" name="'.$item.'"'.
1.80 raeburn 5668: $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
1.1 raeburn 5669: '<label><input type="radio" name="'.$item.'"'.
1.80 raeburn 5670: $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
1.1 raeburn 5671: }
5672:
5673: sub select_from_options {
1.91 raeburn 5674: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 5675: my $output;
1.80 raeburn 5676: my $disabled;
5677: if ($noedit) {
5678: $disabled = ' disabled=disabled"';
5679: }
1.1 raeburn 5680: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
5681: $output='<select name="'.$item.'" '.$onchange;
5682: if ($multiple) {
5683: $output .= ' multiple="multiple"';
5684: my $num = @{$order};
5685: $num ++ if ($nullval ne '');
5686: if (($maxsize) && ($maxsize < $num)) {
5687: $output .= ' size="'.$maxsize.'"';
5688: }
5689: }
1.91 raeburn 5690: if ($id ne '') {
5691: $output .= ' id="'.$id.'"';
5692: }
1.80 raeburn 5693: $output .= $disabled.'>'."\n";
1.1 raeburn 5694: if ($nullval ne '') {
5695: $output .= '<option value=""';
5696: if (ref($curr) eq 'ARRAY') {
5697: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
5698: $output .= ' selected="selected" ';
5699: }
5700: } else {
5701: if ($curr eq '') {
5702: $output .= ' selected="selected" ';
5703: }
5704: }
5705: $output .= '>'.$nullval.'</option>';
5706: }
5707: foreach my $option (@{$order}) {
5708: $output.= '<option value="'.$option.'"';
5709: if (ref($curr) eq 'ARRAY') {
5710: if (grep(/^\Q$option\E$/,@{$curr})) {
5711: $output .= ' selected="selected" ';
5712: }
5713: } else {
5714: if ($option eq $curr) {
5715: $output.=' selected="selected"';
5716: }
5717: }
5718: $output.=">$options->{$option}</option>\n";
5719: }
5720: $output.="</select>";
5721: }
5722: return $output;
5723: }
5724:
5725: sub make_item_rows {
1.80 raeburn 5726: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
1.1 raeburn 5727: my $datatable;
5728: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
5729: my $count = 0;
5730: foreach my $item (@{$ordered}) {
5731: $count ++;
1.56 raeburn 5732: my $colspan;
5733: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
5734: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
5735: $colspan = 2;
5736: }
1.41 www 5737: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.56 raeburn 5738: $datatable .= &item_table_row_start($items->{$item}{text},$count,"advanced",$colspan);
1.41 www 5739: } else {
1.56 raeburn 5740: $datatable .= &item_table_row_start($items->{$item}{text},$count,undef,$colspan);
1.41 www 5741: }
1.55 raeburn 5742: if ($item eq 'defaultcredits') {
5743: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
5744: my $showcredits;
5745: if ($defaultcredits ne '') {
5746: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
5747: } else {
5748: $showcredits = &mt('No default set');
5749: }
5750: $datatable .= $showcredits;
5751: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 5752: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 5753: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 5754: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 5755: } elsif ($item eq 'print_header_format') {
1.80 raeburn 5756: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 5757: } elsif ($item eq 'lti.lcmenu') {
5758: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 5759: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 5760: my $disabled;
5761: if ($noedit) {
5762: $disabled = ' disabled="disabled"';
5763: }
1.1 raeburn 5764: $datatable .=
5765: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 5766: $settings->{$item},$disabled);
1.1 raeburn 5767: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 5768: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 5769: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 5770: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
5771: unless ($domdefs{$item} eq '0') {
5772: $unsetdefault = 1;
5773: }
5774: $valueyes = "1";
5775: $valueno = "0";
1.87 raeburn 5776: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
5777: $valueyes = '1';
1.69 raeburn 5778: }
1.80 raeburn 5779: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 5780: } elsif ($items->{$item}{input} eq 'selectbox') {
1.91 raeburn 5781: my $id;
5782: if ($caller eq 'menuitems') {
5783: $id = $item;
5784: }
1.1 raeburn 5785: my $curr = $settings->{$item};
5786: $datatable .=
5787: &select_from_options($item,$items->{$item}{'order'},
5788: $items->{$item}{'options'},$curr,
1.80 raeburn 5789: $items->{$item}{'nullval'},
1.91 raeburn 5790: undef,undef,undef,$noedit,$id);
1.1 raeburn 5791: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 5792: my $disabled;
5793: if ($noedit) {
5794: $disabled = ' disabled=disabled"';
5795: }
1.1 raeburn 5796: $datatable .=
5797: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 5798: $items->{$item}{size},
5799: $disabled);
1.1 raeburn 5800: }
5801: $datatable .= &item_table_row_end();
5802: }
5803: if (ref($rowtotal)) {
5804: $$rowtotal += scalar(@{$ordered});
5805: }
5806: }
5807: return $datatable;
5808: }
5809:
5810: sub nothidepriv_row {
1.80 raeburn 5811: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 5812: my ($cnum) = &get_course();
1.56 raeburn 5813: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 5814: if (ref($settings) eq 'HASH') {
5815: if ($settings->{$item} ne '') {
5816: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
5817: if ($user !~ /:/) {
5818: $nothide{join(':',split(/[\@]/,$user))}=1;
5819: } else {
5820: $nothide{$user} = 1;
5821: }
5822: }
5823: }
1.56 raeburn 5824: if ($settings->{'checkforpriv'}) {
5825: @checkdoms = split(/,/,$settings->{'checkforpriv'});
5826: }
1.1 raeburn 5827: }
1.56 raeburn 5828: push(@checkdoms,$cdom);
5829: my %coursepersonnel =
5830: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 5831: my @privusers;
5832: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 5833: my ($uname,$udom,$role) = split(/:/,$person);
5834: my $user = $uname.':'.$udom;
5835: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 5836: if ($end == -1 || $start == -1) {
5837: next;
5838: }
1.56 raeburn 5839: foreach my $dom (@checkdoms) {
5840: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
5841: unless (grep(/^\Q$user\E$/,@privusers)) {
5842: push(@privusers,$user);
1.3 raeburn 5843: }
5844: }
5845: }
1.1 raeburn 5846: }
1.56 raeburn 5847: if (@privusers > 0) {
1.80 raeburn 5848: my $disabled;
5849: if ($noedit) {
5850: $disabled = ' disabled="disabled"';
5851: }
1.1 raeburn 5852: $datatable .= '<table align="right">';
5853: foreach my $user (sort(@privusers)) {
5854: my $hideon = ' checked="checked" ';
5855: my $hideoff = '';
5856: if ($nothide{$user}) {
5857: $hideoff = $hideon;
5858: $hideon = '';
5859: }
5860: my ($uname,$udom) = split(':',$user);
5861: $datatable .= '<tr><td align="left">'.
5862: &Apache::loncommon::aboutmewrapper(
5863: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5864: $uname,$udom,'aboutuser').
5865: '</td><td align="left">'.
5866: '<span class="LC_nobreak"><label>'.
5867: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 5868: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 5869: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 5870: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 5871: '</tr>';
5872: }
5873: $datatable .= '</table>';
5874: } else {
1.9 raeburn 5875: if ($crstype eq 'Community') {
5876: $datatable .= &mt('No Domain Coordinators have community roles');
5877: } else {
5878: $datatable .= &mt('No Domain Coordinators have course roles');
5879: }
1.1 raeburn 5880: }
5881: return $datatable;
5882: }
5883:
1.56 raeburn 5884: sub checkforpriv_row {
1.80 raeburn 5885: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 5886: my $datatable;
5887: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
5888: if (keys(%domains) == 1) {
5889: $datatable = '</td><td align="right">'.
5890: &mt("Course's domain is only domain");
5891: return $datatable;
5892: }
5893: my @excdoms = ($cdom);
5894: my $num = 0;
5895: if ($settings->{$item} eq '') {
5896: $datatable = '</td><td align="right">'.
5897: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 5898: 1,1,undef,undef,\@excdoms,
5899: $noedit);
1.56 raeburn 5900: } else {
5901: my @privdoms = split(/,/,$settings->{$item});
5902: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
5903: $datatable = '</td><td align="right"><br />'.
5904: &Apache::loncommon::start_data_table();
1.80 raeburn 5905: my $disabled;
5906: if ($noedit) {
5907: $disabled = ' disabled="disabled"';
5908: }
1.56 raeburn 5909: if (@privdoms > 0) {
5910: foreach my $currdom (@privdoms) {
5911: next unless ($domains{$currdom});
5912: my $domdesc = &Apache::lonnet::domain($currdom,'description');
5913: if ($domdesc eq '') {
5914: $domdesc = $currdom;
5915: }
5916: $datatable .=
5917: &Apache::loncommon::start_data_table_row().
5918: '<td align="left"><span class="LC_nobreak">'.
5919: &mt('Domain:').'<b> '.$domdesc.
5920: '</b><input type="hidden" name="checkforpriv_'.$num.
5921: '" value="'.$currdom.'" /></span><br />'.
5922: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 5923: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
5924: &mt('Delete').'</label></span></td>'.
1.56 raeburn 5925: &Apache::loncommon::end_data_table_row();
5926: $num ++;
5927: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
5928: push(@excdoms,$currdom);
5929: }
5930: }
5931: }
5932: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
5933: $datatable .=
5934: &Apache::loncommon::start_data_table_row().
5935: '<td align="left"><span class="LC_nobreak">'.
5936: &mt('Additional domain:'). '</span><br />'.
5937: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 5938: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 5939: '</td>'.&Apache::loncommon::end_data_table_row();
5940: }
5941: $datatable .= &Apache::loncommon::end_data_table().
5942: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
5943: '<br />';
5944: }
5945: return $datatable;
5946: }
5947:
1.1 raeburn 5948: sub print_hdrfmt_row {
1.80 raeburn 5949: my ($item,$settings,$noedit) = @_;
1.1 raeburn 5950: my @curr;
5951: my $currnum = 0;
5952: my $maxnum = 2;
5953: my $currstr;
5954: if ($settings->{$item} ne '') {
5955: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
5956: $settings->{$item}.'</tt></span></b><br />';
5957: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 5958: foreach my $val (@current) {
5959: unless ($val eq '') {
5960: push(@curr,$val);
1.1 raeburn 5961: }
5962: }
5963: $currnum = @curr;
5964: $maxnum += $currnum;
5965: }
5966:
5967: my $output = <<ENDJS;
5968:
5969: <script type="text/javascript" language="Javascript">
5970:
5971: function reOrder(chgnum) {
5972: var maxnum = $maxnum;
5973: var oldidx = 'printfmthdr_oldpos_'+chgnum;
5974: var newidx = 'printfmthdr_pos_'+chgnum;
5975: oldidx = getIndexByName(oldidx);
5976: newidx = getIndexByName(newidx);
5977: var oldpos = document.display.elements[oldidx].value;
5978: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
5979: document.display.elements[oldidx].value = newpos;
5980: var chgtype = 'up';
5981: if (newpos < oldpos) {
5982: chgtype = 'down';
5983: }
5984: for (var j=0; j<maxnum; j++) {
5985: if (j != chgnum) {
5986: oldidx = 'printfmthdr_oldpos_'+j;
5987: newidx = 'printfmthdr_pos_'+j;
5988: oldidx = getIndexByName(oldidx);
5989: newidx = getIndexByName(newidx);
5990: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
5991: var currsel = document.display.elements[newidx].selectedIndex;
5992: if (chgtype == 'up') {
5993: if ((currpos > oldpos) && (currpos <= newpos)) {
5994: document.display.elements[newidx].selectedIndex = currsel-1;
5995: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
5996: }
5997: } else {
5998: if ((currpos >= newpos) && (currpos < oldpos)) {
5999: document.display.elements[newidx].selectedIndex = currsel+1;
6000: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
6001: }
6002: }
6003: }
6004: }
6005: return;
6006: }
6007:
6008: function getIndexByName(item) {
6009: for (var i=0;i<document.display.elements.length;i++) {
6010: if (document.display.elements[i].name == item) {
6011: return i;
6012: }
6013: }
6014: return -1;
6015: }
6016:
6017: </script>
6018:
6019: ENDJS
1.56 raeburn 6020: $output .= '</td><td align="right"><br />'.
6021: $currstr.'<table class="LC_data_table">';
1.80 raeburn 6022: my $disabled;
6023: if ($noedit) {
6024: $disabled = ' disabled="disabled"';
6025: }
1.1 raeburn 6026: if (@curr > 0) {
6027: for (my $i=0; $i<@curr; $i++) {
6028: my $pos = $i+1;
1.10 raeburn 6029: $output .= '<tr>'.
1.1 raeburn 6030: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 6031: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 6032: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 6033: '"'.$disabled.' /></span></td>';
1.1 raeburn 6034: if ($curr[$i] =~ /^%\d*[nca]$/) {
6035: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
6036: $output .= '<td align="left">'.
1.80 raeburn 6037: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 6038: } else {
6039: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
6040: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 6041: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 6042: }
1.10 raeburn 6043: $output .= '</tr>';
1.1 raeburn 6044: }
6045: }
1.80 raeburn 6046: my $pos = $currnum+1;
6047: unless ($noedit) {
6048: $output .=
6049: '<tr>'.
1.1 raeburn 6050: '<td align="left"><span class="LC_nobreak">'.
6051: &position_selector($pos,$currnum,$maxnum).
6052: '<b>'.&mt('New').'</b></span></td><td align="left">'.
6053: &substitution_selector($currnum).'</td>'.
1.10 raeburn 6054: '</tr>';
1.80 raeburn 6055: $pos ++;
1.82 raeburn 6056: $currnum ++;
6057: $output .=
1.80 raeburn 6058: '<tr>'.
1.1 raeburn 6059: '<td align="left"><span class="LC_nobreak">'.
6060: &position_selector($pos,$currnum,$maxnum).
6061: '<b>'.&mt('New').'</b></span></td>'.
6062: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
6063: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 6064: '" value="" size ="25" />'.
6065: '<input type="hidden" name="printfmthdr_maxnum" value="'.
6066: $maxnum.'" /></td>'.
1.80 raeburn 6067: '</tr>';
6068: }
6069: $output .= '</table><br />';
1.1 raeburn 6070: return $output;
6071: }
6072:
6073: sub position_selector {
1.80 raeburn 6074: my ($pos,$num,$maxnum,$disabled) = @_;
6075: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 6076: for (my $j=1; $j<=$maxnum; $j++) {
6077: my $sel = '';
6078: if ($pos == $j) {
6079: $sel = ' selected="selected"';
6080: }
6081: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
6082: }
6083: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
6084: '" value="'.$pos.'" />';
6085: return $output;
6086: }
6087:
6088: sub substitution_selector {
1.80 raeburn 6089: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 6090: my ($stunametxt,$crsidtxt);
6091: if ($crstype eq 'Community') {
6092: $stunametxt = 'member name';
6093: $crsidtxt = 'community ID',
6094: } else {
6095: $stunametxt = 'student name';
6096: $crsidtxt = 'course ID',
6097: }
1.1 raeburn 6098: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 6099: n => $stunametxt,
6100: c => $crsidtxt,
1.1 raeburn 6101: a => 'assignment note',
6102: );
6103: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 6104: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 6105: if ($subst eq '') {
6106: $output .= '<option value="" selected="selected"> </option>';
6107: }
6108: foreach my $field ('n','c','a') {
6109: my $sel ='';
6110: if ($subst eq $field) {
6111: $sel = ' selected="selected"';
6112: }
6113: $output .= '<option value="'.$field.'"'.$sel.'>'.
6114: $lt{$field}.'</option>';
6115: }
6116: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
6117: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 6118: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 6119: return $output;
6120: }
6121:
1.23 raeburn 6122: sub change_clone {
6123: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
6124: my $clone_crs = $cnum.':'.$cdom;
6125: if ($cnum && $cdom) {
6126: my $clone_crs = $cnum.':'.$cdom;
6127: my @allowclone;
6128: if ($clonelist =~ /,/) {
6129: @allowclone = split(',',$clonelist);
6130: } else {
6131: $allowclone[0] = $clonelist;
6132: }
6133: foreach my $currclone (@allowclone) {
6134: if (!grep(/^$currclone$/,@$oldcloner)) {
6135: if ($currclone ne '*') {
1.71 raeburn 6136: if ($currclone =~ /:/) {
6137: my ($uname,$udom) = split(/:/,$currclone);
6138: if ($uname && $udom && $uname ne '*') {
6139: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
6140: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
6141: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
6142: if ($currclonecrs{'cloneable'} eq '') {
6143: $currclonecrs{'cloneable'} = $clone_crs;
6144: } else {
6145: $currclonecrs{'cloneable'} .= ','.$clone_crs;
6146: }
6147: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 6148: }
6149: }
6150: }
6151: }
6152: }
6153: }
6154: }
6155: foreach my $oldclone (@$oldcloner) {
6156: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
6157: if ($oldclone ne '*') {
1.71 raeburn 6158: if ($oldclone =~ /:/) {
6159: my ($uname,$udom) = split(/:/,$oldclone);
6160: if ($uname && $udom && $uname ne '*' ) {
6161: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
6162: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
6163: my %newclonecrs = ();
6164: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
6165: if ($currclonecrs{'cloneable'} =~ /,/) {
6166: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
6167: foreach my $crs (@currclonecrs) {
6168: if ($crs ne $clone_crs) {
6169: $newclonecrs{'cloneable'} .= $crs.',';
6170: }
1.23 raeburn 6171: }
1.71 raeburn 6172: $newclonecrs{'cloneable'} =~ s/,$//;
6173: } else {
6174: $newclonecrs{'cloneable'} = '';
1.23 raeburn 6175: }
1.71 raeburn 6176: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 6177: }
6178: }
6179: }
6180: }
6181: }
6182: }
6183: }
6184: }
6185: return;
6186: }
6187:
1.1 raeburn 6188: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>