Annotation of loncom/interface/courseprefs.pm, revision 1.126
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.126 ! raeburn 4: # $Id: courseprefs.pm,v 1.125 2023/07/20 12:47:10 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.124 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.124 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: }
1.126 ! raeburn 697: } elsif (($item eq 'linkprot') || ($item eq 'ltitools')) {
! 698: push(@allitems,$item);
1.3 raeburn 699: }
700: }
701: }
702: return @allitems;
703: }
704:
1.1 raeburn 705: sub print_config_box {
1.99 raeburn 706: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 707: my $ordered = $item->{'ordered'};
1.3 raeburn 708: my $itemtext = $item->{'itemtext'};
1.80 raeburn 709: my $noedit;
710: if (ref($parm_permission) eq 'HASH') {
711: unless ($parm_permission->{'process'}) {
712: $noedit = 1;
713: }
714: }
1.1 raeburn 715: my $rowtotal = 0;
716: my $output =
1.45 www 717: '<table class="LC_nested_outer">
718: <tr>
719: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 720: &mt($item->{text});
721: if ($item->{'help'}) {
1.53 raeburn 722: $output .= ' '.
1.52 raeburn 723: &Apache::loncommon::help_open_topic($item->{'help'});
724: }
725: $output .= '</span></th>'."\n".
726: '</tr>';
1.91 raeburn 727: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 728: $output .= '
1.45 www 729: <tr>
730: <td>
1.18 faziophi 731: <table class="LC_nested">';
732: if (exists $item->{'header'}->[0]->{'col1'} ||
733: exists $item->{'header'}->[0]->{'col2'}) {
734: $output .= '
735: <tr class="LC_info_row">
1.56 raeburn 736: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
737: if ($action eq 'feedback') {
738: $output .= '
739: <td class="LC_right_item" colspan="2">';
740: } else {
741: $output .= '
742: <td class="LC_right_item">';
743: }
744: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 745: </tr>';
746: }
1.1 raeburn 747: $rowtotal ++;
748: if ($action eq 'feedback') {
1.80 raeburn 749: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 750: } elsif ($action eq 'classlists') {
1.80 raeburn 751: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 752: } elsif ($action eq 'menuitems') {
753: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 754: }
755: $output .= '
756: </table>
1.45 www 757: </td>
758: </tr>
759: <tr>
760: <td>
1.1 raeburn 761: <table class="LC_nested">
762: <tr class="LC_info_row">
763: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 764: if ($action eq 'classlists') {
765: $output .= '
766: <td class="LC_right_item" colspan="2">';
767: } else {
768: $output .= '
769: <td class="LC_right_item">';
770: }
771: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 772: </tr>';
773: if ($action eq 'classlists') {
1.80 raeburn 774: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 775: '
776: </table>
1.45 www 777: </td>
778: </tr>
779: <tr>
780: <td>
1.18 faziophi 781: <table class="LC_nested">';
1.43 www 782: if (exists $item->{'header'}->[2]->{'col1'} ||
783: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 784: $output .= '
785: <tr class="LC_info_row">
1.43 www 786: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
787: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 788: </tr>';
789: }
1.1 raeburn 790: }
791: } else {
792: $output .= '
1.45 www 793: <tr>
794: <td>
1.18 faziophi 795: <table class="LC_nested">';
796: if (exists $item->{'header'}->[0]->{'col1'} ||
797: exists $item->{'header'}->[0]->{'col2'}) {
798: $output .= '
799: <tr class="LC_info_row">
1.56 raeburn 800: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
801: if (($action eq 'courseinfo') || ($action eq 'localization') ||
802: ($action eq 'print_discussion')) {
803: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
804: } else {
805: $output .= '<td class="LC_right_item" valign="top">';
806: }
807: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 808: </tr>';
809: }
1.1 raeburn 810: }
811: $rowtotal ++;
812: if ($action eq 'courseinfo') {
1.80 raeburn 813: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 814: } elsif ($action eq 'localization') {
1.80 raeburn 815: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 816: } elsif ($action eq 'feedback') {
1.80 raeburn 817: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 818: } elsif ($action eq 'discussion') {
1.80 raeburn 819: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 820: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 821: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 822: } elsif ($action eq 'appearance') {
1.80 raeburn 823: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 824: } elsif ($action eq 'grading') {
1.80 raeburn 825: $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 826: } elsif ($action eq 'printouts') {
1.80 raeburn 827: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 828: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 829: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 830: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 831: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.118 raeburn 832: } elsif ($action eq 'ltitools') {
833: my $currtools = {};
834: if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
835: $currtools = $settings->{'ltitools'};
836: }
837: $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
1.87 raeburn 838: } elsif ($action eq 'lti') {
839: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 840: } elsif ($action eq 'menuitems') {
841: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 842: } elsif ($action eq 'linkprot') {
843: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 844: } elsif ($action eq 'other') {
1.80 raeburn 845: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 846: }
847: $output .= '
848: </table>
1.45 www 849: </td>
850: </tr>
851: </table><br />';
1.1 raeburn 852: return ($output,$rowtotal);
853: }
854:
855: sub process_changes {
1.108 raeburn 856: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 857: my (%newvalues,$errors);
1.3 raeburn 858: if (ref($item) eq 'HASH') {
859: if (ref($changes) eq 'HASH') {
860: my @ordered;
861: if ($action eq 'other') {
862: @ordered = &get_other_items($cdom,$values,$allitems);
863: if ($env{'form.newp_name'} ne '') {
864: my $newp = $env{'form.newp_name'};
865: if ($env{'form.newp_value'} ne '') {
866: if (ref($allitems) eq 'ARRAY') {
867: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
868: (grep(/^\Q$newp\E$/,@{$allitems}))) {
869: $changes->{$newp} = $env{'form.newp_value'};
870: }
871: }
872: }
873: }
1.118 raeburn 874: } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.99 raeburn 875: if (ref($values->{$action}) eq 'HASH') {
876: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 877: if ($id =~ /^\d+$/) {
878: push(@ordered,$id);
879: }
880: }
881: }
882: @ordered = sort { $a <=> $b } @ordered;
1.118 raeburn 883: if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
884: push(@ordered,$env{'form.'.$action.'_maxnum'});
1.93 raeburn 885: }
1.3 raeburn 886: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 887: if ($action eq 'courseinfo') {
888: my ($can_toggle_cat,$can_categorize) =
889: &can_modify_catsettings($cdom,$crstype);
890: foreach my $entry (@{$item->{'ordered'}}) {
891: next if (($entry eq 'hidefromcat') &&
892: (!$can_toggle_cat));
893: next if (($entry eq 'categories') &&
894: (!$can_categorize));
895: next if (($entry eq 'loncaparev') ||
1.63 raeburn 896: ($entry eq 'owner') ||
1.88 raeburn 897: ($entry eq 'clonedfrom') ||
898: ($entry eq 'syllabus'));
1.49 raeburn 899: push(@ordered,$entry);
900: }
1.55 raeburn 901: } elsif ($action eq 'classlists') {
902: foreach my $entry (@{$item->{'ordered'}}) {
903: next if ($entry eq 'defaultcredits');
904: push(@ordered,$entry);
905: }
1.49 raeburn 906: } else {
907: @ordered = @{$item->{'ordered'}};
908: }
1.3 raeburn 909: }
910: if (@ordered > 0) {
911: if ($action eq 'feedback') {
912: foreach my $entry (@ordered) {
913: my $userstr = '';
914: my $total = $env{'form.'.$entry.'_total'};
915: if ($total) {
916: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
917: for (my $i=0; $i<$total; $i++) {
918: unless (grep(/^$i$/,@deletes)) {
919: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
920: &get_sec_str($entry,$i).',';
921: }
922: }
923: } else {
924: $total = 0;
925: }
926: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
927: my $uname = $env{'form.'.$entry.'_uname_'.$total};
928: my $udom = $env{'form.'.$entry.'_udom_'.$total};
929: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
930: $userstr =~ s/,$//;
931: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
932: } else {
933: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
934: }
935: } else {
936: $userstr =~ s/,$//;
937: }
938: $newvalues{$entry} = $userstr;
939: if ($newvalues{$entry} ne $values->{$entry}) {
940: $changes->{$entry} = $newvalues{$entry};
941: }
942: my $ext_entry = $entry.'.text';
943: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
944: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
945: $changes->{$ext_entry} = $newvalues{$ext_entry};
946: }
947: }
1.91 raeburn 948: } elsif ($action eq 'menuitems') {
949: my (%current,@colls);
950: my $next = 1;
951: if ($values->{'menucollections'}) {
952: foreach my $item (split(/;/,$values->{'menucollections'})) {
953: my ($num,$value) = split(/\%/,$item);
954: if ($num =~ /^\d+$/) {
955: unless (grep(/^$num$/,@colls)) {
956: push(@colls,$num);
957: }
958: my @entries = split(/\&/,$value);
959: foreach my $entry (@entries) {
960: my ($name,$fields) = split(/=/,$entry);
961: $current{$num}{$name} = $fields;
962: }
963: }
964: }
965: }
966: if (@colls) {
967: @colls = sort { $a <=> $b } @colls;
968: $next += $colls[-1];
969: }
970: if ($env{'form.menucollections_add'} eq $next) {
971: push(@colls,$next);
972: }
973: my $currdef = $values->{'menudefault'};
974: my $possdef = $env{'form.menudefault'};
975: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 976: if ($currdef ne $possdef) {
1.91 raeburn 977: $changes->{'menudefault'} = $possdef;
978: }
1.92 raeburn 979: } elsif ($currdef) {
1.91 raeburn 980: $changes->{'menudefault'} = '';
981: }
982: my $menucoll;
983: if (@colls) {
984: my ($ordered,$cats) = &menuitems_categories();
985: my %shortcats = &menuitems_abbreviations();
986: foreach my $num (@colls) {
987: my ($entry,%include);
988: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
989: foreach my $item (@{$ordered}) {
990: if ($item eq 'shown') {
991: foreach my $type (@{$cats->{$item}}) {
992: $entry .= $type.'=';
993: if ($include{$type}) {
994: $entry .= 'y';
995: } else {
996: $entry .= 'n';
997: }
998: $entry .= '&';
999: }
1000: } else {
1001: $entry .= $shortcats{$item}.'=';
1002: foreach my $type (@{$cats->{$item}}) {
1003: if ($include{$type}) {
1004: $entry .= $type.',';
1005: }
1006: }
1007: $entry =~ s/,$//;
1008: $entry .= '&';
1009: }
1010: }
1011: $entry =~ s/\&$//;
1012: if ($menucoll) {
1013: $menucoll .= ';';
1014: }
1015: $menucoll .= $num.'%'.$entry;
1016: }
1017: if ($menucoll ne $values->{'menucollections'}) {
1018: $changes->{'menucollections'} = $menucoll;
1019: }
1020: } elsif ($values->{'menucollections'}) {
1021: $changes->{'menucollections'} = '';
1022: }
1.102 raeburn 1023: } elsif ($action eq 'linkprot') {
1024: if (ref($values) eq 'HASH') {
1.108 raeburn 1025: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 1026: }
1.118 raeburn 1027: } elsif ($action eq 'ltitools') {
1028: if (ref($values) eq 'HASH') {
1029: my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1030: $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1031: 'ok','','ok');
1032: }
1.3 raeburn 1033: } else {
1034: foreach my $entry (@ordered) {
1035: if ($entry eq 'cloners') {
1036: if ($env{'form.cloners_all'}) {
1037: $newvalues{$entry} = '*';
1038: } else {
1039: my @clonedoms;
1040: if (exists($env{'form.cloners_activate'})) {
1041: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1042: if ($actnum ne '-1') {
1.33 raeburn 1043: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1044: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1045: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1046: $newvalues{$entry} = '*:'.$clonedom;
1047: push(@clonedoms,$newvalues{$entry});
1048: }
1049: }
1050: }
1051: } else {
1052: my $num = $env{'form.cloners_total'};
1053: my @deletes =
1054: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1055: for (my $i=0; $i<$num; $i++) {
1056: if (!grep(/^$i$/,@deletes)) {
1057: my $clonedom = $env{'form.cloners_dom_'.$i};
1058: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1059: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1060: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1061: }
1062: }
1063: }
1064: }
1065: if (@clonedoms) {
1066: $newvalues{$entry}=join(',',@clonedoms);
1067: }
1068: }
1069: if ($env{'form.cloners_newdom'} ne '') {
1070: my $clonedom = $env{'form.cloners_newdom'};
1071: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1072: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1073: if (@clonedoms) {
1.3 raeburn 1074: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1075: $newvalues{$entry} .= ','.$newdom;
1076: }
1077: } else {
1078: $newvalues{$entry} = $newdom;
1079: }
1080: }
1081: }
1082: if ($env{'form.'.$entry} ne '') {
1083: my @cloners = split(',',$env{'form.'.$entry});
1084: my @okcloners;
1085: foreach my $cloner (@cloners) {
1.23 raeburn 1086: $cloner =~ s/^\s+//;
1087: $cloner =~ s/\s+$//;
1088: unless ($cloner eq '') {
1089: my ($uname,$udom) = split(':',$cloner);
1090: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1091: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1092: push(@okcloners,$cloner);
1093: }
1.3 raeburn 1094: }
1095: }
1096: }
1097: if (@okcloners) {
1098: my $okclonestr = join(',',@okcloners);
1099: if ($newvalues{$entry} ne '') {
1100: $newvalues{$entry} .= ','.$okclonestr;
1101: } else {
1102: $newvalues{$entry} = $okclonestr;
1103: }
1104: }
1105: }
1.71 raeburn 1106: if (ref($values) eq 'HASH') {
1107: my (@code_order,%codedefaults);
1108: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1109: \@code_order);
1110: my $clonebycode;
1111: if ($env{'form.cloners_instcode'}) {
1112: if (@code_order > 0) {
1113: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1114: my %local_to_standard;
1115: for (my $i=0; $i<@code_order; $i++) {
1116: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1117: }
1118: foreach my $item (@code_order) {
1119: my $key = $local_to_standard{$item};
1120: if ($key ne '') {
1121: if ($env{'form.'.$key}) {
1122: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1123: }
1124: }
1125: }
1126: $clonebycode =~ s/\&$//;
1127: }
1128: }
1129: if ($clonebycode) {
1130: if ($newvalues{$entry}) {
1131: $newvalues{$entry} .= ','.$clonebycode;
1132: } else {
1133: $newvalues{$entry} = $clonebycode;
1134: }
1135: }
1136: }
1.3 raeburn 1137: }
1138: if (ref($disallowed) eq 'HASH') {
1139: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1140: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1141: $disallowed->{'cloners'}{$key} =~ s/,$//;
1142: }
1143: }
1144: }
1.25 raeburn 1145: } elsif ($entry eq 'co-owners') {
1146: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1147: my $coowners = $values->{'internal.co-owners'};
1148: my @currcoown;
1149: if ($coowners) {
1150: @currcoown = split(',',$coowners);
1151: }
1152: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1153: my $autocoowner;
1154: if (($crstype eq 'Course') &&
1155: ($values->{'internal.coursecode'})) {
1156: my %domconf =
1157: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1158: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1159: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1160: }
1161: }
1.96 raeburn 1162: if ($autocoowner) {
1163: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1164: } else {
1.25 raeburn 1165: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1166: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1167: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1168: if (@invitecoowners) {
1169: push(@pendingcoowners,@invitecoowners);
1170: }
1171: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1172: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1173: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1174: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1175: push(@{$changes->{$entry}{'changed'}},'co-owners');
1176: }
1177: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1178: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1179: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1180: }
1181: }
1182: } else {
1183: my (@newpending,@newcoown);
1184: my $uname = $env{'user.name'};
1185: my $udom = $env{'user.domain'};
1186: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1187: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1188: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1189: foreach my $item (@pendingcoown) {
1190: unless ($item eq $uname.':'.$udom) {
1191: push(@newpending,$item);
1192: }
1193: }
1194: @newcoown = @currcoown;
1.90 raeburn 1195: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1196: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1197: push(@newcoown,$uname.':'.$udom);
1198: }
1199: }
1.90 raeburn 1200: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1201: foreach my $item (@currcoown) {
1202: unless ($item eq $uname.':'.$udom) {
1203: push(@newcoown,$item);
1204: }
1205: }
1206: if ($pendingcoowners ne '') {
1207: @newpending = @pendingcoown;
1208: }
1.96 raeburn 1209: } else {
1210: @newcoown = @currcoown;
1.25 raeburn 1211: }
1212: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1213: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1214: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1215: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1216: push(@{$changes->{$entry}{'changed'}},'co-owners');
1217: }
1218: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1219: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1220: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1221: }
1222: }
1.3 raeburn 1223: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1224: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1225: } elsif ($entry eq 'rolenames') {
1226: my %adv_roles =
1227: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1228: my @stds;
1229: if ($crstype eq 'Community') {
1230: @stds = ('co');
1231: } else {
1232: @stds = ('cc');
1233: }
1234: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1235: my (@replacements,@regulars);
1236: foreach my $role (@stds) {
1237: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1238: push(@replacements,$role);
1.3 raeburn 1239: } else {
1240: push(@regulars,$role);
1241: }
1.9 raeburn 1242: }
1.3 raeburn 1243: foreach my $stdrole (@stds) {
1244: my $ext_entry = $entry.'_'.$stdrole;
1245: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1246: $env{'request.course.id'},1);
1247: if ($env{'form.'.$ext_entry} eq $stdname) {
1248: $newvalues{$ext_entry} = '';
1249: } else {
1250: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1251: }
1252: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1253: my $dupname = 0;
1254: if ($newvalues{$ext_entry} ne '') {
1255: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1256: $dupname = 1;
1257: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1258: }
1259: if (!$dupname) {
1260: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1261: $dupname = 1;
1262: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1263: }
1264: }
1265: if (!$dupname) {
1266: foreach my $role (keys(%adv_roles)) {
1267: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1268: $dupname = 1;
1269: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1270: last;
1271: }
1272: }
1273: }
1274: }
1275: if (!$dupname) {
1276: $changes->{$ext_entry} = $newvalues{$ext_entry};
1277: }
1278: }
1279: }
1.77 raeburn 1280: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1281: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1282: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1283: @denied = sort(@denied);
1284: my $deniedstr = '';
1285: if (@denied > 0) {
1286: $deniedstr = join(',',@denied);
1287: }
1288: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1289: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1290: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1291: my $total = $env{'form.'.$entry.'_total'};
1292: my $userstr = '';
1293: my @denied;
1294: if ($total > 0) {
1295: my @deletes =
1296: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1297: for (my $i=0; $i<$total; $i++) {
1298: unless (grep(/^$i$/,@deletes)) {
1299: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1300: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1301: }
1302: }
1303: } else {
1304: $total = 0;
1305: }
1306: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1307: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1308: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1309: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1310: $userstr =~ s/,$//;
1311: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1312: } else {
1313: my $newuser .= $uname.':'.$udom;
1314: if (grep(/^\Q$newuser\E$/,@denied)) {
1315: $userstr =~ s/,$//;
1316: } else {
1317: $userstr .= $newuser;
1318: }
1319: }
1320: } else {
1321: $userstr =~ s/,$//;
1322: }
1323: $newvalues{$entry} = $userstr;
1324: } elsif ($entry eq 'allow_discussion_post_editing') {
1325: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1326: @canedit = sort(@canedit);
1327: foreach my $role (@canedit) {
1328: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1329: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1330: $newvalues{$entry} .= $role.',';
1331: } else {
1332: foreach my $sec (@secs) {
1333: $newvalues{$entry} .= $role.':'.$sec.',';
1334: }
1335: }
1336: }
1337: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1338: } elsif ($entry eq 'discussion_post_fonts') {
1339: my ($classorder,$classtitles) = &discussion_vote_classes();
1340: my $fontchange = 0;
1341: foreach my $class (@{$classorder}) {
1.124 raeburn 1342: my $ext_entry = $entry.'_'.$class;
1.50 raeburn 1343: my $size = $env{'form.'.$ext_entry.'_size'};
1344: my $unit = $env{'form.'.$ext_entry.'_unit'};
1345: my $weight = $env{'form.'.$ext_entry.'_weight'};
1346: my $style = $env{'form.'.$ext_entry.'_style'};
1347: my $other = $env{'form.'.$ext_entry.'_other'};
1348: $size =~ s/,//g;
1.124 raeburn 1349: $unit =~ s/,//g;
1.50 raeburn 1350: $weight =~ s/,//g;
1351: $style =~ s/,//g;
1352: $other =~ s/[^\w;:\s\-\%.]//g;
1353: $other =~ s/(^\s+|\s+$)//g;
1354: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1355: my $current = $values->{$ext_entry};
1356: if ($values->{$ext_entry} eq '') {
1.124 raeburn 1357: $current = ',,,';
1.50 raeburn 1358: }
1359: if ($newvalues{$ext_entry} ne $current) {
1360: $changes->{$ext_entry} = $newvalues{$ext_entry};
1361: $fontchange ++;
1362: }
1363: }
1364: if ($fontchange) {
1365: $changes->{$entry} = 1;
1.124 raeburn 1366: }
1.3 raeburn 1367: } elsif ($entry eq 'nothideprivileged') {
1368: my @curr_nothide;
1369: my @new_nothide;
1370: if ($values->{$entry} ne '') {
1371: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1372: my $nothide;
1373: if ($user !~ /:/) {
1374: $nothide = join(':',split(/[\@]/,$user));
1375: } else {
1376: $nothide = $user;
1377: }
1378: if ((defined($nothide)) &&
1379: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1380: push(@curr_nothide,$nothide);
1381: }
1382: }
1383: }
1384: foreach my $key (keys(%env)) {
1385: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1386: if ($env{$key}) {
1.3 raeburn 1387: my $nothide = $1;
1388: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1389: push(@new_nothide,$nothide);
1390: }
1391: }
1392: }
1393: }
1394: @new_nothide = sort(@new_nothide);
1395: my @differences =
1396: &Apache::loncommon::compare_arrays(\@curr_nothide,
1397: \@new_nothide);
1398: if (@differences > 0) {
1399: if (@new_nothide > 0) {
1400: $newvalues{$entry} = join(',',@new_nothide);
1401: } else {
1402: $newvalues{$entry} = '';
1403: }
1404: } else {
1405: $newvalues{$entry} = $values->{$entry};
1406: }
1407: } elsif ($entry eq 'print_header_format') {
1408: my $maxnum = $env{'form.printfmthdr_maxnum'};
1409: my @newhdr;
1410: if ($maxnum > 2) {
1411: for (my $i=0; $i<$maxnum-2; $i++) {
1412: if ($env{'form.printfmthdr_del_'.$i}) {
1413: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1414: } else {
1415: my $hdr;
1416: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1417: $hdr = '%';
1418: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1419: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1420: }
1421: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1422: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1423: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1424: }
1425: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1426: }
1427: }
1428: }
1429: my $newsub = $maxnum-2;
1430: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1431: my $hdr = '%';
1432: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1433: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1434: }
1435: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1436: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1437: }
1438: my $newtext = $maxnum-1;
1439: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1440: $newvalues{$entry} = join('',@newhdr);
1.124 raeburn 1441: } elsif (($entry eq 'languages') ||
1.56 raeburn 1442: ($entry eq 'checkforpriv')) {
1443: my $settings;
1.3 raeburn 1444: my $total = $env{'form.'.$entry.'_total'};
1445: if ($total) {
1446: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1447: for (my $i=0; $i<$total; $i++) {
1448: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1449: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1450: }
1451: }
1452: } else {
1453: $total = 0;
1454: }
1455: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1456: my $new = $env{'form.'.$entry.'_'.$total};
1.124 raeburn 1457: if ($entry eq 'languages') {
1.56 raeburn 1458: my %langchoices = &get_lang_choices();
1459: if ($langchoices{$new}) {
1460: $settings .= $new;
1461: } else {
1462: $settings =~ s/,$//;
1463: $disallowed->{'localization'}{$entry} = $new;
1464: }
1.3 raeburn 1465: } else {
1.56 raeburn 1466: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1467: if ($domains{$new}) {
1468: $settings .= $new;
1469: } else {
1470: $settings =~ s/,$//;
1471: $disallowed->{'classlists'}{$entry} = $new;
1472: }
1.3 raeburn 1473: }
1474: } else {
1.56 raeburn 1475: $settings =~ s/,$//;
1.3 raeburn 1476: }
1.56 raeburn 1477: $newvalues{$entry} = $settings;
1.87 raeburn 1478: } elsif ($action eq 'lti') {
1479: if ($entry eq 'lti.override') {
1480: $newvalues{$entry} = $env{'form.'.$entry};
1481: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1482: if ($env{'form.lti.override'}) {
1483: $newvalues{$entry} = $env{'form.'.$entry};
1484: } else {
1485: $newvalues{$entry} = '';
1486: }
1487: } elsif ($entry eq 'lti.lcmenu') {
1488: if (($env{'form.lti.override'}) &&
1489: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1490: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1491: my @newlcmenu;
1492: if (@lcmenu) {
1493: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1494: foreach my $item (@menuitems) {
1495: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1496: if (grep(/^\Q$item\E$/,@lcmenu)) {
1497: push(@newlcmenu,$item);
1498: }
1499: }
1500: }
1501: if (@newlcmenu) {
1502: $newvalues{$entry} = join(',',@newlcmenu);
1503: } else {
1504: $newvalues{$entry} = 'none';
1505: }
1506: } else {
1507: $newvalues{$entry} = '';
1508: }
1509: }
1.114 raeburn 1510: } elsif ($entry eq 'extresource') {
1511: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1512: $newvalues{$entry} = $env{'form.'.$entry};
1513: if ($env{'form.'.$entry} ne 'iframe') {
1514: if ($env{'form.extwintabreuse'}) {
1515: $newvalues{$entry} .= ':1';
1516: } else {
1517: $newvalues{$entry} .= ':0';
1518: }
1519: if ($env{'form.'.$entry} eq 'window') {
1520: foreach my $dim ('width','height') {
1521: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1522: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1523: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1524: } else {
1525: $newvalues{$entry} .= ':';
1526: }
1527: }
1528: }
1529: }
1530: }
1531: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1532: if ($newvalues{$entry} ne $values->{$entry}) {
1533: $changes->{$entry} = $newvalues{$entry};
1534: }
1535: }
1.115 raeburn 1536: } elsif ($entry eq 'timezone') {
1537: if ($env{'form.'.$entry}) {
1538: $newvalues{$entry} = $env{'form.'.$entry};
1539: if ($newvalues{$entry} ne $values->{$entry}) {
1540: $changes->{$entry} = $newvalues{$entry};
1541: }
1542: if ($env{'form.tzover'}) {
1543: $newvalues{'tzover'} = $env{'form.tzover'};
1544: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1545: $changes->{'tzover'} = $newvalues{'tzover'};
1546: }
1547: } elsif ($values->{'tzover'}) {
1548: $changes->{'tzover'} = '';
1549: }
1550: } elsif ($values->{$entry}) {
1551: $changes->{$entry} = '';
1552: }
1.3 raeburn 1553: } else {
1554: $newvalues{$entry} = $env{'form.'.$entry};
1555: }
1.124 raeburn 1556: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1.115 raeburn 1557: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1558: if ($newvalues{$entry} ne $values->{$entry}) {
1559: $changes->{$entry} = $newvalues{$entry};
1560: }
1.3 raeburn 1561: }
1562: }
1563: }
1564: }
1565: }
1566: }
1.93 raeburn 1567: return $errors;
1568: }
1569:
1.102 raeburn 1570: sub process_linkprot {
1.108 raeburn 1571: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.118 raeburn 1572: my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1573: if (ref($values) eq 'HASH') {
1574: foreach my $id (keys(%{$values})) {
1575: if ($id =~ /^\d+$/) {
1576: unless (ref($values->{$id}) eq 'HASH') {
1577: $linkprot{$id} = '';
1578: }
1579: }
1580: }
1581: }
1.118 raeburn 1582: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.102 raeburn 1583: if ($context eq 'domain') {
1584: $dest = '/adm/domainprefs';
1585: $ltiauth = 1;
1586: } else {
1587: $dest = '/adm/courseprefs';
1588: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1589: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1590: } else {
1591: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1592: $ltiauth = $domdefs{'crsltiauth'};
1593: }
1594: }
1595: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1596: my (@items,%deletions,%itemids,%haschanges);
1597: if ($env{'form.linkprot_add'}) {
1598: my $name = $env{'form.linkprot_name_add'};
1599: $name =~ s/(`)/'/g;
1600: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1601: if ($newid) {
1602: $itemids{'add'} = $newid;
1603: push(@items,'add');
1604: $haschanges{$newid} = 1;
1605: } else {
1606: $errors .= '<span class="LC_error">'.
1607: &mt('Failed to acquire unique ID for link protection').
1608: '</span>';
1609: }
1610: }
1611: if (ref($values) eq 'HASH') {
1612: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1613: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1614: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1615: my $itemid = $env{'form.linkprot_id_'.$i};
1616: $itemid =~ s/\D+//g;
1617: if ($itemid) {
1618: if (ref($values->{$itemid}) eq 'HASH') {
1619: push(@items,$i);
1620: $itemids{$i} = $itemid;
1621: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1622: $deletions{$itemid} = $values->{$itemid}->{'name'};
1623: }
1624: }
1625: }
1626: }
1627: }
1628: foreach my $idx (@items) {
1629: my $itemid = $itemids{$idx};
1630: next unless ($itemid);
1631: if (exists($deletions{$itemid})) {
1632: $linkprot{$itemid} = $deletions{$itemid};
1633: $haschanges{$itemid} = 1;
1634: next;
1635: }
1636: my %current;
1637: if (ref($values) eq 'HASH') {
1638: if (ref($values->{$itemid}) eq 'HASH') {
1639: foreach my $key (keys(%{$values->{$itemid}})) {
1640: $current{$key} = $values->{$itemid}->{$key};
1641: }
1642: }
1643: }
1644: foreach my $inner ('name','lifetime','version') {
1645: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1646: $env{$formitem} =~ s/(`)/'/g;
1647: if ($inner eq 'lifetime') {
1648: $env{$formitem} =~ s/[^\d.]//g;
1649: }
1650: unless ($idx eq 'add') {
1651: if ($current{$inner} ne $env{$formitem}) {
1652: $haschanges{$itemid} = 1;
1653: }
1654: }
1655: if ($env{$formitem} ne '') {
1656: $linkprot{$itemid}{$inner} = $env{$formitem};
1657: }
1658: }
1.112 raeburn 1659: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1660: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1661: if ($env{$urlitem} == 1) {
1662: $env{$urlparamname} =~ s/(`)/'/g;
1663: } elsif (exists($env{$urlparamname})) {
1664: $env{$urlparamname} = '';
1665: }
1.122 raeburn 1666: my $passback = 'form.linkprot_passback_'.$idx;
1667: my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
1668: if ($env{$passback} == 1) {
1669: unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
1670: $env{$passbackparamname} = '';
1671: }
1672: } elsif (exists($env{$passbackparamname})) {
1673: $env{$passbackparamname} = '';
1674: }
1.112 raeburn 1675: unless ($idx eq 'add') {
1676: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1677: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1678: $haschanges{$itemid} = 1;
1679: }
1.122 raeburn 1680: if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
1681: ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
1682: $haschanges{$itemid} = 1;
1683: }
1.112 raeburn 1684: }
1.123 raeburn 1685: if ($env{$urlparamname} ne '') {
1686: $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1687: }
1.122 raeburn 1688: if ($env{$passbackparamname} ne '') {
1689: $linkprot{$itemid}{'passback'} = 1;
1690: $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1.112 raeburn 1691: }
1.102 raeburn 1692: if ($ltiauth) {
1693: my $reqitem = 'form.linkprot_requser_'.$idx;
1694: $env{$reqitem} =~ s/(`)/'/g;
1695: unless ($idx eq 'add') {
1.104 raeburn 1696: if ((!$current{'requser'} && $env{$reqitem}) ||
1697: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1698: $haschanges{$itemid} = 1;
1699: }
1700: }
1701: if ($env{$reqitem} == 1) {
1702: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1703: foreach my $inner ('mapuser','notstudent') {
1704: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1705: $env{$formitem} =~ s/(`)/'/g;
1706: if ($inner eq 'mapuser') {
1707: if ($env{$formitem} eq 'other') {
1708: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1709: $mapuser =~ s/(`)/'/g;
1710: $mapuser =~ s/^\s+|\s+$//g;
1711: if ($mapuser ne '') {
1712: $linkprot{$itemid}{$inner} = $mapuser;
1713: } else {
1714: delete($linkprot{$itemid}{'requser'});
1715: last;
1716: }
1717: } elsif ($env{$formitem} eq 'sourcedid') {
1718: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1719: } elsif ($env{$formitem} eq 'email') {
1720: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1721: }
1722: } else {
1723: $linkprot{$itemid}{$inner} = $env{$formitem};
1724: }
1725: unless ($idx eq 'add') {
1726: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1727: $haschanges{$itemid} = 1;
1728: }
1729: }
1730: }
1731: }
1732: }
1733: unless ($switchserver) {
1734: my $keyitem = 'form.linkprot_key_'.$idx;
1735: $env{$keyitem} =~ s/(`)/'/g;
1736: unless ($idx eq 'add') {
1737: if ($current{'key'} ne $env{$keyitem}) {
1738: $haschanges{$itemid} = 1;
1739: }
1740: }
1741: if ($env{$keyitem} ne '') {
1742: $linkprot{$itemid}{'key'} = $env{$keyitem};
1743: }
1744: my $secretitem = 'form.linkprot_secret_'.$idx;
1745: $env{$secretitem} =~ s/(`)/'/g;
1746: if ($current{'usable'}) {
1747: if ($env{'form.linkprot_changesecret_'.$idx}) {
1748: if ($env{$secretitem} ne '') {
1.103 raeburn 1749: if ($privnum && $cipher) {
1750: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1751: $linkprot{$itemid}{'cipher'} = $privnum;
1752: } else {
1753: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1754: }
1.102 raeburn 1755: $haschanges{$itemid} = 1;
1756: }
1757: } else {
1758: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1759: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1760: }
1761: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1762: if ($privnum && $cipher) {
1763: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1764: $linkprot{$itemid}{'cipher'} = $privnum;
1765: } else {
1766: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1767: }
1.102 raeburn 1768: $haschanges{$itemid} = 1;
1769: }
1770: }
1771: }
1772: if (keys(%haschanges)) {
1773: foreach my $entry (keys(%haschanges)) {
1774: $changes->{$entry} = $linkprot{$entry};
1775: }
1.108 raeburn 1776: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1777: $lastactref->{'courselti'} = 1;
1.108 raeburn 1778: }
1.102 raeburn 1779: }
1780: return $errors;
1781: }
1782:
1783: sub get_linkprot_id {
1784: my ($cdom,$cnum,$name,$context) = @_;
1785: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1786: my $lockhash = {
1787: lock => $env{'user.name'}.
1788: ':'.$env{'user.domain'},
1789: };
1790: my $tries = 0;
1.102 raeburn 1791: my $gotlock;
1792: if ($context eq 'domain') {
1793: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1794: } else {
1795: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1796: }
1.93 raeburn 1797: my ($id,$error);
1798: while (($gotlock ne 'ok') && ($tries<10)) {
1799: $tries ++;
1800: sleep (0.1);
1.102 raeburn 1801: if ($context eq 'domain') {
1.124 raeburn 1802: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1.102 raeburn 1803: } else {
1804: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1805: }
1.93 raeburn 1806: }
1807: if ($gotlock eq 'ok') {
1.102 raeburn 1808: my %currids;
1809: if ($context eq 'domain') {
1810: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1811: } else {
1812: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1813: }
1.93 raeburn 1814: if ($currids{'lock'}) {
1815: delete($currids{'lock'});
1816: if (keys(%currids)) {
1817: my @curr = sort { $a <=> $b } keys(%currids);
1818: if ($curr[-1] =~ /^\d+$/) {
1819: $id = 1 + $curr[-1];
1820: } else {
1821: $id = 1;
1822: }
1823: } else {
1824: $id = 1;
1825: }
1826: if ($id) {
1.102 raeburn 1827: if ($context eq 'domain') {
1828: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1829: $error = 'nostore';
1830: }
1831: } else {
1832: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1833: $error = 'nostore';
1834: }
1.93 raeburn 1835: }
1836: } else {
1837: $error = 'nonumber';
1838: }
1839: }
1.124 raeburn 1840: my $dellockoutcome;
1.102 raeburn 1841: if ($context eq 'domain') {
1842: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1843: } else {
1844: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1845: }
1.93 raeburn 1846: } else {
1847: $error = 'nolock';
1848: }
1849: return ($id,$error);
1.3 raeburn 1850: }
1851:
1.118 raeburn 1852: sub get_credentials {
1853: my ($cdom,$cnum,$type,$context) = @_;
1854: my ($cipher,$privnum,$home);
1855: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1856: my @ids=&Apache::lonnet::current_machine_ids();
1857: if ($context eq 'domain') {
1858: $home = &Apache::lonnet::domain($cdom,'primary');
1859: } else {
1860: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1861: }
1862: my ($hostskey,$domkey,$crskey);
1863: if ($type eq 'ltitools') {
1864: $hostskey = 'toolprivhosts';
1865: $domkey = 'toolenc_dom';
1866: $crskey = 'toolenc_crs';
1867: } else {
1868: $hostskey = 'ltiprivhosts';
1869: $domkey = 'linkprotenc_dom';
1870: $crskey = 'linkprotenc_crs';
1871: }
1872: if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1873: (($context eq 'course') && ($domdefs{$crskey}))) {
1874: unless (($home eq 'no_host') || ($home eq '')) {
1875: if (grep(/^\Q$home\E$/,@ids)) {
1876: if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1877: if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1878: my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1879: my $privkey = $privhash{'key'};
1880: $privnum = $privhash{'version'};
1881: if (($privnum) && ($privkey ne '')) {
1882: $cipher = Crypt::CBC->new({'key' => $privkey,
1883: 'cipher' => 'DES'});
1884: }
1885: }
1886: }
1887: }
1888: }
1889: }
1890: return ($cipher,$privnum);
1891: }
1892:
1893: sub process_ltitools {
1894: my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1895: $author_ok,$confname) = @_;
1896: my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1897:
1898: my (%posslti,%possfield);
1899: my @courseroles = ('cc','in','ta','ep','st');
1900: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1901: map { $posslti{$_} = 1; } @ltiroles;
1902: my @allfields = ('fullname','firstname','lastname','email','user','roles');
1903: map { $possfield{$_} = 1; } @allfields;
1904:
1.120 raeburn 1905: my ($dest,$privnum,$cipher);
1.118 raeburn 1906:
1907: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1908: if ($context eq 'domain') {
1909: $dest = '/adm/domainprefs';
1910: } else {
1911: $dest = '/adm/courseprefs';
1912: }
1913: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1914:
1915: my (@allpos,@items,%deletions,%itemids,%haschanges);
1916: if ($env{'form.ltitools_add'}) {
1917: my $title = $env{'form.ltitools_add_title'};
1918: $title =~ s/(`)/'/g;
1.125 raeburn 1919: my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
1.118 raeburn 1920: if ($newid) {
1921: my $position = $env{'form.ltitools_add_pos'};
1922: $position =~ s/\D+//g;
1923: if ($position ne '') {
1924: $allpos[$position] = $newid;
1925: }
1926: $haschanges{$newid} = 1;
1927: foreach my $item ('title','url','lifetime') {
1928: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1929: if ($item eq 'lifetime') {
1930: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1931: }
1932: if ($env{'form.ltitools_add_'.$item}) {
1933: $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1934: }
1935: }
1936: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1937: $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1938: }
1939: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1940: $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1941: }
1942: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1943: $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1944: } else {
1945: $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1946: }
1947: foreach my $item ('width','height','linktext','explanation') {
1948: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1949: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1950: if (($item eq 'width') || ($item eq 'height')) {
1951: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1952: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1953: }
1954: } else {
1955: if ($env{'form.ltitools_add_'.$item} ne '') {
1956: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1957: }
1958: }
1959: }
1960: if ($env{'form.ltitools_add_target'} eq 'window') {
1961: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1962: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1963: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1964: } else {
1965: $ltitools{$newid}{'display'}{'target'} = 'iframe';
1966: }
1967: foreach my $item ('passback','roster') {
1968: if ($env{'form.ltitools_'.$item.'_add'}) {
1969: $ltitools{$newid}{$item} = 1;
1970: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1971: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1972: $lifetime =~ s/^\s+|\s+$//g;
1973: if ($lifetime =~ /^\d+\.?\d*$/) {
1974: $ltitools{$newid}{$item.'valid'} = $lifetime;
1975: }
1976: }
1977: }
1978: }
1979: if ($env{'form.ltitools_add_image.filename'} ne '') {
1980: my ($imageurl,$error) =
1981: &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
1982: $newid,$configuserok,$lonhost,$author_ok);
1983: if ($imageurl) {
1984: $ltitools{$newid}{'image'} = $imageurl;
1985: }
1986: if ($error) {
1987: &Apache::lonnet::logthis($error);
1988: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1989: }
1990: }
1991: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
1992: foreach my $field (@fields) {
1993: if ($possfield{$field}) {
1994: if ($field eq 'roles') {
1995: foreach my $role (@courseroles) {
1996: my $choice = $env{'form.ltitools_add_roles_'.$role};
1997: if (($choice ne '') && ($posslti{$choice})) {
1998: $ltitools{$newid}{'roles'}{$role} = $choice;
1999: if ($role eq 'cc') {
2000: $ltitools{$newid}{'roles'}{'co'} = $choice;
2001: }
2002: }
2003: }
2004: } else {
2005: $ltitools{$newid}{'fields'}{$field} = 1;
2006: }
2007: }
2008: }
2009: if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
2010: if ($ltitools{$newid}{'fields'}{'user'}) {
2011: if ($env{'form.ltitools_add_userincdom'}) {
2012: $ltitools{$newid}{'incdom'} = 1;
2013: }
2014: }
2015: }
2016: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
2017: foreach my $item (@courseconfig) {
2018: $ltitools{$newid}{'crsconf'}{$item} = 1;
2019: }
2020: if ($env{'form.ltitools_add_custom'}) {
2021: my $name = $env{'form.ltitools_add_custom_name'};
2022: my $value = $env{'form.ltitools_add_custom_value'};
2023: $value =~ s/(`)/'/g;
2024: $name =~ s/(`)/'/g;
2025: $ltitools{$newid}{'custom'}{$name} = $value;
2026: }
2027: unless ($switchserver) {
2028: my $keyitem = 'form.ltitools_add_key';
2029: $env{$keyitem} =~ s/(`)/'/g;
2030: if ($env{$keyitem} ne '') {
2031: $ltitools{$newid}{'key'} = $env{$keyitem};
2032: }
1.119 raeburn 2033: my $secretitem = 'form.ltitools_secret_add';
1.118 raeburn 2034: $env{$secretitem} =~ s/(`)/'/g;
2035: if ($env{$secretitem} ne '') {
2036: if ($privnum && $cipher) {
2037: $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2038: $ltitools{$newid}{'cipher'} = $privnum;
2039: } else {
2040: $ltitools{$newid}{'secret'} = $env{$secretitem};
2041: }
2042: }
2043: }
2044: } else {
2045: $errors .= '<li><span class="LC_error">'.
2046: &mt('Failed to acquire unique ID for new external tool').
2047: '</span></li>';
2048: }
2049: }
2050: if (ref($values) eq 'HASH') {
2051: my %deletions;
2052: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2053: if (@todelete) {
2054: map { $deletions{$_} = 1; } @todelete;
2055: }
2056: my %customadds;
2057: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2058: if (@newcustom) {
2059: map { $customadds{$_} = 1; } @newcustom;
2060: }
2061: my %imgdeletions;
2062: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2063: if (@todeleteimages) {
2064: map { $imgdeletions{$_} = 1; } @todeleteimages;
2065: }
2066: my $maxnum = $env{'form.ltitools_maxnum'};
2067: for (my $i=0; $i<=$maxnum; $i++) {
2068: my $itemid = $env{'form.ltitools_id_'.$i};
2069: $itemid =~ s/\D+//g;
2070: if (ref($values->{$itemid}) eq 'HASH') {
2071: if ($deletions{$itemid}) {
2072: if ($values->{$itemid}{'image'}) {
2073: #FIXME need to obsolete item in RES space
2074: }
2075: $haschanges{$itemid} = $values->{$itemid}{'title'};
2076: next;
2077: } else {
2078: my $newpos = $env{'form.ltitools_'.$itemid};
2079: $newpos =~ s/\D+//g;
2080: foreach my $item ('title','url','lifetime') {
2081: $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2082: if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2083: $haschanges{$itemid} = 1;
2084: }
2085: }
2086: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2087: $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2088: }
2089: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2090: $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2091: }
2092: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2093: $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2094: } else {
2095: $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2096: }
2097: if ($values->{$itemid}{'sigmethod'} eq '') {
2098: if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2099: $haschanges{$itemid} = 1;
2100: }
2101: } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2102: $haschanges{$itemid} = 1;
2103: }
2104: foreach my $size ('width','height') {
2105: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2106: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2107: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2108: $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2109: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2110: if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2111: $haschanges{$itemid} = 1;
2112: }
2113: } else {
2114: $haschanges{$itemid} = 1;
2115: }
2116: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2117: if ($values->{$itemid}{'display'}{$size} ne '') {
2118: $haschanges{$itemid} = 1;
2119: }
2120: }
2121: }
2122: foreach my $item ('linktext','explanation') {
2123: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2124: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2125: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2126: $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2127: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2128: if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2129: $haschanges{$itemid} = 1;
2130: }
2131: } else {
2132: $haschanges{$itemid} = 1;
2133: }
2134: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2135: if ($values->{$itemid}{'display'}{$item} ne '') {
2136: $haschanges{$itemid} = 1;
2137: }
2138: }
2139: }
2140: if ($env{'form.ltitools_target_'.$i} eq 'window') {
2141: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2142: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2143: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2144: } else {
2145: $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2146: }
2147: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2148: if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2149: $haschanges{$itemid} = 1;
2150: }
2151: } else {
2152: $haschanges{$itemid} = 1;
2153: }
2154: foreach my $extra ('passback','roster') {
2155: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2156: $ltitools{$itemid}{$extra} = 1;
2157: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2158: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2159: $lifetime =~ s/^\s+|\s+$//g;
2160: if ($lifetime =~ /^\d+\.?\d*$/) {
2161: $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2162: }
2163: }
2164: }
2165: if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2166: $haschanges{$itemid} = 1;
2167: }
2168: if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2169: $haschanges{$itemid} = 1;
2170: }
2171: }
2172: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2173: foreach my $item ('label','title','target','linktext','explanation','append') {
2174: if (grep(/^\Q$item\E$/,@courseconfig)) {
2175: $ltitools{$itemid}{'crsconf'}{$item} = 1;
2176: if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2177: if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2178: $haschanges{$itemid} = 1;
2179: }
2180: } else {
2181: $haschanges{$itemid} = 1;
2182: }
2183: }
2184: }
2185: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2186: foreach my $field (@fields) {
2187: if ($possfield{$field}) {
2188: if ($field eq 'roles') {
2189: foreach my $role (@courseroles) {
2190: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2191: if (($choice ne '') && ($posslti{$choice})) {
2192: $ltitools{$itemid}{'roles'}{$role} = $choice;
2193: if ($role eq 'cc') {
2194: $ltitools{$itemid}{'roles'}{'co'} = $choice;
2195: }
2196: }
2197: if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2198: if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2199: $haschanges{$itemid} = 1;
2200: }
2201: } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2202: $haschanges{$itemid} = 1;
2203: }
2204: }
2205: } else {
2206: $ltitools{$itemid}{'fields'}{$field} = 1;
2207: if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2208: if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2209: $haschanges{$itemid} = 1;
2210: }
2211: } else {
2212: $haschanges{$itemid} = 1;
2213: }
2214: }
2215: }
2216: }
2217: if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2218: if ($ltitools{$itemid}{'fields'}{'user'}) {
2219: if ($env{'form.ltitools_userincdom_'.$i}) {
2220: $ltitools{$itemid}{'incdom'} = 1;
2221: }
2222: if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2223: $haschanges{$itemid} = 1;
2224: }
2225: }
2226: }
2227: $allpos[$newpos] = $itemid;
2228: }
2229: if ($imgdeletions{$itemid}) {
2230: $haschanges{$itemid} = 1;
2231: if ($context eq 'course') {
2232: my $currimgurl = $values->{$itemid}{'image'};
2233: if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2234: my ($path,$imagefile) = ($1,$2);
2235: if ($imagefile =~ /^tn\-(.+)$/) {
2236: my $origimg = $1;
2237: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2238: }
2239: &Apache::lonnet::removeuploadedurl($currimgurl);
2240: }
2241: }
2242: #FIXME need to obsolete item in RES space
2243: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2244: my $currimgurl = $values->{$itemid}{'image'};
2245: my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2246: $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2247: if ($imgurl) {
2248: $ltitools{$itemid}{'image'} = $imgurl;
2249: $haschanges{$itemid} = 1;
2250: }
2251: if ($error) {
2252: &Apache::lonnet::logthis($error);
2253: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2254: }
2255: } elsif ($values->{$itemid}{'image'}) {
2256: $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2257: }
2258: if ($customadds{$i}) {
2259: my $name = $env{'form.ltitools_custom_name_'.$i};
2260: $name =~ s/(`)/'/g;
2261: $name =~ s/^\s+//;
2262: $name =~ s/\s+$//;
2263: my $value = $env{'form.ltitools_custom_value_'.$i};
2264: $value =~ s/(`)/'/g;
2265: $value =~ s/^\s+//;
2266: $value =~ s/\s+$//;
2267: if ($name ne '') {
2268: $ltitools{$itemid}{'custom'}{$name} = $value;
2269: $haschanges{$itemid} = 1;
2270: }
2271: }
2272: my %customdels;
2273: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2274: if (@customdeletions) {
2275: $haschanges{$itemid} = 1;
2276: }
2277: map { $customdels{$_} = 1; } @customdeletions;
2278: if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2279: foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2280: unless ($customdels{$key}) {
2281: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2282: $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2283: }
2284: if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2285: $haschanges{$itemid} = 1;
2286: }
2287: }
2288: }
2289: }
2290: unless ($switchserver) {
2291: my $keyitem = 'form.ltitools_key_'.$i;
2292: $env{$keyitem} =~ s/(`)/'/g;
2293: if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2294: $haschanges{$itemid} = 1;
2295: }
2296: if ($env{$keyitem} ne '') {
2297: $ltitools{$itemid}{'key'} = $env{$keyitem};
2298: }
2299: my $secretitem = 'form.ltitools_secret_'.$i;
2300: $env{$secretitem} =~ s/(`)/'/g;
2301: if ($values->{$itemid}{'usable'}) {
2302: if ($env{'form.ltitools_changesecret_'.$i}) {
2303: if ($env{$secretitem} ne '') {
2304: if ($privnum && $cipher) {
2305: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2306: $ltitools{$itemid}{'cipher'} = $privnum;
2307: } else {
2308: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2309: }
2310: $haschanges{$itemid} = 1;
2311: }
2312: } else {
2313: $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2314: $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2315: }
2316: } elsif ($env{$secretitem} ne '') {
2317: if ($privnum && $cipher) {
2318: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2319: $ltitools{$itemid}{'cipher'} = $privnum;
2320: } else {
2321: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2322: }
2323: $haschanges{$itemid} = 1;
2324: }
2325: }
2326: unless ($haschanges{$itemid}) {
2327: foreach my $key (keys(%{$values->{$itemid}})) {
2328: if (ref($values->{$itemid}{$key}) eq 'HASH') {
2329: if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2330: foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2331: unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2332: $haschanges{$itemid} = 1;
2333: last;
2334: }
2335: }
2336: } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2337: $haschanges{$itemid} = 1;
2338: }
2339: }
2340: last if ($haschanges{$itemid});
2341: }
2342: }
2343: }
2344: }
2345: }
2346: if (@allpos > 0) {
2347: my $idx = 0;
2348: foreach my $itemid (@allpos) {
2349: if ($itemid ne '') {
2350: $ltitools{$itemid}{'order'} = $idx;
2351: if (ref($values) eq 'HASH') {
2352: if (ref($values->{$itemid}) eq 'HASH') {
2353: if ($values->{$itemid}{'order'} ne $idx) {
2354: $haschanges{$itemid} = 1;
2355: }
2356: }
2357: }
2358: $idx ++;
2359: }
2360: }
2361: }
2362: if (keys(%haschanges)) {
2363: foreach my $entry (keys(%haschanges)) {
2364: $changes->{$entry} = $ltitools{$entry};
2365: }
2366: if (ref($lastactref) eq 'HASH') {
2367: $lastactref->{'courseltitools'} = 1;
2368: }
2369: }
2370: return $errors;
2371: }
2372:
2373: sub process_ltitools_image {
2374: my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2375: my $filename = $env{'form.'.$caller.'.filename'};
2376: my ($error,$url);
2377: my ($width,$height) = (21,21);
2378: if ($configuserok eq 'ok') {
2379: if ($switch) {
2380: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2381: $switch);
2382: } elsif ($author_ok eq 'ok') {
2383: my ($result,$imageurl,$madethumb);
2384: if ($context eq 'domain') {
2385: ($result,$imageurl,$madethumb) =
2386: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2387: "ltitools/$itemid/icon",$width,$height);
2388: } else {
2389: ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2390: }
2391: if ($result eq 'ok') {
2392: if ($madethumb) {
2393: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2394: my $imagethumb = "$path/tn-".$imagefile;
2395: $url = $imagethumb;
2396: } else {
2397: $url = $imageurl;
2398: }
2399: } else {
2400: if ($context eq 'domain') {
2401: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2402: } else {
2403: $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2404: }
2405: }
2406: } else {
2407: $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);
2408: }
2409: } else {
2410: $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);
2411: }
2412: return ($url,$error);
2413: }
2414:
2415: sub processlogo {
2416: my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2417: my ($result,$imageurl,$madethumb);
2418: if ($env{"form.$caller.filename"} ne '') {
2419: unless ($caller eq 'ltitools_add_image') {
2420: if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2421: my ($path,$imagefile) = ($1,$2);
2422: if ($imagefile =~ /^tn\-(.+)$/) {
2423: my $origimg = $1;
2424: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2425: }
2426: &Apache::lonnet::removeuploadedurl($currimg);
2427: }
2428: }
2429: $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2430: '','','',$cnum,$dom,$width,$height);
2431: if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2432: my ($path,$imagefile) = ($1,$2);
2433: $result = 'ok';
2434: my $thumburl = "$path/tn-".$imagefile;
2435: my ($rtncode,$info);
2436: my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2437: if ($res eq 'ok') {
2438: $madethumb = 1;
2439: }
2440: } elsif ($imageurl eq '/adm/notfound.html') {
2441: undef($imageurl);
2442: $result = 'store failed';
2443: } elsif ($imageurl =~ /^error: (.+)$/) {
2444: $result = $1;
2445: }
2446: }
2447: return ($result,$imageurl,$madethumb);
2448: }
2449:
1.3 raeburn 2450: sub get_sec_str {
2451: my ($entry,$num) = @_;
2452: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2453: my $secstr;
2454: if (grep(/^\s*$/,@secs)) {
2455: $secstr = '';
2456: } elsif (@secs > 0) {
2457: $secstr = join(';',@secs);
2458: }
2459: if ($secstr ne '') {
2460: return '('.$secstr.')';
2461: }
2462: return;
2463: }
2464:
2465: sub check_clone {
2466: my ($clonedom,$disallowed,$clonename) = @_;
2467: return if (ref($disallowed) ne 'HASH');
2468: if ($clonedom !~ /^$match_domain$/) {
2469: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2470: return;
2471: } elsif (!&Apache::lonnet::domain($clonedom)) {
2472: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2473: return;
2474: }
2475: if ($clonename ne '') {
2476: if ($clonename !~ /^$match_username$/) {
2477: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2478: return;
2479: } else {
2480: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2481: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2482: return;
2483: }
2484: }
2485: }
2486: return 'ok';
2487: }
2488:
2489: sub store_changes {
1.9 raeburn 2490: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2491: my ($chome,$output);
1.118 raeburn 2492: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2493: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 2494: if (ref($values->{'linkprot'}) eq 'HASH') {
2495: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 2496: }
1.102 raeburn 2497: delete($values->{'linkprot'});
1.118 raeburn 2498: if (ref($values->{'ltitools'}) eq 'HASH') {
2499: %oldltitools = %{$values->{'ltitools'}};
2500: }
1.3 raeburn 2501: %storehash = %{$values};
2502: } else {
1.9 raeburn 2503: if ($crstype eq 'Community') {
2504: $output = &mt('No changes made to community settings.');
2505: } else {
2506: $output = &mt('No changes made to course settings.');
2507: }
2508: return $output;
1.3 raeburn 2509: }
1.93 raeburn 2510: my ($numchanges,$skipstore);
2511: if (ref($changes) eq 'HASH') {
2512: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 2513: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 2514: $skipstore = 1;
1.118 raeburn 2515: } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2516: $skipstore = 1;
1.93 raeburn 2517: } elsif (!$numchanges) {
2518: if ($crstype eq 'Community') {
2519: $output = &mt('No changes made to community settings.');
2520: } else {
2521: $output = &mt('No changes made to course settings.');
2522: }
2523: return $output;
2524: }
2525: }
1.3 raeburn 2526: my %yesno = (
2527: hidefromcat => '1',
2528: problem_stream_switch => '1',
2529: suppress_tries => '1',
2530: disableexampointprint => '1',
2531: hideemptyrows => '1',
2532: suppress_embed_prompt => '1',
2533: );
2534: foreach my $item (@{$prefs_order}) {
2535: if (grep(/^\Q$item\E$/,@{$actions})) {
2536: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2537: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 2538: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2539: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2540: if ($item eq 'other') {
2541: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2542: $storehash{$key} = $changes->{$item}{$key};
2543: if ($changes->{$item}{$key} eq '') {
2544: push(@delkeys,$key);
1.22 wenzelju 2545: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2546: } else {
1.22 wenzelju 2547: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2548: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2549: }
2550: }
1.102 raeburn 2551: } elsif ($item eq 'linkprot') {
2552: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.118 raeburn 2553: } elsif ($item eq 'ltitools') {
2554: $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2555: } else {
2556: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2557: my @settings = @{$prefs->{$item}->{'ordered'}};
2558: if ($item eq 'feedback') {
2559: push(@settings,(map { $_.'.text'; } @settings));
2560: }
2561: foreach my $key (@settings) {
2562: if ($key eq 'rolenames') {
2563: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2564: my $msg;
1.9 raeburn 2565: my @roles;
2566: if ($crstype eq 'Community') {
2567: @roles = ('co');
2568: } else {
2569: @roles = ('cc');
2570: }
2571: push(@roles,('in','ta','ep','ad','st'));
2572: foreach my $role (@roles) {
1.3 raeburn 2573: next if (!exists($changes->{$item}{$key.'_'.$role}));
2574: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2575: my $newname = $changes->{$item}{$key.'_'.$role};
2576: $storehash{$role.'.plaintext'} = $newname;
2577: if ($newname eq '') {
2578: $newname = $stdname;
2579: }
2580: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2581: "'<b>".$newname."</b>'").'</li>';
2582: }
2583: if ($msg ne '') {
1.22 wenzelju 2584: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2585: }
1.115 raeburn 2586: } elsif ($key eq 'timezone') {
2587: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2588: my ($displayname,$text);
2589: $text = $prefs->{$item}->{'itemtext'}{$key};
2590: my $displayval;
2591: if (exists($changes->{$item}{$key})) {
2592: $displayname = &mt($text);
2593: $storehash{$key} = $changes->{$item}{$key};
2594: if ($changes->{$item}{$key} ne '') {
2595: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2596: } else {
2597: push(@delkeys,$key);
2598: if (exists($values->{'tzover'})) {
2599: push(@delkeys,'tzover');
2600: }
2601: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2602: '<i>'.$displayname.'</i>')).'</li>';
2603: }
2604: }
2605: unless (grep(/^\Q$key\E$/,@delkeys)) {
2606: if (exists($changes->{$item}{'tzover'})) {
2607: $storehash{'tzover'} = $changes->{$item}{'tzover'};
2608: my $tzovertext;
2609: if ($changes->{$item}{'tzover'} ne '') {
2610: $tzovertext = &mt('Course Time Zone overrides individual user preference');
2611: } else {
2612: push(@delkeys,'tzover');
2613: $tzovertext = &mt('Course Time Zone does not override individual user preference');
2614: }
2615: if ($displayval eq '') {
2616: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2617: } else {
2618: $displayval .= '<br />'.(' 'x5).$tzovertext;
2619: }
2620: }
2621: if ($displayval ne '') {
2622: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2623: '<i>'.$displayname.'</i>',$displayval)).'</li>';
2624: }
2625: }
1.3 raeburn 2626: } else {
2627: next if (!exists($changes->{$item}{$key}));
2628: my ($displayname,$text);
2629: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2630: my $displayval;
1.114 raeburn 2631: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2632: $displayval = $changes->{$item}{$key};
2633: }
1.3 raeburn 2634: if ($item eq 'feedback') {
2635: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2636: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2637: $displayname = &mt('Custom text for '.$text.' questions');
2638: } else {
2639: $displayname = &mt('Recipients of '.$text.' questions');
2640: }
2641: } elsif ($item eq 'discussion') {
2642: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2643: $displayname = &mt("$text (role-based)");
2644: if ($displayval ne '') {
2645: my @roles = split(',',$displayval);
2646: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2647: $displayval = join(', ',@roles);
2648: }
2649: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2650: $displayname = &mt("$text (specific user(s))");
2651: } else {
2652: if ($key eq 'allow_discussion_post_editing') {
2653: if ($displayval ne '') {
2654: my @roles = split(',',$displayval);
2655: my @longroles;
2656: foreach my $role (@roles) {
2657: my ($trole,$sec) = split(':',$role);
2658: my $rolename =
2659: &Apache::lonnet::plaintext($trole);
2660: if ($sec ne '') {
2661: $rolename .= ':'.$sec;
2662: }
2663: push(@longroles,$rolename);
2664: }
2665: $displayval = join(', ',@longroles);
2666: }
1.50 raeburn 2667: } elsif ($key eq 'discussion_post_fonts') {
2668: my ($classorder,$classtitles)=&discussion_vote_classes();
2669: my ($styleorder,$styleitems)=&discussion_vote_styles();
2670: my $count = 1;
2671: my $total = scalar(keys(%{$changes->{$item}}));
2672: foreach my $class (@{$classorder}) {
2673: $count ++;
2674: next unless ($changes->{$item}{$key.'_'.$class});
2675: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2676: my $showval = '';
2677: for (my $i=0; $i<@{$styleorder}; $i++) {
2678: if ($vals[$i] ne '') {
2679: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2680: }
2681: }
2682: if ($vals[3] ne '') {
2683: $showval .= $vals[3];
2684: }
2685: if ($showval ne '') {
2686: $displayval .= $classtitles->{$class}.':{ '.
2687: $showval.'}';
2688: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2689: } else {
2690: $displayval .= $classtitles->{$class}.': '.&mt('None');
2691: push(@delkeys,$key.'_'.$class);
2692: }
2693: unless ($count == $total) {
2694: $displayval .= (' 'x2);
2695: }
2696: }
1.3 raeburn 2697: }
2698: $displayname = &mt($text);
2699: }
2700: } elsif ($item eq 'spreadsheet') {
2701: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2702: my $sheettype = $1;
2703: if ($sheettype eq 'studentcalc') {
2704: &Apache::lonnet::expirespread('','','studentcalc');
2705: } else {
2706: &Apache::lonnet::expirespread('','','assesscalc');
2707: &Apache::lonnet::expirespread('','','studentcalc');
2708: }
2709: }
2710: $displayname = &mt($text);
1.87 raeburn 2711: } elsif ($item eq 'lti') {
2712: if ($key eq 'lti.lcmenu') {
2713: if ($changes->{$item}{$key} eq 'none') {
2714: $displayval = &mt('None of the configurable menu items displayed');
2715: } else {
2716: my %ltititles = <imenu_titles();
2717: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2718: }
2719: } else {
2720: if ($changes->{$item}{$key} eq '1') {
2721: $displayval = &mt('Yes');
2722: } elsif ($changes->{$item}{$key} eq '') {
2723: $displayval = &mt('No');
2724: }
2725: }
2726: $displayname = &mt($text);
1.91 raeburn 2727: } elsif ($item eq 'menuitems') {
2728: unless ($changes->{$item}{$key} eq '') {
2729: if ($key eq 'menudefault') {
2730: $displayname = &mt('Default collection of menu items');
2731: $displayval = &mt('Collection: [_1]',
2732: $changes->{$item}{$key});
2733: } elsif ($key eq 'menucollections') {
2734: $displayval = &menucollections_display($changes->{$item}{$key});
2735: }
2736: }
1.3 raeburn 2737: } else {
2738: $displayname = &mt($text);
2739: }
2740: if (defined($yesno{$key})) {
1.14 raeburn 2741: $displayval = &mt('No');
1.3 raeburn 2742: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2743: $displayval = &mt('Yes');
1.3 raeburn 2744: }
2745: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2746: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2747: } elsif ($key eq 'categories') {
2748: $displayval = $env{'form.categories_display'};
1.95 raeburn 2749: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2750: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2751: if ($changes->{$item}{$key} eq '1') {
2752: $displayval = &mt('Yes');
2753: } elsif ($changes->{$item}{$key} eq '0') {
2754: $displayval = &mt('No');
2755: }
1.114 raeburn 2756: } elsif ($key eq 'extresource') {
2757: if ($changes->{$item}{$key} eq 'iframe') {
2758: $displayval = &mt('In iframe');
2759: } else {
2760: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2761: if ($selected eq 'tab') {
2762: if ($reuse) {
2763: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2764: "'<b>","</b>'",'<br />');
2765: } else {
2766: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2767: "'<b>","</b>'",'<br />');
2768: }
2769: } elsif ($selected eq 'window') {
2770: if ($reuse) {
2771: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2772: "'<b>","</b>'",'<br />');
2773: } else {
2774: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2775: "'<b>","</b>'",'<br />');
2776: }
2777: if (($width ne '') || ($height ne '')) {
2778: if ($width ne '') {
2779: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2780: }
2781: if ($height ne '') {
2782: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2783: }
2784: }
2785: }
2786: }
1.14 raeburn 2787: }
1.25 raeburn 2788: if ($key eq 'co-owners') {
2789: if (ref($changes->{$item}{$key}) eq 'HASH') {
2790: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2791: foreach my $type ('co-owners','pendingco-owners') {
2792: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2793: if ($type eq 'pendingco-owners') {
2794: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2795: $displayname = &mt('Invited as co-owners, pending acceptance');
2796: }
2797: }
2798: if ($changes->{$item}{$key}{$type} eq '') {
2799: push(@delkeys,'internal.'.$type);
2800: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2801: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2802: '<i>'.$displayname.'</i>')).'</li>';
2803: }
2804: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2805: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2806: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2807: '<i>'.$displayname.'</i>',
2808: "'<b>$displayval</b>'")).'</li>';
2809: }
2810: }
2811: }
2812: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2813: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2814: $displayval = &mt('on');
1.90 raeburn 2815: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2816: $displayval = '';
2817: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2818: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2819: $displayval = &mt('off');
2820: }
2821: if ($displayval) {
2822: $displayname = &mt('Your co-ownership status');
2823: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2824: '<i>'.$displayname.'</i>',
2825: "'<b>$displayval</b>'")).'</li>';
2826: }
2827: }
2828: }
2829: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2830: push(@delkeys,$key);
1.87 raeburn 2831: if ($item eq 'lti') {
2832: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2833: if (($key eq 'lti.lcmenu') &&
2834: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2835: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2836: } else {
2837: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2838: '<i>'.$displayname.'</i>',
2839: "'<b>$displayval</b>'")).'</li>';
2840: }
2841: } elsif (!exists($changes->{$item}{'lti.override'})) {
2842: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2843: }
1.91 raeburn 2844: } elsif ($item eq 'menuitems') {
2845: if ($key eq 'menudefault') {
2846: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2847: } elsif ($key eq 'menucollections') {
2848: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2849: }
1.87 raeburn 2850: } else {
2851: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2852: '<i>'.$displayname.'</i>')).'</li>';
2853: }
1.91 raeburn 2854: } elsif ($key eq 'menucollections') {
2855: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2856: $displayval.'</li>';
1.3 raeburn 2857: } else {
1.114 raeburn 2858: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2859: $displayval = "'<b>$displayval</b>'";
2860: }
1.22 wenzelju 2861: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2862: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2863: if ($key eq 'url') {
2864: my $bkuptime=time;
2865: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2866: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2867: }
2868: $output .= '</li>';
2869: }
1.25 raeburn 2870: if ($key eq 'co-owners') {
2871: if (ref($changes->{$item}{$key}) eq 'HASH') {
2872: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2873: foreach my $type ('co-owners','pendingco-owners') {
2874: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2875: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2876: }
2877: }
2878: }
2879: } else {
1.50 raeburn 2880: unless ($key eq 'discussion_post_fonts') {
2881: $storehash{$key} = $changes->{$item}{$key};
2882: }
1.25 raeburn 2883: }
1.3 raeburn 2884: }
1.23 raeburn 2885: if ($key eq 'cloners') {
2886: # Get existing cloners
2887: my %clonenames =
2888: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2889: if ($clonenames{'cloners'} =~ /,/) {
2890: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2891: } else {
2892: $oldcloner[0] = $clonenames{'cloners'};
2893: }
2894: }
1.3 raeburn 2895: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2896: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2897: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2898: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2899: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2900: push(@need_env_update,$key);
2901: }
2902: }
2903: }
2904: }
2905: $output .= '</ul>';
2906: } else {
1.9 raeburn 2907: if ($crstype eq 'Community') {
1.46 raeburn 2908: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2909: } else {
1.46 raeburn 2910: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2911: }
1.3 raeburn 2912: }
2913: }
2914: }
2915: }
1.93 raeburn 2916: if ($skipstore) {
2917: return $output;
2918: }
1.3 raeburn 2919: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2920: if (ref($changes) eq 'HASH') {
2921: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2922: if (exists($changes->{'courseinfo'}{'cloners'})) {
2923: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2924: \@oldcloner);
2925: }
2926: }
2927: }
1.3 raeburn 2928: if (@delkeys) {
2929: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2930: $output .= '<br /><span class="LC_error">';
2931: if ($crstype eq 'Community') {
2932: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2933: } else {
2934: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2935: }
2936: $output .= '</span>';
1.14 raeburn 2937: } else {
2938: foreach my $key (@delkeys) {
2939: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
2940: }
1.3 raeburn 2941: }
2942: }
2943: if (@need_env_update) {
2944: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2945: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
2946: }
2947: &Apache::lonnet::coursedescription($env{'request.course.id'},
2948: {'freshen_cache' => 1});
2949: } else {
1.9 raeburn 2950: $output = '<span class="LC_error">';
2951: if ($crstype eq 'Community') {
2952: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
2953: } else {
2954: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
2955: }
2956: $output .= '</span>';
1.3 raeburn 2957: }
2958: return $output;
2959: }
2960:
1.102 raeburn 2961: sub store_linkprot {
2962: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 2963: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 2964: if ($context eq 'domain') {
2965: $ltiauth = 1;
1.103 raeburn 2966: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 2967: } else {
1.103 raeburn 2968: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 2969: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
2970: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
2971: } else {
2972: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
2973: $ltiauth = $domdefs{'crsltiauth'};
2974: }
2975: }
2976: if (ref($changes) eq 'HASH') {
2977: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
2978: if (ref($changes->{$id}) eq 'HASH') {
2979: if (exists($changes->{$id}->{'key'})) {
2980: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
2981: delete($changes->{$id}->{'key'});
2982: }
2983: if (exists($changes->{$id}->{'secret'})) {
2984: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
2985: delete($changes->{$id}->{'secret'});
2986: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
2987: if (exists($oldlinkprot->{$id}{'usable'})) {
2988: $changes->{$id}->{'usable'} = 1;
2989: }
1.109 raeburn 2990: if (exists($oldlinkprot->{$id}{'cipher'})) {
2991: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
2992: }
1.102 raeburn 2993: }
2994: }
2995: }
2996: }
2997: my @ids=&Apache::lonnet::current_machine_ids();
2998: if (keys(%ltienc) > 0) {
2999: if ($context eq 'domain') {
3000: foreach my $id (keys(%ltienc)) {
3001: if (exists($ltienc{$id}{'secret'})) {
3002: $changes->{$id}->{'usable'} = 1;
3003: }
3004: }
3005: } else {
1.103 raeburn 3006: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 3007: my $allowed;
3008: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3009: if ($allowed) {
3010: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
3011: foreach my $id (keys(%ltienc)) {
3012: if (exists($ltienc{$id}{'secret'})) {
3013: $changes->{$id}->{'usable'} = 1;
3014: }
3015: }
3016: } else {
3017: $lti_save_error = 1;
3018: }
3019: }
3020: }
3021: }
3022: }
3023: unless ($lti_save_error) {
3024: if ($context eq 'course') {
3025: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3026: my $hashid=$cdom.'_'.$cnum;
3027: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 3028: unless (($home eq 'no_host') || ($home eq '')) {
3029: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 3030: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3031: }
3032: }
3033: } else {
3034: $lti_save_error = 1;
3035: }
3036: }
3037: unless ($lti_save_error) {
3038: foreach my $id (sort { $a <=> $b } %{$changes}) {
3039: if (ref($changes->{$id}) eq 'HASH') {
3040: my %values = %{$changes->{$id}};
3041: my %desc = &linkprot_names();
3042: my $display;
1.122 raeburn 3043: foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.102 raeburn 3044: if (($title eq 'key') || ($title eq 'secret')) {
3045: if (ref($ltienc{$id}) eq 'HASH') {
3046: if (exists($ltienc{$id}{$title})) {
3047: if ($title eq 'secret') {
3048: my $length = length($ltienc{$id}{$title});
1.103 raeburn 3049: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 3050: } else {
3051: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3052: }
3053: }
3054: }
3055: } elsif ($title eq 'version') {
3056: if ($values{$title} eq 'LTI-1p0') {
3057: $display .= $desc{$title}.': 1.1, ';
3058: }
1.112 raeburn 3059: } elsif ($title eq 'returnurl') {
3060: if ($values{$title}) {
1.124 raeburn 3061: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
1.112 raeburn 3062: }
1.122 raeburn 3063: } elsif ($title eq 'passbackformat') {
3064: if ($values{$title} eq '1.0') {
3065: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
3066: } elsif ($values{$title} eq '1.1') {
3067: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
3068: }
1.102 raeburn 3069: } else {
3070: $display .= $desc{$title}.': '.$values{$title}.', ';
3071: }
3072: }
3073: if ($ltiauth) {
3074: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3075: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3076: $display .= &mt('Source of username: Email address [_1]',
3077: '(lis_person_contact_email_primary)').', ';
3078: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3079: $display .= &mt('Source of username: User ID [_1]',
3080: '(lis_person_sourcedid)').', ';
3081: } else {
3082: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3083: }
3084: if ($values{'notstudent'} eq 'auth') {
3085: $display .= &mt('Display LON-CAPA login page if no match').', ';
3086: } elsif ($values{'notstudent'} eq 'reject') {
3087: $display .= &mt('Discontinue launch if no match').', ';
3088: }
3089: }
3090: }
3091: $display =~ s/, $//;
3092: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3093: "'$display'")).'</li>';
3094: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3095: my $oldname = $oldlinkprot->{$id}{'name'};
3096: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3097: }
3098: }
3099: } else {
3100: $lti_save_error = 1;
3101: }
3102: }
3103: unless ($lti_save_error) {
3104: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3105: unless (ref($changes->{$id}) eq 'HASH') {
3106: push(@deletions,$id);
3107: }
3108: }
3109: if (@deletions) {
3110: if ($context eq 'course') {
3111: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3112: }
3113: }
3114: }
3115: if ($lti_save_error) {
3116: $output .= '<li>'.
3117: '<span class="LC_error">'.
3118: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3119: '</span>'.
3120: '</li>';
3121: }
3122: return $output;
3123: }
3124:
1.118 raeburn 3125: sub store_ltitools {
3126: my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3127: my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3128: my %lt = <itools_names();
3129: my @courseroles = ('cc','in','ta','ep','st');
3130: my @allfields = ('fullname','firstname','lastname','email','user','roles');
3131: if ($context eq 'domain') {
3132: $home = &Apache::lonnet::domain($cdom,'primary');
3133: } else {
3134: $home = &Apache::lonnet::homeserver($cnum,$cdom);
3135: }
3136: if (ref($changes) eq 'HASH') {
3137: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3138: if (ref($changes->{$id}) eq 'HASH') {
3139: if (exists($changes->{$id}->{'key'})) {
3140: $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3141: delete($changes->{$id}->{'key'});
3142: }
3143: if (exists($changes->{$id}->{'secret'})) {
3144: $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3145: delete($changes->{$id}->{'secret'});
3146: } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3147: if (exists($oldltitools->{$id}{'usable'})) {
3148: $changes->{$id}->{'usable'} = 1;
3149: }
3150: if (exists($oldltitools->{$id}{'cipher'})) {
3151: $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3152: }
3153: }
3154: }
3155: }
3156: }
3157: my @ids=&Apache::lonnet::current_machine_ids();
3158: if (keys(%toolsenc) > 0) {
3159: unless (($home eq 'no_host') || ($home eq '')) {
3160: my $allowed;
3161: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3162: if ($allowed) {
3163: if (($context eq 'domain') ||
3164: (($context eq 'course') &&
3165: (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3166: foreach my $id (keys(%toolsenc)) {
3167: if (exists($toolsenc{$id}{'secret'})) {
3168: $changes->{$id}->{'usable'} = 1;
3169: }
3170: }
3171: } else {
3172: $ltitools_save_error = 1;
3173: }
3174: }
3175: }
3176: }
3177: unless ($ltitools_save_error) {
3178: if ($context eq 'course') {
3179: if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3180: my $hashid=$cdom.'_'.$cnum;
3181: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3182: unless (($home eq 'no_host') || ($home eq '')) {
3183: if (grep(/^\Q$home\E$/,@ids)) {
1.120 raeburn 3184: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
1.118 raeburn 3185: }
3186: }
3187: } else {
3188: $ltitools_save_error = 1;
3189: }
3190: }
3191: unless ($ltitools_save_error) {
3192: my %bynum;
3193: foreach my $itemid (sort(keys(%{$changes}))) {
3194: my $position = $changes->{$itemid}{'order'};
3195: $bynum{$position} = $itemid;
3196: }
3197: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3198: my $itemid = $bynum{$pos};
3199: if (ref($changes->{$itemid}) ne 'HASH') {
3200: $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3201: } else {
3202: $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3203: if ($changes->{$itemid}{'image'}) {
3204: $output .= ' '.
3205: '<img src="'.$changes->{$itemid}{'image'}.'"'.
3206: ' alt="'.&mt('Tool Provider icon').'" />';
3207: }
3208: $output .= '</li><ul>';
3209: my $position = $pos + 1;
3210: $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3211: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3212: if ($changes->{$itemid}{$item} ne '') {
3213: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3214: }
3215: }
3216: if (ref($toolsenc{$itemid}) eq 'HASH') {
3217: foreach my $item ('key','secret') {
3218: if (exists($toolsenc{$itemid}{$item})) {
3219: if ($item eq 'secret') {
3220: $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3221: } else {
3222: $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3223: }
3224: }
3225: }
3226: }
3227: $output .= '<li>'.&mt('Configurable in course:');
3228: my @possconfig = ('label','title','target','linktext','explanation','append');
3229: my $numconfig = 0;
3230: if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3231: foreach my $item (@possconfig) {
3232: if ($changes->{$itemid}{'crsconf'}{$item}) {
3233: $numconfig ++;
3234: $output .= ' "'.$lt{'crs'.$item}.'"';
3235: }
3236: }
3237: }
3238: if (!$numconfig) {
3239: $output .= ' '.&mt('None');
3240: }
3241: $output .= '</li>';
3242: foreach my $item ('passback','roster') {
3243: $output .= '<li>'.$lt{$item}.' ';
3244: if ($changes->{$itemid}{$item}) {
3245: $output .= &mt('Yes');
3246: if ($changes->{$itemid}{$item.'valid'}) {
3247: if ($item eq 'passback') {
3248: $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3249: $changes->{$itemid}{$item.'valid'});
3250: } else {
3251: $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3252: $changes->{$itemid}{$item.'valid'});
3253: }
3254: }
3255: } else {
3256: $output .= &mt('No');
3257: }
3258: $output .= '</li>';
3259: }
3260: if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3261: my $displaylist;
3262: if ($changes->{$itemid}{'display'}{'target'}) {
3263: $displaylist = &mt('Display target').': '.
3264: $changes->{$itemid}{'display'}{'target'}.',';
3265: }
3266: foreach my $size ('width','height') {
3267: if ($changes->{$itemid}{'display'}{$size}) {
3268: $displaylist .= (' 'x2).$lt{$size}.': '.
3269: $changes->{$itemid}{'display'}{$size}.',';
3270: }
3271: }
3272: if ($displaylist) {
3273: $displaylist =~ s/,$//;
3274: $output .= '<li>'.$displaylist.'</li>';
3275: }
3276: foreach my $item ('linktext','explanation') {
3277: if ($changes->{$itemid}{'display'}{$item}) {
3278: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3279: }
3280: }
3281: }
3282: if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3283: my $fieldlist;
3284: foreach my $field (@allfields) {
3285: if ($changes->{$itemid}{'fields'}{$field}) {
3286: $fieldlist .= (' 'x2).$lt{$field}.',';
3287: }
3288: }
3289: if ($fieldlist) {
3290: $fieldlist =~ s/,$//;
3291: if ($changes->{$itemid}{'fields'}{'user'}) {
3292: if ($changes->{$itemid}{'incdom'}) {
3293: $fieldlist .= ' ('.&mt('username:domain').')';
3294: } else {
3295: $fieldlist .= ' ('.&mt('username').')';
3296: }
3297: }
3298: $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3299: }
3300: }
3301: if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3302: my $rolemaps;
3303: foreach my $role (@courseroles) {
3304: if ($changes->{$itemid}{'roles'}{$role}) {
3305: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3306: $changes->{$itemid}{'roles'}{$role}.',';
3307: }
3308: }
3309: if ($rolemaps) {
3310: $rolemaps =~ s/,$//;
3311: $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3312: }
3313: }
3314: if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3315: my $customlist;
3316: if (keys(%{$changes->{$itemid}{'custom'}})) {
3317: foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3318: $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3319: }
3320: }
3321: if ($customlist) {
3322: $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3323: }
3324: }
3325: $output .= '</ul></li>';
3326: }
3327: }
3328: }
3329: }
3330: return $output;
3331: }
3332:
1.3 raeburn 3333: sub update_env {
3334: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3335: my $count = 0;
3336: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3337: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3338: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3339: foreach my $key (@{$need_env_update}) {
3340: if ($key eq 'description' && defined($storehash->{$key})) {
3341: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3342: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3343: $count ++;
3344: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3345: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3346: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3347: $count ++;
1.25 raeburn 3348: } elsif ($key eq 'co-owners') {
3349: if ($storehash->{'internal.co-owners'} ne '') {
3350: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3351: }
3352: if ($storehash->{'internal.pendingco-owners'} ne '') {
3353: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3354: }
3355: my @coowners = split(',',$storehash->{'internal.'.$key});
3356: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3357: $count ++;
1.87 raeburn 3358: } elsif ($key =~ /^lti\./) {
3359: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 3360: }
3361: }
3362: if ($count) {
3363: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3364: }
3365: }
3366: }
3367: return;
3368: }
3369:
3370: sub display_disallowed {
1.9 raeburn 3371: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3372: my $output;
3373: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3374: if (keys(%{$disallowed})) {
3375: if ($item eq 'cloners') {
3376: my @fails;
3377: my %lt = &Apache::lonlocal::texthash (
3378: format => 'Invalid format',
3379: domain => 'Domain does not exist',
3380: newuser => 'LON-CAPA user(s) do(es) not exist.',
3381: );
3382: foreach my $error ('format','domain','newuser') {
3383: if (defined($disallowed->{$error})) {
3384: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3385: $lt{$error};
3386: if ($error eq 'newuser') {
1.9 raeburn 3387: $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 3388: }
3389: push(@fails,$msg);
3390: }
3391: }
3392: if (@fails) {
3393: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3394: '</span>'.join('; ',@fails).'.<br />';
3395: }
3396: } elsif ($item eq 'rolenames') {
3397: my %lt = &Apache::lonlocal::texthash (
3398: replacements => 'Name already used to replace a different standard role name',
3399: regulars => 'Name already used as a standard role name',
3400: customrole => 'Name already used as the name of a custom role',
3401: );
3402: my @fails;
3403: foreach my $error ('replacements','regulars','customrole') {
3404: if (ref($disallowed->{$error}) eq 'ARRAY') {
3405: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3406: '</b>, '.&mt('reason').' - '.$lt{'error'});
3407: }
3408: }
3409: if (@fails) {
3410: $output .= '<span class="LC_warning">'.
3411: &mt('Unable to include amongst replacements for role names: ').
3412: '</span>'.join('; ',@fails).'.<br />';
3413: }
3414:
3415: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3416: $output .= '<span class="LC_warning">';
3417: if ($item eq 'feedback') {
1.9 raeburn 3418: if ($crstype eq 'Community') {
3419: $output .= &mt('Unable to include as a recipient of community feedback for:');
3420: } else {
3421: $output .= &mt('Unable to include as a recipient of course feedback for:');
3422: }
1.3 raeburn 3423: } elsif ($item eq 'discussion') {
3424: $output .= &mt('Unable to include in user-based access control for:');
3425: } elsif ($item eq 'localization') {
1.9 raeburn 3426: if ($crstype eq 'Community') {
3427: $output .= &mt('Unable to include in community localization:');
3428: } else {
3429: $output .= &mt('Unable to include in course localization:');
3430: }
1.3 raeburn 3431: }
3432: $output .= '</span><ul>';
3433: foreach my $key (sort(keys(%{$disallowed}))) {
3434: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3435: $output .= '<li><i>'.$itemtext.'</i> - ';
3436: if ($item eq 'localization') {
3437: $output .= &mt('reason - unsupported language: [_1]',
3438: '<b>'.$disallowed->{$key}.'</b>');
3439: } else {
3440: $output .= &mt('reason - invalid user: [_1]',
3441: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3442: }
3443: }
3444: $output .= '</ul><br />';
3445: }
3446: }
1.1 raeburn 3447: }
1.3 raeburn 3448: return $output;
1.1 raeburn 3449: }
3450:
3451: sub get_course {
3452: my ($courseid) = @_;
3453: if (!defined($courseid)) {
3454: $courseid = $env{'request.course.id'};
3455: }
3456: my $cdom=$env{'course.'.$courseid.'.domain'};
3457: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 3458: my $chome=$env{'course.'.$courseid.'.home'};
3459: return ($cnum,$cdom,$chome);
1.1 raeburn 3460: }
3461:
3462: sub get_jscript {
1.91 raeburn 3463: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3464: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 raeburn 3465: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3466: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3467: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3468: my $cloners_js = &cloners_javascript($phase);
1.118 raeburn 3469: my $currltitools;
3470: if (ref($settings) eq 'HASH') {
3471: $currltitools = $settings->{'ltitools'};
3472: }
3473: my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.71 raeburn 3474: my @code_order;
3475: if ($crstype ne 'Community') {
3476: if (ref($settings) eq 'HASH') {
3477: my %codedefaults;
3478: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3479: \@code_order);
3480: if (@code_order > 0) {
3481: if ($phase eq 'display') {
3482: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3483: if (grep(/^courseinfo$/,@actions)) {
3484: if ($settings->{'cloners'} ne '') {
3485: unless ($settings->{'cloners'} eq '*') {
3486: my @cloners = split(/,/,$settings->{'cloners'});
3487: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3488: my %local_to_standard;
3489: for (my $i=0; $i<@code_order; $i++) {
3490: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3491: }
3492: foreach my $cloner (@cloners) {
1.124 raeburn 3493: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
1.71 raeburn 3494: ($cloner !~ /^$match_username\:$match_domain$/)) {
3495: foreach my $item (split(/\&/,$cloner)) {
3496: my ($key,$val) = split(/\=/,$item);
3497: $val = &unescape($val);
3498: foreach my $code (@code_order) {
3499: if ($key eq $local_to_standard{$code}) {
3500: $env{'form.'.$key} = $val;
3501: }
3502: }
3503: }
3504: }
3505: }
3506: }
3507: }
3508: }
3509: }
3510: my @codetitles;
3511: (undef,$instcode_js) =
3512: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3513: \@codetitles);
3514: $instcode_js .= <<ENDSCRIPT;
3515: function toggleCloners(callerradio) {
3516: if (document.getElementById('LC_cloners_instcode')) {
3517: if (callerradio.value == 1) {
3518: document.getElementById('LC_cloners_instcode').style.display = "block";
3519: } else {
3520: uncheckOfficialLists();
3521: document.getElementById('LC_cloners_instcode').style.display = "none";
3522: }
3523: }
3524: }
3525:
3526: if (!document.getElementsByClassName) {
3527: function getElementsByClassName(node, classname) {
3528: var a = [];
3529: var re = new RegExp('(^| )'+classname+'( |$)');
3530: var els = node.getElementsByTagName("*");
3531: for(var i=0,j=els.length; i<j; i++)
3532: if(re.test(els[i].className))a.push(els[i]);
3533: return a;
3534: }
3535: }
3536:
3537: function uncheckOfficialLists() {
3538: var codepicks;
3539: if (document.getElementsByClassName) {
3540: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3541: } else {
3542: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3543: }
3544: if (codepicks.length) {
3545: for (var i=0; i<codepicks.length; i++) {
3546: codepicks[i].selectedIndex = 0;
3547: }
3548: }
3549: }
3550:
3551: ENDSCRIPT
3552: }
3553: }
3554: }
1.1 raeburn 3555: if ($can_categorize) {
3556: $categorize_js = <<ENDSCRIPT;
3557: function catsbrowser() {
3558: var catswin = null;
3559: var url = '/adm/courseprefs?phase=categorizecourse';
3560: if (!catswin || catswin.closed) {
3561: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3562: } else {
3563: catswin.focus();
3564: }
3565: }
3566: ENDSCRIPT
3567: }
1.36 raeburn 3568: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3569: if ($loncaparev) {
3570: $loncaparev_js = <<ENDSCRIPT;
3571: function loncaparevinfo() {
3572: var lcrevwin = null;
3573: var url = '/adm/courseprefs?phase=releaseinfo';
3574: if (!lcrevwin || lcrevwin.closed) {
3575: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3576: } else {
3577: lcrevwin.focus();
3578: }
3579: }
3580: ENDSCRIPT
3581: }
1.60 raeburn 3582: my $cnum = $env{'course.'.$cid.'.num'};
3583: my $syllabus_js = <<ENDSCRIPT;
3584: function syllabusinfo() {
3585: var syllwin = null;
3586: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3587: if (!syllwin || syllwin.closed) {
3588: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3589: } else {
3590: syllwin.focus();
3591: }
3592: }
3593: ENDSCRIPT
1.91 raeburn 3594: my $menuitems_js;
3595: unless ($noedit) {
3596: my $collections;
3597: my $next = 1;
3598: if (ref($settings) eq 'HASH') {
3599: if ($settings->{'menucollections'} ne '') {
3600: my @current;
3601: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3602: my ($num) = split(/\%/,$item);
3603: if ($num =~ /^\d+$/) {
3604: push(@current,$num);
3605: }
3606: }
3607: $collections = join("','",sort { $a <=> $b } @current);
3608: if ($collections) {
3609: $collections = "'$collections'";
3610: }
3611: $next += $current[-1];
3612: }
3613: }
3614: my $deftext = &mt('Standard (all menus shown)');
3615: $menuitems_js = <<ENDSCRIPT;
3616: function toggleAddmenucoll() {
3617: if (document.getElementById('menucollections_add')) {
3618: var state = 'none';
3619: var add = document.getElementById('menucollections_add').checked;
3620: if (add) {
3621: state = 'inline-block';
3622: }
3623: var fieldsets = new Array('shown','text','links','list','inline');
3624: for (var i=0; i<fieldsets.length; i++) {
3625: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3626: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3627: }
3628: }
3629: var box = document.getElementsByClassName('LC_menucoll_add');
3630: if (box.length) {
3631: for (var i=0; i<box.length; i++) {
3632: if (add) {
3633: box[i].checked = true;
3634: } else {
3635: box[i].checked = false;
3636: }
3637: }
3638: }
3639: if (document.getElementById('menudefault')) {
3640: var menudef = document.getElementById('menudefault');
3641: var currsel = menudef.selectedIndex;
3642: var colls = new Array($collections);
3643: menudef.options.length = 0;
3644: if (!add) {
3645: if (currsel == 1 + colls.length) {
3646: currsel = 0;
3647: }
3648: }
3649: if (currsel == 0) {
3650: menudef.options[0] = new Option('$deftext','',true,true);
3651: } else {
3652: menudef.options[0] = new Option('$deftext','',false,false);
3653: }
3654: if (colls.length) {
3655: for (var i=0; i<colls.length; i++) {
3656: var idx = i+1;
3657: if (currsel == colls[i]) {
3658: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3659: } else {
3660: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3661: }
3662: }
3663: }
3664: if (add) {
3665: var addidx = 1 + colls.length;
3666: if (currsel == addidx) {
3667: menudef.options[addidx] = new Option('$next','$next',true,true);
3668: } else {
3669: menudef.options[addidx] = new Option('$next','$next',false,false);
3670: }
3671: }
3672: }
3673: }
3674: }
3675: ENDSCRIPT
3676: }
1.114 raeburn 3677: $extresource_js = <<"ENDSCRIPT";
3678: function toggleExtRes() {
3679: if (document.getElementById('LC_extresource')) {
3680: var extressel = document.getElementById('LC_extresource').value;
3681: if (document.getElementById('LC_extresreusediv')) {
3682: var extresreuse = document.getElementById('LC_extresreusediv');
3683: if (document.getElementById('LC_extressize')) {
3684: var extressize = document.getElementById('LC_extressize');
3685: var setvis;
3686: if ((extressel == 'tab') || (extressel == 'window')) {
3687: extresreuse.style.display = 'inline-block';
3688: setvis = 1;
3689: if (extressel == 'window') {
3690: extressize.style.display = 'inline-block';
3691: } else {
3692: extressize.style.display = 'none';
3693: }
3694: }
3695: if (!setvis) {
3696: extresreuse.style.display = 'none';
3697: extressize.style.display = 'none';
3698: }
3699: }
3700: }
3701: }
3702: }
3703: ENDSCRIPT
1.115 raeburn 3704: $localization_js = <<"ENDSCRIPT";
3705: function toggleTimeZone() {
3706: if (document.getElementById('LC_set_timezone')) {
3707: var timezonesel = document.getElementById('LC_set_timezone').value;
3708: if (document.getElementById('LC_tzoverdiv')) {
3709: var tzoverdiv = document.getElementById('LC_tzoverdiv');
3710: if (timezonesel == '') {
3711: tzoverdiv.style.display = 'none';
3712: } else {
3713: tzoverdiv.style.display = 'block';
3714: }
3715: }
3716: }
3717: }
3718: ENDSCRIPT
1.1 raeburn 3719: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.124 raeburn 3720: '// <![CDATA['."\n".
1.36 raeburn 3721: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 raeburn 3722: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 3723: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.102 raeburn 3724: &linkprot_javascript()."\n".'//]]>'."\n".
1.118 raeburn 3725: '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3726: return $jscript;
3727: }
3728:
1.3 raeburn 3729: sub cloners_javascript {
3730: my ($formname) = @_;
3731: return <<"ENDSCRIPT";
3732:
3733: function update_cloners(caller,num) {
3734: var delidx = getIndexByName('cloners_delete');
3735: var actidx = getIndexByName('cloners_activate');
3736: if (caller == 'cloners_all') {
3737: var selall;
3738: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3739: if (document.$formname.cloners_all[i].checked) {
3740: selall = document.$formname.cloners_all[i].value;
3741: }
3742: }
3743: if (selall == 1) {
3744: if (delidx != -1) {
3745: if (document.$formname.cloners_delete.length) {
3746: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3747: document.$formname.cloners_delete[j].checked = true;
3748: }
3749: } else {
3750: document.$formname.elements[delidx].checked = true;
3751: }
3752: }
3753: if (actidx != -1) {
3754: if (document.$formname.cloners_activate.length) {
3755: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3756: if (document.$formname.cloners_activate[i].value == '0') {
3757: document.$formname.cloners_activate[i].checked = false;
3758: }
1.71 raeburn 3759: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3760: document.$formname.cloners_activate[i].checked = true;
3761: }
3762: }
3763: }
3764: }
3765: document.$formname.cloners_newdom.selectedIndex = 0;
3766: }
3767: }
3768: if (caller == 'cloners_activate') {
3769: if (document.$formname.cloners_activate.length) {
3770: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3771: if (document.$formname.cloners_activate[j].value == num) {
3772: if (document.$formname.cloners_activate[j].checked) {
3773: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3774: if (document.$formname.cloners_all[i].value == '1') {
3775: document.$formname.cloners_all[i].checked = false;
3776: }
3777: if (document.$formname.cloners_all[i].value == '0') {
3778: document.$formname.cloners_all[i].checked = true;
3779: }
3780: }
3781: }
3782: }
3783: }
3784: } else {
3785: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3786: if (document.$formname.cloners_all[i].value == '1') {
3787: document.$formname.cloners_all[i].checked = false;
3788: }
3789: if (document.$formname.cloners_all[i].value == '0') {
3790: document.$formname.cloners_all[i].checked = true;
3791: }
3792: }
3793: }
3794: }
3795: return;
3796: }
3797:
3798: function getIndexByName(item) {
3799: for (var i=0;i<document.$formname.elements.length;i++) {
3800: if (document.$formname.elements[i].name == item) {
3801: return i;
3802: }
3803: }
3804: return -1;
3805: }
3806:
3807: ENDSCRIPT
3808: }
3809:
1.102 raeburn 3810: sub linkprot_javascript {
3811: return <<"ENDSCRIPT";
1.112 raeburn 3812: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 3813: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3814: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3815: var itemname = form.elements['linkprot_'+item+'_'+num];
3816: if (itemname) {
3817: if (itemname.length > 0) {
3818: var setvis;
3819: for (var i=0; i<itemname.length; i++) {
3820: if (itemname[i].checked == true) {
3821: if (itemname[i].value == valon) {
3822: extraid.style.display = styleon;
3823: setvis = 1;
3824: }
3825: break;
3826: }
3827: }
3828: if (!setvis) {
3829: extraid.style.display = 'none';
3830: }
3831: }
3832: }
3833: }
3834: return;
3835: }
1.106 raeburn 3836:
1.102 raeburn 3837: ENDSCRIPT
3838:
3839: }
3840:
1.1 raeburn 3841: sub print_courseinfo {
1.80 raeburn 3842: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3843: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3844: return;
3845: }
1.83 raeburn 3846: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3847: if ($noedit) {
3848: $disabled = ' disabled="disabled"';
3849: }
1.1 raeburn 3850: my %domconf =
1.71 raeburn 3851: &Apache::lonnet::get_dom('configuration',
3852: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3853: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3854: $cathash = $domconf{'coursecategories'}{'cats'};
3855: if (ref($cathash) eq 'HASH') {
3856: $categoriesform =
3857: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 3858: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3859: }
3860: }
1.25 raeburn 3861: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3862: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3863: }
1.71 raeburn 3864: my ($currcanclone,@code_order,$cloner_instcode);
3865: my %codedefaults;
3866: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3867: \@code_order);
3868: if ($settings->{'cloners'}) {
3869: unless ($settings->{'cloners'} eq '*') {
3870: my @currclone = split(/,/,$settings->{'cloners'});
3871: foreach my $item (@currclone) {
3872: unless ($item eq '*') {
3873: if (($item !~ /\:/) && ($item =~ /=/)) {
3874: $cloner_instcode = 1;
3875: }
3876: }
3877: }
3878: }
3879: }
3880: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3881: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3882: if (ref($canclone) eq 'HASH') {
3883: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3884: if ($settings->{'internal.coursecode'}) {
3885: my @posscodes;
3886: if (@code_order > 0) {
3887: $currcanclone = 'instcode';
3888: foreach my $item (@{$canclone->{'instcode'}}) {
3889: if (grep(/^\Q$item\E$/,@code_order)) {
3890: push(@posscodes,$item);
3891: }
3892: }
3893: my $codestr = join(' + ',@posscodes);
3894: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3895: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3896: }
3897: }
3898: }
3899: } elsif ($canclone eq 'domain') {
3900: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
3901: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
3902: $currcanclone = 'domain';
3903: }
3904: if ($clonedefaults) {
3905: if ($settings->{'cloners'} ne '') {
3906: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
3907: } else {
3908: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
3909: }
3910: $clonedefaults = '<br /><br />'.$clonedefaults;
3911: }
3912: }
1.1 raeburn 3913: if (!defined($categoriesform)) {
1.15 raeburn 3914: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 3915: }
1.12 raeburn 3916: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 3917: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 3918:
1.9 raeburn 3919: my $replace;
3920: if ($crstype eq 'Community') {
3921: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3922: } else {
3923: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3924: }
1.84 raeburn 3925: my ($editmap,$editsyllabus);
3926: unless ($noedit) {
3927: $editmap = (' 'x2).
3928: '<a href="javascript:openbrowser'.
3929: "('display','url','sequence')\">".
3930: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
3931: &mt('Modification may make assessment data inaccessible!').
3932: '</span>';
3933: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
1.124 raeburn 3934: '</a>');
1.84 raeburn 3935: }
1.1 raeburn 3936: my %items = (
1.3 raeburn 3937: 'url' => {
1.84 raeburn 3938: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 3939: input => 'textbox',
1.55 raeburn 3940: size => '55',
1.19 faziophi 3941: advanced => 1
1.1 raeburn 3942: },
3943: 'description' => {
1.3 raeburn 3944: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 3945: input => 'textbox',
1.55 raeburn 3946: size => '55',
1.1 raeburn 3947: },
1.24 raeburn 3948: 'owner' => {
3949: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
3950: },
1.25 raeburn 3951: 'co-owners' => {
3952: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
3953: },
1.63 raeburn 3954: 'clonedfrom' => {
3955: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
3956: },
1.1 raeburn 3957: 'courseid' => {
1.3 raeburn 3958: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
3959: &mt('internal, optional').')',
1.1 raeburn 3960: input => 'textbox',
3961: size => '25',
3962: },
1.64 raeburn 3963: 'uniquecode' => {
3964: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
3965: },
1.1 raeburn 3966: 'cloners' => {
1.3 raeburn 3967: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 3968: &mt('Owner and Coordinators included automatically').
3969: $clonedefaults,
1.1 raeburn 3970: input => 'textbox',
1.41 www 3971: size => '40'
1.1 raeburn 3972: },
3973: 'rolenames' => {
1.3 raeburn 3974: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 3975: '('.$replace.')',
1.1 raeburn 3976: input => 'textbox',
3977: size => '20',
1.19 faziophi 3978: advanced => 1
1.1 raeburn 3979: },
1.88 raeburn 3980: 'syllabus' => {
3981: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 3982: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 3983: $editsyllabus,
1.1 raeburn 3984: },
3985: 'hidefromcat' => {
1.3 raeburn 3986: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 3987: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
3988: input => 'radio',
3989: },
3990: 'categories' => {
1.3 raeburn 3991: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 3992: &mt('Display Categories').'</a>',
3993: input => 'textbox',
3994: size => '25',
3995: },
1.35 raeburn 3996: 'loncaparev' => {
3997: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
3998: },
1.55 raeburn 3999: 'defaultcredits' => {
4000: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4001: },
1.1 raeburn 4002: );
4003: my $datatable;
4004: my $count = 0;
4005: foreach my $item (@{$ordered}) {
1.56 raeburn 4006: my $colspan;
1.1 raeburn 4007: if ($item eq 'hidefromcat') {
4008: next if (!$can_toggle_cat);
4009: } elsif ($item eq 'categories') {
4010: next if (!$can_categorize);
1.64 raeburn 4011: } elsif ($item eq 'uniquecode') {
4012: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4013: }
1.56 raeburn 4014: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
1.124 raeburn 4015: $colspan = 2;
1.56 raeburn 4016: }
1.1 raeburn 4017: $count ++;
1.19 faziophi 4018: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 4019: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4020: } else {
1.56 raeburn 4021: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4022: }
1.1 raeburn 4023: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 4024: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4025: } elsif ($item eq 'cloners') {
4026: my $includeempty = 1;
4027: my $num = 0;
1.56 raeburn 4028: $datatable .= '</td><td align="right">'.
4029: &Apache::loncommon::start_data_table().
1.1 raeburn 4030: &Apache::loncommon::start_data_table_row().
4031: '<td><span class="LC_nobreak"><label>'.
4032: &mt('Any user in any domain:').
4033: ' <input type="radio" name="cloners_all" value="1" ';
4034: if ($settings->{$item} eq '*') {
4035: $datatable .= ' checked="checked" ';
4036: }
4037: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 4038: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4039: (' 'x2).'<label>'.
4040: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4041: if ($settings->{$item} ne '*') {
4042: $datatable .= ' checked="checked" ';
4043: }
4044: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 4045: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4046: &Apache::loncommon::end_data_table_row().
4047: &Apache::loncommon::end_data_table().
1.56 raeburn 4048: '<table><tr><td align="left"><b>'.&mt('Or').
4049: '</b></td></tr></table>'.
1.1 raeburn 4050: &Apache::loncommon::start_data_table();
4051: my @cloners;
4052: if ($settings->{$item} eq '') {
1.80 raeburn 4053: unless ($noedit) {
4054: my $default;
4055: if ($currcanclone eq 'domain') {
4056: $default = '0';
4057: }
4058: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 4059: }
1.1 raeburn 4060: } elsif ($settings->{$item} ne '*') {
4061: my @entries = split(/,/,$settings->{$item});
4062: if (@entries > 0) {
4063: foreach my $entry (@entries) {
4064: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4065: if ($udom =~ /^$match_domain$/) {
4066: unless (&Apache::lonnet::domain($udom)) {
4067: next;
4068: }
4069: } else {
4070: next;
4071: }
1.1 raeburn 4072: if ($uname eq '*') {
4073: $datatable .=
4074: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4075: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4076: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4077: '</b><input type="hidden" name="cloners_dom_'.$num.
4078: '" value="'.$udom.'" /></span><br />'.
4079: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4080: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4081: &mt('Delete').'</label></span></td>'.
4082: &Apache::loncommon::end_data_table_row();
4083: $num ++;
1.23 raeburn 4084: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4085: unless (grep(/^\Q$entry\E$/,@cloners)) {
4086: push(@cloners,$entry);
4087: }
1.1 raeburn 4088: }
4089: }
4090: }
4091: }
4092: my $add_domtitle = &mt('Any user in additional domain:');
4093: if ($settings->{$item} eq '*') {
4094: $add_domtitle = &mt('Any user in specific domain:');
4095: } elsif ($settings->{$item} eq '') {
4096: $add_domtitle = &mt('Any user in other domain:');
4097: }
4098: my $cloners_str = join(',',@cloners);
4099: $datatable .= &Apache::loncommon::start_data_table_row().
4100: '<td align="left"><span class="LC_nobreak">'.
4101: $add_domtitle.'</span><br />'.
4102: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 4103: $includeempty,undef,undef,
4104: undef,undef,$noedit).
1.1 raeburn 4105: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4106: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4107: &Apache::loncommon::end_data_table().
1.56 raeburn 4108: '<table><tr><td align="left"><b>'.&mt('And').
4109: '</b></td></tr></table>'.
1.1 raeburn 4110: &Apache::loncommon::start_data_table().
4111: &Apache::loncommon::start_data_table_row().
4112: '<td align="left">'.
4113: &mt('Specific users').' (<tt>'.
4114: &mt('user:domain,user:domain').'</tt>)<br />'.
4115: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 4116: $items{$item}{'size'},$disabled).
1.1 raeburn 4117: '</td>'.&Apache::loncommon::end_data_table_row().
4118: &Apache::loncommon::end_data_table();
1.71 raeburn 4119: if (@code_order > 0) {
4120: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4121: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4122: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4123: \%cat_items,\@codetitles,
4124: \%cat_titles,\%cat_order);
4125: my $showncodes = 'off';
4126: my $checkedoff = ' checked="checked"';
4127: my $checkedon = '';
4128: if ($cloner_instcode) {
4129: $checkedon = $checkedoff;
4130: $checkedoff = '';
4131: $showncodes = 'on';
4132: }
4133: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4134: '</b></td></tr></table>'.
4135: &Apache::loncommon::start_data_table().
4136: &Apache::loncommon::start_data_table_row().
4137: '<td align="left"><span class="LC_nobreak">'.
4138: &mt('Cloning by official course(s) based on course category').(' 'x2).
4139: '<label>'.
1.80 raeburn 4140: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4141: (' ').
4142: '<label>'.
1.80 raeburn 4143: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 4144: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4145: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 4146: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 4147: '</td>'.&Apache::loncommon::end_data_table_row().
4148: &Apache::loncommon::end_data_table();
4149: }
1.1 raeburn 4150: } elsif ($item eq 'rolenames') {
1.56 raeburn 4151: $datatable .= '</td><td align="right">'.
4152: &Apache::loncommon::start_data_table();
1.9 raeburn 4153: my @roles;
4154: if ($crstype eq 'Community') {
4155: @roles = ('co');
4156: } else {
4157: @roles = ('cc');
4158: }
4159: push (@roles,('in','ta','ep','ad','st'));
4160: foreach my $role (@roles) {
1.1 raeburn 4161: $datatable .= &Apache::loncommon::start_data_table_row().
4162: '<td align="left"><span class="LC_nobreak">'.
4163: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4164: '</span></td><td align="left">'.
4165: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4166: $settings->{$role.'.plaintext'},
1.80 raeburn 4167: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4168: &Apache::loncommon::end_data_table_row();
4169: }
4170: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4171: } elsif ($item eq 'categories') {
1.80 raeburn 4172: my $launcher;
4173: if ($noedit) {
4174: $launcher = $disabled;
4175: } else {
4176: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4177: }
1.3 raeburn 4178: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4179: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4180: $items{$item}{size},$launcher);
1.24 raeburn 4181: } elsif ($item eq 'owner') {
4182: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4183: if ($owner =~ /:/) {
4184: my ($ownername,$ownerdom) = split(':',$owner);
4185: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4186: } elsif ($owner ne '') {
4187: $owner = &Apache::loncommon::plainname($owner,$cdom);
4188: } else {
4189: $owner = &mt('None specified');
4190: }
4191: $datatable .= $owner;
1.63 raeburn 4192: } elsif ($item eq 'clonedfrom') {
4193: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4194: my $clonedfrom = &mt('None');
4195: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 4196: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 4197: if ($clonesrcinfo{'description'}) {
1.124 raeburn 4198: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
1.63 raeburn 4199: }
4200: }
4201: $datatable .= $clonedfrom;
1.64 raeburn 4202: } elsif ($item eq 'uniquecode') {
1.124 raeburn 4203: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
1.64 raeburn 4204: if ($code) {
4205: $datatable .= $code;
4206: }
1.25 raeburn 4207: } elsif ($item eq 'co-owners') {
4208: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4209: my @currcoown;
4210: if ($coowners) {
4211: @currcoown = split(',',$coowners);
4212: }
4213: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4214: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4215: $datatable .= &show_autocoowners(@currcoown);
4216: } else {
1.80 raeburn 4217: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4218: }
4219: } else {
4220: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4221: $datatable .= &show_autocoowners(@currcoown);
4222: } else {
1.80 raeburn 4223: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4224: }
4225: }
1.88 raeburn 4226: } elsif ($item eq 'syllabus') {
1.60 raeburn 4227: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4228: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4229: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4230: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4231: if ($minimal =~/\w/) {
4232: if ($external =~ m{\Q$minimal\E$}) {
4233: undef($external);
4234: }
4235: } elsif ($uploaded =~/\w/) {
4236: if ($external =~ m{\Q$uploaded\E$}) {
4237: undef($external);
4238: }
4239: }
4240: } elsif ($external!~/\w/) {
4241: undef($external);
4242: }
4243: if ($external) {
4244: $datatable .= &mt('External URL');
4245: } elsif ($minimal) {
4246: $datatable .= &mt('Minimal template');
4247: } elsif ($uploaded) {
4248: $datatable .= &mt('Uploaded file');
4249: } else {
1.124 raeburn 4250: $datatable .= &mt('Standard template');
1.60 raeburn 4251: }
4252: $datatable .= (' ' x 2).
4253: &mt('[_1]View[_2]',
4254: '<a href="javascript:syllabusinfo();">',
1.124 raeburn 4255: '</a>');
1.35 raeburn 4256: } elsif ($item eq 'loncaparev') {
4257: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4258: my $showreqd;
4259: if ($loncaparev) {
1.36 raeburn 4260: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4261: &mt('Details').'</a>';
1.35 raeburn 4262: } else {
4263: $showreqd = &mt('No specific version required');
4264: }
4265: $datatable .= $showreqd;
1.1 raeburn 4266: } else {
1.80 raeburn 4267: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4268: }
4269: $datatable .= &item_table_row_end();
4270: }
4271: $$rowtotal += scalar(@{$ordered});
4272: return $datatable;
4273: }
4274:
4275: sub new_cloners_dom_row {
1.71 raeburn 4276: my ($newdom,$num,$default) = @_;
4277: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4278: if ($newdom ne '') {
1.71 raeburn 4279: if ($num eq $default) {
1.124 raeburn 4280: $checkedon = 'checked="checked" ';
1.71 raeburn 4281: } else {
4282: $checkedoff = 'checked="checked" ';
4283: }
1.1 raeburn 4284: $output .= &Apache::loncommon::start_data_table_row().
4285: '<td valign="top"><span class="LC_nobreak">'.
4286: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4287: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 4288: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4289: 'onchange="javascript:update_cloners('.
1.1 raeburn 4290: "'cloners_activate','$num'".');" />'.
4291: &mt('Yes').'</label>'.(' 'x2).
4292: '<label><input type="radio" '.
1.71 raeburn 4293: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4294: 'onchange="javascript:update_cloners('.
1.1 raeburn 4295: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4296: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4297: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4298: &Apache::loncommon::end_data_table_row();
4299: }
4300: return $output;
4301: }
4302:
4303: sub can_modify_catsettings {
1.12 raeburn 4304: my ($dom,$crstype) = @_;
1.1 raeburn 4305: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4306: my ($can_toggle_cat,$can_categorize);
4307: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4308: if ($crstype eq 'Community') {
4309: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4310: $can_toggle_cat = 1;
4311: }
4312: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4313: $can_categorize = 1;
4314: }
4315: } else {
4316: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4317: $can_toggle_cat = 1;
4318: }
4319: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4320: $can_categorize = 1;
4321: }
1.1 raeburn 4322: }
4323: }
4324: return ($can_toggle_cat,$can_categorize);
4325: }
4326:
4327: sub assign_course_categories {
1.9 raeburn 4328: my ($r,$crstype) = @_;
1.1 raeburn 4329: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4330: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4331: my $hascats = 0;
4332: my $cathash;
4333: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4334: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4335: $cathash = $domconf{'coursecategories'}{'cats'};
4336: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4337: foreach my $cat (keys(%{$cathash})) {
4338: next if ($cat eq 'instcode::0');
4339: unless ($crstype eq 'Community') {
4340: next if ($cat eq 'communities::0');
4341: }
4342: $hascats ++;
4343: }
1.1 raeburn 4344: }
4345: }
4346: my $catwin_js;
4347: if ($hascats) {
1.9 raeburn 4348: my $alert;
4349: if ($crstype eq 'Community') {
4350: $alert = &mt("Use 'Save' in the main window to save community categories");
4351: } else {
4352: $alert = &mt("Use 'Save' in the main window to save course categories");
4353: }
1.72 damieng 4354: &js_escape(\$alert);
1.1 raeburn 4355: $catwin_js = <<ENDSCRIPT;
4356: <script type="text/javascript">
4357:
4358: function updateCategories() {
4359: var newcategories = '';
4360: var unescapedcats = '';
4361: if (document.chgcats.usecategory.length) {
4362: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4363: if (document.chgcats.usecategory[i].checked == true) {
4364: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4365: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4366: }
4367: }
4368: if (newcategories.length > 0) {
4369: newcategories = newcategories.slice(0,-1);
4370: }
4371: if (unescapedcats.length > 0) {
4372: unescapedcats = unescapedcats.slice(0,-3);
4373: }
4374: } else {
4375: if (document.chgcats.usecategory.checked == true) {
4376: newcategories = document.chgcats.usecategory.value;
4377: unescapedcats = document.chgcats.catname.value;
4378: }
4379: }
4380: opener.document.display.categories.value = newcategories;
4381: opener.document.display.categories_display.value = unescapedcats;
4382: alert("$alert");
4383: self.close();
4384: return;
4385: }
4386:
4387: </script>
4388: ENDSCRIPT
4389: } else {
4390: my $onload;
4391: }
1.9 raeburn 4392: my ($crscat,$catcrs,$assign);
4393: if ($crstype eq 'Community') {
4394: $crscat = 'Community Categories';
4395: $catcrs = &mt('Categorize Community');
4396: $assign = &mt('Assign one or more categories to this community.')
4397: } else {
4398: $crscat = 'Course Categories';
4399: $catcrs = &mt('Categorize Course');
4400: $assign = &mt('Assign one or more categories to this course.')
4401: }
1.1 raeburn 4402: my $start_page =
1.9 raeburn 4403: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4404: {'only_body' => 1,});
4405: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4406: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4407: if ($hascats) {
4408: my %currsettings =
4409: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4410: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4411: $currsettings{'categories'},$crstype);
4412: if ($cattable eq '') {
4413: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4414: } else {
4415: $categoriesform .= $assign.'<br /><br />'.
4416: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4417: $cattable."\n".
4418: '<br /><input type="button" name="changes" value="'.
4419: &mt('Copy to main window').'" '.
4420: 'onclick="javascript:updateCategories()" /></form><br />';
4421: }
1.1 raeburn 4422: } else {
1.12 raeburn 4423: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4424: }
4425: $r->print($start_page.$categoriesform.$end_page);
4426: return;
4427: }
4428:
1.36 raeburn 4429: sub display_loncaparev_constraints {
4430: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.124 raeburn 4431: my ($reqdmajor,$reqdminor);
1.36 raeburn 4432: my $cid = $env{'request.course.id'};
4433: my $cdom = $env{'course.'.$cid.'.domain'};
4434: my $cnum = $env{'course.'.$cid.'.num'};
4435: my $output;
1.39 raeburn 4436: my %lt = &Apache::lonlocal::texthash (
4437: 'all' => 'all',
4438: 'section/group' => 'section/group',
4439: 'user' => 'user',
4440: );
1.66 raeburn 4441: &Apache::lonrelrequtils::init_global_hashes();
4442: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4443: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4444: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 4445: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4446: }
4447: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 4448: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 4449: @scopeorder = ('all','section/group','user');
1.67 raeburn 4450: my $now = time;
1.36 raeburn 4451: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4452: if (ref($resourcedata) eq 'HASH') {
4453: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 4454: my %found;
1.66 raeburn 4455: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4456: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 4457: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
4458: my $value = $resourcedata->{$key};
4459: if ($item eq 'examcode') {
4460: if (&Apache::lonnet::validCODE($value)) {
4461: $value = 'valid';
4462: } else {
4463: $value = '';
4464: }
4465: } elsif ($item eq 'printstartdate') {
1.67 raeburn 4466: if ($value =~ /^\d+$/) {
1.70 raeburn 4467: if ($value > $now) {
4468: $value = 'future';
4469: }
4470: }
4471: } elsif ($item eq 'printenddate') {
4472: if ($value =~ /^\d+$/) {
4473: if ($value < $now) {
4474: $value = 'past';
4475: }
4476: }
4477: }
4478: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
4479: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4480: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 4481: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 4482: }
4483: }
4484: }
4485: }
1.79 raeburn 4486: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
4487: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 4488: my $value = $resourcedata->{$key};
1.79 raeburn 4489: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 4490: if ($value =~ /$valuematch/) {
4491: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 4492: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 4493: $found{$item}{'rev'} =
1.76 raeburn 4494: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 4495: last;
4496: }
4497: }
4498: }
4499: }
1.76 raeburn 4500: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
4501: my $regexp;
4502: if ($item eq 'maplevelrecurse') {
4503: $regexp = '\.(?:sequence|page)___\(rec\)\.';
4504: }
4505: if ($regexp ne '') {
4506: if ($key =~ /$regexp.*\.(\w+)$/) {
4507: my $name = $1;
4508: my $value = $resourcedata->{$key};
4509: if ($name eq 'type') {
4510: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
4511: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
4512: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
4513: }
4514: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
4515: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
4516: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
4517: $found{$name}{'rev'} =
4518: $Apache::lonnet::needsrelease{'parameter::::'.$item};
4519: }
4520: }
4521: }
1.70 raeburn 4522: foreach my $item (keys(%found)) {
4523: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4524: my $rev = $found{$item}{'rev'};
4525: my $valname = $found{$item}{'valname'};
1.76 raeburn 4526: my $extra = $found{$item}{'extra'};
1.70 raeburn 4527: my ($middle,$scope,$which,$level,$map,$resource);
4528: my $start = $cid.'.';
4529: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4530: $middle = $1;
4531: $which = $2;
4532: $scope = 'user';
4533: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4534: $middle = $1;
4535: $which = $2;
4536: $scope = 'section/group';
4537: } else {
4538: $scope = 'all';
4539: }
4540: my $what="$stdname=$valname";
1.76 raeburn 4541: if ($extra) {
4542: $what .= "<br/>$extra<br />";
4543: }
1.70 raeburn 4544: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4545: $level = 'general';
4546: if ($scope eq 'all') {
4547: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4548: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4549: push(@{$fromparam{$rev}{$scope}},$what);
4550: }
4551: } else {
4552: push(@{$fromparam{$rev}{$scope}},$what);
4553: }
4554: } else {
4555: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4556: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4557: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4558: }
4559: } else {
4560: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4561: }
4562: }
4563: $rowspan{$rev} ++;
1.76 raeburn 4564: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 4565: $level = 'folder';
4566: $map = $1;
4567: if ($scope eq 'all') {
4568: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4569: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4570: push(@{$bymap{$map}{$rev}{$scope}},$what);
4571: }
4572: } else {
4573: push(@{$bymap{$map}{$rev}{$scope}},$what);
4574: }
4575: } else {
4576: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4577: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4578: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4579: }
4580: } else {
4581: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4582: }
4583: }
4584: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4585: $level = 'resource';
4586: $resource = $1;
4587: if ($scope eq 'all') {
4588: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4589: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4590: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4591: }
4592: } else {
4593: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4594: }
4595: } else {
4596: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4597: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4598: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4599: }
4600: } else {
4601: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 4602: }
4603: }
4604: }
4605: }
4606: }
4607: if (keys(%fromparam)) {
4608: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4609: &Apache::loncommon::start_data_table().
4610: &Apache::loncommon::start_data_table_header_row().
4611: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4612: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4613: &Apache::loncommon::end_data_table_header_row();
4614: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 4615: my ($major,$minor) = split(/\./,$rev);
4616: ($reqdmajor,$reqdminor) =
4617: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4618: $output .= &Apache::loncommon::start_data_table_row().
4619: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4620: my $newrow;
4621: foreach my $scope (@scopeorder) {
4622: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4623: if ($newrow) {
4624: $output .= &Apache::loncommon::continue_data_table_row();
4625: }
1.39 raeburn 4626: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4627: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4628: $output .= '<td>'.$which.'</td><td>'.
4629: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4630: }
4631: $output .= &Apache::loncommon::end_data_table_row();
4632: $newrow = 1;
4633: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4634: if ($newrow) {
4635: $output .= &Apache::loncommon::continue_data_table_row();
4636: }
1.39 raeburn 4637: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4638: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4639: &Apache::loncommon::end_data_table_row();
4640: $newrow = 1;
4641: }
4642: }
4643: }
4644: $output .= &Apache::loncommon::end_data_table().'<br />';
4645: }
4646: }
4647:
1.66 raeburn 4648: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4649: my $now = time;
4650: if (keys(%comm_blocks) > 0) {
4651: foreach my $block (keys(%comm_blocks)) {
4652: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 4653: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 4654: if (ref($comm_blocks{$block}) eq 'HASH') {
4655: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4656: ' '.&mt('set by [_1]',
4657: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4658: }
4659: next;
4660: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4661: my ($start,$end) = ($1,$2);
4662: next if ($end < $now);
4663: }
4664: if (ref($comm_blocks{$block}) eq 'HASH') {
4665: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4666: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4667: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 4668: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 4669: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4670: ' '.
4671: &mt('set by [_1]',
4672: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4673: }
4674: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 4675: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 4676: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4677: ' '.
4678: &mt('set by [_1]',
4679: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4680:
4681: }
4682: }
4683: }
4684: }
4685: if (keys(%fromblocks)) {
4686: my %lt = (
4687: docs => 'Content blocking',
4688: printout => 'Printout generation',
4689: timer => 'Timed quiz trigger',
4690: );
4691: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4692: &Apache::loncommon::start_data_table().
4693: &Apache::loncommon::start_data_table_header_row().
4694: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4695: '<th>'.&mt('Event(s)').'</th>'.
4696: &Apache::loncommon::end_data_table_header_row();
4697: foreach my $type ('docs','printout','timer') {
4698: if (ref($fromblocks{$type}) eq 'HASH') {
4699: foreach my $rev (keys(%{$fromblocks{$type}})) {
4700: my ($major,$minor) = split(/\./,$rev);
1.124 raeburn 4701: ($reqdmajor,$reqdminor) =
1.66 raeburn 4702: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4703: $output .= &Apache::loncommon::start_data_table_row().
4704: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4705: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4706: $output .= $event.'<br />';
4707: }
4708: $output =~ s{\Q<br />\E$}{};
4709: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4710: }
4711: }
4712: }
4713: $output .= &Apache::loncommon::end_data_table().'<br />';
4714: }
4715: }
4716:
1.36 raeburn 4717: if (defined($navmap)) {
4718: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 4719: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 4720: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 4721: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 4722: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 4723: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4724: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4725: my $valanon=&get_param_description($stdtype,'anonsurvey');
4726: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 4727: my %checkedrev;
1.85 raeburn 4728: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 4729: my @parts = @{$res->parts()};
4730: my $symb = $res->symb();
4731: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 4732: if ($res->is_tool()) {
4733: my $rev = $rev_exttool;
4734: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
4735: $allmaps{$enclosing_map} = 1;
4736: next;
4737: }
1.36 raeburn 4738: foreach my $part (@parts) {
4739: if (exists($anonsubms{$symb."\0".$part})) {
4740: my $rev = $rev_anonsurv;
4741: my $what="$stdname=$valanon";
4742: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4743: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4744: push(@{$bysubmission{$symb}{$rev}},$what);
4745: }
4746: } else {
4747: push(@{$bysubmission{$symb}{$rev}},$what);
4748: }
4749: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4750: unless ($checkedrev{'anonsurvey'}) {
4751: my ($major,$minor) = split(/\./,$rev);
4752: ($reqdmajor,$reqdminor) =
4753: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4754: $reqdmajor,$reqdminor);
4755: $checkedrev{'anonsurvey'} = 1;
4756: }
1.36 raeburn 4757: }
4758: if (exists($randtrysubms{$symb."\0".$part})) {
4759: my $rev = $rev_randtry;
4760: my $what="$stdname=$valrandtry";
4761: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4762: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4763: push(@{$bysubmission{$symb}{$rev}},$what);
4764: }
4765: } else {
4766: push(@{$bysubmission{$symb}{$rev}},$what);
4767: }
4768: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4769: unless ($checkedrev{'randomizetry'}) {
4770: my ($major,$minor) = split(/\./,$rev);
4771: ($reqdmajor,$reqdminor) =
4772: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4773: $reqdmajor,$reqdminor);
4774: $checkedrev{'randomizetry'} = 1;
4775: }
1.36 raeburn 4776: }
4777: }
4778: my %responses = $res->responseTypes();
4779: foreach my $key (keys(%responses)) {
1.66 raeburn 4780: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4781: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4782: unless ($checkedrev{$key}) {
4783: my ($major,$minor) = split(/\./,$rev);
4784: ($reqdmajor,$reqdminor) =
4785: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4786: $reqdmajor,$reqdminor);
4787: $checkedrev{$key} = 1;
1.124 raeburn 4788: }
1.66 raeburn 4789: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4790: $allmaps{$enclosing_map} = 1;
4791: }
4792: }
4793: }
4794: if (keys(%byresource) > 0) {
4795: foreach my $symb (keys(%byresource)) {
4796: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4797: $allmaps{$map} = 1;
4798: }
4799: }
4800: if (keys(%bymap) > 0) {
4801: foreach my $map (keys(%bymap)) {
4802: $allmaps{$map} = 1;
4803: }
4804: }
4805: foreach my $map (keys(%allmaps)) {
4806: my $mapres = $navmap->getResourceByUrl($map);
4807: if (ref($mapres)) {
1.68 raeburn 4808: my $mapsymb = $mapres->symb();
4809: $toshow{$mapsymb} = 1;
1.36 raeburn 4810: my $pcslist = $mapres->map_hierarchy();
4811: if ($pcslist ne '') {
4812: foreach my $pc (split(/,/,$pcslist)) {
4813: my $res = $navmap->getByMapPc($pc);
4814: if (ref($res)) {
4815: my $symb = $res->symb();
4816: unless ($symb eq '______') {
4817: $toshow{$symb} = 1;
4818: }
4819: }
4820: }
4821: }
4822: }
4823: }
4824: }
1.117 raeburn 4825: my $supptools = &Apache::lonnet::count_supptools($cnum,$cdom,1,1);
1.36 raeburn 4826: my $mapres_header = '<h4>'.
4827: &mt('Requirements for specific folders or resources').
4828: '</h4>';
4829: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4830: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4831: $output .= $mapres_header;
4832: }
4833: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4834: my $title = 'Version Constraints';
4835: my $start_page =
4836: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4837: $r->print($start_page.$top_header);
4838: if ($output) {
4839: $r->print($output);
1.86 raeburn 4840: if (defined($navmap) || $supptools) {
1.36 raeburn 4841: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4842: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4843: }
4844: $r->print('<br /><br />');
4845: } else {
4846: $r->print('<p class="LC_info">'.
4847: &mt('No version requirements from resource content or settings.').
4848: '</p>');
4849: }
4850: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4851: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4852: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4853: return 1;
4854: }
1.36 raeburn 4855: return;
4856: }
4857:
4858: sub show_contents_view {
1.39 raeburn 4859: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 4860: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
4861: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4862: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4863: my $showmaincontent;
4864: if ((ref($navmap)) &&
4865: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4866: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
4867: (keys(%{$bycrsrestype}) > 0))) {
4868: $showmaincontent = 1;
4869: }
4870: if ($showmaincontent || $supptools) {
4871: $r->print(&Apache::loncommon::start_data_table());
4872: }
4873: if ($showmaincontent) {
4874: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 4875: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 4876: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 4877: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4878: '<th>'.&mt('Attribute/Setting').'</th>'.
4879: &Apache::loncommon::end_data_table_header_row().
4880: &Apache::loncommon::start_data_table_row().
1.58 raeburn 4881: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 4882: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
4883: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4884: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4885: my $curRes;
4886: my $depth = 0;
4887: my %parent = ();
4888: my $startcount = 5;
4889: my $lastcontainer = $startcount;
4890: while ($curRes = $it->next()) {
4891: if ($curRes == $it->BEGIN_MAP()) {
4892: $depth++;
4893: $parent{$depth}= $lastcontainer;
4894: }
4895: if ($curRes == $it->END_MAP()) {
4896: $depth--;
4897: $lastcontainer = $parent{$depth};
4898: }
4899: my $indent;
4900: for (my $i=0; $i<$depth; $i++) {
4901: $indent.= $whitespace;
4902: }
4903: if (ref($curRes)) {
4904: my $symb = $curRes->symb();
4905: my $ressymb = $symb;
4906: my $srcf = $curRes->src();
4907: my $title = &Apache::lonnet::gettitle($srcf);
4908: if (($curRes->is_sequence()) || ($curRes->is_page())) {
4909: next unless($toshow->{$symb});
4910: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
4911: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4912: if ($curRes->is_page()) {
4913: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
4914: }
4915: my $rowspan = 1;
4916: if (ref($bymap->{$url}) eq 'HASH') {
4917: $rowspan = scalar(keys(%{$bymap->{$url}}));
4918: }
4919: $r->print(&Apache::loncommon::start_data_table_row().
4920: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 4921: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 4922: $r->print(&Apache::loncommon::end_data_table_row());
4923: } else {
4924: my $rowspan;
4925: if (ref($byresource->{$symb}) eq 'HASH') {
4926: $rowspan += scalar(keys(%{$byresource->{$symb}}));
4927: }
4928: if (ref($bysubmission->{$symb}) eq 'HASH') {
4929: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
4930: }
4931: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4932: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
4933: }
1.85 raeburn 4934: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
4935: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
4936: }
1.36 raeburn 4937: next if (!$rowspan);
4938: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
4939: &mt('Problem').'" />';
4940: $r->print(&Apache::loncommon::start_data_table_row().
4941: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
4942: my $newrow;
4943: if (ref($byresource->{$symb}) eq 'HASH') {
4944: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
4945: if ($newrow) {
4946: $r->print(&Apache::loncommon::continue_data_table_row());
4947: }
4948: $r->print('<td valign="middle">'.$rev.'</td><td>');
4949: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
4950: $r->print('<table border="0">');
4951: foreach my $scope (@{$scopeorder}) {
4952: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4953: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4954: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
4955: $r->print('<td>'.$which.'</td><td>'.
4956: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
4957: '</td>');
4958: }
4959: $r->print('</tr>');
4960: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4961: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 4962: '<td> </td><td>'.
4963: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
4964: }
4965: }
4966: $r->print('</table>');
4967: }
4968: $r->print('</td>');
4969: $r->print(&Apache::loncommon::end_data_table_row());
4970: $newrow = 1;
4971: }
4972: }
4973: if (ref($bysubmission->{$symb}) eq 'HASH') {
4974: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
4975: if ($newrow) {
4976: $r->print(&Apache::loncommon::continue_data_table_row());
4977: }
4978: $r->print('<td>'.$rev.'</td><td>');
4979: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
4980: $r->print(&mt('Submissions to: ').' '.
4981: join(', ',@{$bysubmission->{$symb}{$rev}}));
4982: }
4983: $r->print('</td>');
4984: $r->print(&Apache::loncommon::end_data_table_row());
4985: $newrow = 1;
4986: }
4987: }
4988: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4989: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
4990: if ($newrow) {
4991: $r->print(&Apache::loncommon::continue_data_table_row());
4992: }
4993: $r->print('<td>'.$rev.'</td><td>');
4994: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
4995: $r->print(&mt('Response Type(s): ').' '.
4996: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
4997: }
4998: $r->print('</td>');
4999: }
5000: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 5001: $newrow = 1;
5002: }
5003: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5004: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
5005: if ($newrow) {
5006: $r->print(&Apache::loncommon::continue_data_table_row());
5007: }
5008: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
5009: }
1.86 raeburn 5010: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5011: }
5012: }
5013: }
5014: }
1.86 raeburn 5015: }
5016: if ($supptools) {
5017: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5018: $r->print(&Apache::loncommon::start_data_table_header_row().
5019: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5020: '<th>'.&mt('Resource Type').'</th>'.
5021: &Apache::loncommon::end_data_table_header_row().
5022: &Apache::loncommon::start_data_table_row().
5023: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
5024: '<td valign="middle">'.
5025: $Apache::lonrelrequtils::exttool{'major'}.'.'.
5026: $Apache::lonrelrequtils::exttool{'minor'}.
5027: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
5028: $supptools).'</td>'.
5029: &Apache::loncommon::end_data_table_row());
5030: }
5031: if ($showmaincontent || $supptools) {
1.36 raeburn 5032: $r->print(&Apache::loncommon::end_data_table());
5033: }
1.66 raeburn 5034: return;
1.36 raeburn 5035: }
5036:
5037: sub releases_by_map {
1.39 raeburn 5038: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 5039: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.124 raeburn 5040: my $newrow = 0;
1.36 raeburn 5041: if (ref($bymap->{$url}) eq 'HASH') {
5042: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 5043: if ($newrow) {
5044: $r->print(&Apache::loncommon::end_data_table_row().
5045: &Apache::loncommon::continue_data_table_row());
5046: }
1.36 raeburn 5047: $r->print('<td valign="middle">'.$rev.'</td><td>');
5048: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
5049: $r->print('<table border="0">');
5050: foreach my $scope (@{$scopeorder}) {
5051: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5052: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5053: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
5054: $r->print('<td>'.$which.'</td><td>'.
5055: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
5056: '</td>');
5057: }
5058: $r->print('</tr>');
5059: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5060: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 5061: '</td><td> </td><td>'.
5062: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
5063: }
5064: }
5065: $r->print('</table>');
5066: }
5067: $r->print('</td>');
1.73 raeburn 5068: $newrow = 1;
1.36 raeburn 5069: }
5070: } else {
5071: $r->print('<td colspan="2"> </td>');
5072: }
5073: return;
5074: }
5075:
5076: sub get_param_description {
1.70 raeburn 5077: my ($stdtype,$value,$regexp) = @_;
5078: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 5079: if ($stdtype =~ /^string/) {
5080: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5081: } elsif ($stdtype eq 'date_interval') {
5082: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
5083: }
1.70 raeburn 5084: if ($regexp) {
1.74 raeburn 5085: if ($stdtype =~ /^string/) {
5086: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
5087: } elsif ($stdtype eq 'date_interval') {
5088: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
5089: }
1.70 raeburn 5090: if (ref($parammatches) eq 'ARRAY') {
5091: @possibles = @{$parammatches};
5092: } else {
5093: undef($regexp);
5094: $name = $value;
5095: }
5096: }
5097: unless ($regexp) {
5098: $name = $value;
5099: if (ref($paramstrings) eq 'ARRAY') {
5100: @possibles = @{$paramstrings};
5101: } else {
1.76 raeburn 5102: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
5103: if ($name == 0) {
5104: $name = &mt('Never');
5105: } elsif (($name ne '') && ($name !~ /\D/)) {
5106: $name = &Apache::lonlocal::locallocaltime($name);
5107: }
5108: }
1.70 raeburn 5109: return $name;
5110: }
1.36 raeburn 5111: }
1.70 raeburn 5112: foreach my $possibilities (@possibles) {
1.36 raeburn 5113: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 5114: my $gotregexmatch = '';
5115: if ($regexp) {
5116: last if ($gotregexmatch);
5117: my ($item,$pattern) = @{ $possibilities };
5118: if ($value =~ /$pattern/) {
5119: if (ref($paramstrings) eq 'ARRAY') {
5120: foreach my $possibles (@{$paramstrings}) {
5121: next unless (ref($possibles) eq 'ARRAY');
5122: my ($thing,$description) = @{$possibles};
5123: if ($thing eq $item) {
5124: $name = $description;
5125: $gotregexmatch = 1;
5126: last;
5127: }
5128: }
5129: last if ($gotregexmatch);
5130: }
5131: }
5132: } else {
5133: my ($thing,$description) = @{ $possibilities };
5134: if ($thing eq $value) {
5135: $name = $description;
5136: last;
5137: }
1.36 raeburn 5138: }
5139: }
5140: return $name;
5141: }
5142:
1.66 raeburn 5143: sub update_releasereq {
5144: my $readmap = 1;
5145: my $getrelreq = 1;
5146: if (ref($modified_courses) eq 'ARRAY') {
5147: foreach my $item (@{$modified_courses}) {
5148: if (ref($item) eq 'ARRAY') {
5149: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5150: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5151: $chome,$crstype,$cdom.'_'.$cnum,
5152: $readmap,$getrelreq);
5153: }
5154: }
5155: $modified_courses = [];
5156: }
5157: undef($registered_cleanup);
5158: return;
5159: }
5160:
1.25 raeburn 5161: sub show_autocoowners {
5162: my (@currcoown) = @_;
1.56 raeburn 5163: 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 5164: if (@currcoown > 0) {
5165: $output .= '<br />'.&mt('Current co-owners are:').' '.
5166: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5167: } else {
5168: $output .= '<br />'.&mt('Currently no co-owners.');
5169: }
5170: return $output;
5171: }
5172:
5173: sub coowner_invitations {
1.80 raeburn 5174: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5175: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5176: my $pendingcoowners =
5177: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5178: if ($pendingcoowners) {
5179: @pendingcoown = split(',',$pendingcoowners);
5180: }
1.80 raeburn 5181: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5182: @currcoown = @{$currcoownref};
1.80 raeburn 5183: }
5184: my $disabled;
5185: if ($noedit) {
5186: $disabled = ' disabled="disabled"';
5187: }
1.25 raeburn 5188: my $ccrole = 'cc';
5189: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5190: foreach my $key (sort(keys(%ccroles))) {
5191: my ($ccname,$ccdom,$role) = split(':',$key);
5192: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5193: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5194: push(@othercoords,$ccname.':'.$ccdom);
5195: }
5196: }
5197: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5198: if ($coowner_rows) {
5199: $output .= &Apache::loncommon::start_data_table();
5200: if (@currcoown) {
5201: $output .= &Apache::loncommon::start_data_table_row().
5202: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5203: foreach my $person (@currcoown) {
5204: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5205: $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 5206: }
5207: $output .= '</td>'.
5208: &Apache::loncommon::end_data_table_row();
5209: }
5210: if ($pendingcoowners) {
5211: $output .= &Apache::loncommon::start_data_table_row().
5212: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5213: foreach my $person (@pendingcoown) {
5214: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5215: $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 5216: }
5217: $output .= '</td>'.
5218: &Apache::loncommon::end_data_table_row();
5219: }
5220: if (@othercoords) {
5221: $output .= &Apache::loncommon::start_data_table_row().
5222: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5223: foreach my $person (@othercoords) {
5224: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5225: $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 5226: }
5227: $output .= '</td>'.
5228: &Apache::loncommon::end_data_table_row();
5229: }
5230: $output .= &Apache::loncommon::end_data_table();
5231: } else {
5232: $output = &mt('There are no coordinators to select as co-owners');
5233: }
5234: return $output;
5235: }
5236:
5237: sub manage_coownership {
1.80 raeburn 5238: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5239: my (@pendingcoown,@currcoown);
1.25 raeburn 5240: my $pendingcoowners =
5241: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5242: if ($pendingcoowners) {
5243: @pendingcoown = split(',',$pendingcoowners);
5244: }
1.80 raeburn 5245: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5246: @currcoown = @{$currcoownref};
1.80 raeburn 5247: }
5248: my $disabled;
5249: if ($noedit) {
5250: $disabled = ' disabled="disabled"';
5251: }
1.25 raeburn 5252: my ($is_coowner,$is_pending,$output);
5253: my $uname = $env{'user.name'};
5254: my $udom = $env{'user.domain'};
5255: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5256: $is_coowner = 1;
5257: }
5258: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5259: $is_pending = 1;
5260: }
5261: if (@currcoown && ($is_coowner || $is_pending)) {
5262: $output = &Apache::loncommon::start_data_table();
5263: }
5264: if (@currcoown) {
5265: if ($is_coowner || $is_pending) {
5266: $output .= &Apache::loncommon::start_data_table().
5267: &Apache::loncommon::start_data_table_row().'<td>';
5268: }
5269: $output .= &mt('Current co-owners are:').' '.
5270: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5271: if ($is_coowner || $is_pending) {
5272: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5273: }
5274: }
5275: if ($is_coowner || $is_pending) {
5276: if (@currcoown) {
5277: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5278: }
5279: $output .= '<span class="LC_nobreak">';
5280: if ($is_coowner) {
1.90 raeburn 5281: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5282: } else {
1.90 raeburn 5283: $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).
5284: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5285: }
5286: $output .= '</span>';
5287: if (@currcoown) {
5288: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5289: }
5290: }
5291: if (@currcoown && ($is_coowner || $is_pending)) {
5292: $output .= &Apache::loncommon::end_data_table();
5293: }
5294: return $output;
5295: }
5296:
1.1 raeburn 5297: sub print_localization {
1.80 raeburn 5298: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5299: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5300: return;
5301: }
5302: my %items = (
5303: languages => {
1.17 faziophi 5304: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5305: &mt("(overrides individual user preference)"),
1.1 raeburn 5306: input => 'selectbox',
5307: },
5308: timezone => {
1.17 faziophi 5309: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5310: input => 'selectbox',
5311: },
5312: datelocale => {
1.17 faziophi 5313: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5314: input => 'selectbox',
5315: },
5316: );
1.80 raeburn 5317: my ($datatable,$disabled);
1.1 raeburn 5318: my $count = 0;
1.80 raeburn 5319: if ($noedit) {
5320: $disabled = ' disabled="disabled"';
5321: }
1.1 raeburn 5322: foreach my $item (@{$ordered}) {
5323: $count ++;
1.56 raeburn 5324: my $colspan;
5325: unless ($item eq 'languages') {
1.80 raeburn 5326: $colspan = 2;
1.56 raeburn 5327: }
5328: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5329: if ($item eq 'timezone') {
5330: my $includeempty = 1;
5331: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5332: my $onchange;
5333: unless ($noedit) {
5334: $onchange = ' onchange="javascript:toggleTimeZone();"';
5335: }
5336: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5337: $datatable .=
1.115 raeburn 5338: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5339: $includeempty,$id,$disabled);
5340: my $tzsty = 'none';
5341: if ($timezone ne '') {
5342: $tzsty = 'block';
5343: }
5344: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5345: '<span class="LC_nobreak">'.
5346: &mt('Override individual user preference?').
5347: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5348: '</span></div>';
1.1 raeburn 5349: } elsif ($item eq 'datelocale') {
5350: my $includeempty = 1;
5351: my $locale_obj = &Apache::lonlocal::getdatelocale();
5352: my $currdatelocale;
5353: if (ref($locale_obj)) {
5354: $currdatelocale = $locale_obj->id();
5355: }
5356: $datatable .=
5357: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5358: undef,$includeempty,$disabled);
1.1 raeburn 5359: } else {
5360: if ($settings->{$item} eq '') {
1.124 raeburn 5361: unless ($noedit) {
1.80 raeburn 5362: $datatable .= '</td><td align="right">'.
5363: &Apache::loncommon::select_language('languages_0','',1);
5364: }
1.1 raeburn 5365: } else {
5366: my $num = 0;
1.3 raeburn 5367: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5368: $datatable .= '</td><td align="right"><br />'.
5369: &Apache::loncommon::start_data_table();
1.1 raeburn 5370: if (@languages > 0) {
1.3 raeburn 5371: my %langchoices = &get_lang_choices();
1.1 raeburn 5372: foreach my $lang (@languages) {
5373: my $showlang = $lang;
1.3 raeburn 5374: if (exists($langchoices{$lang})) {
5375: $showlang = $langchoices{$lang};
1.1 raeburn 5376: }
5377: $datatable .=
5378: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5379: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5380: &mt('Language:').'<b> '.$showlang.
5381: '</b><input type="hidden" name="languages_'.$num.
5382: '" value="'.$lang.'" /></span><br />'.
5383: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5384: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5385: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5386: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5387: $num ++;
5388: }
5389: }
1.80 raeburn 5390: unless ($noedit) {
5391: $datatable .=
5392: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5393: '<td align="left"><span class="LC_nobreak">'.
5394: &mt('Additional language:'). '</span><br />'.
5395: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5396: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5397: '</td>'.&Apache::loncommon::end_data_table_row();
1.124 raeburn 5398: }
5399: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5400: }
5401: }
5402: $datatable .= &item_table_row_end();
5403: }
5404: $$rowtotal += scalar(@{$ordered});
5405: return $datatable;
5406: }
5407:
1.3 raeburn 5408: sub get_lang_choices {
5409: my %langchoices;
5410: foreach my $id (&Apache::loncommon::languageids()) {
5411: my $code = &Apache::loncommon::supportedlanguagecode($id);
5412: if ($code) {
5413: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5414: }
5415: }
5416: return %langchoices;
5417: }
5418:
1.1 raeburn 5419: sub print_feedback {
1.80 raeburn 5420: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5421: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5422: return;
5423: }
5424: my %items = (
1.3 raeburn 5425: 'question.email' => {
5426: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5427: input => 'textbox',
5428: size => '50',
5429: },
5430:
1.3 raeburn 5431: 'comment.email' => {
5432: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5433: input => 'textbox',
5434: size => '50',
5435: },
5436:
1.3 raeburn 5437: 'policy.email' => {
5438: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5439: input => 'textbox',
5440: size => '50',
5441: },
5442: );
5443: my $datatable;
5444: my $count = 0;
5445: my ($cnum) = &get_course();
5446: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5447: my @sections = sort( { $a <=> $b } keys(%sections));
5448: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5449: currone => 'Current recipient:',
5450: currmult => 'Current recipients:',
5451: add => 'Additional recipient:',
5452: del => 'Delete?',
5453: sec => 'Sections:',
1.1 raeburn 5454: );
1.80 raeburn 5455: my $disabled;
5456: if ($noedit) {
5457: $disabled = ' disabled="disabled"';
5458: }
1.1 raeburn 5459: foreach my $item (@{$ordered}) {
5460: $count ++;
1.20 faziophi 5461: if ($position eq 'top') {
5462: $datatable .= &item_table_row_start($items{$item}{text},$count);
5463: } else {
1.56 raeburn 5464: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5465: }
1.1 raeburn 5466: if ($position eq 'top') {
5467: my $includeempty = 0;
1.94 raeburn 5468: $datatable .= '</td><td align="right">'.
5469: &user_table($cdom,$item,\@sections,
1.80 raeburn 5470: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5471: } else {
1.3 raeburn 5472: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5473: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5474: }
5475: $datatable .= &item_table_row_end();
5476: }
5477: $$rowtotal += scalar(@{$ordered});
5478: return $datatable;
5479: }
5480:
5481: sub user_table {
1.80 raeburn 5482: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5483: my $output;
5484: if ($currvalue eq '') {
1.80 raeburn 5485: unless ($noedit) {
5486: $output .= &select_recipient($item,'0',$cdom,$sections);
5487: }
1.1 raeburn 5488: } else {
5489: my $num = 0;
5490: my @curr = split(/,/,$currvalue);
1.56 raeburn 5491: $output .= '<table class="LC_data_table">';
1.1 raeburn 5492: my ($currusers);
1.80 raeburn 5493: my $disabled;
5494: if ($noedit) {
5495: $disabled = ' disabled="disabled"';
5496: }
1.1 raeburn 5497: foreach my $val (@curr) {
5498: next if ($val eq '');
5499: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5500: my @selsec;
5501: if ($seclist) {
5502: $seclist =~ s/(^\(|\)$)//g;
5503: @selsec = split(/\s*;\s*/,$seclist);
5504: }
5505: $currusers .= '<tr>'.
5506: '<td valign="top"><span class="LC_nobreak">'.
5507: '<label><input type="checkbox" '.
1.80 raeburn 5508: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5509: $lt->{'del'}.'</label>'.
5510: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5511: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5512: &Apache::loncommon::aboutmewrapper(
5513: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5514: $uname,$udom,'aboutuser');
5515: if (ref($sections) eq 'ARRAY') {
5516: if (@{$sections}) {
5517: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5518: &select_sections($item,$num,$sections,
1.80 raeburn 5519: \@selsec,$noedit);
1.1 raeburn 5520: }
5521: }
5522: $currusers .= '</span></td></tr>';
5523: $num ++;
5524: }
5525: if ($num) {
1.10 raeburn 5526: $output .= '<tr>'.
1.1 raeburn 5527: '<td align="left"><i>';
1.20 faziophi 5528: if ($num == 1) {
1.1 raeburn 5529: $output .= $lt->{'currone'};
5530: } else {
1.21 raeburn 5531: $output .= $lt->{'currmult'};
1.1 raeburn 5532: }
5533: $output .= '</i><br />'.
5534: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5535: '</tr>';
1.1 raeburn 5536: }
1.80 raeburn 5537: unless ($noedit) {
5538: $output .=
5539: '<tr>'.
1.1 raeburn 5540: '<td align="left"><span class="LC_nobreak"><i>'.
5541: $lt->{'add'}.'</i></span><br />'.
5542: &select_recipient($item,$num,$cdom,$sections).
5543: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5544: '</td></tr>';
5545: }
5546: $output .= '</table>';
1.1 raeburn 5547: }
5548: return $output;
5549: }
5550:
5551: sub select_recipient {
5552: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5553: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5554: my $selectlink =
5555: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5556: $item.'_udom_'.$num,'only');
1.1 raeburn 5557: my $output =
1.10 raeburn 5558: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5559: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5560: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5561: if (ref($sections) eq 'ARRAY') {
5562: if (@{$sections}) {
5563: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5564: &select_sections($item,$num,$sections,$selected).'</td>';
5565: }
5566: }
5567: $output .= '<td valign="top">'.
5568: $selectlink.'</td></tr></table>';
5569: return $output;
5570: }
5571:
5572: sub select_sections {
1.80 raeburn 5573: my ($item,$num,$sections,$selected,$noedit) = @_;
5574: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5575: if (ref($selected) eq 'ARRAY') {
5576: @currsecs = @{$selected};
5577: }
5578: if (!@currsecs) {
5579: $allsec = ' selected="selected"';
5580: }
1.80 raeburn 5581: if ($noedit) {
5582: $disabled = ' disabled="disabled"';
5583: }
1.1 raeburn 5584: if (ref($sections) eq 'ARRAY') {
5585: if (@{$sections}) {
5586: my $mult;
5587: if (@{$sections} > 1) {
5588: $mult = ' multiple="multiple"';
5589: if (@{$sections} > 3) {
5590: $mult .= ' size="4"';
5591: }
5592: }
1.80 raeburn 5593: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
1.1 raeburn 5594: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
5595: foreach my $sec (@{$sections}) {
5596: my $is_sel;
5597: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
5598: $is_sel = 'selected="selected"';
5599: }
5600: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5601: }
5602: $output .= '</select>';
5603: }
5604: }
5605: return $output;
5606: }
5607:
5608: sub print_discussion {
1.80 raeburn 5609: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5610: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5611: return;
5612: }
5613: my %items = (
5614: 'plc.roles.denied' => {
1.10 raeburn 5615: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5616: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5617: &mt('(role-based)'),
1.1 raeburn 5618: input => 'checkbox',
5619: },
5620:
5621: 'plc.users.denied' => {
1.3 raeburn 5622: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5623: &mt('(specific user(s))'),
1.1 raeburn 5624: input => 'checkbox',
5625: },
5626:
5627: 'pch.roles.denied' => {
1.10 raeburn 5628: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5629: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5630: &mt('(role-based)'),
1.1 raeburn 5631: input => 'checkbox',
5632: },
5633:
5634: 'pch.users.denied' => {
1.3 raeburn 5635: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5636: &mt('(specific user(s))'),
1.1 raeburn 5637: input => 'checkbox',
5638: },
1.77 raeburn 5639:
5640: 'pac.roles.denied' => {
5641: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5642: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5643: &mt('(role-based)'),
5644: input => 'checkbox',
5645: },
5646:
5647: 'pac.users.denied' => {
5648: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5649: &mt('(specific user(s))'),
5650: input => 'checkbox',
5651: },
5652:
1.1 raeburn 5653: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5654: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5655: input => 'radio',
5656: },
5657:
5658: 'allow_discussion_post_editing' => {
1.3 raeburn 5659: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5660: input => 'checkbox',
5661: },
1.50 raeburn 5662: 'discussion_post_fonts' => {
5663: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5664: input => 'textbox',
5665: size => '20',
5666: },
1.1 raeburn 5667: );
5668: my $datatable;
5669: my $count;
5670: my ($cnum) = &get_course();
5671: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5672: my @sections = sort( { $a <=> $b } keys(%sections));
5673: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5674: currone => 'Disallowed:',
5675: currmult => 'Disallowed:',
5676: add => 'Disallow more:',
5677: del => 'Delete?',
5678: sec => 'Sections:',
1.1 raeburn 5679: );
5680: foreach my $item (@{$ordered}) {
5681: $count ++;
1.56 raeburn 5682: my $colspan;
5683: if ($item eq 'allow_limited_html_in_feedback') {
5684: $colspan = 2;
1.124 raeburn 5685: }
1.56 raeburn 5686: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5687: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5688: $datatable .= '</td><td align="right">'.
1.80 raeburn 5689: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5690: '</table>';
5691: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5692: $datatable .= '</td><td align="right">'.
5693: &user_table($cdom,$item,undef,
1.80 raeburn 5694: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5695: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5696: $datatable .= '</td><td align="right">'.
1.80 raeburn 5697: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5698: '</table>';
5699: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5700: $datatable .= '</td><td align="right">'.
5701: &user_table($cdom,$item,undef,
1.80 raeburn 5702: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5703: } elsif ($item eq 'pac.roles.denied') {
5704: $datatable .= '</td><td align="right">'.
1.80 raeburn 5705: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5706: '</table>';
5707: } elsif ($item eq 'pac.users.denied') {
5708: $datatable .= '</td><td align="right">'.
5709: &user_table($cdom,$item,undef,
1.80 raeburn 5710: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5711: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5712: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5713: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5714: $datatable .= '</td><td align="right"><br />'.
5715: &Apache::loncommon::start_data_table().
1.1 raeburn 5716: &Apache::loncommon::start_data_table_row().
5717: '<th align="left">'.&mt('Role').'</th><th>'.
5718: &mt('Sections').'</th>'.
5719: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5720: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5721: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5722: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5723: $datatable .= '</td><td align="right"><br />'.
5724: &Apache::loncommon::start_data_table().
1.50 raeburn 5725: &Apache::loncommon::start_data_table_row().
5726: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5727: '<th align="center">'.&mt('font-size').'</th>'.
5728: '<th align="center">'.&mt('font-weight').'</th>'.
5729: '<th align="center">'.&mt('font-style').'</th>'.
1.124 raeburn 5730: '<th align="center">'.&mt('Other css').'</th>'.
1.50 raeburn 5731: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5732: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5733: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5734: }
5735: $datatable .= &item_table_row_end();
5736: }
5737: $$rowtotal += scalar(@{$ordered});
5738: return $datatable;
5739: }
5740:
5741: sub role_checkboxes {
1.80 raeburn 5742: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5743: my @roles = ('st','ad','ta','ep','in');
5744: if ($crstype eq 'Community') {
5745: push(@roles,'co');
5746: } else {
5747: push(@roles,'cc');
5748: }
1.1 raeburn 5749: my $output;
5750: my (@current,@curr_roles,%currsec,@sections);
5751: if ($showsections) {
5752: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5753: @sections = sort( { $a <=> $b } keys(%sections));
5754: }
5755: if (ref($settings) eq 'HASH') {
5756: if ($settings->{$item}) {
5757: @current = split(',',$settings->{$item});
5758: if ($showsections) {
5759: foreach my $role (@current) {
5760: if ($role =~ /:/) {
5761: my ($trole,$sec) = split(':',$role);
5762: push(@curr_roles,$trole);
5763: if (ref($currsec{$trole}) eq 'ARRAY') {
5764: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5765: push(@{$currsec{$trole}},$sec);
5766: }
1.3 raeburn 5767: } else {
5768: $currsec{$trole} = [$sec];
1.1 raeburn 5769: }
5770: } else {
5771: push(@curr_roles,$role);
5772: }
5773: }
5774: @current = @curr_roles;
5775: }
5776: }
5777: }
5778: my $numinrow = 3;
5779: my $count = 0;
1.80 raeburn 5780: my $disabled;
5781: if ($noedit) {
1.124 raeburn 5782: $disabled = ' disabled="disabled"';
1.80 raeburn 5783: }
1.1 raeburn 5784: foreach my $role (@roles) {
5785: my $checked = '';
5786: if (grep(/^\Q$role\E$/,@current)) {
5787: $checked = ' checked="checked" ';
5788: }
1.9 raeburn 5789: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5790: if ($showsections) {
5791: $output .= &Apache::loncommon::start_data_table_row();
5792: } else {
5793: my $rem = $count%($numinrow);
5794: if ($rem == 0) {
5795: if ($count > 0) {
5796: $output .= '</tr>';
5797: }
5798: $output .= '<tr>';
5799: }
5800: }
1.30 raeburn 5801: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5802: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5803: $plrole.'</label></span></td>';
5804: if ($showsections) {
5805: $output .= '<td align="left">'.
1.80 raeburn 5806: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5807: '</td></tr>';
5808: }
5809: $count ++;
5810: }
5811: my %adv_roles =
5812: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5813: my $total = @roles;
5814: foreach my $role (sort(keys(%adv_roles))) {
5815: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5816: my $rolename = $3;
5817: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5818: my $checked = '';
5819: if (grep(/^\Q$value\E$/,@current)) {
5820: $checked = ' checked="checked" ';
5821: }
5822: if ($showsections) {
5823: $output .= &Apache::loncommon::start_data_table_row();
5824: } else {
5825: my $rem = $count%($numinrow);
5826: if ($rem == 0) {
5827: if ($count > 0) {
5828: $output .= '</tr>';
5829: }
5830: $output .= '<tr>';
5831: }
5832: }
1.30 raeburn 5833: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5834: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5835: '</label></span></td>';
5836: if ($showsections) {
5837: $output .= '<td>'.
1.80 raeburn 5838: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5839: '</td>'.&Apache::loncommon::end_data_table_row();
5840: }
5841: $total ++;
5842: $count ++;
5843: }
5844: }
5845: if (!$showsections) {
5846: my $rem = $total%($numinrow);
5847: my $colsleft = $numinrow - $rem;
5848: if ($colsleft > 1 ) {
5849: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5850: ' </td>';
5851: } elsif ($colsleft == 1) {
5852: $output .= '<td class="LC_left_item"> </td>';
5853: }
5854: $output .= '</tr>';
5855: }
5856: return $output;
5857: }
5858:
1.50 raeburn 5859: sub set_discussion_fonts {
1.80 raeburn 5860: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 5861: my ($classorder,$classtitles) = &discussion_vote_classes();
5862: my ($styleorder,$styleitems) = &discussion_vote_styles();
5863: my $output;
5864: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 5865: my $disabled;
5866: if ($noedit) {
5867: $disabled = ' disabled="disabled"';
5868: }
1.50 raeburn 5869: foreach my $cat (@{$classorder}) {
5870: my %curr = ();
5871: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5872: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5873: $output .= &Apache::loncommon::start_data_table_row().
5874: '<td>'.$classtitles->{$cat}.'</td>';
5875: if (ref($styleorder) eq 'ARRAY') {
5876: foreach my $item (@{$styleorder}) {
5877: $output .= '<td><span class="LC_nobreak">';
5878: my $selitem = $item;
5879: if ($item eq 'size') {
5880: my ($currsize,$currunit);
5881: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5882: ($currsize,$currunit) = ($1,$2);
5883: $curr{'size'} = $currunit;
5884: }
1.81 raeburn 5885: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 5886: ' ';
5887: $selitem = 'unit';
5888: }
5889: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 5890: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 5891: foreach my $val (@{$styleitems->{$item}}) {
5892: my $sel;
5893: if ($val eq $curr{$item}) {
5894: $sel = ' selected="selected"';
5895: }
5896: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
5897: }
5898: }
5899: }
5900: }
1.80 raeburn 5901: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 5902: }
5903: $output .= &Apache::loncommon::end_data_table_row();
5904: }
5905: return $output;
5906: }
5907:
5908: sub discussion_vote_classes {
5909: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
1.124 raeburn 5910: my %classtitles = &Apache::lonlocal::texthash(
1.50 raeburn 5911: 'twoplus' => 'Two sigma above mean',
5912: 'oneplus' => 'One sigma above mean',
5913: 'zero' => 'Within one sigma of mean',
5914: 'oneminus' => 'One sigma below mean',
5915: 'twominus' => 'Two sigma below mean',
5916: );
5917: return ($classorder,\%classtitles);
5918: }
5919:
5920: sub discussion_vote_styles {
5921: my $styleorder = ['size','weight','style'];
5922: my $styleitems = {
5923: size => ['','px','%','xx-small','x-small','small','medium','large',
5924: 'x-large','xx-large','smaller','larger'],
5925: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
5926: '500','600','700','800','900'],
5927: style => ['','normal','italic','oblique'],
5928: };
5929: return ($styleorder,$styleitems);
5930: }
5931:
1.1 raeburn 5932: sub print_classlists {
1.80 raeburn 5933: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5934: my @ordered;
5935: if ($position eq 'top') {
5936: @ordered = ('default_enrollment_start_date',
5937: 'default_enrollment_end_date');
1.55 raeburn 5938: if ($crstype eq 'Course') {
5939: push(@ordered,'defaultcredits');
5940: }
1.1 raeburn 5941: } elsif ($position eq 'middle') {
1.56 raeburn 5942: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 5943: } else {
5944: @ordered = ('student_classlist_view',
1.26 raeburn 5945: 'student_classlist_opt_in',
5946: 'student_classlist_portfiles');
1.1 raeburn 5947: }
1.9 raeburn 5948: my %lt;
5949:
5950: if ($crstype eq 'Community') {
5951: %lt = &Apache::lonlocal::texthash (
5952: disabled => 'No viewable membership list',
5953: section => "Membership of viewer's section",
5954: all => 'List of all members',
5955: );
5956: } else {
5957: %lt = &Apache::lonlocal::texthash (
5958: disabled => 'No viewable classlist',
5959: section => "Classlist of viewer's section",
5960: all => 'Classlist of all students',
5961: );
5962: }
5963:
1.1 raeburn 5964: my %items = (
5965: 'default_enrollment_start_date' => {
1.3 raeburn 5966: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 5967: input => 'dates',
5968: },
5969: 'default_enrollment_end_date' => {
1.3 raeburn 5970: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 5971: input => 'dates',
5972: },
1.55 raeburn 5973: 'defaultcredits' => {
5974: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
5975: },
1.124 raeburn 5976:
1.1 raeburn 5977: 'nothideprivileged' => {
1.3 raeburn 5978: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 5979: input => 'checkbox',
5980: },
5981:
1.56 raeburn 5982: 'checkforpriv' => {
5983: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
5984: input => 'selectbox',
5985: },
5986:
1.1 raeburn 5987: 'student_classlist_view' => {
1.3 raeburn 5988: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 5989: input => 'selectbox',
1.9 raeburn 5990: options => \%lt,
1.1 raeburn 5991: order => ['disabled','all','section'],
5992: },
1.26 raeburn 5993: 'student_classlist_opt_in' => {
5994: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 5995: input => 'radio',
5996: },
5997:
5998: 'student_classlist_portfiles' => {
1.3 raeburn 5999: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 6000: input => 'radio',
6001: },
6002: );
6003: unless (($settings->{'student_classlist_view'} eq 'all') ||
6004: ($settings->{'student_classlist_view'} eq 'section')) {
6005: $settings->{'student_classlist_view'} = 'disabled';
6006: }
1.80 raeburn 6007: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6008: }
6009:
6010: sub print_appearance {
1.80 raeburn 6011: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6012: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6013: return;
6014: }
1.9 raeburn 6015: my $mathdef;
6016: if ($crstype eq 'Community') {
6017: $mathdef = &mt("None specified - use member's choice");
6018: } else {
6019: $mathdef = &mt("None specified - use student's choice");
6020: }
1.1 raeburn 6021: my %items = (
6022: 'default_xml_style' => {
1.3 raeburn 6023: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6024: '<a href="javascript:openbrowser'.
6025: "('display','default_xml_style'".
6026: ",'sty')".'">'.&mt('Select Style File').'</a>',
6027: input => 'textbox',
6028: size => 35,
6029: },
6030:
6031: 'pageseparators' => {
1.3 raeburn 6032: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6033: input => 'radio',
6034: },
6035: 'disable_receipt_display' => {
1.3 raeburn 6036: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6037: input => 'radio',
6038: },
6039: 'texengine' => {
1.3 raeburn 6040: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6041: input => 'selectbox',
6042: options => {
1.61 raeburn 6043: MathJax => 'MathJax',
1.1 raeburn 6044: mimetex => &mt('Convert to Images'),
6045: tth => &mt('TeX to HTML'),
6046: },
1.75 raeburn 6047: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6048: nullval => $mathdef,
1.1 raeburn 6049: },
6050: 'tthoptions' => {
1.3 raeburn 6051: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6052: input => 'textbox',
6053: size => 40,
6054: },
1.69 raeburn 6055: 'uselcmath' => {
6056: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6057: input => 'radio',
6058: },
6059: 'usejsme' => {
6060: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6061: input => 'radio',
6062: },
1.95 raeburn 6063: 'inline_chem' => {
6064: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6065: input => 'radio',
6066: },
1.114 raeburn 6067: 'extresource' => {
6068: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6069: input => 'selectbox',
6070: options => {
6071: iframe => 'In iframe',
6072: tab => 'In new tab',
6073: window => 'In pop-up window',
6074: },
6075: order => ['iframe','tab','window'],
6076: },
1.1 raeburn 6077: );
1.80 raeburn 6078: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6079: }
6080:
6081: sub print_grading {
1.80 raeburn 6082: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6083: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6084: return;
6085: }
6086: my %items = (
6087: 'grading' => {
1.3 raeburn 6088: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6089: &Apache::loncommon::help_open_topic('GradingOptions'),
6090: input => 'selectbox',
6091: options => {
6092: standard => &mt('Standard: shows points'),
1.34 www 6093: categories => &mt('Categories: shows points according to categories'),
1.11 www 6094: external => &mt('External: shows number of completed parts and totals'),
6095: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6096: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6097: },
1.34 www 6098: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6099: },
6100: 'rndseed' => {
1.3 raeburn 6101: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 6102: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 6103: &mt('Modifying this will make problems have different numbers and answers!').
6104: '</span>',
6105: input => 'selectbox',
6106: options => {
6107: '32bit' => '32bit',
6108: '64bit' => '64bit',
6109: '64bit2' => '64bit2',
6110: '64bit3' => '64bit3',
6111: '64bit4' => '64bit4',
6112: '64bit5' => '64bit5',
6113: },
6114: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6115: advanced => 1
1.1 raeburn 6116: },
6117: 'receiptalg' => {
1.3 raeburn 6118: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6119: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6120: input => 'selectbox',
6121: options => {
6122: receipt => 'receipt',
6123: receipt2 => 'receipt2',
6124: receipt3 => 'receipt3',
6125: },
6126: order => ['receipt','receipt2','receipt3'],
1.41 www 6127: advanced => 1
1.1 raeburn 6128: },
6129: 'disablesigfigs' => {
1.3 raeburn 6130: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6131: input => 'radio',
6132: },
6133: );
1.80 raeburn 6134: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
1.1 raeburn 6135: }
6136:
6137: sub print_printouts {
1.80 raeburn 6138: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6139: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6140: return;
6141: }
6142: my %items = (
6143: problem_stream_switch => {
1.3 raeburn 6144: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6145: input => 'radio',
6146: },
6147: suppress_tries => {
1.3 raeburn 6148: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6149: input => 'radio',
6150: },
6151: default_paper_size => {
1.3 raeburn 6152: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6153: input => 'selectbox',
6154: options => {
6155: Letter => &mt('Letter').' [8 1/2x11 in]',
6156: Legal => &mt('Legal').' [8 1/2x14 in]',
6157: Tabloid => &mt('Tabloid').' [11x17 in]',
6158: Executive => &mt('Executive').' [7 1/2x10 in]',
6159: A2 => &mt('A2').' [420x594 mm]',
6160: A3 => &mt('A3').' [297x420 mm]',
6161: A4 => &mt('A4').' [210x297 mm]',
6162: A5 => &mt('A5').' [148x210 mm]',
6163: A6 => &mt('A6').' [105x148 mm]',
6164: },
6165: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6166: nullval => &mt('None specified'),
1.1 raeburn 6167: },
6168: print_header_format => {
1.3 raeburn 6169: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6170: input => 'checkbox',
6171: },
6172: disableexampointprint => {
1.3 raeburn 6173: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6174: input => 'radio',
6175: },
1.14 raeburn 6176: canuse_pdfforms => {
6177: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6178: input => 'selectbox',
6179: options => {
6180: 1 => &mt('Yes'),
6181: 0 => &mt('No'),
6182: },
6183: order => ['1','0'],
1.54 bisitz 6184: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6185: }
1.1 raeburn 6186: );
1.80 raeburn 6187: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6188: }
6189:
6190: sub print_spreadsheet {
1.80 raeburn 6191: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6192: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6193: return;
6194: }
6195: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6196: my %items = (
6197: spreadsheet_default_classcalc => {
1.3 raeburn 6198: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6199: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6200: "('display','spreadsheet_default_classcalc'".
6201: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6202: input => 'textbox',
6203: },
6204: spreadsheet_default_studentcalc => {
1.3 raeburn 6205: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6206: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6207: "('display','spreadsheet_default_calc'".
6208: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6209: input => 'textbox',
6210: },
6211: spreadsheet_default_assesscalc => {
1.3 raeburn 6212: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6213: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6214: "('display','spreadsheet_default_assesscalc'".
6215: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6216: input => 'textbox',
6217: },
6218: hideemptyrows => {
1.3 raeburn 6219: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6220: input => 'radio',
6221: },
6222: );
1.80 raeburn 6223: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6224: }
1.1 raeburn 6225:
6226: sub print_bridgetasks {
1.80 raeburn 6227: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6228: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6229: return;
6230: }
1.9 raeburn 6231: my ($stumsg,$msgnote);
6232: if ($crstype eq 'Community') {
6233: $stumsg = &mt('Send message to member');
6234: $msgnote = &mt('Message to member and add to user notes');
6235: } else {
6236: $stumsg = &mt('Send message to student');
6237: $msgnote = &mt('Message to student and add to user notes');
6238: }
1.1 raeburn 6239: my %items = (
6240: task_messages => {
1.3 raeburn 6241: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6242: input => 'selectbox',
6243: options => {
1.9 raeburn 6244: only_student => $stumsg,
6245: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6246: },
6247: order => ['only_student','student_and_user_notes_screen'],
6248: nullval => &mt('No message or record in user notes'),
6249: },
6250: task_grading => {
1.3 raeburn 6251: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6252: input => 'selectbox',
6253: options => {
6254: any => &mt('Grade BTs in any section'),
6255: section => &mt('Grade BTs only in own section')
6256: },
6257: order => ['any','section'],
6258: },
6259: suppress_embed_prompt => {
1.3 raeburn 6260: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6261: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6262: input => 'radio',
6263: },
6264: );
1.80 raeburn 6265: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6266: }
6267:
1.118 raeburn 6268: sub print_ltitools {
6269: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6270: my ($datatable,$disabled,$css_class,$dest);
1.121 raeburn 6271: if ($noedit) {
6272: $disabled = ' disabled="disabled"';
6273: }
1.120 raeburn 6274: my $itemcount = 1;
6275: unless ($context eq 'domain') {
6276: my %tooltypes = &Apache::loncommon::usable_exttools();
6277: unless ($tooltypes{'crs'}) {
6278: my $showtype = 'course';
6279: if ($crstype eq 'Community') {
6280: $showtype = lc($crstype);
6281: }
6282: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6283: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6284: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6285: if ($tooltypes{'dom'}) {
6286: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6287: '<i>'.$cdom.'</i>').
6288: '<br /><br />'.
6289: &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.");
6290: } else {
6291: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6292: '<br /><br />'.
6293: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6294: '<i>'.$cdom.'</i>');
6295:
6296: }
6297: $datatable .= '</tr>';
6298: $itemcount ++;
6299: return $datatable;
6300: }
6301: }
1.118 raeburn 6302: my %lt = <itools_names();
6303: my $maxnum = 0;
6304: my %ordered;
6305: if (ref($settings) eq 'HASH') {
6306: foreach my $item (keys(%{$settings})) {
6307: if (ref($settings->{$item}) eq 'HASH') {
6308: my $num = $settings->{$item}{'order'};
6309: $ordered{$num} = $item;
6310: }
6311: }
6312: }
6313:
6314: if ($context eq 'domain') {
6315: $dest = '/adm/domainprefs';
6316: } else {
6317: $dest = '/adm/courseprefs';
6318: }
6319: my ($switchserver,$switchmessage);
6320: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6321: if ($switchserver) {
6322: if ($context eq 'domain') {
6323: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6324: } elsif ($crstype eq 'Community') {
6325: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6326: } else {
6327: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6328: }
6329: }
6330: my $maxnum = scalar(keys(%ordered));
6331: my @courseroles = ('cc','in','ta','ep','st');
6332: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6333: my @fields = ('fullname','firstname','lastname','email','roles','user');
6334: if (keys(%ordered)) {
6335: my @items = sort { $a <=> $b } keys(%ordered);
6336: for (my $i=0; $i<@items; $i++) {
6337: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6338: my $item = $ordered{$items[$i]};
6339: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6340: if (ref($settings->{$item}) eq 'HASH') {
6341: $title = $settings->{$item}->{'title'};
6342: $url = $settings->{$item}->{'url'};
6343: $key = $settings->{$item}->{'key'};
6344: $usable = $settings->{$item}->{'usable'};
6345: $lifetime = $settings->{$item}->{'lifetime'};
6346: my $image = $settings->{$item}->{'image'};
6347: if ($image ne '') {
6348: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6349: }
6350: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6351: $sigsel{'HMAC-256'} = ' selected="selected"';
6352: } else {
6353: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6354: }
6355: }
6356: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6357: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6358: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6359: for (my $k=0; $k<=$maxnum; $k++) {
6360: my $vpos = $k+1;
6361: my $selstr;
6362: if ($k == $i) {
6363: $selstr = ' selected="selected" ';
6364: }
6365: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6366: }
6367: $datatable .= '</select>'.(' 'x2).
6368: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6369: &mt('Delete?').'</label></span></td>'.
6370: '<td colspan="2">'.
6371: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6372: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6373: (' 'x2).
6374: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6375: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6376: (' 'x2).
6377: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6378: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6379: (' 'x2).
6380: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6381: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6382: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6383: '<br /><br />'.
1.120 raeburn 6384: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6385: ' value="'.$url.'" /></span>'.
6386: (' 'x2).
6387: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6388: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6389: if ($key ne '') {
6390: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6391: if ($noedit) {
6392: $datatable .= ': ['.&mt('not shown').']';
6393: } elsif ($switchserver) {
6394: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6395: } else {
6396: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6397: }
6398: $datatable .= '</span> '.(' 'x2);
6399: } elsif (!$switchserver) {
6400: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6401: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6402: '</span> '.(' 'x2);
6403: }
6404: if ($switchserver) {
6405: if ($usable ne '') {
6406: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6407: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6408: '<span class="LC_nobreak">'.&mt('Change secret?').
6409: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6410: (' 'x2).
6411: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6412: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6413: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6414: '</div>';
6415: } elsif ($key eq '') {
6416: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6417: } else {
6418: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6419: }
6420: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6421: } else {
6422: if ($usable ne '') {
6423: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6424: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6425: '<span class="LC_nobreak">'.&mt('Change?').
6426: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6427: (' 'x2).
6428: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6429: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6430: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6431: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6432: '<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>'.
6433: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6434: } else {
6435: $datatable .=
6436: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6437: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6438: '<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>'.
6439: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6440: }
6441: }
6442: $datatable .= '</fieldset>'.
6443: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6444: '<span class="LC_nobreak">'.&mt('Display target:');
6445: my %currdisp;
6446: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6447: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6448: $currdisp{'window'} = ' checked="checked"';
6449: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6450: $currdisp{'tab'} = ' checked="checked"';
6451: } else {
6452: $currdisp{'iframe'} = ' checked="checked"';
6453: }
6454: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6455: $currdisp{'width'} = $1;
6456: }
6457: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6458: $currdisp{'height'} = $1;
6459: }
6460: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6461: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6462: } else {
6463: $currdisp{'iframe'} = ' checked="checked"';
6464: }
6465: foreach my $disp ('iframe','tab','window') {
6466: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6467: $lt{$disp}.'</label>'.(' 'x2);
6468: }
6469: $datatable .= (' 'x4);
6470: foreach my $dimen ('width','height') {
6471: $datatable .= '<label>'.$lt{$dimen}.' '.
6472: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6473: (' 'x2);
6474: }
6475: $datatable .= '</span><br />'.
6476: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6477: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6478: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6479: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6480: '</textarea></div><div style=""></div><br />';
6481: my %units = (
6482: 'passback' => 'days',
6483: 'roster' => 'seconds',
6484: );
6485: foreach my $extra ('passback','roster') {
6486: my $validsty = 'none';
6487: my $currvalid;
6488: my $checkedon = '';
6489: my $checkedoff = ' checked="checked"';
6490: if ($settings->{$item}->{$extra}) {
6491: $checkedon = $checkedoff;
6492: $checkedoff = '';
6493: $validsty = 'inline-block';
6494: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6495: $currvalid = $settings->{$item}->{$extra.'valid'};
6496: }
6497: }
6498: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6499: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6500: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6501: &mt('No').'</label>'.(' 'x2).
6502: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6503: &mt('Yes').'</label></span></div>'.
6504: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6505: '<span class="LC_nobreak">'.
6506: &mt("until at least [_1] $units{$extra} after launch",
6507: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6508: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6509: }
6510: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6511: if ($imgsrc) {
6512: $datatable .= $imgsrc.
6513: '<label><input type="checkbox" name="ltitools_image_del"'.
6514: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6515: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6516: } else {
6517: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6518: }
6519: if ($switchserver) {
6520: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6521: } else {
6522: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6523: }
6524: $datatable .= '</span></fieldset>';
6525: my (%checkedfields,%rolemaps,$userincdom);
6526: if (ref($settings->{$item}) eq 'HASH') {
6527: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6528: %checkedfields = %{$settings->{$item}->{'fields'}};
6529: }
6530: $userincdom = $settings->{$item}->{'incdom'};
6531: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6532: %rolemaps = %{$settings->{$item}->{'roles'}};
6533: $checkedfields{'roles'} = 1;
6534: }
6535: }
6536: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6537: '<span class="LC_nobreak">';
6538: my $userfieldstyle = 'display:none;';
6539: my $seluserdom = '';
6540: my $unseluserdom = ' selected="selected"';
6541: foreach my $field (@fields) {
6542: my ($checked,$onclick,$id,$spacer);
6543: if ($checkedfields{$field}) {
6544: $checked = ' checked="checked"';
6545: }
6546: if ($field eq 'user') {
6547: $id = ' id="ltitools_user_field_'.$i.'"';
6548: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6549: if ($checked) {
6550: $userfieldstyle = 'display:inline-block';
6551: if ($userincdom) {
6552: $seluserdom = $unseluserdom;
6553: $unseluserdom = '';
6554: }
6555: }
6556: } else {
6557: $spacer = (' ' x2);
6558: }
6559: $datatable .= '<label>'.
6560: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6561: $lt{$field}.'</label>'.$spacer;
6562: }
6563: $datatable .= '</span>';
6564: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6565: '<span class="LC_nobreak"> : '.
6566: '<select name="ltitools_userincdom_'.$i.'">'.
6567: '<option value="">'.&mt('Select').'</option>'.
6568: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6569: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6570: '</select></span></div>';
6571: $datatable .= '</fieldset>'.
6572: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6573: foreach my $role (@courseroles) {
6574: my ($selected,$selectnone);
6575: if (!$rolemaps{$role}) {
6576: $selectnone = ' selected="selected"';
6577: }
6578: $datatable .= '<td style="text-align: center">'.
6579: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6580: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6581: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6582: foreach my $ltirole (@ltiroles) {
6583: unless ($selectnone) {
6584: if ($rolemaps{$role} eq $ltirole) {
6585: $selected = ' selected="selected"';
6586: } else {
6587: $selected = '';
6588: }
6589: }
6590: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6591: }
6592: $datatable .= '</select></td>';
6593: }
6594: $datatable .= '</tr></table></fieldset>';
6595: my %courseconfig;
6596: if (ref($settings->{$item}) eq 'HASH') {
6597: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6598: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6599: }
6600: }
6601: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6602: foreach my $item ('label','title','target','linktext','explanation','append') {
6603: my $checked;
6604: if ($courseconfig{$item}) {
6605: $checked = ' checked="checked"';
6606: }
6607: $datatable .= '<label>'.
6608: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6609: $lt{'crs'.$item}.'</label> '."\n";
6610: }
6611: $datatable .= '</span></fieldset>'.
6612: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6613: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6614: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6615: my %custom = %{$settings->{$item}->{'custom'}};
6616: if (keys(%custom) > 0) {
6617: foreach my $key (sort(keys(%custom))) {
6618: $datatable .= '<tr><td><span class="LC_nobreak">'.
6619: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6620: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6621: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6622: ' value="'.$custom{$key}.'" /></td></tr>';
6623: }
6624: }
6625: }
6626: $datatable .= '<tr><td><span class="LC_nobreak">'.
6627: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6628: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6629: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6630: $datatable .= '</table></fieldset></td></tr>'."\n";
6631: $itemcount ++;
6632: }
6633: }
6634: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6635: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6636: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6637: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6638: '<select name="ltitools_add_pos"'.$chgstr.'>';
6639: for (my $k=0; $k<$maxnum+1; $k++) {
6640: my $vpos = $k+1;
6641: my $selstr;
6642: if ($k == $maxnum) {
6643: $selstr = ' selected="selected" ';
6644: }
6645: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6646: }
6647: $datatable .= '</select> '."\n".
6648: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6649: '<td colspan="2">'.
6650: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6651: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6652: (' 'x2).
6653: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6654: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6655: (' 'x2).
6656: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6657: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6658: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6659: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6660: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6661: '<br />'.
1.120 raeburn 6662: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6663: (' 'x2).
6664: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6665: if ($switchserver) {
6666: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6667: } else {
6668: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6669: (' 'x2).
1.119 raeburn 6670: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6671: '<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 6672: }
6673: $datatable .= '<br /><br />'.
6674: '</fieldset>'.
6675: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6676: '<span class="LC_nobreak">'.&mt('Display target:');
6677: my %defaultdisp;
6678: $defaultdisp{'iframe'} = ' checked="checked"';
6679: foreach my $disp ('iframe','tab','window') {
6680: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6681: $lt{$disp}.'</label>'.(' 'x2);
6682: }
6683: $datatable .= (' 'x4);
6684: foreach my $dimen ('width','height') {
6685: $datatable .= '<label>'.$lt{$dimen}.' '.
6686: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6687: (' 'x2);
6688: }
6689: $datatable .= '</span><br />'.
6690: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6691: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6692: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6693: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6694: '</div><div style=""></div><br />';
6695: my %units = (
6696: 'passback' => 'days',
6697: 'roster' => 'seconds',
6698: );
6699: my %defaulttimes = (
6700: 'passback' => '7',
6701: 'roster' => '300',
6702: );
6703: foreach my $extra ('passback','roster') {
6704: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6705: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6706: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6707: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6708: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6709: &mt('Yes').'</label></span></div>'.
6710: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6711: '<span class="LC_nobreak">'.
6712: &mt("until at least [_1] $units{$extra} after launch",
6713: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6714: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6715: }
6716: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6717: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6718: if ($switchserver) {
6719: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6720: } else {
6721: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6722: }
6723: $datatable .= '</span></fieldset>'.
6724: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6725: '<span class="LC_nobreak">';
6726: foreach my $field (@fields) {
6727: my ($id,$onclick,$spacer);
6728: if ($field eq 'user') {
6729: $id = ' id="ltitools_user_field_add"';
6730: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6731: } else {
6732: $spacer = (' ' x2);
6733: }
6734: $datatable .= '<label>'.
6735: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6736: $lt{$field}.'</label>'.$spacer;
6737: }
6738: $datatable .= '</span>'.
6739: '<div style="display:none;" id="ltitools_user_div_add">'.
6740: '<span class="LC_nobreak"> : '.
6741: '<select name="ltitools_add_userincdom">'.
6742: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6743: '<option value="0">'.&mt('username').'</option>'.
6744: '<option value="1">'.&mt('username:domain').'</option>'.
6745: '</select></span></div></fieldset>';
6746: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6747: foreach my $role (@courseroles) {
6748: my ($checked,$checkednone);
6749: $datatable .= '<td style="text-align: center">'.
6750: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6751: '<select name="ltitools_add_roles_'.$role.'">'.
6752: '<option value="" selected="selected">'.&mt('Select').'</option>';
6753: foreach my $ltirole (@ltiroles) {
6754: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6755: }
6756: $datatable .= '</select></td>';
6757: }
6758: $datatable .= '</tr></table></fieldset>'.
6759: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6760: foreach my $item ('label','title','target','linktext','explanation','append') {
6761: $datatable .= '<label>'.
6762: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6763: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6764: }
6765: $datatable .= '</span></fieldset>'.
6766: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6767: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6768: '<tr><td><span class="LC_nobreak">'.
6769: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6770: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6771: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6772: '</table></fieldset>'."\n".
6773: '</td>'."\n".
6774: '</tr>'."\n";
6775: $itemcount ++;
6776: return $datatable;
6777: }
6778:
6779: sub ltitools_names {
6780: my %lt = &Apache::lonlocal::texthash(
6781: 'title' => 'Title',
6782: 'version' => 'Version',
6783: 'msgtype' => 'Message Type',
6784: 'sigmethod' => 'Signature Method',
6785: 'url' => 'URL',
6786: 'key' => 'Key',
6787: 'lifetime' => 'Nonce lifetime (s)',
6788: 'secret' => 'Secret',
6789: 'icon' => 'Icon',
6790: 'user' => 'User',
6791: 'fullname' => 'Full Name',
6792: 'firstname' => 'First Name',
6793: 'lastname' => 'Last Name',
6794: 'email' => 'E-mail',
6795: 'roles' => 'Role',
6796: 'window' => 'Window',
6797: 'tab' => 'Tab',
6798: 'iframe' => 'iFrame',
6799: 'height' => 'Height',
6800: 'width' => 'Width',
6801: 'linktext' => 'Default Link Text',
6802: 'explanation' => 'Default Explanation',
6803: 'passback' => 'Tool can return grades:',
6804: 'roster' => 'Tool can retrieve roster:',
6805: 'crstarget' => 'Display target',
6806: 'crslabel' => 'Course label',
6807: 'crstitle' => 'Course title',
6808: 'crslinktext' => 'Link Text',
6809: 'crsexplanation' => 'Explanation',
6810: 'crsappend' => 'Provider URL',
6811: );
6812: return %lt;
6813: }
6814:
1.87 raeburn 6815: sub print_lti {
6816: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6817: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6818: return;
6819: }
6820: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6821: my %menutitles = <imenu_titles();
6822: my ($domdefs,$displaydefs);
6823: if ($env{'request.lti.login'}) {
6824: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6825: my @domdefsmenu;
6826: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6827: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6828: $domdefs = &mt('Header shown').', ';
6829: }
6830: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6831: $domdefs .= &mt('Inline menu shown');
6832: }
6833: $domdefs =~ s/,\s$//;
6834: if (!$domdefs) {
6835: $domdefs = &mt('No header or inline menu shown');
6836: }
6837: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
6838: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6839: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6840: }
6841: }
6842: $displaydefs = &mt('Domain defaults');
6843: if (@domdefsmenu) {
6844: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
6845: if (@diffs) {
6846: my $missing;
6847: foreach my $item (@menuitems) {
6848: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
6849: $missing .= ' '.$menutitles{$item}.',';
6850: }
6851: }
6852: $missing =~ s/,$//;
6853: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
6854: } else {
6855: $displaydefs .= ': '.&mt('All shown');
6856: }
6857: } else {
6858: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
6859: }
6860: } else {
6861: $displaydefs = &mt('Domain defaults only available in LTI context');
6862: }
6863: my %items = (
6864: 'lti.override' => {
6865: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
6866: input => 'radio',
6867: },
6868: 'lti.topmenu' => {
6869: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
6870: input => 'radio',
6871: },
6872: 'lti.inlinemenu' => {
6873: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
6874: input => 'radio',
6875: },
6876: 'lti.lcmenu' => {
6877: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
6878: input => 'custom',
6879: },
6880: );
6881: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
6882: }
6883:
6884: sub lcmenu_checkboxes {
6885: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
6886: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6887: my %menutitles = <imenu_titles();
6888: my (@current,@domdefs);
6889: if ($env{'request.lti.login'}) {
6890: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6891: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6892: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6893: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6894: }
6895: }
6896: }
6897: if (ref($settings) eq 'HASH') {
6898: if ($settings->{'lti.lcmenu'}) {
6899: unless ($settings->{'lti.lcmenu'} eq 'none') {
6900: @current = split(',',$settings->{'lti.lcmenu'});
6901: }
6902: } else {
6903: @current = @domdefs;
6904: }
6905: } else {
6906: @current = @domdefs;
6907: }
6908: my $numinrow = 3;
6909: my $count = 0;
6910: my $disabled;
6911: if ($noedit) {
6912: $disabled = ' disabled="disabled"';
6913: }
6914: my $output = '<table>';
6915: foreach my $item (@menuitems) {
6916: my $checked = '';
6917: if (grep(/^\Q$item\E$/,@current)) {
6918: $checked = ' checked="checked" ';
6919: }
6920: my $rem = $count%($numinrow);
6921: if ($rem == 0) {
6922: if ($count > 0) {
6923: $output .= '</tr>';
6924: }
6925: $output .= '<tr>';
6926: }
6927: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
6928: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
6929: $menutitles{$item}.'</label></span></td>';
6930: $count ++;
6931: }
6932: my $rem = $count%($numinrow);
6933: my $colsleft = $numinrow - $rem;
6934: if ($colsleft > 1 ) {
6935: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6936: ' </td>';
6937: } elsif ($colsleft == 1) {
6938: $output .= '<td class="LC_left_item"> </td>';
6939: }
6940: $output .= '</tr></table>';
6941: }
6942:
6943: sub ltimenu_titles {
6944: return &Apache::lonlocal::texthash(
6945: fullname => 'Full name',
6946: coursetitle => 'Course title',
6947: role => 'Role',
6948: logout => 'Logout',
6949: grades => 'Grades',
6950: );
6951: }
6952:
1.91 raeburn 6953: sub print_menuitems {
6954: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6955: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
6956: return;
6957: }
6958: if ($position eq 'top') {
6959: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
6960: if ($settings->{'menucollections'} ne '') {
6961: foreach my $item (split(/;/,$settings->{'menucollections'})) {
6962: my ($num,$value) = split(/\%/,$item);
6963: if ($num =~ /^\d+$/) {
6964: $defaultmenu_options{$num} = $num;
6965: }
6966: }
6967: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
6968: $addcollection = $defaultmenu_order[-1] + 1;
6969: } else {
6970: $addcollection = 1;
6971: }
6972: $defaultmenu_options{$addcollection} = $addcollection;
6973: my %items = (
6974: 'menudefault' => {
6975: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
6976: &mt("(can be overriden in deep-link context)"),
6977: input => 'selectbox',
6978: options => \%defaultmenu_options,
6979: order => \@defaultmenu_order,
6980: nullval => &mt('Standard (all menus shown)'),
6981: },
6982: );
6983: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
6984: } else {
6985: my %menu;
6986: my $count = 0;
6987: my $next = 1;
6988: my ($datatable,$disabled);
6989: if ($noedit) {
6990: $disabled = ' disabled="disabled"';
6991: }
6992:
6993: my ($ordered,$cats) = &menuitems_categories();
6994: my @order = @{$ordered};
6995: my %categories = %{$cats};
6996: my %menutitles = &menuitems_titles();
6997: my %menufields = &menuitems_fields();
6998:
6999: if ($settings->{'menucollections'} ne '') {
7000: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7001: my ($num,$value) = split(/\%/,$item);
7002: if ($num =~ /^\d+$/) {
7003: my @entries = split(/\&/,$value);
7004: foreach my $entry (@entries) {
7005: my ($name,$fields) = split(/=/,$entry);
7006: $menu{$num}{$name} = $fields;
7007: }
7008: }
7009: }
7010: if (keys(%menu)) {
7011: my @current = sort { $a <=> $b } keys(%menu);
7012: $next += $current[-1];
7013: foreach my $num (@current) {
7014: my %checked;
7015: my $on = ' checked="checked"';
7016: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7017: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7018: if ($menu{$num}{$key} eq 'y') {
7019: $checked{$key} = $on;
7020: }
7021: } else {
7022: foreach my $field (split(/,/,$menu{$num}{$key})) {
7023: if (exists($menufields{$field})) {
7024: $checked{$field} = $on;
7025: }
7026: }
7027: }
7028: }
7029: if (ref($menu{$num}) eq 'HASH') {
7030: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7031: foreach my $category (@order) {
7032: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7033: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7034: if ($category eq 'text') {
7035: $datatable .= '<i>'.&mt('Header').'</i><br />';
7036: }
1.91 raeburn 7037: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7038: if ($field eq 'disc') {
7039: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7040: }
1.91 raeburn 7041: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7042: $menufields{$field}.'</label><br />';
7043: }
7044: $datatable .= '</fieldset>';
7045: }
7046: }
7047: $datatable .= &item_table_row_end();
7048: $count ++;
7049: }
7050: }
7051: }
7052: } elsif ($noedit) {
7053: my $text = &mt('No menu collections defined for this course.');
7054: $datatable .= &item_table_row_start($text,$count);
7055: }
7056: unless ($noedit) {
7057: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7058: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7059: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7060: foreach my $category (@order) {
7061: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7062: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7063: foreach my $field (@{$categories{$category}}) {
7064: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7065: $menufields{$field}.'</label><br />';
7066: }
7067: $datatable .= '</fieldset>';
7068: }
7069: }
7070: $datatable .= &item_table_row_end();
7071: $count ++;
7072: }
7073: return $datatable;
7074: }
7075: }
7076:
7077: sub menuitems_abbreviations {
7078: my %briefcats = (
7079: text => 'pt',
7080: links => 'p',
7081: list => 'ps',
7082: inline => 's',
7083: );
7084: return %briefcats;
7085: }
7086:
7087: sub menuitems_categories {
7088: my @order = ('shown','text','links','list','inline');
7089: my %categories = (
1.94 raeburn 7090: shown => ['top','inline','foot','main'],
7091: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7092: links => ['pers','logo','menu','comm','roles','help','logout'],
1.91 raeburn 7093: list => ['about','prefs','port','wish','anno','rss'],
7094: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7095: );
7096: return (\@order,\%categories);
7097: }
7098:
7099: sub menuitems_titles {
7100: return &Apache::lonlocal::texthash (
7101: shown => 'Hierarchy',
1.94 raeburn 7102: text => 'Text',
1.91 raeburn 7103: links => 'Header links',
7104: list => 'Drop-down list',
7105: inline => 'Inline links',
7106: );
7107: }
7108:
7109: sub menuitems_fields {
7110: return &Apache::lonlocal::texthash (
7111: top => 'Display header',
7112: inline => 'Display inline menu',
1.94 raeburn 7113: foot => 'Display footer',
1.91 raeburn 7114: main => 'Access to main menu',
1.92 raeburn 7115: pers => 'Personal',
7116: logo => 'LON-CAPA',
1.91 raeburn 7117: menu => 'Home',
7118: comm => 'Messages',
7119: roles => 'Roles/Courses',
7120: help => 'Help',
7121: logout => 'Logout',
7122: name => 'Fullname',
7123: crs => 'Course Title',
7124: role => 'Current Role',
1.94 raeburn 7125: disc => 'Discussion',
7126: fdbk => 'Feedback',
1.91 raeburn 7127: about => 'Information',
7128: prefs => 'Preferences',
7129: port => 'Portfolio',
7130: wish => 'Stored Links',
7131: anno => 'Calendar',
7132: rss => 'RSS Feeds',
7133: cont => 'Contents',
7134: grades => 'Grades',
7135: chat => 'Chat',
7136: people => 'People',
7137: groups => 'Groups',
7138: resv => 'Reservations',
7139: syll => 'Syllabus',
7140: feeds => 'Feeds',
7141: );
7142: }
7143:
7144: sub menucollections_display {
7145: my ($collections) = @_;
7146: my %menu;
7147: my ($ordered,$cats) = &menuitems_categories();
7148: my @order = @{$ordered};
7149: my %categories = %{$cats};
7150: my %menutitles = &menuitems_titles();
7151: my %menufields = &menuitems_fields();
7152: foreach my $item (split(/;/,$collections)) {
7153: my ($num,$value) = split(/\%/,$item);
7154: if ($num =~ /^\d+$/) {
7155: my @entries = split(/\&/,$value);
7156: foreach my $entry (@entries) {
7157: my ($name,$fields) = split(/=/,$entry);
7158: $menu{$num}{$name} = $fields;
7159: }
7160: }
7161: }
7162: my $output = '';
7163: if (keys(%menu)) {
7164: my @current = sort { $a <=> $b } keys(%menu);
7165: foreach my $num (@current) {
7166: my %checked;
7167: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7168: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7169: if ($menu{$num}{$key} eq 'y') {
7170: $checked{$key} = 1;
7171: }
7172: } else {
7173: foreach my $field (split(/,/,$menu{$num}{$key})) {
7174: if (exists($menufields{$field})) {
7175: $checked{$field} = 1;
7176: }
7177: }
7178: }
7179: }
7180: if (ref($menu{$num}) eq 'HASH') {
7181: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7182: foreach my $category (@order) {
7183: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7184: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7185: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7186: if ($category eq 'text') {
7187: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
1.124 raeburn 7188: }
1.91 raeburn 7189: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7190: if ($field eq 'disc') {
7191: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7192: }
1.91 raeburn 7193: if ($checked{$field}) {
7194: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7195: } else {
7196: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7197: }
7198: $output .= '<br />';
7199: }
7200: $output .= '</fieldset>';
7201: }
7202: }
7203: $output .= '</fieldset>';
7204: }
7205: }
7206: }
7207: return $output;
7208: }
7209:
1.93 raeburn 7210: sub print_linkprotection {
1.102 raeburn 7211: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7212:
7213: my %linkprotection;
7214: my $count = 0;
7215: my $next = 1;
1.102 raeburn 7216: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7217: if ($noedit) {
7218: $disabled = ' disabled="disabled"';
7219: }
1.100 raeburn 7220: my %desc = &linkprot_names();
7221: my %lt = &Apache::lonlocal::texthash (
7222: 'requ' => 'Required settings',
7223: 'opti' => 'Optional settings',
7224: );
1.93 raeburn 7225: my $itemcount = 0;
7226:
1.100 raeburn 7227: my $ltiauth;
1.102 raeburn 7228: if ($context eq 'domain') {
7229: $ltiauth = 1;
7230: } else {
7231: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7232: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7233: } else {
7234: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7235: $ltiauth = $domdefs{'crsltiauth'};
7236: }
7237: }
7238: if ($context eq 'domain') {
7239: $dest = '/adm/domainprefs';
1.100 raeburn 7240: } else {
1.102 raeburn 7241: $dest = '/adm/courseprefs';
7242: }
1.124 raeburn 7243:
1.102 raeburn 7244: my ($switchserver,$switchmessage);
7245: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7246: if ($switchserver) {
7247: if ($context eq 'domain') {
1.124 raeburn 7248: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.102 raeburn 7249: } elsif ($crstype eq 'Community') {
7250: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7251: } else {
7252: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7253: }
1.100 raeburn 7254: }
1.99 raeburn 7255:
1.105 raeburn 7256: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7257: if (keys(%{$settings->{'linkprot'}})) {
7258: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7259: $next += $current[-1];
7260: for (my $i=0; $i<@current; $i++) {
7261: my $num = $current[$i];
7262: my %values;
1.102 raeburn 7263: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7264: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7265: } else {
7266: next;
7267: }
7268: my $selected;
7269: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7270: $selected = ' selected="selected"';
7271: }
7272: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7273: $datatable .=
7274: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7275: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7276: &mt('Delete?').'</label></span></td><td>';
1.122 raeburn 7277: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7278: $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
7279: $passbacksty = 'none';
7280: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
7281: %checkedpassback = (
7282: 'no' => ' checked="checked"',
7283: 'yes' => '',
1.124 raeburn 7284: );
1.122 raeburn 7285: %checkedpassbackfmt = (
7286: '1p1' => ' checked="checked"',
7287: '1p0' => '',
7288: );
7289: if ($values{'passback'} ne '') {
7290: $passbacksty = 'inline-block';
7291: $checkedpassback{'yes'} = ' checked="checked"';
7292: $checkedpassback{'no'} = '';
7293: if ($values{'passbackformat'} eq '1.0') {
7294: $checkedpassbackfmt{'1p0'} = ' checked="checked"';
7295: $checkedpassbackfmt{'1p1'} = '';
7296: }
7297: }
1.100 raeburn 7298: if ($ltiauth) {
7299: $usersty = 'display:none';
1.112 raeburn 7300: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7301: %checkedrequser = (
7302: no => ' checked="checked"',
7303: yes => '',
7304: );
7305: if ($values{'requser'}) {
7306: $checkedrequser{'yes'} = $checkedrequser{'no'};
7307: $checkedrequser{'no'} = '';
7308: }
7309: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
1.124 raeburn 7310: if ($values{'requser'}) {
1.100 raeburn 7311: $usersty = 'display:inline-block';
7312: }
7313: }
1.112 raeburn 7314: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7315: %checkedreturnurl = (
7316: no => ' checked="checked"',
7317: yes => '',
7318: );
7319: if ($values{'returnurl'} ne '') {
7320: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7321: $checkedreturnurl{'no'} = '';
7322: }
1.100 raeburn 7323: $datatable .=
7324: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7325: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7326: (' 'x2).
1.100 raeburn 7327: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7328: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7329: (' 'x2).
1.100 raeburn 7330: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7331: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7332: if ($values{'key'} ne '') {
1.100 raeburn 7333: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7334: if ($noedit) {
7335: $datatable .= ': ['.&mt('not shown').']';
7336: } elsif ($switchserver) {
7337: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7338: } else {
7339: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7340: }
7341: $datatable .= '</span> '.(' 'x2);
7342: } elsif (!$switchserver) {
1.100 raeburn 7343: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7344: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7345: '</span> '.(' 'x2);
7346: }
7347: if ($switchserver) {
7348: if ($values{'usable'} ne '') {
7349: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7350: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7351: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7352: '<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 7353: (' 'x2).
1.118 raeburn 7354: '<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 7355: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7356: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7357: '</div>';
7358: } elsif ($values{'key'} eq '') {
1.102 raeburn 7359: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7360: } else {
1.102 raeburn 7361: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7362: }
1.111 raeburn 7363: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7364: } else {
7365: if ($values{'usable'} ne '') {
7366: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7367: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7368: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7369: '<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 7370: (' 'x2).
1.118 raeburn 7371: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7372: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7373: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7374: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7375: '<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 7376: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7377: } else {
7378: $datatable .=
1.100 raeburn 7379: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7380: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7381: '<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 7382: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7383: }
7384: }
1.112 raeburn 7385: $datatable .= '<br /><br />'.
1.122 raeburn 7386: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7387: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7388: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7389: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7390: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7391: '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7392: '<span class="LC_nobreak">'.&mt('Grade format').
7393: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7394: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7395: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7396: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7397: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7398: '<br />'.
1.112 raeburn 7399: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7400: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7401: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7402: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7403: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7404: ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7405: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7406: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7407: '</span></div> ';
1.100 raeburn 7408: if ($ltiauth) {
1.112 raeburn 7409: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7410: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7411: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7412: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7413: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7414: '</fieldset>'.
7415: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7416: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7417: '</fieldset>';
7418: }
1.99 raeburn 7419: $datatable .= '</td></tr>';
1.93 raeburn 7420: $itemcount ++;
7421: }
7422: }
7423: }
7424: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7425: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7426: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7427: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7428: '<td width="100%">';
1.122 raeburn 7429: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7430: $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.100 raeburn 7431: if ($ltiauth) {
7432: $usersty = 'display:none';
1.112 raeburn 7433: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7434: %checkedrequser = (
7435: no => ' checked="checked"',
7436: yes => '',
7437: );
7438: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7439: }
1.122 raeburn 7440: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7441: %checkedpassback = (
7442: 'no' => ' checked="checked"',
7443: 'yes' => '',
7444: );
7445: %checkedpassbackfmt = (
7446: '1p1' => ' checked="checked"',
7447: '1p0' => '',
7448: );
1.112 raeburn 7449: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7450: %checkedreturnurl = (
7451: no => ' checked="checked"',
7452: yes => '',
7453: );
1.100 raeburn 7454: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7455: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7456: (' 'x2).
1.100 raeburn 7457: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7458: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7459: (' 'x2).
1.112 raeburn 7460: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7461: '<br /><br />';
1.99 raeburn 7462: if ($switchserver) {
1.102 raeburn 7463: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7464: } else {
1.100 raeburn 7465: $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 7466: (' 'x2).
1.116 raeburn 7467: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7468: '<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 7469: }
1.112 raeburn 7470: $datatable .= '<br /><br />'.
1.122 raeburn 7471: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7472: '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7473: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7474: '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7475: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7476: '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none" />'.
7477: '<span class="LC_nobreak">'.&mt('Grade format').
7478: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7479: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7480: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7481: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7482: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7483: '<br />'.
1.112 raeburn 7484: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7485: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7486: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7487: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7488: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7489: ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7490: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7491: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7492: '</span></div> ';
7493: if ($ltiauth) {
7494: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7495: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7496: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7497: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7498: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7499: '</fieldset>'.
1.100 raeburn 7500: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7501: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7502: '</fieldset>';
7503: }
1.99 raeburn 7504: $datatable .= '</td></tr>';
1.93 raeburn 7505: $$rowtotal ++;
1.101 raeburn 7506: return $datatable;
1.93 raeburn 7507: }
7508:
7509: sub linkprot_names {
1.100 raeburn 7510: return &Apache::lonlocal::texthash(
1.93 raeburn 7511: 'version' => 'LTI Version',
7512: 'key' => 'Key',
7513: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7514: 'name' => 'Launcher Application',
1.93 raeburn 7515: 'secret' => 'Secret',
1.122 raeburn 7516: 'passback' => 'Can return grades to Launcher',
1.112 raeburn 7517: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7518: 'requser' => 'Use identity',
7519: 'email' => 'Email address',
7520: 'sourcedid' => 'User ID',
7521: 'other' => 'Other',
7522: 'auth' => 'Display LON-CAPA login page',
7523: 'reject' => 'Discontinue launch process',
1.93 raeburn 7524: );
7525: }
7526:
1.99 raeburn 7527: sub check_switchserver {
1.102 raeburn 7528: my ($cdom,$cnum,$context,$dest) = @_;
7529: my ($allowed,$switchserver,$home);
7530: if ($context eq 'domain') {
7531: $home = &Apache::lonnet::domain($cdom,'primary');
7532: } else {
7533: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7534: }
7535: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7536: my @ids=&Apache::lonnet::current_machine_ids();
7537: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7538: if (!$allowed) {
7539: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7540: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7541: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7542: }
7543: }
7544: return $switchserver;
7545: }
7546:
1.100 raeburn 7547: sub linkprot_options {
7548: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7549: my %lt;
7550: if (ref($desc) eq 'HASH') {
7551: %lt = %{$desc};
7552: }
7553: my $userfieldsty = 'none';
7554: my (%checked,$userfield);
7555: $checked{'sourcedid'} = ' checked="checked"';
7556: $checked{'reject'} = ' checked="checked"';
7557: if (ref($current) eq 'HASH') {
7558: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7559: $checked{'sourcedid'} = '';
7560: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7561: $checked{'email'} = ' checked="checked"';
7562: } else {
7563: $checked{'other'} = ' checked="checked"';
7564: $userfield = $current->{'mapuser'};
7565: $userfieldsty = 'inline-block';
7566: }
7567: }
7568: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7569: $checked{'reject'} = '';
7570: $checked{'auth'} = ' checked="checked"';
7571: }
7572: }
1.112 raeburn 7573: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7574: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7575: &mt('Source of LON-CAPA username in LTI request').': ';
7576: foreach my $option ('sourcedid','email','other') {
7577: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7578: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7579: ($option eq 'other' ? '' : (' 'x2) );
7580: }
7581: $output .= '</span></div>'.
7582: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7583: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7584: 'value="'.$userfield.'"'.$disabled.' /></div>';
7585: $output .= '<br />'.
7586: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7587: &mt('Action when username is not for an enrolled student').': ';
7588: foreach my $option ('reject','auth') {
7589: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7590: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7591: ($option eq 'auth' ? '' : (' 'x2) );
7592: }
7593: $output .= '</span></div>';
7594: return $output;
7595: }
7596:
1.114 raeburn 7597: sub print_extresource_row {
7598: my ($item,$config,$curr,$noedit) = @_;
7599: my $onchange;
7600: unless ($noedit) {
7601: $onchange = ' onchange="javascript:toggleExtRes();"';
7602: }
7603: my $id = 'LC_'.$item;
7604: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7605: my $output = &select_from_options($item,$config->{'order'},
7606: $config->{'options'},$selected,
7607: $config->{'nullval'},
7608: undef,undef,$onchange,$noedit,$id);
1.124 raeburn 7609: my ($checked,$reusesty,$sizesty);
1.114 raeburn 7610: if ($reuse) {
7611: $checked = ' checked="checked"';
7612: }
7613: $reusesty = 'none';
7614: $sizesty = 'none';
7615: if (($selected eq 'window') || ($selected eq 'tab')) {
7616: $reusesty = 'inline-block';
7617: if ($selected eq 'window') {
7618: $sizesty = 'inline-block';
7619: }
7620: }
7621: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7622: '<span class="LC_nobreak">'.
7623: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7624: &mt('Re-use tab/window').'</label>'.
7625: '</span></div>'.
7626: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7627: '<legend>'.&mt('Window size (optional)').'</legend>'.
7628: '<span class="LC_nobreak">'.
7629: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7630: (' ' x 3).
7631: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7632: '</span></fieldset>';
7633: return $output;
7634: }
7635:
1.1 raeburn 7636: sub print_other {
1.80 raeburn 7637: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7638: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7639: return;
7640: }
1.3 raeburn 7641: my @ordered = &get_other_items($cdom,$settings,$allitems);
7642: my %items;
7643: foreach my $parameter (@ordered) {
7644: $items{$parameter} = {
7645: text => '<b>'.$parameter.'</b>',
7646: input => 'textbox',
7647: size => '15',
7648: },
7649: }
7650: push (@ordered,'newp_value');
7651: $items{'newp_value'} = {
7652: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7653: '<input type="textbox" name="newp_name"'.
7654: ' value="" size="30" />',
7655: input => 'textbox',
7656: size => '30',
7657: };
1.93 raeburn 7658: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7659: }
7660:
7661: sub get_other_items {
7662: my ($cdom,$settings,$allitems) = @_;
7663: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7664: return;
7665: }
1.1 raeburn 7666: my @ordered;
7667: if (ref($settings) eq 'HASH') {
7668: foreach my $parameter (sort(keys(%{$settings}))) {
7669: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7670: next if (($parameter eq 'course.helper.not.run') &&
7671: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7672: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7673: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7674: || ($parameter eq 'type') ||
1.50 raeburn 7675: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7676: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7677: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7678: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7679: push(@ordered,$parameter);
7680: }
7681: }
7682: }
1.3 raeburn 7683: return @ordered;
1.1 raeburn 7684: }
7685:
7686: sub item_table_row_start {
1.91 raeburn 7687: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7688: my $output;
1.56 raeburn 7689: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7690: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7691: if ($leftclass eq '') {
7692: $leftclass = 'LC_left_item';
7693: }
7694: if ($rightclass eq '') {
7695: $rightclass = 'LC_right_item';
7696: }
1.56 raeburn 7697: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7698: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7699: '</td>';
1.91 raeburn 7700: if ($colspan > 1) {
7701: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7702: } else {
1.91 raeburn 7703: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7704: }
1.1 raeburn 7705: return $output;
7706: }
7707:
7708: sub item_table_row_end {
7709: return '</td></tr>';
7710: }
7711:
7712: sub yesno_radio {
1.80 raeburn 7713: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
1.1 raeburn 7714: my $itemon = ' ';
7715: my $itemoff = ' checked="checked" ';
1.69 raeburn 7716: if (($valueyes eq '') && ($valueno eq '')) {
7717: $valueyes = 'yes';
7718: $valueno = '';
7719: }
1.1 raeburn 7720: if (ref($settings) eq 'HASH') {
1.69 raeburn 7721: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7722: $itemon = $itemoff;
7723: $itemoff = ' ';
7724: }
1.69 raeburn 7725: unless (exists($settings->{$item})) {
7726: if ($unsetdefault eq $valueyes) {
7727: $itemon = $itemoff;
7728: $itemoff = ' ';
7729: }
7730: }
1.1 raeburn 7731: }
1.80 raeburn 7732: my $disabled;
7733: if ($noedit) {
7734: $disabled = ' disabled="disabled"';
7735: }
1.1 raeburn 7736: return '<span class="LC_nobreak"><label>'.
7737: '<input type="radio" name="'.$item.'"'.
1.80 raeburn 7738: $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
1.1 raeburn 7739: '<label><input type="radio" name="'.$item.'"'.
1.80 raeburn 7740: $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
1.1 raeburn 7741: }
7742:
7743: sub select_from_options {
1.91 raeburn 7744: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7745: my $output;
1.80 raeburn 7746: my $disabled;
7747: if ($noedit) {
7748: $disabled = ' disabled=disabled"';
7749: }
1.1 raeburn 7750: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7751: $output='<select name="'.$item.'" '.$onchange;
7752: if ($multiple) {
7753: $output .= ' multiple="multiple"';
7754: my $num = @{$order};
7755: $num ++ if ($nullval ne '');
7756: if (($maxsize) && ($maxsize < $num)) {
7757: $output .= ' size="'.$maxsize.'"';
7758: }
7759: }
1.91 raeburn 7760: if ($id ne '') {
7761: $output .= ' id="'.$id.'"';
7762: }
1.80 raeburn 7763: $output .= $disabled.'>'."\n";
1.1 raeburn 7764: if ($nullval ne '') {
7765: $output .= '<option value=""';
7766: if (ref($curr) eq 'ARRAY') {
7767: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7768: $output .= ' selected="selected" ';
7769: }
7770: } else {
7771: if ($curr eq '') {
7772: $output .= ' selected="selected" ';
7773: }
7774: }
7775: $output .= '>'.$nullval.'</option>';
7776: }
7777: foreach my $option (@{$order}) {
7778: $output.= '<option value="'.$option.'"';
7779: if (ref($curr) eq 'ARRAY') {
7780: if (grep(/^\Q$option\E$/,@{$curr})) {
7781: $output .= ' selected="selected" ';
7782: }
7783: } else {
7784: if ($option eq $curr) {
7785: $output.=' selected="selected"';
7786: }
7787: }
7788: $output.=">$options->{$option}</option>\n";
7789: }
7790: $output.="</select>";
7791: }
7792: return $output;
7793: }
7794:
7795: sub make_item_rows {
1.80 raeburn 7796: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
1.1 raeburn 7797: my $datatable;
7798: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7799: my $count = 0;
7800: foreach my $item (@{$ordered}) {
7801: $count ++;
1.56 raeburn 7802: my $colspan;
7803: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7804: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7805: $colspan = 2;
7806: }
1.114 raeburn 7807: my $rowdesc;
7808: if ($caller eq 'appearance') {
7809: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7810: } else {
7811: $rowdesc = $items->{$item}{text};
7812: }
1.41 www 7813: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7814: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7815: } else {
1.114 raeburn 7816: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7817: }
1.55 raeburn 7818: if ($item eq 'defaultcredits') {
7819: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7820: my $showcredits;
7821: if ($defaultcredits ne '') {
7822: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7823: } else {
7824: $showcredits = &mt('No default set');
7825: }
7826: $datatable .= $showcredits;
7827: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 7828: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 7829: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 7830: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7831: } elsif ($item eq 'print_header_format') {
1.80 raeburn 7832: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 7833: } elsif ($item eq 'lti.lcmenu') {
7834: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 7835: } elsif ($item eq 'extresource') {
7836: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7837: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 7838: my $disabled;
7839: if ($noedit) {
7840: $disabled = ' disabled="disabled"';
7841: }
1.1 raeburn 7842: $datatable .=
7843: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 7844: $settings->{$item},$disabled);
1.1 raeburn 7845: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 7846: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 7847: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 7848: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7849: unless ($domdefs{$item} eq '0') {
7850: $unsetdefault = 1;
7851: }
7852: $valueyes = "1";
7853: $valueno = "0";
1.87 raeburn 7854: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
7855: $valueyes = '1';
1.69 raeburn 7856: }
1.80 raeburn 7857: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7858: } elsif ($items->{$item}{input} eq 'selectbox') {
1.91 raeburn 7859: my $id;
7860: if ($caller eq 'menuitems') {
7861: $id = $item;
7862: }
1.1 raeburn 7863: my $curr = $settings->{$item};
7864: $datatable .=
7865: &select_from_options($item,$items->{$item}{'order'},
7866: $items->{$item}{'options'},$curr,
1.80 raeburn 7867: $items->{$item}{'nullval'},
1.91 raeburn 7868: undef,undef,undef,$noedit,$id);
1.1 raeburn 7869: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 7870: my $disabled;
7871: if ($noedit) {
7872: $disabled = ' disabled=disabled"';
7873: }
1.1 raeburn 7874: $datatable .=
7875: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 7876: $items->{$item}{size},
7877: $disabled);
1.1 raeburn 7878: }
7879: $datatable .= &item_table_row_end();
7880: }
7881: if (ref($rowtotal)) {
7882: $$rowtotal += scalar(@{$ordered});
7883: }
7884: }
7885: return $datatable;
7886: }
7887:
7888: sub nothidepriv_row {
1.80 raeburn 7889: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 7890: my ($cnum) = &get_course();
1.56 raeburn 7891: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 7892: if (ref($settings) eq 'HASH') {
7893: if ($settings->{$item} ne '') {
7894: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
7895: if ($user !~ /:/) {
7896: $nothide{join(':',split(/[\@]/,$user))}=1;
7897: } else {
7898: $nothide{$user} = 1;
7899: }
7900: }
7901: }
1.56 raeburn 7902: if ($settings->{'checkforpriv'}) {
1.124 raeburn 7903: @checkdoms = split(/,/,$settings->{'checkforpriv'});
1.56 raeburn 7904: }
1.1 raeburn 7905: }
1.56 raeburn 7906: push(@checkdoms,$cdom);
7907: my %coursepersonnel =
7908: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 7909: my @privusers;
7910: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 7911: my ($uname,$udom,$role) = split(/:/,$person);
7912: my $user = $uname.':'.$udom;
7913: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 7914: if ($end == -1 || $start == -1) {
7915: next;
7916: }
1.124 raeburn 7917: foreach my $dom (@checkdoms) {
1.56 raeburn 7918: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
7919: unless (grep(/^\Q$user\E$/,@privusers)) {
7920: push(@privusers,$user);
1.3 raeburn 7921: }
7922: }
7923: }
1.1 raeburn 7924: }
1.56 raeburn 7925: if (@privusers > 0) {
1.80 raeburn 7926: my $disabled;
7927: if ($noedit) {
7928: $disabled = ' disabled="disabled"';
7929: }
1.1 raeburn 7930: $datatable .= '<table align="right">';
7931: foreach my $user (sort(@privusers)) {
7932: my $hideon = ' checked="checked" ';
7933: my $hideoff = '';
7934: if ($nothide{$user}) {
7935: $hideoff = $hideon;
7936: $hideon = '';
7937: }
7938: my ($uname,$udom) = split(':',$user);
7939: $datatable .= '<tr><td align="left">'.
7940: &Apache::loncommon::aboutmewrapper(
7941: &Apache::loncommon::plainname($uname,$udom,'firstname'),
7942: $uname,$udom,'aboutuser').
7943: '</td><td align="left">'.
7944: '<span class="LC_nobreak"><label>'.
7945: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 7946: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 7947: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 7948: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 7949: '</tr>';
7950: }
7951: $datatable .= '</table>';
7952: } else {
1.9 raeburn 7953: if ($crstype eq 'Community') {
7954: $datatable .= &mt('No Domain Coordinators have community roles');
7955: } else {
7956: $datatable .= &mt('No Domain Coordinators have course roles');
7957: }
1.1 raeburn 7958: }
7959: return $datatable;
7960: }
7961:
1.56 raeburn 7962: sub checkforpriv_row {
1.80 raeburn 7963: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 7964: my $datatable;
7965: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7966: if (keys(%domains) == 1) {
7967: $datatable = '</td><td align="right">'.
7968: &mt("Course's domain is only domain");
7969: return $datatable;
7970: }
7971: my @excdoms = ($cdom);
7972: my $num = 0;
7973: if ($settings->{$item} eq '') {
7974: $datatable = '</td><td align="right">'.
7975: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 7976: 1,1,undef,undef,\@excdoms,
7977: $noedit);
1.56 raeburn 7978: } else {
7979: my @privdoms = split(/,/,$settings->{$item});
7980: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7981: $datatable = '</td><td align="right"><br />'.
7982: &Apache::loncommon::start_data_table();
1.80 raeburn 7983: my $disabled;
7984: if ($noedit) {
7985: $disabled = ' disabled="disabled"';
7986: }
1.56 raeburn 7987: if (@privdoms > 0) {
7988: foreach my $currdom (@privdoms) {
7989: next unless ($domains{$currdom});
7990: my $domdesc = &Apache::lonnet::domain($currdom,'description');
7991: if ($domdesc eq '') {
7992: $domdesc = $currdom;
1.124 raeburn 7993: }
1.56 raeburn 7994: $datatable .=
7995: &Apache::loncommon::start_data_table_row().
7996: '<td align="left"><span class="LC_nobreak">'.
7997: &mt('Domain:').'<b> '.$domdesc.
7998: '</b><input type="hidden" name="checkforpriv_'.$num.
7999: '" value="'.$currdom.'" /></span><br />'.
8000: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 8001: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
8002: &mt('Delete').'</label></span></td>'.
1.56 raeburn 8003: &Apache::loncommon::end_data_table_row();
8004: $num ++;
1.124 raeburn 8005: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
1.56 raeburn 8006: push(@excdoms,$currdom);
8007: }
8008: }
8009: }
8010: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
1.124 raeburn 8011: $datatable .=
1.56 raeburn 8012: &Apache::loncommon::start_data_table_row().
8013: '<td align="left"><span class="LC_nobreak">'.
8014: &mt('Additional domain:'). '</span><br />'.
8015: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8016: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8017: '</td>'.&Apache::loncommon::end_data_table_row();
8018: }
8019: $datatable .= &Apache::loncommon::end_data_table().
8020: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8021: '<br />';
8022: }
8023: return $datatable;
8024: }
8025:
1.1 raeburn 8026: sub print_hdrfmt_row {
1.80 raeburn 8027: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8028: my @curr;
8029: my $currnum = 0;
8030: my $maxnum = 2;
8031: my $currstr;
8032: if ($settings->{$item} ne '') {
8033: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8034: $settings->{$item}.'</tt></span></b><br />';
8035: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8036: foreach my $val (@current) {
8037: unless ($val eq '') {
8038: push(@curr,$val);
1.1 raeburn 8039: }
8040: }
8041: $currnum = @curr;
8042: $maxnum += $currnum;
8043: }
8044:
8045: my $output = <<ENDJS;
8046:
8047: <script type="text/javascript" language="Javascript">
8048:
8049: function reOrder(chgnum) {
8050: var maxnum = $maxnum;
8051: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8052: var newidx = 'printfmthdr_pos_'+chgnum;
8053: oldidx = getIndexByName(oldidx);
8054: newidx = getIndexByName(newidx);
8055: var oldpos = document.display.elements[oldidx].value;
8056: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8057: document.display.elements[oldidx].value = newpos;
8058: var chgtype = 'up';
8059: if (newpos < oldpos) {
8060: chgtype = 'down';
8061: }
8062: for (var j=0; j<maxnum; j++) {
8063: if (j != chgnum) {
8064: oldidx = 'printfmthdr_oldpos_'+j;
8065: newidx = 'printfmthdr_pos_'+j;
8066: oldidx = getIndexByName(oldidx);
8067: newidx = getIndexByName(newidx);
8068: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8069: var currsel = document.display.elements[newidx].selectedIndex;
8070: if (chgtype == 'up') {
8071: if ((currpos > oldpos) && (currpos <= newpos)) {
8072: document.display.elements[newidx].selectedIndex = currsel-1;
8073: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8074: }
8075: } else {
8076: if ((currpos >= newpos) && (currpos < oldpos)) {
8077: document.display.elements[newidx].selectedIndex = currsel+1;
8078: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8079: }
8080: }
8081: }
8082: }
8083: return;
8084: }
8085:
8086: function getIndexByName(item) {
8087: for (var i=0;i<document.display.elements.length;i++) {
8088: if (document.display.elements[i].name == item) {
8089: return i;
8090: }
8091: }
8092: return -1;
8093: }
8094:
8095: </script>
8096:
8097: ENDJS
1.56 raeburn 8098: $output .= '</td><td align="right"><br />'.
8099: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8100: my $disabled;
8101: if ($noedit) {
8102: $disabled = ' disabled="disabled"';
8103: }
1.1 raeburn 8104: if (@curr > 0) {
8105: for (my $i=0; $i<@curr; $i++) {
8106: my $pos = $i+1;
1.10 raeburn 8107: $output .= '<tr>'.
1.1 raeburn 8108: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8109: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8110: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8111: '"'.$disabled.' /></span></td>';
1.1 raeburn 8112: if ($curr[$i] =~ /^%\d*[nca]$/) {
8113: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8114: $output .= '<td align="left">'.
1.80 raeburn 8115: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8116: } else {
8117: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8118: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8119: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8120: }
1.10 raeburn 8121: $output .= '</tr>';
1.1 raeburn 8122: }
8123: }
1.80 raeburn 8124: my $pos = $currnum+1;
1.124 raeburn 8125: unless ($noedit) {
1.80 raeburn 8126: $output .=
8127: '<tr>'.
1.1 raeburn 8128: '<td align="left"><span class="LC_nobreak">'.
8129: &position_selector($pos,$currnum,$maxnum).
8130: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8131: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8132: '</tr>';
1.80 raeburn 8133: $pos ++;
1.82 raeburn 8134: $currnum ++;
8135: $output .=
1.80 raeburn 8136: '<tr>'.
1.1 raeburn 8137: '<td align="left"><span class="LC_nobreak">'.
8138: &position_selector($pos,$currnum,$maxnum).
8139: '<b>'.&mt('New').'</b></span></td>'.
8140: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8141: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8142: '" value="" size ="25" />'.
8143: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8144: $maxnum.'" /></td>'.
1.80 raeburn 8145: '</tr>';
8146: }
8147: $output .= '</table><br />';
1.1 raeburn 8148: return $output;
8149: }
8150:
8151: sub position_selector {
1.80 raeburn 8152: my ($pos,$num,$maxnum,$disabled) = @_;
8153: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8154: for (my $j=1; $j<=$maxnum; $j++) {
8155: my $sel = '';
8156: if ($pos == $j) {
8157: $sel = ' selected="selected"';
8158: }
8159: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8160: }
8161: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8162: '" value="'.$pos.'" />';
8163: return $output;
8164: }
8165:
8166: sub substitution_selector {
1.80 raeburn 8167: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8168: my ($stunametxt,$crsidtxt);
8169: if ($crstype eq 'Community') {
8170: $stunametxt = 'member name';
8171: $crsidtxt = 'community ID',
8172: } else {
8173: $stunametxt = 'student name';
8174: $crsidtxt = 'course ID',
8175: }
1.1 raeburn 8176: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8177: n => $stunametxt,
8178: c => $crsidtxt,
1.1 raeburn 8179: a => 'assignment note',
8180: );
8181: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8182: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8183: if ($subst eq '') {
8184: $output .= '<option value="" selected="selected"> </option>';
8185: }
8186: foreach my $field ('n','c','a') {
8187: my $sel ='';
8188: if ($subst eq $field) {
8189: $sel = ' selected="selected"';
8190: }
8191: $output .= '<option value="'.$field.'"'.$sel.'>'.
8192: $lt{$field}.'</option>';
8193: }
8194: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8195: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8196: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8197: return $output;
8198: }
8199:
1.23 raeburn 8200: sub change_clone {
8201: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8202: my $clone_crs = $cnum.':'.$cdom;
8203: if ($cnum && $cdom) {
8204: my $clone_crs = $cnum.':'.$cdom;
8205: my @allowclone;
8206: if ($clonelist =~ /,/) {
8207: @allowclone = split(',',$clonelist);
8208: } else {
8209: $allowclone[0] = $clonelist;
8210: }
8211: foreach my $currclone (@allowclone) {
8212: if (!grep(/^$currclone$/,@$oldcloner)) {
8213: if ($currclone ne '*') {
1.71 raeburn 8214: if ($currclone =~ /:/) {
8215: my ($uname,$udom) = split(/:/,$currclone);
8216: if ($uname && $udom && $uname ne '*') {
8217: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8218: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8219: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8220: if ($currclonecrs{'cloneable'} eq '') {
8221: $currclonecrs{'cloneable'} = $clone_crs;
8222: } else {
8223: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8224: }
8225: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8226: }
8227: }
8228: }
8229: }
8230: }
8231: }
8232: }
8233: foreach my $oldclone (@$oldcloner) {
8234: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8235: if ($oldclone ne '*') {
1.71 raeburn 8236: if ($oldclone =~ /:/) {
8237: my ($uname,$udom) = split(/:/,$oldclone);
8238: if ($uname && $udom && $uname ne '*' ) {
8239: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8240: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8241: my %newclonecrs = ();
8242: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8243: if ($currclonecrs{'cloneable'} =~ /,/) {
8244: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8245: foreach my $crs (@currclonecrs) {
8246: if ($crs ne $clone_crs) {
8247: $newclonecrs{'cloneable'} .= $crs.',';
8248: }
1.23 raeburn 8249: }
1.71 raeburn 8250: $newclonecrs{'cloneable'} =~ s/,$//;
8251: } else {
8252: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8253: }
1.71 raeburn 8254: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8255: }
8256: }
8257: }
8258: }
8259: }
8260: }
8261: }
8262: }
8263: return;
8264: }
8265:
1.108 raeburn 8266: sub devalidate_remote_courseprefs {
8267: my ($cdom,$cnum,$cachekeys) = @_;
8268: return unless (ref($cachekeys) eq 'HASH');
8269: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8270: my %thismachine;
8271: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8272: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8273: if (keys(%servers)) {
8274: foreach my $server (keys(%servers)) {
8275: next if ($thismachine{$server});
8276: my @cached;
8277: foreach my $name (@posscached) {
8278: if ($cachekeys->{$name}) {
8279: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8280: }
8281: }
8282: if (@cached) {
8283: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8284: }
8285: }
8286: }
8287: return;
8288: }
8289:
1.1 raeburn 8290: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>