Annotation of loncom/interface/courseprefs.pm, revision 1.125
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.125 ! raeburn 4: # $Id: courseprefs.pm,v 1.124 2023/06/03 11:21:37 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: }
697: }
698: }
699: }
700: return @allitems;
701: }
702:
1.1 raeburn 703: sub print_config_box {
1.99 raeburn 704: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 705: my $ordered = $item->{'ordered'};
1.3 raeburn 706: my $itemtext = $item->{'itemtext'};
1.80 raeburn 707: my $noedit;
708: if (ref($parm_permission) eq 'HASH') {
709: unless ($parm_permission->{'process'}) {
710: $noedit = 1;
711: }
712: }
1.1 raeburn 713: my $rowtotal = 0;
714: my $output =
1.45 www 715: '<table class="LC_nested_outer">
716: <tr>
717: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 718: &mt($item->{text});
719: if ($item->{'help'}) {
1.53 raeburn 720: $output .= ' '.
1.52 raeburn 721: &Apache::loncommon::help_open_topic($item->{'help'});
722: }
723: $output .= '</span></th>'."\n".
724: '</tr>';
1.91 raeburn 725: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 726: $output .= '
1.45 www 727: <tr>
728: <td>
1.18 faziophi 729: <table class="LC_nested">';
730: if (exists $item->{'header'}->[0]->{'col1'} ||
731: exists $item->{'header'}->[0]->{'col2'}) {
732: $output .= '
733: <tr class="LC_info_row">
1.56 raeburn 734: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
735: if ($action eq 'feedback') {
736: $output .= '
737: <td class="LC_right_item" colspan="2">';
738: } else {
739: $output .= '
740: <td class="LC_right_item">';
741: }
742: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 743: </tr>';
744: }
1.1 raeburn 745: $rowtotal ++;
746: if ($action eq 'feedback') {
1.80 raeburn 747: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 748: } elsif ($action eq 'classlists') {
1.80 raeburn 749: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 750: } elsif ($action eq 'menuitems') {
751: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 752: }
753: $output .= '
754: </table>
1.45 www 755: </td>
756: </tr>
757: <tr>
758: <td>
1.1 raeburn 759: <table class="LC_nested">
760: <tr class="LC_info_row">
761: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 762: if ($action eq 'classlists') {
763: $output .= '
764: <td class="LC_right_item" colspan="2">';
765: } else {
766: $output .= '
767: <td class="LC_right_item">';
768: }
769: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 770: </tr>';
771: if ($action eq 'classlists') {
1.80 raeburn 772: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 773: '
774: </table>
1.45 www 775: </td>
776: </tr>
777: <tr>
778: <td>
1.18 faziophi 779: <table class="LC_nested">';
1.43 www 780: if (exists $item->{'header'}->[2]->{'col1'} ||
781: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 782: $output .= '
783: <tr class="LC_info_row">
1.43 www 784: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
785: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 786: </tr>';
787: }
1.1 raeburn 788: }
789: } else {
790: $output .= '
1.45 www 791: <tr>
792: <td>
1.18 faziophi 793: <table class="LC_nested">';
794: if (exists $item->{'header'}->[0]->{'col1'} ||
795: exists $item->{'header'}->[0]->{'col2'}) {
796: $output .= '
797: <tr class="LC_info_row">
1.56 raeburn 798: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
799: if (($action eq 'courseinfo') || ($action eq 'localization') ||
800: ($action eq 'print_discussion')) {
801: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
802: } else {
803: $output .= '<td class="LC_right_item" valign="top">';
804: }
805: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 806: </tr>';
807: }
1.1 raeburn 808: }
809: $rowtotal ++;
810: if ($action eq 'courseinfo') {
1.80 raeburn 811: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 812: } elsif ($action eq 'localization') {
1.80 raeburn 813: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 814: } elsif ($action eq 'feedback') {
1.80 raeburn 815: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 816: } elsif ($action eq 'discussion') {
1.80 raeburn 817: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 818: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 819: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 820: } elsif ($action eq 'appearance') {
1.80 raeburn 821: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 822: } elsif ($action eq 'grading') {
1.80 raeburn 823: $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 824: } elsif ($action eq 'printouts') {
1.80 raeburn 825: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 826: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 827: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 828: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 829: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.118 raeburn 830: } elsif ($action eq 'ltitools') {
831: my $currtools = {};
832: if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
833: $currtools = $settings->{'ltitools'};
834: }
835: $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
1.87 raeburn 836: } elsif ($action eq 'lti') {
837: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 838: } elsif ($action eq 'menuitems') {
839: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 840: } elsif ($action eq 'linkprot') {
841: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 842: } elsif ($action eq 'other') {
1.80 raeburn 843: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 844: }
845: $output .= '
846: </table>
1.45 www 847: </td>
848: </tr>
849: </table><br />';
1.1 raeburn 850: return ($output,$rowtotal);
851: }
852:
853: sub process_changes {
1.108 raeburn 854: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 855: my (%newvalues,$errors);
1.3 raeburn 856: if (ref($item) eq 'HASH') {
857: if (ref($changes) eq 'HASH') {
858: my @ordered;
859: if ($action eq 'other') {
860: @ordered = &get_other_items($cdom,$values,$allitems);
861: if ($env{'form.newp_name'} ne '') {
862: my $newp = $env{'form.newp_name'};
863: if ($env{'form.newp_value'} ne '') {
864: if (ref($allitems) eq 'ARRAY') {
865: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
866: (grep(/^\Q$newp\E$/,@{$allitems}))) {
867: $changes->{$newp} = $env{'form.newp_value'};
868: }
869: }
870: }
871: }
1.118 raeburn 872: } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.99 raeburn 873: if (ref($values->{$action}) eq 'HASH') {
874: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 875: if ($id =~ /^\d+$/) {
876: push(@ordered,$id);
877: }
878: }
879: }
880: @ordered = sort { $a <=> $b } @ordered;
1.118 raeburn 881: if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
882: push(@ordered,$env{'form.'.$action.'_maxnum'});
1.93 raeburn 883: }
1.3 raeburn 884: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 885: if ($action eq 'courseinfo') {
886: my ($can_toggle_cat,$can_categorize) =
887: &can_modify_catsettings($cdom,$crstype);
888: foreach my $entry (@{$item->{'ordered'}}) {
889: next if (($entry eq 'hidefromcat') &&
890: (!$can_toggle_cat));
891: next if (($entry eq 'categories') &&
892: (!$can_categorize));
893: next if (($entry eq 'loncaparev') ||
1.63 raeburn 894: ($entry eq 'owner') ||
1.88 raeburn 895: ($entry eq 'clonedfrom') ||
896: ($entry eq 'syllabus'));
1.49 raeburn 897: push(@ordered,$entry);
898: }
1.55 raeburn 899: } elsif ($action eq 'classlists') {
900: foreach my $entry (@{$item->{'ordered'}}) {
901: next if ($entry eq 'defaultcredits');
902: push(@ordered,$entry);
903: }
1.49 raeburn 904: } else {
905: @ordered = @{$item->{'ordered'}};
906: }
1.3 raeburn 907: }
908: if (@ordered > 0) {
909: if ($action eq 'feedback') {
910: foreach my $entry (@ordered) {
911: my $userstr = '';
912: my $total = $env{'form.'.$entry.'_total'};
913: if ($total) {
914: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
915: for (my $i=0; $i<$total; $i++) {
916: unless (grep(/^$i$/,@deletes)) {
917: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
918: &get_sec_str($entry,$i).',';
919: }
920: }
921: } else {
922: $total = 0;
923: }
924: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
925: my $uname = $env{'form.'.$entry.'_uname_'.$total};
926: my $udom = $env{'form.'.$entry.'_udom_'.$total};
927: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
928: $userstr =~ s/,$//;
929: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
930: } else {
931: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
932: }
933: } else {
934: $userstr =~ s/,$//;
935: }
936: $newvalues{$entry} = $userstr;
937: if ($newvalues{$entry} ne $values->{$entry}) {
938: $changes->{$entry} = $newvalues{$entry};
939: }
940: my $ext_entry = $entry.'.text';
941: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
942: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
943: $changes->{$ext_entry} = $newvalues{$ext_entry};
944: }
945: }
1.91 raeburn 946: } elsif ($action eq 'menuitems') {
947: my (%current,@colls);
948: my $next = 1;
949: if ($values->{'menucollections'}) {
950: foreach my $item (split(/;/,$values->{'menucollections'})) {
951: my ($num,$value) = split(/\%/,$item);
952: if ($num =~ /^\d+$/) {
953: unless (grep(/^$num$/,@colls)) {
954: push(@colls,$num);
955: }
956: my @entries = split(/\&/,$value);
957: foreach my $entry (@entries) {
958: my ($name,$fields) = split(/=/,$entry);
959: $current{$num}{$name} = $fields;
960: }
961: }
962: }
963: }
964: if (@colls) {
965: @colls = sort { $a <=> $b } @colls;
966: $next += $colls[-1];
967: }
968: if ($env{'form.menucollections_add'} eq $next) {
969: push(@colls,$next);
970: }
971: my $currdef = $values->{'menudefault'};
972: my $possdef = $env{'form.menudefault'};
973: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 974: if ($currdef ne $possdef) {
1.91 raeburn 975: $changes->{'menudefault'} = $possdef;
976: }
1.92 raeburn 977: } elsif ($currdef) {
1.91 raeburn 978: $changes->{'menudefault'} = '';
979: }
980: my $menucoll;
981: if (@colls) {
982: my ($ordered,$cats) = &menuitems_categories();
983: my %shortcats = &menuitems_abbreviations();
984: foreach my $num (@colls) {
985: my ($entry,%include);
986: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
987: foreach my $item (@{$ordered}) {
988: if ($item eq 'shown') {
989: foreach my $type (@{$cats->{$item}}) {
990: $entry .= $type.'=';
991: if ($include{$type}) {
992: $entry .= 'y';
993: } else {
994: $entry .= 'n';
995: }
996: $entry .= '&';
997: }
998: } else {
999: $entry .= $shortcats{$item}.'=';
1000: foreach my $type (@{$cats->{$item}}) {
1001: if ($include{$type}) {
1002: $entry .= $type.',';
1003: }
1004: }
1005: $entry =~ s/,$//;
1006: $entry .= '&';
1007: }
1008: }
1009: $entry =~ s/\&$//;
1010: if ($menucoll) {
1011: $menucoll .= ';';
1012: }
1013: $menucoll .= $num.'%'.$entry;
1014: }
1015: if ($menucoll ne $values->{'menucollections'}) {
1016: $changes->{'menucollections'} = $menucoll;
1017: }
1018: } elsif ($values->{'menucollections'}) {
1019: $changes->{'menucollections'} = '';
1020: }
1.102 raeburn 1021: } elsif ($action eq 'linkprot') {
1022: if (ref($values) eq 'HASH') {
1.108 raeburn 1023: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 1024: }
1.118 raeburn 1025: } elsif ($action eq 'ltitools') {
1026: if (ref($values) eq 'HASH') {
1027: my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1028: $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1029: 'ok','','ok');
1030: }
1.3 raeburn 1031: } else {
1032: foreach my $entry (@ordered) {
1033: if ($entry eq 'cloners') {
1034: if ($env{'form.cloners_all'}) {
1035: $newvalues{$entry} = '*';
1036: } else {
1037: my @clonedoms;
1038: if (exists($env{'form.cloners_activate'})) {
1039: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1040: if ($actnum ne '-1') {
1.33 raeburn 1041: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1042: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1043: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1044: $newvalues{$entry} = '*:'.$clonedom;
1045: push(@clonedoms,$newvalues{$entry});
1046: }
1047: }
1048: }
1049: } else {
1050: my $num = $env{'form.cloners_total'};
1051: my @deletes =
1052: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1053: for (my $i=0; $i<$num; $i++) {
1054: if (!grep(/^$i$/,@deletes)) {
1055: my $clonedom = $env{'form.cloners_dom_'.$i};
1056: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1057: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1058: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1059: }
1060: }
1061: }
1062: }
1063: if (@clonedoms) {
1064: $newvalues{$entry}=join(',',@clonedoms);
1065: }
1066: }
1067: if ($env{'form.cloners_newdom'} ne '') {
1068: my $clonedom = $env{'form.cloners_newdom'};
1069: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1070: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1071: if (@clonedoms) {
1.3 raeburn 1072: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1073: $newvalues{$entry} .= ','.$newdom;
1074: }
1075: } else {
1076: $newvalues{$entry} = $newdom;
1077: }
1078: }
1079: }
1080: if ($env{'form.'.$entry} ne '') {
1081: my @cloners = split(',',$env{'form.'.$entry});
1082: my @okcloners;
1083: foreach my $cloner (@cloners) {
1.23 raeburn 1084: $cloner =~ s/^\s+//;
1085: $cloner =~ s/\s+$//;
1086: unless ($cloner eq '') {
1087: my ($uname,$udom) = split(':',$cloner);
1088: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1089: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1090: push(@okcloners,$cloner);
1091: }
1.3 raeburn 1092: }
1093: }
1094: }
1095: if (@okcloners) {
1096: my $okclonestr = join(',',@okcloners);
1097: if ($newvalues{$entry} ne '') {
1098: $newvalues{$entry} .= ','.$okclonestr;
1099: } else {
1100: $newvalues{$entry} = $okclonestr;
1101: }
1102: }
1103: }
1.71 raeburn 1104: if (ref($values) eq 'HASH') {
1105: my (@code_order,%codedefaults);
1106: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1107: \@code_order);
1108: my $clonebycode;
1109: if ($env{'form.cloners_instcode'}) {
1110: if (@code_order > 0) {
1111: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1112: my %local_to_standard;
1113: for (my $i=0; $i<@code_order; $i++) {
1114: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1115: }
1116: foreach my $item (@code_order) {
1117: my $key = $local_to_standard{$item};
1118: if ($key ne '') {
1119: if ($env{'form.'.$key}) {
1120: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1121: }
1122: }
1123: }
1124: $clonebycode =~ s/\&$//;
1125: }
1126: }
1127: if ($clonebycode) {
1128: if ($newvalues{$entry}) {
1129: $newvalues{$entry} .= ','.$clonebycode;
1130: } else {
1131: $newvalues{$entry} = $clonebycode;
1132: }
1133: }
1134: }
1.3 raeburn 1135: }
1136: if (ref($disallowed) eq 'HASH') {
1137: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1138: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1139: $disallowed->{'cloners'}{$key} =~ s/,$//;
1140: }
1141: }
1142: }
1.25 raeburn 1143: } elsif ($entry eq 'co-owners') {
1144: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1145: my $coowners = $values->{'internal.co-owners'};
1146: my @currcoown;
1147: if ($coowners) {
1148: @currcoown = split(',',$coowners);
1149: }
1150: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1151: my $autocoowner;
1152: if (($crstype eq 'Course') &&
1153: ($values->{'internal.coursecode'})) {
1154: my %domconf =
1155: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1156: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1157: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1158: }
1159: }
1.96 raeburn 1160: if ($autocoowner) {
1161: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1162: } else {
1.25 raeburn 1163: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1164: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1165: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1166: if (@invitecoowners) {
1167: push(@pendingcoowners,@invitecoowners);
1168: }
1169: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1170: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1171: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1172: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1173: push(@{$changes->{$entry}{'changed'}},'co-owners');
1174: }
1175: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1176: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1177: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1178: }
1179: }
1180: } else {
1181: my (@newpending,@newcoown);
1182: my $uname = $env{'user.name'};
1183: my $udom = $env{'user.domain'};
1184: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1185: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1186: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1187: foreach my $item (@pendingcoown) {
1188: unless ($item eq $uname.':'.$udom) {
1189: push(@newpending,$item);
1190: }
1191: }
1192: @newcoown = @currcoown;
1.90 raeburn 1193: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1194: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1195: push(@newcoown,$uname.':'.$udom);
1196: }
1197: }
1.90 raeburn 1198: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1199: foreach my $item (@currcoown) {
1200: unless ($item eq $uname.':'.$udom) {
1201: push(@newcoown,$item);
1202: }
1203: }
1204: if ($pendingcoowners ne '') {
1205: @newpending = @pendingcoown;
1206: }
1.96 raeburn 1207: } else {
1208: @newcoown = @currcoown;
1.25 raeburn 1209: }
1210: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1211: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1212: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1213: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1214: push(@{$changes->{$entry}{'changed'}},'co-owners');
1215: }
1216: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1217: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1218: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1219: }
1220: }
1.3 raeburn 1221: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1222: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1223: } elsif ($entry eq 'rolenames') {
1224: my %adv_roles =
1225: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1226: my @stds;
1227: if ($crstype eq 'Community') {
1228: @stds = ('co');
1229: } else {
1230: @stds = ('cc');
1231: }
1232: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1233: my (@replacements,@regulars);
1234: foreach my $role (@stds) {
1235: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1236: push(@replacements,$role);
1.3 raeburn 1237: } else {
1238: push(@regulars,$role);
1239: }
1.9 raeburn 1240: }
1.3 raeburn 1241: foreach my $stdrole (@stds) {
1242: my $ext_entry = $entry.'_'.$stdrole;
1243: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1244: $env{'request.course.id'},1);
1245: if ($env{'form.'.$ext_entry} eq $stdname) {
1246: $newvalues{$ext_entry} = '';
1247: } else {
1248: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1249: }
1250: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1251: my $dupname = 0;
1252: if ($newvalues{$ext_entry} ne '') {
1253: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1254: $dupname = 1;
1255: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1256: }
1257: if (!$dupname) {
1258: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1259: $dupname = 1;
1260: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1261: }
1262: }
1263: if (!$dupname) {
1264: foreach my $role (keys(%adv_roles)) {
1265: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1266: $dupname = 1;
1267: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1268: last;
1269: }
1270: }
1271: }
1272: }
1273: if (!$dupname) {
1274: $changes->{$ext_entry} = $newvalues{$ext_entry};
1275: }
1276: }
1277: }
1.77 raeburn 1278: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1279: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1280: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1281: @denied = sort(@denied);
1282: my $deniedstr = '';
1283: if (@denied > 0) {
1284: $deniedstr = join(',',@denied);
1285: }
1286: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1287: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1288: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1289: my $total = $env{'form.'.$entry.'_total'};
1290: my $userstr = '';
1291: my @denied;
1292: if ($total > 0) {
1293: my @deletes =
1294: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1295: for (my $i=0; $i<$total; $i++) {
1296: unless (grep(/^$i$/,@deletes)) {
1297: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1298: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1299: }
1300: }
1301: } else {
1302: $total = 0;
1303: }
1304: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1305: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1306: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1307: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1308: $userstr =~ s/,$//;
1309: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1310: } else {
1311: my $newuser .= $uname.':'.$udom;
1312: if (grep(/^\Q$newuser\E$/,@denied)) {
1313: $userstr =~ s/,$//;
1314: } else {
1315: $userstr .= $newuser;
1316: }
1317: }
1318: } else {
1319: $userstr =~ s/,$//;
1320: }
1321: $newvalues{$entry} = $userstr;
1322: } elsif ($entry eq 'allow_discussion_post_editing') {
1323: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1324: @canedit = sort(@canedit);
1325: foreach my $role (@canedit) {
1326: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1327: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1328: $newvalues{$entry} .= $role.',';
1329: } else {
1330: foreach my $sec (@secs) {
1331: $newvalues{$entry} .= $role.':'.$sec.',';
1332: }
1333: }
1334: }
1335: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1336: } elsif ($entry eq 'discussion_post_fonts') {
1337: my ($classorder,$classtitles) = &discussion_vote_classes();
1338: my $fontchange = 0;
1339: foreach my $class (@{$classorder}) {
1.124 raeburn 1340: my $ext_entry = $entry.'_'.$class;
1.50 raeburn 1341: my $size = $env{'form.'.$ext_entry.'_size'};
1342: my $unit = $env{'form.'.$ext_entry.'_unit'};
1343: my $weight = $env{'form.'.$ext_entry.'_weight'};
1344: my $style = $env{'form.'.$ext_entry.'_style'};
1345: my $other = $env{'form.'.$ext_entry.'_other'};
1346: $size =~ s/,//g;
1.124 raeburn 1347: $unit =~ s/,//g;
1.50 raeburn 1348: $weight =~ s/,//g;
1349: $style =~ s/,//g;
1350: $other =~ s/[^\w;:\s\-\%.]//g;
1351: $other =~ s/(^\s+|\s+$)//g;
1352: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1353: my $current = $values->{$ext_entry};
1354: if ($values->{$ext_entry} eq '') {
1.124 raeburn 1355: $current = ',,,';
1.50 raeburn 1356: }
1357: if ($newvalues{$ext_entry} ne $current) {
1358: $changes->{$ext_entry} = $newvalues{$ext_entry};
1359: $fontchange ++;
1360: }
1361: }
1362: if ($fontchange) {
1363: $changes->{$entry} = 1;
1.124 raeburn 1364: }
1.3 raeburn 1365: } elsif ($entry eq 'nothideprivileged') {
1366: my @curr_nothide;
1367: my @new_nothide;
1368: if ($values->{$entry} ne '') {
1369: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1370: my $nothide;
1371: if ($user !~ /:/) {
1372: $nothide = join(':',split(/[\@]/,$user));
1373: } else {
1374: $nothide = $user;
1375: }
1376: if ((defined($nothide)) &&
1377: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1378: push(@curr_nothide,$nothide);
1379: }
1380: }
1381: }
1382: foreach my $key (keys(%env)) {
1383: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1384: if ($env{$key}) {
1.3 raeburn 1385: my $nothide = $1;
1386: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1387: push(@new_nothide,$nothide);
1388: }
1389: }
1390: }
1391: }
1392: @new_nothide = sort(@new_nothide);
1393: my @differences =
1394: &Apache::loncommon::compare_arrays(\@curr_nothide,
1395: \@new_nothide);
1396: if (@differences > 0) {
1397: if (@new_nothide > 0) {
1398: $newvalues{$entry} = join(',',@new_nothide);
1399: } else {
1400: $newvalues{$entry} = '';
1401: }
1402: } else {
1403: $newvalues{$entry} = $values->{$entry};
1404: }
1405: } elsif ($entry eq 'print_header_format') {
1406: my $maxnum = $env{'form.printfmthdr_maxnum'};
1407: my @newhdr;
1408: if ($maxnum > 2) {
1409: for (my $i=0; $i<$maxnum-2; $i++) {
1410: if ($env{'form.printfmthdr_del_'.$i}) {
1411: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1412: } else {
1413: my $hdr;
1414: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1415: $hdr = '%';
1416: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1417: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1418: }
1419: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1420: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1421: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1422: }
1423: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1424: }
1425: }
1426: }
1427: my $newsub = $maxnum-2;
1428: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1429: my $hdr = '%';
1430: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1431: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1432: }
1433: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1434: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1435: }
1436: my $newtext = $maxnum-1;
1437: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1438: $newvalues{$entry} = join('',@newhdr);
1.124 raeburn 1439: } elsif (($entry eq 'languages') ||
1.56 raeburn 1440: ($entry eq 'checkforpriv')) {
1441: my $settings;
1.3 raeburn 1442: my $total = $env{'form.'.$entry.'_total'};
1443: if ($total) {
1444: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1445: for (my $i=0; $i<$total; $i++) {
1446: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1447: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1448: }
1449: }
1450: } else {
1451: $total = 0;
1452: }
1453: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1454: my $new = $env{'form.'.$entry.'_'.$total};
1.124 raeburn 1455: if ($entry eq 'languages') {
1.56 raeburn 1456: my %langchoices = &get_lang_choices();
1457: if ($langchoices{$new}) {
1458: $settings .= $new;
1459: } else {
1460: $settings =~ s/,$//;
1461: $disallowed->{'localization'}{$entry} = $new;
1462: }
1.3 raeburn 1463: } else {
1.56 raeburn 1464: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1465: if ($domains{$new}) {
1466: $settings .= $new;
1467: } else {
1468: $settings =~ s/,$//;
1469: $disallowed->{'classlists'}{$entry} = $new;
1470: }
1.3 raeburn 1471: }
1472: } else {
1.56 raeburn 1473: $settings =~ s/,$//;
1.3 raeburn 1474: }
1.56 raeburn 1475: $newvalues{$entry} = $settings;
1.87 raeburn 1476: } elsif ($action eq 'lti') {
1477: if ($entry eq 'lti.override') {
1478: $newvalues{$entry} = $env{'form.'.$entry};
1479: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1480: if ($env{'form.lti.override'}) {
1481: $newvalues{$entry} = $env{'form.'.$entry};
1482: } else {
1483: $newvalues{$entry} = '';
1484: }
1485: } elsif ($entry eq 'lti.lcmenu') {
1486: if (($env{'form.lti.override'}) &&
1487: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1488: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1489: my @newlcmenu;
1490: if (@lcmenu) {
1491: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1492: foreach my $item (@menuitems) {
1493: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1494: if (grep(/^\Q$item\E$/,@lcmenu)) {
1495: push(@newlcmenu,$item);
1496: }
1497: }
1498: }
1499: if (@newlcmenu) {
1500: $newvalues{$entry} = join(',',@newlcmenu);
1501: } else {
1502: $newvalues{$entry} = 'none';
1503: }
1504: } else {
1505: $newvalues{$entry} = '';
1506: }
1507: }
1.114 raeburn 1508: } elsif ($entry eq 'extresource') {
1509: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1510: $newvalues{$entry} = $env{'form.'.$entry};
1511: if ($env{'form.'.$entry} ne 'iframe') {
1512: if ($env{'form.extwintabreuse'}) {
1513: $newvalues{$entry} .= ':1';
1514: } else {
1515: $newvalues{$entry} .= ':0';
1516: }
1517: if ($env{'form.'.$entry} eq 'window') {
1518: foreach my $dim ('width','height') {
1519: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1520: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1521: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1522: } else {
1523: $newvalues{$entry} .= ':';
1524: }
1525: }
1526: }
1527: }
1528: }
1529: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1530: if ($newvalues{$entry} ne $values->{$entry}) {
1531: $changes->{$entry} = $newvalues{$entry};
1532: }
1533: }
1.115 raeburn 1534: } elsif ($entry eq 'timezone') {
1535: if ($env{'form.'.$entry}) {
1536: $newvalues{$entry} = $env{'form.'.$entry};
1537: if ($newvalues{$entry} ne $values->{$entry}) {
1538: $changes->{$entry} = $newvalues{$entry};
1539: }
1540: if ($env{'form.tzover'}) {
1541: $newvalues{'tzover'} = $env{'form.tzover'};
1542: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1543: $changes->{'tzover'} = $newvalues{'tzover'};
1544: }
1545: } elsif ($values->{'tzover'}) {
1546: $changes->{'tzover'} = '';
1547: }
1548: } elsif ($values->{$entry}) {
1549: $changes->{$entry} = '';
1550: }
1.3 raeburn 1551: } else {
1552: $newvalues{$entry} = $env{'form.'.$entry};
1553: }
1.124 raeburn 1554: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1.115 raeburn 1555: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1556: if ($newvalues{$entry} ne $values->{$entry}) {
1557: $changes->{$entry} = $newvalues{$entry};
1558: }
1.3 raeburn 1559: }
1560: }
1561: }
1562: }
1563: }
1564: }
1.93 raeburn 1565: return $errors;
1566: }
1567:
1.102 raeburn 1568: sub process_linkprot {
1.108 raeburn 1569: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.118 raeburn 1570: my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1571: if (ref($values) eq 'HASH') {
1572: foreach my $id (keys(%{$values})) {
1573: if ($id =~ /^\d+$/) {
1574: unless (ref($values->{$id}) eq 'HASH') {
1575: $linkprot{$id} = '';
1576: }
1577: }
1578: }
1579: }
1.118 raeburn 1580: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.102 raeburn 1581: if ($context eq 'domain') {
1582: $dest = '/adm/domainprefs';
1583: $ltiauth = 1;
1584: } else {
1585: $dest = '/adm/courseprefs';
1586: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1587: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1588: } else {
1589: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1590: $ltiauth = $domdefs{'crsltiauth'};
1591: }
1592: }
1593: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1594: my (@items,%deletions,%itemids,%haschanges);
1595: if ($env{'form.linkprot_add'}) {
1596: my $name = $env{'form.linkprot_name_add'};
1597: $name =~ s/(`)/'/g;
1598: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1599: if ($newid) {
1600: $itemids{'add'} = $newid;
1601: push(@items,'add');
1602: $haschanges{$newid} = 1;
1603: } else {
1604: $errors .= '<span class="LC_error">'.
1605: &mt('Failed to acquire unique ID for link protection').
1606: '</span>';
1607: }
1608: }
1609: if (ref($values) eq 'HASH') {
1610: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1611: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1612: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1613: my $itemid = $env{'form.linkprot_id_'.$i};
1614: $itemid =~ s/\D+//g;
1615: if ($itemid) {
1616: if (ref($values->{$itemid}) eq 'HASH') {
1617: push(@items,$i);
1618: $itemids{$i} = $itemid;
1619: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1620: $deletions{$itemid} = $values->{$itemid}->{'name'};
1621: }
1622: }
1623: }
1624: }
1625: }
1626: foreach my $idx (@items) {
1627: my $itemid = $itemids{$idx};
1628: next unless ($itemid);
1629: if (exists($deletions{$itemid})) {
1630: $linkprot{$itemid} = $deletions{$itemid};
1631: $haschanges{$itemid} = 1;
1632: next;
1633: }
1634: my %current;
1635: if (ref($values) eq 'HASH') {
1636: if (ref($values->{$itemid}) eq 'HASH') {
1637: foreach my $key (keys(%{$values->{$itemid}})) {
1638: $current{$key} = $values->{$itemid}->{$key};
1639: }
1640: }
1641: }
1642: foreach my $inner ('name','lifetime','version') {
1643: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1644: $env{$formitem} =~ s/(`)/'/g;
1645: if ($inner eq 'lifetime') {
1646: $env{$formitem} =~ s/[^\d.]//g;
1647: }
1648: unless ($idx eq 'add') {
1649: if ($current{$inner} ne $env{$formitem}) {
1650: $haschanges{$itemid} = 1;
1651: }
1652: }
1653: if ($env{$formitem} ne '') {
1654: $linkprot{$itemid}{$inner} = $env{$formitem};
1655: }
1656: }
1.112 raeburn 1657: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1658: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1659: if ($env{$urlitem} == 1) {
1660: $env{$urlparamname} =~ s/(`)/'/g;
1661: } elsif (exists($env{$urlparamname})) {
1662: $env{$urlparamname} = '';
1663: }
1.122 raeburn 1664: my $passback = 'form.linkprot_passback_'.$idx;
1665: my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
1666: if ($env{$passback} == 1) {
1667: unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
1668: $env{$passbackparamname} = '';
1669: }
1670: } elsif (exists($env{$passbackparamname})) {
1671: $env{$passbackparamname} = '';
1672: }
1.112 raeburn 1673: unless ($idx eq 'add') {
1674: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1675: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1676: $haschanges{$itemid} = 1;
1677: }
1.122 raeburn 1678: if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
1679: ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
1680: $haschanges{$itemid} = 1;
1681: }
1.112 raeburn 1682: }
1.123 raeburn 1683: if ($env{$urlparamname} ne '') {
1684: $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1685: }
1.122 raeburn 1686: if ($env{$passbackparamname} ne '') {
1687: $linkprot{$itemid}{'passback'} = 1;
1688: $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1.112 raeburn 1689: }
1.102 raeburn 1690: if ($ltiauth) {
1691: my $reqitem = 'form.linkprot_requser_'.$idx;
1692: $env{$reqitem} =~ s/(`)/'/g;
1693: unless ($idx eq 'add') {
1.104 raeburn 1694: if ((!$current{'requser'} && $env{$reqitem}) ||
1695: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1696: $haschanges{$itemid} = 1;
1697: }
1698: }
1699: if ($env{$reqitem} == 1) {
1700: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1701: foreach my $inner ('mapuser','notstudent') {
1702: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1703: $env{$formitem} =~ s/(`)/'/g;
1704: if ($inner eq 'mapuser') {
1705: if ($env{$formitem} eq 'other') {
1706: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1707: $mapuser =~ s/(`)/'/g;
1708: $mapuser =~ s/^\s+|\s+$//g;
1709: if ($mapuser ne '') {
1710: $linkprot{$itemid}{$inner} = $mapuser;
1711: } else {
1712: delete($linkprot{$itemid}{'requser'});
1713: last;
1714: }
1715: } elsif ($env{$formitem} eq 'sourcedid') {
1716: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1717: } elsif ($env{$formitem} eq 'email') {
1718: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1719: }
1720: } else {
1721: $linkprot{$itemid}{$inner} = $env{$formitem};
1722: }
1723: unless ($idx eq 'add') {
1724: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1725: $haschanges{$itemid} = 1;
1726: }
1727: }
1728: }
1729: }
1730: }
1731: unless ($switchserver) {
1732: my $keyitem = 'form.linkprot_key_'.$idx;
1733: $env{$keyitem} =~ s/(`)/'/g;
1734: unless ($idx eq 'add') {
1735: if ($current{'key'} ne $env{$keyitem}) {
1736: $haschanges{$itemid} = 1;
1737: }
1738: }
1739: if ($env{$keyitem} ne '') {
1740: $linkprot{$itemid}{'key'} = $env{$keyitem};
1741: }
1742: my $secretitem = 'form.linkprot_secret_'.$idx;
1743: $env{$secretitem} =~ s/(`)/'/g;
1744: if ($current{'usable'}) {
1745: if ($env{'form.linkprot_changesecret_'.$idx}) {
1746: if ($env{$secretitem} ne '') {
1.103 raeburn 1747: if ($privnum && $cipher) {
1748: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1749: $linkprot{$itemid}{'cipher'} = $privnum;
1750: } else {
1751: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1752: }
1.102 raeburn 1753: $haschanges{$itemid} = 1;
1754: }
1755: } else {
1756: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1757: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1758: }
1759: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1760: if ($privnum && $cipher) {
1761: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1762: $linkprot{$itemid}{'cipher'} = $privnum;
1763: } else {
1764: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1765: }
1.102 raeburn 1766: $haschanges{$itemid} = 1;
1767: }
1768: }
1769: }
1770: if (keys(%haschanges)) {
1771: foreach my $entry (keys(%haschanges)) {
1772: $changes->{$entry} = $linkprot{$entry};
1773: }
1.108 raeburn 1774: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1775: $lastactref->{'courselti'} = 1;
1.108 raeburn 1776: }
1.102 raeburn 1777: }
1778: return $errors;
1779: }
1780:
1781: sub get_linkprot_id {
1782: my ($cdom,$cnum,$name,$context) = @_;
1783: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1784: my $lockhash = {
1785: lock => $env{'user.name'}.
1786: ':'.$env{'user.domain'},
1787: };
1788: my $tries = 0;
1.102 raeburn 1789: my $gotlock;
1790: if ($context eq 'domain') {
1791: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1792: } else {
1793: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1794: }
1.93 raeburn 1795: my ($id,$error);
1796: while (($gotlock ne 'ok') && ($tries<10)) {
1797: $tries ++;
1798: sleep (0.1);
1.102 raeburn 1799: if ($context eq 'domain') {
1.124 raeburn 1800: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1.102 raeburn 1801: } else {
1802: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1803: }
1.93 raeburn 1804: }
1805: if ($gotlock eq 'ok') {
1.102 raeburn 1806: my %currids;
1807: if ($context eq 'domain') {
1808: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1809: } else {
1810: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1811: }
1.93 raeburn 1812: if ($currids{'lock'}) {
1813: delete($currids{'lock'});
1814: if (keys(%currids)) {
1815: my @curr = sort { $a <=> $b } keys(%currids);
1816: if ($curr[-1] =~ /^\d+$/) {
1817: $id = 1 + $curr[-1];
1818: } else {
1819: $id = 1;
1820: }
1821: } else {
1822: $id = 1;
1823: }
1824: if ($id) {
1.102 raeburn 1825: if ($context eq 'domain') {
1826: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1827: $error = 'nostore';
1828: }
1829: } else {
1830: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1831: $error = 'nostore';
1832: }
1.93 raeburn 1833: }
1834: } else {
1835: $error = 'nonumber';
1836: }
1837: }
1.124 raeburn 1838: my $dellockoutcome;
1.102 raeburn 1839: if ($context eq 'domain') {
1840: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1841: } else {
1842: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1843: }
1.93 raeburn 1844: } else {
1845: $error = 'nolock';
1846: }
1847: return ($id,$error);
1.3 raeburn 1848: }
1849:
1.118 raeburn 1850: sub get_credentials {
1851: my ($cdom,$cnum,$type,$context) = @_;
1852: my ($cipher,$privnum,$home);
1853: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1854: my @ids=&Apache::lonnet::current_machine_ids();
1855: if ($context eq 'domain') {
1856: $home = &Apache::lonnet::domain($cdom,'primary');
1857: } else {
1858: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1859: }
1860: my ($hostskey,$domkey,$crskey);
1861: if ($type eq 'ltitools') {
1862: $hostskey = 'toolprivhosts';
1863: $domkey = 'toolenc_dom';
1864: $crskey = 'toolenc_crs';
1865: } else {
1866: $hostskey = 'ltiprivhosts';
1867: $domkey = 'linkprotenc_dom';
1868: $crskey = 'linkprotenc_crs';
1869: }
1870: if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1871: (($context eq 'course') && ($domdefs{$crskey}))) {
1872: unless (($home eq 'no_host') || ($home eq '')) {
1873: if (grep(/^\Q$home\E$/,@ids)) {
1874: if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1875: if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1876: my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1877: my $privkey = $privhash{'key'};
1878: $privnum = $privhash{'version'};
1879: if (($privnum) && ($privkey ne '')) {
1880: $cipher = Crypt::CBC->new({'key' => $privkey,
1881: 'cipher' => 'DES'});
1882: }
1883: }
1884: }
1885: }
1886: }
1887: }
1888: return ($cipher,$privnum);
1889: }
1890:
1891: sub process_ltitools {
1892: my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1893: $author_ok,$confname) = @_;
1894: my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1895:
1896: my (%posslti,%possfield);
1897: my @courseroles = ('cc','in','ta','ep','st');
1898: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1899: map { $posslti{$_} = 1; } @ltiroles;
1900: my @allfields = ('fullname','firstname','lastname','email','user','roles');
1901: map { $possfield{$_} = 1; } @allfields;
1902:
1.120 raeburn 1903: my ($dest,$privnum,$cipher);
1.118 raeburn 1904:
1905: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1906: if ($context eq 'domain') {
1907: $dest = '/adm/domainprefs';
1908: } else {
1909: $dest = '/adm/courseprefs';
1910: }
1911: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1912:
1913: my (@allpos,@items,%deletions,%itemids,%haschanges);
1914: if ($env{'form.ltitools_add'}) {
1915: my $title = $env{'form.ltitools_add_title'};
1916: $title =~ s/(`)/'/g;
1.125 ! raeburn 1917: my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
1.118 raeburn 1918: if ($newid) {
1919: my $position = $env{'form.ltitools_add_pos'};
1920: $position =~ s/\D+//g;
1921: if ($position ne '') {
1922: $allpos[$position] = $newid;
1923: }
1924: $haschanges{$newid} = 1;
1925: foreach my $item ('title','url','lifetime') {
1926: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1927: if ($item eq 'lifetime') {
1928: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1929: }
1930: if ($env{'form.ltitools_add_'.$item}) {
1931: $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1932: }
1933: }
1934: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1935: $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1936: }
1937: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1938: $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1939: }
1940: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1941: $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1942: } else {
1943: $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1944: }
1945: foreach my $item ('width','height','linktext','explanation') {
1946: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1947: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1948: if (($item eq 'width') || ($item eq 'height')) {
1949: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1950: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1951: }
1952: } else {
1953: if ($env{'form.ltitools_add_'.$item} ne '') {
1954: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1955: }
1956: }
1957: }
1958: if ($env{'form.ltitools_add_target'} eq 'window') {
1959: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1960: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1961: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1962: } else {
1963: $ltitools{$newid}{'display'}{'target'} = 'iframe';
1964: }
1965: foreach my $item ('passback','roster') {
1966: if ($env{'form.ltitools_'.$item.'_add'}) {
1967: $ltitools{$newid}{$item} = 1;
1968: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1969: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1970: $lifetime =~ s/^\s+|\s+$//g;
1971: if ($lifetime =~ /^\d+\.?\d*$/) {
1972: $ltitools{$newid}{$item.'valid'} = $lifetime;
1973: }
1974: }
1975: }
1976: }
1977: if ($env{'form.ltitools_add_image.filename'} ne '') {
1978: my ($imageurl,$error) =
1979: &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
1980: $newid,$configuserok,$lonhost,$author_ok);
1981: if ($imageurl) {
1982: $ltitools{$newid}{'image'} = $imageurl;
1983: }
1984: if ($error) {
1985: &Apache::lonnet::logthis($error);
1986: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1987: }
1988: }
1989: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
1990: foreach my $field (@fields) {
1991: if ($possfield{$field}) {
1992: if ($field eq 'roles') {
1993: foreach my $role (@courseroles) {
1994: my $choice = $env{'form.ltitools_add_roles_'.$role};
1995: if (($choice ne '') && ($posslti{$choice})) {
1996: $ltitools{$newid}{'roles'}{$role} = $choice;
1997: if ($role eq 'cc') {
1998: $ltitools{$newid}{'roles'}{'co'} = $choice;
1999: }
2000: }
2001: }
2002: } else {
2003: $ltitools{$newid}{'fields'}{$field} = 1;
2004: }
2005: }
2006: }
2007: if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
2008: if ($ltitools{$newid}{'fields'}{'user'}) {
2009: if ($env{'form.ltitools_add_userincdom'}) {
2010: $ltitools{$newid}{'incdom'} = 1;
2011: }
2012: }
2013: }
2014: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
2015: foreach my $item (@courseconfig) {
2016: $ltitools{$newid}{'crsconf'}{$item} = 1;
2017: }
2018: if ($env{'form.ltitools_add_custom'}) {
2019: my $name = $env{'form.ltitools_add_custom_name'};
2020: my $value = $env{'form.ltitools_add_custom_value'};
2021: $value =~ s/(`)/'/g;
2022: $name =~ s/(`)/'/g;
2023: $ltitools{$newid}{'custom'}{$name} = $value;
2024: }
2025: unless ($switchserver) {
2026: my $keyitem = 'form.ltitools_add_key';
2027: $env{$keyitem} =~ s/(`)/'/g;
2028: if ($env{$keyitem} ne '') {
2029: $ltitools{$newid}{'key'} = $env{$keyitem};
2030: }
1.119 raeburn 2031: my $secretitem = 'form.ltitools_secret_add';
1.118 raeburn 2032: $env{$secretitem} =~ s/(`)/'/g;
2033: if ($env{$secretitem} ne '') {
2034: if ($privnum && $cipher) {
2035: $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2036: $ltitools{$newid}{'cipher'} = $privnum;
2037: } else {
2038: $ltitools{$newid}{'secret'} = $env{$secretitem};
2039: }
2040: }
2041: }
2042: } else {
2043: $errors .= '<li><span class="LC_error">'.
2044: &mt('Failed to acquire unique ID for new external tool').
2045: '</span></li>';
2046: }
2047: }
2048: if (ref($values) eq 'HASH') {
2049: my %deletions;
2050: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2051: if (@todelete) {
2052: map { $deletions{$_} = 1; } @todelete;
2053: }
2054: my %customadds;
2055: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2056: if (@newcustom) {
2057: map { $customadds{$_} = 1; } @newcustom;
2058: }
2059: my %imgdeletions;
2060: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2061: if (@todeleteimages) {
2062: map { $imgdeletions{$_} = 1; } @todeleteimages;
2063: }
2064: my $maxnum = $env{'form.ltitools_maxnum'};
2065: for (my $i=0; $i<=$maxnum; $i++) {
2066: my $itemid = $env{'form.ltitools_id_'.$i};
2067: $itemid =~ s/\D+//g;
2068: if (ref($values->{$itemid}) eq 'HASH') {
2069: if ($deletions{$itemid}) {
2070: if ($values->{$itemid}{'image'}) {
2071: #FIXME need to obsolete item in RES space
2072: }
2073: $haschanges{$itemid} = $values->{$itemid}{'title'};
2074: next;
2075: } else {
2076: my $newpos = $env{'form.ltitools_'.$itemid};
2077: $newpos =~ s/\D+//g;
2078: foreach my $item ('title','url','lifetime') {
2079: $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2080: if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2081: $haschanges{$itemid} = 1;
2082: }
2083: }
2084: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2085: $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2086: }
2087: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2088: $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2089: }
2090: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2091: $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2092: } else {
2093: $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2094: }
2095: if ($values->{$itemid}{'sigmethod'} eq '') {
2096: if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2097: $haschanges{$itemid} = 1;
2098: }
2099: } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2100: $haschanges{$itemid} = 1;
2101: }
2102: foreach my $size ('width','height') {
2103: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2104: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2105: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2106: $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2107: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2108: if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2109: $haschanges{$itemid} = 1;
2110: }
2111: } else {
2112: $haschanges{$itemid} = 1;
2113: }
2114: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2115: if ($values->{$itemid}{'display'}{$size} ne '') {
2116: $haschanges{$itemid} = 1;
2117: }
2118: }
2119: }
2120: foreach my $item ('linktext','explanation') {
2121: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2122: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2123: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2124: $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2125: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2126: if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2127: $haschanges{$itemid} = 1;
2128: }
2129: } else {
2130: $haschanges{$itemid} = 1;
2131: }
2132: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2133: if ($values->{$itemid}{'display'}{$item} ne '') {
2134: $haschanges{$itemid} = 1;
2135: }
2136: }
2137: }
2138: if ($env{'form.ltitools_target_'.$i} eq 'window') {
2139: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2140: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2141: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2142: } else {
2143: $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2144: }
2145: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2146: if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2147: $haschanges{$itemid} = 1;
2148: }
2149: } else {
2150: $haschanges{$itemid} = 1;
2151: }
2152: foreach my $extra ('passback','roster') {
2153: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2154: $ltitools{$itemid}{$extra} = 1;
2155: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2156: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2157: $lifetime =~ s/^\s+|\s+$//g;
2158: if ($lifetime =~ /^\d+\.?\d*$/) {
2159: $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2160: }
2161: }
2162: }
2163: if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2164: $haschanges{$itemid} = 1;
2165: }
2166: if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2167: $haschanges{$itemid} = 1;
2168: }
2169: }
2170: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2171: foreach my $item ('label','title','target','linktext','explanation','append') {
2172: if (grep(/^\Q$item\E$/,@courseconfig)) {
2173: $ltitools{$itemid}{'crsconf'}{$item} = 1;
2174: if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2175: if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2176: $haschanges{$itemid} = 1;
2177: }
2178: } else {
2179: $haschanges{$itemid} = 1;
2180: }
2181: }
2182: }
2183: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2184: foreach my $field (@fields) {
2185: if ($possfield{$field}) {
2186: if ($field eq 'roles') {
2187: foreach my $role (@courseroles) {
2188: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2189: if (($choice ne '') && ($posslti{$choice})) {
2190: $ltitools{$itemid}{'roles'}{$role} = $choice;
2191: if ($role eq 'cc') {
2192: $ltitools{$itemid}{'roles'}{'co'} = $choice;
2193: }
2194: }
2195: if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2196: if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2197: $haschanges{$itemid} = 1;
2198: }
2199: } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2200: $haschanges{$itemid} = 1;
2201: }
2202: }
2203: } else {
2204: $ltitools{$itemid}{'fields'}{$field} = 1;
2205: if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2206: if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2207: $haschanges{$itemid} = 1;
2208: }
2209: } else {
2210: $haschanges{$itemid} = 1;
2211: }
2212: }
2213: }
2214: }
2215: if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2216: if ($ltitools{$itemid}{'fields'}{'user'}) {
2217: if ($env{'form.ltitools_userincdom_'.$i}) {
2218: $ltitools{$itemid}{'incdom'} = 1;
2219: }
2220: if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2221: $haschanges{$itemid} = 1;
2222: }
2223: }
2224: }
2225: $allpos[$newpos] = $itemid;
2226: }
2227: if ($imgdeletions{$itemid}) {
2228: $haschanges{$itemid} = 1;
2229: if ($context eq 'course') {
2230: my $currimgurl = $values->{$itemid}{'image'};
2231: if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2232: my ($path,$imagefile) = ($1,$2);
2233: if ($imagefile =~ /^tn\-(.+)$/) {
2234: my $origimg = $1;
2235: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2236: }
2237: &Apache::lonnet::removeuploadedurl($currimgurl);
2238: }
2239: }
2240: #FIXME need to obsolete item in RES space
2241: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2242: my $currimgurl = $values->{$itemid}{'image'};
2243: my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2244: $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2245: if ($imgurl) {
2246: $ltitools{$itemid}{'image'} = $imgurl;
2247: $haschanges{$itemid} = 1;
2248: }
2249: if ($error) {
2250: &Apache::lonnet::logthis($error);
2251: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2252: }
2253: } elsif ($values->{$itemid}{'image'}) {
2254: $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2255: }
2256: if ($customadds{$i}) {
2257: my $name = $env{'form.ltitools_custom_name_'.$i};
2258: $name =~ s/(`)/'/g;
2259: $name =~ s/^\s+//;
2260: $name =~ s/\s+$//;
2261: my $value = $env{'form.ltitools_custom_value_'.$i};
2262: $value =~ s/(`)/'/g;
2263: $value =~ s/^\s+//;
2264: $value =~ s/\s+$//;
2265: if ($name ne '') {
2266: $ltitools{$itemid}{'custom'}{$name} = $value;
2267: $haschanges{$itemid} = 1;
2268: }
2269: }
2270: my %customdels;
2271: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2272: if (@customdeletions) {
2273: $haschanges{$itemid} = 1;
2274: }
2275: map { $customdels{$_} = 1; } @customdeletions;
2276: if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2277: foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2278: unless ($customdels{$key}) {
2279: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2280: $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2281: }
2282: if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2283: $haschanges{$itemid} = 1;
2284: }
2285: }
2286: }
2287: }
2288: unless ($switchserver) {
2289: my $keyitem = 'form.ltitools_key_'.$i;
2290: $env{$keyitem} =~ s/(`)/'/g;
2291: if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2292: $haschanges{$itemid} = 1;
2293: }
2294: if ($env{$keyitem} ne '') {
2295: $ltitools{$itemid}{'key'} = $env{$keyitem};
2296: }
2297: my $secretitem = 'form.ltitools_secret_'.$i;
2298: $env{$secretitem} =~ s/(`)/'/g;
2299: if ($values->{$itemid}{'usable'}) {
2300: if ($env{'form.ltitools_changesecret_'.$i}) {
2301: if ($env{$secretitem} ne '') {
2302: if ($privnum && $cipher) {
2303: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2304: $ltitools{$itemid}{'cipher'} = $privnum;
2305: } else {
2306: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2307: }
2308: $haschanges{$itemid} = 1;
2309: }
2310: } else {
2311: $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2312: $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2313: }
2314: } elsif ($env{$secretitem} ne '') {
2315: if ($privnum && $cipher) {
2316: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2317: $ltitools{$itemid}{'cipher'} = $privnum;
2318: } else {
2319: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2320: }
2321: $haschanges{$itemid} = 1;
2322: }
2323: }
2324: unless ($haschanges{$itemid}) {
2325: foreach my $key (keys(%{$values->{$itemid}})) {
2326: if (ref($values->{$itemid}{$key}) eq 'HASH') {
2327: if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2328: foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2329: unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2330: $haschanges{$itemid} = 1;
2331: last;
2332: }
2333: }
2334: } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2335: $haschanges{$itemid} = 1;
2336: }
2337: }
2338: last if ($haschanges{$itemid});
2339: }
2340: }
2341: }
2342: }
2343: }
2344: if (@allpos > 0) {
2345: my $idx = 0;
2346: foreach my $itemid (@allpos) {
2347: if ($itemid ne '') {
2348: $ltitools{$itemid}{'order'} = $idx;
2349: if (ref($values) eq 'HASH') {
2350: if (ref($values->{$itemid}) eq 'HASH') {
2351: if ($values->{$itemid}{'order'} ne $idx) {
2352: $haschanges{$itemid} = 1;
2353: }
2354: }
2355: }
2356: $idx ++;
2357: }
2358: }
2359: }
2360: if (keys(%haschanges)) {
2361: foreach my $entry (keys(%haschanges)) {
2362: $changes->{$entry} = $ltitools{$entry};
2363: }
2364: if (ref($lastactref) eq 'HASH') {
2365: $lastactref->{'courseltitools'} = 1;
2366: }
2367: }
2368: return $errors;
2369: }
2370:
2371: sub process_ltitools_image {
2372: my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2373: my $filename = $env{'form.'.$caller.'.filename'};
2374: my ($error,$url);
2375: my ($width,$height) = (21,21);
2376: if ($configuserok eq 'ok') {
2377: if ($switch) {
2378: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2379: $switch);
2380: } elsif ($author_ok eq 'ok') {
2381: my ($result,$imageurl,$madethumb);
2382: if ($context eq 'domain') {
2383: ($result,$imageurl,$madethumb) =
2384: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2385: "ltitools/$itemid/icon",$width,$height);
2386: } else {
2387: ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2388: }
2389: if ($result eq 'ok') {
2390: if ($madethumb) {
2391: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2392: my $imagethumb = "$path/tn-".$imagefile;
2393: $url = $imagethumb;
2394: } else {
2395: $url = $imageurl;
2396: }
2397: } else {
2398: if ($context eq 'domain') {
2399: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2400: } else {
2401: $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2402: }
2403: }
2404: } else {
2405: $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);
2406: }
2407: } else {
2408: $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);
2409: }
2410: return ($url,$error);
2411: }
2412:
2413: sub processlogo {
2414: my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2415: my ($result,$imageurl,$madethumb);
2416: if ($env{"form.$caller.filename"} ne '') {
2417: unless ($caller eq 'ltitools_add_image') {
2418: if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2419: my ($path,$imagefile) = ($1,$2);
2420: if ($imagefile =~ /^tn\-(.+)$/) {
2421: my $origimg = $1;
2422: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2423: }
2424: &Apache::lonnet::removeuploadedurl($currimg);
2425: }
2426: }
2427: $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2428: '','','',$cnum,$dom,$width,$height);
2429: if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2430: my ($path,$imagefile) = ($1,$2);
2431: $result = 'ok';
2432: my $thumburl = "$path/tn-".$imagefile;
2433: my ($rtncode,$info);
2434: my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2435: if ($res eq 'ok') {
2436: $madethumb = 1;
2437: }
2438: } elsif ($imageurl eq '/adm/notfound.html') {
2439: undef($imageurl);
2440: $result = 'store failed';
2441: } elsif ($imageurl =~ /^error: (.+)$/) {
2442: $result = $1;
2443: }
2444: }
2445: return ($result,$imageurl,$madethumb);
2446: }
2447:
1.3 raeburn 2448: sub get_sec_str {
2449: my ($entry,$num) = @_;
2450: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2451: my $secstr;
2452: if (grep(/^\s*$/,@secs)) {
2453: $secstr = '';
2454: } elsif (@secs > 0) {
2455: $secstr = join(';',@secs);
2456: }
2457: if ($secstr ne '') {
2458: return '('.$secstr.')';
2459: }
2460: return;
2461: }
2462:
2463: sub check_clone {
2464: my ($clonedom,$disallowed,$clonename) = @_;
2465: return if (ref($disallowed) ne 'HASH');
2466: if ($clonedom !~ /^$match_domain$/) {
2467: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2468: return;
2469: } elsif (!&Apache::lonnet::domain($clonedom)) {
2470: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2471: return;
2472: }
2473: if ($clonename ne '') {
2474: if ($clonename !~ /^$match_username$/) {
2475: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2476: return;
2477: } else {
2478: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2479: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2480: return;
2481: }
2482: }
2483: }
2484: return 'ok';
2485: }
2486:
2487: sub store_changes {
1.9 raeburn 2488: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2489: my ($chome,$output);
1.118 raeburn 2490: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2491: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 2492: if (ref($values->{'linkprot'}) eq 'HASH') {
2493: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 2494: }
1.102 raeburn 2495: delete($values->{'linkprot'});
1.118 raeburn 2496: if (ref($values->{'ltitools'}) eq 'HASH') {
2497: %oldltitools = %{$values->{'ltitools'}};
2498: }
1.3 raeburn 2499: %storehash = %{$values};
2500: } else {
1.9 raeburn 2501: if ($crstype eq 'Community') {
2502: $output = &mt('No changes made to community settings.');
2503: } else {
2504: $output = &mt('No changes made to course settings.');
2505: }
2506: return $output;
1.3 raeburn 2507: }
1.93 raeburn 2508: my ($numchanges,$skipstore);
2509: if (ref($changes) eq 'HASH') {
2510: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 2511: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 2512: $skipstore = 1;
1.118 raeburn 2513: } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2514: $skipstore = 1;
1.93 raeburn 2515: } elsif (!$numchanges) {
2516: if ($crstype eq 'Community') {
2517: $output = &mt('No changes made to community settings.');
2518: } else {
2519: $output = &mt('No changes made to course settings.');
2520: }
2521: return $output;
2522: }
2523: }
1.3 raeburn 2524: my %yesno = (
2525: hidefromcat => '1',
2526: problem_stream_switch => '1',
2527: suppress_tries => '1',
2528: disableexampointprint => '1',
2529: hideemptyrows => '1',
2530: suppress_embed_prompt => '1',
2531: );
2532: foreach my $item (@{$prefs_order}) {
2533: if (grep(/^\Q$item\E$/,@{$actions})) {
2534: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2535: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 2536: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2537: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2538: if ($item eq 'other') {
2539: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2540: $storehash{$key} = $changes->{$item}{$key};
2541: if ($changes->{$item}{$key} eq '') {
2542: push(@delkeys,$key);
1.22 wenzelju 2543: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2544: } else {
1.22 wenzelju 2545: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2546: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2547: }
2548: }
1.102 raeburn 2549: } elsif ($item eq 'linkprot') {
2550: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.118 raeburn 2551: } elsif ($item eq 'ltitools') {
2552: $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2553: } else {
2554: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2555: my @settings = @{$prefs->{$item}->{'ordered'}};
2556: if ($item eq 'feedback') {
2557: push(@settings,(map { $_.'.text'; } @settings));
2558: }
2559: foreach my $key (@settings) {
2560: if ($key eq 'rolenames') {
2561: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2562: my $msg;
1.9 raeburn 2563: my @roles;
2564: if ($crstype eq 'Community') {
2565: @roles = ('co');
2566: } else {
2567: @roles = ('cc');
2568: }
2569: push(@roles,('in','ta','ep','ad','st'));
2570: foreach my $role (@roles) {
1.3 raeburn 2571: next if (!exists($changes->{$item}{$key.'_'.$role}));
2572: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2573: my $newname = $changes->{$item}{$key.'_'.$role};
2574: $storehash{$role.'.plaintext'} = $newname;
2575: if ($newname eq '') {
2576: $newname = $stdname;
2577: }
2578: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2579: "'<b>".$newname."</b>'").'</li>';
2580: }
2581: if ($msg ne '') {
1.22 wenzelju 2582: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2583: }
1.115 raeburn 2584: } elsif ($key eq 'timezone') {
2585: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2586: my ($displayname,$text);
2587: $text = $prefs->{$item}->{'itemtext'}{$key};
2588: my $displayval;
2589: if (exists($changes->{$item}{$key})) {
2590: $displayname = &mt($text);
2591: $storehash{$key} = $changes->{$item}{$key};
2592: if ($changes->{$item}{$key} ne '') {
2593: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2594: } else {
2595: push(@delkeys,$key);
2596: if (exists($values->{'tzover'})) {
2597: push(@delkeys,'tzover');
2598: }
2599: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2600: '<i>'.$displayname.'</i>')).'</li>';
2601: }
2602: }
2603: unless (grep(/^\Q$key\E$/,@delkeys)) {
2604: if (exists($changes->{$item}{'tzover'})) {
2605: $storehash{'tzover'} = $changes->{$item}{'tzover'};
2606: my $tzovertext;
2607: if ($changes->{$item}{'tzover'} ne '') {
2608: $tzovertext = &mt('Course Time Zone overrides individual user preference');
2609: } else {
2610: push(@delkeys,'tzover');
2611: $tzovertext = &mt('Course Time Zone does not override individual user preference');
2612: }
2613: if ($displayval eq '') {
2614: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2615: } else {
2616: $displayval .= '<br />'.(' 'x5).$tzovertext;
2617: }
2618: }
2619: if ($displayval ne '') {
2620: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2621: '<i>'.$displayname.'</i>',$displayval)).'</li>';
2622: }
2623: }
1.3 raeburn 2624: } else {
2625: next if (!exists($changes->{$item}{$key}));
2626: my ($displayname,$text);
2627: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2628: my $displayval;
1.114 raeburn 2629: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2630: $displayval = $changes->{$item}{$key};
2631: }
1.3 raeburn 2632: if ($item eq 'feedback') {
2633: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2634: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2635: $displayname = &mt('Custom text for '.$text.' questions');
2636: } else {
2637: $displayname = &mt('Recipients of '.$text.' questions');
2638: }
2639: } elsif ($item eq 'discussion') {
2640: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2641: $displayname = &mt("$text (role-based)");
2642: if ($displayval ne '') {
2643: my @roles = split(',',$displayval);
2644: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2645: $displayval = join(', ',@roles);
2646: }
2647: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2648: $displayname = &mt("$text (specific user(s))");
2649: } else {
2650: if ($key eq 'allow_discussion_post_editing') {
2651: if ($displayval ne '') {
2652: my @roles = split(',',$displayval);
2653: my @longroles;
2654: foreach my $role (@roles) {
2655: my ($trole,$sec) = split(':',$role);
2656: my $rolename =
2657: &Apache::lonnet::plaintext($trole);
2658: if ($sec ne '') {
2659: $rolename .= ':'.$sec;
2660: }
2661: push(@longroles,$rolename);
2662: }
2663: $displayval = join(', ',@longroles);
2664: }
1.50 raeburn 2665: } elsif ($key eq 'discussion_post_fonts') {
2666: my ($classorder,$classtitles)=&discussion_vote_classes();
2667: my ($styleorder,$styleitems)=&discussion_vote_styles();
2668: my $count = 1;
2669: my $total = scalar(keys(%{$changes->{$item}}));
2670: foreach my $class (@{$classorder}) {
2671: $count ++;
2672: next unless ($changes->{$item}{$key.'_'.$class});
2673: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2674: my $showval = '';
2675: for (my $i=0; $i<@{$styleorder}; $i++) {
2676: if ($vals[$i] ne '') {
2677: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2678: }
2679: }
2680: if ($vals[3] ne '') {
2681: $showval .= $vals[3];
2682: }
2683: if ($showval ne '') {
2684: $displayval .= $classtitles->{$class}.':{ '.
2685: $showval.'}';
2686: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2687: } else {
2688: $displayval .= $classtitles->{$class}.': '.&mt('None');
2689: push(@delkeys,$key.'_'.$class);
2690: }
2691: unless ($count == $total) {
2692: $displayval .= (' 'x2);
2693: }
2694: }
1.3 raeburn 2695: }
2696: $displayname = &mt($text);
2697: }
2698: } elsif ($item eq 'spreadsheet') {
2699: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2700: my $sheettype = $1;
2701: if ($sheettype eq 'studentcalc') {
2702: &Apache::lonnet::expirespread('','','studentcalc');
2703: } else {
2704: &Apache::lonnet::expirespread('','','assesscalc');
2705: &Apache::lonnet::expirespread('','','studentcalc');
2706: }
2707: }
2708: $displayname = &mt($text);
1.87 raeburn 2709: } elsif ($item eq 'lti') {
2710: if ($key eq 'lti.lcmenu') {
2711: if ($changes->{$item}{$key} eq 'none') {
2712: $displayval = &mt('None of the configurable menu items displayed');
2713: } else {
2714: my %ltititles = <imenu_titles();
2715: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2716: }
2717: } else {
2718: if ($changes->{$item}{$key} eq '1') {
2719: $displayval = &mt('Yes');
2720: } elsif ($changes->{$item}{$key} eq '') {
2721: $displayval = &mt('No');
2722: }
2723: }
2724: $displayname = &mt($text);
1.91 raeburn 2725: } elsif ($item eq 'menuitems') {
2726: unless ($changes->{$item}{$key} eq '') {
2727: if ($key eq 'menudefault') {
2728: $displayname = &mt('Default collection of menu items');
2729: $displayval = &mt('Collection: [_1]',
2730: $changes->{$item}{$key});
2731: } elsif ($key eq 'menucollections') {
2732: $displayval = &menucollections_display($changes->{$item}{$key});
2733: }
2734: }
1.3 raeburn 2735: } else {
2736: $displayname = &mt($text);
2737: }
2738: if (defined($yesno{$key})) {
1.14 raeburn 2739: $displayval = &mt('No');
1.3 raeburn 2740: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2741: $displayval = &mt('Yes');
1.3 raeburn 2742: }
2743: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2744: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2745: } elsif ($key eq 'categories') {
2746: $displayval = $env{'form.categories_display'};
1.95 raeburn 2747: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2748: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2749: if ($changes->{$item}{$key} eq '1') {
2750: $displayval = &mt('Yes');
2751: } elsif ($changes->{$item}{$key} eq '0') {
2752: $displayval = &mt('No');
2753: }
1.114 raeburn 2754: } elsif ($key eq 'extresource') {
2755: if ($changes->{$item}{$key} eq 'iframe') {
2756: $displayval = &mt('In iframe');
2757: } else {
2758: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2759: if ($selected eq 'tab') {
2760: if ($reuse) {
2761: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2762: "'<b>","</b>'",'<br />');
2763: } else {
2764: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2765: "'<b>","</b>'",'<br />');
2766: }
2767: } elsif ($selected eq 'window') {
2768: if ($reuse) {
2769: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2770: "'<b>","</b>'",'<br />');
2771: } else {
2772: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2773: "'<b>","</b>'",'<br />');
2774: }
2775: if (($width ne '') || ($height ne '')) {
2776: if ($width ne '') {
2777: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2778: }
2779: if ($height ne '') {
2780: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2781: }
2782: }
2783: }
2784: }
1.14 raeburn 2785: }
1.25 raeburn 2786: if ($key eq 'co-owners') {
2787: if (ref($changes->{$item}{$key}) eq 'HASH') {
2788: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2789: foreach my $type ('co-owners','pendingco-owners') {
2790: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2791: if ($type eq 'pendingco-owners') {
2792: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2793: $displayname = &mt('Invited as co-owners, pending acceptance');
2794: }
2795: }
2796: if ($changes->{$item}{$key}{$type} eq '') {
2797: push(@delkeys,'internal.'.$type);
2798: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2799: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2800: '<i>'.$displayname.'</i>')).'</li>';
2801: }
2802: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2803: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2804: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2805: '<i>'.$displayname.'</i>',
2806: "'<b>$displayval</b>'")).'</li>';
2807: }
2808: }
2809: }
2810: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2811: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2812: $displayval = &mt('on');
1.90 raeburn 2813: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2814: $displayval = '';
2815: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2816: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2817: $displayval = &mt('off');
2818: }
2819: if ($displayval) {
2820: $displayname = &mt('Your co-ownership status');
2821: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2822: '<i>'.$displayname.'</i>',
2823: "'<b>$displayval</b>'")).'</li>';
2824: }
2825: }
2826: }
2827: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2828: push(@delkeys,$key);
1.87 raeburn 2829: if ($item eq 'lti') {
2830: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2831: if (($key eq 'lti.lcmenu') &&
2832: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2833: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2834: } else {
2835: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2836: '<i>'.$displayname.'</i>',
2837: "'<b>$displayval</b>'")).'</li>';
2838: }
2839: } elsif (!exists($changes->{$item}{'lti.override'})) {
2840: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2841: }
1.91 raeburn 2842: } elsif ($item eq 'menuitems') {
2843: if ($key eq 'menudefault') {
2844: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2845: } elsif ($key eq 'menucollections') {
2846: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2847: }
1.87 raeburn 2848: } else {
2849: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2850: '<i>'.$displayname.'</i>')).'</li>';
2851: }
1.91 raeburn 2852: } elsif ($key eq 'menucollections') {
2853: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2854: $displayval.'</li>';
1.3 raeburn 2855: } else {
1.114 raeburn 2856: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2857: $displayval = "'<b>$displayval</b>'";
2858: }
1.22 wenzelju 2859: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2860: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2861: if ($key eq 'url') {
2862: my $bkuptime=time;
2863: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2864: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2865: }
2866: $output .= '</li>';
2867: }
1.25 raeburn 2868: if ($key eq 'co-owners') {
2869: if (ref($changes->{$item}{$key}) eq 'HASH') {
2870: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2871: foreach my $type ('co-owners','pendingco-owners') {
2872: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2873: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2874: }
2875: }
2876: }
2877: } else {
1.50 raeburn 2878: unless ($key eq 'discussion_post_fonts') {
2879: $storehash{$key} = $changes->{$item}{$key};
2880: }
1.25 raeburn 2881: }
1.3 raeburn 2882: }
1.23 raeburn 2883: if ($key eq 'cloners') {
2884: # Get existing cloners
2885: my %clonenames =
2886: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2887: if ($clonenames{'cloners'} =~ /,/) {
2888: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2889: } else {
2890: $oldcloner[0] = $clonenames{'cloners'};
2891: }
2892: }
1.3 raeburn 2893: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2894: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2895: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2896: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2897: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2898: push(@need_env_update,$key);
2899: }
2900: }
2901: }
2902: }
2903: $output .= '</ul>';
2904: } else {
1.9 raeburn 2905: if ($crstype eq 'Community') {
1.46 raeburn 2906: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2907: } else {
1.46 raeburn 2908: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2909: }
1.3 raeburn 2910: }
2911: }
2912: }
2913: }
1.93 raeburn 2914: if ($skipstore) {
2915: return $output;
2916: }
1.3 raeburn 2917: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2918: if (ref($changes) eq 'HASH') {
2919: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2920: if (exists($changes->{'courseinfo'}{'cloners'})) {
2921: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2922: \@oldcloner);
2923: }
2924: }
2925: }
1.3 raeburn 2926: if (@delkeys) {
2927: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2928: $output .= '<br /><span class="LC_error">';
2929: if ($crstype eq 'Community') {
2930: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2931: } else {
2932: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2933: }
2934: $output .= '</span>';
1.14 raeburn 2935: } else {
2936: foreach my $key (@delkeys) {
2937: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
2938: }
1.3 raeburn 2939: }
2940: }
2941: if (@need_env_update) {
2942: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2943: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
2944: }
2945: &Apache::lonnet::coursedescription($env{'request.course.id'},
2946: {'freshen_cache' => 1});
2947: } else {
1.9 raeburn 2948: $output = '<span class="LC_error">';
2949: if ($crstype eq 'Community') {
2950: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
2951: } else {
2952: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
2953: }
2954: $output .= '</span>';
1.3 raeburn 2955: }
2956: return $output;
2957: }
2958:
1.102 raeburn 2959: sub store_linkprot {
2960: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 2961: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 2962: if ($context eq 'domain') {
2963: $ltiauth = 1;
1.103 raeburn 2964: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 2965: } else {
1.103 raeburn 2966: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 2967: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
2968: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
2969: } else {
2970: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
2971: $ltiauth = $domdefs{'crsltiauth'};
2972: }
2973: }
2974: if (ref($changes) eq 'HASH') {
2975: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
2976: if (ref($changes->{$id}) eq 'HASH') {
2977: if (exists($changes->{$id}->{'key'})) {
2978: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
2979: delete($changes->{$id}->{'key'});
2980: }
2981: if (exists($changes->{$id}->{'secret'})) {
2982: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
2983: delete($changes->{$id}->{'secret'});
2984: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
2985: if (exists($oldlinkprot->{$id}{'usable'})) {
2986: $changes->{$id}->{'usable'} = 1;
2987: }
1.109 raeburn 2988: if (exists($oldlinkprot->{$id}{'cipher'})) {
2989: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
2990: }
1.102 raeburn 2991: }
2992: }
2993: }
2994: }
2995: my @ids=&Apache::lonnet::current_machine_ids();
2996: if (keys(%ltienc) > 0) {
2997: if ($context eq 'domain') {
2998: foreach my $id (keys(%ltienc)) {
2999: if (exists($ltienc{$id}{'secret'})) {
3000: $changes->{$id}->{'usable'} = 1;
3001: }
3002: }
3003: } else {
1.103 raeburn 3004: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 3005: my $allowed;
3006: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3007: if ($allowed) {
3008: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
3009: foreach my $id (keys(%ltienc)) {
3010: if (exists($ltienc{$id}{'secret'})) {
3011: $changes->{$id}->{'usable'} = 1;
3012: }
3013: }
3014: } else {
3015: $lti_save_error = 1;
3016: }
3017: }
3018: }
3019: }
3020: }
3021: unless ($lti_save_error) {
3022: if ($context eq 'course') {
3023: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3024: my $hashid=$cdom.'_'.$cnum;
3025: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 3026: unless (($home eq 'no_host') || ($home eq '')) {
3027: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 3028: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3029: }
3030: }
3031: } else {
3032: $lti_save_error = 1;
3033: }
3034: }
3035: unless ($lti_save_error) {
3036: foreach my $id (sort { $a <=> $b } %{$changes}) {
3037: if (ref($changes->{$id}) eq 'HASH') {
3038: my %values = %{$changes->{$id}};
3039: my %desc = &linkprot_names();
3040: my $display;
1.122 raeburn 3041: foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.102 raeburn 3042: if (($title eq 'key') || ($title eq 'secret')) {
3043: if (ref($ltienc{$id}) eq 'HASH') {
3044: if (exists($ltienc{$id}{$title})) {
3045: if ($title eq 'secret') {
3046: my $length = length($ltienc{$id}{$title});
1.103 raeburn 3047: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 3048: } else {
3049: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3050: }
3051: }
3052: }
3053: } elsif ($title eq 'version') {
3054: if ($values{$title} eq 'LTI-1p0') {
3055: $display .= $desc{$title}.': 1.1, ';
3056: }
1.112 raeburn 3057: } elsif ($title eq 'returnurl') {
3058: if ($values{$title}) {
1.124 raeburn 3059: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
1.112 raeburn 3060: }
1.122 raeburn 3061: } elsif ($title eq 'passbackformat') {
3062: if ($values{$title} eq '1.0') {
3063: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
3064: } elsif ($values{$title} eq '1.1') {
3065: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
3066: }
1.102 raeburn 3067: } else {
3068: $display .= $desc{$title}.': '.$values{$title}.', ';
3069: }
3070: }
3071: if ($ltiauth) {
3072: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3073: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3074: $display .= &mt('Source of username: Email address [_1]',
3075: '(lis_person_contact_email_primary)').', ';
3076: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3077: $display .= &mt('Source of username: User ID [_1]',
3078: '(lis_person_sourcedid)').', ';
3079: } else {
3080: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3081: }
3082: if ($values{'notstudent'} eq 'auth') {
3083: $display .= &mt('Display LON-CAPA login page if no match').', ';
3084: } elsif ($values{'notstudent'} eq 'reject') {
3085: $display .= &mt('Discontinue launch if no match').', ';
3086: }
3087: }
3088: }
3089: $display =~ s/, $//;
3090: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3091: "'$display'")).'</li>';
3092: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3093: my $oldname = $oldlinkprot->{$id}{'name'};
3094: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3095: }
3096: }
3097: } else {
3098: $lti_save_error = 1;
3099: }
3100: }
3101: unless ($lti_save_error) {
3102: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3103: unless (ref($changes->{$id}) eq 'HASH') {
3104: push(@deletions,$id);
3105: }
3106: }
3107: if (@deletions) {
3108: if ($context eq 'course') {
3109: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3110: }
3111: }
3112: }
3113: if ($lti_save_error) {
3114: $output .= '<li>'.
3115: '<span class="LC_error">'.
3116: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3117: '</span>'.
3118: '</li>';
3119: }
3120: return $output;
3121: }
3122:
1.118 raeburn 3123: sub store_ltitools {
3124: my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3125: my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3126: my %lt = <itools_names();
3127: my @courseroles = ('cc','in','ta','ep','st');
3128: my @allfields = ('fullname','firstname','lastname','email','user','roles');
3129: if ($context eq 'domain') {
3130: $home = &Apache::lonnet::domain($cdom,'primary');
3131: } else {
3132: $home = &Apache::lonnet::homeserver($cnum,$cdom);
3133: }
3134: if (ref($changes) eq 'HASH') {
3135: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3136: if (ref($changes->{$id}) eq 'HASH') {
3137: if (exists($changes->{$id}->{'key'})) {
3138: $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3139: delete($changes->{$id}->{'key'});
3140: }
3141: if (exists($changes->{$id}->{'secret'})) {
3142: $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3143: delete($changes->{$id}->{'secret'});
3144: } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3145: if (exists($oldltitools->{$id}{'usable'})) {
3146: $changes->{$id}->{'usable'} = 1;
3147: }
3148: if (exists($oldltitools->{$id}{'cipher'})) {
3149: $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3150: }
3151: }
3152: }
3153: }
3154: }
3155: my @ids=&Apache::lonnet::current_machine_ids();
3156: if (keys(%toolsenc) > 0) {
3157: unless (($home eq 'no_host') || ($home eq '')) {
3158: my $allowed;
3159: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3160: if ($allowed) {
3161: if (($context eq 'domain') ||
3162: (($context eq 'course') &&
3163: (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3164: foreach my $id (keys(%toolsenc)) {
3165: if (exists($toolsenc{$id}{'secret'})) {
3166: $changes->{$id}->{'usable'} = 1;
3167: }
3168: }
3169: } else {
3170: $ltitools_save_error = 1;
3171: }
3172: }
3173: }
3174: }
3175: unless ($ltitools_save_error) {
3176: if ($context eq 'course') {
3177: if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3178: my $hashid=$cdom.'_'.$cnum;
3179: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3180: unless (($home eq 'no_host') || ($home eq '')) {
3181: if (grep(/^\Q$home\E$/,@ids)) {
1.120 raeburn 3182: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
1.118 raeburn 3183: }
3184: }
3185: } else {
3186: $ltitools_save_error = 1;
3187: }
3188: }
3189: unless ($ltitools_save_error) {
3190: my %bynum;
3191: foreach my $itemid (sort(keys(%{$changes}))) {
3192: my $position = $changes->{$itemid}{'order'};
3193: $bynum{$position} = $itemid;
3194: }
3195: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3196: my $itemid = $bynum{$pos};
3197: if (ref($changes->{$itemid}) ne 'HASH') {
3198: $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3199: } else {
3200: $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3201: if ($changes->{$itemid}{'image'}) {
3202: $output .= ' '.
3203: '<img src="'.$changes->{$itemid}{'image'}.'"'.
3204: ' alt="'.&mt('Tool Provider icon').'" />';
3205: }
3206: $output .= '</li><ul>';
3207: my $position = $pos + 1;
3208: $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3209: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3210: if ($changes->{$itemid}{$item} ne '') {
3211: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3212: }
3213: }
3214: if (ref($toolsenc{$itemid}) eq 'HASH') {
3215: foreach my $item ('key','secret') {
3216: if (exists($toolsenc{$itemid}{$item})) {
3217: if ($item eq 'secret') {
3218: $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3219: } else {
3220: $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3221: }
3222: }
3223: }
3224: }
3225: $output .= '<li>'.&mt('Configurable in course:');
3226: my @possconfig = ('label','title','target','linktext','explanation','append');
3227: my $numconfig = 0;
3228: if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3229: foreach my $item (@possconfig) {
3230: if ($changes->{$itemid}{'crsconf'}{$item}) {
3231: $numconfig ++;
3232: $output .= ' "'.$lt{'crs'.$item}.'"';
3233: }
3234: }
3235: }
3236: if (!$numconfig) {
3237: $output .= ' '.&mt('None');
3238: }
3239: $output .= '</li>';
3240: foreach my $item ('passback','roster') {
3241: $output .= '<li>'.$lt{$item}.' ';
3242: if ($changes->{$itemid}{$item}) {
3243: $output .= &mt('Yes');
3244: if ($changes->{$itemid}{$item.'valid'}) {
3245: if ($item eq 'passback') {
3246: $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3247: $changes->{$itemid}{$item.'valid'});
3248: } else {
3249: $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3250: $changes->{$itemid}{$item.'valid'});
3251: }
3252: }
3253: } else {
3254: $output .= &mt('No');
3255: }
3256: $output .= '</li>';
3257: }
3258: if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3259: my $displaylist;
3260: if ($changes->{$itemid}{'display'}{'target'}) {
3261: $displaylist = &mt('Display target').': '.
3262: $changes->{$itemid}{'display'}{'target'}.',';
3263: }
3264: foreach my $size ('width','height') {
3265: if ($changes->{$itemid}{'display'}{$size}) {
3266: $displaylist .= (' 'x2).$lt{$size}.': '.
3267: $changes->{$itemid}{'display'}{$size}.',';
3268: }
3269: }
3270: if ($displaylist) {
3271: $displaylist =~ s/,$//;
3272: $output .= '<li>'.$displaylist.'</li>';
3273: }
3274: foreach my $item ('linktext','explanation') {
3275: if ($changes->{$itemid}{'display'}{$item}) {
3276: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3277: }
3278: }
3279: }
3280: if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3281: my $fieldlist;
3282: foreach my $field (@allfields) {
3283: if ($changes->{$itemid}{'fields'}{$field}) {
3284: $fieldlist .= (' 'x2).$lt{$field}.',';
3285: }
3286: }
3287: if ($fieldlist) {
3288: $fieldlist =~ s/,$//;
3289: if ($changes->{$itemid}{'fields'}{'user'}) {
3290: if ($changes->{$itemid}{'incdom'}) {
3291: $fieldlist .= ' ('.&mt('username:domain').')';
3292: } else {
3293: $fieldlist .= ' ('.&mt('username').')';
3294: }
3295: }
3296: $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3297: }
3298: }
3299: if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3300: my $rolemaps;
3301: foreach my $role (@courseroles) {
3302: if ($changes->{$itemid}{'roles'}{$role}) {
3303: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3304: $changes->{$itemid}{'roles'}{$role}.',';
3305: }
3306: }
3307: if ($rolemaps) {
3308: $rolemaps =~ s/,$//;
3309: $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3310: }
3311: }
3312: if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3313: my $customlist;
3314: if (keys(%{$changes->{$itemid}{'custom'}})) {
3315: foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3316: $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3317: }
3318: }
3319: if ($customlist) {
3320: $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3321: }
3322: }
3323: $output .= '</ul></li>';
3324: }
3325: }
3326: }
3327: }
3328: return $output;
3329: }
3330:
1.3 raeburn 3331: sub update_env {
3332: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3333: my $count = 0;
3334: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3335: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3336: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3337: foreach my $key (@{$need_env_update}) {
3338: if ($key eq 'description' && defined($storehash->{$key})) {
3339: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3340: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3341: $count ++;
3342: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3343: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3344: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3345: $count ++;
1.25 raeburn 3346: } elsif ($key eq 'co-owners') {
3347: if ($storehash->{'internal.co-owners'} ne '') {
3348: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3349: }
3350: if ($storehash->{'internal.pendingco-owners'} ne '') {
3351: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3352: }
3353: my @coowners = split(',',$storehash->{'internal.'.$key});
3354: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3355: $count ++;
1.87 raeburn 3356: } elsif ($key =~ /^lti\./) {
3357: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 3358: }
3359: }
3360: if ($count) {
3361: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3362: }
3363: }
3364: }
3365: return;
3366: }
3367:
3368: sub display_disallowed {
1.9 raeburn 3369: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3370: my $output;
3371: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3372: if (keys(%{$disallowed})) {
3373: if ($item eq 'cloners') {
3374: my @fails;
3375: my %lt = &Apache::lonlocal::texthash (
3376: format => 'Invalid format',
3377: domain => 'Domain does not exist',
3378: newuser => 'LON-CAPA user(s) do(es) not exist.',
3379: );
3380: foreach my $error ('format','domain','newuser') {
3381: if (defined($disallowed->{$error})) {
3382: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3383: $lt{$error};
3384: if ($error eq 'newuser') {
1.9 raeburn 3385: $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 3386: }
3387: push(@fails,$msg);
3388: }
3389: }
3390: if (@fails) {
3391: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3392: '</span>'.join('; ',@fails).'.<br />';
3393: }
3394: } elsif ($item eq 'rolenames') {
3395: my %lt = &Apache::lonlocal::texthash (
3396: replacements => 'Name already used to replace a different standard role name',
3397: regulars => 'Name already used as a standard role name',
3398: customrole => 'Name already used as the name of a custom role',
3399: );
3400: my @fails;
3401: foreach my $error ('replacements','regulars','customrole') {
3402: if (ref($disallowed->{$error}) eq 'ARRAY') {
3403: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3404: '</b>, '.&mt('reason').' - '.$lt{'error'});
3405: }
3406: }
3407: if (@fails) {
3408: $output .= '<span class="LC_warning">'.
3409: &mt('Unable to include amongst replacements for role names: ').
3410: '</span>'.join('; ',@fails).'.<br />';
3411: }
3412:
3413: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3414: $output .= '<span class="LC_warning">';
3415: if ($item eq 'feedback') {
1.9 raeburn 3416: if ($crstype eq 'Community') {
3417: $output .= &mt('Unable to include as a recipient of community feedback for:');
3418: } else {
3419: $output .= &mt('Unable to include as a recipient of course feedback for:');
3420: }
1.3 raeburn 3421: } elsif ($item eq 'discussion') {
3422: $output .= &mt('Unable to include in user-based access control for:');
3423: } elsif ($item eq 'localization') {
1.9 raeburn 3424: if ($crstype eq 'Community') {
3425: $output .= &mt('Unable to include in community localization:');
3426: } else {
3427: $output .= &mt('Unable to include in course localization:');
3428: }
1.3 raeburn 3429: }
3430: $output .= '</span><ul>';
3431: foreach my $key (sort(keys(%{$disallowed}))) {
3432: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3433: $output .= '<li><i>'.$itemtext.'</i> - ';
3434: if ($item eq 'localization') {
3435: $output .= &mt('reason - unsupported language: [_1]',
3436: '<b>'.$disallowed->{$key}.'</b>');
3437: } else {
3438: $output .= &mt('reason - invalid user: [_1]',
3439: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3440: }
3441: }
3442: $output .= '</ul><br />';
3443: }
3444: }
1.1 raeburn 3445: }
1.3 raeburn 3446: return $output;
1.1 raeburn 3447: }
3448:
3449: sub get_course {
3450: my ($courseid) = @_;
3451: if (!defined($courseid)) {
3452: $courseid = $env{'request.course.id'};
3453: }
3454: my $cdom=$env{'course.'.$courseid.'.domain'};
3455: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 3456: my $chome=$env{'course.'.$courseid.'.home'};
3457: return ($cnum,$cdom,$chome);
1.1 raeburn 3458: }
3459:
3460: sub get_jscript {
1.91 raeburn 3461: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3462: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 raeburn 3463: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3464: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3465: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3466: my $cloners_js = &cloners_javascript($phase);
1.118 raeburn 3467: my $currltitools;
3468: if (ref($settings) eq 'HASH') {
3469: $currltitools = $settings->{'ltitools'};
3470: }
3471: my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.71 raeburn 3472: my @code_order;
3473: if ($crstype ne 'Community') {
3474: if (ref($settings) eq 'HASH') {
3475: my %codedefaults;
3476: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3477: \@code_order);
3478: if (@code_order > 0) {
3479: if ($phase eq 'display') {
3480: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3481: if (grep(/^courseinfo$/,@actions)) {
3482: if ($settings->{'cloners'} ne '') {
3483: unless ($settings->{'cloners'} eq '*') {
3484: my @cloners = split(/,/,$settings->{'cloners'});
3485: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3486: my %local_to_standard;
3487: for (my $i=0; $i<@code_order; $i++) {
3488: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3489: }
3490: foreach my $cloner (@cloners) {
1.124 raeburn 3491: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
1.71 raeburn 3492: ($cloner !~ /^$match_username\:$match_domain$/)) {
3493: foreach my $item (split(/\&/,$cloner)) {
3494: my ($key,$val) = split(/\=/,$item);
3495: $val = &unescape($val);
3496: foreach my $code (@code_order) {
3497: if ($key eq $local_to_standard{$code}) {
3498: $env{'form.'.$key} = $val;
3499: }
3500: }
3501: }
3502: }
3503: }
3504: }
3505: }
3506: }
3507: }
3508: my @codetitles;
3509: (undef,$instcode_js) =
3510: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3511: \@codetitles);
3512: $instcode_js .= <<ENDSCRIPT;
3513: function toggleCloners(callerradio) {
3514: if (document.getElementById('LC_cloners_instcode')) {
3515: if (callerradio.value == 1) {
3516: document.getElementById('LC_cloners_instcode').style.display = "block";
3517: } else {
3518: uncheckOfficialLists();
3519: document.getElementById('LC_cloners_instcode').style.display = "none";
3520: }
3521: }
3522: }
3523:
3524: if (!document.getElementsByClassName) {
3525: function getElementsByClassName(node, classname) {
3526: var a = [];
3527: var re = new RegExp('(^| )'+classname+'( |$)');
3528: var els = node.getElementsByTagName("*");
3529: for(var i=0,j=els.length; i<j; i++)
3530: if(re.test(els[i].className))a.push(els[i]);
3531: return a;
3532: }
3533: }
3534:
3535: function uncheckOfficialLists() {
3536: var codepicks;
3537: if (document.getElementsByClassName) {
3538: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3539: } else {
3540: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3541: }
3542: if (codepicks.length) {
3543: for (var i=0; i<codepicks.length; i++) {
3544: codepicks[i].selectedIndex = 0;
3545: }
3546: }
3547: }
3548:
3549: ENDSCRIPT
3550: }
3551: }
3552: }
1.1 raeburn 3553: if ($can_categorize) {
3554: $categorize_js = <<ENDSCRIPT;
3555: function catsbrowser() {
3556: var catswin = null;
3557: var url = '/adm/courseprefs?phase=categorizecourse';
3558: if (!catswin || catswin.closed) {
3559: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3560: } else {
3561: catswin.focus();
3562: }
3563: }
3564: ENDSCRIPT
3565: }
1.36 raeburn 3566: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3567: if ($loncaparev) {
3568: $loncaparev_js = <<ENDSCRIPT;
3569: function loncaparevinfo() {
3570: var lcrevwin = null;
3571: var url = '/adm/courseprefs?phase=releaseinfo';
3572: if (!lcrevwin || lcrevwin.closed) {
3573: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3574: } else {
3575: lcrevwin.focus();
3576: }
3577: }
3578: ENDSCRIPT
3579: }
1.60 raeburn 3580: my $cnum = $env{'course.'.$cid.'.num'};
3581: my $syllabus_js = <<ENDSCRIPT;
3582: function syllabusinfo() {
3583: var syllwin = null;
3584: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3585: if (!syllwin || syllwin.closed) {
3586: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3587: } else {
3588: syllwin.focus();
3589: }
3590: }
3591: ENDSCRIPT
1.91 raeburn 3592: my $menuitems_js;
3593: unless ($noedit) {
3594: my $collections;
3595: my $next = 1;
3596: if (ref($settings) eq 'HASH') {
3597: if ($settings->{'menucollections'} ne '') {
3598: my @current;
3599: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3600: my ($num) = split(/\%/,$item);
3601: if ($num =~ /^\d+$/) {
3602: push(@current,$num);
3603: }
3604: }
3605: $collections = join("','",sort { $a <=> $b } @current);
3606: if ($collections) {
3607: $collections = "'$collections'";
3608: }
3609: $next += $current[-1];
3610: }
3611: }
3612: my $deftext = &mt('Standard (all menus shown)');
3613: $menuitems_js = <<ENDSCRIPT;
3614: function toggleAddmenucoll() {
3615: if (document.getElementById('menucollections_add')) {
3616: var state = 'none';
3617: var add = document.getElementById('menucollections_add').checked;
3618: if (add) {
3619: state = 'inline-block';
3620: }
3621: var fieldsets = new Array('shown','text','links','list','inline');
3622: for (var i=0; i<fieldsets.length; i++) {
3623: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3624: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3625: }
3626: }
3627: var box = document.getElementsByClassName('LC_menucoll_add');
3628: if (box.length) {
3629: for (var i=0; i<box.length; i++) {
3630: if (add) {
3631: box[i].checked = true;
3632: } else {
3633: box[i].checked = false;
3634: }
3635: }
3636: }
3637: if (document.getElementById('menudefault')) {
3638: var menudef = document.getElementById('menudefault');
3639: var currsel = menudef.selectedIndex;
3640: var colls = new Array($collections);
3641: menudef.options.length = 0;
3642: if (!add) {
3643: if (currsel == 1 + colls.length) {
3644: currsel = 0;
3645: }
3646: }
3647: if (currsel == 0) {
3648: menudef.options[0] = new Option('$deftext','',true,true);
3649: } else {
3650: menudef.options[0] = new Option('$deftext','',false,false);
3651: }
3652: if (colls.length) {
3653: for (var i=0; i<colls.length; i++) {
3654: var idx = i+1;
3655: if (currsel == colls[i]) {
3656: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3657: } else {
3658: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3659: }
3660: }
3661: }
3662: if (add) {
3663: var addidx = 1 + colls.length;
3664: if (currsel == addidx) {
3665: menudef.options[addidx] = new Option('$next','$next',true,true);
3666: } else {
3667: menudef.options[addidx] = new Option('$next','$next',false,false);
3668: }
3669: }
3670: }
3671: }
3672: }
3673: ENDSCRIPT
3674: }
1.114 raeburn 3675: $extresource_js = <<"ENDSCRIPT";
3676: function toggleExtRes() {
3677: if (document.getElementById('LC_extresource')) {
3678: var extressel = document.getElementById('LC_extresource').value;
3679: if (document.getElementById('LC_extresreusediv')) {
3680: var extresreuse = document.getElementById('LC_extresreusediv');
3681: if (document.getElementById('LC_extressize')) {
3682: var extressize = document.getElementById('LC_extressize');
3683: var setvis;
3684: if ((extressel == 'tab') || (extressel == 'window')) {
3685: extresreuse.style.display = 'inline-block';
3686: setvis = 1;
3687: if (extressel == 'window') {
3688: extressize.style.display = 'inline-block';
3689: } else {
3690: extressize.style.display = 'none';
3691: }
3692: }
3693: if (!setvis) {
3694: extresreuse.style.display = 'none';
3695: extressize.style.display = 'none';
3696: }
3697: }
3698: }
3699: }
3700: }
3701: ENDSCRIPT
1.115 raeburn 3702: $localization_js = <<"ENDSCRIPT";
3703: function toggleTimeZone() {
3704: if (document.getElementById('LC_set_timezone')) {
3705: var timezonesel = document.getElementById('LC_set_timezone').value;
3706: if (document.getElementById('LC_tzoverdiv')) {
3707: var tzoverdiv = document.getElementById('LC_tzoverdiv');
3708: if (timezonesel == '') {
3709: tzoverdiv.style.display = 'none';
3710: } else {
3711: tzoverdiv.style.display = 'block';
3712: }
3713: }
3714: }
3715: }
3716: ENDSCRIPT
1.1 raeburn 3717: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.124 raeburn 3718: '// <![CDATA['."\n".
1.36 raeburn 3719: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 raeburn 3720: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 3721: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.102 raeburn 3722: &linkprot_javascript()."\n".'//]]>'."\n".
1.118 raeburn 3723: '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3724: return $jscript;
3725: }
3726:
1.3 raeburn 3727: sub cloners_javascript {
3728: my ($formname) = @_;
3729: return <<"ENDSCRIPT";
3730:
3731: function update_cloners(caller,num) {
3732: var delidx = getIndexByName('cloners_delete');
3733: var actidx = getIndexByName('cloners_activate');
3734: if (caller == 'cloners_all') {
3735: var selall;
3736: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3737: if (document.$formname.cloners_all[i].checked) {
3738: selall = document.$formname.cloners_all[i].value;
3739: }
3740: }
3741: if (selall == 1) {
3742: if (delidx != -1) {
3743: if (document.$formname.cloners_delete.length) {
3744: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3745: document.$formname.cloners_delete[j].checked = true;
3746: }
3747: } else {
3748: document.$formname.elements[delidx].checked = true;
3749: }
3750: }
3751: if (actidx != -1) {
3752: if (document.$formname.cloners_activate.length) {
3753: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3754: if (document.$formname.cloners_activate[i].value == '0') {
3755: document.$formname.cloners_activate[i].checked = false;
3756: }
1.71 raeburn 3757: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3758: document.$formname.cloners_activate[i].checked = true;
3759: }
3760: }
3761: }
3762: }
3763: document.$formname.cloners_newdom.selectedIndex = 0;
3764: }
3765: }
3766: if (caller == 'cloners_activate') {
3767: if (document.$formname.cloners_activate.length) {
3768: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3769: if (document.$formname.cloners_activate[j].value == num) {
3770: if (document.$formname.cloners_activate[j].checked) {
3771: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3772: if (document.$formname.cloners_all[i].value == '1') {
3773: document.$formname.cloners_all[i].checked = false;
3774: }
3775: if (document.$formname.cloners_all[i].value == '0') {
3776: document.$formname.cloners_all[i].checked = true;
3777: }
3778: }
3779: }
3780: }
3781: }
3782: } else {
3783: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3784: if (document.$formname.cloners_all[i].value == '1') {
3785: document.$formname.cloners_all[i].checked = false;
3786: }
3787: if (document.$formname.cloners_all[i].value == '0') {
3788: document.$formname.cloners_all[i].checked = true;
3789: }
3790: }
3791: }
3792: }
3793: return;
3794: }
3795:
3796: function getIndexByName(item) {
3797: for (var i=0;i<document.$formname.elements.length;i++) {
3798: if (document.$formname.elements[i].name == item) {
3799: return i;
3800: }
3801: }
3802: return -1;
3803: }
3804:
3805: ENDSCRIPT
3806: }
3807:
1.102 raeburn 3808: sub linkprot_javascript {
3809: return <<"ENDSCRIPT";
1.112 raeburn 3810: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 3811: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3812: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3813: var itemname = form.elements['linkprot_'+item+'_'+num];
3814: if (itemname) {
3815: if (itemname.length > 0) {
3816: var setvis;
3817: for (var i=0; i<itemname.length; i++) {
3818: if (itemname[i].checked == true) {
3819: if (itemname[i].value == valon) {
3820: extraid.style.display = styleon;
3821: setvis = 1;
3822: }
3823: break;
3824: }
3825: }
3826: if (!setvis) {
3827: extraid.style.display = 'none';
3828: }
3829: }
3830: }
3831: }
3832: return;
3833: }
1.106 raeburn 3834:
1.102 raeburn 3835: ENDSCRIPT
3836:
3837: }
3838:
1.1 raeburn 3839: sub print_courseinfo {
1.80 raeburn 3840: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3841: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3842: return;
3843: }
1.83 raeburn 3844: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3845: if ($noedit) {
3846: $disabled = ' disabled="disabled"';
3847: }
1.1 raeburn 3848: my %domconf =
1.71 raeburn 3849: &Apache::lonnet::get_dom('configuration',
3850: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3851: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3852: $cathash = $domconf{'coursecategories'}{'cats'};
3853: if (ref($cathash) eq 'HASH') {
3854: $categoriesform =
3855: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 3856: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3857: }
3858: }
1.25 raeburn 3859: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3860: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3861: }
1.71 raeburn 3862: my ($currcanclone,@code_order,$cloner_instcode);
3863: my %codedefaults;
3864: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3865: \@code_order);
3866: if ($settings->{'cloners'}) {
3867: unless ($settings->{'cloners'} eq '*') {
3868: my @currclone = split(/,/,$settings->{'cloners'});
3869: foreach my $item (@currclone) {
3870: unless ($item eq '*') {
3871: if (($item !~ /\:/) && ($item =~ /=/)) {
3872: $cloner_instcode = 1;
3873: }
3874: }
3875: }
3876: }
3877: }
3878: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3879: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3880: if (ref($canclone) eq 'HASH') {
3881: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3882: if ($settings->{'internal.coursecode'}) {
3883: my @posscodes;
3884: if (@code_order > 0) {
3885: $currcanclone = 'instcode';
3886: foreach my $item (@{$canclone->{'instcode'}}) {
3887: if (grep(/^\Q$item\E$/,@code_order)) {
3888: push(@posscodes,$item);
3889: }
3890: }
3891: my $codestr = join(' + ',@posscodes);
3892: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3893: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3894: }
3895: }
3896: }
3897: } elsif ($canclone eq 'domain') {
3898: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
3899: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
3900: $currcanclone = 'domain';
3901: }
3902: if ($clonedefaults) {
3903: if ($settings->{'cloners'} ne '') {
3904: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
3905: } else {
3906: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
3907: }
3908: $clonedefaults = '<br /><br />'.$clonedefaults;
3909: }
3910: }
1.1 raeburn 3911: if (!defined($categoriesform)) {
1.15 raeburn 3912: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 3913: }
1.12 raeburn 3914: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 3915: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 3916:
1.9 raeburn 3917: my $replace;
3918: if ($crstype eq 'Community') {
3919: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3920: } else {
3921: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3922: }
1.84 raeburn 3923: my ($editmap,$editsyllabus);
3924: unless ($noedit) {
3925: $editmap = (' 'x2).
3926: '<a href="javascript:openbrowser'.
3927: "('display','url','sequence')\">".
3928: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
3929: &mt('Modification may make assessment data inaccessible!').
3930: '</span>';
3931: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
1.124 raeburn 3932: '</a>');
1.84 raeburn 3933: }
1.1 raeburn 3934: my %items = (
1.3 raeburn 3935: 'url' => {
1.84 raeburn 3936: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 3937: input => 'textbox',
1.55 raeburn 3938: size => '55',
1.19 faziophi 3939: advanced => 1
1.1 raeburn 3940: },
3941: 'description' => {
1.3 raeburn 3942: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 3943: input => 'textbox',
1.55 raeburn 3944: size => '55',
1.1 raeburn 3945: },
1.24 raeburn 3946: 'owner' => {
3947: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
3948: },
1.25 raeburn 3949: 'co-owners' => {
3950: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
3951: },
1.63 raeburn 3952: 'clonedfrom' => {
3953: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
3954: },
1.1 raeburn 3955: 'courseid' => {
1.3 raeburn 3956: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
3957: &mt('internal, optional').')',
1.1 raeburn 3958: input => 'textbox',
3959: size => '25',
3960: },
1.64 raeburn 3961: 'uniquecode' => {
3962: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
3963: },
1.1 raeburn 3964: 'cloners' => {
1.3 raeburn 3965: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 3966: &mt('Owner and Coordinators included automatically').
3967: $clonedefaults,
1.1 raeburn 3968: input => 'textbox',
1.41 www 3969: size => '40'
1.1 raeburn 3970: },
3971: 'rolenames' => {
1.3 raeburn 3972: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 3973: '('.$replace.')',
1.1 raeburn 3974: input => 'textbox',
3975: size => '20',
1.19 faziophi 3976: advanced => 1
1.1 raeburn 3977: },
1.88 raeburn 3978: 'syllabus' => {
3979: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 3980: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 3981: $editsyllabus,
1.1 raeburn 3982: },
3983: 'hidefromcat' => {
1.3 raeburn 3984: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 3985: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
3986: input => 'radio',
3987: },
3988: 'categories' => {
1.3 raeburn 3989: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 3990: &mt('Display Categories').'</a>',
3991: input => 'textbox',
3992: size => '25',
3993: },
1.35 raeburn 3994: 'loncaparev' => {
3995: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
3996: },
1.55 raeburn 3997: 'defaultcredits' => {
3998: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
3999: },
1.1 raeburn 4000: );
4001: my $datatable;
4002: my $count = 0;
4003: foreach my $item (@{$ordered}) {
1.56 raeburn 4004: my $colspan;
1.1 raeburn 4005: if ($item eq 'hidefromcat') {
4006: next if (!$can_toggle_cat);
4007: } elsif ($item eq 'categories') {
4008: next if (!$can_categorize);
1.64 raeburn 4009: } elsif ($item eq 'uniquecode') {
4010: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4011: }
1.56 raeburn 4012: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
1.124 raeburn 4013: $colspan = 2;
1.56 raeburn 4014: }
1.1 raeburn 4015: $count ++;
1.19 faziophi 4016: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 4017: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4018: } else {
1.56 raeburn 4019: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4020: }
1.1 raeburn 4021: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 4022: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4023: } elsif ($item eq 'cloners') {
4024: my $includeempty = 1;
4025: my $num = 0;
1.56 raeburn 4026: $datatable .= '</td><td align="right">'.
4027: &Apache::loncommon::start_data_table().
1.1 raeburn 4028: &Apache::loncommon::start_data_table_row().
4029: '<td><span class="LC_nobreak"><label>'.
4030: &mt('Any user in any domain:').
4031: ' <input type="radio" name="cloners_all" value="1" ';
4032: if ($settings->{$item} eq '*') {
4033: $datatable .= ' checked="checked" ';
4034: }
4035: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 4036: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4037: (' 'x2).'<label>'.
4038: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4039: if ($settings->{$item} ne '*') {
4040: $datatable .= ' checked="checked" ';
4041: }
4042: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 4043: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4044: &Apache::loncommon::end_data_table_row().
4045: &Apache::loncommon::end_data_table().
1.56 raeburn 4046: '<table><tr><td align="left"><b>'.&mt('Or').
4047: '</b></td></tr></table>'.
1.1 raeburn 4048: &Apache::loncommon::start_data_table();
4049: my @cloners;
4050: if ($settings->{$item} eq '') {
1.80 raeburn 4051: unless ($noedit) {
4052: my $default;
4053: if ($currcanclone eq 'domain') {
4054: $default = '0';
4055: }
4056: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 4057: }
1.1 raeburn 4058: } elsif ($settings->{$item} ne '*') {
4059: my @entries = split(/,/,$settings->{$item});
4060: if (@entries > 0) {
4061: foreach my $entry (@entries) {
4062: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4063: if ($udom =~ /^$match_domain$/) {
4064: unless (&Apache::lonnet::domain($udom)) {
4065: next;
4066: }
4067: } else {
4068: next;
4069: }
1.1 raeburn 4070: if ($uname eq '*') {
4071: $datatable .=
4072: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4073: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4074: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4075: '</b><input type="hidden" name="cloners_dom_'.$num.
4076: '" value="'.$udom.'" /></span><br />'.
4077: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4078: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4079: &mt('Delete').'</label></span></td>'.
4080: &Apache::loncommon::end_data_table_row();
4081: $num ++;
1.23 raeburn 4082: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4083: unless (grep(/^\Q$entry\E$/,@cloners)) {
4084: push(@cloners,$entry);
4085: }
1.1 raeburn 4086: }
4087: }
4088: }
4089: }
4090: my $add_domtitle = &mt('Any user in additional domain:');
4091: if ($settings->{$item} eq '*') {
4092: $add_domtitle = &mt('Any user in specific domain:');
4093: } elsif ($settings->{$item} eq '') {
4094: $add_domtitle = &mt('Any user in other domain:');
4095: }
4096: my $cloners_str = join(',',@cloners);
4097: $datatable .= &Apache::loncommon::start_data_table_row().
4098: '<td align="left"><span class="LC_nobreak">'.
4099: $add_domtitle.'</span><br />'.
4100: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 4101: $includeempty,undef,undef,
4102: undef,undef,$noedit).
1.1 raeburn 4103: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4104: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4105: &Apache::loncommon::end_data_table().
1.56 raeburn 4106: '<table><tr><td align="left"><b>'.&mt('And').
4107: '</b></td></tr></table>'.
1.1 raeburn 4108: &Apache::loncommon::start_data_table().
4109: &Apache::loncommon::start_data_table_row().
4110: '<td align="left">'.
4111: &mt('Specific users').' (<tt>'.
4112: &mt('user:domain,user:domain').'</tt>)<br />'.
4113: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 4114: $items{$item}{'size'},$disabled).
1.1 raeburn 4115: '</td>'.&Apache::loncommon::end_data_table_row().
4116: &Apache::loncommon::end_data_table();
1.71 raeburn 4117: if (@code_order > 0) {
4118: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4119: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4120: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4121: \%cat_items,\@codetitles,
4122: \%cat_titles,\%cat_order);
4123: my $showncodes = 'off';
4124: my $checkedoff = ' checked="checked"';
4125: my $checkedon = '';
4126: if ($cloner_instcode) {
4127: $checkedon = $checkedoff;
4128: $checkedoff = '';
4129: $showncodes = 'on';
4130: }
4131: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4132: '</b></td></tr></table>'.
4133: &Apache::loncommon::start_data_table().
4134: &Apache::loncommon::start_data_table_row().
4135: '<td align="left"><span class="LC_nobreak">'.
4136: &mt('Cloning by official course(s) based on course category').(' 'x2).
4137: '<label>'.
1.80 raeburn 4138: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4139: (' ').
4140: '<label>'.
1.80 raeburn 4141: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 4142: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4143: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 4144: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 4145: '</td>'.&Apache::loncommon::end_data_table_row().
4146: &Apache::loncommon::end_data_table();
4147: }
1.1 raeburn 4148: } elsif ($item eq 'rolenames') {
1.56 raeburn 4149: $datatable .= '</td><td align="right">'.
4150: &Apache::loncommon::start_data_table();
1.9 raeburn 4151: my @roles;
4152: if ($crstype eq 'Community') {
4153: @roles = ('co');
4154: } else {
4155: @roles = ('cc');
4156: }
4157: push (@roles,('in','ta','ep','ad','st'));
4158: foreach my $role (@roles) {
1.1 raeburn 4159: $datatable .= &Apache::loncommon::start_data_table_row().
4160: '<td align="left"><span class="LC_nobreak">'.
4161: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4162: '</span></td><td align="left">'.
4163: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4164: $settings->{$role.'.plaintext'},
1.80 raeburn 4165: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4166: &Apache::loncommon::end_data_table_row();
4167: }
4168: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4169: } elsif ($item eq 'categories') {
1.80 raeburn 4170: my $launcher;
4171: if ($noedit) {
4172: $launcher = $disabled;
4173: } else {
4174: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4175: }
1.3 raeburn 4176: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4177: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4178: $items{$item}{size},$launcher);
1.24 raeburn 4179: } elsif ($item eq 'owner') {
4180: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4181: if ($owner =~ /:/) {
4182: my ($ownername,$ownerdom) = split(':',$owner);
4183: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4184: } elsif ($owner ne '') {
4185: $owner = &Apache::loncommon::plainname($owner,$cdom);
4186: } else {
4187: $owner = &mt('None specified');
4188: }
4189: $datatable .= $owner;
1.63 raeburn 4190: } elsif ($item eq 'clonedfrom') {
4191: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4192: my $clonedfrom = &mt('None');
4193: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 4194: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 4195: if ($clonesrcinfo{'description'}) {
1.124 raeburn 4196: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
1.63 raeburn 4197: }
4198: }
4199: $datatable .= $clonedfrom;
1.64 raeburn 4200: } elsif ($item eq 'uniquecode') {
1.124 raeburn 4201: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
1.64 raeburn 4202: if ($code) {
4203: $datatable .= $code;
4204: }
1.25 raeburn 4205: } elsif ($item eq 'co-owners') {
4206: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4207: my @currcoown;
4208: if ($coowners) {
4209: @currcoown = split(',',$coowners);
4210: }
4211: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4212: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4213: $datatable .= &show_autocoowners(@currcoown);
4214: } else {
1.80 raeburn 4215: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4216: }
4217: } else {
4218: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4219: $datatable .= &show_autocoowners(@currcoown);
4220: } else {
1.80 raeburn 4221: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4222: }
4223: }
1.88 raeburn 4224: } elsif ($item eq 'syllabus') {
1.60 raeburn 4225: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4226: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4227: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4228: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4229: if ($minimal =~/\w/) {
4230: if ($external =~ m{\Q$minimal\E$}) {
4231: undef($external);
4232: }
4233: } elsif ($uploaded =~/\w/) {
4234: if ($external =~ m{\Q$uploaded\E$}) {
4235: undef($external);
4236: }
4237: }
4238: } elsif ($external!~/\w/) {
4239: undef($external);
4240: }
4241: if ($external) {
4242: $datatable .= &mt('External URL');
4243: } elsif ($minimal) {
4244: $datatable .= &mt('Minimal template');
4245: } elsif ($uploaded) {
4246: $datatable .= &mt('Uploaded file');
4247: } else {
1.124 raeburn 4248: $datatable .= &mt('Standard template');
1.60 raeburn 4249: }
4250: $datatable .= (' ' x 2).
4251: &mt('[_1]View[_2]',
4252: '<a href="javascript:syllabusinfo();">',
1.124 raeburn 4253: '</a>');
1.35 raeburn 4254: } elsif ($item eq 'loncaparev') {
4255: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4256: my $showreqd;
4257: if ($loncaparev) {
1.36 raeburn 4258: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4259: &mt('Details').'</a>';
1.35 raeburn 4260: } else {
4261: $showreqd = &mt('No specific version required');
4262: }
4263: $datatable .= $showreqd;
1.1 raeburn 4264: } else {
1.80 raeburn 4265: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4266: }
4267: $datatable .= &item_table_row_end();
4268: }
4269: $$rowtotal += scalar(@{$ordered});
4270: return $datatable;
4271: }
4272:
4273: sub new_cloners_dom_row {
1.71 raeburn 4274: my ($newdom,$num,$default) = @_;
4275: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4276: if ($newdom ne '') {
1.71 raeburn 4277: if ($num eq $default) {
1.124 raeburn 4278: $checkedon = 'checked="checked" ';
1.71 raeburn 4279: } else {
4280: $checkedoff = 'checked="checked" ';
4281: }
1.1 raeburn 4282: $output .= &Apache::loncommon::start_data_table_row().
4283: '<td valign="top"><span class="LC_nobreak">'.
4284: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4285: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 4286: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4287: 'onchange="javascript:update_cloners('.
1.1 raeburn 4288: "'cloners_activate','$num'".');" />'.
4289: &mt('Yes').'</label>'.(' 'x2).
4290: '<label><input type="radio" '.
1.71 raeburn 4291: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4292: 'onchange="javascript:update_cloners('.
1.1 raeburn 4293: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4294: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4295: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4296: &Apache::loncommon::end_data_table_row();
4297: }
4298: return $output;
4299: }
4300:
4301: sub can_modify_catsettings {
1.12 raeburn 4302: my ($dom,$crstype) = @_;
1.1 raeburn 4303: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4304: my ($can_toggle_cat,$can_categorize);
4305: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4306: if ($crstype eq 'Community') {
4307: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4308: $can_toggle_cat = 1;
4309: }
4310: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4311: $can_categorize = 1;
4312: }
4313: } else {
4314: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4315: $can_toggle_cat = 1;
4316: }
4317: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4318: $can_categorize = 1;
4319: }
1.1 raeburn 4320: }
4321: }
4322: return ($can_toggle_cat,$can_categorize);
4323: }
4324:
4325: sub assign_course_categories {
1.9 raeburn 4326: my ($r,$crstype) = @_;
1.1 raeburn 4327: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4328: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4329: my $hascats = 0;
4330: my $cathash;
4331: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4332: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4333: $cathash = $domconf{'coursecategories'}{'cats'};
4334: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4335: foreach my $cat (keys(%{$cathash})) {
4336: next if ($cat eq 'instcode::0');
4337: unless ($crstype eq 'Community') {
4338: next if ($cat eq 'communities::0');
4339: }
4340: $hascats ++;
4341: }
1.1 raeburn 4342: }
4343: }
4344: my $catwin_js;
4345: if ($hascats) {
1.9 raeburn 4346: my $alert;
4347: if ($crstype eq 'Community') {
4348: $alert = &mt("Use 'Save' in the main window to save community categories");
4349: } else {
4350: $alert = &mt("Use 'Save' in the main window to save course categories");
4351: }
1.72 damieng 4352: &js_escape(\$alert);
1.1 raeburn 4353: $catwin_js = <<ENDSCRIPT;
4354: <script type="text/javascript">
4355:
4356: function updateCategories() {
4357: var newcategories = '';
4358: var unescapedcats = '';
4359: if (document.chgcats.usecategory.length) {
4360: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4361: if (document.chgcats.usecategory[i].checked == true) {
4362: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4363: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4364: }
4365: }
4366: if (newcategories.length > 0) {
4367: newcategories = newcategories.slice(0,-1);
4368: }
4369: if (unescapedcats.length > 0) {
4370: unescapedcats = unescapedcats.slice(0,-3);
4371: }
4372: } else {
4373: if (document.chgcats.usecategory.checked == true) {
4374: newcategories = document.chgcats.usecategory.value;
4375: unescapedcats = document.chgcats.catname.value;
4376: }
4377: }
4378: opener.document.display.categories.value = newcategories;
4379: opener.document.display.categories_display.value = unescapedcats;
4380: alert("$alert");
4381: self.close();
4382: return;
4383: }
4384:
4385: </script>
4386: ENDSCRIPT
4387: } else {
4388: my $onload;
4389: }
1.9 raeburn 4390: my ($crscat,$catcrs,$assign);
4391: if ($crstype eq 'Community') {
4392: $crscat = 'Community Categories';
4393: $catcrs = &mt('Categorize Community');
4394: $assign = &mt('Assign one or more categories to this community.')
4395: } else {
4396: $crscat = 'Course Categories';
4397: $catcrs = &mt('Categorize Course');
4398: $assign = &mt('Assign one or more categories to this course.')
4399: }
1.1 raeburn 4400: my $start_page =
1.9 raeburn 4401: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4402: {'only_body' => 1,});
4403: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4404: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4405: if ($hascats) {
4406: my %currsettings =
4407: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4408: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4409: $currsettings{'categories'},$crstype);
4410: if ($cattable eq '') {
4411: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4412: } else {
4413: $categoriesform .= $assign.'<br /><br />'.
4414: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4415: $cattable."\n".
4416: '<br /><input type="button" name="changes" value="'.
4417: &mt('Copy to main window').'" '.
4418: 'onclick="javascript:updateCategories()" /></form><br />';
4419: }
1.1 raeburn 4420: } else {
1.12 raeburn 4421: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4422: }
4423: $r->print($start_page.$categoriesform.$end_page);
4424: return;
4425: }
4426:
1.36 raeburn 4427: sub display_loncaparev_constraints {
4428: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.124 raeburn 4429: my ($reqdmajor,$reqdminor);
1.36 raeburn 4430: my $cid = $env{'request.course.id'};
4431: my $cdom = $env{'course.'.$cid.'.domain'};
4432: my $cnum = $env{'course.'.$cid.'.num'};
4433: my $output;
1.39 raeburn 4434: my %lt = &Apache::lonlocal::texthash (
4435: 'all' => 'all',
4436: 'section/group' => 'section/group',
4437: 'user' => 'user',
4438: );
1.66 raeburn 4439: &Apache::lonrelrequtils::init_global_hashes();
4440: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4441: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4442: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 4443: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4444: }
4445: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 4446: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 4447: @scopeorder = ('all','section/group','user');
1.67 raeburn 4448: my $now = time;
1.36 raeburn 4449: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4450: if (ref($resourcedata) eq 'HASH') {
4451: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 4452: my %found;
1.66 raeburn 4453: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4454: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 4455: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
4456: my $value = $resourcedata->{$key};
4457: if ($item eq 'examcode') {
4458: if (&Apache::lonnet::validCODE($value)) {
4459: $value = 'valid';
4460: } else {
4461: $value = '';
4462: }
4463: } elsif ($item eq 'printstartdate') {
1.67 raeburn 4464: if ($value =~ /^\d+$/) {
1.70 raeburn 4465: if ($value > $now) {
4466: $value = 'future';
4467: }
4468: }
4469: } elsif ($item eq 'printenddate') {
4470: if ($value =~ /^\d+$/) {
4471: if ($value < $now) {
4472: $value = 'past';
4473: }
4474: }
4475: }
4476: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
4477: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4478: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 4479: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 4480: }
4481: }
4482: }
4483: }
1.79 raeburn 4484: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
4485: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 4486: my $value = $resourcedata->{$key};
1.79 raeburn 4487: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 4488: if ($value =~ /$valuematch/) {
4489: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 4490: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 4491: $found{$item}{'rev'} =
1.76 raeburn 4492: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 4493: last;
4494: }
4495: }
4496: }
4497: }
1.76 raeburn 4498: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
4499: my $regexp;
4500: if ($item eq 'maplevelrecurse') {
4501: $regexp = '\.(?:sequence|page)___\(rec\)\.';
4502: }
4503: if ($regexp ne '') {
4504: if ($key =~ /$regexp.*\.(\w+)$/) {
4505: my $name = $1;
4506: my $value = $resourcedata->{$key};
4507: if ($name eq 'type') {
4508: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
4509: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
4510: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
4511: }
4512: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
4513: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
4514: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
4515: $found{$name}{'rev'} =
4516: $Apache::lonnet::needsrelease{'parameter::::'.$item};
4517: }
4518: }
4519: }
1.70 raeburn 4520: foreach my $item (keys(%found)) {
4521: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4522: my $rev = $found{$item}{'rev'};
4523: my $valname = $found{$item}{'valname'};
1.76 raeburn 4524: my $extra = $found{$item}{'extra'};
1.70 raeburn 4525: my ($middle,$scope,$which,$level,$map,$resource);
4526: my $start = $cid.'.';
4527: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4528: $middle = $1;
4529: $which = $2;
4530: $scope = 'user';
4531: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4532: $middle = $1;
4533: $which = $2;
4534: $scope = 'section/group';
4535: } else {
4536: $scope = 'all';
4537: }
4538: my $what="$stdname=$valname";
1.76 raeburn 4539: if ($extra) {
4540: $what .= "<br/>$extra<br />";
4541: }
1.70 raeburn 4542: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4543: $level = 'general';
4544: if ($scope eq 'all') {
4545: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4546: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4547: push(@{$fromparam{$rev}{$scope}},$what);
4548: }
4549: } else {
4550: push(@{$fromparam{$rev}{$scope}},$what);
4551: }
4552: } else {
4553: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4554: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4555: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4556: }
4557: } else {
4558: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4559: }
4560: }
4561: $rowspan{$rev} ++;
1.76 raeburn 4562: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 4563: $level = 'folder';
4564: $map = $1;
4565: if ($scope eq 'all') {
4566: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4567: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4568: push(@{$bymap{$map}{$rev}{$scope}},$what);
4569: }
4570: } else {
4571: push(@{$bymap{$map}{$rev}{$scope}},$what);
4572: }
4573: } else {
4574: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4575: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4576: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4577: }
4578: } else {
4579: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4580: }
4581: }
4582: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4583: $level = 'resource';
4584: $resource = $1;
4585: if ($scope eq 'all') {
4586: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4587: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4588: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4589: }
4590: } else {
4591: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4592: }
4593: } else {
4594: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4595: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4596: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4597: }
4598: } else {
4599: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 4600: }
4601: }
4602: }
4603: }
4604: }
4605: if (keys(%fromparam)) {
4606: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4607: &Apache::loncommon::start_data_table().
4608: &Apache::loncommon::start_data_table_header_row().
4609: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4610: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4611: &Apache::loncommon::end_data_table_header_row();
4612: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 4613: my ($major,$minor) = split(/\./,$rev);
4614: ($reqdmajor,$reqdminor) =
4615: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4616: $output .= &Apache::loncommon::start_data_table_row().
4617: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4618: my $newrow;
4619: foreach my $scope (@scopeorder) {
4620: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4621: if ($newrow) {
4622: $output .= &Apache::loncommon::continue_data_table_row();
4623: }
1.39 raeburn 4624: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4625: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4626: $output .= '<td>'.$which.'</td><td>'.
4627: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4628: }
4629: $output .= &Apache::loncommon::end_data_table_row();
4630: $newrow = 1;
4631: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4632: if ($newrow) {
4633: $output .= &Apache::loncommon::continue_data_table_row();
4634: }
1.39 raeburn 4635: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4636: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4637: &Apache::loncommon::end_data_table_row();
4638: $newrow = 1;
4639: }
4640: }
4641: }
4642: $output .= &Apache::loncommon::end_data_table().'<br />';
4643: }
4644: }
4645:
1.66 raeburn 4646: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4647: my $now = time;
4648: if (keys(%comm_blocks) > 0) {
4649: foreach my $block (keys(%comm_blocks)) {
4650: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 4651: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 4652: if (ref($comm_blocks{$block}) eq 'HASH') {
4653: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4654: ' '.&mt('set by [_1]',
4655: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4656: }
4657: next;
4658: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4659: my ($start,$end) = ($1,$2);
4660: next if ($end < $now);
4661: }
4662: if (ref($comm_blocks{$block}) eq 'HASH') {
4663: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4664: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4665: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 4666: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 4667: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4668: ' '.
4669: &mt('set by [_1]',
4670: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4671: }
4672: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 4673: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 4674: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4675: ' '.
4676: &mt('set by [_1]',
4677: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4678:
4679: }
4680: }
4681: }
4682: }
4683: if (keys(%fromblocks)) {
4684: my %lt = (
4685: docs => 'Content blocking',
4686: printout => 'Printout generation',
4687: timer => 'Timed quiz trigger',
4688: );
4689: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4690: &Apache::loncommon::start_data_table().
4691: &Apache::loncommon::start_data_table_header_row().
4692: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4693: '<th>'.&mt('Event(s)').'</th>'.
4694: &Apache::loncommon::end_data_table_header_row();
4695: foreach my $type ('docs','printout','timer') {
4696: if (ref($fromblocks{$type}) eq 'HASH') {
4697: foreach my $rev (keys(%{$fromblocks{$type}})) {
4698: my ($major,$minor) = split(/\./,$rev);
1.124 raeburn 4699: ($reqdmajor,$reqdminor) =
1.66 raeburn 4700: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4701: $output .= &Apache::loncommon::start_data_table_row().
4702: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4703: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4704: $output .= $event.'<br />';
4705: }
4706: $output =~ s{\Q<br />\E$}{};
4707: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4708: }
4709: }
4710: }
4711: $output .= &Apache::loncommon::end_data_table().'<br />';
4712: }
4713: }
4714:
1.36 raeburn 4715: if (defined($navmap)) {
4716: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 4717: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 4718: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 4719: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 4720: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 4721: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4722: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4723: my $valanon=&get_param_description($stdtype,'anonsurvey');
4724: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 4725: my %checkedrev;
1.85 raeburn 4726: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 4727: my @parts = @{$res->parts()};
4728: my $symb = $res->symb();
4729: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 4730: if ($res->is_tool()) {
4731: my $rev = $rev_exttool;
4732: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
4733: $allmaps{$enclosing_map} = 1;
4734: next;
4735: }
1.36 raeburn 4736: foreach my $part (@parts) {
4737: if (exists($anonsubms{$symb."\0".$part})) {
4738: my $rev = $rev_anonsurv;
4739: my $what="$stdname=$valanon";
4740: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4741: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4742: push(@{$bysubmission{$symb}{$rev}},$what);
4743: }
4744: } else {
4745: push(@{$bysubmission{$symb}{$rev}},$what);
4746: }
4747: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4748: unless ($checkedrev{'anonsurvey'}) {
4749: my ($major,$minor) = split(/\./,$rev);
4750: ($reqdmajor,$reqdminor) =
4751: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4752: $reqdmajor,$reqdminor);
4753: $checkedrev{'anonsurvey'} = 1;
4754: }
1.36 raeburn 4755: }
4756: if (exists($randtrysubms{$symb."\0".$part})) {
4757: my $rev = $rev_randtry;
4758: my $what="$stdname=$valrandtry";
4759: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4760: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4761: push(@{$bysubmission{$symb}{$rev}},$what);
4762: }
4763: } else {
4764: push(@{$bysubmission{$symb}{$rev}},$what);
4765: }
4766: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4767: unless ($checkedrev{'randomizetry'}) {
4768: my ($major,$minor) = split(/\./,$rev);
4769: ($reqdmajor,$reqdminor) =
4770: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4771: $reqdmajor,$reqdminor);
4772: $checkedrev{'randomizetry'} = 1;
4773: }
1.36 raeburn 4774: }
4775: }
4776: my %responses = $res->responseTypes();
4777: foreach my $key (keys(%responses)) {
1.66 raeburn 4778: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4779: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4780: unless ($checkedrev{$key}) {
4781: my ($major,$minor) = split(/\./,$rev);
4782: ($reqdmajor,$reqdminor) =
4783: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4784: $reqdmajor,$reqdminor);
4785: $checkedrev{$key} = 1;
1.124 raeburn 4786: }
1.66 raeburn 4787: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4788: $allmaps{$enclosing_map} = 1;
4789: }
4790: }
4791: }
4792: if (keys(%byresource) > 0) {
4793: foreach my $symb (keys(%byresource)) {
4794: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4795: $allmaps{$map} = 1;
4796: }
4797: }
4798: if (keys(%bymap) > 0) {
4799: foreach my $map (keys(%bymap)) {
4800: $allmaps{$map} = 1;
4801: }
4802: }
4803: foreach my $map (keys(%allmaps)) {
4804: my $mapres = $navmap->getResourceByUrl($map);
4805: if (ref($mapres)) {
1.68 raeburn 4806: my $mapsymb = $mapres->symb();
4807: $toshow{$mapsymb} = 1;
1.36 raeburn 4808: my $pcslist = $mapres->map_hierarchy();
4809: if ($pcslist ne '') {
4810: foreach my $pc (split(/,/,$pcslist)) {
4811: my $res = $navmap->getByMapPc($pc);
4812: if (ref($res)) {
4813: my $symb = $res->symb();
4814: unless ($symb eq '______') {
4815: $toshow{$symb} = 1;
4816: }
4817: }
4818: }
4819: }
4820: }
4821: }
4822: }
1.117 raeburn 4823: my $supptools = &Apache::lonnet::count_supptools($cnum,$cdom,1,1);
1.36 raeburn 4824: my $mapres_header = '<h4>'.
4825: &mt('Requirements for specific folders or resources').
4826: '</h4>';
4827: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4828: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4829: $output .= $mapres_header;
4830: }
4831: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4832: my $title = 'Version Constraints';
4833: my $start_page =
4834: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4835: $r->print($start_page.$top_header);
4836: if ($output) {
4837: $r->print($output);
1.86 raeburn 4838: if (defined($navmap) || $supptools) {
1.36 raeburn 4839: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4840: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4841: }
4842: $r->print('<br /><br />');
4843: } else {
4844: $r->print('<p class="LC_info">'.
4845: &mt('No version requirements from resource content or settings.').
4846: '</p>');
4847: }
4848: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4849: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4850: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4851: return 1;
4852: }
1.36 raeburn 4853: return;
4854: }
4855:
4856: sub show_contents_view {
1.39 raeburn 4857: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 4858: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
4859: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4860: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4861: my $showmaincontent;
4862: if ((ref($navmap)) &&
4863: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4864: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
4865: (keys(%{$bycrsrestype}) > 0))) {
4866: $showmaincontent = 1;
4867: }
4868: if ($showmaincontent || $supptools) {
4869: $r->print(&Apache::loncommon::start_data_table());
4870: }
4871: if ($showmaincontent) {
4872: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 4873: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 4874: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 4875: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4876: '<th>'.&mt('Attribute/Setting').'</th>'.
4877: &Apache::loncommon::end_data_table_header_row().
4878: &Apache::loncommon::start_data_table_row().
1.58 raeburn 4879: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 4880: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
4881: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4882: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4883: my $curRes;
4884: my $depth = 0;
4885: my %parent = ();
4886: my $startcount = 5;
4887: my $lastcontainer = $startcount;
4888: while ($curRes = $it->next()) {
4889: if ($curRes == $it->BEGIN_MAP()) {
4890: $depth++;
4891: $parent{$depth}= $lastcontainer;
4892: }
4893: if ($curRes == $it->END_MAP()) {
4894: $depth--;
4895: $lastcontainer = $parent{$depth};
4896: }
4897: my $indent;
4898: for (my $i=0; $i<$depth; $i++) {
4899: $indent.= $whitespace;
4900: }
4901: if (ref($curRes)) {
4902: my $symb = $curRes->symb();
4903: my $ressymb = $symb;
4904: my $srcf = $curRes->src();
4905: my $title = &Apache::lonnet::gettitle($srcf);
4906: if (($curRes->is_sequence()) || ($curRes->is_page())) {
4907: next unless($toshow->{$symb});
4908: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
4909: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4910: if ($curRes->is_page()) {
4911: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
4912: }
4913: my $rowspan = 1;
4914: if (ref($bymap->{$url}) eq 'HASH') {
4915: $rowspan = scalar(keys(%{$bymap->{$url}}));
4916: }
4917: $r->print(&Apache::loncommon::start_data_table_row().
4918: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 4919: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 4920: $r->print(&Apache::loncommon::end_data_table_row());
4921: } else {
4922: my $rowspan;
4923: if (ref($byresource->{$symb}) eq 'HASH') {
4924: $rowspan += scalar(keys(%{$byresource->{$symb}}));
4925: }
4926: if (ref($bysubmission->{$symb}) eq 'HASH') {
4927: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
4928: }
4929: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4930: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
4931: }
1.85 raeburn 4932: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
4933: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
4934: }
1.36 raeburn 4935: next if (!$rowspan);
4936: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
4937: &mt('Problem').'" />';
4938: $r->print(&Apache::loncommon::start_data_table_row().
4939: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
4940: my $newrow;
4941: if (ref($byresource->{$symb}) eq 'HASH') {
4942: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
4943: if ($newrow) {
4944: $r->print(&Apache::loncommon::continue_data_table_row());
4945: }
4946: $r->print('<td valign="middle">'.$rev.'</td><td>');
4947: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
4948: $r->print('<table border="0">');
4949: foreach my $scope (@{$scopeorder}) {
4950: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4951: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4952: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
4953: $r->print('<td>'.$which.'</td><td>'.
4954: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
4955: '</td>');
4956: }
4957: $r->print('</tr>');
4958: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4959: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 4960: '<td> </td><td>'.
4961: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
4962: }
4963: }
4964: $r->print('</table>');
4965: }
4966: $r->print('</td>');
4967: $r->print(&Apache::loncommon::end_data_table_row());
4968: $newrow = 1;
4969: }
4970: }
4971: if (ref($bysubmission->{$symb}) eq 'HASH') {
4972: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
4973: if ($newrow) {
4974: $r->print(&Apache::loncommon::continue_data_table_row());
4975: }
4976: $r->print('<td>'.$rev.'</td><td>');
4977: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
4978: $r->print(&mt('Submissions to: ').' '.
4979: join(', ',@{$bysubmission->{$symb}{$rev}}));
4980: }
4981: $r->print('</td>');
4982: $r->print(&Apache::loncommon::end_data_table_row());
4983: $newrow = 1;
4984: }
4985: }
4986: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4987: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
4988: if ($newrow) {
4989: $r->print(&Apache::loncommon::continue_data_table_row());
4990: }
4991: $r->print('<td>'.$rev.'</td><td>');
4992: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
4993: $r->print(&mt('Response Type(s): ').' '.
4994: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
4995: }
4996: $r->print('</td>');
4997: }
4998: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 4999: $newrow = 1;
5000: }
5001: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5002: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
5003: if ($newrow) {
5004: $r->print(&Apache::loncommon::continue_data_table_row());
5005: }
5006: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
5007: }
1.86 raeburn 5008: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5009: }
5010: }
5011: }
5012: }
1.86 raeburn 5013: }
5014: if ($supptools) {
5015: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5016: $r->print(&Apache::loncommon::start_data_table_header_row().
5017: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5018: '<th>'.&mt('Resource Type').'</th>'.
5019: &Apache::loncommon::end_data_table_header_row().
5020: &Apache::loncommon::start_data_table_row().
5021: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
5022: '<td valign="middle">'.
5023: $Apache::lonrelrequtils::exttool{'major'}.'.'.
5024: $Apache::lonrelrequtils::exttool{'minor'}.
5025: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
5026: $supptools).'</td>'.
5027: &Apache::loncommon::end_data_table_row());
5028: }
5029: if ($showmaincontent || $supptools) {
1.36 raeburn 5030: $r->print(&Apache::loncommon::end_data_table());
5031: }
1.66 raeburn 5032: return;
1.36 raeburn 5033: }
5034:
5035: sub releases_by_map {
1.39 raeburn 5036: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 5037: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.124 raeburn 5038: my $newrow = 0;
1.36 raeburn 5039: if (ref($bymap->{$url}) eq 'HASH') {
5040: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 5041: if ($newrow) {
5042: $r->print(&Apache::loncommon::end_data_table_row().
5043: &Apache::loncommon::continue_data_table_row());
5044: }
1.36 raeburn 5045: $r->print('<td valign="middle">'.$rev.'</td><td>');
5046: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
5047: $r->print('<table border="0">');
5048: foreach my $scope (@{$scopeorder}) {
5049: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5050: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5051: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
5052: $r->print('<td>'.$which.'</td><td>'.
5053: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
5054: '</td>');
5055: }
5056: $r->print('</tr>');
5057: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5058: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 5059: '</td><td> </td><td>'.
5060: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
5061: }
5062: }
5063: $r->print('</table>');
5064: }
5065: $r->print('</td>');
1.73 raeburn 5066: $newrow = 1;
1.36 raeburn 5067: }
5068: } else {
5069: $r->print('<td colspan="2"> </td>');
5070: }
5071: return;
5072: }
5073:
5074: sub get_param_description {
1.70 raeburn 5075: my ($stdtype,$value,$regexp) = @_;
5076: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 5077: if ($stdtype =~ /^string/) {
5078: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5079: } elsif ($stdtype eq 'date_interval') {
5080: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
5081: }
1.70 raeburn 5082: if ($regexp) {
1.74 raeburn 5083: if ($stdtype =~ /^string/) {
5084: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
5085: } elsif ($stdtype eq 'date_interval') {
5086: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
5087: }
1.70 raeburn 5088: if (ref($parammatches) eq 'ARRAY') {
5089: @possibles = @{$parammatches};
5090: } else {
5091: undef($regexp);
5092: $name = $value;
5093: }
5094: }
5095: unless ($regexp) {
5096: $name = $value;
5097: if (ref($paramstrings) eq 'ARRAY') {
5098: @possibles = @{$paramstrings};
5099: } else {
1.76 raeburn 5100: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
5101: if ($name == 0) {
5102: $name = &mt('Never');
5103: } elsif (($name ne '') && ($name !~ /\D/)) {
5104: $name = &Apache::lonlocal::locallocaltime($name);
5105: }
5106: }
1.70 raeburn 5107: return $name;
5108: }
1.36 raeburn 5109: }
1.70 raeburn 5110: foreach my $possibilities (@possibles) {
1.36 raeburn 5111: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 5112: my $gotregexmatch = '';
5113: if ($regexp) {
5114: last if ($gotregexmatch);
5115: my ($item,$pattern) = @{ $possibilities };
5116: if ($value =~ /$pattern/) {
5117: if (ref($paramstrings) eq 'ARRAY') {
5118: foreach my $possibles (@{$paramstrings}) {
5119: next unless (ref($possibles) eq 'ARRAY');
5120: my ($thing,$description) = @{$possibles};
5121: if ($thing eq $item) {
5122: $name = $description;
5123: $gotregexmatch = 1;
5124: last;
5125: }
5126: }
5127: last if ($gotregexmatch);
5128: }
5129: }
5130: } else {
5131: my ($thing,$description) = @{ $possibilities };
5132: if ($thing eq $value) {
5133: $name = $description;
5134: last;
5135: }
1.36 raeburn 5136: }
5137: }
5138: return $name;
5139: }
5140:
1.66 raeburn 5141: sub update_releasereq {
5142: my $readmap = 1;
5143: my $getrelreq = 1;
5144: if (ref($modified_courses) eq 'ARRAY') {
5145: foreach my $item (@{$modified_courses}) {
5146: if (ref($item) eq 'ARRAY') {
5147: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5148: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5149: $chome,$crstype,$cdom.'_'.$cnum,
5150: $readmap,$getrelreq);
5151: }
5152: }
5153: $modified_courses = [];
5154: }
5155: undef($registered_cleanup);
5156: return;
5157: }
5158:
1.25 raeburn 5159: sub show_autocoowners {
5160: my (@currcoown) = @_;
1.56 raeburn 5161: 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 5162: if (@currcoown > 0) {
5163: $output .= '<br />'.&mt('Current co-owners are:').' '.
5164: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5165: } else {
5166: $output .= '<br />'.&mt('Currently no co-owners.');
5167: }
5168: return $output;
5169: }
5170:
5171: sub coowner_invitations {
1.80 raeburn 5172: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5173: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5174: my $pendingcoowners =
5175: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5176: if ($pendingcoowners) {
5177: @pendingcoown = split(',',$pendingcoowners);
5178: }
1.80 raeburn 5179: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5180: @currcoown = @{$currcoownref};
1.80 raeburn 5181: }
5182: my $disabled;
5183: if ($noedit) {
5184: $disabled = ' disabled="disabled"';
5185: }
1.25 raeburn 5186: my $ccrole = 'cc';
5187: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5188: foreach my $key (sort(keys(%ccroles))) {
5189: my ($ccname,$ccdom,$role) = split(':',$key);
5190: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5191: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5192: push(@othercoords,$ccname.':'.$ccdom);
5193: }
5194: }
5195: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5196: if ($coowner_rows) {
5197: $output .= &Apache::loncommon::start_data_table();
5198: if (@currcoown) {
5199: $output .= &Apache::loncommon::start_data_table_row().
5200: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5201: foreach my $person (@currcoown) {
5202: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5203: $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 5204: }
5205: $output .= '</td>'.
5206: &Apache::loncommon::end_data_table_row();
5207: }
5208: if ($pendingcoowners) {
5209: $output .= &Apache::loncommon::start_data_table_row().
5210: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5211: foreach my $person (@pendingcoown) {
5212: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5213: $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 5214: }
5215: $output .= '</td>'.
5216: &Apache::loncommon::end_data_table_row();
5217: }
5218: if (@othercoords) {
5219: $output .= &Apache::loncommon::start_data_table_row().
5220: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5221: foreach my $person (@othercoords) {
5222: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5223: $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 5224: }
5225: $output .= '</td>'.
5226: &Apache::loncommon::end_data_table_row();
5227: }
5228: $output .= &Apache::loncommon::end_data_table();
5229: } else {
5230: $output = &mt('There are no coordinators to select as co-owners');
5231: }
5232: return $output;
5233: }
5234:
5235: sub manage_coownership {
1.80 raeburn 5236: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5237: my (@pendingcoown,@currcoown);
1.25 raeburn 5238: my $pendingcoowners =
5239: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5240: if ($pendingcoowners) {
5241: @pendingcoown = split(',',$pendingcoowners);
5242: }
1.80 raeburn 5243: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5244: @currcoown = @{$currcoownref};
1.80 raeburn 5245: }
5246: my $disabled;
5247: if ($noedit) {
5248: $disabled = ' disabled="disabled"';
5249: }
1.25 raeburn 5250: my ($is_coowner,$is_pending,$output);
5251: my $uname = $env{'user.name'};
5252: my $udom = $env{'user.domain'};
5253: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5254: $is_coowner = 1;
5255: }
5256: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5257: $is_pending = 1;
5258: }
5259: if (@currcoown && ($is_coowner || $is_pending)) {
5260: $output = &Apache::loncommon::start_data_table();
5261: }
5262: if (@currcoown) {
5263: if ($is_coowner || $is_pending) {
5264: $output .= &Apache::loncommon::start_data_table().
5265: &Apache::loncommon::start_data_table_row().'<td>';
5266: }
5267: $output .= &mt('Current co-owners are:').' '.
5268: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5269: if ($is_coowner || $is_pending) {
5270: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5271: }
5272: }
5273: if ($is_coowner || $is_pending) {
5274: if (@currcoown) {
5275: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5276: }
5277: $output .= '<span class="LC_nobreak">';
5278: if ($is_coowner) {
1.90 raeburn 5279: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5280: } else {
1.90 raeburn 5281: $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).
5282: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5283: }
5284: $output .= '</span>';
5285: if (@currcoown) {
5286: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5287: }
5288: }
5289: if (@currcoown && ($is_coowner || $is_pending)) {
5290: $output .= &Apache::loncommon::end_data_table();
5291: }
5292: return $output;
5293: }
5294:
1.1 raeburn 5295: sub print_localization {
1.80 raeburn 5296: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5297: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5298: return;
5299: }
5300: my %items = (
5301: languages => {
1.17 faziophi 5302: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5303: &mt("(overrides individual user preference)"),
1.1 raeburn 5304: input => 'selectbox',
5305: },
5306: timezone => {
1.17 faziophi 5307: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5308: input => 'selectbox',
5309: },
5310: datelocale => {
1.17 faziophi 5311: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5312: input => 'selectbox',
5313: },
5314: );
1.80 raeburn 5315: my ($datatable,$disabled);
1.1 raeburn 5316: my $count = 0;
1.80 raeburn 5317: if ($noedit) {
5318: $disabled = ' disabled="disabled"';
5319: }
1.1 raeburn 5320: foreach my $item (@{$ordered}) {
5321: $count ++;
1.56 raeburn 5322: my $colspan;
5323: unless ($item eq 'languages') {
1.80 raeburn 5324: $colspan = 2;
1.56 raeburn 5325: }
5326: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5327: if ($item eq 'timezone') {
5328: my $includeempty = 1;
5329: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5330: my $onchange;
5331: unless ($noedit) {
5332: $onchange = ' onchange="javascript:toggleTimeZone();"';
5333: }
5334: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5335: $datatable .=
1.115 raeburn 5336: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5337: $includeempty,$id,$disabled);
5338: my $tzsty = 'none';
5339: if ($timezone ne '') {
5340: $tzsty = 'block';
5341: }
5342: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5343: '<span class="LC_nobreak">'.
5344: &mt('Override individual user preference?').
5345: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5346: '</span></div>';
1.1 raeburn 5347: } elsif ($item eq 'datelocale') {
5348: my $includeempty = 1;
5349: my $locale_obj = &Apache::lonlocal::getdatelocale();
5350: my $currdatelocale;
5351: if (ref($locale_obj)) {
5352: $currdatelocale = $locale_obj->id();
5353: }
5354: $datatable .=
5355: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5356: undef,$includeempty,$disabled);
1.1 raeburn 5357: } else {
5358: if ($settings->{$item} eq '') {
1.124 raeburn 5359: unless ($noedit) {
1.80 raeburn 5360: $datatable .= '</td><td align="right">'.
5361: &Apache::loncommon::select_language('languages_0','',1);
5362: }
1.1 raeburn 5363: } else {
5364: my $num = 0;
1.3 raeburn 5365: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5366: $datatable .= '</td><td align="right"><br />'.
5367: &Apache::loncommon::start_data_table();
1.1 raeburn 5368: if (@languages > 0) {
1.3 raeburn 5369: my %langchoices = &get_lang_choices();
1.1 raeburn 5370: foreach my $lang (@languages) {
5371: my $showlang = $lang;
1.3 raeburn 5372: if (exists($langchoices{$lang})) {
5373: $showlang = $langchoices{$lang};
1.1 raeburn 5374: }
5375: $datatable .=
5376: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5377: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5378: &mt('Language:').'<b> '.$showlang.
5379: '</b><input type="hidden" name="languages_'.$num.
5380: '" value="'.$lang.'" /></span><br />'.
5381: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5382: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5383: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5384: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5385: $num ++;
5386: }
5387: }
1.80 raeburn 5388: unless ($noedit) {
5389: $datatable .=
5390: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5391: '<td align="left"><span class="LC_nobreak">'.
5392: &mt('Additional language:'). '</span><br />'.
5393: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5394: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5395: '</td>'.&Apache::loncommon::end_data_table_row();
1.124 raeburn 5396: }
5397: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5398: }
5399: }
5400: $datatable .= &item_table_row_end();
5401: }
5402: $$rowtotal += scalar(@{$ordered});
5403: return $datatable;
5404: }
5405:
1.3 raeburn 5406: sub get_lang_choices {
5407: my %langchoices;
5408: foreach my $id (&Apache::loncommon::languageids()) {
5409: my $code = &Apache::loncommon::supportedlanguagecode($id);
5410: if ($code) {
5411: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5412: }
5413: }
5414: return %langchoices;
5415: }
5416:
1.1 raeburn 5417: sub print_feedback {
1.80 raeburn 5418: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5419: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5420: return;
5421: }
5422: my %items = (
1.3 raeburn 5423: 'question.email' => {
5424: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5425: input => 'textbox',
5426: size => '50',
5427: },
5428:
1.3 raeburn 5429: 'comment.email' => {
5430: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5431: input => 'textbox',
5432: size => '50',
5433: },
5434:
1.3 raeburn 5435: 'policy.email' => {
5436: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5437: input => 'textbox',
5438: size => '50',
5439: },
5440: );
5441: my $datatable;
5442: my $count = 0;
5443: my ($cnum) = &get_course();
5444: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5445: my @sections = sort( { $a <=> $b } keys(%sections));
5446: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5447: currone => 'Current recipient:',
5448: currmult => 'Current recipients:',
5449: add => 'Additional recipient:',
5450: del => 'Delete?',
5451: sec => 'Sections:',
1.1 raeburn 5452: );
1.80 raeburn 5453: my $disabled;
5454: if ($noedit) {
5455: $disabled = ' disabled="disabled"';
5456: }
1.1 raeburn 5457: foreach my $item (@{$ordered}) {
5458: $count ++;
1.20 faziophi 5459: if ($position eq 'top') {
5460: $datatable .= &item_table_row_start($items{$item}{text},$count);
5461: } else {
1.56 raeburn 5462: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5463: }
1.1 raeburn 5464: if ($position eq 'top') {
5465: my $includeempty = 0;
1.94 raeburn 5466: $datatable .= '</td><td align="right">'.
5467: &user_table($cdom,$item,\@sections,
1.80 raeburn 5468: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5469: } else {
1.3 raeburn 5470: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5471: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5472: }
5473: $datatable .= &item_table_row_end();
5474: }
5475: $$rowtotal += scalar(@{$ordered});
5476: return $datatable;
5477: }
5478:
5479: sub user_table {
1.80 raeburn 5480: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5481: my $output;
5482: if ($currvalue eq '') {
1.80 raeburn 5483: unless ($noedit) {
5484: $output .= &select_recipient($item,'0',$cdom,$sections);
5485: }
1.1 raeburn 5486: } else {
5487: my $num = 0;
5488: my @curr = split(/,/,$currvalue);
1.56 raeburn 5489: $output .= '<table class="LC_data_table">';
1.1 raeburn 5490: my ($currusers);
1.80 raeburn 5491: my $disabled;
5492: if ($noedit) {
5493: $disabled = ' disabled="disabled"';
5494: }
1.1 raeburn 5495: foreach my $val (@curr) {
5496: next if ($val eq '');
5497: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5498: my @selsec;
5499: if ($seclist) {
5500: $seclist =~ s/(^\(|\)$)//g;
5501: @selsec = split(/\s*;\s*/,$seclist);
5502: }
5503: $currusers .= '<tr>'.
5504: '<td valign="top"><span class="LC_nobreak">'.
5505: '<label><input type="checkbox" '.
1.80 raeburn 5506: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5507: $lt->{'del'}.'</label>'.
5508: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5509: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5510: &Apache::loncommon::aboutmewrapper(
5511: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5512: $uname,$udom,'aboutuser');
5513: if (ref($sections) eq 'ARRAY') {
5514: if (@{$sections}) {
5515: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5516: &select_sections($item,$num,$sections,
1.80 raeburn 5517: \@selsec,$noedit);
1.1 raeburn 5518: }
5519: }
5520: $currusers .= '</span></td></tr>';
5521: $num ++;
5522: }
5523: if ($num) {
1.10 raeburn 5524: $output .= '<tr>'.
1.1 raeburn 5525: '<td align="left"><i>';
1.20 faziophi 5526: if ($num == 1) {
1.1 raeburn 5527: $output .= $lt->{'currone'};
5528: } else {
1.21 raeburn 5529: $output .= $lt->{'currmult'};
1.1 raeburn 5530: }
5531: $output .= '</i><br />'.
5532: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5533: '</tr>';
1.1 raeburn 5534: }
1.80 raeburn 5535: unless ($noedit) {
5536: $output .=
5537: '<tr>'.
1.1 raeburn 5538: '<td align="left"><span class="LC_nobreak"><i>'.
5539: $lt->{'add'}.'</i></span><br />'.
5540: &select_recipient($item,$num,$cdom,$sections).
5541: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5542: '</td></tr>';
5543: }
5544: $output .= '</table>';
1.1 raeburn 5545: }
5546: return $output;
5547: }
5548:
5549: sub select_recipient {
5550: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5551: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5552: my $selectlink =
5553: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5554: $item.'_udom_'.$num,'only');
1.1 raeburn 5555: my $output =
1.10 raeburn 5556: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5557: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5558: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5559: if (ref($sections) eq 'ARRAY') {
5560: if (@{$sections}) {
5561: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5562: &select_sections($item,$num,$sections,$selected).'</td>';
5563: }
5564: }
5565: $output .= '<td valign="top">'.
5566: $selectlink.'</td></tr></table>';
5567: return $output;
5568: }
5569:
5570: sub select_sections {
1.80 raeburn 5571: my ($item,$num,$sections,$selected,$noedit) = @_;
5572: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5573: if (ref($selected) eq 'ARRAY') {
5574: @currsecs = @{$selected};
5575: }
5576: if (!@currsecs) {
5577: $allsec = ' selected="selected"';
5578: }
1.80 raeburn 5579: if ($noedit) {
5580: $disabled = ' disabled="disabled"';
5581: }
1.1 raeburn 5582: if (ref($sections) eq 'ARRAY') {
5583: if (@{$sections}) {
5584: my $mult;
5585: if (@{$sections} > 1) {
5586: $mult = ' multiple="multiple"';
5587: if (@{$sections} > 3) {
5588: $mult .= ' size="4"';
5589: }
5590: }
1.80 raeburn 5591: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
1.1 raeburn 5592: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
5593: foreach my $sec (@{$sections}) {
5594: my $is_sel;
5595: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
5596: $is_sel = 'selected="selected"';
5597: }
5598: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5599: }
5600: $output .= '</select>';
5601: }
5602: }
5603: return $output;
5604: }
5605:
5606: sub print_discussion {
1.80 raeburn 5607: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5608: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5609: return;
5610: }
5611: my %items = (
5612: 'plc.roles.denied' => {
1.10 raeburn 5613: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5614: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5615: &mt('(role-based)'),
1.1 raeburn 5616: input => 'checkbox',
5617: },
5618:
5619: 'plc.users.denied' => {
1.3 raeburn 5620: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5621: &mt('(specific user(s))'),
1.1 raeburn 5622: input => 'checkbox',
5623: },
5624:
5625: 'pch.roles.denied' => {
1.10 raeburn 5626: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5627: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5628: &mt('(role-based)'),
1.1 raeburn 5629: input => 'checkbox',
5630: },
5631:
5632: 'pch.users.denied' => {
1.3 raeburn 5633: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5634: &mt('(specific user(s))'),
1.1 raeburn 5635: input => 'checkbox',
5636: },
1.77 raeburn 5637:
5638: 'pac.roles.denied' => {
5639: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5640: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5641: &mt('(role-based)'),
5642: input => 'checkbox',
5643: },
5644:
5645: 'pac.users.denied' => {
5646: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5647: &mt('(specific user(s))'),
5648: input => 'checkbox',
5649: },
5650:
1.1 raeburn 5651: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5652: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5653: input => 'radio',
5654: },
5655:
5656: 'allow_discussion_post_editing' => {
1.3 raeburn 5657: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5658: input => 'checkbox',
5659: },
1.50 raeburn 5660: 'discussion_post_fonts' => {
5661: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5662: input => 'textbox',
5663: size => '20',
5664: },
1.1 raeburn 5665: );
5666: my $datatable;
5667: my $count;
5668: my ($cnum) = &get_course();
5669: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5670: my @sections = sort( { $a <=> $b } keys(%sections));
5671: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5672: currone => 'Disallowed:',
5673: currmult => 'Disallowed:',
5674: add => 'Disallow more:',
5675: del => 'Delete?',
5676: sec => 'Sections:',
1.1 raeburn 5677: );
5678: foreach my $item (@{$ordered}) {
5679: $count ++;
1.56 raeburn 5680: my $colspan;
5681: if ($item eq 'allow_limited_html_in_feedback') {
5682: $colspan = 2;
1.124 raeburn 5683: }
1.56 raeburn 5684: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5685: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5686: $datatable .= '</td><td align="right">'.
1.80 raeburn 5687: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5688: '</table>';
5689: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5690: $datatable .= '</td><td align="right">'.
5691: &user_table($cdom,$item,undef,
1.80 raeburn 5692: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5693: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5694: $datatable .= '</td><td align="right">'.
1.80 raeburn 5695: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5696: '</table>';
5697: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5698: $datatable .= '</td><td align="right">'.
5699: &user_table($cdom,$item,undef,
1.80 raeburn 5700: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5701: } elsif ($item eq 'pac.roles.denied') {
5702: $datatable .= '</td><td align="right">'.
1.80 raeburn 5703: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5704: '</table>';
5705: } elsif ($item eq 'pac.users.denied') {
5706: $datatable .= '</td><td align="right">'.
5707: &user_table($cdom,$item,undef,
1.80 raeburn 5708: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5709: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5710: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5711: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5712: $datatable .= '</td><td align="right"><br />'.
5713: &Apache::loncommon::start_data_table().
1.1 raeburn 5714: &Apache::loncommon::start_data_table_row().
5715: '<th align="left">'.&mt('Role').'</th><th>'.
5716: &mt('Sections').'</th>'.
5717: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5718: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5719: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5720: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5721: $datatable .= '</td><td align="right"><br />'.
5722: &Apache::loncommon::start_data_table().
1.50 raeburn 5723: &Apache::loncommon::start_data_table_row().
5724: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5725: '<th align="center">'.&mt('font-size').'</th>'.
5726: '<th align="center">'.&mt('font-weight').'</th>'.
5727: '<th align="center">'.&mt('font-style').'</th>'.
1.124 raeburn 5728: '<th align="center">'.&mt('Other css').'</th>'.
1.50 raeburn 5729: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5730: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5731: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5732: }
5733: $datatable .= &item_table_row_end();
5734: }
5735: $$rowtotal += scalar(@{$ordered});
5736: return $datatable;
5737: }
5738:
5739: sub role_checkboxes {
1.80 raeburn 5740: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5741: my @roles = ('st','ad','ta','ep','in');
5742: if ($crstype eq 'Community') {
5743: push(@roles,'co');
5744: } else {
5745: push(@roles,'cc');
5746: }
1.1 raeburn 5747: my $output;
5748: my (@current,@curr_roles,%currsec,@sections);
5749: if ($showsections) {
5750: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5751: @sections = sort( { $a <=> $b } keys(%sections));
5752: }
5753: if (ref($settings) eq 'HASH') {
5754: if ($settings->{$item}) {
5755: @current = split(',',$settings->{$item});
5756: if ($showsections) {
5757: foreach my $role (@current) {
5758: if ($role =~ /:/) {
5759: my ($trole,$sec) = split(':',$role);
5760: push(@curr_roles,$trole);
5761: if (ref($currsec{$trole}) eq 'ARRAY') {
5762: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5763: push(@{$currsec{$trole}},$sec);
5764: }
1.3 raeburn 5765: } else {
5766: $currsec{$trole} = [$sec];
1.1 raeburn 5767: }
5768: } else {
5769: push(@curr_roles,$role);
5770: }
5771: }
5772: @current = @curr_roles;
5773: }
5774: }
5775: }
5776: my $numinrow = 3;
5777: my $count = 0;
1.80 raeburn 5778: my $disabled;
5779: if ($noedit) {
1.124 raeburn 5780: $disabled = ' disabled="disabled"';
1.80 raeburn 5781: }
1.1 raeburn 5782: foreach my $role (@roles) {
5783: my $checked = '';
5784: if (grep(/^\Q$role\E$/,@current)) {
5785: $checked = ' checked="checked" ';
5786: }
1.9 raeburn 5787: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5788: if ($showsections) {
5789: $output .= &Apache::loncommon::start_data_table_row();
5790: } else {
5791: my $rem = $count%($numinrow);
5792: if ($rem == 0) {
5793: if ($count > 0) {
5794: $output .= '</tr>';
5795: }
5796: $output .= '<tr>';
5797: }
5798: }
1.30 raeburn 5799: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5800: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5801: $plrole.'</label></span></td>';
5802: if ($showsections) {
5803: $output .= '<td align="left">'.
1.80 raeburn 5804: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5805: '</td></tr>';
5806: }
5807: $count ++;
5808: }
5809: my %adv_roles =
5810: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5811: my $total = @roles;
5812: foreach my $role (sort(keys(%adv_roles))) {
5813: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5814: my $rolename = $3;
5815: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5816: my $checked = '';
5817: if (grep(/^\Q$value\E$/,@current)) {
5818: $checked = ' checked="checked" ';
5819: }
5820: if ($showsections) {
5821: $output .= &Apache::loncommon::start_data_table_row();
5822: } else {
5823: my $rem = $count%($numinrow);
5824: if ($rem == 0) {
5825: if ($count > 0) {
5826: $output .= '</tr>';
5827: }
5828: $output .= '<tr>';
5829: }
5830: }
1.30 raeburn 5831: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5832: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5833: '</label></span></td>';
5834: if ($showsections) {
5835: $output .= '<td>'.
1.80 raeburn 5836: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5837: '</td>'.&Apache::loncommon::end_data_table_row();
5838: }
5839: $total ++;
5840: $count ++;
5841: }
5842: }
5843: if (!$showsections) {
5844: my $rem = $total%($numinrow);
5845: my $colsleft = $numinrow - $rem;
5846: if ($colsleft > 1 ) {
5847: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5848: ' </td>';
5849: } elsif ($colsleft == 1) {
5850: $output .= '<td class="LC_left_item"> </td>';
5851: }
5852: $output .= '</tr>';
5853: }
5854: return $output;
5855: }
5856:
1.50 raeburn 5857: sub set_discussion_fonts {
1.80 raeburn 5858: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 5859: my ($classorder,$classtitles) = &discussion_vote_classes();
5860: my ($styleorder,$styleitems) = &discussion_vote_styles();
5861: my $output;
5862: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 5863: my $disabled;
5864: if ($noedit) {
5865: $disabled = ' disabled="disabled"';
5866: }
1.50 raeburn 5867: foreach my $cat (@{$classorder}) {
5868: my %curr = ();
5869: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5870: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5871: $output .= &Apache::loncommon::start_data_table_row().
5872: '<td>'.$classtitles->{$cat}.'</td>';
5873: if (ref($styleorder) eq 'ARRAY') {
5874: foreach my $item (@{$styleorder}) {
5875: $output .= '<td><span class="LC_nobreak">';
5876: my $selitem = $item;
5877: if ($item eq 'size') {
5878: my ($currsize,$currunit);
5879: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5880: ($currsize,$currunit) = ($1,$2);
5881: $curr{'size'} = $currunit;
5882: }
1.81 raeburn 5883: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 5884: ' ';
5885: $selitem = 'unit';
5886: }
5887: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 5888: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 5889: foreach my $val (@{$styleitems->{$item}}) {
5890: my $sel;
5891: if ($val eq $curr{$item}) {
5892: $sel = ' selected="selected"';
5893: }
5894: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
5895: }
5896: }
5897: }
5898: }
1.80 raeburn 5899: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 5900: }
5901: $output .= &Apache::loncommon::end_data_table_row();
5902: }
5903: return $output;
5904: }
5905:
5906: sub discussion_vote_classes {
5907: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
1.124 raeburn 5908: my %classtitles = &Apache::lonlocal::texthash(
1.50 raeburn 5909: 'twoplus' => 'Two sigma above mean',
5910: 'oneplus' => 'One sigma above mean',
5911: 'zero' => 'Within one sigma of mean',
5912: 'oneminus' => 'One sigma below mean',
5913: 'twominus' => 'Two sigma below mean',
5914: );
5915: return ($classorder,\%classtitles);
5916: }
5917:
5918: sub discussion_vote_styles {
5919: my $styleorder = ['size','weight','style'];
5920: my $styleitems = {
5921: size => ['','px','%','xx-small','x-small','small','medium','large',
5922: 'x-large','xx-large','smaller','larger'],
5923: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
5924: '500','600','700','800','900'],
5925: style => ['','normal','italic','oblique'],
5926: };
5927: return ($styleorder,$styleitems);
5928: }
5929:
1.1 raeburn 5930: sub print_classlists {
1.80 raeburn 5931: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5932: my @ordered;
5933: if ($position eq 'top') {
5934: @ordered = ('default_enrollment_start_date',
5935: 'default_enrollment_end_date');
1.55 raeburn 5936: if ($crstype eq 'Course') {
5937: push(@ordered,'defaultcredits');
5938: }
1.1 raeburn 5939: } elsif ($position eq 'middle') {
1.56 raeburn 5940: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 5941: } else {
5942: @ordered = ('student_classlist_view',
1.26 raeburn 5943: 'student_classlist_opt_in',
5944: 'student_classlist_portfiles');
1.1 raeburn 5945: }
1.9 raeburn 5946: my %lt;
5947:
5948: if ($crstype eq 'Community') {
5949: %lt = &Apache::lonlocal::texthash (
5950: disabled => 'No viewable membership list',
5951: section => "Membership of viewer's section",
5952: all => 'List of all members',
5953: );
5954: } else {
5955: %lt = &Apache::lonlocal::texthash (
5956: disabled => 'No viewable classlist',
5957: section => "Classlist of viewer's section",
5958: all => 'Classlist of all students',
5959: );
5960: }
5961:
1.1 raeburn 5962: my %items = (
5963: 'default_enrollment_start_date' => {
1.3 raeburn 5964: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 5965: input => 'dates',
5966: },
5967: 'default_enrollment_end_date' => {
1.3 raeburn 5968: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 5969: input => 'dates',
5970: },
1.55 raeburn 5971: 'defaultcredits' => {
5972: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
5973: },
1.124 raeburn 5974:
1.1 raeburn 5975: 'nothideprivileged' => {
1.3 raeburn 5976: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 5977: input => 'checkbox',
5978: },
5979:
1.56 raeburn 5980: 'checkforpriv' => {
5981: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
5982: input => 'selectbox',
5983: },
5984:
1.1 raeburn 5985: 'student_classlist_view' => {
1.3 raeburn 5986: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 5987: input => 'selectbox',
1.9 raeburn 5988: options => \%lt,
1.1 raeburn 5989: order => ['disabled','all','section'],
5990: },
1.26 raeburn 5991: 'student_classlist_opt_in' => {
5992: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 5993: input => 'radio',
5994: },
5995:
5996: 'student_classlist_portfiles' => {
1.3 raeburn 5997: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 5998: input => 'radio',
5999: },
6000: );
6001: unless (($settings->{'student_classlist_view'} eq 'all') ||
6002: ($settings->{'student_classlist_view'} eq 'section')) {
6003: $settings->{'student_classlist_view'} = 'disabled';
6004: }
1.80 raeburn 6005: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6006: }
6007:
6008: sub print_appearance {
1.80 raeburn 6009: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6010: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6011: return;
6012: }
1.9 raeburn 6013: my $mathdef;
6014: if ($crstype eq 'Community') {
6015: $mathdef = &mt("None specified - use member's choice");
6016: } else {
6017: $mathdef = &mt("None specified - use student's choice");
6018: }
1.1 raeburn 6019: my %items = (
6020: 'default_xml_style' => {
1.3 raeburn 6021: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6022: '<a href="javascript:openbrowser'.
6023: "('display','default_xml_style'".
6024: ",'sty')".'">'.&mt('Select Style File').'</a>',
6025: input => 'textbox',
6026: size => 35,
6027: },
6028:
6029: 'pageseparators' => {
1.3 raeburn 6030: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6031: input => 'radio',
6032: },
6033: 'disable_receipt_display' => {
1.3 raeburn 6034: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6035: input => 'radio',
6036: },
6037: 'texengine' => {
1.3 raeburn 6038: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6039: input => 'selectbox',
6040: options => {
1.61 raeburn 6041: MathJax => 'MathJax',
1.1 raeburn 6042: mimetex => &mt('Convert to Images'),
6043: tth => &mt('TeX to HTML'),
6044: },
1.75 raeburn 6045: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6046: nullval => $mathdef,
1.1 raeburn 6047: },
6048: 'tthoptions' => {
1.3 raeburn 6049: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6050: input => 'textbox',
6051: size => 40,
6052: },
1.69 raeburn 6053: 'uselcmath' => {
6054: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6055: input => 'radio',
6056: },
6057: 'usejsme' => {
6058: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6059: input => 'radio',
6060: },
1.95 raeburn 6061: 'inline_chem' => {
6062: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6063: input => 'radio',
6064: },
1.114 raeburn 6065: 'extresource' => {
6066: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6067: input => 'selectbox',
6068: options => {
6069: iframe => 'In iframe',
6070: tab => 'In new tab',
6071: window => 'In pop-up window',
6072: },
6073: order => ['iframe','tab','window'],
6074: },
1.1 raeburn 6075: );
1.80 raeburn 6076: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6077: }
6078:
6079: sub print_grading {
1.80 raeburn 6080: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6081: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6082: return;
6083: }
6084: my %items = (
6085: 'grading' => {
1.3 raeburn 6086: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6087: &Apache::loncommon::help_open_topic('GradingOptions'),
6088: input => 'selectbox',
6089: options => {
6090: standard => &mt('Standard: shows points'),
1.34 www 6091: categories => &mt('Categories: shows points according to categories'),
1.11 www 6092: external => &mt('External: shows number of completed parts and totals'),
6093: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6094: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6095: },
1.34 www 6096: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6097: },
6098: 'rndseed' => {
1.3 raeburn 6099: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 6100: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 6101: &mt('Modifying this will make problems have different numbers and answers!').
6102: '</span>',
6103: input => 'selectbox',
6104: options => {
6105: '32bit' => '32bit',
6106: '64bit' => '64bit',
6107: '64bit2' => '64bit2',
6108: '64bit3' => '64bit3',
6109: '64bit4' => '64bit4',
6110: '64bit5' => '64bit5',
6111: },
6112: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6113: advanced => 1
1.1 raeburn 6114: },
6115: 'receiptalg' => {
1.3 raeburn 6116: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6117: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6118: input => 'selectbox',
6119: options => {
6120: receipt => 'receipt',
6121: receipt2 => 'receipt2',
6122: receipt3 => 'receipt3',
6123: },
6124: order => ['receipt','receipt2','receipt3'],
1.41 www 6125: advanced => 1
1.1 raeburn 6126: },
6127: 'disablesigfigs' => {
1.3 raeburn 6128: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6129: input => 'radio',
6130: },
6131: );
1.80 raeburn 6132: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
1.1 raeburn 6133: }
6134:
6135: sub print_printouts {
1.80 raeburn 6136: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6137: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6138: return;
6139: }
6140: my %items = (
6141: problem_stream_switch => {
1.3 raeburn 6142: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6143: input => 'radio',
6144: },
6145: suppress_tries => {
1.3 raeburn 6146: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6147: input => 'radio',
6148: },
6149: default_paper_size => {
1.3 raeburn 6150: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6151: input => 'selectbox',
6152: options => {
6153: Letter => &mt('Letter').' [8 1/2x11 in]',
6154: Legal => &mt('Legal').' [8 1/2x14 in]',
6155: Tabloid => &mt('Tabloid').' [11x17 in]',
6156: Executive => &mt('Executive').' [7 1/2x10 in]',
6157: A2 => &mt('A2').' [420x594 mm]',
6158: A3 => &mt('A3').' [297x420 mm]',
6159: A4 => &mt('A4').' [210x297 mm]',
6160: A5 => &mt('A5').' [148x210 mm]',
6161: A6 => &mt('A6').' [105x148 mm]',
6162: },
6163: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6164: nullval => &mt('None specified'),
1.1 raeburn 6165: },
6166: print_header_format => {
1.3 raeburn 6167: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6168: input => 'checkbox',
6169: },
6170: disableexampointprint => {
1.3 raeburn 6171: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6172: input => 'radio',
6173: },
1.14 raeburn 6174: canuse_pdfforms => {
6175: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6176: input => 'selectbox',
6177: options => {
6178: 1 => &mt('Yes'),
6179: 0 => &mt('No'),
6180: },
6181: order => ['1','0'],
1.54 bisitz 6182: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6183: }
1.1 raeburn 6184: );
1.80 raeburn 6185: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6186: }
6187:
6188: sub print_spreadsheet {
1.80 raeburn 6189: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6190: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6191: return;
6192: }
6193: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6194: my %items = (
6195: spreadsheet_default_classcalc => {
1.3 raeburn 6196: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6197: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6198: "('display','spreadsheet_default_classcalc'".
6199: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6200: input => 'textbox',
6201: },
6202: spreadsheet_default_studentcalc => {
1.3 raeburn 6203: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6204: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6205: "('display','spreadsheet_default_calc'".
6206: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6207: input => 'textbox',
6208: },
6209: spreadsheet_default_assesscalc => {
1.3 raeburn 6210: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6211: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6212: "('display','spreadsheet_default_assesscalc'".
6213: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6214: input => 'textbox',
6215: },
6216: hideemptyrows => {
1.3 raeburn 6217: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6218: input => 'radio',
6219: },
6220: );
1.80 raeburn 6221: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6222: }
1.1 raeburn 6223:
6224: sub print_bridgetasks {
1.80 raeburn 6225: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6226: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6227: return;
6228: }
1.9 raeburn 6229: my ($stumsg,$msgnote);
6230: if ($crstype eq 'Community') {
6231: $stumsg = &mt('Send message to member');
6232: $msgnote = &mt('Message to member and add to user notes');
6233: } else {
6234: $stumsg = &mt('Send message to student');
6235: $msgnote = &mt('Message to student and add to user notes');
6236: }
1.1 raeburn 6237: my %items = (
6238: task_messages => {
1.3 raeburn 6239: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6240: input => 'selectbox',
6241: options => {
1.9 raeburn 6242: only_student => $stumsg,
6243: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6244: },
6245: order => ['only_student','student_and_user_notes_screen'],
6246: nullval => &mt('No message or record in user notes'),
6247: },
6248: task_grading => {
1.3 raeburn 6249: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6250: input => 'selectbox',
6251: options => {
6252: any => &mt('Grade BTs in any section'),
6253: section => &mt('Grade BTs only in own section')
6254: },
6255: order => ['any','section'],
6256: },
6257: suppress_embed_prompt => {
1.3 raeburn 6258: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6259: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6260: input => 'radio',
6261: },
6262: );
1.80 raeburn 6263: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6264: }
6265:
1.118 raeburn 6266: sub print_ltitools {
6267: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6268: my ($datatable,$disabled,$css_class,$dest);
1.121 raeburn 6269: if ($noedit) {
6270: $disabled = ' disabled="disabled"';
6271: }
1.120 raeburn 6272: my $itemcount = 1;
6273: unless ($context eq 'domain') {
6274: my %tooltypes = &Apache::loncommon::usable_exttools();
6275: unless ($tooltypes{'crs'}) {
6276: my $showtype = 'course';
6277: if ($crstype eq 'Community') {
6278: $showtype = lc($crstype);
6279: }
6280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6281: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6282: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6283: if ($tooltypes{'dom'}) {
6284: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6285: '<i>'.$cdom.'</i>').
6286: '<br /><br />'.
6287: &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.");
6288: } else {
6289: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6290: '<br /><br />'.
6291: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6292: '<i>'.$cdom.'</i>');
6293:
6294: }
6295: $datatable .= '</tr>';
6296: $itemcount ++;
6297: return $datatable;
6298: }
6299: }
1.118 raeburn 6300: my %lt = <itools_names();
6301: my $maxnum = 0;
6302: my %ordered;
6303: if (ref($settings) eq 'HASH') {
6304: foreach my $item (keys(%{$settings})) {
6305: if (ref($settings->{$item}) eq 'HASH') {
6306: my $num = $settings->{$item}{'order'};
6307: $ordered{$num} = $item;
6308: }
6309: }
6310: }
6311:
6312: if ($context eq 'domain') {
6313: $dest = '/adm/domainprefs';
6314: } else {
6315: $dest = '/adm/courseprefs';
6316: }
6317: my ($switchserver,$switchmessage);
6318: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6319: if ($switchserver) {
6320: if ($context eq 'domain') {
6321: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6322: } elsif ($crstype eq 'Community') {
6323: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6324: } else {
6325: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6326: }
6327: }
6328: my $maxnum = scalar(keys(%ordered));
6329: my @courseroles = ('cc','in','ta','ep','st');
6330: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6331: my @fields = ('fullname','firstname','lastname','email','roles','user');
6332: if (keys(%ordered)) {
6333: my @items = sort { $a <=> $b } keys(%ordered);
6334: for (my $i=0; $i<@items; $i++) {
6335: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6336: my $item = $ordered{$items[$i]};
6337: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6338: if (ref($settings->{$item}) eq 'HASH') {
6339: $title = $settings->{$item}->{'title'};
6340: $url = $settings->{$item}->{'url'};
6341: $key = $settings->{$item}->{'key'};
6342: $usable = $settings->{$item}->{'usable'};
6343: $lifetime = $settings->{$item}->{'lifetime'};
6344: my $image = $settings->{$item}->{'image'};
6345: if ($image ne '') {
6346: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6347: }
6348: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6349: $sigsel{'HMAC-256'} = ' selected="selected"';
6350: } else {
6351: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6352: }
6353: }
6354: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6355: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6356: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6357: for (my $k=0; $k<=$maxnum; $k++) {
6358: my $vpos = $k+1;
6359: my $selstr;
6360: if ($k == $i) {
6361: $selstr = ' selected="selected" ';
6362: }
6363: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6364: }
6365: $datatable .= '</select>'.(' 'x2).
6366: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6367: &mt('Delete?').'</label></span></td>'.
6368: '<td colspan="2">'.
6369: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6370: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6371: (' 'x2).
6372: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6373: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6374: (' 'x2).
6375: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6376: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6377: (' 'x2).
6378: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6379: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6380: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6381: '<br /><br />'.
1.120 raeburn 6382: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6383: ' value="'.$url.'" /></span>'.
6384: (' 'x2).
6385: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6386: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6387: if ($key ne '') {
6388: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6389: if ($noedit) {
6390: $datatable .= ': ['.&mt('not shown').']';
6391: } elsif ($switchserver) {
6392: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6393: } else {
6394: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6395: }
6396: $datatable .= '</span> '.(' 'x2);
6397: } elsif (!$switchserver) {
6398: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6399: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6400: '</span> '.(' 'x2);
6401: }
6402: if ($switchserver) {
6403: if ($usable ne '') {
6404: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6405: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6406: '<span class="LC_nobreak">'.&mt('Change secret?').
6407: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6408: (' 'x2).
6409: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6410: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6411: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6412: '</div>';
6413: } elsif ($key eq '') {
6414: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6415: } else {
6416: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6417: }
6418: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6419: } else {
6420: if ($usable ne '') {
6421: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6422: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6423: '<span class="LC_nobreak">'.&mt('Change?').
6424: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6425: (' 'x2).
6426: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6427: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6428: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6429: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6430: '<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>'.
6431: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6432: } else {
6433: $datatable .=
6434: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6435: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6436: '<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>'.
6437: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6438: }
6439: }
6440: $datatable .= '</fieldset>'.
6441: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6442: '<span class="LC_nobreak">'.&mt('Display target:');
6443: my %currdisp;
6444: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6445: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6446: $currdisp{'window'} = ' checked="checked"';
6447: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6448: $currdisp{'tab'} = ' checked="checked"';
6449: } else {
6450: $currdisp{'iframe'} = ' checked="checked"';
6451: }
6452: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6453: $currdisp{'width'} = $1;
6454: }
6455: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6456: $currdisp{'height'} = $1;
6457: }
6458: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6459: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6460: } else {
6461: $currdisp{'iframe'} = ' checked="checked"';
6462: }
6463: foreach my $disp ('iframe','tab','window') {
6464: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6465: $lt{$disp}.'</label>'.(' 'x2);
6466: }
6467: $datatable .= (' 'x4);
6468: foreach my $dimen ('width','height') {
6469: $datatable .= '<label>'.$lt{$dimen}.' '.
6470: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6471: (' 'x2);
6472: }
6473: $datatable .= '</span><br />'.
6474: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6475: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6476: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6477: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6478: '</textarea></div><div style=""></div><br />';
6479: my %units = (
6480: 'passback' => 'days',
6481: 'roster' => 'seconds',
6482: );
6483: foreach my $extra ('passback','roster') {
6484: my $validsty = 'none';
6485: my $currvalid;
6486: my $checkedon = '';
6487: my $checkedoff = ' checked="checked"';
6488: if ($settings->{$item}->{$extra}) {
6489: $checkedon = $checkedoff;
6490: $checkedoff = '';
6491: $validsty = 'inline-block';
6492: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6493: $currvalid = $settings->{$item}->{$extra.'valid'};
6494: }
6495: }
6496: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6497: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6498: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6499: &mt('No').'</label>'.(' 'x2).
6500: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6501: &mt('Yes').'</label></span></div>'.
6502: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6503: '<span class="LC_nobreak">'.
6504: &mt("until at least [_1] $units{$extra} after launch",
6505: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6506: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6507: }
6508: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6509: if ($imgsrc) {
6510: $datatable .= $imgsrc.
6511: '<label><input type="checkbox" name="ltitools_image_del"'.
6512: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6513: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6514: } else {
6515: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6516: }
6517: if ($switchserver) {
6518: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6519: } else {
6520: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6521: }
6522: $datatable .= '</span></fieldset>';
6523: my (%checkedfields,%rolemaps,$userincdom);
6524: if (ref($settings->{$item}) eq 'HASH') {
6525: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6526: %checkedfields = %{$settings->{$item}->{'fields'}};
6527: }
6528: $userincdom = $settings->{$item}->{'incdom'};
6529: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6530: %rolemaps = %{$settings->{$item}->{'roles'}};
6531: $checkedfields{'roles'} = 1;
6532: }
6533: }
6534: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6535: '<span class="LC_nobreak">';
6536: my $userfieldstyle = 'display:none;';
6537: my $seluserdom = '';
6538: my $unseluserdom = ' selected="selected"';
6539: foreach my $field (@fields) {
6540: my ($checked,$onclick,$id,$spacer);
6541: if ($checkedfields{$field}) {
6542: $checked = ' checked="checked"';
6543: }
6544: if ($field eq 'user') {
6545: $id = ' id="ltitools_user_field_'.$i.'"';
6546: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6547: if ($checked) {
6548: $userfieldstyle = 'display:inline-block';
6549: if ($userincdom) {
6550: $seluserdom = $unseluserdom;
6551: $unseluserdom = '';
6552: }
6553: }
6554: } else {
6555: $spacer = (' ' x2);
6556: }
6557: $datatable .= '<label>'.
6558: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6559: $lt{$field}.'</label>'.$spacer;
6560: }
6561: $datatable .= '</span>';
6562: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6563: '<span class="LC_nobreak"> : '.
6564: '<select name="ltitools_userincdom_'.$i.'">'.
6565: '<option value="">'.&mt('Select').'</option>'.
6566: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6567: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6568: '</select></span></div>';
6569: $datatable .= '</fieldset>'.
6570: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6571: foreach my $role (@courseroles) {
6572: my ($selected,$selectnone);
6573: if (!$rolemaps{$role}) {
6574: $selectnone = ' selected="selected"';
6575: }
6576: $datatable .= '<td style="text-align: center">'.
6577: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6578: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6579: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6580: foreach my $ltirole (@ltiroles) {
6581: unless ($selectnone) {
6582: if ($rolemaps{$role} eq $ltirole) {
6583: $selected = ' selected="selected"';
6584: } else {
6585: $selected = '';
6586: }
6587: }
6588: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6589: }
6590: $datatable .= '</select></td>';
6591: }
6592: $datatable .= '</tr></table></fieldset>';
6593: my %courseconfig;
6594: if (ref($settings->{$item}) eq 'HASH') {
6595: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6596: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6597: }
6598: }
6599: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6600: foreach my $item ('label','title','target','linktext','explanation','append') {
6601: my $checked;
6602: if ($courseconfig{$item}) {
6603: $checked = ' checked="checked"';
6604: }
6605: $datatable .= '<label>'.
6606: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6607: $lt{'crs'.$item}.'</label> '."\n";
6608: }
6609: $datatable .= '</span></fieldset>'.
6610: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6611: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6612: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6613: my %custom = %{$settings->{$item}->{'custom'}};
6614: if (keys(%custom) > 0) {
6615: foreach my $key (sort(keys(%custom))) {
6616: $datatable .= '<tr><td><span class="LC_nobreak">'.
6617: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6618: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6619: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6620: ' value="'.$custom{$key}.'" /></td></tr>';
6621: }
6622: }
6623: }
6624: $datatable .= '<tr><td><span class="LC_nobreak">'.
6625: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6626: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6627: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6628: $datatable .= '</table></fieldset></td></tr>'."\n";
6629: $itemcount ++;
6630: }
6631: }
6632: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6633: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6634: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6635: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6636: '<select name="ltitools_add_pos"'.$chgstr.'>';
6637: for (my $k=0; $k<$maxnum+1; $k++) {
6638: my $vpos = $k+1;
6639: my $selstr;
6640: if ($k == $maxnum) {
6641: $selstr = ' selected="selected" ';
6642: }
6643: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6644: }
6645: $datatable .= '</select> '."\n".
6646: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6647: '<td colspan="2">'.
6648: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6649: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6650: (' 'x2).
6651: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6652: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6653: (' 'x2).
6654: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6655: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6656: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6657: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6658: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6659: '<br />'.
1.120 raeburn 6660: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6661: (' 'x2).
6662: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6663: if ($switchserver) {
6664: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6665: } else {
6666: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6667: (' 'x2).
1.119 raeburn 6668: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6669: '<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 6670: }
6671: $datatable .= '<br /><br />'.
6672: '</fieldset>'.
6673: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6674: '<span class="LC_nobreak">'.&mt('Display target:');
6675: my %defaultdisp;
6676: $defaultdisp{'iframe'} = ' checked="checked"';
6677: foreach my $disp ('iframe','tab','window') {
6678: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6679: $lt{$disp}.'</label>'.(' 'x2);
6680: }
6681: $datatable .= (' 'x4);
6682: foreach my $dimen ('width','height') {
6683: $datatable .= '<label>'.$lt{$dimen}.' '.
6684: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6685: (' 'x2);
6686: }
6687: $datatable .= '</span><br />'.
6688: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6689: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6690: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6691: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6692: '</div><div style=""></div><br />';
6693: my %units = (
6694: 'passback' => 'days',
6695: 'roster' => 'seconds',
6696: );
6697: my %defaulttimes = (
6698: 'passback' => '7',
6699: 'roster' => '300',
6700: );
6701: foreach my $extra ('passback','roster') {
6702: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6703: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6704: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6705: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6706: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6707: &mt('Yes').'</label></span></div>'.
6708: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6709: '<span class="LC_nobreak">'.
6710: &mt("until at least [_1] $units{$extra} after launch",
6711: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6712: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6713: }
6714: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6715: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6716: if ($switchserver) {
6717: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6718: } else {
6719: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6720: }
6721: $datatable .= '</span></fieldset>'.
6722: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6723: '<span class="LC_nobreak">';
6724: foreach my $field (@fields) {
6725: my ($id,$onclick,$spacer);
6726: if ($field eq 'user') {
6727: $id = ' id="ltitools_user_field_add"';
6728: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6729: } else {
6730: $spacer = (' ' x2);
6731: }
6732: $datatable .= '<label>'.
6733: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6734: $lt{$field}.'</label>'.$spacer;
6735: }
6736: $datatable .= '</span>'.
6737: '<div style="display:none;" id="ltitools_user_div_add">'.
6738: '<span class="LC_nobreak"> : '.
6739: '<select name="ltitools_add_userincdom">'.
6740: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6741: '<option value="0">'.&mt('username').'</option>'.
6742: '<option value="1">'.&mt('username:domain').'</option>'.
6743: '</select></span></div></fieldset>';
6744: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6745: foreach my $role (@courseroles) {
6746: my ($checked,$checkednone);
6747: $datatable .= '<td style="text-align: center">'.
6748: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6749: '<select name="ltitools_add_roles_'.$role.'">'.
6750: '<option value="" selected="selected">'.&mt('Select').'</option>';
6751: foreach my $ltirole (@ltiroles) {
6752: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6753: }
6754: $datatable .= '</select></td>';
6755: }
6756: $datatable .= '</tr></table></fieldset>'.
6757: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6758: foreach my $item ('label','title','target','linktext','explanation','append') {
6759: $datatable .= '<label>'.
6760: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6761: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6762: }
6763: $datatable .= '</span></fieldset>'.
6764: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6765: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6766: '<tr><td><span class="LC_nobreak">'.
6767: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6768: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6769: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6770: '</table></fieldset>'."\n".
6771: '</td>'."\n".
6772: '</tr>'."\n";
6773: $itemcount ++;
6774: return $datatable;
6775: }
6776:
6777: sub ltitools_names {
6778: my %lt = &Apache::lonlocal::texthash(
6779: 'title' => 'Title',
6780: 'version' => 'Version',
6781: 'msgtype' => 'Message Type',
6782: 'sigmethod' => 'Signature Method',
6783: 'url' => 'URL',
6784: 'key' => 'Key',
6785: 'lifetime' => 'Nonce lifetime (s)',
6786: 'secret' => 'Secret',
6787: 'icon' => 'Icon',
6788: 'user' => 'User',
6789: 'fullname' => 'Full Name',
6790: 'firstname' => 'First Name',
6791: 'lastname' => 'Last Name',
6792: 'email' => 'E-mail',
6793: 'roles' => 'Role',
6794: 'window' => 'Window',
6795: 'tab' => 'Tab',
6796: 'iframe' => 'iFrame',
6797: 'height' => 'Height',
6798: 'width' => 'Width',
6799: 'linktext' => 'Default Link Text',
6800: 'explanation' => 'Default Explanation',
6801: 'passback' => 'Tool can return grades:',
6802: 'roster' => 'Tool can retrieve roster:',
6803: 'crstarget' => 'Display target',
6804: 'crslabel' => 'Course label',
6805: 'crstitle' => 'Course title',
6806: 'crslinktext' => 'Link Text',
6807: 'crsexplanation' => 'Explanation',
6808: 'crsappend' => 'Provider URL',
6809: );
6810: return %lt;
6811: }
6812:
1.87 raeburn 6813: sub print_lti {
6814: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6815: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6816: return;
6817: }
6818: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6819: my %menutitles = <imenu_titles();
6820: my ($domdefs,$displaydefs);
6821: if ($env{'request.lti.login'}) {
6822: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6823: my @domdefsmenu;
6824: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6825: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6826: $domdefs = &mt('Header shown').', ';
6827: }
6828: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6829: $domdefs .= &mt('Inline menu shown');
6830: }
6831: $domdefs =~ s/,\s$//;
6832: if (!$domdefs) {
6833: $domdefs = &mt('No header or inline menu shown');
6834: }
6835: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
6836: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6837: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6838: }
6839: }
6840: $displaydefs = &mt('Domain defaults');
6841: if (@domdefsmenu) {
6842: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
6843: if (@diffs) {
6844: my $missing;
6845: foreach my $item (@menuitems) {
6846: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
6847: $missing .= ' '.$menutitles{$item}.',';
6848: }
6849: }
6850: $missing =~ s/,$//;
6851: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
6852: } else {
6853: $displaydefs .= ': '.&mt('All shown');
6854: }
6855: } else {
6856: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
6857: }
6858: } else {
6859: $displaydefs = &mt('Domain defaults only available in LTI context');
6860: }
6861: my %items = (
6862: 'lti.override' => {
6863: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
6864: input => 'radio',
6865: },
6866: 'lti.topmenu' => {
6867: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
6868: input => 'radio',
6869: },
6870: 'lti.inlinemenu' => {
6871: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
6872: input => 'radio',
6873: },
6874: 'lti.lcmenu' => {
6875: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
6876: input => 'custom',
6877: },
6878: );
6879: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
6880: }
6881:
6882: sub lcmenu_checkboxes {
6883: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
6884: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6885: my %menutitles = <imenu_titles();
6886: my (@current,@domdefs);
6887: if ($env{'request.lti.login'}) {
6888: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6889: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6890: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6891: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6892: }
6893: }
6894: }
6895: if (ref($settings) eq 'HASH') {
6896: if ($settings->{'lti.lcmenu'}) {
6897: unless ($settings->{'lti.lcmenu'} eq 'none') {
6898: @current = split(',',$settings->{'lti.lcmenu'});
6899: }
6900: } else {
6901: @current = @domdefs;
6902: }
6903: } else {
6904: @current = @domdefs;
6905: }
6906: my $numinrow = 3;
6907: my $count = 0;
6908: my $disabled;
6909: if ($noedit) {
6910: $disabled = ' disabled="disabled"';
6911: }
6912: my $output = '<table>';
6913: foreach my $item (@menuitems) {
6914: my $checked = '';
6915: if (grep(/^\Q$item\E$/,@current)) {
6916: $checked = ' checked="checked" ';
6917: }
6918: my $rem = $count%($numinrow);
6919: if ($rem == 0) {
6920: if ($count > 0) {
6921: $output .= '</tr>';
6922: }
6923: $output .= '<tr>';
6924: }
6925: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
6926: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
6927: $menutitles{$item}.'</label></span></td>';
6928: $count ++;
6929: }
6930: my $rem = $count%($numinrow);
6931: my $colsleft = $numinrow - $rem;
6932: if ($colsleft > 1 ) {
6933: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6934: ' </td>';
6935: } elsif ($colsleft == 1) {
6936: $output .= '<td class="LC_left_item"> </td>';
6937: }
6938: $output .= '</tr></table>';
6939: }
6940:
6941: sub ltimenu_titles {
6942: return &Apache::lonlocal::texthash(
6943: fullname => 'Full name',
6944: coursetitle => 'Course title',
6945: role => 'Role',
6946: logout => 'Logout',
6947: grades => 'Grades',
6948: );
6949: }
6950:
1.91 raeburn 6951: sub print_menuitems {
6952: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6953: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
6954: return;
6955: }
6956: if ($position eq 'top') {
6957: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
6958: if ($settings->{'menucollections'} ne '') {
6959: foreach my $item (split(/;/,$settings->{'menucollections'})) {
6960: my ($num,$value) = split(/\%/,$item);
6961: if ($num =~ /^\d+$/) {
6962: $defaultmenu_options{$num} = $num;
6963: }
6964: }
6965: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
6966: $addcollection = $defaultmenu_order[-1] + 1;
6967: } else {
6968: $addcollection = 1;
6969: }
6970: $defaultmenu_options{$addcollection} = $addcollection;
6971: my %items = (
6972: 'menudefault' => {
6973: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
6974: &mt("(can be overriden in deep-link context)"),
6975: input => 'selectbox',
6976: options => \%defaultmenu_options,
6977: order => \@defaultmenu_order,
6978: nullval => &mt('Standard (all menus shown)'),
6979: },
6980: );
6981: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
6982: } else {
6983: my %menu;
6984: my $count = 0;
6985: my $next = 1;
6986: my ($datatable,$disabled);
6987: if ($noedit) {
6988: $disabled = ' disabled="disabled"';
6989: }
6990:
6991: my ($ordered,$cats) = &menuitems_categories();
6992: my @order = @{$ordered};
6993: my %categories = %{$cats};
6994: my %menutitles = &menuitems_titles();
6995: my %menufields = &menuitems_fields();
6996:
6997: if ($settings->{'menucollections'} ne '') {
6998: foreach my $item (split(/;/,$settings->{'menucollections'})) {
6999: my ($num,$value) = split(/\%/,$item);
7000: if ($num =~ /^\d+$/) {
7001: my @entries = split(/\&/,$value);
7002: foreach my $entry (@entries) {
7003: my ($name,$fields) = split(/=/,$entry);
7004: $menu{$num}{$name} = $fields;
7005: }
7006: }
7007: }
7008: if (keys(%menu)) {
7009: my @current = sort { $a <=> $b } keys(%menu);
7010: $next += $current[-1];
7011: foreach my $num (@current) {
7012: my %checked;
7013: my $on = ' checked="checked"';
7014: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7015: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7016: if ($menu{$num}{$key} eq 'y') {
7017: $checked{$key} = $on;
7018: }
7019: } else {
7020: foreach my $field (split(/,/,$menu{$num}{$key})) {
7021: if (exists($menufields{$field})) {
7022: $checked{$field} = $on;
7023: }
7024: }
7025: }
7026: }
7027: if (ref($menu{$num}) eq 'HASH') {
7028: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7029: foreach my $category (@order) {
7030: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7031: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7032: if ($category eq 'text') {
7033: $datatable .= '<i>'.&mt('Header').'</i><br />';
7034: }
1.91 raeburn 7035: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7036: if ($field eq 'disc') {
7037: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7038: }
1.91 raeburn 7039: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7040: $menufields{$field}.'</label><br />';
7041: }
7042: $datatable .= '</fieldset>';
7043: }
7044: }
7045: $datatable .= &item_table_row_end();
7046: $count ++;
7047: }
7048: }
7049: }
7050: } elsif ($noedit) {
7051: my $text = &mt('No menu collections defined for this course.');
7052: $datatable .= &item_table_row_start($text,$count);
7053: }
7054: unless ($noedit) {
7055: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7056: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7057: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7058: foreach my $category (@order) {
7059: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7060: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7061: foreach my $field (@{$categories{$category}}) {
7062: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7063: $menufields{$field}.'</label><br />';
7064: }
7065: $datatable .= '</fieldset>';
7066: }
7067: }
7068: $datatable .= &item_table_row_end();
7069: $count ++;
7070: }
7071: return $datatable;
7072: }
7073: }
7074:
7075: sub menuitems_abbreviations {
7076: my %briefcats = (
7077: text => 'pt',
7078: links => 'p',
7079: list => 'ps',
7080: inline => 's',
7081: );
7082: return %briefcats;
7083: }
7084:
7085: sub menuitems_categories {
7086: my @order = ('shown','text','links','list','inline');
7087: my %categories = (
1.94 raeburn 7088: shown => ['top','inline','foot','main'],
7089: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7090: links => ['pers','logo','menu','comm','roles','help','logout'],
1.91 raeburn 7091: list => ['about','prefs','port','wish','anno','rss'],
7092: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7093: );
7094: return (\@order,\%categories);
7095: }
7096:
7097: sub menuitems_titles {
7098: return &Apache::lonlocal::texthash (
7099: shown => 'Hierarchy',
1.94 raeburn 7100: text => 'Text',
1.91 raeburn 7101: links => 'Header links',
7102: list => 'Drop-down list',
7103: inline => 'Inline links',
7104: );
7105: }
7106:
7107: sub menuitems_fields {
7108: return &Apache::lonlocal::texthash (
7109: top => 'Display header',
7110: inline => 'Display inline menu',
1.94 raeburn 7111: foot => 'Display footer',
1.91 raeburn 7112: main => 'Access to main menu',
1.92 raeburn 7113: pers => 'Personal',
7114: logo => 'LON-CAPA',
1.91 raeburn 7115: menu => 'Home',
7116: comm => 'Messages',
7117: roles => 'Roles/Courses',
7118: help => 'Help',
7119: logout => 'Logout',
7120: name => 'Fullname',
7121: crs => 'Course Title',
7122: role => 'Current Role',
1.94 raeburn 7123: disc => 'Discussion',
7124: fdbk => 'Feedback',
1.91 raeburn 7125: about => 'Information',
7126: prefs => 'Preferences',
7127: port => 'Portfolio',
7128: wish => 'Stored Links',
7129: anno => 'Calendar',
7130: rss => 'RSS Feeds',
7131: cont => 'Contents',
7132: grades => 'Grades',
7133: chat => 'Chat',
7134: people => 'People',
7135: groups => 'Groups',
7136: resv => 'Reservations',
7137: syll => 'Syllabus',
7138: feeds => 'Feeds',
7139: );
7140: }
7141:
7142: sub menucollections_display {
7143: my ($collections) = @_;
7144: my %menu;
7145: my ($ordered,$cats) = &menuitems_categories();
7146: my @order = @{$ordered};
7147: my %categories = %{$cats};
7148: my %menutitles = &menuitems_titles();
7149: my %menufields = &menuitems_fields();
7150: foreach my $item (split(/;/,$collections)) {
7151: my ($num,$value) = split(/\%/,$item);
7152: if ($num =~ /^\d+$/) {
7153: my @entries = split(/\&/,$value);
7154: foreach my $entry (@entries) {
7155: my ($name,$fields) = split(/=/,$entry);
7156: $menu{$num}{$name} = $fields;
7157: }
7158: }
7159: }
7160: my $output = '';
7161: if (keys(%menu)) {
7162: my @current = sort { $a <=> $b } keys(%menu);
7163: foreach my $num (@current) {
7164: my %checked;
7165: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7166: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7167: if ($menu{$num}{$key} eq 'y') {
7168: $checked{$key} = 1;
7169: }
7170: } else {
7171: foreach my $field (split(/,/,$menu{$num}{$key})) {
7172: if (exists($menufields{$field})) {
7173: $checked{$field} = 1;
7174: }
7175: }
7176: }
7177: }
7178: if (ref($menu{$num}) eq 'HASH') {
7179: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7180: foreach my $category (@order) {
7181: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7182: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7183: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7184: if ($category eq 'text') {
7185: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
1.124 raeburn 7186: }
1.91 raeburn 7187: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7188: if ($field eq 'disc') {
7189: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7190: }
1.91 raeburn 7191: if ($checked{$field}) {
7192: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7193: } else {
7194: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7195: }
7196: $output .= '<br />';
7197: }
7198: $output .= '</fieldset>';
7199: }
7200: }
7201: $output .= '</fieldset>';
7202: }
7203: }
7204: }
7205: return $output;
7206: }
7207:
1.93 raeburn 7208: sub print_linkprotection {
1.102 raeburn 7209: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7210:
7211: my %linkprotection;
7212: my $count = 0;
7213: my $next = 1;
1.102 raeburn 7214: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7215: if ($noedit) {
7216: $disabled = ' disabled="disabled"';
7217: }
1.100 raeburn 7218: my %desc = &linkprot_names();
7219: my %lt = &Apache::lonlocal::texthash (
7220: 'requ' => 'Required settings',
7221: 'opti' => 'Optional settings',
7222: );
1.93 raeburn 7223: my $itemcount = 0;
7224:
1.100 raeburn 7225: my $ltiauth;
1.102 raeburn 7226: if ($context eq 'domain') {
7227: $ltiauth = 1;
7228: } else {
7229: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7230: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7231: } else {
7232: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7233: $ltiauth = $domdefs{'crsltiauth'};
7234: }
7235: }
7236: if ($context eq 'domain') {
7237: $dest = '/adm/domainprefs';
1.100 raeburn 7238: } else {
1.102 raeburn 7239: $dest = '/adm/courseprefs';
7240: }
1.124 raeburn 7241:
1.102 raeburn 7242: my ($switchserver,$switchmessage);
7243: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7244: if ($switchserver) {
7245: if ($context eq 'domain') {
1.124 raeburn 7246: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.102 raeburn 7247: } elsif ($crstype eq 'Community') {
7248: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7249: } else {
7250: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7251: }
1.100 raeburn 7252: }
1.99 raeburn 7253:
1.105 raeburn 7254: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7255: if (keys(%{$settings->{'linkprot'}})) {
7256: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7257: $next += $current[-1];
7258: for (my $i=0; $i<@current; $i++) {
7259: my $num = $current[$i];
7260: my %values;
1.102 raeburn 7261: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7262: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7263: } else {
7264: next;
7265: }
7266: my $selected;
7267: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7268: $selected = ' selected="selected"';
7269: }
7270: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7271: $datatable .=
7272: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7273: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7274: &mt('Delete?').'</label></span></td><td>';
1.122 raeburn 7275: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7276: $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
7277: $passbacksty = 'none';
7278: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
7279: %checkedpassback = (
7280: 'no' => ' checked="checked"',
7281: 'yes' => '',
1.124 raeburn 7282: );
1.122 raeburn 7283: %checkedpassbackfmt = (
7284: '1p1' => ' checked="checked"',
7285: '1p0' => '',
7286: );
7287: if ($values{'passback'} ne '') {
7288: $passbacksty = 'inline-block';
7289: $checkedpassback{'yes'} = ' checked="checked"';
7290: $checkedpassback{'no'} = '';
7291: if ($values{'passbackformat'} eq '1.0') {
7292: $checkedpassbackfmt{'1p0'} = ' checked="checked"';
7293: $checkedpassbackfmt{'1p1'} = '';
7294: }
7295: }
1.100 raeburn 7296: if ($ltiauth) {
7297: $usersty = 'display:none';
1.112 raeburn 7298: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7299: %checkedrequser = (
7300: no => ' checked="checked"',
7301: yes => '',
7302: );
7303: if ($values{'requser'}) {
7304: $checkedrequser{'yes'} = $checkedrequser{'no'};
7305: $checkedrequser{'no'} = '';
7306: }
7307: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
1.124 raeburn 7308: if ($values{'requser'}) {
1.100 raeburn 7309: $usersty = 'display:inline-block';
7310: }
7311: }
1.112 raeburn 7312: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7313: %checkedreturnurl = (
7314: no => ' checked="checked"',
7315: yes => '',
7316: );
7317: if ($values{'returnurl'} ne '') {
7318: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7319: $checkedreturnurl{'no'} = '';
7320: }
1.100 raeburn 7321: $datatable .=
7322: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7323: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7324: (' 'x2).
1.100 raeburn 7325: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7326: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7327: (' 'x2).
1.100 raeburn 7328: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7329: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7330: if ($values{'key'} ne '') {
1.100 raeburn 7331: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7332: if ($noedit) {
7333: $datatable .= ': ['.&mt('not shown').']';
7334: } elsif ($switchserver) {
7335: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7336: } else {
7337: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7338: }
7339: $datatable .= '</span> '.(' 'x2);
7340: } elsif (!$switchserver) {
1.100 raeburn 7341: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7342: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7343: '</span> '.(' 'x2);
7344: }
7345: if ($switchserver) {
7346: if ($values{'usable'} ne '') {
7347: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7348: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7349: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7350: '<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 7351: (' 'x2).
1.118 raeburn 7352: '<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 7353: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7354: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7355: '</div>';
7356: } elsif ($values{'key'} eq '') {
1.102 raeburn 7357: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7358: } else {
1.102 raeburn 7359: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7360: }
1.111 raeburn 7361: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7362: } else {
7363: if ($values{'usable'} ne '') {
7364: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7365: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7366: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7367: '<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 7368: (' 'x2).
1.118 raeburn 7369: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7370: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7371: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7372: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7373: '<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 7374: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7375: } else {
7376: $datatable .=
1.100 raeburn 7377: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7378: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7379: '<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 7380: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7381: }
7382: }
1.112 raeburn 7383: $datatable .= '<br /><br />'.
1.122 raeburn 7384: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7385: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7386: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7387: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7388: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7389: '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7390: '<span class="LC_nobreak">'.&mt('Grade format').
7391: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7392: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7393: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7394: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7395: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7396: '<br />'.
1.112 raeburn 7397: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7398: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7399: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7400: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7401: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7402: ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7403: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7404: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7405: '</span></div> ';
1.100 raeburn 7406: if ($ltiauth) {
1.112 raeburn 7407: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7408: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7409: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7410: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7411: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7412: '</fieldset>'.
7413: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7414: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7415: '</fieldset>';
7416: }
1.99 raeburn 7417: $datatable .= '</td></tr>';
1.93 raeburn 7418: $itemcount ++;
7419: }
7420: }
7421: }
7422: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7423: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7424: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7425: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7426: '<td width="100%">';
1.122 raeburn 7427: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7428: $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.100 raeburn 7429: if ($ltiauth) {
7430: $usersty = 'display:none';
1.112 raeburn 7431: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7432: %checkedrequser = (
7433: no => ' checked="checked"',
7434: yes => '',
7435: );
7436: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7437: }
1.122 raeburn 7438: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7439: %checkedpassback = (
7440: 'no' => ' checked="checked"',
7441: 'yes' => '',
7442: );
7443: %checkedpassbackfmt = (
7444: '1p1' => ' checked="checked"',
7445: '1p0' => '',
7446: );
1.112 raeburn 7447: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7448: %checkedreturnurl = (
7449: no => ' checked="checked"',
7450: yes => '',
7451: );
1.100 raeburn 7452: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7453: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7454: (' 'x2).
1.100 raeburn 7455: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7456: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7457: (' 'x2).
1.112 raeburn 7458: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7459: '<br /><br />';
1.99 raeburn 7460: if ($switchserver) {
1.102 raeburn 7461: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7462: } else {
1.100 raeburn 7463: $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 7464: (' 'x2).
1.116 raeburn 7465: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7466: '<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 7467: }
1.112 raeburn 7468: $datatable .= '<br /><br />'.
1.122 raeburn 7469: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7470: '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7471: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7472: '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7473: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7474: '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none" />'.
7475: '<span class="LC_nobreak">'.&mt('Grade format').
7476: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7477: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7478: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7479: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7480: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7481: '<br />'.
1.112 raeburn 7482: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7483: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7484: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7485: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7486: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7487: ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7488: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7489: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7490: '</span></div> ';
7491: if ($ltiauth) {
7492: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7493: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7494: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7495: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7496: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7497: '</fieldset>'.
1.100 raeburn 7498: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7499: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7500: '</fieldset>';
7501: }
1.99 raeburn 7502: $datatable .= '</td></tr>';
1.93 raeburn 7503: $$rowtotal ++;
1.101 raeburn 7504: return $datatable;
1.93 raeburn 7505: }
7506:
7507: sub linkprot_names {
1.100 raeburn 7508: return &Apache::lonlocal::texthash(
1.93 raeburn 7509: 'version' => 'LTI Version',
7510: 'key' => 'Key',
7511: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7512: 'name' => 'Launcher Application',
1.93 raeburn 7513: 'secret' => 'Secret',
1.122 raeburn 7514: 'passback' => 'Can return grades to Launcher',
1.112 raeburn 7515: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7516: 'requser' => 'Use identity',
7517: 'email' => 'Email address',
7518: 'sourcedid' => 'User ID',
7519: 'other' => 'Other',
7520: 'auth' => 'Display LON-CAPA login page',
7521: 'reject' => 'Discontinue launch process',
1.93 raeburn 7522: );
7523: }
7524:
1.99 raeburn 7525: sub check_switchserver {
1.102 raeburn 7526: my ($cdom,$cnum,$context,$dest) = @_;
7527: my ($allowed,$switchserver,$home);
7528: if ($context eq 'domain') {
7529: $home = &Apache::lonnet::domain($cdom,'primary');
7530: } else {
7531: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7532: }
7533: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7534: my @ids=&Apache::lonnet::current_machine_ids();
7535: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7536: if (!$allowed) {
7537: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7538: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7539: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7540: }
7541: }
7542: return $switchserver;
7543: }
7544:
1.100 raeburn 7545: sub linkprot_options {
7546: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7547: my %lt;
7548: if (ref($desc) eq 'HASH') {
7549: %lt = %{$desc};
7550: }
7551: my $userfieldsty = 'none';
7552: my (%checked,$userfield);
7553: $checked{'sourcedid'} = ' checked="checked"';
7554: $checked{'reject'} = ' checked="checked"';
7555: if (ref($current) eq 'HASH') {
7556: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7557: $checked{'sourcedid'} = '';
7558: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7559: $checked{'email'} = ' checked="checked"';
7560: } else {
7561: $checked{'other'} = ' checked="checked"';
7562: $userfield = $current->{'mapuser'};
7563: $userfieldsty = 'inline-block';
7564: }
7565: }
7566: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7567: $checked{'reject'} = '';
7568: $checked{'auth'} = ' checked="checked"';
7569: }
7570: }
1.112 raeburn 7571: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7572: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7573: &mt('Source of LON-CAPA username in LTI request').': ';
7574: foreach my $option ('sourcedid','email','other') {
7575: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7576: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7577: ($option eq 'other' ? '' : (' 'x2) );
7578: }
7579: $output .= '</span></div>'.
7580: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7581: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7582: 'value="'.$userfield.'"'.$disabled.' /></div>';
7583: $output .= '<br />'.
7584: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7585: &mt('Action when username is not for an enrolled student').': ';
7586: foreach my $option ('reject','auth') {
7587: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7588: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7589: ($option eq 'auth' ? '' : (' 'x2) );
7590: }
7591: $output .= '</span></div>';
7592: return $output;
7593: }
7594:
1.114 raeburn 7595: sub print_extresource_row {
7596: my ($item,$config,$curr,$noedit) = @_;
7597: my $onchange;
7598: unless ($noedit) {
7599: $onchange = ' onchange="javascript:toggleExtRes();"';
7600: }
7601: my $id = 'LC_'.$item;
7602: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7603: my $output = &select_from_options($item,$config->{'order'},
7604: $config->{'options'},$selected,
7605: $config->{'nullval'},
7606: undef,undef,$onchange,$noedit,$id);
1.124 raeburn 7607: my ($checked,$reusesty,$sizesty);
1.114 raeburn 7608: if ($reuse) {
7609: $checked = ' checked="checked"';
7610: }
7611: $reusesty = 'none';
7612: $sizesty = 'none';
7613: if (($selected eq 'window') || ($selected eq 'tab')) {
7614: $reusesty = 'inline-block';
7615: if ($selected eq 'window') {
7616: $sizesty = 'inline-block';
7617: }
7618: }
7619: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7620: '<span class="LC_nobreak">'.
7621: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7622: &mt('Re-use tab/window').'</label>'.
7623: '</span></div>'.
7624: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7625: '<legend>'.&mt('Window size (optional)').'</legend>'.
7626: '<span class="LC_nobreak">'.
7627: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7628: (' ' x 3).
7629: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7630: '</span></fieldset>';
7631: return $output;
7632: }
7633:
1.1 raeburn 7634: sub print_other {
1.80 raeburn 7635: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7636: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7637: return;
7638: }
1.3 raeburn 7639: my @ordered = &get_other_items($cdom,$settings,$allitems);
7640: my %items;
7641: foreach my $parameter (@ordered) {
7642: $items{$parameter} = {
7643: text => '<b>'.$parameter.'</b>',
7644: input => 'textbox',
7645: size => '15',
7646: },
7647: }
7648: push (@ordered,'newp_value');
7649: $items{'newp_value'} = {
7650: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7651: '<input type="textbox" name="newp_name"'.
7652: ' value="" size="30" />',
7653: input => 'textbox',
7654: size => '30',
7655: };
1.93 raeburn 7656: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7657: }
7658:
7659: sub get_other_items {
7660: my ($cdom,$settings,$allitems) = @_;
7661: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7662: return;
7663: }
1.1 raeburn 7664: my @ordered;
7665: if (ref($settings) eq 'HASH') {
7666: foreach my $parameter (sort(keys(%{$settings}))) {
7667: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7668: next if (($parameter eq 'course.helper.not.run') &&
7669: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7670: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7671: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7672: || ($parameter eq 'type') ||
1.50 raeburn 7673: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7674: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7675: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7676: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7677: push(@ordered,$parameter);
7678: }
7679: }
7680: }
1.3 raeburn 7681: return @ordered;
1.1 raeburn 7682: }
7683:
7684: sub item_table_row_start {
1.91 raeburn 7685: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7686: my $output;
1.56 raeburn 7687: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7688: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7689: if ($leftclass eq '') {
7690: $leftclass = 'LC_left_item';
7691: }
7692: if ($rightclass eq '') {
7693: $rightclass = 'LC_right_item';
7694: }
1.56 raeburn 7695: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7696: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7697: '</td>';
1.91 raeburn 7698: if ($colspan > 1) {
7699: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7700: } else {
1.91 raeburn 7701: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7702: }
1.1 raeburn 7703: return $output;
7704: }
7705:
7706: sub item_table_row_end {
7707: return '</td></tr>';
7708: }
7709:
7710: sub yesno_radio {
1.80 raeburn 7711: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
1.1 raeburn 7712: my $itemon = ' ';
7713: my $itemoff = ' checked="checked" ';
1.69 raeburn 7714: if (($valueyes eq '') && ($valueno eq '')) {
7715: $valueyes = 'yes';
7716: $valueno = '';
7717: }
1.1 raeburn 7718: if (ref($settings) eq 'HASH') {
1.69 raeburn 7719: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7720: $itemon = $itemoff;
7721: $itemoff = ' ';
7722: }
1.69 raeburn 7723: unless (exists($settings->{$item})) {
7724: if ($unsetdefault eq $valueyes) {
7725: $itemon = $itemoff;
7726: $itemoff = ' ';
7727: }
7728: }
1.1 raeburn 7729: }
1.80 raeburn 7730: my $disabled;
7731: if ($noedit) {
7732: $disabled = ' disabled="disabled"';
7733: }
1.1 raeburn 7734: return '<span class="LC_nobreak"><label>'.
7735: '<input type="radio" name="'.$item.'"'.
1.80 raeburn 7736: $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
1.1 raeburn 7737: '<label><input type="radio" name="'.$item.'"'.
1.80 raeburn 7738: $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
1.1 raeburn 7739: }
7740:
7741: sub select_from_options {
1.91 raeburn 7742: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7743: my $output;
1.80 raeburn 7744: my $disabled;
7745: if ($noedit) {
7746: $disabled = ' disabled=disabled"';
7747: }
1.1 raeburn 7748: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7749: $output='<select name="'.$item.'" '.$onchange;
7750: if ($multiple) {
7751: $output .= ' multiple="multiple"';
7752: my $num = @{$order};
7753: $num ++ if ($nullval ne '');
7754: if (($maxsize) && ($maxsize < $num)) {
7755: $output .= ' size="'.$maxsize.'"';
7756: }
7757: }
1.91 raeburn 7758: if ($id ne '') {
7759: $output .= ' id="'.$id.'"';
7760: }
1.80 raeburn 7761: $output .= $disabled.'>'."\n";
1.1 raeburn 7762: if ($nullval ne '') {
7763: $output .= '<option value=""';
7764: if (ref($curr) eq 'ARRAY') {
7765: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7766: $output .= ' selected="selected" ';
7767: }
7768: } else {
7769: if ($curr eq '') {
7770: $output .= ' selected="selected" ';
7771: }
7772: }
7773: $output .= '>'.$nullval.'</option>';
7774: }
7775: foreach my $option (@{$order}) {
7776: $output.= '<option value="'.$option.'"';
7777: if (ref($curr) eq 'ARRAY') {
7778: if (grep(/^\Q$option\E$/,@{$curr})) {
7779: $output .= ' selected="selected" ';
7780: }
7781: } else {
7782: if ($option eq $curr) {
7783: $output.=' selected="selected"';
7784: }
7785: }
7786: $output.=">$options->{$option}</option>\n";
7787: }
7788: $output.="</select>";
7789: }
7790: return $output;
7791: }
7792:
7793: sub make_item_rows {
1.80 raeburn 7794: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
1.1 raeburn 7795: my $datatable;
7796: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7797: my $count = 0;
7798: foreach my $item (@{$ordered}) {
7799: $count ++;
1.56 raeburn 7800: my $colspan;
7801: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7802: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7803: $colspan = 2;
7804: }
1.114 raeburn 7805: my $rowdesc;
7806: if ($caller eq 'appearance') {
7807: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7808: } else {
7809: $rowdesc = $items->{$item}{text};
7810: }
1.41 www 7811: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7812: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7813: } else {
1.114 raeburn 7814: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7815: }
1.55 raeburn 7816: if ($item eq 'defaultcredits') {
7817: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7818: my $showcredits;
7819: if ($defaultcredits ne '') {
7820: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7821: } else {
7822: $showcredits = &mt('No default set');
7823: }
7824: $datatable .= $showcredits;
7825: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 7826: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 7827: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 7828: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7829: } elsif ($item eq 'print_header_format') {
1.80 raeburn 7830: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 7831: } elsif ($item eq 'lti.lcmenu') {
7832: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 7833: } elsif ($item eq 'extresource') {
7834: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7835: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 7836: my $disabled;
7837: if ($noedit) {
7838: $disabled = ' disabled="disabled"';
7839: }
1.1 raeburn 7840: $datatable .=
7841: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 7842: $settings->{$item},$disabled);
1.1 raeburn 7843: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 7844: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 7845: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 7846: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7847: unless ($domdefs{$item} eq '0') {
7848: $unsetdefault = 1;
7849: }
7850: $valueyes = "1";
7851: $valueno = "0";
1.87 raeburn 7852: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
7853: $valueyes = '1';
1.69 raeburn 7854: }
1.80 raeburn 7855: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7856: } elsif ($items->{$item}{input} eq 'selectbox') {
1.91 raeburn 7857: my $id;
7858: if ($caller eq 'menuitems') {
7859: $id = $item;
7860: }
1.1 raeburn 7861: my $curr = $settings->{$item};
7862: $datatable .=
7863: &select_from_options($item,$items->{$item}{'order'},
7864: $items->{$item}{'options'},$curr,
1.80 raeburn 7865: $items->{$item}{'nullval'},
1.91 raeburn 7866: undef,undef,undef,$noedit,$id);
1.1 raeburn 7867: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 7868: my $disabled;
7869: if ($noedit) {
7870: $disabled = ' disabled=disabled"';
7871: }
1.1 raeburn 7872: $datatable .=
7873: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 7874: $items->{$item}{size},
7875: $disabled);
1.1 raeburn 7876: }
7877: $datatable .= &item_table_row_end();
7878: }
7879: if (ref($rowtotal)) {
7880: $$rowtotal += scalar(@{$ordered});
7881: }
7882: }
7883: return $datatable;
7884: }
7885:
7886: sub nothidepriv_row {
1.80 raeburn 7887: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 7888: my ($cnum) = &get_course();
1.56 raeburn 7889: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 7890: if (ref($settings) eq 'HASH') {
7891: if ($settings->{$item} ne '') {
7892: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
7893: if ($user !~ /:/) {
7894: $nothide{join(':',split(/[\@]/,$user))}=1;
7895: } else {
7896: $nothide{$user} = 1;
7897: }
7898: }
7899: }
1.56 raeburn 7900: if ($settings->{'checkforpriv'}) {
1.124 raeburn 7901: @checkdoms = split(/,/,$settings->{'checkforpriv'});
1.56 raeburn 7902: }
1.1 raeburn 7903: }
1.56 raeburn 7904: push(@checkdoms,$cdom);
7905: my %coursepersonnel =
7906: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 7907: my @privusers;
7908: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 7909: my ($uname,$udom,$role) = split(/:/,$person);
7910: my $user = $uname.':'.$udom;
7911: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 7912: if ($end == -1 || $start == -1) {
7913: next;
7914: }
1.124 raeburn 7915: foreach my $dom (@checkdoms) {
1.56 raeburn 7916: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
7917: unless (grep(/^\Q$user\E$/,@privusers)) {
7918: push(@privusers,$user);
1.3 raeburn 7919: }
7920: }
7921: }
1.1 raeburn 7922: }
1.56 raeburn 7923: if (@privusers > 0) {
1.80 raeburn 7924: my $disabled;
7925: if ($noedit) {
7926: $disabled = ' disabled="disabled"';
7927: }
1.1 raeburn 7928: $datatable .= '<table align="right">';
7929: foreach my $user (sort(@privusers)) {
7930: my $hideon = ' checked="checked" ';
7931: my $hideoff = '';
7932: if ($nothide{$user}) {
7933: $hideoff = $hideon;
7934: $hideon = '';
7935: }
7936: my ($uname,$udom) = split(':',$user);
7937: $datatable .= '<tr><td align="left">'.
7938: &Apache::loncommon::aboutmewrapper(
7939: &Apache::loncommon::plainname($uname,$udom,'firstname'),
7940: $uname,$udom,'aboutuser').
7941: '</td><td align="left">'.
7942: '<span class="LC_nobreak"><label>'.
7943: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 7944: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 7945: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 7946: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 7947: '</tr>';
7948: }
7949: $datatable .= '</table>';
7950: } else {
1.9 raeburn 7951: if ($crstype eq 'Community') {
7952: $datatable .= &mt('No Domain Coordinators have community roles');
7953: } else {
7954: $datatable .= &mt('No Domain Coordinators have course roles');
7955: }
1.1 raeburn 7956: }
7957: return $datatable;
7958: }
7959:
1.56 raeburn 7960: sub checkforpriv_row {
1.80 raeburn 7961: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 7962: my $datatable;
7963: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7964: if (keys(%domains) == 1) {
7965: $datatable = '</td><td align="right">'.
7966: &mt("Course's domain is only domain");
7967: return $datatable;
7968: }
7969: my @excdoms = ($cdom);
7970: my $num = 0;
7971: if ($settings->{$item} eq '') {
7972: $datatable = '</td><td align="right">'.
7973: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 7974: 1,1,undef,undef,\@excdoms,
7975: $noedit);
1.56 raeburn 7976: } else {
7977: my @privdoms = split(/,/,$settings->{$item});
7978: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7979: $datatable = '</td><td align="right"><br />'.
7980: &Apache::loncommon::start_data_table();
1.80 raeburn 7981: my $disabled;
7982: if ($noedit) {
7983: $disabled = ' disabled="disabled"';
7984: }
1.56 raeburn 7985: if (@privdoms > 0) {
7986: foreach my $currdom (@privdoms) {
7987: next unless ($domains{$currdom});
7988: my $domdesc = &Apache::lonnet::domain($currdom,'description');
7989: if ($domdesc eq '') {
7990: $domdesc = $currdom;
1.124 raeburn 7991: }
1.56 raeburn 7992: $datatable .=
7993: &Apache::loncommon::start_data_table_row().
7994: '<td align="left"><span class="LC_nobreak">'.
7995: &mt('Domain:').'<b> '.$domdesc.
7996: '</b><input type="hidden" name="checkforpriv_'.$num.
7997: '" value="'.$currdom.'" /></span><br />'.
7998: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 7999: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
8000: &mt('Delete').'</label></span></td>'.
1.56 raeburn 8001: &Apache::loncommon::end_data_table_row();
8002: $num ++;
1.124 raeburn 8003: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
1.56 raeburn 8004: push(@excdoms,$currdom);
8005: }
8006: }
8007: }
8008: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
1.124 raeburn 8009: $datatable .=
1.56 raeburn 8010: &Apache::loncommon::start_data_table_row().
8011: '<td align="left"><span class="LC_nobreak">'.
8012: &mt('Additional domain:'). '</span><br />'.
8013: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8014: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8015: '</td>'.&Apache::loncommon::end_data_table_row();
8016: }
8017: $datatable .= &Apache::loncommon::end_data_table().
8018: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8019: '<br />';
8020: }
8021: return $datatable;
8022: }
8023:
1.1 raeburn 8024: sub print_hdrfmt_row {
1.80 raeburn 8025: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8026: my @curr;
8027: my $currnum = 0;
8028: my $maxnum = 2;
8029: my $currstr;
8030: if ($settings->{$item} ne '') {
8031: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8032: $settings->{$item}.'</tt></span></b><br />';
8033: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8034: foreach my $val (@current) {
8035: unless ($val eq '') {
8036: push(@curr,$val);
1.1 raeburn 8037: }
8038: }
8039: $currnum = @curr;
8040: $maxnum += $currnum;
8041: }
8042:
8043: my $output = <<ENDJS;
8044:
8045: <script type="text/javascript" language="Javascript">
8046:
8047: function reOrder(chgnum) {
8048: var maxnum = $maxnum;
8049: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8050: var newidx = 'printfmthdr_pos_'+chgnum;
8051: oldidx = getIndexByName(oldidx);
8052: newidx = getIndexByName(newidx);
8053: var oldpos = document.display.elements[oldidx].value;
8054: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8055: document.display.elements[oldidx].value = newpos;
8056: var chgtype = 'up';
8057: if (newpos < oldpos) {
8058: chgtype = 'down';
8059: }
8060: for (var j=0; j<maxnum; j++) {
8061: if (j != chgnum) {
8062: oldidx = 'printfmthdr_oldpos_'+j;
8063: newidx = 'printfmthdr_pos_'+j;
8064: oldidx = getIndexByName(oldidx);
8065: newidx = getIndexByName(newidx);
8066: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8067: var currsel = document.display.elements[newidx].selectedIndex;
8068: if (chgtype == 'up') {
8069: if ((currpos > oldpos) && (currpos <= newpos)) {
8070: document.display.elements[newidx].selectedIndex = currsel-1;
8071: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8072: }
8073: } else {
8074: if ((currpos >= newpos) && (currpos < oldpos)) {
8075: document.display.elements[newidx].selectedIndex = currsel+1;
8076: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8077: }
8078: }
8079: }
8080: }
8081: return;
8082: }
8083:
8084: function getIndexByName(item) {
8085: for (var i=0;i<document.display.elements.length;i++) {
8086: if (document.display.elements[i].name == item) {
8087: return i;
8088: }
8089: }
8090: return -1;
8091: }
8092:
8093: </script>
8094:
8095: ENDJS
1.56 raeburn 8096: $output .= '</td><td align="right"><br />'.
8097: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8098: my $disabled;
8099: if ($noedit) {
8100: $disabled = ' disabled="disabled"';
8101: }
1.1 raeburn 8102: if (@curr > 0) {
8103: for (my $i=0; $i<@curr; $i++) {
8104: my $pos = $i+1;
1.10 raeburn 8105: $output .= '<tr>'.
1.1 raeburn 8106: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8107: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8108: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8109: '"'.$disabled.' /></span></td>';
1.1 raeburn 8110: if ($curr[$i] =~ /^%\d*[nca]$/) {
8111: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8112: $output .= '<td align="left">'.
1.80 raeburn 8113: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8114: } else {
8115: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8116: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8117: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8118: }
1.10 raeburn 8119: $output .= '</tr>';
1.1 raeburn 8120: }
8121: }
1.80 raeburn 8122: my $pos = $currnum+1;
1.124 raeburn 8123: unless ($noedit) {
1.80 raeburn 8124: $output .=
8125: '<tr>'.
1.1 raeburn 8126: '<td align="left"><span class="LC_nobreak">'.
8127: &position_selector($pos,$currnum,$maxnum).
8128: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8129: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8130: '</tr>';
1.80 raeburn 8131: $pos ++;
1.82 raeburn 8132: $currnum ++;
8133: $output .=
1.80 raeburn 8134: '<tr>'.
1.1 raeburn 8135: '<td align="left"><span class="LC_nobreak">'.
8136: &position_selector($pos,$currnum,$maxnum).
8137: '<b>'.&mt('New').'</b></span></td>'.
8138: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8139: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8140: '" value="" size ="25" />'.
8141: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8142: $maxnum.'" /></td>'.
1.80 raeburn 8143: '</tr>';
8144: }
8145: $output .= '</table><br />';
1.1 raeburn 8146: return $output;
8147: }
8148:
8149: sub position_selector {
1.80 raeburn 8150: my ($pos,$num,$maxnum,$disabled) = @_;
8151: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8152: for (my $j=1; $j<=$maxnum; $j++) {
8153: my $sel = '';
8154: if ($pos == $j) {
8155: $sel = ' selected="selected"';
8156: }
8157: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8158: }
8159: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8160: '" value="'.$pos.'" />';
8161: return $output;
8162: }
8163:
8164: sub substitution_selector {
1.80 raeburn 8165: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8166: my ($stunametxt,$crsidtxt);
8167: if ($crstype eq 'Community') {
8168: $stunametxt = 'member name';
8169: $crsidtxt = 'community ID',
8170: } else {
8171: $stunametxt = 'student name';
8172: $crsidtxt = 'course ID',
8173: }
1.1 raeburn 8174: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8175: n => $stunametxt,
8176: c => $crsidtxt,
1.1 raeburn 8177: a => 'assignment note',
8178: );
8179: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8180: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8181: if ($subst eq '') {
8182: $output .= '<option value="" selected="selected"> </option>';
8183: }
8184: foreach my $field ('n','c','a') {
8185: my $sel ='';
8186: if ($subst eq $field) {
8187: $sel = ' selected="selected"';
8188: }
8189: $output .= '<option value="'.$field.'"'.$sel.'>'.
8190: $lt{$field}.'</option>';
8191: }
8192: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8193: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8194: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8195: return $output;
8196: }
8197:
1.23 raeburn 8198: sub change_clone {
8199: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8200: my $clone_crs = $cnum.':'.$cdom;
8201: if ($cnum && $cdom) {
8202: my $clone_crs = $cnum.':'.$cdom;
8203: my @allowclone;
8204: if ($clonelist =~ /,/) {
8205: @allowclone = split(',',$clonelist);
8206: } else {
8207: $allowclone[0] = $clonelist;
8208: }
8209: foreach my $currclone (@allowclone) {
8210: if (!grep(/^$currclone$/,@$oldcloner)) {
8211: if ($currclone ne '*') {
1.71 raeburn 8212: if ($currclone =~ /:/) {
8213: my ($uname,$udom) = split(/:/,$currclone);
8214: if ($uname && $udom && $uname ne '*') {
8215: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8216: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8217: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8218: if ($currclonecrs{'cloneable'} eq '') {
8219: $currclonecrs{'cloneable'} = $clone_crs;
8220: } else {
8221: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8222: }
8223: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8224: }
8225: }
8226: }
8227: }
8228: }
8229: }
8230: }
8231: foreach my $oldclone (@$oldcloner) {
8232: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8233: if ($oldclone ne '*') {
1.71 raeburn 8234: if ($oldclone =~ /:/) {
8235: my ($uname,$udom) = split(/:/,$oldclone);
8236: if ($uname && $udom && $uname ne '*' ) {
8237: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8238: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8239: my %newclonecrs = ();
8240: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8241: if ($currclonecrs{'cloneable'} =~ /,/) {
8242: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8243: foreach my $crs (@currclonecrs) {
8244: if ($crs ne $clone_crs) {
8245: $newclonecrs{'cloneable'} .= $crs.',';
8246: }
1.23 raeburn 8247: }
1.71 raeburn 8248: $newclonecrs{'cloneable'} =~ s/,$//;
8249: } else {
8250: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8251: }
1.71 raeburn 8252: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8253: }
8254: }
8255: }
8256: }
8257: }
8258: }
8259: }
8260: }
8261: return;
8262: }
8263:
1.108 raeburn 8264: sub devalidate_remote_courseprefs {
8265: my ($cdom,$cnum,$cachekeys) = @_;
8266: return unless (ref($cachekeys) eq 'HASH');
8267: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8268: my %thismachine;
8269: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8270: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8271: if (keys(%servers)) {
8272: foreach my $server (keys(%servers)) {
8273: next if ($thismachine{$server});
8274: my @cached;
8275: foreach my $name (@posscached) {
8276: if ($cachekeys->{$name}) {
8277: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8278: }
8279: }
8280: if (@cached) {
8281: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8282: }
8283: }
8284: }
8285: return;
8286: }
8287:
1.1 raeburn 8288: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>