Annotation of loncom/interface/courseprefs.pm, revision 1.122
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.122 ! raeburn 4: # $Id: courseprefs.pm,v 1.121 2023/06/01 20:04:36 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.118 raeburn 228: use Time::HiRes qw( sleep );
1.1 raeburn 229:
1.66 raeburn 230: my $registered_cleanup;
231: my $modified_courses;
232:
1.1 raeburn 233: sub handler {
234: my $r=shift;
235: if ($r->header_only) {
236: &Apache::loncommon::content_type($r,'text/html');
237: $r->send_http_header;
238: return OK;
239: }
240: my $context = 'course';
241: my $cid = $env{'request.course.id'};
1.66 raeburn 242: my ($cnum,$cdom,$chome) = &get_course($cid);
1.1 raeburn 243: my $crstype = &Apache::loncommon::course_type();
1.80 raeburn 244: my ($parm_permission,$allowed) = &get_permission($cid);
1.1 raeburn 245: my $navmap = Apache::lonnavmaps::navmap->new();
1.80 raeburn 246: if ($allowed && $navmap) {
1.1 raeburn 247: &Apache::loncommon::content_type($r,'text/html');
248: $r->send_http_header;
249: } else {
250: if ($navmap) {
1.9 raeburn 251: if ($crstype eq 'Community') {
252: $env{'user.error.msg'}=
253: "/adm/courseprefs:opa:0:0:Cannot modify community settings";
254: } else {
255: $env{'user.error.msg'}=
256: "/adm/courseprefs:opa:0:0:Cannot modify course settings";
257: }
1.1 raeburn 258: } else {
1.9 raeburn 259: if ($crstype eq 'Community') {
260: $env{'user.error.msg'}=
261: "/adm/courseprefs::0:1:Course environment gone, reinitialize the community";
262: } else {
263: $env{'user.error.msg'}=
264: "/adm/courseprefs::0:1:Course environment gone, reinitialize the course";
265:
266: }
1.1 raeburn 267: }
268: return HTTP_NOT_ACCEPTABLE;
269: }
270:
1.66 raeburn 271: $registered_cleanup=0;
272: @{$modified_courses}=();
273:
1.4 raeburn 274: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
275: ['phase','actions','origin']);
1.1 raeburn 276: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.4 raeburn 277: if ($env{'form.origin'} eq 'params') {
278: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
279: text=>"Parameter Manager"});
280: }
1.9 raeburn 281: my ($brtext,$brtitle,$crsinfotext,$crsinfodesc,$crscateg,$crshide);
282: my %lt;
283: if ($crstype eq 'Community') {
284: %lt = (
1.40 www 285: conf => 'Community Settings',
286: edit => 'Edit Community Settings',
1.9 raeburn 287: gens => 'General community settings',
288: idnu => 'Community ID or number',
1.64 raeburn 289: unco => 'Unique code',
1.9 raeburn 290: desc => 'Community Description',
1.24 raeburn 291: ownr => 'Community Owner',
1.25 raeburn 292: cown => 'Community Co-owners',
1.9 raeburn 293: catg => 'Categorize community',
294: excc => 'Exclude from community catalog',
295: clon => 'Users allowed to clone community',
296: rept => 'Replacement titles for standard community roles',
1.115 raeburn 297: time => 'Time Zone where the community is located',
1.9 raeburn 298: date => 'Locale used for community calendar',
299: coco => 'Community Content',
300: copo => 'Community Policy',
1.13 bisitz 301: priv => 'Domain Coordinators in community',
1.9 raeburn 302: defd => 'Default dates for member access',
303: stuv => 'Member-viewable membership list options',
304: stul => 'Member agreement needed to be listed',
1.42 www 305: clas => 'Membership and facilitator listing',
1.57 raeburn 306: prus => 'Privileged users (Domain Coordinators) in facilitator listing',
1.9 raeburn 307: defc => 'Default Community Spreadsheet',
308: defs => 'Default User Spreadsheet',
309: seme => 'Send message to member when clicking Done on Tasks'
310: );
311: } else {
312: %lt = (
1.40 www 313: conf => 'Course Settings',
314: edit => 'Edit Course Settings',
1.20 faziophi 315: gens => 'General course settings',
316: idnu => 'Course ID or number',
1.64 raeburn 317: unco => 'Unique code',
1.20 faziophi 318: desc => 'Course Description',
1.55 raeburn 319: cred => 'Student credits',
1.24 raeburn 320: ownr => 'Course Owner',
1.25 raeburn 321: cown => 'Course Co-owners',
1.9 raeburn 322: catg => 'Categorize course',
323: excc => 'Exclude from course catalog',
324: clon => 'Users allowed to clone course',
325: rept => 'Replacement titles for standard course roles',
1.115 raeburn 326: time => 'Time Zone in which the course takes place',
1.20 faziophi 327: date => 'Locale used for course calendar',
1.9 raeburn 328: coco => 'Course Content',
329: copo => 'Course Policy',
1.13 bisitz 330: priv => 'Domain Coordinators in course',
1.9 raeburn 331: defd => 'Default dates for student access',
332: stuv => 'Student-viewable classlist options',
333: stul => 'Student agreement needed to be listed',
1.42 www 334: clas => 'Classlists and staff listing',
1.57 raeburn 335: prus => 'Privileged users (Domain Coordinators) in staff listing',
1.56 raeburn 336: prdo => "Domains to check for privileged users (besides course's domain)",
1.9 raeburn 337: defc => 'Default Course Spreadsheet',
338: defs => 'Default Student Spreadsheet',
339: seme => 'Send message to student when clicking Done on Tasks',
340: );
341: }
1.35 raeburn 342: $lt{'lcrv'} = 'Required LON-CAPA version';
1.1 raeburn 343: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/courseprefs',
1.9 raeburn 344: text=>$lt{'conf'}});
1.1 raeburn 345: my $breadcrumbs =
1.9 raeburn 346: &Apache::lonhtmlcommon::breadcrumbs($lt{'edit'});
1.1 raeburn 347:
348: my $phase = 'pickactions';
349: if ( exists($env{'form.phase'}) ) {
350: $phase = $env{'form.phase'};
351: }
352:
1.80 raeburn 353: if (($phase eq 'categorizecourse') && ($parm_permission->{'categorizecourse'})) {
1.9 raeburn 354: &assign_course_categories($r,$crstype);
1.1 raeburn 355: return OK;
356: }
357:
1.80 raeburn 358: if (($phase eq 'releaseinfo') && ($parm_permission->{'releaseinfo'})) {
1.36 raeburn 359: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
360: if ($loncaparev) {
1.66 raeburn 361: if (&display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype)) {
362: push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
363: unless ($registered_cleanup) {
364: my $handlers = $r->get_handlers('PerlCleanupHandler');
365: $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
366: $registered_cleanup=1;
367: }
368: }
1.36 raeburn 369: return OK;
370: }
371: }
372:
1.1 raeburn 373: my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.102 raeburn 374: my %linkprot=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1.99 raeburn 375: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
1.118 raeburn 376: my %ltitools = &Apache::lonnet::dump('ltitools',$cdom,$cnum,undef,undef,undef,1);
377: my %ltitoolsenc = &Apache::lonnet::dump('nohist_toolsenc',$cdom,$cnum,undef,undef,undef,1);
1.102 raeburn 378: foreach my $id (keys(%linkprot)) {
379: if (ref($linkprot{$id}) eq 'HASH') {
1.99 raeburn 380: if (ref($ltienc{$id}) eq 'HASH') {
1.102 raeburn 381: $values{'linkprot'}{$id} = { %{$linkprot{$id}}, %{$ltienc{$id}} };
1.99 raeburn 382: } else {
1.102 raeburn 383: $values{'linkprot'}{$id} = $linkprot{$id};
1.99 raeburn 384: }
385: }
386: unless ($phase eq 'process') {
1.102 raeburn 387: if (ref($values{'linkprot'}{$id}) eq 'HASH') {
388: delete($values{'linkprot'}{$id}{'secret'});
1.99 raeburn 389: }
390: }
391: }
1.102 raeburn 392: if ($linkprot{'lock'}) {
393: delete($linkprot{'lock'});
1.93 raeburn 394: }
1.118 raeburn 395: foreach my $id (keys(%ltitools)) {
396: if (ref($ltitools{$id}) eq 'HASH') {
397: if (ref($ltitoolsenc{$id}) eq 'HASH') {
398: $values{'ltitools'}{$id} = { %{$ltitools{$id}}, %{$ltitoolsenc{$id}} };
399: } else {
400: $values{'ltitools'}{$id} = $ltitools{$id};
401: }
402: }
403: unless ($phase eq 'process') {
404: if (ref($values{'ltitools'}{$id}) eq 'HASH') {
405: delete($values{'ltitools'}{$id}{'secret'});
406: }
407: }
408: }
409: if ($ltitools{'lock'}) {
410: delete($ltitools{'lock'});
411: }
1.1 raeburn 412: my @prefs_order = ('courseinfo','localization','feedback','discussion',
413: 'classlists','appearance','grading','printouts',
1.118 raeburn 414: 'menuitems','ltitools','linkprot','spreadsheet',
415: 'bridgetasks','lti','other');
1.1 raeburn 416: my %prefs = (
417: 'courseinfo' =>
1.9 raeburn 418: { text => $lt{'gens'},
1.44 www 419: help => 'Course_Prefs_General',
1.35 raeburn 420: ordered => ['owner','co-owners','loncaparev','description',
1.64 raeburn 421: 'clonedfrom','courseid','uniquecode','categories',
1.88 raeburn 422: 'hidefromcat','syllabus','cloners','url',
1.64 raeburn 423: 'rolenames'],
1.3 raeburn 424: itemtext => {
1.25 raeburn 425: 'owner' => $lt{'ownr'},
426: 'co-owners' => $lt{'cown'},
427: 'description' => $lt{'desc'},
428: 'courseid' => $lt{'idnu'},
1.64 raeburn 429: 'uniquecode' => $lt{'unco'},
1.25 raeburn 430: 'categories' => $lt{'catg'},
431: 'hidefromcat' => $lt{'excc'},
432: 'cloners' => $lt{'clon'},
1.88 raeburn 433: 'syllabus' => 'Syllabus status',
1.25 raeburn 434: 'url' => 'Top Level Map',
435: 'rolenames' => $lt{'rept'},
1.35 raeburn 436: 'loncaparev' => $lt{'lcrv'},
1.63 raeburn 437: 'clonedfrom' => 'Cloned from',
1.3 raeburn 438: },
1.1 raeburn 439: },
440: 'localization' =>
1.42 www 441: { text => 'Language and time localization',
1.44 www 442: help => 'Course_Prefs_Language',
1.1 raeburn 443: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 444: itemtext => {
1.20 faziophi 445: languages => 'Languages used',
1.9 raeburn 446: timezone => $lt{'time'},
447: datelocale => $lt{'date'},
1.3 raeburn 448: },
1.1 raeburn 449: },
450: 'feedback' =>
1.20 faziophi 451: { text => 'Feedback messages',
1.44 www 452: help => 'Course_Prefs_Feedback',
1.1 raeburn 453: header => [{col1 => 'Questions about:',
1.20 faziophi 454: col2 => 'Recipients'}],
1.3 raeburn 455: ordered => ['question.email','comment.email','policy.email'],
456: itemtext => {
457: 'question.email' => 'Resource Content',
1.9 raeburn 458: 'comment.email' => $lt{'coco'},
459: 'policy.email' => $lt{'copo'},
1.3 raeburn 460: },
1.1 raeburn 461: },
462: 'discussion' =>
463: { text => 'Discussion and Chat',
1.44 www 464: help => 'Course_Prefs_Discussions',
1.31 raeburn 465: ordered => ['pch.roles.denied','pch.users.denied',
1.77 raeburn 466: 'pac.roles.denied','pac.users.denied',
1.31 raeburn 467: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 468: 'allow_limited_html_in_feedback',
1.50 raeburn 469: 'allow_discussion_post_editing',
470: 'discussion_post_fonts'],
1.3 raeburn 471: itemtext => {
1.31 raeburn 472: 'pch.roles.denied' => 'No Resource Discussion',
473: 'pch.users.denied' => 'No Resource Discussion',
474: 'plc.roles.denied' => 'No Chat room use',
475: 'plc.users.denied' => 'No Chat room use',
1.77 raeburn 476: 'pac.roles.denied' => 'No Anonymous Resource Discussion',
477: 'pac.users.denied' => 'No Anonymous Resource Discussion',
1.20 faziophi 478: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
479: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.77 raeburn 480: discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 481: },
1.1 raeburn 482: },
483: 'classlists' =>
1.9 raeburn 484: { text => $lt{'clas'},
1.44 www 485: help => 'Course_Prefs_Classlists',
1.1 raeburn 486: header => [{col1 => 'Type',
1.9 raeburn 487: col2 => $lt{'defd'}},
1.1 raeburn 488: {col1 => 'Setting',
1.9 raeburn 489: col2 => $lt{'priv'}},
1.1 raeburn 490: {col1 => 'Setting',
1.9 raeburn 491: col2 => $lt{'stuv'}}],
1.1 raeburn 492: ordered => ['default_enrollment_start_date',
493: 'default_enrollment_end_date',
1.55 raeburn 494: 'defaultcredits',
1.56 raeburn 495: 'nothideprivileged','checkforpriv',
496: 'student_classlist_view',
1.26 raeburn 497: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 498: itemtext => {
499: default_enrollment_start_date => 'Start date',
500: default_enrollment_end_date => 'End date',
1.57 raeburn 501: nothideprivileged => $lt{'prus'},
1.56 raeburn 502: checkforpriv => $lt{'prdo'},
1.9 raeburn 503: student_classlist_view => $lt{'stuv'},
1.26 raeburn 504: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 505: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.55 raeburn 506: defaultcredits => $lt{'cred'},
1.3 raeburn 507: },
1.1 raeburn 508: },
509: 'appearance' =>
1.20 faziophi 510: { text => 'Display of resources ',
1.44 www 511: help => 'Course_Prefs_Display',
1.1 raeburn 512: ordered => ['default_xml_style','pageseparators',
513: 'disable_receipt_display','texengine',
1.114 raeburn 514: 'tthoptions','uselcmath','usejsme',
515: 'inline_chem','extresource'],
1.3 raeburn 516: itemtext => {
1.17 faziophi 517: default_xml_style => 'Default XML style file',
1.20 faziophi 518: pageseparators => 'Visibly Separate Items on Pages',
519: disable_receipt_display => 'Disable display of problem receipts',
520: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 521: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.69 raeburn 522: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
523: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.95 raeburn 524: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.114 raeburn 525: extresource => 'Display of external resources',
1.3 raeburn 526: },
1.1 raeburn 527: },
528: 'grading' =>
529: { text => 'Grading',
1.44 www 530: help => 'Course_Prefs_Grading',
1.1 raeburn 531: ordered => ['grading','rndseed',
532: 'receiptalg','disablesigfigs'],
1.3 raeburn 533: itemtext => {
1.20 faziophi 534: grading => 'Grading',
535: rndseed => 'Randomization algorithm used',
536: receiptalg => 'Receipt algorithm used',
537: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 538: },
539:
1.1 raeburn 540: },
541: 'printouts' =>
1.20 faziophi 542: { text => 'Printout generation',
1.44 www 543: help => 'Course_Prefs_Printouts',
1.1 raeburn 544: ordered => ['problem_stream_switch','suppress_tries',
545: 'default_paper_size','print_header_format',
1.14 raeburn 546: 'disableexampointprint','canuse_pdfforms'],
1.3 raeburn 547: itemtext => {
548: problem_stream_switch => 'Allow problems to be split over pages',
549: suppress_tries => 'Suppress number of tries in printing',
550: default_paper_size => 'Default paper type',
551: print_header_format => 'Print header format',
1.51 bisitz 552: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 553: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 554: },
1.1 raeburn 555: },
556: 'spreadsheet' =>
557: { text => 'Spreadsheets',
1.44 www 558: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 559: ordered => ['spreadsheet_default_classcalc',
560: 'spreadsheet_default_studentcalc',
561: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 562: itemtext => {
1.9 raeburn 563: spreadsheet_default_classcalc => $lt{'defc'},
564: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 565: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
566: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
567: },
1.1 raeburn 568: },
569: 'bridgetasks' =>
570: { text => 'Bridge tasks',
1.44 www 571: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 572: ordered => ['task_messages','task_grading',
573: 'suppress_embed_prompt'],
1.3 raeburn 574: itemtext => {
1.9 raeburn 575: task_messages => $lt{'seme'},
1.3 raeburn 576: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 577: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 578: },
1.1 raeburn 579: },
1.87 raeburn 580: 'lti' =>
581: {
582: text => 'LTI provider settings',
583: help => 'Course_Prefs_LTIProvider',
584: ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'],
585: itemtext => {
586: 'lti.override' => 'Override domain defaults',
587: 'lti.topmenu' => 'Display LON-CAPA page header',
588: 'lti.inlinemenu' => 'Display LON-CAPA inline menu',
589: 'lti.lcmenu' => 'Menu items',
590: },
591: },
1.91 raeburn 592: 'menuitems' =>
593: {
594: text => 'Menu display',
595: help => 'Course_Prefs_Menus',
596: header => [{col1 => 'Default Menu',
597: col2 => 'Value',},
598: {col1 => 'Menu collections',
599: col2 => 'Settings',
600: }],
601: ordered => ['menudefault','menucollections'],
602: itemtext => {
603: menudefault => 'Choose default collection of menu items for course',
604: menucollections => 'Menu collections',
605: },
606: },
1.102 raeburn 607: 'linkprot' =>
1.93 raeburn 608: {
609: text => 'Link protection',
610: help => 'Course_Prefs_Linkprotection',
611: header => [{col1 => 'Item',
612: col2 => 'Settings',
613: }],
614: },
1.118 raeburn 615: 'ltitools' =>
616: {
617: text => 'External tools',
618: help => 'Course_Prefs_ExternalTools',
619: header => [{col1 => 'Item',
620: col2 => 'Settings',
621: }],
622: },
1.1 raeburn 623: 'other' =>
624: { text => 'Other settings',
1.44 www 625: help => 'Course_Prefs_Other',
1.1 raeburn 626: header => [ {col1 => 'Item',
627: col2 => 'Value',
628: }],
629: },
630: );
1.80 raeburn 631: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 632: my @allitems = &get_allitems(%prefs);
1.108 raeburn 633: my $result = &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
634: \@prefs_order,\%prefs,\%values,
635: $cnum,undef,\@allitems,
636: 'coursepref',$parm_permission);
637: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
638: $r->rflush();
639: &devalidate_remote_courseprefs($cdom,$cnum,$result);
640: }
1.80 raeburn 641: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.91 raeburn 642: my $noedit;
643: if (ref($parm_permission) eq 'HASH') {
644: unless ($parm_permission->{'process'}) {
645: $noedit = 1;
646: }
647: }
648: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 649: my @allitems = &get_allitems(%prefs);
1.1 raeburn 650: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.99 raeburn 651: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.80 raeburn 652: 'coursepref',$parm_permission);
1.1 raeburn 653: } else {
654: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.80 raeburn 655: \@prefs_order,\%prefs,
656: 'coursepref',$parm_permission);
1.1 raeburn 657: }
658: return OK;
659: }
660:
1.80 raeburn 661: sub get_permission {
662: my ($cid) = @_;
663: my %permission;
664: my $allowed = 0;
665: return (\%permission,$allowed) unless ($cid);
666: if (&Apache::lonnet::allowed('opa',$cid)) {
667: %permission= (
668: 'pickactions' => 1,
669: 'categorizecourse' => 1,
670: 'releaseinfo' => 1,
671: 'process' => 1,
672: 'display' => 1,
673: );
674: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
675: %permission = (
676: 'pickactions' => 1,
677: 'releaseinfo' => 1,
678: 'display' => 1,
679: );
680: }
681: foreach my $perm (values(%permission)) {
682: if ($perm) { $allowed=1; last; }
683: }
684: return (\%permission,$allowed);
685: }
686:
1.3 raeburn 687: sub get_allitems {
688: my (%prefs) = @_;
689: my @allitems;
690: foreach my $item (keys(%prefs)) {
691: if (ref($prefs{$item}) eq 'HASH') {
692: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
693: push(@allitems,@{$prefs{$item}{'ordered'}});
694: if ($item eq 'feedback') {
695: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
696: }
697: }
698: }
699: }
700: return @allitems;
701: }
702:
1.1 raeburn 703: sub print_config_box {
1.99 raeburn 704: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 705: my $ordered = $item->{'ordered'};
1.3 raeburn 706: my $itemtext = $item->{'itemtext'};
1.80 raeburn 707: my $noedit;
708: if (ref($parm_permission) eq 'HASH') {
709: unless ($parm_permission->{'process'}) {
710: $noedit = 1;
711: }
712: }
1.1 raeburn 713: my $rowtotal = 0;
714: my $output =
1.45 www 715: '<table class="LC_nested_outer">
716: <tr>
717: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 718: &mt($item->{text});
719: if ($item->{'help'}) {
1.53 raeburn 720: $output .= ' '.
1.52 raeburn 721: &Apache::loncommon::help_open_topic($item->{'help'});
722: }
723: $output .= '</span></th>'."\n".
724: '</tr>';
1.91 raeburn 725: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 726: $output .= '
1.45 www 727: <tr>
728: <td>
1.18 faziophi 729: <table class="LC_nested">';
730: if (exists $item->{'header'}->[0]->{'col1'} ||
731: exists $item->{'header'}->[0]->{'col2'}) {
732: $output .= '
733: <tr class="LC_info_row">
1.56 raeburn 734: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
735: if ($action eq 'feedback') {
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'}->[0]->{'col2'}).'</td>
1.18 faziophi 743: </tr>';
744: }
1.1 raeburn 745: $rowtotal ++;
746: if ($action eq 'feedback') {
1.80 raeburn 747: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 748: } elsif ($action eq 'classlists') {
1.80 raeburn 749: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 750: } elsif ($action eq 'menuitems') {
751: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 752: }
753: $output .= '
754: </table>
1.45 www 755: </td>
756: </tr>
757: <tr>
758: <td>
1.1 raeburn 759: <table class="LC_nested">
760: <tr class="LC_info_row">
761: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 762: if ($action eq 'classlists') {
763: $output .= '
764: <td class="LC_right_item" colspan="2">';
765: } else {
766: $output .= '
767: <td class="LC_right_item">';
768: }
769: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 770: </tr>';
771: if ($action eq 'classlists') {
1.80 raeburn 772: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 773: '
774: </table>
1.45 www 775: </td>
776: </tr>
777: <tr>
778: <td>
1.18 faziophi 779: <table class="LC_nested">';
1.43 www 780: if (exists $item->{'header'}->[2]->{'col1'} ||
781: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 782: $output .= '
783: <tr class="LC_info_row">
1.43 www 784: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
785: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 786: </tr>';
787: }
1.1 raeburn 788: }
789: } else {
790: $output .= '
1.45 www 791: <tr>
792: <td>
1.18 faziophi 793: <table class="LC_nested">';
794: if (exists $item->{'header'}->[0]->{'col1'} ||
795: exists $item->{'header'}->[0]->{'col2'}) {
796: $output .= '
797: <tr class="LC_info_row">
1.56 raeburn 798: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
799: if (($action eq 'courseinfo') || ($action eq 'localization') ||
800: ($action eq 'print_discussion')) {
801: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
802: } else {
803: $output .= '<td class="LC_right_item" valign="top">';
804: }
805: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 806: </tr>';
807: }
1.1 raeburn 808: }
809: $rowtotal ++;
810: if ($action eq 'courseinfo') {
1.80 raeburn 811: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 812: } elsif ($action eq 'localization') {
1.80 raeburn 813: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 814: } elsif ($action eq 'feedback') {
1.80 raeburn 815: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 816: } elsif ($action eq 'discussion') {
1.80 raeburn 817: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 818: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 819: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 820: } elsif ($action eq 'appearance') {
1.80 raeburn 821: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 822: } elsif ($action eq 'grading') {
1.80 raeburn 823: $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 824: } elsif ($action eq 'printouts') {
1.80 raeburn 825: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 826: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 827: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 828: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 829: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.118 raeburn 830: } elsif ($action eq 'ltitools') {
831: my $currtools = {};
832: if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
833: $currtools = $settings->{'ltitools'};
834: }
835: $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
1.87 raeburn 836: } elsif ($action eq 'lti') {
837: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 838: } elsif ($action eq 'menuitems') {
839: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 840: } elsif ($action eq 'linkprot') {
841: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 842: } elsif ($action eq 'other') {
1.80 raeburn 843: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 844: }
845: $output .= '
846: </table>
1.45 www 847: </td>
848: </tr>
849: </table><br />';
1.1 raeburn 850: return ($output,$rowtotal);
851: }
852:
853: sub process_changes {
1.108 raeburn 854: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 855: my (%newvalues,$errors);
1.3 raeburn 856: if (ref($item) eq 'HASH') {
857: if (ref($changes) eq 'HASH') {
858: my @ordered;
859: if ($action eq 'other') {
860: @ordered = &get_other_items($cdom,$values,$allitems);
861: if ($env{'form.newp_name'} ne '') {
862: my $newp = $env{'form.newp_name'};
863: if ($env{'form.newp_value'} ne '') {
864: if (ref($allitems) eq 'ARRAY') {
865: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
866: (grep(/^\Q$newp\E$/,@{$allitems}))) {
867: $changes->{$newp} = $env{'form.newp_value'};
868: }
869: }
870: }
871: }
1.118 raeburn 872: } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.99 raeburn 873: if (ref($values->{$action}) eq 'HASH') {
874: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 875: if ($id =~ /^\d+$/) {
876: push(@ordered,$id);
877: }
878: }
879: }
880: @ordered = sort { $a <=> $b } @ordered;
1.118 raeburn 881: if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
882: push(@ordered,$env{'form.'.$action.'_maxnum'});
1.93 raeburn 883: }
1.3 raeburn 884: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 885: if ($action eq 'courseinfo') {
886: my ($can_toggle_cat,$can_categorize) =
887: &can_modify_catsettings($cdom,$crstype);
888: foreach my $entry (@{$item->{'ordered'}}) {
889: next if (($entry eq 'hidefromcat') &&
890: (!$can_toggle_cat));
891: next if (($entry eq 'categories') &&
892: (!$can_categorize));
893: next if (($entry eq 'loncaparev') ||
1.63 raeburn 894: ($entry eq 'owner') ||
1.88 raeburn 895: ($entry eq 'clonedfrom') ||
896: ($entry eq 'syllabus'));
1.49 raeburn 897: push(@ordered,$entry);
898: }
1.55 raeburn 899: } elsif ($action eq 'classlists') {
900: foreach my $entry (@{$item->{'ordered'}}) {
901: next if ($entry eq 'defaultcredits');
902: push(@ordered,$entry);
903: }
1.49 raeburn 904: } else {
905: @ordered = @{$item->{'ordered'}};
906: }
1.3 raeburn 907: }
908: if (@ordered > 0) {
909: if ($action eq 'feedback') {
910: foreach my $entry (@ordered) {
911: my $userstr = '';
912: my $total = $env{'form.'.$entry.'_total'};
913: if ($total) {
914: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
915: for (my $i=0; $i<$total; $i++) {
916: unless (grep(/^$i$/,@deletes)) {
917: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
918: &get_sec_str($entry,$i).',';
919: }
920: }
921: } else {
922: $total = 0;
923: }
924: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
925: my $uname = $env{'form.'.$entry.'_uname_'.$total};
926: my $udom = $env{'form.'.$entry.'_udom_'.$total};
927: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
928: $userstr =~ s/,$//;
929: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
930: } else {
931: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
932: }
933: } else {
934: $userstr =~ s/,$//;
935: }
936: $newvalues{$entry} = $userstr;
937: if ($newvalues{$entry} ne $values->{$entry}) {
938: $changes->{$entry} = $newvalues{$entry};
939: }
940: my $ext_entry = $entry.'.text';
941: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
942: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
943: $changes->{$ext_entry} = $newvalues{$ext_entry};
944: }
945: }
1.91 raeburn 946: } elsif ($action eq 'menuitems') {
947: my (%current,@colls);
948: my $next = 1;
949: if ($values->{'menucollections'}) {
950: foreach my $item (split(/;/,$values->{'menucollections'})) {
951: my ($num,$value) = split(/\%/,$item);
952: if ($num =~ /^\d+$/) {
953: unless (grep(/^$num$/,@colls)) {
954: push(@colls,$num);
955: }
956: my @entries = split(/\&/,$value);
957: foreach my $entry (@entries) {
958: my ($name,$fields) = split(/=/,$entry);
959: $current{$num}{$name} = $fields;
960: }
961: }
962: }
963: }
964: if (@colls) {
965: @colls = sort { $a <=> $b } @colls;
966: $next += $colls[-1];
967: }
968: if ($env{'form.menucollections_add'} eq $next) {
969: push(@colls,$next);
970: }
971: my $currdef = $values->{'menudefault'};
972: my $possdef = $env{'form.menudefault'};
973: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 974: if ($currdef ne $possdef) {
1.91 raeburn 975: $changes->{'menudefault'} = $possdef;
976: }
1.92 raeburn 977: } elsif ($currdef) {
1.91 raeburn 978: $changes->{'menudefault'} = '';
979: }
980: my $menucoll;
981: if (@colls) {
982: my ($ordered,$cats) = &menuitems_categories();
983: my %shortcats = &menuitems_abbreviations();
984: foreach my $num (@colls) {
985: my ($entry,%include);
986: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
987: foreach my $item (@{$ordered}) {
988: if ($item eq 'shown') {
989: foreach my $type (@{$cats->{$item}}) {
990: $entry .= $type.'=';
991: if ($include{$type}) {
992: $entry .= 'y';
993: } else {
994: $entry .= 'n';
995: }
996: $entry .= '&';
997: }
998: } else {
999: $entry .= $shortcats{$item}.'=';
1000: foreach my $type (@{$cats->{$item}}) {
1001: if ($include{$type}) {
1002: $entry .= $type.',';
1003: }
1004: }
1005: $entry =~ s/,$//;
1006: $entry .= '&';
1007: }
1008: }
1009: $entry =~ s/\&$//;
1010: if ($menucoll) {
1011: $menucoll .= ';';
1012: }
1013: $menucoll .= $num.'%'.$entry;
1014: }
1015: if ($menucoll ne $values->{'menucollections'}) {
1016: $changes->{'menucollections'} = $menucoll;
1017: }
1018: } elsif ($values->{'menucollections'}) {
1019: $changes->{'menucollections'} = '';
1020: }
1.102 raeburn 1021: } elsif ($action eq 'linkprot') {
1022: if (ref($values) eq 'HASH') {
1.108 raeburn 1023: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 1024: }
1.118 raeburn 1025: } elsif ($action eq 'ltitools') {
1026: if (ref($values) eq 'HASH') {
1027: my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1028: $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1029: 'ok','','ok');
1030: }
1.3 raeburn 1031: } else {
1032: foreach my $entry (@ordered) {
1033: if ($entry eq 'cloners') {
1034: if ($env{'form.cloners_all'}) {
1035: $newvalues{$entry} = '*';
1036: } else {
1037: my @clonedoms;
1038: if (exists($env{'form.cloners_activate'})) {
1039: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1040: if ($actnum ne '-1') {
1.33 raeburn 1041: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1042: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1043: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1044: $newvalues{$entry} = '*:'.$clonedom;
1045: push(@clonedoms,$newvalues{$entry});
1046: }
1047: }
1048: }
1049: } else {
1050: my $num = $env{'form.cloners_total'};
1051: my @deletes =
1052: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1053: for (my $i=0; $i<$num; $i++) {
1054: if (!grep(/^$i$/,@deletes)) {
1055: my $clonedom = $env{'form.cloners_dom_'.$i};
1056: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1057: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1058: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1059: }
1060: }
1061: }
1062: }
1063: if (@clonedoms) {
1064: $newvalues{$entry}=join(',',@clonedoms);
1065: }
1066: }
1067: if ($env{'form.cloners_newdom'} ne '') {
1068: my $clonedom = $env{'form.cloners_newdom'};
1069: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1070: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1071: if (@clonedoms) {
1.3 raeburn 1072: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1073: $newvalues{$entry} .= ','.$newdom;
1074: }
1075: } else {
1076: $newvalues{$entry} = $newdom;
1077: }
1078: }
1079: }
1080: if ($env{'form.'.$entry} ne '') {
1081: my @cloners = split(',',$env{'form.'.$entry});
1082: my @okcloners;
1083: foreach my $cloner (@cloners) {
1.23 raeburn 1084: $cloner =~ s/^\s+//;
1085: $cloner =~ s/\s+$//;
1086: unless ($cloner eq '') {
1087: my ($uname,$udom) = split(':',$cloner);
1088: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1089: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1090: push(@okcloners,$cloner);
1091: }
1.3 raeburn 1092: }
1093: }
1094: }
1095: if (@okcloners) {
1096: my $okclonestr = join(',',@okcloners);
1097: if ($newvalues{$entry} ne '') {
1098: $newvalues{$entry} .= ','.$okclonestr;
1099: } else {
1100: $newvalues{$entry} = $okclonestr;
1101: }
1102: }
1103: }
1.71 raeburn 1104: if (ref($values) eq 'HASH') {
1105: my (@code_order,%codedefaults);
1106: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1107: \@code_order);
1108: my $clonebycode;
1109: if ($env{'form.cloners_instcode'}) {
1110: if (@code_order > 0) {
1111: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1112: my %local_to_standard;
1113: for (my $i=0; $i<@code_order; $i++) {
1114: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1115: }
1116: foreach my $item (@code_order) {
1117: my $key = $local_to_standard{$item};
1118: if ($key ne '') {
1119: if ($env{'form.'.$key}) {
1120: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1121: }
1122: }
1123: }
1124: $clonebycode =~ s/\&$//;
1125: }
1126: }
1127: if ($clonebycode) {
1128: if ($newvalues{$entry}) {
1129: $newvalues{$entry} .= ','.$clonebycode;
1130: } else {
1131: $newvalues{$entry} = $clonebycode;
1132: }
1133: }
1134: }
1.3 raeburn 1135: }
1136: if (ref($disallowed) eq 'HASH') {
1137: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1138: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1139: $disallowed->{'cloners'}{$key} =~ s/,$//;
1140: }
1141: }
1142: }
1.25 raeburn 1143: } elsif ($entry eq 'co-owners') {
1144: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1145: my $coowners = $values->{'internal.co-owners'};
1146: my @currcoown;
1147: if ($coowners) {
1148: @currcoown = split(',',$coowners);
1149: }
1150: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1151: my $autocoowner;
1152: if (($crstype eq 'Course') &&
1153: ($values->{'internal.coursecode'})) {
1154: my %domconf =
1155: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1156: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1157: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1158: }
1159: }
1.96 raeburn 1160: if ($autocoowner) {
1161: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1162: } else {
1.25 raeburn 1163: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1164: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1165: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1166: if (@invitecoowners) {
1167: push(@pendingcoowners,@invitecoowners);
1168: }
1169: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1170: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1171: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1172: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1173: push(@{$changes->{$entry}{'changed'}},'co-owners');
1174: }
1175: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1176: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1177: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1178: }
1179: }
1180: } else {
1181: my (@newpending,@newcoown);
1182: my $uname = $env{'user.name'};
1183: my $udom = $env{'user.domain'};
1184: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1185: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1186: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1187: foreach my $item (@pendingcoown) {
1188: unless ($item eq $uname.':'.$udom) {
1189: push(@newpending,$item);
1190: }
1191: }
1192: @newcoown = @currcoown;
1.90 raeburn 1193: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1194: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1195: push(@newcoown,$uname.':'.$udom);
1196: }
1197: }
1.90 raeburn 1198: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1199: foreach my $item (@currcoown) {
1200: unless ($item eq $uname.':'.$udom) {
1201: push(@newcoown,$item);
1202: }
1203: }
1204: if ($pendingcoowners ne '') {
1205: @newpending = @pendingcoown;
1206: }
1.96 raeburn 1207: } else {
1208: @newcoown = @currcoown;
1.25 raeburn 1209: }
1210: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1211: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1212: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1213: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1214: push(@{$changes->{$entry}{'changed'}},'co-owners');
1215: }
1216: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1217: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1218: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1219: }
1220: }
1.3 raeburn 1221: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1222: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1223: } elsif ($entry eq 'rolenames') {
1224: my %adv_roles =
1225: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1226: my @stds;
1227: if ($crstype eq 'Community') {
1228: @stds = ('co');
1229: } else {
1230: @stds = ('cc');
1231: }
1232: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1233: my (@replacements,@regulars);
1234: foreach my $role (@stds) {
1235: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1236: push(@replacements,$role);
1.3 raeburn 1237: } else {
1238: push(@regulars,$role);
1239: }
1.9 raeburn 1240: }
1.3 raeburn 1241: foreach my $stdrole (@stds) {
1242: my $ext_entry = $entry.'_'.$stdrole;
1243: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1244: $env{'request.course.id'},1);
1245: if ($env{'form.'.$ext_entry} eq $stdname) {
1246: $newvalues{$ext_entry} = '';
1247: } else {
1248: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1249: }
1250: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1251: my $dupname = 0;
1252: if ($newvalues{$ext_entry} ne '') {
1253: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1254: $dupname = 1;
1255: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1256: }
1257: if (!$dupname) {
1258: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1259: $dupname = 1;
1260: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1261: }
1262: }
1263: if (!$dupname) {
1264: foreach my $role (keys(%adv_roles)) {
1265: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1266: $dupname = 1;
1267: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1268: last;
1269: }
1270: }
1271: }
1272: }
1273: if (!$dupname) {
1274: $changes->{$ext_entry} = $newvalues{$ext_entry};
1275: }
1276: }
1277: }
1.77 raeburn 1278: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1279: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1280: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1281: @denied = sort(@denied);
1282: my $deniedstr = '';
1283: if (@denied > 0) {
1284: $deniedstr = join(',',@denied);
1285: }
1286: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1287: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1288: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1289: my $total = $env{'form.'.$entry.'_total'};
1290: my $userstr = '';
1291: my @denied;
1292: if ($total > 0) {
1293: my @deletes =
1294: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1295: for (my $i=0; $i<$total; $i++) {
1296: unless (grep(/^$i$/,@deletes)) {
1297: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1298: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1299: }
1300: }
1301: } else {
1302: $total = 0;
1303: }
1304: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1305: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1306: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1307: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1308: $userstr =~ s/,$//;
1309: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1310: } else {
1311: my $newuser .= $uname.':'.$udom;
1312: if (grep(/^\Q$newuser\E$/,@denied)) {
1313: $userstr =~ s/,$//;
1314: } else {
1315: $userstr .= $newuser;
1316: }
1317: }
1318: } else {
1319: $userstr =~ s/,$//;
1320: }
1321: $newvalues{$entry} = $userstr;
1322: } elsif ($entry eq 'allow_discussion_post_editing') {
1323: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1324: @canedit = sort(@canedit);
1325: foreach my $role (@canedit) {
1326: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1327: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1328: $newvalues{$entry} .= $role.',';
1329: } else {
1330: foreach my $sec (@secs) {
1331: $newvalues{$entry} .= $role.':'.$sec.',';
1332: }
1333: }
1334: }
1335: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1336: } elsif ($entry eq 'discussion_post_fonts') {
1337: my ($classorder,$classtitles) = &discussion_vote_classes();
1338: my $fontchange = 0;
1339: foreach my $class (@{$classorder}) {
1340: my $ext_entry = $entry.'_'.$class;
1341: my $size = $env{'form.'.$ext_entry.'_size'};
1342: my $unit = $env{'form.'.$ext_entry.'_unit'};
1343: my $weight = $env{'form.'.$ext_entry.'_weight'};
1344: my $style = $env{'form.'.$ext_entry.'_style'};
1345: my $other = $env{'form.'.$ext_entry.'_other'};
1346: $size =~ s/,//g;
1347: $unit =~ s/,//g;
1348: $weight =~ s/,//g;
1349: $style =~ s/,//g;
1350: $other =~ s/[^\w;:\s\-\%.]//g;
1351: $other =~ s/(^\s+|\s+$)//g;
1352: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1353: my $current = $values->{$ext_entry};
1354: if ($values->{$ext_entry} eq '') {
1355: $current = ',,,';
1356: }
1357: if ($newvalues{$ext_entry} ne $current) {
1358: $changes->{$ext_entry} = $newvalues{$ext_entry};
1359: $fontchange ++;
1360: }
1361: }
1362: if ($fontchange) {
1363: $changes->{$entry} = 1;
1364: }
1.3 raeburn 1365: } elsif ($entry eq 'nothideprivileged') {
1366: my @curr_nothide;
1367: my @new_nothide;
1368: if ($values->{$entry} ne '') {
1369: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1370: my $nothide;
1371: if ($user !~ /:/) {
1372: $nothide = join(':',split(/[\@]/,$user));
1373: } else {
1374: $nothide = $user;
1375: }
1376: if ((defined($nothide)) &&
1377: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1378: push(@curr_nothide,$nothide);
1379: }
1380: }
1381: }
1382: foreach my $key (keys(%env)) {
1383: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1384: if ($env{$key}) {
1.3 raeburn 1385: my $nothide = $1;
1386: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1387: push(@new_nothide,$nothide);
1388: }
1389: }
1390: }
1391: }
1392: @new_nothide = sort(@new_nothide);
1393: my @differences =
1394: &Apache::loncommon::compare_arrays(\@curr_nothide,
1395: \@new_nothide);
1396: if (@differences > 0) {
1397: if (@new_nothide > 0) {
1398: $newvalues{$entry} = join(',',@new_nothide);
1399: } else {
1400: $newvalues{$entry} = '';
1401: }
1402: } else {
1403: $newvalues{$entry} = $values->{$entry};
1404: }
1405: } elsif ($entry eq 'print_header_format') {
1406: my $maxnum = $env{'form.printfmthdr_maxnum'};
1407: my @newhdr;
1408: if ($maxnum > 2) {
1409: for (my $i=0; $i<$maxnum-2; $i++) {
1410: if ($env{'form.printfmthdr_del_'.$i}) {
1411: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1412: } else {
1413: my $hdr;
1414: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1415: $hdr = '%';
1416: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1417: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1418: }
1419: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1420: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1421: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1422: }
1423: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1424: }
1425: }
1426: }
1427: my $newsub = $maxnum-2;
1428: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1429: my $hdr = '%';
1430: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1431: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1432: }
1433: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1434: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1435: }
1436: my $newtext = $maxnum-1;
1437: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1438: $newvalues{$entry} = join('',@newhdr);
1.56 raeburn 1439: } elsif (($entry eq 'languages') ||
1440: ($entry eq 'checkforpriv')) {
1441: my $settings;
1.3 raeburn 1442: my $total = $env{'form.'.$entry.'_total'};
1443: if ($total) {
1444: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1445: for (my $i=0; $i<$total; $i++) {
1446: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1447: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1448: }
1449: }
1450: } else {
1451: $total = 0;
1452: }
1453: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1454: my $new = $env{'form.'.$entry.'_'.$total};
1455: if ($entry eq 'languages') {
1456: my %langchoices = &get_lang_choices();
1457: if ($langchoices{$new}) {
1458: $settings .= $new;
1459: } else {
1460: $settings =~ s/,$//;
1461: $disallowed->{'localization'}{$entry} = $new;
1462: }
1.3 raeburn 1463: } else {
1.56 raeburn 1464: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1465: if ($domains{$new}) {
1466: $settings .= $new;
1467: } else {
1468: $settings =~ s/,$//;
1469: $disallowed->{'classlists'}{$entry} = $new;
1470: }
1.3 raeburn 1471: }
1472: } else {
1.56 raeburn 1473: $settings =~ s/,$//;
1.3 raeburn 1474: }
1.56 raeburn 1475: $newvalues{$entry} = $settings;
1.87 raeburn 1476: } elsif ($action eq 'lti') {
1477: if ($entry eq 'lti.override') {
1478: $newvalues{$entry} = $env{'form.'.$entry};
1479: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1480: if ($env{'form.lti.override'}) {
1481: $newvalues{$entry} = $env{'form.'.$entry};
1482: } else {
1483: $newvalues{$entry} = '';
1484: }
1485: } elsif ($entry eq 'lti.lcmenu') {
1486: if (($env{'form.lti.override'}) &&
1487: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1488: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1489: my @newlcmenu;
1490: if (@lcmenu) {
1491: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1492: foreach my $item (@menuitems) {
1493: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1494: if (grep(/^\Q$item\E$/,@lcmenu)) {
1495: push(@newlcmenu,$item);
1496: }
1497: }
1498: }
1499: if (@newlcmenu) {
1500: $newvalues{$entry} = join(',',@newlcmenu);
1501: } else {
1502: $newvalues{$entry} = 'none';
1503: }
1504: } else {
1505: $newvalues{$entry} = '';
1506: }
1507: }
1.114 raeburn 1508: } elsif ($entry eq 'extresource') {
1509: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1510: $newvalues{$entry} = $env{'form.'.$entry};
1511: if ($env{'form.'.$entry} ne 'iframe') {
1512: if ($env{'form.extwintabreuse'}) {
1513: $newvalues{$entry} .= ':1';
1514: } else {
1515: $newvalues{$entry} .= ':0';
1516: }
1517: if ($env{'form.'.$entry} eq 'window') {
1518: foreach my $dim ('width','height') {
1519: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1520: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1521: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1522: } else {
1523: $newvalues{$entry} .= ':';
1524: }
1525: }
1526: }
1527: }
1528: }
1529: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1530: if ($newvalues{$entry} ne $values->{$entry}) {
1531: $changes->{$entry} = $newvalues{$entry};
1532: }
1533: }
1.115 raeburn 1534: } elsif ($entry eq 'timezone') {
1535: if ($env{'form.'.$entry}) {
1536: $newvalues{$entry} = $env{'form.'.$entry};
1537: if ($newvalues{$entry} ne $values->{$entry}) {
1538: $changes->{$entry} = $newvalues{$entry};
1539: }
1540: if ($env{'form.tzover'}) {
1541: $newvalues{'tzover'} = $env{'form.tzover'};
1542: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1543: $changes->{'tzover'} = $newvalues{'tzover'};
1544: }
1545: } elsif ($values->{'tzover'}) {
1546: $changes->{'tzover'} = '';
1547: }
1548: } elsif ($values->{$entry}) {
1549: $changes->{$entry} = '';
1550: }
1.3 raeburn 1551: } else {
1552: $newvalues{$entry} = $env{'form.'.$entry};
1553: }
1.115 raeburn 1554: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1555: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1556: if ($newvalues{$entry} ne $values->{$entry}) {
1557: $changes->{$entry} = $newvalues{$entry};
1558: }
1.3 raeburn 1559: }
1560: }
1561: }
1562: }
1563: }
1564: }
1.93 raeburn 1565: return $errors;
1566: }
1567:
1.102 raeburn 1568: sub process_linkprot {
1.108 raeburn 1569: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.118 raeburn 1570: my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1571: if (ref($values) eq 'HASH') {
1572: foreach my $id (keys(%{$values})) {
1573: if ($id =~ /^\d+$/) {
1574: unless (ref($values->{$id}) eq 'HASH') {
1575: $linkprot{$id} = '';
1576: }
1577: }
1578: }
1579: }
1.118 raeburn 1580: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.102 raeburn 1581: if ($context eq 'domain') {
1582: $dest = '/adm/domainprefs';
1583: $ltiauth = 1;
1584: } else {
1585: $dest = '/adm/courseprefs';
1586: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1587: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1588: } else {
1589: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1590: $ltiauth = $domdefs{'crsltiauth'};
1591: }
1592: }
1593: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1594: my (@items,%deletions,%itemids,%haschanges);
1595: if ($env{'form.linkprot_add'}) {
1596: my $name = $env{'form.linkprot_name_add'};
1597: $name =~ s/(`)/'/g;
1598: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1599: if ($newid) {
1600: $itemids{'add'} = $newid;
1601: push(@items,'add');
1602: $haschanges{$newid} = 1;
1603: } else {
1604: $errors .= '<span class="LC_error">'.
1605: &mt('Failed to acquire unique ID for link protection').
1606: '</span>';
1607: }
1608: }
1609: if (ref($values) eq 'HASH') {
1610: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1611: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1612: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1613: my $itemid = $env{'form.linkprot_id_'.$i};
1614: $itemid =~ s/\D+//g;
1615: if ($itemid) {
1616: if (ref($values->{$itemid}) eq 'HASH') {
1617: push(@items,$i);
1618: $itemids{$i} = $itemid;
1619: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1620: $deletions{$itemid} = $values->{$itemid}->{'name'};
1621: }
1622: }
1623: }
1624: }
1625: }
1626: foreach my $idx (@items) {
1627: my $itemid = $itemids{$idx};
1628: next unless ($itemid);
1629: if (exists($deletions{$itemid})) {
1630: $linkprot{$itemid} = $deletions{$itemid};
1631: $haschanges{$itemid} = 1;
1632: next;
1633: }
1634: my %current;
1635: if (ref($values) eq 'HASH') {
1636: if (ref($values->{$itemid}) eq 'HASH') {
1637: foreach my $key (keys(%{$values->{$itemid}})) {
1638: $current{$key} = $values->{$itemid}->{$key};
1639: }
1640: }
1641: }
1642: foreach my $inner ('name','lifetime','version') {
1643: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1644: $env{$formitem} =~ s/(`)/'/g;
1645: if ($inner eq 'lifetime') {
1646: $env{$formitem} =~ s/[^\d.]//g;
1647: }
1648: unless ($idx eq 'add') {
1649: if ($current{$inner} ne $env{$formitem}) {
1650: $haschanges{$itemid} = 1;
1651: }
1652: }
1653: if ($env{$formitem} ne '') {
1654: $linkprot{$itemid}{$inner} = $env{$formitem};
1655: }
1656: }
1.112 raeburn 1657: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1658: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1659: if ($env{$urlitem} == 1) {
1660: $env{$urlparamname} =~ s/(`)/'/g;
1661: } elsif (exists($env{$urlparamname})) {
1662: $env{$urlparamname} = '';
1663: }
1.122 ! raeburn 1664: my $passback = 'form.linkprot_passback_'.$idx;
! 1665: my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
! 1666: if ($env{$passback} == 1) {
! 1667: unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
! 1668: $env{$passbackparamname} = '';
! 1669: }
! 1670: } elsif (exists($env{$passbackparamname})) {
! 1671: $env{$passbackparamname} = '';
! 1672: }
1.112 raeburn 1673: unless ($idx eq 'add') {
1674: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1675: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1676: $haschanges{$itemid} = 1;
1677: }
1.122 ! raeburn 1678: if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
! 1679: ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
! 1680: $haschanges{$itemid} = 1;
! 1681: }
1.112 raeburn 1682: }
1.122 ! raeburn 1683: if ($env{$passbackparamname} ne '') {
! 1684: $linkprot{$itemid}{'passback'} = 1;
! 1685: $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1.112 raeburn 1686: }
1.102 raeburn 1687: if ($ltiauth) {
1688: my $reqitem = 'form.linkprot_requser_'.$idx;
1689: $env{$reqitem} =~ s/(`)/'/g;
1690: unless ($idx eq 'add') {
1.104 raeburn 1691: if ((!$current{'requser'} && $env{$reqitem}) ||
1692: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1693: $haschanges{$itemid} = 1;
1694: }
1695: }
1696: if ($env{$reqitem} == 1) {
1697: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1698: foreach my $inner ('mapuser','notstudent') {
1699: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1700: $env{$formitem} =~ s/(`)/'/g;
1701: if ($inner eq 'mapuser') {
1702: if ($env{$formitem} eq 'other') {
1703: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1704: $mapuser =~ s/(`)/'/g;
1705: $mapuser =~ s/^\s+|\s+$//g;
1706: if ($mapuser ne '') {
1707: $linkprot{$itemid}{$inner} = $mapuser;
1708: } else {
1709: delete($linkprot{$itemid}{'requser'});
1710: last;
1711: }
1712: } elsif ($env{$formitem} eq 'sourcedid') {
1713: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1714: } elsif ($env{$formitem} eq 'email') {
1715: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1716: }
1717: } else {
1718: $linkprot{$itemid}{$inner} = $env{$formitem};
1719: }
1720: unless ($idx eq 'add') {
1721: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1722: $haschanges{$itemid} = 1;
1723: }
1724: }
1725: }
1726: }
1727: }
1728: unless ($switchserver) {
1729: my $keyitem = 'form.linkprot_key_'.$idx;
1730: $env{$keyitem} =~ s/(`)/'/g;
1731: unless ($idx eq 'add') {
1732: if ($current{'key'} ne $env{$keyitem}) {
1733: $haschanges{$itemid} = 1;
1734: }
1735: }
1736: if ($env{$keyitem} ne '') {
1737: $linkprot{$itemid}{'key'} = $env{$keyitem};
1738: }
1739: my $secretitem = 'form.linkprot_secret_'.$idx;
1740: $env{$secretitem} =~ s/(`)/'/g;
1741: if ($current{'usable'}) {
1742: if ($env{'form.linkprot_changesecret_'.$idx}) {
1743: if ($env{$secretitem} ne '') {
1.103 raeburn 1744: if ($privnum && $cipher) {
1745: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1746: $linkprot{$itemid}{'cipher'} = $privnum;
1747: } else {
1748: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1749: }
1.102 raeburn 1750: $haschanges{$itemid} = 1;
1751: }
1752: } else {
1753: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1754: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1755: }
1756: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1757: if ($privnum && $cipher) {
1758: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1759: $linkprot{$itemid}{'cipher'} = $privnum;
1760: } else {
1761: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1762: }
1.102 raeburn 1763: $haschanges{$itemid} = 1;
1764: }
1765: }
1766: }
1767: if (keys(%haschanges)) {
1768: foreach my $entry (keys(%haschanges)) {
1769: $changes->{$entry} = $linkprot{$entry};
1770: }
1.108 raeburn 1771: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1772: $lastactref->{'courselti'} = 1;
1.108 raeburn 1773: }
1.102 raeburn 1774: }
1775: return $errors;
1776: }
1777:
1778: sub get_linkprot_id {
1779: my ($cdom,$cnum,$name,$context) = @_;
1780: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1781: my $lockhash = {
1782: lock => $env{'user.name'}.
1783: ':'.$env{'user.domain'},
1784: };
1785: my $tries = 0;
1.102 raeburn 1786: my $gotlock;
1787: if ($context eq 'domain') {
1788: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1789: } else {
1790: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1791: }
1.93 raeburn 1792: my ($id,$error);
1793: while (($gotlock ne 'ok') && ($tries<10)) {
1794: $tries ++;
1795: sleep (0.1);
1.102 raeburn 1796: if ($context eq 'domain') {
1797: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1798: } else {
1799: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1800: }
1.93 raeburn 1801: }
1802: if ($gotlock eq 'ok') {
1.102 raeburn 1803: my %currids;
1804: if ($context eq 'domain') {
1805: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1806: } else {
1807: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1808: }
1.93 raeburn 1809: if ($currids{'lock'}) {
1810: delete($currids{'lock'});
1811: if (keys(%currids)) {
1812: my @curr = sort { $a <=> $b } keys(%currids);
1813: if ($curr[-1] =~ /^\d+$/) {
1814: $id = 1 + $curr[-1];
1815: } else {
1816: $id = 1;
1817: }
1818: } else {
1819: $id = 1;
1820: }
1821: if ($id) {
1.102 raeburn 1822: if ($context eq 'domain') {
1823: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1824: $error = 'nostore';
1825: }
1826: } else {
1827: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1828: $error = 'nostore';
1829: }
1.93 raeburn 1830: }
1831: } else {
1832: $error = 'nonumber';
1833: }
1834: }
1.102 raeburn 1835: my $dellockoutcome;
1836: if ($context eq 'domain') {
1837: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1838: } else {
1839: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1840: }
1.93 raeburn 1841: } else {
1842: $error = 'nolock';
1843: }
1844: return ($id,$error);
1.3 raeburn 1845: }
1846:
1.118 raeburn 1847: sub get_credentials {
1848: my ($cdom,$cnum,$type,$context) = @_;
1849: my ($cipher,$privnum,$home);
1850: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1851: my @ids=&Apache::lonnet::current_machine_ids();
1852: if ($context eq 'domain') {
1853: $home = &Apache::lonnet::domain($cdom,'primary');
1854: } else {
1855: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1856: }
1857: my ($hostskey,$domkey,$crskey);
1858: if ($type eq 'ltitools') {
1859: $hostskey = 'toolprivhosts';
1860: $domkey = 'toolenc_dom';
1861: $crskey = 'toolenc_crs';
1862: } else {
1863: $hostskey = 'ltiprivhosts';
1864: $domkey = 'linkprotenc_dom';
1865: $crskey = 'linkprotenc_crs';
1866: }
1867: if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1868: (($context eq 'course') && ($domdefs{$crskey}))) {
1869: unless (($home eq 'no_host') || ($home eq '')) {
1870: if (grep(/^\Q$home\E$/,@ids)) {
1871: if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1872: if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1873: my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1874: my $privkey = $privhash{'key'};
1875: $privnum = $privhash{'version'};
1876: if (($privnum) && ($privkey ne '')) {
1877: $cipher = Crypt::CBC->new({'key' => $privkey,
1878: 'cipher' => 'DES'});
1879: }
1880: }
1881: }
1882: }
1883: }
1884: }
1885: return ($cipher,$privnum);
1886: }
1887:
1888: sub process_ltitools {
1889: my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1890: $author_ok,$confname) = @_;
1891: my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1892:
1893: my (%posslti,%possfield);
1894: my @courseroles = ('cc','in','ta','ep','st');
1895: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1896: map { $posslti{$_} = 1; } @ltiroles;
1897: my @allfields = ('fullname','firstname','lastname','email','user','roles');
1898: map { $possfield{$_} = 1; } @allfields;
1899:
1.120 raeburn 1900: my ($dest,$privnum,$cipher);
1.118 raeburn 1901:
1902: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1903: if ($context eq 'domain') {
1904: $dest = '/adm/domainprefs';
1905: } else {
1906: $dest = '/adm/courseprefs';
1907: }
1908: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1909:
1910: my (@allpos,@items,%deletions,%itemids,%haschanges);
1911: if ($env{'form.ltitools_add'}) {
1912: my $title = $env{'form.ltitools_add_title'};
1913: $title =~ s/(`)/'/g;
1914: my ($newid,$error) = &get_ltitools_id($context,$cdom,$cnum,$title);
1915: if ($newid) {
1916: my $position = $env{'form.ltitools_add_pos'};
1917: $position =~ s/\D+//g;
1918: if ($position ne '') {
1919: $allpos[$position] = $newid;
1920: }
1921: $haschanges{$newid} = 1;
1922: foreach my $item ('title','url','lifetime') {
1923: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1924: if ($item eq 'lifetime') {
1925: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1926: }
1927: if ($env{'form.ltitools_add_'.$item}) {
1928: $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1929: }
1930: }
1931: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1932: $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1933: }
1934: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1935: $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1936: }
1937: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1938: $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1939: } else {
1940: $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1941: }
1942: foreach my $item ('width','height','linktext','explanation') {
1943: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1944: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1945: if (($item eq 'width') || ($item eq 'height')) {
1946: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1947: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1948: }
1949: } else {
1950: if ($env{'form.ltitools_add_'.$item} ne '') {
1951: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1952: }
1953: }
1954: }
1955: if ($env{'form.ltitools_add_target'} eq 'window') {
1956: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1957: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1958: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1959: } else {
1960: $ltitools{$newid}{'display'}{'target'} = 'iframe';
1961: }
1962: foreach my $item ('passback','roster') {
1963: if ($env{'form.ltitools_'.$item.'_add'}) {
1964: $ltitools{$newid}{$item} = 1;
1965: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1966: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1967: $lifetime =~ s/^\s+|\s+$//g;
1968: if ($lifetime =~ /^\d+\.?\d*$/) {
1969: $ltitools{$newid}{$item.'valid'} = $lifetime;
1970: }
1971: }
1972: }
1973: }
1974: if ($env{'form.ltitools_add_image.filename'} ne '') {
1975: my ($imageurl,$error) =
1976: &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
1977: $newid,$configuserok,$lonhost,$author_ok);
1978: if ($imageurl) {
1979: $ltitools{$newid}{'image'} = $imageurl;
1980: }
1981: if ($error) {
1982: &Apache::lonnet::logthis($error);
1983: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1984: }
1985: }
1986: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
1987: foreach my $field (@fields) {
1988: if ($possfield{$field}) {
1989: if ($field eq 'roles') {
1990: foreach my $role (@courseroles) {
1991: my $choice = $env{'form.ltitools_add_roles_'.$role};
1992: if (($choice ne '') && ($posslti{$choice})) {
1993: $ltitools{$newid}{'roles'}{$role} = $choice;
1994: if ($role eq 'cc') {
1995: $ltitools{$newid}{'roles'}{'co'} = $choice;
1996: }
1997: }
1998: }
1999: } else {
2000: $ltitools{$newid}{'fields'}{$field} = 1;
2001: }
2002: }
2003: }
2004: if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
2005: if ($ltitools{$newid}{'fields'}{'user'}) {
2006: if ($env{'form.ltitools_add_userincdom'}) {
2007: $ltitools{$newid}{'incdom'} = 1;
2008: }
2009: }
2010: }
2011: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
2012: foreach my $item (@courseconfig) {
2013: $ltitools{$newid}{'crsconf'}{$item} = 1;
2014: }
2015: if ($env{'form.ltitools_add_custom'}) {
2016: my $name = $env{'form.ltitools_add_custom_name'};
2017: my $value = $env{'form.ltitools_add_custom_value'};
2018: $value =~ s/(`)/'/g;
2019: $name =~ s/(`)/'/g;
2020: $ltitools{$newid}{'custom'}{$name} = $value;
2021: }
2022: unless ($switchserver) {
2023: my $keyitem = 'form.ltitools_add_key';
2024: $env{$keyitem} =~ s/(`)/'/g;
2025: if ($env{$keyitem} ne '') {
2026: $ltitools{$newid}{'key'} = $env{$keyitem};
2027: }
1.119 raeburn 2028: my $secretitem = 'form.ltitools_secret_add';
1.118 raeburn 2029: $env{$secretitem} =~ s/(`)/'/g;
2030: if ($env{$secretitem} ne '') {
2031: if ($privnum && $cipher) {
2032: $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2033: $ltitools{$newid}{'cipher'} = $privnum;
2034: } else {
2035: $ltitools{$newid}{'secret'} = $env{$secretitem};
2036: }
2037: }
2038: }
2039: } else {
2040: $errors .= '<li><span class="LC_error">'.
2041: &mt('Failed to acquire unique ID for new external tool').
2042: '</span></li>';
2043: }
2044: }
2045: if (ref($values) eq 'HASH') {
2046: my %deletions;
2047: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2048: if (@todelete) {
2049: map { $deletions{$_} = 1; } @todelete;
2050: }
2051: my %customadds;
2052: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2053: if (@newcustom) {
2054: map { $customadds{$_} = 1; } @newcustom;
2055: }
2056: my %imgdeletions;
2057: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2058: if (@todeleteimages) {
2059: map { $imgdeletions{$_} = 1; } @todeleteimages;
2060: }
2061: my $maxnum = $env{'form.ltitools_maxnum'};
2062: for (my $i=0; $i<=$maxnum; $i++) {
2063: my $itemid = $env{'form.ltitools_id_'.$i};
2064: $itemid =~ s/\D+//g;
2065: if (ref($values->{$itemid}) eq 'HASH') {
2066: if ($deletions{$itemid}) {
2067: if ($values->{$itemid}{'image'}) {
2068: #FIXME need to obsolete item in RES space
2069: }
2070: $haschanges{$itemid} = $values->{$itemid}{'title'};
2071: next;
2072: } else {
2073: my $newpos = $env{'form.ltitools_'.$itemid};
2074: $newpos =~ s/\D+//g;
2075: foreach my $item ('title','url','lifetime') {
2076: $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2077: if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2078: $haschanges{$itemid} = 1;
2079: }
2080: }
2081: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2082: $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2083: }
2084: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2085: $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2086: }
2087: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2088: $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2089: } else {
2090: $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2091: }
2092: if ($values->{$itemid}{'sigmethod'} eq '') {
2093: if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2094: $haschanges{$itemid} = 1;
2095: }
2096: } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2097: $haschanges{$itemid} = 1;
2098: }
2099: foreach my $size ('width','height') {
2100: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2101: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2102: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2103: $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2104: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2105: if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2106: $haschanges{$itemid} = 1;
2107: }
2108: } else {
2109: $haschanges{$itemid} = 1;
2110: }
2111: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2112: if ($values->{$itemid}{'display'}{$size} ne '') {
2113: $haschanges{$itemid} = 1;
2114: }
2115: }
2116: }
2117: foreach my $item ('linktext','explanation') {
2118: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2119: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2120: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2121: $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2122: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2123: if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2124: $haschanges{$itemid} = 1;
2125: }
2126: } else {
2127: $haschanges{$itemid} = 1;
2128: }
2129: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2130: if ($values->{$itemid}{'display'}{$item} ne '') {
2131: $haschanges{$itemid} = 1;
2132: }
2133: }
2134: }
2135: if ($env{'form.ltitools_target_'.$i} eq 'window') {
2136: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2137: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2138: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2139: } else {
2140: $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2141: }
2142: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2143: if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2144: $haschanges{$itemid} = 1;
2145: }
2146: } else {
2147: $haschanges{$itemid} = 1;
2148: }
2149: foreach my $extra ('passback','roster') {
2150: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2151: $ltitools{$itemid}{$extra} = 1;
2152: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2153: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2154: $lifetime =~ s/^\s+|\s+$//g;
2155: if ($lifetime =~ /^\d+\.?\d*$/) {
2156: $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2157: }
2158: }
2159: }
2160: if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2161: $haschanges{$itemid} = 1;
2162: }
2163: if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2164: $haschanges{$itemid} = 1;
2165: }
2166: }
2167: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2168: foreach my $item ('label','title','target','linktext','explanation','append') {
2169: if (grep(/^\Q$item\E$/,@courseconfig)) {
2170: $ltitools{$itemid}{'crsconf'}{$item} = 1;
2171: if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2172: if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2173: $haschanges{$itemid} = 1;
2174: }
2175: } else {
2176: $haschanges{$itemid} = 1;
2177: }
2178: }
2179: }
2180: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2181: foreach my $field (@fields) {
2182: if ($possfield{$field}) {
2183: if ($field eq 'roles') {
2184: foreach my $role (@courseroles) {
2185: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2186: if (($choice ne '') && ($posslti{$choice})) {
2187: $ltitools{$itemid}{'roles'}{$role} = $choice;
2188: if ($role eq 'cc') {
2189: $ltitools{$itemid}{'roles'}{'co'} = $choice;
2190: }
2191: }
2192: if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2193: if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2194: $haschanges{$itemid} = 1;
2195: }
2196: } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2197: $haschanges{$itemid} = 1;
2198: }
2199: }
2200: } else {
2201: $ltitools{$itemid}{'fields'}{$field} = 1;
2202: if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2203: if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2204: $haschanges{$itemid} = 1;
2205: }
2206: } else {
2207: $haschanges{$itemid} = 1;
2208: }
2209: }
2210: }
2211: }
2212: if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2213: if ($ltitools{$itemid}{'fields'}{'user'}) {
2214: if ($env{'form.ltitools_userincdom_'.$i}) {
2215: $ltitools{$itemid}{'incdom'} = 1;
2216: }
2217: if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2218: $haschanges{$itemid} = 1;
2219: }
2220: }
2221: }
2222: $allpos[$newpos] = $itemid;
2223: }
2224: if ($imgdeletions{$itemid}) {
2225: $haschanges{$itemid} = 1;
2226: if ($context eq 'course') {
2227: my $currimgurl = $values->{$itemid}{'image'};
2228: if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2229: my ($path,$imagefile) = ($1,$2);
2230: if ($imagefile =~ /^tn\-(.+)$/) {
2231: my $origimg = $1;
2232: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2233: }
2234: &Apache::lonnet::removeuploadedurl($currimgurl);
2235: }
2236: }
2237: #FIXME need to obsolete item in RES space
2238: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2239: my $currimgurl = $values->{$itemid}{'image'};
2240: my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2241: $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2242: if ($imgurl) {
2243: $ltitools{$itemid}{'image'} = $imgurl;
2244: $haschanges{$itemid} = 1;
2245: }
2246: if ($error) {
2247: &Apache::lonnet::logthis($error);
2248: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2249: }
2250: } elsif ($values->{$itemid}{'image'}) {
2251: $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2252: }
2253: if ($customadds{$i}) {
2254: my $name = $env{'form.ltitools_custom_name_'.$i};
2255: $name =~ s/(`)/'/g;
2256: $name =~ s/^\s+//;
2257: $name =~ s/\s+$//;
2258: my $value = $env{'form.ltitools_custom_value_'.$i};
2259: $value =~ s/(`)/'/g;
2260: $value =~ s/^\s+//;
2261: $value =~ s/\s+$//;
2262: if ($name ne '') {
2263: $ltitools{$itemid}{'custom'}{$name} = $value;
2264: $haschanges{$itemid} = 1;
2265: }
2266: }
2267: my %customdels;
2268: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2269: if (@customdeletions) {
2270: $haschanges{$itemid} = 1;
2271: }
2272: map { $customdels{$_} = 1; } @customdeletions;
2273: if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2274: foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2275: unless ($customdels{$key}) {
2276: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2277: $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2278: }
2279: if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2280: $haschanges{$itemid} = 1;
2281: }
2282: }
2283: }
2284: }
2285: unless ($switchserver) {
2286: my $keyitem = 'form.ltitools_key_'.$i;
2287: $env{$keyitem} =~ s/(`)/'/g;
2288: if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2289: $haschanges{$itemid} = 1;
2290: }
2291: if ($env{$keyitem} ne '') {
2292: $ltitools{$itemid}{'key'} = $env{$keyitem};
2293: }
2294: my $secretitem = 'form.ltitools_secret_'.$i;
2295: $env{$secretitem} =~ s/(`)/'/g;
2296: if ($values->{$itemid}{'usable'}) {
2297: if ($env{'form.ltitools_changesecret_'.$i}) {
2298: if ($env{$secretitem} ne '') {
2299: if ($privnum && $cipher) {
2300: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2301: $ltitools{$itemid}{'cipher'} = $privnum;
2302: } else {
2303: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2304: }
2305: $haschanges{$itemid} = 1;
2306: }
2307: } else {
2308: $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2309: $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2310: }
2311: } elsif ($env{$secretitem} ne '') {
2312: if ($privnum && $cipher) {
2313: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2314: $ltitools{$itemid}{'cipher'} = $privnum;
2315: } else {
2316: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2317: }
2318: $haschanges{$itemid} = 1;
2319: }
2320: }
2321: unless ($haschanges{$itemid}) {
2322: foreach my $key (keys(%{$values->{$itemid}})) {
2323: if (ref($values->{$itemid}{$key}) eq 'HASH') {
2324: if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2325: foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2326: unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2327: $haschanges{$itemid} = 1;
2328: last;
2329: }
2330: }
2331: } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2332: $haschanges{$itemid} = 1;
2333: }
2334: }
2335: last if ($haschanges{$itemid});
2336: }
2337: }
2338: }
2339: }
2340: }
2341: if (@allpos > 0) {
2342: my $idx = 0;
2343: foreach my $itemid (@allpos) {
2344: if ($itemid ne '') {
2345: $ltitools{$itemid}{'order'} = $idx;
2346: if (ref($values) eq 'HASH') {
2347: if (ref($values->{$itemid}) eq 'HASH') {
2348: if ($values->{$itemid}{'order'} ne $idx) {
2349: $haschanges{$itemid} = 1;
2350: }
2351: }
2352: }
2353: $idx ++;
2354: }
2355: }
2356: }
2357: if (keys(%haschanges)) {
2358: foreach my $entry (keys(%haschanges)) {
2359: $changes->{$entry} = $ltitools{$entry};
2360: }
2361: if (ref($lastactref) eq 'HASH') {
2362: $lastactref->{'courseltitools'} = 1;
2363: }
2364: }
2365: return $errors;
2366: }
2367:
2368: sub get_ltitools_id {
2369: my ($context,$cdom,$cnum,$title) = @_;
2370: my ($lockhash,$tries,$gotlock,$id,$error);
2371:
2372: # get lock on ltitools db
2373: $lockhash = {
2374: lock => $env{'user.name'}.
2375: ':'.$env{'user.domain'},
2376: };
2377: $tries = 0;
2378: if ($context eq 'domain') {
2379: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
2380: } else {
2381: $gotlock = &Apache::lonnet::newput('ltitools',$lockhash,$cdom,$cnum);
2382: }
2383: while (($gotlock ne 'ok') && ($tries<10)) {
2384: $tries ++;
2385: sleep (0.1);
2386: if ($context eq 'domain') {
2387: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
2388: } else {
2389: $gotlock = &Apache::lonnet::newput('ltitools',$lockhash,$cdom,$cnum);
2390: }
2391: }
2392: if ($gotlock eq 'ok') {
2393: my %currids;
2394: if ($context eq 'domain') {
2395: %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
2396: } else {
2397: %currids = &Apache::lonnet::dump('ltitools',$cdom,$cnum);
2398: }
2399: if ($currids{'lock'}) {
2400: delete($currids{'lock'});
2401: if (keys(%currids)) {
2402: my @curr = sort { $a <=> $b } keys(%currids);
2403: if ($curr[-1] =~ /^\d+$/) {
2404: $id = 1 + $curr[-1];
2405: }
2406: } else {
2407: $id = 1;
2408: }
2409: if ($id) {
2410: if ($context eq 'domain') {
2411: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
2412: $error = 'nostore';
2413: }
2414: } else {
2415: unless (&Apache::lonnet::newput('ltitools',{ $id => $title },$cdom,$cnum) eq 'ok') {
2416: $error = 'nostore';
2417: }
2418: }
2419: } else {
2420: $error = 'nonumber';
2421: }
2422: }
2423: my $dellockoutcome;
2424: if ($context eq 'domain') {
2425: $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
2426: } else {
2427: $dellockoutcome = &Apache::lonnet::del('ltitools',['lock'],$cdom,$cnum);
2428: }
2429: } else {
2430: $error = 'nolock';
2431: }
2432: return ($id,$error);
2433: }
2434:
2435: sub process_ltitools_image {
2436: my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2437: my $filename = $env{'form.'.$caller.'.filename'};
2438: my ($error,$url);
2439: my ($width,$height) = (21,21);
2440: if ($configuserok eq 'ok') {
2441: if ($switch) {
2442: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2443: $switch);
2444: } elsif ($author_ok eq 'ok') {
2445: my ($result,$imageurl,$madethumb);
2446: if ($context eq 'domain') {
2447: ($result,$imageurl,$madethumb) =
2448: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2449: "ltitools/$itemid/icon",$width,$height);
2450: } else {
2451: ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2452: }
2453: if ($result eq 'ok') {
2454: if ($madethumb) {
2455: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2456: my $imagethumb = "$path/tn-".$imagefile;
2457: $url = $imagethumb;
2458: } else {
2459: $url = $imageurl;
2460: }
2461: } else {
2462: if ($context eq 'domain') {
2463: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2464: } else {
2465: $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2466: }
2467: }
2468: } else {
2469: $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$author_ok);
2470: }
2471: } else {
2472: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$configuserok);
2473: }
2474: return ($url,$error);
2475: }
2476:
2477: sub processlogo {
2478: my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2479: my ($result,$imageurl,$madethumb);
2480: if ($env{"form.$caller.filename"} ne '') {
2481: unless ($caller eq 'ltitools_add_image') {
2482: if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2483: my ($path,$imagefile) = ($1,$2);
2484: if ($imagefile =~ /^tn\-(.+)$/) {
2485: my $origimg = $1;
2486: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2487: }
2488: &Apache::lonnet::removeuploadedurl($currimg);
2489: }
2490: }
2491: $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2492: '','','',$cnum,$dom,$width,$height);
2493: if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2494: my ($path,$imagefile) = ($1,$2);
2495: $result = 'ok';
2496: my $thumburl = "$path/tn-".$imagefile;
2497: my ($rtncode,$info);
2498: my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2499: if ($res eq 'ok') {
2500: $madethumb = 1;
2501: }
2502: } elsif ($imageurl eq '/adm/notfound.html') {
2503: undef($imageurl);
2504: $result = 'store failed';
2505: } elsif ($imageurl =~ /^error: (.+)$/) {
2506: $result = $1;
2507: }
2508: }
2509: return ($result,$imageurl,$madethumb);
2510: }
2511:
1.3 raeburn 2512: sub get_sec_str {
2513: my ($entry,$num) = @_;
2514: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2515: my $secstr;
2516: if (grep(/^\s*$/,@secs)) {
2517: $secstr = '';
2518: } elsif (@secs > 0) {
2519: $secstr = join(';',@secs);
2520: }
2521: if ($secstr ne '') {
2522: return '('.$secstr.')';
2523: }
2524: return;
2525: }
2526:
2527: sub check_clone {
2528: my ($clonedom,$disallowed,$clonename) = @_;
2529: return if (ref($disallowed) ne 'HASH');
2530: if ($clonedom !~ /^$match_domain$/) {
2531: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2532: return;
2533: } elsif (!&Apache::lonnet::domain($clonedom)) {
2534: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2535: return;
2536: }
2537: if ($clonename ne '') {
2538: if ($clonename !~ /^$match_username$/) {
2539: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2540: return;
2541: } else {
2542: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2543: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2544: return;
2545: }
2546: }
2547: }
2548: return 'ok';
2549: }
2550:
2551: sub store_changes {
1.9 raeburn 2552: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2553: my ($chome,$output);
1.118 raeburn 2554: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2555: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 2556: if (ref($values->{'linkprot'}) eq 'HASH') {
2557: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 2558: }
1.102 raeburn 2559: delete($values->{'linkprot'});
1.118 raeburn 2560: if (ref($values->{'ltitools'}) eq 'HASH') {
2561: %oldltitools = %{$values->{'ltitools'}};
2562: }
1.3 raeburn 2563: %storehash = %{$values};
2564: } else {
1.9 raeburn 2565: if ($crstype eq 'Community') {
2566: $output = &mt('No changes made to community settings.');
2567: } else {
2568: $output = &mt('No changes made to course settings.');
2569: }
2570: return $output;
1.3 raeburn 2571: }
1.93 raeburn 2572: my ($numchanges,$skipstore);
2573: if (ref($changes) eq 'HASH') {
2574: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 2575: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 2576: $skipstore = 1;
1.118 raeburn 2577: } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2578: $skipstore = 1;
1.93 raeburn 2579: } elsif (!$numchanges) {
2580: if ($crstype eq 'Community') {
2581: $output = &mt('No changes made to community settings.');
2582: } else {
2583: $output = &mt('No changes made to course settings.');
2584: }
2585: return $output;
2586: }
2587: }
1.3 raeburn 2588: my %yesno = (
2589: hidefromcat => '1',
2590: problem_stream_switch => '1',
2591: suppress_tries => '1',
2592: disableexampointprint => '1',
2593: hideemptyrows => '1',
2594: suppress_embed_prompt => '1',
2595: );
2596: foreach my $item (@{$prefs_order}) {
2597: if (grep(/^\Q$item\E$/,@{$actions})) {
2598: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2599: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 2600: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2601: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2602: if ($item eq 'other') {
2603: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2604: $storehash{$key} = $changes->{$item}{$key};
2605: if ($changes->{$item}{$key} eq '') {
2606: push(@delkeys,$key);
1.22 wenzelju 2607: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2608: } else {
1.22 wenzelju 2609: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2610: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2611: }
2612: }
1.102 raeburn 2613: } elsif ($item eq 'linkprot') {
2614: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.118 raeburn 2615: } elsif ($item eq 'ltitools') {
2616: $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2617: } else {
2618: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2619: my @settings = @{$prefs->{$item}->{'ordered'}};
2620: if ($item eq 'feedback') {
2621: push(@settings,(map { $_.'.text'; } @settings));
2622: }
2623: foreach my $key (@settings) {
2624: if ($key eq 'rolenames') {
2625: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2626: my $msg;
1.9 raeburn 2627: my @roles;
2628: if ($crstype eq 'Community') {
2629: @roles = ('co');
2630: } else {
2631: @roles = ('cc');
2632: }
2633: push(@roles,('in','ta','ep','ad','st'));
2634: foreach my $role (@roles) {
1.3 raeburn 2635: next if (!exists($changes->{$item}{$key.'_'.$role}));
2636: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2637: my $newname = $changes->{$item}{$key.'_'.$role};
2638: $storehash{$role.'.plaintext'} = $newname;
2639: if ($newname eq '') {
2640: $newname = $stdname;
2641: }
2642: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2643: "'<b>".$newname."</b>'").'</li>';
2644: }
2645: if ($msg ne '') {
1.22 wenzelju 2646: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2647: }
1.115 raeburn 2648: } elsif ($key eq 'timezone') {
2649: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2650: my ($displayname,$text);
2651: $text = $prefs->{$item}->{'itemtext'}{$key};
2652: my $displayval;
2653: if (exists($changes->{$item}{$key})) {
2654: $displayname = &mt($text);
2655: $storehash{$key} = $changes->{$item}{$key};
2656: if ($changes->{$item}{$key} ne '') {
2657: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2658: } else {
2659: push(@delkeys,$key);
2660: if (exists($values->{'tzover'})) {
2661: push(@delkeys,'tzover');
2662: }
2663: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2664: '<i>'.$displayname.'</i>')).'</li>';
2665: }
2666: }
2667: unless (grep(/^\Q$key\E$/,@delkeys)) {
2668: if (exists($changes->{$item}{'tzover'})) {
2669: $storehash{'tzover'} = $changes->{$item}{'tzover'};
2670: my $tzovertext;
2671: if ($changes->{$item}{'tzover'} ne '') {
2672: $tzovertext = &mt('Course Time Zone overrides individual user preference');
2673: } else {
2674: push(@delkeys,'tzover');
2675: $tzovertext = &mt('Course Time Zone does not override individual user preference');
2676: }
2677: if ($displayval eq '') {
2678: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2679: } else {
2680: $displayval .= '<br />'.(' 'x5).$tzovertext;
2681: }
2682: }
2683: if ($displayval ne '') {
2684: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2685: '<i>'.$displayname.'</i>',$displayval)).'</li>';
2686: }
2687: }
1.3 raeburn 2688: } else {
2689: next if (!exists($changes->{$item}{$key}));
2690: my ($displayname,$text);
2691: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2692: my $displayval;
1.114 raeburn 2693: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2694: $displayval = $changes->{$item}{$key};
2695: }
1.3 raeburn 2696: if ($item eq 'feedback') {
2697: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2698: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2699: $displayname = &mt('Custom text for '.$text.' questions');
2700: } else {
2701: $displayname = &mt('Recipients of '.$text.' questions');
2702: }
2703: } elsif ($item eq 'discussion') {
2704: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2705: $displayname = &mt("$text (role-based)");
2706: if ($displayval ne '') {
2707: my @roles = split(',',$displayval);
2708: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2709: $displayval = join(', ',@roles);
2710: }
2711: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2712: $displayname = &mt("$text (specific user(s))");
2713: } else {
2714: if ($key eq 'allow_discussion_post_editing') {
2715: if ($displayval ne '') {
2716: my @roles = split(',',$displayval);
2717: my @longroles;
2718: foreach my $role (@roles) {
2719: my ($trole,$sec) = split(':',$role);
2720: my $rolename =
2721: &Apache::lonnet::plaintext($trole);
2722: if ($sec ne '') {
2723: $rolename .= ':'.$sec;
2724: }
2725: push(@longroles,$rolename);
2726: }
2727: $displayval = join(', ',@longroles);
2728: }
1.50 raeburn 2729: } elsif ($key eq 'discussion_post_fonts') {
2730: my ($classorder,$classtitles)=&discussion_vote_classes();
2731: my ($styleorder,$styleitems)=&discussion_vote_styles();
2732: my $count = 1;
2733: my $total = scalar(keys(%{$changes->{$item}}));
2734: foreach my $class (@{$classorder}) {
2735: $count ++;
2736: next unless ($changes->{$item}{$key.'_'.$class});
2737: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2738: my $showval = '';
2739: for (my $i=0; $i<@{$styleorder}; $i++) {
2740: if ($vals[$i] ne '') {
2741: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2742: }
2743: }
2744: if ($vals[3] ne '') {
2745: $showval .= $vals[3];
2746: }
2747: if ($showval ne '') {
2748: $displayval .= $classtitles->{$class}.':{ '.
2749: $showval.'}';
2750: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2751: } else {
2752: $displayval .= $classtitles->{$class}.': '.&mt('None');
2753: push(@delkeys,$key.'_'.$class);
2754: }
2755: unless ($count == $total) {
2756: $displayval .= (' 'x2);
2757: }
2758: }
1.3 raeburn 2759: }
2760: $displayname = &mt($text);
2761: }
2762: } elsif ($item eq 'spreadsheet') {
2763: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2764: my $sheettype = $1;
2765: if ($sheettype eq 'studentcalc') {
2766: &Apache::lonnet::expirespread('','','studentcalc');
2767: } else {
2768: &Apache::lonnet::expirespread('','','assesscalc');
2769: &Apache::lonnet::expirespread('','','studentcalc');
2770: }
2771: }
2772: $displayname = &mt($text);
1.87 raeburn 2773: } elsif ($item eq 'lti') {
2774: if ($key eq 'lti.lcmenu') {
2775: if ($changes->{$item}{$key} eq 'none') {
2776: $displayval = &mt('None of the configurable menu items displayed');
2777: } else {
2778: my %ltititles = <imenu_titles();
2779: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2780: }
2781: } else {
2782: if ($changes->{$item}{$key} eq '1') {
2783: $displayval = &mt('Yes');
2784: } elsif ($changes->{$item}{$key} eq '') {
2785: $displayval = &mt('No');
2786: }
2787: }
2788: $displayname = &mt($text);
1.91 raeburn 2789: } elsif ($item eq 'menuitems') {
2790: unless ($changes->{$item}{$key} eq '') {
2791: if ($key eq 'menudefault') {
2792: $displayname = &mt('Default collection of menu items');
2793: $displayval = &mt('Collection: [_1]',
2794: $changes->{$item}{$key});
2795: } elsif ($key eq 'menucollections') {
2796: $displayval = &menucollections_display($changes->{$item}{$key});
2797: }
2798: }
1.3 raeburn 2799: } else {
2800: $displayname = &mt($text);
2801: }
2802: if (defined($yesno{$key})) {
1.14 raeburn 2803: $displayval = &mt('No');
1.3 raeburn 2804: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2805: $displayval = &mt('Yes');
1.3 raeburn 2806: }
2807: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2808: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2809: } elsif ($key eq 'categories') {
2810: $displayval = $env{'form.categories_display'};
1.95 raeburn 2811: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2812: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2813: if ($changes->{$item}{$key} eq '1') {
2814: $displayval = &mt('Yes');
2815: } elsif ($changes->{$item}{$key} eq '0') {
2816: $displayval = &mt('No');
2817: }
1.114 raeburn 2818: } elsif ($key eq 'extresource') {
2819: if ($changes->{$item}{$key} eq 'iframe') {
2820: $displayval = &mt('In iframe');
2821: } else {
2822: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2823: if ($selected eq 'tab') {
2824: if ($reuse) {
2825: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2826: "'<b>","</b>'",'<br />');
2827: } else {
2828: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2829: "'<b>","</b>'",'<br />');
2830: }
2831: } elsif ($selected eq 'window') {
2832: if ($reuse) {
2833: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2834: "'<b>","</b>'",'<br />');
2835: } else {
2836: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2837: "'<b>","</b>'",'<br />');
2838: }
2839: if (($width ne '') || ($height ne '')) {
2840: if ($width ne '') {
2841: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2842: }
2843: if ($height ne '') {
2844: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2845: }
2846: }
2847: }
2848: }
1.14 raeburn 2849: }
1.25 raeburn 2850: if ($key eq 'co-owners') {
2851: if (ref($changes->{$item}{$key}) eq 'HASH') {
2852: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2853: foreach my $type ('co-owners','pendingco-owners') {
2854: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2855: if ($type eq 'pendingco-owners') {
2856: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2857: $displayname = &mt('Invited as co-owners, pending acceptance');
2858: }
2859: }
2860: if ($changes->{$item}{$key}{$type} eq '') {
2861: push(@delkeys,'internal.'.$type);
2862: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2863: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2864: '<i>'.$displayname.'</i>')).'</li>';
2865: }
2866: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2867: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2868: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2869: '<i>'.$displayname.'</i>',
2870: "'<b>$displayval</b>'")).'</li>';
2871: }
2872: }
2873: }
2874: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2875: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2876: $displayval = &mt('on');
1.90 raeburn 2877: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2878: $displayval = '';
2879: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2880: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2881: $displayval = &mt('off');
2882: }
2883: if ($displayval) {
2884: $displayname = &mt('Your co-ownership status');
2885: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2886: '<i>'.$displayname.'</i>',
2887: "'<b>$displayval</b>'")).'</li>';
2888: }
2889: }
2890: }
2891: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2892: push(@delkeys,$key);
1.87 raeburn 2893: if ($item eq 'lti') {
2894: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2895: if (($key eq 'lti.lcmenu') &&
2896: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2897: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2898: } else {
2899: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2900: '<i>'.$displayname.'</i>',
2901: "'<b>$displayval</b>'")).'</li>';
2902: }
2903: } elsif (!exists($changes->{$item}{'lti.override'})) {
2904: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2905: }
1.91 raeburn 2906: } elsif ($item eq 'menuitems') {
2907: if ($key eq 'menudefault') {
2908: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2909: } elsif ($key eq 'menucollections') {
2910: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2911: }
1.87 raeburn 2912: } else {
2913: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2914: '<i>'.$displayname.'</i>')).'</li>';
2915: }
1.91 raeburn 2916: } elsif ($key eq 'menucollections') {
2917: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2918: $displayval.'</li>';
1.3 raeburn 2919: } else {
1.114 raeburn 2920: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2921: $displayval = "'<b>$displayval</b>'";
2922: }
1.22 wenzelju 2923: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2924: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2925: if ($key eq 'url') {
2926: my $bkuptime=time;
2927: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2928: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2929: }
2930: $output .= '</li>';
2931: }
1.25 raeburn 2932: if ($key eq 'co-owners') {
2933: if (ref($changes->{$item}{$key}) eq 'HASH') {
2934: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2935: foreach my $type ('co-owners','pendingco-owners') {
2936: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2937: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2938: }
2939: }
2940: }
2941: } else {
1.50 raeburn 2942: unless ($key eq 'discussion_post_fonts') {
2943: $storehash{$key} = $changes->{$item}{$key};
2944: }
1.25 raeburn 2945: }
1.3 raeburn 2946: }
1.23 raeburn 2947: if ($key eq 'cloners') {
2948: # Get existing cloners
2949: my %clonenames =
2950: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2951: if ($clonenames{'cloners'} =~ /,/) {
2952: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2953: } else {
2954: $oldcloner[0] = $clonenames{'cloners'};
2955: }
2956: }
1.3 raeburn 2957: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2958: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2959: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2960: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2961: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2962: push(@need_env_update,$key);
2963: }
2964: }
2965: }
2966: }
2967: $output .= '</ul>';
2968: } else {
1.9 raeburn 2969: if ($crstype eq 'Community') {
1.46 raeburn 2970: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2971: } else {
1.46 raeburn 2972: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2973: }
1.3 raeburn 2974: }
2975: }
2976: }
2977: }
1.93 raeburn 2978: if ($skipstore) {
2979: return $output;
2980: }
1.3 raeburn 2981: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2982: if (ref($changes) eq 'HASH') {
2983: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2984: if (exists($changes->{'courseinfo'}{'cloners'})) {
2985: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2986: \@oldcloner);
2987: }
2988: }
2989: }
1.3 raeburn 2990: if (@delkeys) {
2991: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2992: $output .= '<br /><span class="LC_error">';
2993: if ($crstype eq 'Community') {
2994: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2995: } else {
2996: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2997: }
2998: $output .= '</span>';
1.14 raeburn 2999: } else {
3000: foreach my $key (@delkeys) {
3001: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
3002: }
1.3 raeburn 3003: }
3004: }
3005: if (@need_env_update) {
3006: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
3007: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
3008: }
3009: &Apache::lonnet::coursedescription($env{'request.course.id'},
3010: {'freshen_cache' => 1});
3011: } else {
1.9 raeburn 3012: $output = '<span class="LC_error">';
3013: if ($crstype eq 'Community') {
3014: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
3015: } else {
3016: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
3017: }
3018: $output .= '</span>';
1.3 raeburn 3019: }
3020: return $output;
3021: }
3022:
1.102 raeburn 3023: sub store_linkprot {
3024: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 3025: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 3026: if ($context eq 'domain') {
3027: $ltiauth = 1;
1.103 raeburn 3028: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 3029: } else {
1.103 raeburn 3030: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 3031: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
3032: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
3033: } else {
3034: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
3035: $ltiauth = $domdefs{'crsltiauth'};
3036: }
3037: }
3038: if (ref($changes) eq 'HASH') {
3039: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3040: if (ref($changes->{$id}) eq 'HASH') {
3041: if (exists($changes->{$id}->{'key'})) {
3042: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
3043: delete($changes->{$id}->{'key'});
3044: }
3045: if (exists($changes->{$id}->{'secret'})) {
3046: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
3047: delete($changes->{$id}->{'secret'});
3048: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3049: if (exists($oldlinkprot->{$id}{'usable'})) {
3050: $changes->{$id}->{'usable'} = 1;
3051: }
1.109 raeburn 3052: if (exists($oldlinkprot->{$id}{'cipher'})) {
3053: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
3054: }
1.102 raeburn 3055: }
3056: }
3057: }
3058: }
3059: my @ids=&Apache::lonnet::current_machine_ids();
3060: if (keys(%ltienc) > 0) {
3061: if ($context eq 'domain') {
3062: foreach my $id (keys(%ltienc)) {
3063: if (exists($ltienc{$id}{'secret'})) {
3064: $changes->{$id}->{'usable'} = 1;
3065: }
3066: }
3067: } else {
1.103 raeburn 3068: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 3069: my $allowed;
3070: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3071: if ($allowed) {
3072: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
3073: foreach my $id (keys(%ltienc)) {
3074: if (exists($ltienc{$id}{'secret'})) {
3075: $changes->{$id}->{'usable'} = 1;
3076: }
3077: }
3078: } else {
3079: $lti_save_error = 1;
3080: }
3081: }
3082: }
3083: }
3084: }
3085: unless ($lti_save_error) {
3086: if ($context eq 'course') {
3087: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3088: my $hashid=$cdom.'_'.$cnum;
3089: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 3090: unless (($home eq 'no_host') || ($home eq '')) {
3091: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 3092: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3093: }
3094: }
3095: } else {
3096: $lti_save_error = 1;
3097: }
3098: }
3099: unless ($lti_save_error) {
3100: foreach my $id (sort { $a <=> $b } %{$changes}) {
3101: if (ref($changes->{$id}) eq 'HASH') {
3102: my %values = %{$changes->{$id}};
3103: my %desc = &linkprot_names();
3104: my $display;
1.122 ! raeburn 3105: foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.102 raeburn 3106: if (($title eq 'key') || ($title eq 'secret')) {
3107: if (ref($ltienc{$id}) eq 'HASH') {
3108: if (exists($ltienc{$id}{$title})) {
3109: if ($title eq 'secret') {
3110: my $length = length($ltienc{$id}{$title});
1.103 raeburn 3111: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 3112: } else {
3113: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3114: }
3115: }
3116: }
3117: } elsif ($title eq 'version') {
3118: if ($values{$title} eq 'LTI-1p0') {
3119: $display .= $desc{$title}.': 1.1, ';
3120: }
1.112 raeburn 3121: } elsif ($title eq 'returnurl') {
3122: if ($values{$title}) {
3123: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
3124: }
1.122 ! raeburn 3125: } elsif ($title eq 'passbackformat') {
! 3126: if ($values{$title} eq '1.0') {
! 3127: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
! 3128: } elsif ($values{$title} eq '1.1') {
! 3129: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
! 3130: }
1.102 raeburn 3131: } else {
3132: $display .= $desc{$title}.': '.$values{$title}.', ';
3133: }
3134: }
3135: if ($ltiauth) {
3136: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3137: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3138: $display .= &mt('Source of username: Email address [_1]',
3139: '(lis_person_contact_email_primary)').', ';
3140: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3141: $display .= &mt('Source of username: User ID [_1]',
3142: '(lis_person_sourcedid)').', ';
3143: } else {
3144: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3145: }
3146: if ($values{'notstudent'} eq 'auth') {
3147: $display .= &mt('Display LON-CAPA login page if no match').', ';
3148: } elsif ($values{'notstudent'} eq 'reject') {
3149: $display .= &mt('Discontinue launch if no match').', ';
3150: }
3151: }
3152: }
3153: $display =~ s/, $//;
3154: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3155: "'$display'")).'</li>';
3156: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3157: my $oldname = $oldlinkprot->{$id}{'name'};
3158: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3159: }
3160: }
3161: } else {
3162: $lti_save_error = 1;
3163: }
3164: }
3165: unless ($lti_save_error) {
3166: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3167: unless (ref($changes->{$id}) eq 'HASH') {
3168: push(@deletions,$id);
3169: }
3170: }
3171: if (@deletions) {
3172: if ($context eq 'course') {
3173: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3174: }
3175: }
3176: }
3177: if ($lti_save_error) {
3178: $output .= '<li>'.
3179: '<span class="LC_error">'.
3180: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3181: '</span>'.
3182: '</li>';
3183: }
3184: return $output;
3185: }
3186:
1.118 raeburn 3187: sub store_ltitools {
3188: my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3189: my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3190: my %lt = <itools_names();
3191: my @courseroles = ('cc','in','ta','ep','st');
3192: my @allfields = ('fullname','firstname','lastname','email','user','roles');
3193: if ($context eq 'domain') {
3194: $home = &Apache::lonnet::domain($cdom,'primary');
3195: } else {
3196: $home = &Apache::lonnet::homeserver($cnum,$cdom);
3197: }
3198: if (ref($changes) eq 'HASH') {
3199: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3200: if (ref($changes->{$id}) eq 'HASH') {
3201: if (exists($changes->{$id}->{'key'})) {
3202: $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3203: delete($changes->{$id}->{'key'});
3204: }
3205: if (exists($changes->{$id}->{'secret'})) {
3206: $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3207: delete($changes->{$id}->{'secret'});
3208: } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3209: if (exists($oldltitools->{$id}{'usable'})) {
3210: $changes->{$id}->{'usable'} = 1;
3211: }
3212: if (exists($oldltitools->{$id}{'cipher'})) {
3213: $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3214: }
3215: }
3216: }
3217: }
3218: }
3219: my @ids=&Apache::lonnet::current_machine_ids();
3220: if (keys(%toolsenc) > 0) {
3221: unless (($home eq 'no_host') || ($home eq '')) {
3222: my $allowed;
3223: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3224: if ($allowed) {
3225: if (($context eq 'domain') ||
3226: (($context eq 'course') &&
3227: (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3228: foreach my $id (keys(%toolsenc)) {
3229: if (exists($toolsenc{$id}{'secret'})) {
3230: $changes->{$id}->{'usable'} = 1;
3231: }
3232: }
3233: } else {
3234: $ltitools_save_error = 1;
3235: }
3236: }
3237: }
3238: }
3239: unless ($ltitools_save_error) {
3240: if ($context eq 'course') {
3241: if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3242: my $hashid=$cdom.'_'.$cnum;
3243: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3244: unless (($home eq 'no_host') || ($home eq '')) {
3245: if (grep(/^\Q$home\E$/,@ids)) {
1.120 raeburn 3246: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
1.118 raeburn 3247: }
3248: }
3249: } else {
3250: $ltitools_save_error = 1;
3251: }
3252: }
3253: unless ($ltitools_save_error) {
3254: my %bynum;
3255: foreach my $itemid (sort(keys(%{$changes}))) {
3256: my $position = $changes->{$itemid}{'order'};
3257: $bynum{$position} = $itemid;
3258: }
3259: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3260: my $itemid = $bynum{$pos};
3261: if (ref($changes->{$itemid}) ne 'HASH') {
3262: $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3263: } else {
3264: $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3265: if ($changes->{$itemid}{'image'}) {
3266: $output .= ' '.
3267: '<img src="'.$changes->{$itemid}{'image'}.'"'.
3268: ' alt="'.&mt('Tool Provider icon').'" />';
3269: }
3270: $output .= '</li><ul>';
3271: my $position = $pos + 1;
3272: $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3273: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3274: if ($changes->{$itemid}{$item} ne '') {
3275: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3276: }
3277: }
3278: if (ref($toolsenc{$itemid}) eq 'HASH') {
3279: foreach my $item ('key','secret') {
3280: if (exists($toolsenc{$itemid}{$item})) {
3281: if ($item eq 'secret') {
3282: $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3283: } else {
3284: $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3285: }
3286: }
3287: }
3288: }
3289: $output .= '<li>'.&mt('Configurable in course:');
3290: my @possconfig = ('label','title','target','linktext','explanation','append');
3291: my $numconfig = 0;
3292: if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3293: foreach my $item (@possconfig) {
3294: if ($changes->{$itemid}{'crsconf'}{$item}) {
3295: $numconfig ++;
3296: $output .= ' "'.$lt{'crs'.$item}.'"';
3297: }
3298: }
3299: }
3300: if (!$numconfig) {
3301: $output .= ' '.&mt('None');
3302: }
3303: $output .= '</li>';
3304: foreach my $item ('passback','roster') {
3305: $output .= '<li>'.$lt{$item}.' ';
3306: if ($changes->{$itemid}{$item}) {
3307: $output .= &mt('Yes');
3308: if ($changes->{$itemid}{$item.'valid'}) {
3309: if ($item eq 'passback') {
3310: $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3311: $changes->{$itemid}{$item.'valid'});
3312: } else {
3313: $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3314: $changes->{$itemid}{$item.'valid'});
3315: }
3316: }
3317: } else {
3318: $output .= &mt('No');
3319: }
3320: $output .= '</li>';
3321: }
3322: if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3323: my $displaylist;
3324: if ($changes->{$itemid}{'display'}{'target'}) {
3325: $displaylist = &mt('Display target').': '.
3326: $changes->{$itemid}{'display'}{'target'}.',';
3327: }
3328: foreach my $size ('width','height') {
3329: if ($changes->{$itemid}{'display'}{$size}) {
3330: $displaylist .= (' 'x2).$lt{$size}.': '.
3331: $changes->{$itemid}{'display'}{$size}.',';
3332: }
3333: }
3334: if ($displaylist) {
3335: $displaylist =~ s/,$//;
3336: $output .= '<li>'.$displaylist.'</li>';
3337: }
3338: foreach my $item ('linktext','explanation') {
3339: if ($changes->{$itemid}{'display'}{$item}) {
3340: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3341: }
3342: }
3343: }
3344: if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3345: my $fieldlist;
3346: foreach my $field (@allfields) {
3347: if ($changes->{$itemid}{'fields'}{$field}) {
3348: $fieldlist .= (' 'x2).$lt{$field}.',';
3349: }
3350: }
3351: if ($fieldlist) {
3352: $fieldlist =~ s/,$//;
3353: if ($changes->{$itemid}{'fields'}{'user'}) {
3354: if ($changes->{$itemid}{'incdom'}) {
3355: $fieldlist .= ' ('.&mt('username:domain').')';
3356: } else {
3357: $fieldlist .= ' ('.&mt('username').')';
3358: }
3359: }
3360: $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3361: }
3362: }
3363: if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3364: my $rolemaps;
3365: foreach my $role (@courseroles) {
3366: if ($changes->{$itemid}{'roles'}{$role}) {
3367: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3368: $changes->{$itemid}{'roles'}{$role}.',';
3369: }
3370: }
3371: if ($rolemaps) {
3372: $rolemaps =~ s/,$//;
3373: $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3374: }
3375: }
3376: if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3377: my $customlist;
3378: if (keys(%{$changes->{$itemid}{'custom'}})) {
3379: foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3380: $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3381: }
3382: }
3383: if ($customlist) {
3384: $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3385: }
3386: }
3387: $output .= '</ul></li>';
3388: }
3389: }
3390: }
3391: }
3392: return $output;
3393: }
3394:
1.3 raeburn 3395: sub update_env {
3396: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3397: my $count = 0;
3398: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3399: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3400: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3401: foreach my $key (@{$need_env_update}) {
3402: if ($key eq 'description' && defined($storehash->{$key})) {
3403: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3404: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3405: $count ++;
3406: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3407: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3408: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3409: $count ++;
1.25 raeburn 3410: } elsif ($key eq 'co-owners') {
3411: if ($storehash->{'internal.co-owners'} ne '') {
3412: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3413: }
3414: if ($storehash->{'internal.pendingco-owners'} ne '') {
3415: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3416: }
3417: my @coowners = split(',',$storehash->{'internal.'.$key});
3418: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3419: $count ++;
1.87 raeburn 3420: } elsif ($key =~ /^lti\./) {
3421: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 3422: }
3423: }
3424: if ($count) {
3425: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3426: }
3427: }
3428: }
3429: return;
3430: }
3431:
3432: sub display_disallowed {
1.9 raeburn 3433: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3434: my $output;
3435: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3436: if (keys(%{$disallowed})) {
3437: if ($item eq 'cloners') {
3438: my @fails;
3439: my %lt = &Apache::lonlocal::texthash (
3440: format => 'Invalid format',
3441: domain => 'Domain does not exist',
3442: newuser => 'LON-CAPA user(s) do(es) not exist.',
3443: );
3444: foreach my $error ('format','domain','newuser') {
3445: if (defined($disallowed->{$error})) {
3446: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3447: $lt{$error};
3448: if ($error eq 'newuser') {
1.9 raeburn 3449: $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 3450: }
3451: push(@fails,$msg);
3452: }
3453: }
3454: if (@fails) {
3455: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3456: '</span>'.join('; ',@fails).'.<br />';
3457: }
3458: } elsif ($item eq 'rolenames') {
3459: my %lt = &Apache::lonlocal::texthash (
3460: replacements => 'Name already used to replace a different standard role name',
3461: regulars => 'Name already used as a standard role name',
3462: customrole => 'Name already used as the name of a custom role',
3463: );
3464: my @fails;
3465: foreach my $error ('replacements','regulars','customrole') {
3466: if (ref($disallowed->{$error}) eq 'ARRAY') {
3467: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3468: '</b>, '.&mt('reason').' - '.$lt{'error'});
3469: }
3470: }
3471: if (@fails) {
3472: $output .= '<span class="LC_warning">'.
3473: &mt('Unable to include amongst replacements for role names: ').
3474: '</span>'.join('; ',@fails).'.<br />';
3475: }
3476:
3477: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3478: $output .= '<span class="LC_warning">';
3479: if ($item eq 'feedback') {
1.9 raeburn 3480: if ($crstype eq 'Community') {
3481: $output .= &mt('Unable to include as a recipient of community feedback for:');
3482: } else {
3483: $output .= &mt('Unable to include as a recipient of course feedback for:');
3484: }
1.3 raeburn 3485: } elsif ($item eq 'discussion') {
3486: $output .= &mt('Unable to include in user-based access control for:');
3487: } elsif ($item eq 'localization') {
1.9 raeburn 3488: if ($crstype eq 'Community') {
3489: $output .= &mt('Unable to include in community localization:');
3490: } else {
3491: $output .= &mt('Unable to include in course localization:');
3492: }
1.3 raeburn 3493: }
3494: $output .= '</span><ul>';
3495: foreach my $key (sort(keys(%{$disallowed}))) {
3496: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3497: $output .= '<li><i>'.$itemtext.'</i> - ';
3498: if ($item eq 'localization') {
3499: $output .= &mt('reason - unsupported language: [_1]',
3500: '<b>'.$disallowed->{$key}.'</b>');
3501: } else {
3502: $output .= &mt('reason - invalid user: [_1]',
3503: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3504: }
3505: }
3506: $output .= '</ul><br />';
3507: }
3508: }
1.1 raeburn 3509: }
1.3 raeburn 3510: return $output;
1.1 raeburn 3511: }
3512:
3513: sub get_course {
3514: my ($courseid) = @_;
3515: if (!defined($courseid)) {
3516: $courseid = $env{'request.course.id'};
3517: }
3518: my $cdom=$env{'course.'.$courseid.'.domain'};
3519: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 3520: my $chome=$env{'course.'.$courseid.'.home'};
3521: return ($cnum,$cdom,$chome);
1.1 raeburn 3522: }
3523:
3524: sub get_jscript {
1.91 raeburn 3525: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3526: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 raeburn 3527: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3528: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3529: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3530: my $cloners_js = &cloners_javascript($phase);
1.118 raeburn 3531: my $currltitools;
3532: if (ref($settings) eq 'HASH') {
3533: $currltitools = $settings->{'ltitools'};
3534: }
3535: my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.71 raeburn 3536: my @code_order;
3537: if ($crstype ne 'Community') {
3538: if (ref($settings) eq 'HASH') {
3539: my %codedefaults;
3540: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3541: \@code_order);
3542: if (@code_order > 0) {
3543: if ($phase eq 'display') {
3544: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3545: if (grep(/^courseinfo$/,@actions)) {
3546: if ($settings->{'cloners'} ne '') {
3547: unless ($settings->{'cloners'} eq '*') {
3548: my @cloners = split(/,/,$settings->{'cloners'});
3549: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3550: my %local_to_standard;
3551: for (my $i=0; $i<@code_order; $i++) {
3552: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3553: }
3554: foreach my $cloner (@cloners) {
3555: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
3556: ($cloner !~ /^$match_username\:$match_domain$/)) {
3557: foreach my $item (split(/\&/,$cloner)) {
3558: my ($key,$val) = split(/\=/,$item);
3559: $val = &unescape($val);
3560: foreach my $code (@code_order) {
3561: if ($key eq $local_to_standard{$code}) {
3562: $env{'form.'.$key} = $val;
3563: }
3564: }
3565: }
3566: }
3567: }
3568: }
3569: }
3570: }
3571: }
3572: my @codetitles;
3573: (undef,$instcode_js) =
3574: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3575: \@codetitles);
3576: $instcode_js .= <<ENDSCRIPT;
3577: function toggleCloners(callerradio) {
3578: if (document.getElementById('LC_cloners_instcode')) {
3579: if (callerradio.value == 1) {
3580: document.getElementById('LC_cloners_instcode').style.display = "block";
3581: } else {
3582: uncheckOfficialLists();
3583: document.getElementById('LC_cloners_instcode').style.display = "none";
3584: }
3585: }
3586: }
3587:
3588: if (!document.getElementsByClassName) {
3589: function getElementsByClassName(node, classname) {
3590: var a = [];
3591: var re = new RegExp('(^| )'+classname+'( |$)');
3592: var els = node.getElementsByTagName("*");
3593: for(var i=0,j=els.length; i<j; i++)
3594: if(re.test(els[i].className))a.push(els[i]);
3595: return a;
3596: }
3597: }
3598:
3599: function uncheckOfficialLists() {
3600: var codepicks;
3601: if (document.getElementsByClassName) {
3602: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3603: } else {
3604: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3605: }
3606: if (codepicks.length) {
3607: for (var i=0; i<codepicks.length; i++) {
3608: codepicks[i].selectedIndex = 0;
3609: }
3610: }
3611: }
3612:
3613: ENDSCRIPT
3614: }
3615: }
3616: }
1.1 raeburn 3617: if ($can_categorize) {
3618: $categorize_js = <<ENDSCRIPT;
3619: function catsbrowser() {
3620: var catswin = null;
3621: var url = '/adm/courseprefs?phase=categorizecourse';
3622: if (!catswin || catswin.closed) {
3623: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3624: } else {
3625: catswin.focus();
3626: }
3627: }
3628: ENDSCRIPT
3629: }
1.36 raeburn 3630: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3631: if ($loncaparev) {
3632: $loncaparev_js = <<ENDSCRIPT;
3633: function loncaparevinfo() {
3634: var lcrevwin = null;
3635: var url = '/adm/courseprefs?phase=releaseinfo';
3636: if (!lcrevwin || lcrevwin.closed) {
3637: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3638: } else {
3639: lcrevwin.focus();
3640: }
3641: }
3642: ENDSCRIPT
3643: }
1.60 raeburn 3644: my $cnum = $env{'course.'.$cid.'.num'};
3645: my $syllabus_js = <<ENDSCRIPT;
3646: function syllabusinfo() {
3647: var syllwin = null;
3648: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3649: if (!syllwin || syllwin.closed) {
3650: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3651: } else {
3652: syllwin.focus();
3653: }
3654: }
3655: ENDSCRIPT
1.91 raeburn 3656: my $menuitems_js;
3657: unless ($noedit) {
3658: my $collections;
3659: my $next = 1;
3660: if (ref($settings) eq 'HASH') {
3661: if ($settings->{'menucollections'} ne '') {
3662: my @current;
3663: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3664: my ($num) = split(/\%/,$item);
3665: if ($num =~ /^\d+$/) {
3666: push(@current,$num);
3667: }
3668: }
3669: $collections = join("','",sort { $a <=> $b } @current);
3670: if ($collections) {
3671: $collections = "'$collections'";
3672: }
3673: $next += $current[-1];
3674: }
3675: }
3676: my $deftext = &mt('Standard (all menus shown)');
3677: $menuitems_js = <<ENDSCRIPT;
3678: function toggleAddmenucoll() {
3679: if (document.getElementById('menucollections_add')) {
3680: var state = 'none';
3681: var add = document.getElementById('menucollections_add').checked;
3682: if (add) {
3683: state = 'inline-block';
3684: }
3685: var fieldsets = new Array('shown','text','links','list','inline');
3686: for (var i=0; i<fieldsets.length; i++) {
3687: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3688: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3689: }
3690: }
3691: var box = document.getElementsByClassName('LC_menucoll_add');
3692: if (box.length) {
3693: for (var i=0; i<box.length; i++) {
3694: if (add) {
3695: box[i].checked = true;
3696: } else {
3697: box[i].checked = false;
3698: }
3699: }
3700: }
3701: if (document.getElementById('menudefault')) {
3702: var menudef = document.getElementById('menudefault');
3703: var currsel = menudef.selectedIndex;
3704: var colls = new Array($collections);
3705: menudef.options.length = 0;
3706: if (!add) {
3707: if (currsel == 1 + colls.length) {
3708: currsel = 0;
3709: }
3710: }
3711: if (currsel == 0) {
3712: menudef.options[0] = new Option('$deftext','',true,true);
3713: } else {
3714: menudef.options[0] = new Option('$deftext','',false,false);
3715: }
3716: if (colls.length) {
3717: for (var i=0; i<colls.length; i++) {
3718: var idx = i+1;
3719: if (currsel == colls[i]) {
3720: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3721: } else {
3722: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3723: }
3724: }
3725: }
3726: if (add) {
3727: var addidx = 1 + colls.length;
3728: if (currsel == addidx) {
3729: menudef.options[addidx] = new Option('$next','$next',true,true);
3730: } else {
3731: menudef.options[addidx] = new Option('$next','$next',false,false);
3732: }
3733: }
3734: }
3735: }
3736: }
3737: ENDSCRIPT
3738: }
1.114 raeburn 3739: $extresource_js = <<"ENDSCRIPT";
3740: function toggleExtRes() {
3741: if (document.getElementById('LC_extresource')) {
3742: var extressel = document.getElementById('LC_extresource').value;
3743: if (document.getElementById('LC_extresreusediv')) {
3744: var extresreuse = document.getElementById('LC_extresreusediv');
3745: if (document.getElementById('LC_extressize')) {
3746: var extressize = document.getElementById('LC_extressize');
3747: var setvis;
3748: if ((extressel == 'tab') || (extressel == 'window')) {
3749: extresreuse.style.display = 'inline-block';
3750: setvis = 1;
3751: if (extressel == 'window') {
3752: extressize.style.display = 'inline-block';
3753: } else {
3754: extressize.style.display = 'none';
3755: }
3756: }
3757: if (!setvis) {
3758: extresreuse.style.display = 'none';
3759: extressize.style.display = 'none';
3760: }
3761: }
3762: }
3763: }
3764: }
3765: ENDSCRIPT
1.115 raeburn 3766: $localization_js = <<"ENDSCRIPT";
3767: function toggleTimeZone() {
3768: if (document.getElementById('LC_set_timezone')) {
3769: var timezonesel = document.getElementById('LC_set_timezone').value;
3770: if (document.getElementById('LC_tzoverdiv')) {
3771: var tzoverdiv = document.getElementById('LC_tzoverdiv');
3772: if (timezonesel == '') {
3773: tzoverdiv.style.display = 'none';
3774: } else {
3775: tzoverdiv.style.display = 'block';
3776: }
3777: }
3778: }
3779: }
3780: ENDSCRIPT
1.1 raeburn 3781: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.56 raeburn 3782: '// <![CDATA['."\n".
1.36 raeburn 3783: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 raeburn 3784: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 3785: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.102 raeburn 3786: &linkprot_javascript()."\n".'//]]>'."\n".
1.118 raeburn 3787: '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3788: return $jscript;
3789: }
3790:
1.3 raeburn 3791: sub cloners_javascript {
3792: my ($formname) = @_;
3793: return <<"ENDSCRIPT";
3794:
3795: function update_cloners(caller,num) {
3796: var delidx = getIndexByName('cloners_delete');
3797: var actidx = getIndexByName('cloners_activate');
3798: if (caller == 'cloners_all') {
3799: var selall;
3800: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3801: if (document.$formname.cloners_all[i].checked) {
3802: selall = document.$formname.cloners_all[i].value;
3803: }
3804: }
3805: if (selall == 1) {
3806: if (delidx != -1) {
3807: if (document.$formname.cloners_delete.length) {
3808: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3809: document.$formname.cloners_delete[j].checked = true;
3810: }
3811: } else {
3812: document.$formname.elements[delidx].checked = true;
3813: }
3814: }
3815: if (actidx != -1) {
3816: if (document.$formname.cloners_activate.length) {
3817: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3818: if (document.$formname.cloners_activate[i].value == '0') {
3819: document.$formname.cloners_activate[i].checked = false;
3820: }
1.71 raeburn 3821: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3822: document.$formname.cloners_activate[i].checked = true;
3823: }
3824: }
3825: }
3826: }
3827: document.$formname.cloners_newdom.selectedIndex = 0;
3828: }
3829: }
3830: if (caller == 'cloners_activate') {
3831: if (document.$formname.cloners_activate.length) {
3832: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3833: if (document.$formname.cloners_activate[j].value == num) {
3834: if (document.$formname.cloners_activate[j].checked) {
3835: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3836: if (document.$formname.cloners_all[i].value == '1') {
3837: document.$formname.cloners_all[i].checked = false;
3838: }
3839: if (document.$formname.cloners_all[i].value == '0') {
3840: document.$formname.cloners_all[i].checked = true;
3841: }
3842: }
3843: }
3844: }
3845: }
3846: } else {
3847: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3848: if (document.$formname.cloners_all[i].value == '1') {
3849: document.$formname.cloners_all[i].checked = false;
3850: }
3851: if (document.$formname.cloners_all[i].value == '0') {
3852: document.$formname.cloners_all[i].checked = true;
3853: }
3854: }
3855: }
3856: }
3857: return;
3858: }
3859:
3860: function getIndexByName(item) {
3861: for (var i=0;i<document.$formname.elements.length;i++) {
3862: if (document.$formname.elements[i].name == item) {
3863: return i;
3864: }
3865: }
3866: return -1;
3867: }
3868:
3869: ENDSCRIPT
3870: }
3871:
1.102 raeburn 3872: sub linkprot_javascript {
3873: return <<"ENDSCRIPT";
1.112 raeburn 3874: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 3875: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3876: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3877: var itemname = form.elements['linkprot_'+item+'_'+num];
3878: if (itemname) {
3879: if (itemname.length > 0) {
3880: var setvis;
3881: for (var i=0; i<itemname.length; i++) {
3882: if (itemname[i].checked == true) {
3883: if (itemname[i].value == valon) {
3884: extraid.style.display = styleon;
3885: setvis = 1;
3886: }
3887: break;
3888: }
3889: }
3890: if (!setvis) {
3891: extraid.style.display = 'none';
3892: }
3893: }
3894: }
3895: }
3896: return;
3897: }
1.106 raeburn 3898:
1.102 raeburn 3899: ENDSCRIPT
3900:
3901: }
3902:
1.1 raeburn 3903: sub print_courseinfo {
1.80 raeburn 3904: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3905: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3906: return;
3907: }
1.83 raeburn 3908: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3909: if ($noedit) {
3910: $disabled = ' disabled="disabled"';
3911: }
1.1 raeburn 3912: my %domconf =
1.71 raeburn 3913: &Apache::lonnet::get_dom('configuration',
3914: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3915: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3916: $cathash = $domconf{'coursecategories'}{'cats'};
3917: if (ref($cathash) eq 'HASH') {
3918: $categoriesform =
3919: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 3920: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3921: }
3922: }
1.25 raeburn 3923: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3924: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3925: }
1.71 raeburn 3926: my ($currcanclone,@code_order,$cloner_instcode);
3927: my %codedefaults;
3928: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3929: \@code_order);
3930: if ($settings->{'cloners'}) {
3931: unless ($settings->{'cloners'} eq '*') {
3932: my @currclone = split(/,/,$settings->{'cloners'});
3933: foreach my $item (@currclone) {
3934: unless ($item eq '*') {
3935: if (($item !~ /\:/) && ($item =~ /=/)) {
3936: $cloner_instcode = 1;
3937: }
3938: }
3939: }
3940: }
3941: }
3942: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3943: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3944: if (ref($canclone) eq 'HASH') {
3945: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3946: if ($settings->{'internal.coursecode'}) {
3947: my @posscodes;
3948: if (@code_order > 0) {
3949: $currcanclone = 'instcode';
3950: foreach my $item (@{$canclone->{'instcode'}}) {
3951: if (grep(/^\Q$item\E$/,@code_order)) {
3952: push(@posscodes,$item);
3953: }
3954: }
3955: my $codestr = join(' + ',@posscodes);
3956: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3957: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3958: }
3959: }
3960: }
3961: } elsif ($canclone eq 'domain') {
3962: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
3963: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
3964: $currcanclone = 'domain';
3965: }
3966: if ($clonedefaults) {
3967: if ($settings->{'cloners'} ne '') {
3968: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
3969: } else {
3970: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
3971: }
3972: $clonedefaults = '<br /><br />'.$clonedefaults;
3973: }
3974: }
1.1 raeburn 3975: if (!defined($categoriesform)) {
1.15 raeburn 3976: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 3977: }
1.12 raeburn 3978: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 3979: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 3980:
1.9 raeburn 3981: my $replace;
3982: if ($crstype eq 'Community') {
3983: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3984: } else {
3985: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3986: }
1.84 raeburn 3987: my ($editmap,$editsyllabus);
3988: unless ($noedit) {
3989: $editmap = (' 'x2).
3990: '<a href="javascript:openbrowser'.
3991: "('display','url','sequence')\">".
3992: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
3993: &mt('Modification may make assessment data inaccessible!').
3994: '</span>';
3995: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
3996: '</a>');
3997: }
1.1 raeburn 3998: my %items = (
1.3 raeburn 3999: 'url' => {
1.84 raeburn 4000: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 4001: input => 'textbox',
1.55 raeburn 4002: size => '55',
1.19 faziophi 4003: advanced => 1
1.1 raeburn 4004: },
4005: 'description' => {
1.3 raeburn 4006: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 4007: input => 'textbox',
1.55 raeburn 4008: size => '55',
1.1 raeburn 4009: },
1.24 raeburn 4010: 'owner' => {
4011: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
4012: },
1.25 raeburn 4013: 'co-owners' => {
4014: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
4015: },
1.63 raeburn 4016: 'clonedfrom' => {
4017: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
4018: },
1.1 raeburn 4019: 'courseid' => {
1.3 raeburn 4020: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
4021: &mt('internal, optional').')',
1.1 raeburn 4022: input => 'textbox',
4023: size => '25',
4024: },
1.64 raeburn 4025: 'uniquecode' => {
4026: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
4027: },
1.1 raeburn 4028: 'cloners' => {
1.3 raeburn 4029: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 4030: &mt('Owner and Coordinators included automatically').
4031: $clonedefaults,
1.1 raeburn 4032: input => 'textbox',
1.41 www 4033: size => '40'
1.1 raeburn 4034: },
4035: 'rolenames' => {
1.3 raeburn 4036: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 4037: '('.$replace.')',
1.1 raeburn 4038: input => 'textbox',
4039: size => '20',
1.19 faziophi 4040: advanced => 1
1.1 raeburn 4041: },
1.88 raeburn 4042: 'syllabus' => {
4043: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 4044: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 4045: $editsyllabus,
1.1 raeburn 4046: },
4047: 'hidefromcat' => {
1.3 raeburn 4048: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 4049: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
4050: input => 'radio',
4051: },
4052: 'categories' => {
1.3 raeburn 4053: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 4054: &mt('Display Categories').'</a>',
4055: input => 'textbox',
4056: size => '25',
4057: },
1.35 raeburn 4058: 'loncaparev' => {
4059: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
4060: },
1.55 raeburn 4061: 'defaultcredits' => {
4062: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4063: },
1.1 raeburn 4064: );
4065: my $datatable;
4066: my $count = 0;
4067: foreach my $item (@{$ordered}) {
1.56 raeburn 4068: my $colspan;
1.1 raeburn 4069: if ($item eq 'hidefromcat') {
4070: next if (!$can_toggle_cat);
4071: } elsif ($item eq 'categories') {
4072: next if (!$can_categorize);
1.64 raeburn 4073: } elsif ($item eq 'uniquecode') {
4074: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4075: }
1.56 raeburn 4076: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
4077: $colspan = 2;
4078: }
1.1 raeburn 4079: $count ++;
1.19 faziophi 4080: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 4081: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4082: } else {
1.56 raeburn 4083: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4084: }
1.1 raeburn 4085: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 4086: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4087: } elsif ($item eq 'cloners') {
4088: my $includeempty = 1;
4089: my $num = 0;
1.56 raeburn 4090: $datatable .= '</td><td align="right">'.
4091: &Apache::loncommon::start_data_table().
1.1 raeburn 4092: &Apache::loncommon::start_data_table_row().
4093: '<td><span class="LC_nobreak"><label>'.
4094: &mt('Any user in any domain:').
4095: ' <input type="radio" name="cloners_all" value="1" ';
4096: if ($settings->{$item} eq '*') {
4097: $datatable .= ' checked="checked" ';
4098: }
4099: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 4100: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4101: (' 'x2).'<label>'.
4102: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4103: if ($settings->{$item} ne '*') {
4104: $datatable .= ' checked="checked" ';
4105: }
4106: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 4107: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4108: &Apache::loncommon::end_data_table_row().
4109: &Apache::loncommon::end_data_table().
1.56 raeburn 4110: '<table><tr><td align="left"><b>'.&mt('Or').
4111: '</b></td></tr></table>'.
1.1 raeburn 4112: &Apache::loncommon::start_data_table();
4113: my @cloners;
4114: if ($settings->{$item} eq '') {
1.80 raeburn 4115: unless ($noedit) {
4116: my $default;
4117: if ($currcanclone eq 'domain') {
4118: $default = '0';
4119: }
4120: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 4121: }
1.1 raeburn 4122: } elsif ($settings->{$item} ne '*') {
4123: my @entries = split(/,/,$settings->{$item});
4124: if (@entries > 0) {
4125: foreach my $entry (@entries) {
4126: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4127: if ($udom =~ /^$match_domain$/) {
4128: unless (&Apache::lonnet::domain($udom)) {
4129: next;
4130: }
4131: } else {
4132: next;
4133: }
1.1 raeburn 4134: if ($uname eq '*') {
4135: $datatable .=
4136: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4137: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4138: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4139: '</b><input type="hidden" name="cloners_dom_'.$num.
4140: '" value="'.$udom.'" /></span><br />'.
4141: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4142: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4143: &mt('Delete').'</label></span></td>'.
4144: &Apache::loncommon::end_data_table_row();
4145: $num ++;
1.23 raeburn 4146: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4147: unless (grep(/^\Q$entry\E$/,@cloners)) {
4148: push(@cloners,$entry);
4149: }
1.1 raeburn 4150: }
4151: }
4152: }
4153: }
4154: my $add_domtitle = &mt('Any user in additional domain:');
4155: if ($settings->{$item} eq '*') {
4156: $add_domtitle = &mt('Any user in specific domain:');
4157: } elsif ($settings->{$item} eq '') {
4158: $add_domtitle = &mt('Any user in other domain:');
4159: }
4160: my $cloners_str = join(',',@cloners);
4161: $datatable .= &Apache::loncommon::start_data_table_row().
4162: '<td align="left"><span class="LC_nobreak">'.
4163: $add_domtitle.'</span><br />'.
4164: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 4165: $includeempty,undef,undef,
4166: undef,undef,$noedit).
1.1 raeburn 4167: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4168: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4169: &Apache::loncommon::end_data_table().
1.56 raeburn 4170: '<table><tr><td align="left"><b>'.&mt('And').
4171: '</b></td></tr></table>'.
1.1 raeburn 4172: &Apache::loncommon::start_data_table().
4173: &Apache::loncommon::start_data_table_row().
4174: '<td align="left">'.
4175: &mt('Specific users').' (<tt>'.
4176: &mt('user:domain,user:domain').'</tt>)<br />'.
4177: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 4178: $items{$item}{'size'},$disabled).
1.1 raeburn 4179: '</td>'.&Apache::loncommon::end_data_table_row().
4180: &Apache::loncommon::end_data_table();
1.71 raeburn 4181: if (@code_order > 0) {
4182: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4183: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4184: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4185: \%cat_items,\@codetitles,
4186: \%cat_titles,\%cat_order);
4187: my $showncodes = 'off';
4188: my $checkedoff = ' checked="checked"';
4189: my $checkedon = '';
4190: if ($cloner_instcode) {
4191: $checkedon = $checkedoff;
4192: $checkedoff = '';
4193: $showncodes = 'on';
4194: }
4195: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4196: '</b></td></tr></table>'.
4197: &Apache::loncommon::start_data_table().
4198: &Apache::loncommon::start_data_table_row().
4199: '<td align="left"><span class="LC_nobreak">'.
4200: &mt('Cloning by official course(s) based on course category').(' 'x2).
4201: '<label>'.
1.80 raeburn 4202: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4203: (' ').
4204: '<label>'.
1.80 raeburn 4205: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 4206: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4207: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 4208: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 4209: '</td>'.&Apache::loncommon::end_data_table_row().
4210: &Apache::loncommon::end_data_table();
4211: }
1.1 raeburn 4212: } elsif ($item eq 'rolenames') {
1.56 raeburn 4213: $datatable .= '</td><td align="right">'.
4214: &Apache::loncommon::start_data_table();
1.9 raeburn 4215: my @roles;
4216: if ($crstype eq 'Community') {
4217: @roles = ('co');
4218: } else {
4219: @roles = ('cc');
4220: }
4221: push (@roles,('in','ta','ep','ad','st'));
4222: foreach my $role (@roles) {
1.1 raeburn 4223: $datatable .= &Apache::loncommon::start_data_table_row().
4224: '<td align="left"><span class="LC_nobreak">'.
4225: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4226: '</span></td><td align="left">'.
4227: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4228: $settings->{$role.'.plaintext'},
1.80 raeburn 4229: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4230: &Apache::loncommon::end_data_table_row();
4231: }
4232: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4233: } elsif ($item eq 'categories') {
1.80 raeburn 4234: my $launcher;
4235: if ($noedit) {
4236: $launcher = $disabled;
4237: } else {
4238: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4239: }
1.3 raeburn 4240: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4241: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4242: $items{$item}{size},$launcher);
1.24 raeburn 4243: } elsif ($item eq 'owner') {
4244: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4245: if ($owner =~ /:/) {
4246: my ($ownername,$ownerdom) = split(':',$owner);
4247: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4248: } elsif ($owner ne '') {
4249: $owner = &Apache::loncommon::plainname($owner,$cdom);
4250: } else {
4251: $owner = &mt('None specified');
4252: }
4253: $datatable .= $owner;
1.63 raeburn 4254: } elsif ($item eq 'clonedfrom') {
4255: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4256: my $clonedfrom = &mt('None');
4257: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 4258: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 4259: if ($clonesrcinfo{'description'}) {
4260: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
4261: }
4262: }
4263: $datatable .= $clonedfrom;
1.64 raeburn 4264: } elsif ($item eq 'uniquecode') {
4265: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
4266: if ($code) {
4267: $datatable .= $code;
4268: }
1.25 raeburn 4269: } elsif ($item eq 'co-owners') {
4270: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4271: my @currcoown;
4272: if ($coowners) {
4273: @currcoown = split(',',$coowners);
4274: }
4275: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4276: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4277: $datatable .= &show_autocoowners(@currcoown);
4278: } else {
1.80 raeburn 4279: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4280: }
4281: } else {
4282: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4283: $datatable .= &show_autocoowners(@currcoown);
4284: } else {
1.80 raeburn 4285: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4286: }
4287: }
1.88 raeburn 4288: } elsif ($item eq 'syllabus') {
1.60 raeburn 4289: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4290: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4291: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4292: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4293: if ($minimal =~/\w/) {
4294: if ($external =~ m{\Q$minimal\E$}) {
4295: undef($external);
4296: }
4297: } elsif ($uploaded =~/\w/) {
4298: if ($external =~ m{\Q$uploaded\E$}) {
4299: undef($external);
4300: }
4301: }
4302: } elsif ($external!~/\w/) {
4303: undef($external);
4304: }
4305: if ($external) {
4306: $datatable .= &mt('External URL');
4307: } elsif ($minimal) {
4308: $datatable .= &mt('Minimal template');
4309: } elsif ($uploaded) {
4310: $datatable .= &mt('Uploaded file');
4311: } else {
4312: $datatable .= &mt('Standard template');
4313: }
4314: $datatable .= (' ' x 2).
4315: &mt('[_1]View[_2]',
4316: '<a href="javascript:syllabusinfo();">',
4317: '</a>');
1.35 raeburn 4318: } elsif ($item eq 'loncaparev') {
4319: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4320: my $showreqd;
4321: if ($loncaparev) {
1.36 raeburn 4322: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4323: &mt('Details').'</a>';
1.35 raeburn 4324: } else {
4325: $showreqd = &mt('No specific version required');
4326: }
4327: $datatable .= $showreqd;
1.1 raeburn 4328: } else {
1.80 raeburn 4329: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4330: }
4331: $datatable .= &item_table_row_end();
4332: }
4333: $$rowtotal += scalar(@{$ordered});
4334: return $datatable;
4335: }
4336:
4337: sub new_cloners_dom_row {
1.71 raeburn 4338: my ($newdom,$num,$default) = @_;
4339: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4340: if ($newdom ne '') {
1.71 raeburn 4341: if ($num eq $default) {
4342: $checkedon = 'checked="checked" ';
4343: } else {
4344: $checkedoff = 'checked="checked" ';
4345: }
1.1 raeburn 4346: $output .= &Apache::loncommon::start_data_table_row().
4347: '<td valign="top"><span class="LC_nobreak">'.
4348: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4349: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 4350: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4351: 'onchange="javascript:update_cloners('.
1.1 raeburn 4352: "'cloners_activate','$num'".');" />'.
4353: &mt('Yes').'</label>'.(' 'x2).
4354: '<label><input type="radio" '.
1.71 raeburn 4355: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4356: 'onchange="javascript:update_cloners('.
1.1 raeburn 4357: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4358: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4359: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4360: &Apache::loncommon::end_data_table_row();
4361: }
4362: return $output;
4363: }
4364:
4365: sub can_modify_catsettings {
1.12 raeburn 4366: my ($dom,$crstype) = @_;
1.1 raeburn 4367: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4368: my ($can_toggle_cat,$can_categorize);
4369: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4370: if ($crstype eq 'Community') {
4371: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4372: $can_toggle_cat = 1;
4373: }
4374: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4375: $can_categorize = 1;
4376: }
4377: } else {
4378: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4379: $can_toggle_cat = 1;
4380: }
4381: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4382: $can_categorize = 1;
4383: }
1.1 raeburn 4384: }
4385: }
4386: return ($can_toggle_cat,$can_categorize);
4387: }
4388:
4389: sub assign_course_categories {
1.9 raeburn 4390: my ($r,$crstype) = @_;
1.1 raeburn 4391: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4392: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4393: my $hascats = 0;
4394: my $cathash;
4395: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4396: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4397: $cathash = $domconf{'coursecategories'}{'cats'};
4398: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4399: foreach my $cat (keys(%{$cathash})) {
4400: next if ($cat eq 'instcode::0');
4401: unless ($crstype eq 'Community') {
4402: next if ($cat eq 'communities::0');
4403: }
4404: $hascats ++;
4405: }
1.1 raeburn 4406: }
4407: }
4408: my $catwin_js;
4409: if ($hascats) {
1.9 raeburn 4410: my $alert;
4411: if ($crstype eq 'Community') {
4412: $alert = &mt("Use 'Save' in the main window to save community categories");
4413: } else {
4414: $alert = &mt("Use 'Save' in the main window to save course categories");
4415: }
1.72 damieng 4416: &js_escape(\$alert);
1.1 raeburn 4417: $catwin_js = <<ENDSCRIPT;
4418: <script type="text/javascript">
4419:
4420: function updateCategories() {
4421: var newcategories = '';
4422: var unescapedcats = '';
4423: if (document.chgcats.usecategory.length) {
4424: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4425: if (document.chgcats.usecategory[i].checked == true) {
4426: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4427: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4428: }
4429: }
4430: if (newcategories.length > 0) {
4431: newcategories = newcategories.slice(0,-1);
4432: }
4433: if (unescapedcats.length > 0) {
4434: unescapedcats = unescapedcats.slice(0,-3);
4435: }
4436: } else {
4437: if (document.chgcats.usecategory.checked == true) {
4438: newcategories = document.chgcats.usecategory.value;
4439: unescapedcats = document.chgcats.catname.value;
4440: }
4441: }
4442: opener.document.display.categories.value = newcategories;
4443: opener.document.display.categories_display.value = unescapedcats;
4444: alert("$alert");
4445: self.close();
4446: return;
4447: }
4448:
4449: </script>
4450: ENDSCRIPT
4451: } else {
4452: my $onload;
4453: }
1.9 raeburn 4454: my ($crscat,$catcrs,$assign);
4455: if ($crstype eq 'Community') {
4456: $crscat = 'Community Categories';
4457: $catcrs = &mt('Categorize Community');
4458: $assign = &mt('Assign one or more categories to this community.')
4459: } else {
4460: $crscat = 'Course Categories';
4461: $catcrs = &mt('Categorize Course');
4462: $assign = &mt('Assign one or more categories to this course.')
4463: }
1.1 raeburn 4464: my $start_page =
1.9 raeburn 4465: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4466: {'only_body' => 1,});
4467: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4468: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4469: if ($hascats) {
4470: my %currsettings =
4471: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4472: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4473: $currsettings{'categories'},$crstype);
4474: if ($cattable eq '') {
4475: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4476: } else {
4477: $categoriesform .= $assign.'<br /><br />'.
4478: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4479: $cattable."\n".
4480: '<br /><input type="button" name="changes" value="'.
4481: &mt('Copy to main window').'" '.
4482: 'onclick="javascript:updateCategories()" /></form><br />';
4483: }
1.1 raeburn 4484: } else {
1.12 raeburn 4485: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4486: }
4487: $r->print($start_page.$categoriesform.$end_page);
4488: return;
4489: }
4490:
1.36 raeburn 4491: sub display_loncaparev_constraints {
4492: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.66 raeburn 4493: my ($reqdmajor,$reqdminor);
1.36 raeburn 4494: my $cid = $env{'request.course.id'};
4495: my $cdom = $env{'course.'.$cid.'.domain'};
4496: my $cnum = $env{'course.'.$cid.'.num'};
4497: my $output;
1.39 raeburn 4498: my %lt = &Apache::lonlocal::texthash (
4499: 'all' => 'all',
4500: 'section/group' => 'section/group',
4501: 'user' => 'user',
4502: );
1.66 raeburn 4503: &Apache::lonrelrequtils::init_global_hashes();
4504: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4505: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4506: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 4507: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4508: }
4509: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 4510: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 4511: @scopeorder = ('all','section/group','user');
1.67 raeburn 4512: my $now = time;
1.36 raeburn 4513: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4514: if (ref($resourcedata) eq 'HASH') {
4515: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 4516: my %found;
1.66 raeburn 4517: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4518: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 4519: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
4520: my $value = $resourcedata->{$key};
4521: if ($item eq 'examcode') {
4522: if (&Apache::lonnet::validCODE($value)) {
4523: $value = 'valid';
4524: } else {
4525: $value = '';
4526: }
4527: } elsif ($item eq 'printstartdate') {
1.67 raeburn 4528: if ($value =~ /^\d+$/) {
1.70 raeburn 4529: if ($value > $now) {
4530: $value = 'future';
4531: }
4532: }
4533: } elsif ($item eq 'printenddate') {
4534: if ($value =~ /^\d+$/) {
4535: if ($value < $now) {
4536: $value = 'past';
4537: }
4538: }
4539: }
4540: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
4541: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4542: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 4543: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 4544: }
4545: }
4546: }
4547: }
1.79 raeburn 4548: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
4549: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 4550: my $value = $resourcedata->{$key};
1.79 raeburn 4551: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 4552: if ($value =~ /$valuematch/) {
4553: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 4554: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 4555: $found{$item}{'rev'} =
1.76 raeburn 4556: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 4557: last;
4558: }
4559: }
4560: }
4561: }
1.76 raeburn 4562: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
4563: my $regexp;
4564: if ($item eq 'maplevelrecurse') {
4565: $regexp = '\.(?:sequence|page)___\(rec\)\.';
4566: }
4567: if ($regexp ne '') {
4568: if ($key =~ /$regexp.*\.(\w+)$/) {
4569: my $name = $1;
4570: my $value = $resourcedata->{$key};
4571: if ($name eq 'type') {
4572: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
4573: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
4574: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
4575: }
4576: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
4577: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
4578: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
4579: $found{$name}{'rev'} =
4580: $Apache::lonnet::needsrelease{'parameter::::'.$item};
4581: }
4582: }
4583: }
1.70 raeburn 4584: foreach my $item (keys(%found)) {
4585: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4586: my $rev = $found{$item}{'rev'};
4587: my $valname = $found{$item}{'valname'};
1.76 raeburn 4588: my $extra = $found{$item}{'extra'};
1.70 raeburn 4589: my ($middle,$scope,$which,$level,$map,$resource);
4590: my $start = $cid.'.';
4591: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4592: $middle = $1;
4593: $which = $2;
4594: $scope = 'user';
4595: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4596: $middle = $1;
4597: $which = $2;
4598: $scope = 'section/group';
4599: } else {
4600: $scope = 'all';
4601: }
4602: my $what="$stdname=$valname";
1.76 raeburn 4603: if ($extra) {
4604: $what .= "<br/>$extra<br />";
4605: }
1.70 raeburn 4606: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4607: $level = 'general';
4608: if ($scope eq 'all') {
4609: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4610: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4611: push(@{$fromparam{$rev}{$scope}},$what);
4612: }
4613: } else {
4614: push(@{$fromparam{$rev}{$scope}},$what);
4615: }
4616: } else {
4617: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4618: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4619: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4620: }
4621: } else {
4622: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4623: }
4624: }
4625: $rowspan{$rev} ++;
1.76 raeburn 4626: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 4627: $level = 'folder';
4628: $map = $1;
4629: if ($scope eq 'all') {
4630: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4631: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4632: push(@{$bymap{$map}{$rev}{$scope}},$what);
4633: }
4634: } else {
4635: push(@{$bymap{$map}{$rev}{$scope}},$what);
4636: }
4637: } else {
4638: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4639: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4640: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4641: }
4642: } else {
4643: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4644: }
4645: }
4646: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4647: $level = 'resource';
4648: $resource = $1;
4649: if ($scope eq 'all') {
4650: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4651: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4652: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4653: }
4654: } else {
4655: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4656: }
4657: } else {
4658: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4659: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4660: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4661: }
4662: } else {
4663: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 4664: }
4665: }
4666: }
4667: }
4668: }
4669: if (keys(%fromparam)) {
4670: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4671: &Apache::loncommon::start_data_table().
4672: &Apache::loncommon::start_data_table_header_row().
4673: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4674: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4675: &Apache::loncommon::end_data_table_header_row();
4676: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 4677: my ($major,$minor) = split(/\./,$rev);
4678: ($reqdmajor,$reqdminor) =
4679: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4680: $output .= &Apache::loncommon::start_data_table_row().
4681: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4682: my $newrow;
4683: foreach my $scope (@scopeorder) {
4684: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4685: if ($newrow) {
4686: $output .= &Apache::loncommon::continue_data_table_row();
4687: }
1.39 raeburn 4688: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4689: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4690: $output .= '<td>'.$which.'</td><td>'.
4691: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4692: }
4693: $output .= &Apache::loncommon::end_data_table_row();
4694: $newrow = 1;
4695: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4696: if ($newrow) {
4697: $output .= &Apache::loncommon::continue_data_table_row();
4698: }
1.39 raeburn 4699: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4700: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4701: &Apache::loncommon::end_data_table_row();
4702: $newrow = 1;
4703: }
4704: }
4705: }
4706: $output .= &Apache::loncommon::end_data_table().'<br />';
4707: }
4708: }
4709:
1.66 raeburn 4710: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4711: my $now = time;
4712: if (keys(%comm_blocks) > 0) {
4713: foreach my $block (keys(%comm_blocks)) {
4714: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 4715: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 4716: if (ref($comm_blocks{$block}) eq 'HASH') {
4717: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4718: ' '.&mt('set by [_1]',
4719: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4720: }
4721: next;
4722: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4723: my ($start,$end) = ($1,$2);
4724: next if ($end < $now);
4725: }
4726: if (ref($comm_blocks{$block}) eq 'HASH') {
4727: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4728: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4729: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 4730: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 4731: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4732: ' '.
4733: &mt('set by [_1]',
4734: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4735: }
4736: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 4737: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 4738: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4739: ' '.
4740: &mt('set by [_1]',
4741: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4742:
4743: }
4744: }
4745: }
4746: }
4747: if (keys(%fromblocks)) {
4748: my %lt = (
4749: docs => 'Content blocking',
4750: printout => 'Printout generation',
4751: timer => 'Timed quiz trigger',
4752: );
4753: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4754: &Apache::loncommon::start_data_table().
4755: &Apache::loncommon::start_data_table_header_row().
4756: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4757: '<th>'.&mt('Event(s)').'</th>'.
4758: &Apache::loncommon::end_data_table_header_row();
4759: foreach my $type ('docs','printout','timer') {
4760: if (ref($fromblocks{$type}) eq 'HASH') {
4761: foreach my $rev (keys(%{$fromblocks{$type}})) {
4762: my ($major,$minor) = split(/\./,$rev);
4763: ($reqdmajor,$reqdminor) =
4764: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4765: $output .= &Apache::loncommon::start_data_table_row().
4766: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4767: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4768: $output .= $event.'<br />';
4769: }
4770: $output =~ s{\Q<br />\E$}{};
4771: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4772: }
4773: }
4774: }
4775: $output .= &Apache::loncommon::end_data_table().'<br />';
4776: }
4777: }
4778:
1.36 raeburn 4779: if (defined($navmap)) {
4780: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 4781: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 4782: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 4783: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 4784: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 4785: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4786: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4787: my $valanon=&get_param_description($stdtype,'anonsurvey');
4788: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 4789: my %checkedrev;
1.85 raeburn 4790: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 4791: my @parts = @{$res->parts()};
4792: my $symb = $res->symb();
4793: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 4794: if ($res->is_tool()) {
4795: my $rev = $rev_exttool;
4796: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
4797: $allmaps{$enclosing_map} = 1;
4798: next;
4799: }
1.36 raeburn 4800: foreach my $part (@parts) {
4801: if (exists($anonsubms{$symb."\0".$part})) {
4802: my $rev = $rev_anonsurv;
4803: my $what="$stdname=$valanon";
4804: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4805: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4806: push(@{$bysubmission{$symb}{$rev}},$what);
4807: }
4808: } else {
4809: push(@{$bysubmission{$symb}{$rev}},$what);
4810: }
4811: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4812: unless ($checkedrev{'anonsurvey'}) {
4813: my ($major,$minor) = split(/\./,$rev);
4814: ($reqdmajor,$reqdminor) =
4815: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4816: $reqdmajor,$reqdminor);
4817: $checkedrev{'anonsurvey'} = 1;
4818: }
1.36 raeburn 4819: }
4820: if (exists($randtrysubms{$symb."\0".$part})) {
4821: my $rev = $rev_randtry;
4822: my $what="$stdname=$valrandtry";
4823: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4824: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4825: push(@{$bysubmission{$symb}{$rev}},$what);
4826: }
4827: } else {
4828: push(@{$bysubmission{$symb}{$rev}},$what);
4829: }
4830: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4831: unless ($checkedrev{'randomizetry'}) {
4832: my ($major,$minor) = split(/\./,$rev);
4833: ($reqdmajor,$reqdminor) =
4834: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4835: $reqdmajor,$reqdminor);
4836: $checkedrev{'randomizetry'} = 1;
4837: }
1.36 raeburn 4838: }
4839: }
4840: my %responses = $res->responseTypes();
4841: foreach my $key (keys(%responses)) {
1.66 raeburn 4842: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4843: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4844: unless ($checkedrev{$key}) {
4845: my ($major,$minor) = split(/\./,$rev);
4846: ($reqdmajor,$reqdminor) =
4847: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4848: $reqdmajor,$reqdminor);
4849: $checkedrev{$key} = 1;
4850: }
4851: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4852: $allmaps{$enclosing_map} = 1;
4853: }
4854: }
4855: }
4856: if (keys(%byresource) > 0) {
4857: foreach my $symb (keys(%byresource)) {
4858: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4859: $allmaps{$map} = 1;
4860: }
4861: }
4862: if (keys(%bymap) > 0) {
4863: foreach my $map (keys(%bymap)) {
4864: $allmaps{$map} = 1;
4865: }
4866: }
4867: foreach my $map (keys(%allmaps)) {
4868: my $mapres = $navmap->getResourceByUrl($map);
4869: if (ref($mapres)) {
1.68 raeburn 4870: my $mapsymb = $mapres->symb();
4871: $toshow{$mapsymb} = 1;
1.36 raeburn 4872: my $pcslist = $mapres->map_hierarchy();
4873: if ($pcslist ne '') {
4874: foreach my $pc (split(/,/,$pcslist)) {
4875: my $res = $navmap->getByMapPc($pc);
4876: if (ref($res)) {
4877: my $symb = $res->symb();
4878: unless ($symb eq '______') {
4879: $toshow{$symb} = 1;
4880: }
4881: }
4882: }
4883: }
4884: }
4885: }
4886: }
1.117 raeburn 4887: my $supptools = &Apache::lonnet::count_supptools($cnum,$cdom,1,1);
1.36 raeburn 4888: my $mapres_header = '<h4>'.
4889: &mt('Requirements for specific folders or resources').
4890: '</h4>';
4891: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4892: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4893: $output .= $mapres_header;
4894: }
4895: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4896: my $title = 'Version Constraints';
4897: my $start_page =
4898: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4899: $r->print($start_page.$top_header);
4900: if ($output) {
4901: $r->print($output);
1.86 raeburn 4902: if (defined($navmap) || $supptools) {
1.36 raeburn 4903: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4904: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4905: }
4906: $r->print('<br /><br />');
4907: } else {
4908: $r->print('<p class="LC_info">'.
4909: &mt('No version requirements from resource content or settings.').
4910: '</p>');
4911: }
4912: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4913: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4914: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4915: return 1;
4916: }
1.36 raeburn 4917: return;
4918: }
4919:
4920: sub show_contents_view {
1.39 raeburn 4921: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 4922: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
4923: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4924: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4925: my $showmaincontent;
4926: if ((ref($navmap)) &&
4927: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4928: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
4929: (keys(%{$bycrsrestype}) > 0))) {
4930: $showmaincontent = 1;
4931: }
4932: if ($showmaincontent || $supptools) {
4933: $r->print(&Apache::loncommon::start_data_table());
4934: }
4935: if ($showmaincontent) {
4936: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 4937: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 4938: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 4939: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4940: '<th>'.&mt('Attribute/Setting').'</th>'.
4941: &Apache::loncommon::end_data_table_header_row().
4942: &Apache::loncommon::start_data_table_row().
1.58 raeburn 4943: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 4944: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
4945: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4946: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4947: my $curRes;
4948: my $depth = 0;
4949: my %parent = ();
4950: my $startcount = 5;
4951: my $lastcontainer = $startcount;
4952: while ($curRes = $it->next()) {
4953: if ($curRes == $it->BEGIN_MAP()) {
4954: $depth++;
4955: $parent{$depth}= $lastcontainer;
4956: }
4957: if ($curRes == $it->END_MAP()) {
4958: $depth--;
4959: $lastcontainer = $parent{$depth};
4960: }
4961: my $indent;
4962: for (my $i=0; $i<$depth; $i++) {
4963: $indent.= $whitespace;
4964: }
4965: if (ref($curRes)) {
4966: my $symb = $curRes->symb();
4967: my $ressymb = $symb;
4968: my $srcf = $curRes->src();
4969: my $title = &Apache::lonnet::gettitle($srcf);
4970: if (($curRes->is_sequence()) || ($curRes->is_page())) {
4971: next unless($toshow->{$symb});
4972: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
4973: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4974: if ($curRes->is_page()) {
4975: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
4976: }
4977: my $rowspan = 1;
4978: if (ref($bymap->{$url}) eq 'HASH') {
4979: $rowspan = scalar(keys(%{$bymap->{$url}}));
4980: }
4981: $r->print(&Apache::loncommon::start_data_table_row().
4982: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 4983: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 4984: $r->print(&Apache::loncommon::end_data_table_row());
4985: } else {
4986: my $rowspan;
4987: if (ref($byresource->{$symb}) eq 'HASH') {
4988: $rowspan += scalar(keys(%{$byresource->{$symb}}));
4989: }
4990: if (ref($bysubmission->{$symb}) eq 'HASH') {
4991: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
4992: }
4993: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4994: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
4995: }
1.85 raeburn 4996: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
4997: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
4998: }
1.36 raeburn 4999: next if (!$rowspan);
5000: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
5001: &mt('Problem').'" />';
5002: $r->print(&Apache::loncommon::start_data_table_row().
5003: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
5004: my $newrow;
5005: if (ref($byresource->{$symb}) eq 'HASH') {
5006: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
5007: if ($newrow) {
5008: $r->print(&Apache::loncommon::continue_data_table_row());
5009: }
5010: $r->print('<td valign="middle">'.$rev.'</td><td>');
5011: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
5012: $r->print('<table border="0">');
5013: foreach my $scope (@{$scopeorder}) {
5014: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5015: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5016: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
5017: $r->print('<td>'.$which.'</td><td>'.
5018: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
5019: '</td>');
5020: }
5021: $r->print('</tr>');
5022: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5023: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 5024: '<td> </td><td>'.
5025: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
5026: }
5027: }
5028: $r->print('</table>');
5029: }
5030: $r->print('</td>');
5031: $r->print(&Apache::loncommon::end_data_table_row());
5032: $newrow = 1;
5033: }
5034: }
5035: if (ref($bysubmission->{$symb}) eq 'HASH') {
5036: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
5037: if ($newrow) {
5038: $r->print(&Apache::loncommon::continue_data_table_row());
5039: }
5040: $r->print('<td>'.$rev.'</td><td>');
5041: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
5042: $r->print(&mt('Submissions to: ').' '.
5043: join(', ',@{$bysubmission->{$symb}{$rev}}));
5044: }
5045: $r->print('</td>');
5046: $r->print(&Apache::loncommon::end_data_table_row());
5047: $newrow = 1;
5048: }
5049: }
5050: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5051: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
5052: if ($newrow) {
5053: $r->print(&Apache::loncommon::continue_data_table_row());
5054: }
5055: $r->print('<td>'.$rev.'</td><td>');
5056: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
5057: $r->print(&mt('Response Type(s): ').' '.
5058: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
5059: }
5060: $r->print('</td>');
5061: }
5062: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 5063: $newrow = 1;
5064: }
5065: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5066: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
5067: if ($newrow) {
5068: $r->print(&Apache::loncommon::continue_data_table_row());
5069: }
5070: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
5071: }
1.86 raeburn 5072: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5073: }
5074: }
5075: }
5076: }
1.86 raeburn 5077: }
5078: if ($supptools) {
5079: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5080: $r->print(&Apache::loncommon::start_data_table_header_row().
5081: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5082: '<th>'.&mt('Resource Type').'</th>'.
5083: &Apache::loncommon::end_data_table_header_row().
5084: &Apache::loncommon::start_data_table_row().
5085: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
5086: '<td valign="middle">'.
5087: $Apache::lonrelrequtils::exttool{'major'}.'.'.
5088: $Apache::lonrelrequtils::exttool{'minor'}.
5089: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
5090: $supptools).'</td>'.
5091: &Apache::loncommon::end_data_table_row());
5092: }
5093: if ($showmaincontent || $supptools) {
1.36 raeburn 5094: $r->print(&Apache::loncommon::end_data_table());
5095: }
1.66 raeburn 5096: return;
1.36 raeburn 5097: }
5098:
5099: sub releases_by_map {
1.39 raeburn 5100: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 5101: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.73 raeburn 5102: my $newrow = 0;
1.36 raeburn 5103: if (ref($bymap->{$url}) eq 'HASH') {
5104: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 5105: if ($newrow) {
5106: $r->print(&Apache::loncommon::end_data_table_row().
5107: &Apache::loncommon::continue_data_table_row());
5108: }
1.36 raeburn 5109: $r->print('<td valign="middle">'.$rev.'</td><td>');
5110: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
5111: $r->print('<table border="0">');
5112: foreach my $scope (@{$scopeorder}) {
5113: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5114: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5115: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
5116: $r->print('<td>'.$which.'</td><td>'.
5117: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
5118: '</td>');
5119: }
5120: $r->print('</tr>');
5121: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5122: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 5123: '</td><td> </td><td>'.
5124: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
5125: }
5126: }
5127: $r->print('</table>');
5128: }
5129: $r->print('</td>');
1.73 raeburn 5130: $newrow = 1;
1.36 raeburn 5131: }
5132: } else {
5133: $r->print('<td colspan="2"> </td>');
5134: }
5135: return;
5136: }
5137:
5138: sub get_param_description {
1.70 raeburn 5139: my ($stdtype,$value,$regexp) = @_;
5140: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 5141: if ($stdtype =~ /^string/) {
5142: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5143: } elsif ($stdtype eq 'date_interval') {
5144: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
5145: }
1.70 raeburn 5146: if ($regexp) {
1.74 raeburn 5147: if ($stdtype =~ /^string/) {
5148: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
5149: } elsif ($stdtype eq 'date_interval') {
5150: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
5151: }
1.70 raeburn 5152: if (ref($parammatches) eq 'ARRAY') {
5153: @possibles = @{$parammatches};
5154: } else {
5155: undef($regexp);
5156: $name = $value;
5157: }
5158: }
5159: unless ($regexp) {
5160: $name = $value;
5161: if (ref($paramstrings) eq 'ARRAY') {
5162: @possibles = @{$paramstrings};
5163: } else {
1.76 raeburn 5164: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
5165: if ($name == 0) {
5166: $name = &mt('Never');
5167: } elsif (($name ne '') && ($name !~ /\D/)) {
5168: $name = &Apache::lonlocal::locallocaltime($name);
5169: }
5170: }
1.70 raeburn 5171: return $name;
5172: }
1.36 raeburn 5173: }
1.70 raeburn 5174: foreach my $possibilities (@possibles) {
1.36 raeburn 5175: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 5176: my $gotregexmatch = '';
5177: if ($regexp) {
5178: last if ($gotregexmatch);
5179: my ($item,$pattern) = @{ $possibilities };
5180: if ($value =~ /$pattern/) {
5181: if (ref($paramstrings) eq 'ARRAY') {
5182: foreach my $possibles (@{$paramstrings}) {
5183: next unless (ref($possibles) eq 'ARRAY');
5184: my ($thing,$description) = @{$possibles};
5185: if ($thing eq $item) {
5186: $name = $description;
5187: $gotregexmatch = 1;
5188: last;
5189: }
5190: }
5191: last if ($gotregexmatch);
5192: }
5193: }
5194: } else {
5195: my ($thing,$description) = @{ $possibilities };
5196: if ($thing eq $value) {
5197: $name = $description;
5198: last;
5199: }
1.36 raeburn 5200: }
5201: }
5202: return $name;
5203: }
5204:
1.66 raeburn 5205: sub update_releasereq {
5206: my $readmap = 1;
5207: my $getrelreq = 1;
5208: if (ref($modified_courses) eq 'ARRAY') {
5209: foreach my $item (@{$modified_courses}) {
5210: if (ref($item) eq 'ARRAY') {
5211: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5212: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5213: $chome,$crstype,$cdom.'_'.$cnum,
5214: $readmap,$getrelreq);
5215: }
5216: }
5217: $modified_courses = [];
5218: }
5219: undef($registered_cleanup);
5220: return;
5221: }
5222:
1.25 raeburn 5223: sub show_autocoowners {
5224: my (@currcoown) = @_;
1.56 raeburn 5225: 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 5226: if (@currcoown > 0) {
5227: $output .= '<br />'.&mt('Current co-owners are:').' '.
5228: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5229: } else {
5230: $output .= '<br />'.&mt('Currently no co-owners.');
5231: }
5232: return $output;
5233: }
5234:
5235: sub coowner_invitations {
1.80 raeburn 5236: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5237: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5238: my $pendingcoowners =
5239: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5240: if ($pendingcoowners) {
5241: @pendingcoown = split(',',$pendingcoowners);
5242: }
1.80 raeburn 5243: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5244: @currcoown = @{$currcoownref};
1.80 raeburn 5245: }
5246: my $disabled;
5247: if ($noedit) {
5248: $disabled = ' disabled="disabled"';
5249: }
1.25 raeburn 5250: my $ccrole = 'cc';
5251: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5252: foreach my $key (sort(keys(%ccroles))) {
5253: my ($ccname,$ccdom,$role) = split(':',$key);
5254: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5255: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5256: push(@othercoords,$ccname.':'.$ccdom);
5257: }
5258: }
5259: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5260: if ($coowner_rows) {
5261: $output .= &Apache::loncommon::start_data_table();
5262: if (@currcoown) {
5263: $output .= &Apache::loncommon::start_data_table_row().
5264: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5265: foreach my $person (@currcoown) {
5266: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5267: $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 5268: }
5269: $output .= '</td>'.
5270: &Apache::loncommon::end_data_table_row();
5271: }
5272: if ($pendingcoowners) {
5273: $output .= &Apache::loncommon::start_data_table_row().
5274: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5275: foreach my $person (@pendingcoown) {
5276: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5277: $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 5278: }
5279: $output .= '</td>'.
5280: &Apache::loncommon::end_data_table_row();
5281: }
5282: if (@othercoords) {
5283: $output .= &Apache::loncommon::start_data_table_row().
5284: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5285: foreach my $person (@othercoords) {
5286: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5287: $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 5288: }
5289: $output .= '</td>'.
5290: &Apache::loncommon::end_data_table_row();
5291: }
5292: $output .= &Apache::loncommon::end_data_table();
5293: } else {
5294: $output = &mt('There are no coordinators to select as co-owners');
5295: }
5296: return $output;
5297: }
5298:
5299: sub manage_coownership {
1.80 raeburn 5300: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5301: my (@pendingcoown,@currcoown);
1.25 raeburn 5302: my $pendingcoowners =
5303: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5304: if ($pendingcoowners) {
5305: @pendingcoown = split(',',$pendingcoowners);
5306: }
1.80 raeburn 5307: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5308: @currcoown = @{$currcoownref};
1.80 raeburn 5309: }
5310: my $disabled;
5311: if ($noedit) {
5312: $disabled = ' disabled="disabled"';
5313: }
1.25 raeburn 5314: my ($is_coowner,$is_pending,$output);
5315: my $uname = $env{'user.name'};
5316: my $udom = $env{'user.domain'};
5317: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5318: $is_coowner = 1;
5319: }
5320: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5321: $is_pending = 1;
5322: }
5323: if (@currcoown && ($is_coowner || $is_pending)) {
5324: $output = &Apache::loncommon::start_data_table();
5325: }
5326: if (@currcoown) {
5327: if ($is_coowner || $is_pending) {
5328: $output .= &Apache::loncommon::start_data_table().
5329: &Apache::loncommon::start_data_table_row().'<td>';
5330: }
5331: $output .= &mt('Current co-owners are:').' '.
5332: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5333: if ($is_coowner || $is_pending) {
5334: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5335: }
5336: }
5337: if ($is_coowner || $is_pending) {
5338: if (@currcoown) {
5339: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5340: }
5341: $output .= '<span class="LC_nobreak">';
5342: if ($is_coowner) {
1.90 raeburn 5343: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5344: } else {
1.90 raeburn 5345: $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).
5346: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5347: }
5348: $output .= '</span>';
5349: if (@currcoown) {
5350: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5351: }
5352: }
5353: if (@currcoown && ($is_coowner || $is_pending)) {
5354: $output .= &Apache::loncommon::end_data_table();
5355: }
5356: return $output;
5357: }
5358:
1.1 raeburn 5359: sub print_localization {
1.80 raeburn 5360: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5361: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5362: return;
5363: }
5364: my %items = (
5365: languages => {
1.17 faziophi 5366: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5367: &mt("(overrides individual user preference)"),
1.1 raeburn 5368: input => 'selectbox',
5369: },
5370: timezone => {
1.17 faziophi 5371: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5372: input => 'selectbox',
5373: },
5374: datelocale => {
1.17 faziophi 5375: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5376: input => 'selectbox',
5377: },
5378: );
1.80 raeburn 5379: my ($datatable,$disabled);
1.1 raeburn 5380: my $count = 0;
1.80 raeburn 5381: if ($noedit) {
5382: $disabled = ' disabled="disabled"';
5383: }
1.1 raeburn 5384: foreach my $item (@{$ordered}) {
5385: $count ++;
1.56 raeburn 5386: my $colspan;
5387: unless ($item eq 'languages') {
1.80 raeburn 5388: $colspan = 2;
1.56 raeburn 5389: }
5390: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5391: if ($item eq 'timezone') {
5392: my $includeempty = 1;
5393: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5394: my $onchange;
5395: unless ($noedit) {
5396: $onchange = ' onchange="javascript:toggleTimeZone();"';
5397: }
5398: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5399: $datatable .=
1.115 raeburn 5400: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5401: $includeempty,$id,$disabled);
5402: my $tzsty = 'none';
5403: if ($timezone ne '') {
5404: $tzsty = 'block';
5405: }
5406: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5407: '<span class="LC_nobreak">'.
5408: &mt('Override individual user preference?').
5409: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5410: '</span></div>';
1.1 raeburn 5411: } elsif ($item eq 'datelocale') {
5412: my $includeempty = 1;
5413: my $locale_obj = &Apache::lonlocal::getdatelocale();
5414: my $currdatelocale;
5415: if (ref($locale_obj)) {
5416: $currdatelocale = $locale_obj->id();
5417: }
5418: $datatable .=
5419: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5420: undef,$includeempty,$disabled);
1.1 raeburn 5421: } else {
5422: if ($settings->{$item} eq '') {
1.80 raeburn 5423: unless ($noedit) {
5424: $datatable .= '</td><td align="right">'.
5425: &Apache::loncommon::select_language('languages_0','',1);
5426: }
1.1 raeburn 5427: } else {
5428: my $num = 0;
1.3 raeburn 5429: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5430: $datatable .= '</td><td align="right"><br />'.
5431: &Apache::loncommon::start_data_table();
1.1 raeburn 5432: if (@languages > 0) {
1.3 raeburn 5433: my %langchoices = &get_lang_choices();
1.1 raeburn 5434: foreach my $lang (@languages) {
5435: my $showlang = $lang;
1.3 raeburn 5436: if (exists($langchoices{$lang})) {
5437: $showlang = $langchoices{$lang};
1.1 raeburn 5438: }
5439: $datatable .=
5440: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5441: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5442: &mt('Language:').'<b> '.$showlang.
5443: '</b><input type="hidden" name="languages_'.$num.
5444: '" value="'.$lang.'" /></span><br />'.
5445: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5446: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5447: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5448: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5449: $num ++;
5450: }
5451: }
1.80 raeburn 5452: unless ($noedit) {
5453: $datatable .=
5454: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5455: '<td align="left"><span class="LC_nobreak">'.
5456: &mt('Additional language:'). '</span><br />'.
5457: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5458: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5459: '</td>'.&Apache::loncommon::end_data_table_row();
5460: }
5461: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5462: }
5463: }
5464: $datatable .= &item_table_row_end();
5465: }
5466: $$rowtotal += scalar(@{$ordered});
5467: return $datatable;
5468: }
5469:
1.3 raeburn 5470: sub get_lang_choices {
5471: my %langchoices;
5472: foreach my $id (&Apache::loncommon::languageids()) {
5473: my $code = &Apache::loncommon::supportedlanguagecode($id);
5474: if ($code) {
5475: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5476: }
5477: }
5478: return %langchoices;
5479: }
5480:
1.1 raeburn 5481: sub print_feedback {
1.80 raeburn 5482: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5483: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5484: return;
5485: }
5486: my %items = (
1.3 raeburn 5487: 'question.email' => {
5488: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5489: input => 'textbox',
5490: size => '50',
5491: },
5492:
1.3 raeburn 5493: 'comment.email' => {
5494: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5495: input => 'textbox',
5496: size => '50',
5497: },
5498:
1.3 raeburn 5499: 'policy.email' => {
5500: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5501: input => 'textbox',
5502: size => '50',
5503: },
5504: );
5505: my $datatable;
5506: my $count = 0;
5507: my ($cnum) = &get_course();
5508: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5509: my @sections = sort( { $a <=> $b } keys(%sections));
5510: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5511: currone => 'Current recipient:',
5512: currmult => 'Current recipients:',
5513: add => 'Additional recipient:',
5514: del => 'Delete?',
5515: sec => 'Sections:',
1.1 raeburn 5516: );
1.80 raeburn 5517: my $disabled;
5518: if ($noedit) {
5519: $disabled = ' disabled="disabled"';
5520: }
1.1 raeburn 5521: foreach my $item (@{$ordered}) {
5522: $count ++;
1.20 faziophi 5523: if ($position eq 'top') {
5524: $datatable .= &item_table_row_start($items{$item}{text},$count);
5525: } else {
1.56 raeburn 5526: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5527: }
1.1 raeburn 5528: if ($position eq 'top') {
5529: my $includeempty = 0;
1.94 raeburn 5530: $datatable .= '</td><td align="right">'.
5531: &user_table($cdom,$item,\@sections,
1.80 raeburn 5532: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5533: } else {
1.3 raeburn 5534: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5535: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5536: }
5537: $datatable .= &item_table_row_end();
5538: }
5539: $$rowtotal += scalar(@{$ordered});
5540: return $datatable;
5541: }
5542:
5543: sub user_table {
1.80 raeburn 5544: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5545: my $output;
5546: if ($currvalue eq '') {
1.80 raeburn 5547: unless ($noedit) {
5548: $output .= &select_recipient($item,'0',$cdom,$sections);
5549: }
1.1 raeburn 5550: } else {
5551: my $num = 0;
5552: my @curr = split(/,/,$currvalue);
1.56 raeburn 5553: $output .= '<table class="LC_data_table">';
1.1 raeburn 5554: my ($currusers);
1.80 raeburn 5555: my $disabled;
5556: if ($noedit) {
5557: $disabled = ' disabled="disabled"';
5558: }
1.1 raeburn 5559: foreach my $val (@curr) {
5560: next if ($val eq '');
5561: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5562: my @selsec;
5563: if ($seclist) {
5564: $seclist =~ s/(^\(|\)$)//g;
5565: @selsec = split(/\s*;\s*/,$seclist);
5566: }
5567: $currusers .= '<tr>'.
5568: '<td valign="top"><span class="LC_nobreak">'.
5569: '<label><input type="checkbox" '.
1.80 raeburn 5570: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5571: $lt->{'del'}.'</label>'.
5572: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5573: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5574: &Apache::loncommon::aboutmewrapper(
5575: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5576: $uname,$udom,'aboutuser');
5577: if (ref($sections) eq 'ARRAY') {
5578: if (@{$sections}) {
5579: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5580: &select_sections($item,$num,$sections,
1.80 raeburn 5581: \@selsec,$noedit);
1.1 raeburn 5582: }
5583: }
5584: $currusers .= '</span></td></tr>';
5585: $num ++;
5586: }
5587: if ($num) {
1.10 raeburn 5588: $output .= '<tr>'.
1.1 raeburn 5589: '<td align="left"><i>';
1.20 faziophi 5590: if ($num == 1) {
1.1 raeburn 5591: $output .= $lt->{'currone'};
5592: } else {
1.21 raeburn 5593: $output .= $lt->{'currmult'};
1.1 raeburn 5594: }
5595: $output .= '</i><br />'.
5596: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5597: '</tr>';
1.1 raeburn 5598: }
1.80 raeburn 5599: unless ($noedit) {
5600: $output .=
5601: '<tr>'.
1.1 raeburn 5602: '<td align="left"><span class="LC_nobreak"><i>'.
5603: $lt->{'add'}.'</i></span><br />'.
5604: &select_recipient($item,$num,$cdom,$sections).
5605: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5606: '</td></tr>';
5607: }
5608: $output .= '</table>';
1.1 raeburn 5609: }
5610: return $output;
5611: }
5612:
5613: sub select_recipient {
5614: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5615: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5616: my $selectlink =
5617: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5618: $item.'_udom_'.$num,'only');
1.1 raeburn 5619: my $output =
1.10 raeburn 5620: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5621: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5622: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5623: if (ref($sections) eq 'ARRAY') {
5624: if (@{$sections}) {
5625: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5626: &select_sections($item,$num,$sections,$selected).'</td>';
5627: }
5628: }
5629: $output .= '<td valign="top">'.
5630: $selectlink.'</td></tr></table>';
5631: return $output;
5632: }
5633:
5634: sub select_sections {
1.80 raeburn 5635: my ($item,$num,$sections,$selected,$noedit) = @_;
5636: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5637: if (ref($selected) eq 'ARRAY') {
5638: @currsecs = @{$selected};
5639: }
5640: if (!@currsecs) {
5641: $allsec = ' selected="selected"';
5642: }
1.80 raeburn 5643: if ($noedit) {
5644: $disabled = ' disabled="disabled"';
5645: }
1.1 raeburn 5646: if (ref($sections) eq 'ARRAY') {
5647: if (@{$sections}) {
5648: my $mult;
5649: if (@{$sections} > 1) {
5650: $mult = ' multiple="multiple"';
5651: if (@{$sections} > 3) {
5652: $mult .= ' size="4"';
5653: }
5654: }
1.80 raeburn 5655: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
1.1 raeburn 5656: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
5657: foreach my $sec (@{$sections}) {
5658: my $is_sel;
5659: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
5660: $is_sel = 'selected="selected"';
5661: }
5662: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5663: }
5664: $output .= '</select>';
5665: }
5666: }
5667: return $output;
5668: }
5669:
5670: sub print_discussion {
1.80 raeburn 5671: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5672: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5673: return;
5674: }
5675: my %items = (
5676: 'plc.roles.denied' => {
1.10 raeburn 5677: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5678: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5679: &mt('(role-based)'),
1.1 raeburn 5680: input => 'checkbox',
5681: },
5682:
5683: 'plc.users.denied' => {
1.3 raeburn 5684: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5685: &mt('(specific user(s))'),
1.1 raeburn 5686: input => 'checkbox',
5687: },
5688:
5689: 'pch.roles.denied' => {
1.10 raeburn 5690: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5691: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5692: &mt('(role-based)'),
1.1 raeburn 5693: input => 'checkbox',
5694: },
5695:
5696: 'pch.users.denied' => {
1.3 raeburn 5697: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5698: &mt('(specific user(s))'),
1.1 raeburn 5699: input => 'checkbox',
5700: },
1.77 raeburn 5701:
5702: 'pac.roles.denied' => {
5703: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5704: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5705: &mt('(role-based)'),
5706: input => 'checkbox',
5707: },
5708:
5709: 'pac.users.denied' => {
5710: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5711: &mt('(specific user(s))'),
5712: input => 'checkbox',
5713: },
5714:
1.1 raeburn 5715: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5716: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5717: input => 'radio',
5718: },
5719:
5720: 'allow_discussion_post_editing' => {
1.3 raeburn 5721: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5722: input => 'checkbox',
5723: },
1.50 raeburn 5724: 'discussion_post_fonts' => {
5725: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5726: input => 'textbox',
5727: size => '20',
5728: },
1.1 raeburn 5729: );
5730: my $datatable;
5731: my $count;
5732: my ($cnum) = &get_course();
5733: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5734: my @sections = sort( { $a <=> $b } keys(%sections));
5735: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5736: currone => 'Disallowed:',
5737: currmult => 'Disallowed:',
5738: add => 'Disallow more:',
5739: del => 'Delete?',
5740: sec => 'Sections:',
1.1 raeburn 5741: );
5742: foreach my $item (@{$ordered}) {
5743: $count ++;
1.56 raeburn 5744: my $colspan;
5745: if ($item eq 'allow_limited_html_in_feedback') {
5746: $colspan = 2;
5747: }
5748: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5749: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5750: $datatable .= '</td><td align="right">'.
1.80 raeburn 5751: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5752: '</table>';
5753: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5754: $datatable .= '</td><td align="right">'.
5755: &user_table($cdom,$item,undef,
1.80 raeburn 5756: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5757: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5758: $datatable .= '</td><td align="right">'.
1.80 raeburn 5759: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5760: '</table>';
5761: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5762: $datatable .= '</td><td align="right">'.
5763: &user_table($cdom,$item,undef,
1.80 raeburn 5764: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5765: } elsif ($item eq 'pac.roles.denied') {
5766: $datatable .= '</td><td align="right">'.
1.80 raeburn 5767: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5768: '</table>';
5769: } elsif ($item eq 'pac.users.denied') {
5770: $datatable .= '</td><td align="right">'.
5771: &user_table($cdom,$item,undef,
1.80 raeburn 5772: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5773: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5774: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5775: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5776: $datatable .= '</td><td align="right"><br />'.
5777: &Apache::loncommon::start_data_table().
1.1 raeburn 5778: &Apache::loncommon::start_data_table_row().
5779: '<th align="left">'.&mt('Role').'</th><th>'.
5780: &mt('Sections').'</th>'.
5781: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5782: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5783: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5784: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5785: $datatable .= '</td><td align="right"><br />'.
5786: &Apache::loncommon::start_data_table().
1.50 raeburn 5787: &Apache::loncommon::start_data_table_row().
5788: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5789: '<th align="center">'.&mt('font-size').'</th>'.
5790: '<th align="center">'.&mt('font-weight').'</th>'.
5791: '<th align="center">'.&mt('font-style').'</th>'.
5792: '<th align="center">'.&mt('Other css').'</th>'.
5793: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5794: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5795: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5796: }
5797: $datatable .= &item_table_row_end();
5798: }
5799: $$rowtotal += scalar(@{$ordered});
5800: return $datatable;
5801: }
5802:
5803: sub role_checkboxes {
1.80 raeburn 5804: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5805: my @roles = ('st','ad','ta','ep','in');
5806: if ($crstype eq 'Community') {
5807: push(@roles,'co');
5808: } else {
5809: push(@roles,'cc');
5810: }
1.1 raeburn 5811: my $output;
5812: my (@current,@curr_roles,%currsec,@sections);
5813: if ($showsections) {
5814: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5815: @sections = sort( { $a <=> $b } keys(%sections));
5816: }
5817: if (ref($settings) eq 'HASH') {
5818: if ($settings->{$item}) {
5819: @current = split(',',$settings->{$item});
5820: if ($showsections) {
5821: foreach my $role (@current) {
5822: if ($role =~ /:/) {
5823: my ($trole,$sec) = split(':',$role);
5824: push(@curr_roles,$trole);
5825: if (ref($currsec{$trole}) eq 'ARRAY') {
5826: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5827: push(@{$currsec{$trole}},$sec);
5828: }
1.3 raeburn 5829: } else {
5830: $currsec{$trole} = [$sec];
1.1 raeburn 5831: }
5832: } else {
5833: push(@curr_roles,$role);
5834: }
5835: }
5836: @current = @curr_roles;
5837: }
5838: }
5839: }
5840: my $numinrow = 3;
5841: my $count = 0;
1.80 raeburn 5842: my $disabled;
5843: if ($noedit) {
5844: $disabled = ' disabled="disabled"';
5845: }
1.1 raeburn 5846: foreach my $role (@roles) {
5847: my $checked = '';
5848: if (grep(/^\Q$role\E$/,@current)) {
5849: $checked = ' checked="checked" ';
5850: }
1.9 raeburn 5851: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5852: if ($showsections) {
5853: $output .= &Apache::loncommon::start_data_table_row();
5854: } else {
5855: my $rem = $count%($numinrow);
5856: if ($rem == 0) {
5857: if ($count > 0) {
5858: $output .= '</tr>';
5859: }
5860: $output .= '<tr>';
5861: }
5862: }
1.30 raeburn 5863: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5864: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5865: $plrole.'</label></span></td>';
5866: if ($showsections) {
5867: $output .= '<td align="left">'.
1.80 raeburn 5868: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5869: '</td></tr>';
5870: }
5871: $count ++;
5872: }
5873: my %adv_roles =
5874: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5875: my $total = @roles;
5876: foreach my $role (sort(keys(%adv_roles))) {
5877: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5878: my $rolename = $3;
5879: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5880: my $checked = '';
5881: if (grep(/^\Q$value\E$/,@current)) {
5882: $checked = ' checked="checked" ';
5883: }
5884: if ($showsections) {
5885: $output .= &Apache::loncommon::start_data_table_row();
5886: } else {
5887: my $rem = $count%($numinrow);
5888: if ($rem == 0) {
5889: if ($count > 0) {
5890: $output .= '</tr>';
5891: }
5892: $output .= '<tr>';
5893: }
5894: }
1.30 raeburn 5895: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5896: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5897: '</label></span></td>';
5898: if ($showsections) {
5899: $output .= '<td>'.
1.80 raeburn 5900: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5901: '</td>'.&Apache::loncommon::end_data_table_row();
5902: }
5903: $total ++;
5904: $count ++;
5905: }
5906: }
5907: if (!$showsections) {
5908: my $rem = $total%($numinrow);
5909: my $colsleft = $numinrow - $rem;
5910: if ($colsleft > 1 ) {
5911: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5912: ' </td>';
5913: } elsif ($colsleft == 1) {
5914: $output .= '<td class="LC_left_item"> </td>';
5915: }
5916: $output .= '</tr>';
5917: }
5918: return $output;
5919: }
5920:
1.50 raeburn 5921: sub set_discussion_fonts {
1.80 raeburn 5922: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 5923: my ($classorder,$classtitles) = &discussion_vote_classes();
5924: my ($styleorder,$styleitems) = &discussion_vote_styles();
5925: my $output;
5926: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 5927: my $disabled;
5928: if ($noedit) {
5929: $disabled = ' disabled="disabled"';
5930: }
1.50 raeburn 5931: foreach my $cat (@{$classorder}) {
5932: my %curr = ();
5933: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5934: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5935: $output .= &Apache::loncommon::start_data_table_row().
5936: '<td>'.$classtitles->{$cat}.'</td>';
5937: if (ref($styleorder) eq 'ARRAY') {
5938: foreach my $item (@{$styleorder}) {
5939: $output .= '<td><span class="LC_nobreak">';
5940: my $selitem = $item;
5941: if ($item eq 'size') {
5942: my ($currsize,$currunit);
5943: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5944: ($currsize,$currunit) = ($1,$2);
5945: $curr{'size'} = $currunit;
5946: }
1.81 raeburn 5947: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 5948: ' ';
5949: $selitem = 'unit';
5950: }
5951: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 5952: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 5953: foreach my $val (@{$styleitems->{$item}}) {
5954: my $sel;
5955: if ($val eq $curr{$item}) {
5956: $sel = ' selected="selected"';
5957: }
5958: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
5959: }
5960: }
5961: }
5962: }
1.80 raeburn 5963: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 5964: }
5965: $output .= &Apache::loncommon::end_data_table_row();
5966: }
5967: return $output;
5968: }
5969:
5970: sub discussion_vote_classes {
5971: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
5972: my %classtitles = &Apache::lonlocal::texthash(
5973: 'twoplus' => 'Two sigma above mean',
5974: 'oneplus' => 'One sigma above mean',
5975: 'zero' => 'Within one sigma of mean',
5976: 'oneminus' => 'One sigma below mean',
5977: 'twominus' => 'Two sigma below mean',
5978: );
5979: return ($classorder,\%classtitles);
5980: }
5981:
5982: sub discussion_vote_styles {
5983: my $styleorder = ['size','weight','style'];
5984: my $styleitems = {
5985: size => ['','px','%','xx-small','x-small','small','medium','large',
5986: 'x-large','xx-large','smaller','larger'],
5987: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
5988: '500','600','700','800','900'],
5989: style => ['','normal','italic','oblique'],
5990: };
5991: return ($styleorder,$styleitems);
5992: }
5993:
1.1 raeburn 5994: sub print_classlists {
1.80 raeburn 5995: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5996: my @ordered;
5997: if ($position eq 'top') {
5998: @ordered = ('default_enrollment_start_date',
5999: 'default_enrollment_end_date');
1.55 raeburn 6000: if ($crstype eq 'Course') {
6001: push(@ordered,'defaultcredits');
6002: }
1.1 raeburn 6003: } elsif ($position eq 'middle') {
1.56 raeburn 6004: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 6005: } else {
6006: @ordered = ('student_classlist_view',
1.26 raeburn 6007: 'student_classlist_opt_in',
6008: 'student_classlist_portfiles');
1.1 raeburn 6009: }
1.9 raeburn 6010: my %lt;
6011:
6012: if ($crstype eq 'Community') {
6013: %lt = &Apache::lonlocal::texthash (
6014: disabled => 'No viewable membership list',
6015: section => "Membership of viewer's section",
6016: all => 'List of all members',
6017: );
6018: } else {
6019: %lt = &Apache::lonlocal::texthash (
6020: disabled => 'No viewable classlist',
6021: section => "Classlist of viewer's section",
6022: all => 'Classlist of all students',
6023: );
6024: }
6025:
1.1 raeburn 6026: my %items = (
6027: 'default_enrollment_start_date' => {
1.3 raeburn 6028: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 6029: input => 'dates',
6030: },
6031: 'default_enrollment_end_date' => {
1.3 raeburn 6032: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 6033: input => 'dates',
6034: },
1.55 raeburn 6035: 'defaultcredits' => {
6036: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
6037: },
6038:
1.1 raeburn 6039: 'nothideprivileged' => {
1.3 raeburn 6040: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 6041: input => 'checkbox',
6042: },
6043:
1.56 raeburn 6044: 'checkforpriv' => {
6045: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
6046: input => 'selectbox',
6047: },
6048:
1.1 raeburn 6049: 'student_classlist_view' => {
1.3 raeburn 6050: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 6051: input => 'selectbox',
1.9 raeburn 6052: options => \%lt,
1.1 raeburn 6053: order => ['disabled','all','section'],
6054: },
1.26 raeburn 6055: 'student_classlist_opt_in' => {
6056: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 6057: input => 'radio',
6058: },
6059:
6060: 'student_classlist_portfiles' => {
1.3 raeburn 6061: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 6062: input => 'radio',
6063: },
6064: );
6065: unless (($settings->{'student_classlist_view'} eq 'all') ||
6066: ($settings->{'student_classlist_view'} eq 'section')) {
6067: $settings->{'student_classlist_view'} = 'disabled';
6068: }
1.80 raeburn 6069: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6070: }
6071:
6072: sub print_appearance {
1.80 raeburn 6073: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6074: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6075: return;
6076: }
1.9 raeburn 6077: my $mathdef;
6078: if ($crstype eq 'Community') {
6079: $mathdef = &mt("None specified - use member's choice");
6080: } else {
6081: $mathdef = &mt("None specified - use student's choice");
6082: }
1.1 raeburn 6083: my %items = (
6084: 'default_xml_style' => {
1.3 raeburn 6085: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6086: '<a href="javascript:openbrowser'.
6087: "('display','default_xml_style'".
6088: ",'sty')".'">'.&mt('Select Style File').'</a>',
6089: input => 'textbox',
6090: size => 35,
6091: },
6092:
6093: 'pageseparators' => {
1.3 raeburn 6094: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6095: input => 'radio',
6096: },
6097: 'disable_receipt_display' => {
1.3 raeburn 6098: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6099: input => 'radio',
6100: },
6101: 'texengine' => {
1.3 raeburn 6102: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6103: input => 'selectbox',
6104: options => {
1.61 raeburn 6105: MathJax => 'MathJax',
1.1 raeburn 6106: mimetex => &mt('Convert to Images'),
6107: tth => &mt('TeX to HTML'),
6108: },
1.75 raeburn 6109: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6110: nullval => $mathdef,
1.1 raeburn 6111: },
6112: 'tthoptions' => {
1.3 raeburn 6113: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6114: input => 'textbox',
6115: size => 40,
6116: },
1.69 raeburn 6117: 'uselcmath' => {
6118: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6119: input => 'radio',
6120: },
6121: 'usejsme' => {
6122: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6123: input => 'radio',
6124: },
1.95 raeburn 6125: 'inline_chem' => {
6126: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6127: input => 'radio',
6128: },
1.114 raeburn 6129: 'extresource' => {
6130: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6131: input => 'selectbox',
6132: options => {
6133: iframe => 'In iframe',
6134: tab => 'In new tab',
6135: window => 'In pop-up window',
6136: },
6137: order => ['iframe','tab','window'],
6138: },
1.1 raeburn 6139: );
1.80 raeburn 6140: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6141: }
6142:
6143: sub print_grading {
1.80 raeburn 6144: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6145: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6146: return;
6147: }
6148: my %items = (
6149: 'grading' => {
1.3 raeburn 6150: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6151: &Apache::loncommon::help_open_topic('GradingOptions'),
6152: input => 'selectbox',
6153: options => {
6154: standard => &mt('Standard: shows points'),
1.34 www 6155: categories => &mt('Categories: shows points according to categories'),
1.11 www 6156: external => &mt('External: shows number of completed parts and totals'),
6157: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6158: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6159: },
1.34 www 6160: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6161: },
6162: 'rndseed' => {
1.3 raeburn 6163: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 6164: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 6165: &mt('Modifying this will make problems have different numbers and answers!').
6166: '</span>',
6167: input => 'selectbox',
6168: options => {
6169: '32bit' => '32bit',
6170: '64bit' => '64bit',
6171: '64bit2' => '64bit2',
6172: '64bit3' => '64bit3',
6173: '64bit4' => '64bit4',
6174: '64bit5' => '64bit5',
6175: },
6176: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6177: advanced => 1
1.1 raeburn 6178: },
6179: 'receiptalg' => {
1.3 raeburn 6180: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6181: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6182: input => 'selectbox',
6183: options => {
6184: receipt => 'receipt',
6185: receipt2 => 'receipt2',
6186: receipt3 => 'receipt3',
6187: },
6188: order => ['receipt','receipt2','receipt3'],
1.41 www 6189: advanced => 1
1.1 raeburn 6190: },
6191: 'disablesigfigs' => {
1.3 raeburn 6192: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6193: input => 'radio',
6194: },
6195: );
1.80 raeburn 6196: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
1.1 raeburn 6197: }
6198:
6199: sub print_printouts {
1.80 raeburn 6200: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6201: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6202: return;
6203: }
6204: my %items = (
6205: problem_stream_switch => {
1.3 raeburn 6206: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6207: input => 'radio',
6208: },
6209: suppress_tries => {
1.3 raeburn 6210: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6211: input => 'radio',
6212: },
6213: default_paper_size => {
1.3 raeburn 6214: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6215: input => 'selectbox',
6216: options => {
6217: Letter => &mt('Letter').' [8 1/2x11 in]',
6218: Legal => &mt('Legal').' [8 1/2x14 in]',
6219: Tabloid => &mt('Tabloid').' [11x17 in]',
6220: Executive => &mt('Executive').' [7 1/2x10 in]',
6221: A2 => &mt('A2').' [420x594 mm]',
6222: A3 => &mt('A3').' [297x420 mm]',
6223: A4 => &mt('A4').' [210x297 mm]',
6224: A5 => &mt('A5').' [148x210 mm]',
6225: A6 => &mt('A6').' [105x148 mm]',
6226: },
6227: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6228: nullval => &mt('None specified'),
1.1 raeburn 6229: },
6230: print_header_format => {
1.3 raeburn 6231: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6232: input => 'checkbox',
6233: },
6234: disableexampointprint => {
1.3 raeburn 6235: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6236: input => 'radio',
6237: },
1.14 raeburn 6238: canuse_pdfforms => {
6239: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6240: input => 'selectbox',
6241: options => {
6242: 1 => &mt('Yes'),
6243: 0 => &mt('No'),
6244: },
6245: order => ['1','0'],
1.54 bisitz 6246: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6247: }
1.1 raeburn 6248: );
1.80 raeburn 6249: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6250: }
6251:
6252: sub print_spreadsheet {
1.80 raeburn 6253: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6254: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6255: return;
6256: }
6257: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6258: my %items = (
6259: spreadsheet_default_classcalc => {
1.3 raeburn 6260: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6261: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6262: "('display','spreadsheet_default_classcalc'".
6263: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6264: input => 'textbox',
6265: },
6266: spreadsheet_default_studentcalc => {
1.3 raeburn 6267: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6268: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6269: "('display','spreadsheet_default_calc'".
6270: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6271: input => 'textbox',
6272: },
6273: spreadsheet_default_assesscalc => {
1.3 raeburn 6274: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6275: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6276: "('display','spreadsheet_default_assesscalc'".
6277: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6278: input => 'textbox',
6279: },
6280: hideemptyrows => {
1.3 raeburn 6281: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6282: input => 'radio',
6283: },
6284: );
1.80 raeburn 6285: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6286: }
1.1 raeburn 6287:
6288: sub print_bridgetasks {
1.80 raeburn 6289: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6290: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6291: return;
6292: }
1.9 raeburn 6293: my ($stumsg,$msgnote);
6294: if ($crstype eq 'Community') {
6295: $stumsg = &mt('Send message to member');
6296: $msgnote = &mt('Message to member and add to user notes');
6297: } else {
6298: $stumsg = &mt('Send message to student');
6299: $msgnote = &mt('Message to student and add to user notes');
6300: }
1.1 raeburn 6301: my %items = (
6302: task_messages => {
1.3 raeburn 6303: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6304: input => 'selectbox',
6305: options => {
1.9 raeburn 6306: only_student => $stumsg,
6307: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6308: },
6309: order => ['only_student','student_and_user_notes_screen'],
6310: nullval => &mt('No message or record in user notes'),
6311: },
6312: task_grading => {
1.3 raeburn 6313: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6314: input => 'selectbox',
6315: options => {
6316: any => &mt('Grade BTs in any section'),
6317: section => &mt('Grade BTs only in own section')
6318: },
6319: order => ['any','section'],
6320: },
6321: suppress_embed_prompt => {
1.3 raeburn 6322: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6323: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6324: input => 'radio',
6325: },
6326: );
1.80 raeburn 6327: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6328: }
6329:
1.118 raeburn 6330: sub print_ltitools {
6331: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6332: my ($datatable,$disabled,$css_class,$dest);
1.121 raeburn 6333: if ($noedit) {
6334: $disabled = ' disabled="disabled"';
6335: }
1.120 raeburn 6336: my $itemcount = 1;
6337: unless ($context eq 'domain') {
6338: my %tooltypes = &Apache::loncommon::usable_exttools();
6339: unless ($tooltypes{'crs'}) {
6340: my $showtype = 'course';
6341: if ($crstype eq 'Community') {
6342: $showtype = lc($crstype);
6343: }
6344: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6345: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6346: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6347: if ($tooltypes{'dom'}) {
6348: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6349: '<i>'.$cdom.'</i>').
6350: '<br /><br />'.
6351: &mt("Use of external tools defined at a domain level is enabled, so the $showtype editor can be used to add tool(s), if any have been defined.");
6352: } else {
6353: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6354: '<br /><br />'.
6355: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6356: '<i>'.$cdom.'</i>');
6357:
6358: }
6359: $datatable .= '</tr>';
6360: $itemcount ++;
6361: return $datatable;
6362: }
6363: }
1.118 raeburn 6364: my %lt = <itools_names();
6365: my $maxnum = 0;
6366: my %ordered;
6367: if (ref($settings) eq 'HASH') {
6368: foreach my $item (keys(%{$settings})) {
6369: if (ref($settings->{$item}) eq 'HASH') {
6370: my $num = $settings->{$item}{'order'};
6371: $ordered{$num} = $item;
6372: }
6373: }
6374: }
6375:
6376: if ($context eq 'domain') {
6377: $dest = '/adm/domainprefs';
6378: } else {
6379: $dest = '/adm/courseprefs';
6380: }
6381: my ($switchserver,$switchmessage);
6382: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6383: if ($switchserver) {
6384: if ($context eq 'domain') {
6385: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6386: } elsif ($crstype eq 'Community') {
6387: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6388: } else {
6389: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6390: }
6391: }
6392: my $maxnum = scalar(keys(%ordered));
6393: my @courseroles = ('cc','in','ta','ep','st');
6394: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6395: my @fields = ('fullname','firstname','lastname','email','roles','user');
6396: if (keys(%ordered)) {
6397: my @items = sort { $a <=> $b } keys(%ordered);
6398: for (my $i=0; $i<@items; $i++) {
6399: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6400: my $item = $ordered{$items[$i]};
6401: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6402: if (ref($settings->{$item}) eq 'HASH') {
6403: $title = $settings->{$item}->{'title'};
6404: $url = $settings->{$item}->{'url'};
6405: $key = $settings->{$item}->{'key'};
6406: $usable = $settings->{$item}->{'usable'};
6407: $lifetime = $settings->{$item}->{'lifetime'};
6408: my $image = $settings->{$item}->{'image'};
6409: if ($image ne '') {
6410: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6411: }
6412: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6413: $sigsel{'HMAC-256'} = ' selected="selected"';
6414: } else {
6415: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6416: }
6417: }
6418: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6419: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6420: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6421: for (my $k=0; $k<=$maxnum; $k++) {
6422: my $vpos = $k+1;
6423: my $selstr;
6424: if ($k == $i) {
6425: $selstr = ' selected="selected" ';
6426: }
6427: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6428: }
6429: $datatable .= '</select>'.(' 'x2).
6430: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6431: &mt('Delete?').'</label></span></td>'.
6432: '<td colspan="2">'.
6433: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6434: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6435: (' 'x2).
6436: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6437: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6438: (' 'x2).
6439: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6440: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6441: (' 'x2).
6442: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6443: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6444: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6445: '<br /><br />'.
1.120 raeburn 6446: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6447: ' value="'.$url.'" /></span>'.
6448: (' 'x2).
6449: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6450: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6451: if ($key ne '') {
6452: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6453: if ($noedit) {
6454: $datatable .= ': ['.&mt('not shown').']';
6455: } elsif ($switchserver) {
6456: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6457: } else {
6458: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6459: }
6460: $datatable .= '</span> '.(' 'x2);
6461: } elsif (!$switchserver) {
6462: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6463: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6464: '</span> '.(' 'x2);
6465: }
6466: if ($switchserver) {
6467: if ($usable ne '') {
6468: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6469: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6470: '<span class="LC_nobreak">'.&mt('Change secret?').
6471: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6472: (' 'x2).
6473: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6474: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6475: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6476: '</div>';
6477: } elsif ($key eq '') {
6478: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6479: } else {
6480: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6481: }
6482: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6483: } else {
6484: if ($usable ne '') {
6485: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6486: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6487: '<span class="LC_nobreak">'.&mt('Change?').
6488: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6489: (' 'x2).
6490: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6491: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6492: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6493: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6494: '<label><input type="checkbox" name="ltitools_visible_'.$i.'" id="ltitools_visible_'.$i.'" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>'.
6495: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6496: } else {
6497: $datatable .=
6498: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6499: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6500: '<label><input type="checkbox" name="ltitools_visible_'.$i.'" id="ltitools_visible_'.$i.'" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>'.
6501: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6502: }
6503: }
6504: $datatable .= '</fieldset>'.
6505: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6506: '<span class="LC_nobreak">'.&mt('Display target:');
6507: my %currdisp;
6508: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6509: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6510: $currdisp{'window'} = ' checked="checked"';
6511: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6512: $currdisp{'tab'} = ' checked="checked"';
6513: } else {
6514: $currdisp{'iframe'} = ' checked="checked"';
6515: }
6516: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6517: $currdisp{'width'} = $1;
6518: }
6519: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6520: $currdisp{'height'} = $1;
6521: }
6522: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6523: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6524: } else {
6525: $currdisp{'iframe'} = ' checked="checked"';
6526: }
6527: foreach my $disp ('iframe','tab','window') {
6528: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6529: $lt{$disp}.'</label>'.(' 'x2);
6530: }
6531: $datatable .= (' 'x4);
6532: foreach my $dimen ('width','height') {
6533: $datatable .= '<label>'.$lt{$dimen}.' '.
6534: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6535: (' 'x2);
6536: }
6537: $datatable .= '</span><br />'.
6538: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6539: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6540: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6541: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6542: '</textarea></div><div style=""></div><br />';
6543: my %units = (
6544: 'passback' => 'days',
6545: 'roster' => 'seconds',
6546: );
6547: foreach my $extra ('passback','roster') {
6548: my $validsty = 'none';
6549: my $currvalid;
6550: my $checkedon = '';
6551: my $checkedoff = ' checked="checked"';
6552: if ($settings->{$item}->{$extra}) {
6553: $checkedon = $checkedoff;
6554: $checkedoff = '';
6555: $validsty = 'inline-block';
6556: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6557: $currvalid = $settings->{$item}->{$extra.'valid'};
6558: }
6559: }
6560: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6561: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6562: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6563: &mt('No').'</label>'.(' 'x2).
6564: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6565: &mt('Yes').'</label></span></div>'.
6566: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6567: '<span class="LC_nobreak">'.
6568: &mt("until at least [_1] $units{$extra} after launch",
6569: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6570: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6571: }
6572: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6573: if ($imgsrc) {
6574: $datatable .= $imgsrc.
6575: '<label><input type="checkbox" name="ltitools_image_del"'.
6576: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6577: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6578: } else {
6579: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6580: }
6581: if ($switchserver) {
6582: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6583: } else {
6584: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6585: }
6586: $datatable .= '</span></fieldset>';
6587: my (%checkedfields,%rolemaps,$userincdom);
6588: if (ref($settings->{$item}) eq 'HASH') {
6589: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6590: %checkedfields = %{$settings->{$item}->{'fields'}};
6591: }
6592: $userincdom = $settings->{$item}->{'incdom'};
6593: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6594: %rolemaps = %{$settings->{$item}->{'roles'}};
6595: $checkedfields{'roles'} = 1;
6596: }
6597: }
6598: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6599: '<span class="LC_nobreak">';
6600: my $userfieldstyle = 'display:none;';
6601: my $seluserdom = '';
6602: my $unseluserdom = ' selected="selected"';
6603: foreach my $field (@fields) {
6604: my ($checked,$onclick,$id,$spacer);
6605: if ($checkedfields{$field}) {
6606: $checked = ' checked="checked"';
6607: }
6608: if ($field eq 'user') {
6609: $id = ' id="ltitools_user_field_'.$i.'"';
6610: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6611: if ($checked) {
6612: $userfieldstyle = 'display:inline-block';
6613: if ($userincdom) {
6614: $seluserdom = $unseluserdom;
6615: $unseluserdom = '';
6616: }
6617: }
6618: } else {
6619: $spacer = (' ' x2);
6620: }
6621: $datatable .= '<label>'.
6622: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6623: $lt{$field}.'</label>'.$spacer;
6624: }
6625: $datatable .= '</span>';
6626: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6627: '<span class="LC_nobreak"> : '.
6628: '<select name="ltitools_userincdom_'.$i.'">'.
6629: '<option value="">'.&mt('Select').'</option>'.
6630: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6631: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6632: '</select></span></div>';
6633: $datatable .= '</fieldset>'.
6634: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6635: foreach my $role (@courseroles) {
6636: my ($selected,$selectnone);
6637: if (!$rolemaps{$role}) {
6638: $selectnone = ' selected="selected"';
6639: }
6640: $datatable .= '<td style="text-align: center">'.
6641: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6642: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6643: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6644: foreach my $ltirole (@ltiroles) {
6645: unless ($selectnone) {
6646: if ($rolemaps{$role} eq $ltirole) {
6647: $selected = ' selected="selected"';
6648: } else {
6649: $selected = '';
6650: }
6651: }
6652: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6653: }
6654: $datatable .= '</select></td>';
6655: }
6656: $datatable .= '</tr></table></fieldset>';
6657: my %courseconfig;
6658: if (ref($settings->{$item}) eq 'HASH') {
6659: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6660: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6661: }
6662: }
6663: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6664: foreach my $item ('label','title','target','linktext','explanation','append') {
6665: my $checked;
6666: if ($courseconfig{$item}) {
6667: $checked = ' checked="checked"';
6668: }
6669: $datatable .= '<label>'.
6670: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6671: $lt{'crs'.$item}.'</label> '."\n";
6672: }
6673: $datatable .= '</span></fieldset>'.
6674: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6675: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6676: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6677: my %custom = %{$settings->{$item}->{'custom'}};
6678: if (keys(%custom) > 0) {
6679: foreach my $key (sort(keys(%custom))) {
6680: $datatable .= '<tr><td><span class="LC_nobreak">'.
6681: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6682: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6683: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6684: ' value="'.$custom{$key}.'" /></td></tr>';
6685: }
6686: }
6687: }
6688: $datatable .= '<tr><td><span class="LC_nobreak">'.
6689: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6690: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6691: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6692: $datatable .= '</table></fieldset></td></tr>'."\n";
6693: $itemcount ++;
6694: }
6695: }
6696: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6697: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6698: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6699: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6700: '<select name="ltitools_add_pos"'.$chgstr.'>';
6701: for (my $k=0; $k<$maxnum+1; $k++) {
6702: my $vpos = $k+1;
6703: my $selstr;
6704: if ($k == $maxnum) {
6705: $selstr = ' selected="selected" ';
6706: }
6707: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6708: }
6709: $datatable .= '</select> '."\n".
6710: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6711: '<td colspan="2">'.
6712: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6713: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6714: (' 'x2).
6715: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6716: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6717: (' 'x2).
6718: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6719: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6720: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6721: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6722: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6723: '<br />'.
1.120 raeburn 6724: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6725: (' 'x2).
6726: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6727: if ($switchserver) {
6728: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6729: } else {
6730: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6731: (' 'x2).
1.119 raeburn 6732: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6733: '<label><input type="checkbox" name="ltitools_add_visible" id="ltitools_add_visible" onclick="if (this.checked) { this.form.ltitools_secret_add.type='."'text'".' } else { this.form.ltitools_secret_add.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label></span> '."\n";
1.118 raeburn 6734: }
6735: $datatable .= '<br /><br />'.
6736: '</fieldset>'.
6737: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6738: '<span class="LC_nobreak">'.&mt('Display target:');
6739: my %defaultdisp;
6740: $defaultdisp{'iframe'} = ' checked="checked"';
6741: foreach my $disp ('iframe','tab','window') {
6742: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6743: $lt{$disp}.'</label>'.(' 'x2);
6744: }
6745: $datatable .= (' 'x4);
6746: foreach my $dimen ('width','height') {
6747: $datatable .= '<label>'.$lt{$dimen}.' '.
6748: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6749: (' 'x2);
6750: }
6751: $datatable .= '</span><br />'.
6752: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6753: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6754: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6755: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6756: '</div><div style=""></div><br />';
6757: my %units = (
6758: 'passback' => 'days',
6759: 'roster' => 'seconds',
6760: );
6761: my %defaulttimes = (
6762: 'passback' => '7',
6763: 'roster' => '300',
6764: );
6765: foreach my $extra ('passback','roster') {
6766: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6767: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6768: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6769: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6770: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6771: &mt('Yes').'</label></span></div>'.
6772: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6773: '<span class="LC_nobreak">'.
6774: &mt("until at least [_1] $units{$extra} after launch",
6775: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6776: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6777: }
6778: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6779: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6780: if ($switchserver) {
6781: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6782: } else {
6783: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6784: }
6785: $datatable .= '</span></fieldset>'.
6786: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6787: '<span class="LC_nobreak">';
6788: foreach my $field (@fields) {
6789: my ($id,$onclick,$spacer);
6790: if ($field eq 'user') {
6791: $id = ' id="ltitools_user_field_add"';
6792: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6793: } else {
6794: $spacer = (' ' x2);
6795: }
6796: $datatable .= '<label>'.
6797: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6798: $lt{$field}.'</label>'.$spacer;
6799: }
6800: $datatable .= '</span>'.
6801: '<div style="display:none;" id="ltitools_user_div_add">'.
6802: '<span class="LC_nobreak"> : '.
6803: '<select name="ltitools_add_userincdom">'.
6804: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6805: '<option value="0">'.&mt('username').'</option>'.
6806: '<option value="1">'.&mt('username:domain').'</option>'.
6807: '</select></span></div></fieldset>';
6808: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6809: foreach my $role (@courseroles) {
6810: my ($checked,$checkednone);
6811: $datatable .= '<td style="text-align: center">'.
6812: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6813: '<select name="ltitools_add_roles_'.$role.'">'.
6814: '<option value="" selected="selected">'.&mt('Select').'</option>';
6815: foreach my $ltirole (@ltiroles) {
6816: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6817: }
6818: $datatable .= '</select></td>';
6819: }
6820: $datatable .= '</tr></table></fieldset>'.
6821: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6822: foreach my $item ('label','title','target','linktext','explanation','append') {
6823: $datatable .= '<label>'.
6824: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6825: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6826: }
6827: $datatable .= '</span></fieldset>'.
6828: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6829: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6830: '<tr><td><span class="LC_nobreak">'.
6831: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6832: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6833: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6834: '</table></fieldset>'."\n".
6835: '</td>'."\n".
6836: '</tr>'."\n";
6837: $itemcount ++;
6838: return $datatable;
6839: }
6840:
6841: sub ltitools_names {
6842: my %lt = &Apache::lonlocal::texthash(
6843: 'title' => 'Title',
6844: 'version' => 'Version',
6845: 'msgtype' => 'Message Type',
6846: 'sigmethod' => 'Signature Method',
6847: 'url' => 'URL',
6848: 'key' => 'Key',
6849: 'lifetime' => 'Nonce lifetime (s)',
6850: 'secret' => 'Secret',
6851: 'icon' => 'Icon',
6852: 'user' => 'User',
6853: 'fullname' => 'Full Name',
6854: 'firstname' => 'First Name',
6855: 'lastname' => 'Last Name',
6856: 'email' => 'E-mail',
6857: 'roles' => 'Role',
6858: 'window' => 'Window',
6859: 'tab' => 'Tab',
6860: 'iframe' => 'iFrame',
6861: 'height' => 'Height',
6862: 'width' => 'Width',
6863: 'linktext' => 'Default Link Text',
6864: 'explanation' => 'Default Explanation',
6865: 'passback' => 'Tool can return grades:',
6866: 'roster' => 'Tool can retrieve roster:',
6867: 'crstarget' => 'Display target',
6868: 'crslabel' => 'Course label',
6869: 'crstitle' => 'Course title',
6870: 'crslinktext' => 'Link Text',
6871: 'crsexplanation' => 'Explanation',
6872: 'crsappend' => 'Provider URL',
6873: );
6874: return %lt;
6875: }
6876:
1.87 raeburn 6877: sub print_lti {
6878: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6879: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6880: return;
6881: }
6882: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6883: my %menutitles = <imenu_titles();
6884: my ($domdefs,$displaydefs);
6885: if ($env{'request.lti.login'}) {
6886: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6887: my @domdefsmenu;
6888: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6889: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6890: $domdefs = &mt('Header shown').', ';
6891: }
6892: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6893: $domdefs .= &mt('Inline menu shown');
6894: }
6895: $domdefs =~ s/,\s$//;
6896: if (!$domdefs) {
6897: $domdefs = &mt('No header or inline menu shown');
6898: }
6899: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
6900: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6901: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6902: }
6903: }
6904: $displaydefs = &mt('Domain defaults');
6905: if (@domdefsmenu) {
6906: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
6907: if (@diffs) {
6908: my $missing;
6909: foreach my $item (@menuitems) {
6910: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
6911: $missing .= ' '.$menutitles{$item}.',';
6912: }
6913: }
6914: $missing =~ s/,$//;
6915: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
6916: } else {
6917: $displaydefs .= ': '.&mt('All shown');
6918: }
6919: } else {
6920: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
6921: }
6922: } else {
6923: $displaydefs = &mt('Domain defaults only available in LTI context');
6924: }
6925: my %items = (
6926: 'lti.override' => {
6927: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
6928: input => 'radio',
6929: },
6930: 'lti.topmenu' => {
6931: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
6932: input => 'radio',
6933: },
6934: 'lti.inlinemenu' => {
6935: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
6936: input => 'radio',
6937: },
6938: 'lti.lcmenu' => {
6939: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
6940: input => 'custom',
6941: },
6942: );
6943: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
6944: }
6945:
6946: sub lcmenu_checkboxes {
6947: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
6948: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6949: my %menutitles = <imenu_titles();
6950: my (@current,@domdefs);
6951: if ($env{'request.lti.login'}) {
6952: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6953: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6954: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6955: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6956: }
6957: }
6958: }
6959: if (ref($settings) eq 'HASH') {
6960: if ($settings->{'lti.lcmenu'}) {
6961: unless ($settings->{'lti.lcmenu'} eq 'none') {
6962: @current = split(',',$settings->{'lti.lcmenu'});
6963: }
6964: } else {
6965: @current = @domdefs;
6966: }
6967: } else {
6968: @current = @domdefs;
6969: }
6970: my $numinrow = 3;
6971: my $count = 0;
6972: my $disabled;
6973: if ($noedit) {
6974: $disabled = ' disabled="disabled"';
6975: }
6976: my $output = '<table>';
6977: foreach my $item (@menuitems) {
6978: my $checked = '';
6979: if (grep(/^\Q$item\E$/,@current)) {
6980: $checked = ' checked="checked" ';
6981: }
6982: my $rem = $count%($numinrow);
6983: if ($rem == 0) {
6984: if ($count > 0) {
6985: $output .= '</tr>';
6986: }
6987: $output .= '<tr>';
6988: }
6989: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
6990: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
6991: $menutitles{$item}.'</label></span></td>';
6992: $count ++;
6993: }
6994: my $rem = $count%($numinrow);
6995: my $colsleft = $numinrow - $rem;
6996: if ($colsleft > 1 ) {
6997: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6998: ' </td>';
6999: } elsif ($colsleft == 1) {
7000: $output .= '<td class="LC_left_item"> </td>';
7001: }
7002: $output .= '</tr></table>';
7003: }
7004:
7005: sub ltimenu_titles {
7006: return &Apache::lonlocal::texthash(
7007: fullname => 'Full name',
7008: coursetitle => 'Course title',
7009: role => 'Role',
7010: logout => 'Logout',
7011: grades => 'Grades',
7012: );
7013: }
7014:
1.91 raeburn 7015: sub print_menuitems {
7016: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
7017: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
7018: return;
7019: }
7020: if ($position eq 'top') {
7021: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
7022: if ($settings->{'menucollections'} ne '') {
7023: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7024: my ($num,$value) = split(/\%/,$item);
7025: if ($num =~ /^\d+$/) {
7026: $defaultmenu_options{$num} = $num;
7027: }
7028: }
7029: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
7030: $addcollection = $defaultmenu_order[-1] + 1;
7031: } else {
7032: $addcollection = 1;
7033: }
7034: $defaultmenu_options{$addcollection} = $addcollection;
7035: my %items = (
7036: 'menudefault' => {
7037: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
7038: &mt("(can be overriden in deep-link context)"),
7039: input => 'selectbox',
7040: options => \%defaultmenu_options,
7041: order => \@defaultmenu_order,
7042: nullval => &mt('Standard (all menus shown)'),
7043: },
7044: );
7045: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
7046: } else {
7047: my %menu;
7048: my $count = 0;
7049: my $next = 1;
7050: my ($datatable,$disabled);
7051: if ($noedit) {
7052: $disabled = ' disabled="disabled"';
7053: }
7054:
7055: my ($ordered,$cats) = &menuitems_categories();
7056: my @order = @{$ordered};
7057: my %categories = %{$cats};
7058: my %menutitles = &menuitems_titles();
7059: my %menufields = &menuitems_fields();
7060:
7061: if ($settings->{'menucollections'} ne '') {
7062: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7063: my ($num,$value) = split(/\%/,$item);
7064: if ($num =~ /^\d+$/) {
7065: my @entries = split(/\&/,$value);
7066: foreach my $entry (@entries) {
7067: my ($name,$fields) = split(/=/,$entry);
7068: $menu{$num}{$name} = $fields;
7069: }
7070: }
7071: }
7072: if (keys(%menu)) {
7073: my @current = sort { $a <=> $b } keys(%menu);
7074: $next += $current[-1];
7075: foreach my $num (@current) {
7076: my %checked;
7077: my $on = ' checked="checked"';
7078: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7079: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7080: if ($menu{$num}{$key} eq 'y') {
7081: $checked{$key} = $on;
7082: }
7083: } else {
7084: foreach my $field (split(/,/,$menu{$num}{$key})) {
7085: if (exists($menufields{$field})) {
7086: $checked{$field} = $on;
7087: }
7088: }
7089: }
7090: }
7091: if (ref($menu{$num}) eq 'HASH') {
7092: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7093: foreach my $category (@order) {
7094: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7095: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7096: if ($category eq 'text') {
7097: $datatable .= '<i>'.&mt('Header').'</i><br />';
7098: }
1.91 raeburn 7099: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7100: if ($field eq 'disc') {
7101: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7102: }
1.91 raeburn 7103: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7104: $menufields{$field}.'</label><br />';
7105: }
7106: $datatable .= '</fieldset>';
7107: }
7108: }
7109: $datatable .= &item_table_row_end();
7110: $count ++;
7111: }
7112: }
7113: }
7114: } elsif ($noedit) {
7115: my $text = &mt('No menu collections defined for this course.');
7116: $datatable .= &item_table_row_start($text,$count);
7117: }
7118: unless ($noedit) {
7119: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7120: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7121: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7122: foreach my $category (@order) {
7123: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7124: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7125: foreach my $field (@{$categories{$category}}) {
7126: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7127: $menufields{$field}.'</label><br />';
7128: }
7129: $datatable .= '</fieldset>';
7130: }
7131: }
7132: $datatable .= &item_table_row_end();
7133: $count ++;
7134: }
7135: return $datatable;
7136: }
7137: }
7138:
7139: sub menuitems_abbreviations {
7140: my %briefcats = (
7141: text => 'pt',
7142: links => 'p',
7143: list => 'ps',
7144: inline => 's',
7145: );
7146: return %briefcats;
7147: }
7148:
7149: sub menuitems_categories {
7150: my @order = ('shown','text','links','list','inline');
7151: my %categories = (
1.94 raeburn 7152: shown => ['top','inline','foot','main'],
7153: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7154: links => ['pers','logo','menu','comm','roles','help','logout'],
1.91 raeburn 7155: list => ['about','prefs','port','wish','anno','rss'],
7156: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7157: );
7158: return (\@order,\%categories);
7159: }
7160:
7161: sub menuitems_titles {
7162: return &Apache::lonlocal::texthash (
7163: shown => 'Hierarchy',
1.94 raeburn 7164: text => 'Text',
1.91 raeburn 7165: links => 'Header links',
7166: list => 'Drop-down list',
7167: inline => 'Inline links',
7168: );
7169: }
7170:
7171: sub menuitems_fields {
7172: return &Apache::lonlocal::texthash (
7173: top => 'Display header',
7174: inline => 'Display inline menu',
1.94 raeburn 7175: foot => 'Display footer',
1.91 raeburn 7176: main => 'Access to main menu',
1.92 raeburn 7177: pers => 'Personal',
7178: logo => 'LON-CAPA',
1.91 raeburn 7179: menu => 'Home',
7180: comm => 'Messages',
7181: roles => 'Roles/Courses',
7182: help => 'Help',
7183: logout => 'Logout',
7184: name => 'Fullname',
7185: crs => 'Course Title',
7186: role => 'Current Role',
1.94 raeburn 7187: disc => 'Discussion',
7188: fdbk => 'Feedback',
1.91 raeburn 7189: about => 'Information',
7190: prefs => 'Preferences',
7191: port => 'Portfolio',
7192: wish => 'Stored Links',
7193: anno => 'Calendar',
7194: rss => 'RSS Feeds',
7195: cont => 'Contents',
7196: grades => 'Grades',
7197: chat => 'Chat',
7198: people => 'People',
7199: groups => 'Groups',
7200: resv => 'Reservations',
7201: syll => 'Syllabus',
7202: feeds => 'Feeds',
7203: );
7204: }
7205:
7206: sub menucollections_display {
7207: my ($collections) = @_;
7208: my %menu;
7209: my ($ordered,$cats) = &menuitems_categories();
7210: my @order = @{$ordered};
7211: my %categories = %{$cats};
7212: my %menutitles = &menuitems_titles();
7213: my %menufields = &menuitems_fields();
7214: foreach my $item (split(/;/,$collections)) {
7215: my ($num,$value) = split(/\%/,$item);
7216: if ($num =~ /^\d+$/) {
7217: my @entries = split(/\&/,$value);
7218: foreach my $entry (@entries) {
7219: my ($name,$fields) = split(/=/,$entry);
7220: $menu{$num}{$name} = $fields;
7221: }
7222: }
7223: }
7224: my $output = '';
7225: if (keys(%menu)) {
7226: my @current = sort { $a <=> $b } keys(%menu);
7227: foreach my $num (@current) {
7228: my %checked;
7229: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7230: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7231: if ($menu{$num}{$key} eq 'y') {
7232: $checked{$key} = 1;
7233: }
7234: } else {
7235: foreach my $field (split(/,/,$menu{$num}{$key})) {
7236: if (exists($menufields{$field})) {
7237: $checked{$field} = 1;
7238: }
7239: }
7240: }
7241: }
7242: if (ref($menu{$num}) eq 'HASH') {
7243: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7244: foreach my $category (@order) {
7245: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7246: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7247: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7248: if ($category eq 'text') {
7249: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
7250: }
1.91 raeburn 7251: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7252: if ($field eq 'disc') {
7253: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7254: }
1.91 raeburn 7255: if ($checked{$field}) {
7256: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7257: } else {
7258: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7259: }
7260: $output .= '<br />';
7261: }
7262: $output .= '</fieldset>';
7263: }
7264: }
7265: $output .= '</fieldset>';
7266: }
7267: }
7268: }
7269: return $output;
7270: }
7271:
1.93 raeburn 7272: sub print_linkprotection {
1.102 raeburn 7273: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7274:
7275: my %linkprotection;
7276: my $count = 0;
7277: my $next = 1;
1.102 raeburn 7278: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7279: if ($noedit) {
7280: $disabled = ' disabled="disabled"';
7281: }
1.100 raeburn 7282: my %desc = &linkprot_names();
7283: my %lt = &Apache::lonlocal::texthash (
7284: 'requ' => 'Required settings',
7285: 'opti' => 'Optional settings',
7286: );
1.93 raeburn 7287: my $itemcount = 0;
7288:
1.100 raeburn 7289: my $ltiauth;
1.102 raeburn 7290: if ($context eq 'domain') {
7291: $ltiauth = 1;
7292: } else {
7293: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7294: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7295: } else {
7296: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7297: $ltiauth = $domdefs{'crsltiauth'};
7298: }
7299: }
7300: if ($context eq 'domain') {
7301: $dest = '/adm/domainprefs';
1.100 raeburn 7302: } else {
1.102 raeburn 7303: $dest = '/adm/courseprefs';
7304: }
7305:
7306: my ($switchserver,$switchmessage);
7307: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7308: if ($switchserver) {
7309: if ($context eq 'domain') {
7310: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
7311: } elsif ($crstype eq 'Community') {
7312: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7313: } else {
7314: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7315: }
1.100 raeburn 7316: }
1.99 raeburn 7317:
1.105 raeburn 7318: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7319: if (keys(%{$settings->{'linkprot'}})) {
7320: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7321: $next += $current[-1];
7322: for (my $i=0; $i<@current; $i++) {
7323: my $num = $current[$i];
7324: my %values;
1.102 raeburn 7325: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7326: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7327: } else {
7328: next;
7329: }
7330: my $selected;
7331: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7332: $selected = ' selected="selected"';
7333: }
7334: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7335: $datatable .=
7336: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7337: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7338: &mt('Delete?').'</label></span></td><td>';
1.122 ! raeburn 7339: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
! 7340: $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
! 7341: $passbacksty = 'none';
! 7342: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
! 7343: %checkedpassback = (
! 7344: 'no' => ' checked="checked"',
! 7345: 'yes' => '',
! 7346: );
! 7347: %checkedpassbackfmt = (
! 7348: '1p1' => ' checked="checked"',
! 7349: '1p0' => '',
! 7350: );
! 7351: if ($values{'passback'} ne '') {
! 7352: $passbacksty = 'inline-block';
! 7353: $checkedpassback{'yes'} = ' checked="checked"';
! 7354: $checkedpassback{'no'} = '';
! 7355: if ($values{'passbackformat'} eq '1.0') {
! 7356: $checkedpassbackfmt{'1p0'} = ' checked="checked"';
! 7357: $checkedpassbackfmt{'1p1'} = '';
! 7358: }
! 7359: }
1.100 raeburn 7360: if ($ltiauth) {
7361: $usersty = 'display:none';
1.112 raeburn 7362: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7363: %checkedrequser = (
7364: no => ' checked="checked"',
7365: yes => '',
7366: );
7367: if ($values{'requser'}) {
7368: $checkedrequser{'yes'} = $checkedrequser{'no'};
7369: $checkedrequser{'no'} = '';
7370: }
7371: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7372: if ($values{'requser'}) {
7373: $usersty = 'display:inline-block';
7374: }
7375: }
1.112 raeburn 7376: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7377: %checkedreturnurl = (
7378: no => ' checked="checked"',
7379: yes => '',
7380: );
7381: if ($values{'returnurl'} ne '') {
7382: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7383: $checkedreturnurl{'no'} = '';
7384: }
1.100 raeburn 7385: $datatable .=
7386: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7387: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7388: (' 'x2).
1.100 raeburn 7389: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7390: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7391: (' 'x2).
1.100 raeburn 7392: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7393: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7394: if ($values{'key'} ne '') {
1.100 raeburn 7395: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7396: if ($noedit) {
7397: $datatable .= ': ['.&mt('not shown').']';
7398: } elsif ($switchserver) {
7399: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7400: } else {
7401: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7402: }
7403: $datatable .= '</span> '.(' 'x2);
7404: } elsif (!$switchserver) {
1.100 raeburn 7405: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7406: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7407: '</span> '.(' 'x2);
7408: }
7409: if ($switchserver) {
7410: if ($values{'usable'} ne '') {
7411: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7412: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7413: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7414: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
1.99 raeburn 7415: (' 'x2).
1.118 raeburn 7416: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
1.99 raeburn 7417: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7418: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7419: '</div>';
7420: } elsif ($values{'key'} eq '') {
1.102 raeburn 7421: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7422: } else {
1.102 raeburn 7423: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7424: }
1.111 raeburn 7425: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7426: } else {
7427: if ($values{'usable'} ne '') {
7428: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7429: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7430: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7431: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
1.99 raeburn 7432: (' 'x2).
1.118 raeburn 7433: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7434: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7435: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7436: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7437: '<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 7438: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7439: } else {
7440: $datatable .=
1.100 raeburn 7441: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7442: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7443: '<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 7444: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7445: }
7446: }
1.112 raeburn 7447: $datatable .= '<br /><br />'.
1.122 ! raeburn 7448: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
! 7449: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
! 7450: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
! 7451: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
! 7452: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
! 7453: '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
! 7454: '<span class="LC_nobreak">'.&mt('Grade format').
! 7455: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
! 7456: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
! 7457: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
! 7458: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
! 7459: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
! 7460: '<br />'.
1.112 raeburn 7461: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7462: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7463: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7464: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7465: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7466: ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7467: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7468: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7469: '</span></div> ';
1.100 raeburn 7470: if ($ltiauth) {
1.112 raeburn 7471: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7472: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7473: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7474: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7475: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7476: '</fieldset>'.
7477: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7478: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7479: '</fieldset>';
7480: }
1.99 raeburn 7481: $datatable .= '</td></tr>';
1.93 raeburn 7482: $itemcount ++;
7483: }
7484: }
7485: }
7486: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7487: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7488: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7489: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7490: '<td width="100%">';
1.122 ! raeburn 7491: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
! 7492: $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.100 raeburn 7493: if ($ltiauth) {
7494: $usersty = 'display:none';
1.112 raeburn 7495: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7496: %checkedrequser = (
7497: no => ' checked="checked"',
7498: yes => '',
7499: );
7500: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7501: }
1.122 ! raeburn 7502: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
! 7503: %checkedpassback = (
! 7504: 'no' => ' checked="checked"',
! 7505: 'yes' => '',
! 7506: );
! 7507: %checkedpassbackfmt = (
! 7508: '1p1' => ' checked="checked"',
! 7509: '1p0' => '',
! 7510: );
1.112 raeburn 7511: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7512: %checkedreturnurl = (
7513: no => ' checked="checked"',
7514: yes => '',
7515: );
1.100 raeburn 7516: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7517: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7518: (' 'x2).
1.100 raeburn 7519: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7520: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7521: (' 'x2).
1.112 raeburn 7522: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7523: '<br /><br />';
1.99 raeburn 7524: if ($switchserver) {
1.102 raeburn 7525: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7526: } else {
1.100 raeburn 7527: $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 7528: (' 'x2).
1.116 raeburn 7529: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7530: '<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 7531: }
1.112 raeburn 7532: $datatable .= '<br /><br />'.
1.122 ! raeburn 7533: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
! 7534: '<label><input type="radio" name="linkprot_passback_add" value="0"'.
! 7535: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
! 7536: '<label><input type="radio" name="linkprot_passback_add" value="1"'.
! 7537: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
! 7538: '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none" />'.
! 7539: '<span class="LC_nobreak">'.&mt('Grade format').
! 7540: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
! 7541: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
! 7542: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
! 7543: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
! 7544: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
! 7545: '<br />'.
1.112 raeburn 7546: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7547: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7548: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7549: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7550: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7551: ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7552: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7553: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7554: '</span></div> ';
7555: if ($ltiauth) {
7556: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7557: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7558: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7559: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7560: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7561: '</fieldset>'.
1.100 raeburn 7562: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7563: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7564: '</fieldset>';
7565: }
1.99 raeburn 7566: $datatable .= '</td></tr>';
1.93 raeburn 7567: $$rowtotal ++;
1.101 raeburn 7568: return $datatable;
1.93 raeburn 7569: }
7570:
7571: sub linkprot_names {
1.100 raeburn 7572: return &Apache::lonlocal::texthash(
1.93 raeburn 7573: 'version' => 'LTI Version',
7574: 'key' => 'Key',
7575: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7576: 'name' => 'Launcher Application',
1.93 raeburn 7577: 'secret' => 'Secret',
1.122 ! raeburn 7578: 'passback' => 'Can return grades to Launcher',
1.112 raeburn 7579: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7580: 'requser' => 'Use identity',
7581: 'email' => 'Email address',
7582: 'sourcedid' => 'User ID',
7583: 'other' => 'Other',
7584: 'auth' => 'Display LON-CAPA login page',
7585: 'reject' => 'Discontinue launch process',
1.93 raeburn 7586: );
7587: }
7588:
1.99 raeburn 7589: sub check_switchserver {
1.102 raeburn 7590: my ($cdom,$cnum,$context,$dest) = @_;
7591: my ($allowed,$switchserver,$home);
7592: if ($context eq 'domain') {
7593: $home = &Apache::lonnet::domain($cdom,'primary');
7594: } else {
7595: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7596: }
7597: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7598: my @ids=&Apache::lonnet::current_machine_ids();
7599: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7600: if (!$allowed) {
7601: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7602: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7603: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7604: }
7605: }
7606: return $switchserver;
7607: }
7608:
1.100 raeburn 7609: sub linkprot_options {
7610: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7611: my %lt;
7612: if (ref($desc) eq 'HASH') {
7613: %lt = %{$desc};
7614: }
7615: my $userfieldsty = 'none';
7616: my (%checked,$userfield);
7617: $checked{'sourcedid'} = ' checked="checked"';
7618: $checked{'reject'} = ' checked="checked"';
7619: if (ref($current) eq 'HASH') {
7620: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7621: $checked{'sourcedid'} = '';
7622: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7623: $checked{'email'} = ' checked="checked"';
7624: } else {
7625: $checked{'other'} = ' checked="checked"';
7626: $userfield = $current->{'mapuser'};
7627: $userfieldsty = 'inline-block';
7628: }
7629: }
7630: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7631: $checked{'reject'} = '';
7632: $checked{'auth'} = ' checked="checked"';
7633: }
7634: }
1.112 raeburn 7635: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7636: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7637: &mt('Source of LON-CAPA username in LTI request').': ';
7638: foreach my $option ('sourcedid','email','other') {
7639: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7640: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7641: ($option eq 'other' ? '' : (' 'x2) );
7642: }
7643: $output .= '</span></div>'.
7644: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7645: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7646: 'value="'.$userfield.'"'.$disabled.' /></div>';
7647: $output .= '<br />'.
7648: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7649: &mt('Action when username is not for an enrolled student').': ';
7650: foreach my $option ('reject','auth') {
7651: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7652: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7653: ($option eq 'auth' ? '' : (' 'x2) );
7654: }
7655: $output .= '</span></div>';
7656: return $output;
7657: }
7658:
1.114 raeburn 7659: sub print_extresource_row {
7660: my ($item,$config,$curr,$noedit) = @_;
7661: my $onchange;
7662: unless ($noedit) {
7663: $onchange = ' onchange="javascript:toggleExtRes();"';
7664: }
7665: my $id = 'LC_'.$item;
7666: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7667: my $output = &select_from_options($item,$config->{'order'},
7668: $config->{'options'},$selected,
7669: $config->{'nullval'},
7670: undef,undef,$onchange,$noedit,$id);
7671: my ($checked,$reusesty,$sizesty);
7672: if ($reuse) {
7673: $checked = ' checked="checked"';
7674: }
7675: $reusesty = 'none';
7676: $sizesty = 'none';
7677: if (($selected eq 'window') || ($selected eq 'tab')) {
7678: $reusesty = 'inline-block';
7679: if ($selected eq 'window') {
7680: $sizesty = 'inline-block';
7681: }
7682: }
7683: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7684: '<span class="LC_nobreak">'.
7685: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7686: &mt('Re-use tab/window').'</label>'.
7687: '</span></div>'.
7688: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7689: '<legend>'.&mt('Window size (optional)').'</legend>'.
7690: '<span class="LC_nobreak">'.
7691: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7692: (' ' x 3).
7693: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7694: '</span></fieldset>';
7695: return $output;
7696: }
7697:
1.1 raeburn 7698: sub print_other {
1.80 raeburn 7699: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7700: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7701: return;
7702: }
1.3 raeburn 7703: my @ordered = &get_other_items($cdom,$settings,$allitems);
7704: my %items;
7705: foreach my $parameter (@ordered) {
7706: $items{$parameter} = {
7707: text => '<b>'.$parameter.'</b>',
7708: input => 'textbox',
7709: size => '15',
7710: },
7711: }
7712: push (@ordered,'newp_value');
7713: $items{'newp_value'} = {
7714: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7715: '<input type="textbox" name="newp_name"'.
7716: ' value="" size="30" />',
7717: input => 'textbox',
7718: size => '30',
7719: };
1.93 raeburn 7720: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7721: }
7722:
7723: sub get_other_items {
7724: my ($cdom,$settings,$allitems) = @_;
7725: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7726: return;
7727: }
1.1 raeburn 7728: my @ordered;
7729: if (ref($settings) eq 'HASH') {
7730: foreach my $parameter (sort(keys(%{$settings}))) {
7731: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7732: next if (($parameter eq 'course.helper.not.run') &&
7733: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7734: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7735: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7736: || ($parameter eq 'type') ||
1.50 raeburn 7737: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7738: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7739: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7740: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7741: push(@ordered,$parameter);
7742: }
7743: }
7744: }
1.3 raeburn 7745: return @ordered;
1.1 raeburn 7746: }
7747:
7748: sub item_table_row_start {
1.91 raeburn 7749: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7750: my $output;
1.56 raeburn 7751: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7752: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7753: if ($leftclass eq '') {
7754: $leftclass = 'LC_left_item';
7755: }
7756: if ($rightclass eq '') {
7757: $rightclass = 'LC_right_item';
7758: }
1.56 raeburn 7759: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7760: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7761: '</td>';
1.91 raeburn 7762: if ($colspan > 1) {
7763: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7764: } else {
1.91 raeburn 7765: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7766: }
1.1 raeburn 7767: return $output;
7768: }
7769:
7770: sub item_table_row_end {
7771: return '</td></tr>';
7772: }
7773:
7774: sub yesno_radio {
1.80 raeburn 7775: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
1.1 raeburn 7776: my $itemon = ' ';
7777: my $itemoff = ' checked="checked" ';
1.69 raeburn 7778: if (($valueyes eq '') && ($valueno eq '')) {
7779: $valueyes = 'yes';
7780: $valueno = '';
7781: }
1.1 raeburn 7782: if (ref($settings) eq 'HASH') {
1.69 raeburn 7783: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7784: $itemon = $itemoff;
7785: $itemoff = ' ';
7786: }
1.69 raeburn 7787: unless (exists($settings->{$item})) {
7788: if ($unsetdefault eq $valueyes) {
7789: $itemon = $itemoff;
7790: $itemoff = ' ';
7791: }
7792: }
1.1 raeburn 7793: }
1.80 raeburn 7794: my $disabled;
7795: if ($noedit) {
7796: $disabled = ' disabled="disabled"';
7797: }
1.1 raeburn 7798: return '<span class="LC_nobreak"><label>'.
7799: '<input type="radio" name="'.$item.'"'.
1.80 raeburn 7800: $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
1.1 raeburn 7801: '<label><input type="radio" name="'.$item.'"'.
1.80 raeburn 7802: $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
1.1 raeburn 7803: }
7804:
7805: sub select_from_options {
1.91 raeburn 7806: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7807: my $output;
1.80 raeburn 7808: my $disabled;
7809: if ($noedit) {
7810: $disabled = ' disabled=disabled"';
7811: }
1.1 raeburn 7812: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7813: $output='<select name="'.$item.'" '.$onchange;
7814: if ($multiple) {
7815: $output .= ' multiple="multiple"';
7816: my $num = @{$order};
7817: $num ++ if ($nullval ne '');
7818: if (($maxsize) && ($maxsize < $num)) {
7819: $output .= ' size="'.$maxsize.'"';
7820: }
7821: }
1.91 raeburn 7822: if ($id ne '') {
7823: $output .= ' id="'.$id.'"';
7824: }
1.80 raeburn 7825: $output .= $disabled.'>'."\n";
1.1 raeburn 7826: if ($nullval ne '') {
7827: $output .= '<option value=""';
7828: if (ref($curr) eq 'ARRAY') {
7829: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7830: $output .= ' selected="selected" ';
7831: }
7832: } else {
7833: if ($curr eq '') {
7834: $output .= ' selected="selected" ';
7835: }
7836: }
7837: $output .= '>'.$nullval.'</option>';
7838: }
7839: foreach my $option (@{$order}) {
7840: $output.= '<option value="'.$option.'"';
7841: if (ref($curr) eq 'ARRAY') {
7842: if (grep(/^\Q$option\E$/,@{$curr})) {
7843: $output .= ' selected="selected" ';
7844: }
7845: } else {
7846: if ($option eq $curr) {
7847: $output.=' selected="selected"';
7848: }
7849: }
7850: $output.=">$options->{$option}</option>\n";
7851: }
7852: $output.="</select>";
7853: }
7854: return $output;
7855: }
7856:
7857: sub make_item_rows {
1.80 raeburn 7858: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
1.1 raeburn 7859: my $datatable;
7860: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7861: my $count = 0;
7862: foreach my $item (@{$ordered}) {
7863: $count ++;
1.56 raeburn 7864: my $colspan;
7865: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7866: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7867: $colspan = 2;
7868: }
1.114 raeburn 7869: my $rowdesc;
7870: if ($caller eq 'appearance') {
7871: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7872: } else {
7873: $rowdesc = $items->{$item}{text};
7874: }
1.41 www 7875: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7876: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7877: } else {
1.114 raeburn 7878: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7879: }
1.55 raeburn 7880: if ($item eq 'defaultcredits') {
7881: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7882: my $showcredits;
7883: if ($defaultcredits ne '') {
7884: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7885: } else {
7886: $showcredits = &mt('No default set');
7887: }
7888: $datatable .= $showcredits;
7889: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 7890: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 7891: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 7892: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7893: } elsif ($item eq 'print_header_format') {
1.80 raeburn 7894: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 7895: } elsif ($item eq 'lti.lcmenu') {
7896: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 7897: } elsif ($item eq 'extresource') {
7898: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7899: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 7900: my $disabled;
7901: if ($noedit) {
7902: $disabled = ' disabled="disabled"';
7903: }
1.1 raeburn 7904: $datatable .=
7905: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 7906: $settings->{$item},$disabled);
1.1 raeburn 7907: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 7908: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 7909: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 7910: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7911: unless ($domdefs{$item} eq '0') {
7912: $unsetdefault = 1;
7913: }
7914: $valueyes = "1";
7915: $valueno = "0";
1.87 raeburn 7916: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
7917: $valueyes = '1';
1.69 raeburn 7918: }
1.80 raeburn 7919: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7920: } elsif ($items->{$item}{input} eq 'selectbox') {
1.91 raeburn 7921: my $id;
7922: if ($caller eq 'menuitems') {
7923: $id = $item;
7924: }
1.1 raeburn 7925: my $curr = $settings->{$item};
7926: $datatable .=
7927: &select_from_options($item,$items->{$item}{'order'},
7928: $items->{$item}{'options'},$curr,
1.80 raeburn 7929: $items->{$item}{'nullval'},
1.91 raeburn 7930: undef,undef,undef,$noedit,$id);
1.1 raeburn 7931: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 7932: my $disabled;
7933: if ($noedit) {
7934: $disabled = ' disabled=disabled"';
7935: }
1.1 raeburn 7936: $datatable .=
7937: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 7938: $items->{$item}{size},
7939: $disabled);
1.1 raeburn 7940: }
7941: $datatable .= &item_table_row_end();
7942: }
7943: if (ref($rowtotal)) {
7944: $$rowtotal += scalar(@{$ordered});
7945: }
7946: }
7947: return $datatable;
7948: }
7949:
7950: sub nothidepriv_row {
1.80 raeburn 7951: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 7952: my ($cnum) = &get_course();
1.56 raeburn 7953: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 7954: if (ref($settings) eq 'HASH') {
7955: if ($settings->{$item} ne '') {
7956: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
7957: if ($user !~ /:/) {
7958: $nothide{join(':',split(/[\@]/,$user))}=1;
7959: } else {
7960: $nothide{$user} = 1;
7961: }
7962: }
7963: }
1.56 raeburn 7964: if ($settings->{'checkforpriv'}) {
7965: @checkdoms = split(/,/,$settings->{'checkforpriv'});
7966: }
1.1 raeburn 7967: }
1.56 raeburn 7968: push(@checkdoms,$cdom);
7969: my %coursepersonnel =
7970: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 7971: my @privusers;
7972: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 7973: my ($uname,$udom,$role) = split(/:/,$person);
7974: my $user = $uname.':'.$udom;
7975: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 7976: if ($end == -1 || $start == -1) {
7977: next;
7978: }
1.56 raeburn 7979: foreach my $dom (@checkdoms) {
7980: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
7981: unless (grep(/^\Q$user\E$/,@privusers)) {
7982: push(@privusers,$user);
1.3 raeburn 7983: }
7984: }
7985: }
1.1 raeburn 7986: }
1.56 raeburn 7987: if (@privusers > 0) {
1.80 raeburn 7988: my $disabled;
7989: if ($noedit) {
7990: $disabled = ' disabled="disabled"';
7991: }
1.1 raeburn 7992: $datatable .= '<table align="right">';
7993: foreach my $user (sort(@privusers)) {
7994: my $hideon = ' checked="checked" ';
7995: my $hideoff = '';
7996: if ($nothide{$user}) {
7997: $hideoff = $hideon;
7998: $hideon = '';
7999: }
8000: my ($uname,$udom) = split(':',$user);
8001: $datatable .= '<tr><td align="left">'.
8002: &Apache::loncommon::aboutmewrapper(
8003: &Apache::loncommon::plainname($uname,$udom,'firstname'),
8004: $uname,$udom,'aboutuser').
8005: '</td><td align="left">'.
8006: '<span class="LC_nobreak"><label>'.
8007: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8008: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 8009: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8010: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 8011: '</tr>';
8012: }
8013: $datatable .= '</table>';
8014: } else {
1.9 raeburn 8015: if ($crstype eq 'Community') {
8016: $datatable .= &mt('No Domain Coordinators have community roles');
8017: } else {
8018: $datatable .= &mt('No Domain Coordinators have course roles');
8019: }
1.1 raeburn 8020: }
8021: return $datatable;
8022: }
8023:
1.56 raeburn 8024: sub checkforpriv_row {
1.80 raeburn 8025: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 8026: my $datatable;
8027: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8028: if (keys(%domains) == 1) {
8029: $datatable = '</td><td align="right">'.
8030: &mt("Course's domain is only domain");
8031: return $datatable;
8032: }
8033: my @excdoms = ($cdom);
8034: my $num = 0;
8035: if ($settings->{$item} eq '') {
8036: $datatable = '</td><td align="right">'.
8037: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 8038: 1,1,undef,undef,\@excdoms,
8039: $noedit);
1.56 raeburn 8040: } else {
8041: my @privdoms = split(/,/,$settings->{$item});
8042: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8043: $datatable = '</td><td align="right"><br />'.
8044: &Apache::loncommon::start_data_table();
1.80 raeburn 8045: my $disabled;
8046: if ($noedit) {
8047: $disabled = ' disabled="disabled"';
8048: }
1.56 raeburn 8049: if (@privdoms > 0) {
8050: foreach my $currdom (@privdoms) {
8051: next unless ($domains{$currdom});
8052: my $domdesc = &Apache::lonnet::domain($currdom,'description');
8053: if ($domdesc eq '') {
8054: $domdesc = $currdom;
8055: }
8056: $datatable .=
8057: &Apache::loncommon::start_data_table_row().
8058: '<td align="left"><span class="LC_nobreak">'.
8059: &mt('Domain:').'<b> '.$domdesc.
8060: '</b><input type="hidden" name="checkforpriv_'.$num.
8061: '" value="'.$currdom.'" /></span><br />'.
8062: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 8063: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
8064: &mt('Delete').'</label></span></td>'.
1.56 raeburn 8065: &Apache::loncommon::end_data_table_row();
8066: $num ++;
8067: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
8068: push(@excdoms,$currdom);
8069: }
8070: }
8071: }
8072: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
8073: $datatable .=
8074: &Apache::loncommon::start_data_table_row().
8075: '<td align="left"><span class="LC_nobreak">'.
8076: &mt('Additional domain:'). '</span><br />'.
8077: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8078: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8079: '</td>'.&Apache::loncommon::end_data_table_row();
8080: }
8081: $datatable .= &Apache::loncommon::end_data_table().
8082: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8083: '<br />';
8084: }
8085: return $datatable;
8086: }
8087:
1.1 raeburn 8088: sub print_hdrfmt_row {
1.80 raeburn 8089: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8090: my @curr;
8091: my $currnum = 0;
8092: my $maxnum = 2;
8093: my $currstr;
8094: if ($settings->{$item} ne '') {
8095: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8096: $settings->{$item}.'</tt></span></b><br />';
8097: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8098: foreach my $val (@current) {
8099: unless ($val eq '') {
8100: push(@curr,$val);
1.1 raeburn 8101: }
8102: }
8103: $currnum = @curr;
8104: $maxnum += $currnum;
8105: }
8106:
8107: my $output = <<ENDJS;
8108:
8109: <script type="text/javascript" language="Javascript">
8110:
8111: function reOrder(chgnum) {
8112: var maxnum = $maxnum;
8113: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8114: var newidx = 'printfmthdr_pos_'+chgnum;
8115: oldidx = getIndexByName(oldidx);
8116: newidx = getIndexByName(newidx);
8117: var oldpos = document.display.elements[oldidx].value;
8118: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8119: document.display.elements[oldidx].value = newpos;
8120: var chgtype = 'up';
8121: if (newpos < oldpos) {
8122: chgtype = 'down';
8123: }
8124: for (var j=0; j<maxnum; j++) {
8125: if (j != chgnum) {
8126: oldidx = 'printfmthdr_oldpos_'+j;
8127: newidx = 'printfmthdr_pos_'+j;
8128: oldidx = getIndexByName(oldidx);
8129: newidx = getIndexByName(newidx);
8130: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8131: var currsel = document.display.elements[newidx].selectedIndex;
8132: if (chgtype == 'up') {
8133: if ((currpos > oldpos) && (currpos <= newpos)) {
8134: document.display.elements[newidx].selectedIndex = currsel-1;
8135: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8136: }
8137: } else {
8138: if ((currpos >= newpos) && (currpos < oldpos)) {
8139: document.display.elements[newidx].selectedIndex = currsel+1;
8140: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8141: }
8142: }
8143: }
8144: }
8145: return;
8146: }
8147:
8148: function getIndexByName(item) {
8149: for (var i=0;i<document.display.elements.length;i++) {
8150: if (document.display.elements[i].name == item) {
8151: return i;
8152: }
8153: }
8154: return -1;
8155: }
8156:
8157: </script>
8158:
8159: ENDJS
1.56 raeburn 8160: $output .= '</td><td align="right"><br />'.
8161: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8162: my $disabled;
8163: if ($noedit) {
8164: $disabled = ' disabled="disabled"';
8165: }
1.1 raeburn 8166: if (@curr > 0) {
8167: for (my $i=0; $i<@curr; $i++) {
8168: my $pos = $i+1;
1.10 raeburn 8169: $output .= '<tr>'.
1.1 raeburn 8170: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8171: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8172: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8173: '"'.$disabled.' /></span></td>';
1.1 raeburn 8174: if ($curr[$i] =~ /^%\d*[nca]$/) {
8175: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8176: $output .= '<td align="left">'.
1.80 raeburn 8177: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8178: } else {
8179: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8180: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8181: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8182: }
1.10 raeburn 8183: $output .= '</tr>';
1.1 raeburn 8184: }
8185: }
1.80 raeburn 8186: my $pos = $currnum+1;
8187: unless ($noedit) {
8188: $output .=
8189: '<tr>'.
1.1 raeburn 8190: '<td align="left"><span class="LC_nobreak">'.
8191: &position_selector($pos,$currnum,$maxnum).
8192: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8193: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8194: '</tr>';
1.80 raeburn 8195: $pos ++;
1.82 raeburn 8196: $currnum ++;
8197: $output .=
1.80 raeburn 8198: '<tr>'.
1.1 raeburn 8199: '<td align="left"><span class="LC_nobreak">'.
8200: &position_selector($pos,$currnum,$maxnum).
8201: '<b>'.&mt('New').'</b></span></td>'.
8202: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8203: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8204: '" value="" size ="25" />'.
8205: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8206: $maxnum.'" /></td>'.
1.80 raeburn 8207: '</tr>';
8208: }
8209: $output .= '</table><br />';
1.1 raeburn 8210: return $output;
8211: }
8212:
8213: sub position_selector {
1.80 raeburn 8214: my ($pos,$num,$maxnum,$disabled) = @_;
8215: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8216: for (my $j=1; $j<=$maxnum; $j++) {
8217: my $sel = '';
8218: if ($pos == $j) {
8219: $sel = ' selected="selected"';
8220: }
8221: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8222: }
8223: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8224: '" value="'.$pos.'" />';
8225: return $output;
8226: }
8227:
8228: sub substitution_selector {
1.80 raeburn 8229: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8230: my ($stunametxt,$crsidtxt);
8231: if ($crstype eq 'Community') {
8232: $stunametxt = 'member name';
8233: $crsidtxt = 'community ID',
8234: } else {
8235: $stunametxt = 'student name';
8236: $crsidtxt = 'course ID',
8237: }
1.1 raeburn 8238: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8239: n => $stunametxt,
8240: c => $crsidtxt,
1.1 raeburn 8241: a => 'assignment note',
8242: );
8243: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8244: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8245: if ($subst eq '') {
8246: $output .= '<option value="" selected="selected"> </option>';
8247: }
8248: foreach my $field ('n','c','a') {
8249: my $sel ='';
8250: if ($subst eq $field) {
8251: $sel = ' selected="selected"';
8252: }
8253: $output .= '<option value="'.$field.'"'.$sel.'>'.
8254: $lt{$field}.'</option>';
8255: }
8256: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8257: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8258: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8259: return $output;
8260: }
8261:
1.23 raeburn 8262: sub change_clone {
8263: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8264: my $clone_crs = $cnum.':'.$cdom;
8265: if ($cnum && $cdom) {
8266: my $clone_crs = $cnum.':'.$cdom;
8267: my @allowclone;
8268: if ($clonelist =~ /,/) {
8269: @allowclone = split(',',$clonelist);
8270: } else {
8271: $allowclone[0] = $clonelist;
8272: }
8273: foreach my $currclone (@allowclone) {
8274: if (!grep(/^$currclone$/,@$oldcloner)) {
8275: if ($currclone ne '*') {
1.71 raeburn 8276: if ($currclone =~ /:/) {
8277: my ($uname,$udom) = split(/:/,$currclone);
8278: if ($uname && $udom && $uname ne '*') {
8279: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8280: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8281: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8282: if ($currclonecrs{'cloneable'} eq '') {
8283: $currclonecrs{'cloneable'} = $clone_crs;
8284: } else {
8285: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8286: }
8287: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8288: }
8289: }
8290: }
8291: }
8292: }
8293: }
8294: }
8295: foreach my $oldclone (@$oldcloner) {
8296: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8297: if ($oldclone ne '*') {
1.71 raeburn 8298: if ($oldclone =~ /:/) {
8299: my ($uname,$udom) = split(/:/,$oldclone);
8300: if ($uname && $udom && $uname ne '*' ) {
8301: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8302: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8303: my %newclonecrs = ();
8304: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8305: if ($currclonecrs{'cloneable'} =~ /,/) {
8306: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8307: foreach my $crs (@currclonecrs) {
8308: if ($crs ne $clone_crs) {
8309: $newclonecrs{'cloneable'} .= $crs.',';
8310: }
1.23 raeburn 8311: }
1.71 raeburn 8312: $newclonecrs{'cloneable'} =~ s/,$//;
8313: } else {
8314: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8315: }
1.71 raeburn 8316: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8317: }
8318: }
8319: }
8320: }
8321: }
8322: }
8323: }
8324: }
8325: return;
8326: }
8327:
1.108 raeburn 8328: sub devalidate_remote_courseprefs {
8329: my ($cdom,$cnum,$cachekeys) = @_;
8330: return unless (ref($cachekeys) eq 'HASH');
8331: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8332: my %thismachine;
8333: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8334: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8335: if (keys(%servers)) {
8336: foreach my $server (keys(%servers)) {
8337: next if ($thismachine{$server});
8338: my @cached;
8339: foreach my $name (@posscached) {
8340: if ($cachekeys->{$name}) {
8341: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8342: }
8343: }
8344: if (@cached) {
8345: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8346: }
8347: }
8348: }
8349: return;
8350: }
8351:
1.1 raeburn 8352: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>