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