Annotation of loncom/interface/courseprefs.pm, revision 1.129
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.129 ! raeburn 4: # $Id: courseprefs.pm,v 1.128 2023/12/13 22:12:17 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.23 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: courseprefs- Handler to set/modify course configuration
36:
37: =head1 SYNOPSIS
38:
39: courseprefs provides an interface for setting general course configuration
40:
41: =head1 DESCRIPTION
42:
43: This module is used for configuration of a course
44:
45: =head1 INTERNAL SUBROUTINES
46:
47: =over
48:
49: =item get_allitems()
50:
51: =item print_config_box()
52:
53: =item process_changes()
54:
1.102 raeburn 55: =item process_linkprot()
56:
1.23 raeburn 57: =item get_sec_str()
58:
59: =item check_clone()
60:
61: =item store_changes()
62:
1.102 raeburn 63: =item store_linkprot()
64:
1.23 raeburn 65: =item update_env()
66:
67: =item display_disallowed()
68:
69: =item get_course()
70:
71: =item get_jscript()
72:
73: =item cloners_javascript()
74:
75: =item print_courseinfo()
76:
77: =item new_cloners_dom_row()
78:
79: =item can_modify_catsettings()
80:
81: =item assign_course_categories()
82:
83: =item print_localization()
84:
85: =item get_lang_choices()
86:
87: =item print_feedback()
88:
89: =item user_table()
90:
91: =item select_recipient()
92:
93: =item select_sections()
94:
95: =item print_discussion()
96:
97: =item role_checkboxes()
98:
99: =item print_classlists()
100:
101: =item print_appearance()
102:
103: =item print_grading()
104:
105: =item print_printouts()
106:
107: =item print_spreadsheet()
108:
109: =item print_bridgetasks()
110:
111: =item print_other()
112:
113: =item get_other_items()
114:
115: =item item_table_row_start()
116:
117: =item item_table_row_end()
118:
1.115 raeburn 119: =item yesno_radio()
1.23 raeburn 120:
121: =item select_from_options()
122:
123: =item make_item_rows()
124:
125: Creates table used to display and set course configuration items.
126:
127: Inputs: $cdom,$items,$ordered,$settings,$rowtotal,$crstype
128: where $cdom is course's domain, $items is HASH ref for current config
129: item, $ordered is ARRAY ref of items to include in row in
130: display order, $settings is HASH ref of current values forrow,
131: $rowtotal is SCALAR ref used to accumulate row count, $crstype is
132: course type.
133:
134: Returns: $datatable
135: HTML mark-up of data table which accumulates individual rows.
136:
137: =item nothidepriv_row()
138:
139: Creates row containing form elements used to display and set
140: whether Domain coordinators who are currently included in
141: advanced course user .db file for a course are to be hidden (e.g.,
142: in syllabus, or from course user lists).
143:
1.80 raeburn 144: Inputs: $cdom,$item,$settings,$crstype,$noedit
1.23 raeburn 145: where $cdom is course domain, item is nothideprivileged, $settings is
146: HASH ref of the current values for nothideprivileged, $crstype is
147: course type (Course or Community).
148:
149: Return: $datatable
150: HTML mark-up for Privileged users (Domain Coordinators) in staff listing.
151:
152: =item print_hdrfmt_row()
153:
154: Creates row containing form elements used to display and set
155: substitution items and text to be used in the header included
156: on printouts.
157:
158: Inputs: $item,$settings
159: where $item is print_header_format, and $settings is a HASH ref
160: of the current values stored for print_header_format.
161:
162: Returns: $output
163: HTML mark-up containing Javascript functions: reOrder() and getIndexByName()
164: used to dynamically update position selectboxes, and HTML table elements
165: for the "Print header format" row.
166:
167: =item position_selector()
168:
169: Creates a select box which can be used to reorder substitutions
170: and text included in a printout header.
171:
172: Inputs: $pos,$num,$maxnum
173: where $pos is current position, $num is the unique identifier,
174: and $maxnum is the total number of items (both substitutions
175: and text in the printout header.
176:
177: Returns: $output
178: HTML mark-up for the selectbox and a hidden form element containing
179: the current position.
180:
181: =item substitution_selector()
182:
183: Creates a combination of select box for choosing an item
184: (student name, course ID or assignment note) to substitute,
185: and a corresponding size limit in the header used for printouts.
186:
187: Inputs: $num,$subst,$limit,$crstype
188: where $num is the unique identifier, $subst is the current
189: substitution (n,c or a, for name, course or note respectively,
190: $limit is the current size limit (integer), and $crstype is
191: course type - course or community.
192:
193: Returns: $output
194: HTML mark-up for selectbox and textbox (separate table cells).
195:
196: =item change_clone()
197:
198: Modifies the list of courses a user can clone (stored
199: in the user's environment.db file), called when a
200: change is made to the list of users allowed to clone
201: a course.
202:
203: Inputs: $action,$cloner
204: where $action is add or drop, and $cloner is identity of
205: user for whom cloning ability is to be changed in course.
206:
207: Returns: nothing
208:
209: =back
210:
211: =cut
212:
213:
1.1 raeburn 214: package Apache::courseprefs;
215:
216: use strict;
217: use Apache::Constants qw(:common :http);
218: use Apache::lonnet;
219: use Apache::loncommon();
220: use Apache::lonhtmlcommon();
221: use Apache::lonconfigsettings;
1.66 raeburn 222: use Apache::lonrelrequtils;
1.36 raeburn 223: use Apache::lonparmset;
1.71 raeburn 224: use Apache::courseclassifier;
1.1 raeburn 225: use Apache::lonlocal;
226: use LONCAPA qw(:DEFAULT :match);
1.103 raeburn 227: use Crypt::CBC;
1.118 raeburn 228: use Time::HiRes qw( sleep );
1.1 raeburn 229:
1.66 raeburn 230: my $registered_cleanup;
231: my $modified_courses;
232:
1.1 raeburn 233: sub handler {
234: my $r=shift;
235: if ($r->header_only) {
236: &Apache::loncommon::content_type($r,'text/html');
237: $r->send_http_header;
238: return OK;
239: }
240: my $context = 'course';
241: my $cid = $env{'request.course.id'};
1.66 raeburn 242: my ($cnum,$cdom,$chome) = &get_course($cid);
1.1 raeburn 243: my $crstype = &Apache::loncommon::course_type();
1.80 raeburn 244: my ($parm_permission,$allowed) = &get_permission($cid);
1.1 raeburn 245: my $navmap = Apache::lonnavmaps::navmap->new();
1.80 raeburn 246: if ($allowed && $navmap) {
1.1 raeburn 247: &Apache::loncommon::content_type($r,'text/html');
248: $r->send_http_header;
249: } else {
250: if ($navmap) {
1.9 raeburn 251: if ($crstype eq 'Community') {
252: $env{'user.error.msg'}=
253: "/adm/courseprefs:opa:0:0:Cannot modify community settings";
254: } else {
255: $env{'user.error.msg'}=
256: "/adm/courseprefs:opa:0:0:Cannot modify course settings";
257: }
1.1 raeburn 258: } else {
1.9 raeburn 259: if ($crstype eq 'Community') {
260: $env{'user.error.msg'}=
261: "/adm/courseprefs::0:1:Course environment gone, reinitialize the community";
262: } else {
263: $env{'user.error.msg'}=
264: "/adm/courseprefs::0:1:Course environment gone, reinitialize the course";
265:
266: }
1.1 raeburn 267: }
268: return HTTP_NOT_ACCEPTABLE;
269: }
270:
1.66 raeburn 271: $registered_cleanup=0;
272: @{$modified_courses}=();
273:
1.4 raeburn 274: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
275: ['phase','actions','origin']);
1.1 raeburn 276: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.4 raeburn 277: if ($env{'form.origin'} eq 'params') {
278: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
279: text=>"Parameter Manager"});
280: }
1.9 raeburn 281: my ($brtext,$brtitle,$crsinfotext,$crsinfodesc,$crscateg,$crshide);
282: my %lt;
283: if ($crstype eq 'Community') {
284: %lt = (
1.40 www 285: conf => 'Community Settings',
286: edit => 'Edit Community Settings',
1.9 raeburn 287: gens => 'General community settings',
288: idnu => 'Community ID or number',
1.64 raeburn 289: unco => 'Unique code',
1.9 raeburn 290: desc => 'Community Description',
1.24 raeburn 291: ownr => 'Community Owner',
1.25 raeburn 292: cown => 'Community Co-owners',
1.9 raeburn 293: catg => 'Categorize community',
294: excc => 'Exclude from community catalog',
295: clon => 'Users allowed to clone community',
296: rept => 'Replacement titles for standard community roles',
1.115 raeburn 297: time => 'Time Zone where the community is located',
1.9 raeburn 298: date => 'Locale used for community calendar',
299: coco => 'Community Content',
300: copo => 'Community Policy',
1.13 bisitz 301: priv => 'Domain Coordinators in community',
1.9 raeburn 302: defd => 'Default dates for member access',
303: stuv => 'Member-viewable membership list options',
304: stul => 'Member agreement needed to be listed',
1.42 www 305: clas => 'Membership and facilitator listing',
1.57 raeburn 306: prus => 'Privileged users (Domain Coordinators) in facilitator listing',
1.9 raeburn 307: defc => 'Default Community Spreadsheet',
308: defs => 'Default User Spreadsheet',
309: seme => 'Send message to member when clicking Done on Tasks'
310: );
311: } else {
312: %lt = (
1.40 www 313: conf => 'Course Settings',
314: edit => 'Edit Course Settings',
1.20 faziophi 315: gens => 'General course settings',
316: idnu => 'Course ID or number',
1.64 raeburn 317: unco => 'Unique code',
1.20 faziophi 318: desc => 'Course Description',
1.124 raeburn 319: cred => 'Student credits',
1.24 raeburn 320: ownr => 'Course Owner',
1.25 raeburn 321: cown => 'Course Co-owners',
1.9 raeburn 322: catg => 'Categorize course',
323: excc => 'Exclude from course catalog',
324: clon => 'Users allowed to clone course',
325: rept => 'Replacement titles for standard course roles',
1.115 raeburn 326: time => 'Time Zone in which the course takes place',
1.20 faziophi 327: date => 'Locale used for course calendar',
1.9 raeburn 328: coco => 'Course Content',
329: copo => 'Course Policy',
1.13 bisitz 330: priv => 'Domain Coordinators in course',
1.9 raeburn 331: defd => 'Default dates for student access',
332: stuv => 'Student-viewable classlist options',
333: stul => 'Student agreement needed to be listed',
1.42 www 334: clas => 'Classlists and staff listing',
1.57 raeburn 335: prus => 'Privileged users (Domain Coordinators) in staff listing',
1.56 raeburn 336: prdo => "Domains to check for privileged users (besides course's domain)",
1.9 raeburn 337: defc => 'Default Course Spreadsheet',
338: defs => 'Default Student Spreadsheet',
339: seme => 'Send message to student when clicking Done on Tasks',
340: );
341: }
1.35 raeburn 342: $lt{'lcrv'} = 'Required LON-CAPA version';
1.1 raeburn 343: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/courseprefs',
1.9 raeburn 344: text=>$lt{'conf'}});
1.1 raeburn 345: my $breadcrumbs =
1.9 raeburn 346: &Apache::lonhtmlcommon::breadcrumbs($lt{'edit'});
1.1 raeburn 347:
348: my $phase = 'pickactions';
349: if ( exists($env{'form.phase'}) ) {
350: $phase = $env{'form.phase'};
351: }
352:
1.80 raeburn 353: if (($phase eq 'categorizecourse') && ($parm_permission->{'categorizecourse'})) {
1.9 raeburn 354: &assign_course_categories($r,$crstype);
1.1 raeburn 355: return OK;
356: }
357:
1.80 raeburn 358: if (($phase eq 'releaseinfo') && ($parm_permission->{'releaseinfo'})) {
1.36 raeburn 359: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
360: if ($loncaparev) {
1.66 raeburn 361: if (&display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype)) {
362: push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
363: unless ($registered_cleanup) {
364: my $handlers = $r->get_handlers('PerlCleanupHandler');
365: $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
366: $registered_cleanup=1;
367: }
368: }
1.36 raeburn 369: return OK;
370: }
371: }
372:
1.1 raeburn 373: my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.102 raeburn 374: my %linkprot=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1.99 raeburn 375: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
1.118 raeburn 376: my %ltitools = &Apache::lonnet::dump('ltitools',$cdom,$cnum,undef,undef,undef,1);
377: my %ltitoolsenc = &Apache::lonnet::dump('nohist_toolsenc',$cdom,$cnum,undef,undef,undef,1);
1.102 raeburn 378: foreach my $id (keys(%linkprot)) {
379: if (ref($linkprot{$id}) eq 'HASH') {
1.99 raeburn 380: if (ref($ltienc{$id}) eq 'HASH') {
1.102 raeburn 381: $values{'linkprot'}{$id} = { %{$linkprot{$id}}, %{$ltienc{$id}} };
1.99 raeburn 382: } else {
1.102 raeburn 383: $values{'linkprot'}{$id} = $linkprot{$id};
1.99 raeburn 384: }
385: }
386: unless ($phase eq 'process') {
1.102 raeburn 387: if (ref($values{'linkprot'}{$id}) eq 'HASH') {
388: delete($values{'linkprot'}{$id}{'secret'});
1.99 raeburn 389: }
390: }
391: }
1.102 raeburn 392: if ($linkprot{'lock'}) {
393: delete($linkprot{'lock'});
1.93 raeburn 394: }
1.118 raeburn 395: foreach my $id (keys(%ltitools)) {
396: if (ref($ltitools{$id}) eq 'HASH') {
397: if (ref($ltitoolsenc{$id}) eq 'HASH') {
398: $values{'ltitools'}{$id} = { %{$ltitools{$id}}, %{$ltitoolsenc{$id}} };
399: } else {
400: $values{'ltitools'}{$id} = $ltitools{$id};
401: }
402: }
403: unless ($phase eq 'process') {
404: if (ref($values{'ltitools'}{$id}) eq 'HASH') {
405: delete($values{'ltitools'}{$id}{'secret'});
406: }
407: }
408: }
409: if ($ltitools{'lock'}) {
410: delete($ltitools{'lock'});
411: }
1.1 raeburn 412: my @prefs_order = ('courseinfo','localization','feedback','discussion',
413: 'classlists','appearance','grading','printouts',
1.118 raeburn 414: 'menuitems','ltitools','linkprot','spreadsheet',
415: 'bridgetasks','lti','other');
1.1 raeburn 416: my %prefs = (
417: 'courseinfo' =>
1.9 raeburn 418: { text => $lt{'gens'},
1.44 www 419: help => 'Course_Prefs_General',
1.35 raeburn 420: ordered => ['owner','co-owners','loncaparev','description',
1.64 raeburn 421: 'clonedfrom','courseid','uniquecode','categories',
1.88 raeburn 422: 'hidefromcat','syllabus','cloners','url',
1.64 raeburn 423: 'rolenames'],
1.3 raeburn 424: itemtext => {
1.25 raeburn 425: 'owner' => $lt{'ownr'},
426: 'co-owners' => $lt{'cown'},
427: 'description' => $lt{'desc'},
428: 'courseid' => $lt{'idnu'},
1.64 raeburn 429: 'uniquecode' => $lt{'unco'},
1.25 raeburn 430: 'categories' => $lt{'catg'},
431: 'hidefromcat' => $lt{'excc'},
432: 'cloners' => $lt{'clon'},
1.88 raeburn 433: 'syllabus' => 'Syllabus status',
1.25 raeburn 434: 'url' => 'Top Level Map',
435: 'rolenames' => $lt{'rept'},
1.35 raeburn 436: 'loncaparev' => $lt{'lcrv'},
1.63 raeburn 437: 'clonedfrom' => 'Cloned from',
1.3 raeburn 438: },
1.1 raeburn 439: },
440: 'localization' =>
1.42 www 441: { text => 'Language and time localization',
1.44 www 442: help => 'Course_Prefs_Language',
1.1 raeburn 443: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 444: itemtext => {
1.20 faziophi 445: languages => 'Languages used',
1.9 raeburn 446: timezone => $lt{'time'},
447: datelocale => $lt{'date'},
1.3 raeburn 448: },
1.1 raeburn 449: },
450: 'feedback' =>
1.20 faziophi 451: { text => 'Feedback messages',
1.44 www 452: help => 'Course_Prefs_Feedback',
1.1 raeburn 453: header => [{col1 => 'Questions about:',
1.20 faziophi 454: col2 => 'Recipients'}],
1.3 raeburn 455: ordered => ['question.email','comment.email','policy.email'],
456: itemtext => {
457: 'question.email' => 'Resource Content',
1.9 raeburn 458: 'comment.email' => $lt{'coco'},
459: 'policy.email' => $lt{'copo'},
1.3 raeburn 460: },
1.1 raeburn 461: },
462: 'discussion' =>
463: { text => 'Discussion and Chat',
1.44 www 464: help => 'Course_Prefs_Discussions',
1.31 raeburn 465: ordered => ['pch.roles.denied','pch.users.denied',
1.77 raeburn 466: 'pac.roles.denied','pac.users.denied',
1.31 raeburn 467: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 468: 'allow_limited_html_in_feedback',
1.50 raeburn 469: 'allow_discussion_post_editing',
470: 'discussion_post_fonts'],
1.3 raeburn 471: itemtext => {
1.31 raeburn 472: 'pch.roles.denied' => 'No Resource Discussion',
473: 'pch.users.denied' => 'No Resource Discussion',
474: 'plc.roles.denied' => 'No Chat room use',
475: 'plc.users.denied' => 'No Chat room use',
1.77 raeburn 476: 'pac.roles.denied' => 'No Anonymous Resource Discussion',
477: 'pac.users.denied' => 'No Anonymous Resource Discussion',
1.20 faziophi 478: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
479: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.77 raeburn 480: discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 481: },
1.1 raeburn 482: },
483: 'classlists' =>
1.9 raeburn 484: { text => $lt{'clas'},
1.44 www 485: help => 'Course_Prefs_Classlists',
1.1 raeburn 486: header => [{col1 => 'Type',
1.9 raeburn 487: col2 => $lt{'defd'}},
1.1 raeburn 488: {col1 => 'Setting',
1.9 raeburn 489: col2 => $lt{'priv'}},
1.1 raeburn 490: {col1 => 'Setting',
1.9 raeburn 491: col2 => $lt{'stuv'}}],
1.1 raeburn 492: ordered => ['default_enrollment_start_date',
493: 'default_enrollment_end_date',
1.55 raeburn 494: 'defaultcredits',
1.56 raeburn 495: 'nothideprivileged','checkforpriv',
496: 'student_classlist_view',
1.26 raeburn 497: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 498: itemtext => {
499: default_enrollment_start_date => 'Start date',
500: default_enrollment_end_date => 'End date',
1.57 raeburn 501: nothideprivileged => $lt{'prus'},
1.56 raeburn 502: checkforpriv => $lt{'prdo'},
1.9 raeburn 503: student_classlist_view => $lt{'stuv'},
1.26 raeburn 504: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 505: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.55 raeburn 506: defaultcredits => $lt{'cred'},
1.3 raeburn 507: },
1.1 raeburn 508: },
509: 'appearance' =>
1.20 faziophi 510: { text => 'Display of resources ',
1.44 www 511: help => 'Course_Prefs_Display',
1.1 raeburn 512: ordered => ['default_xml_style','pageseparators',
513: 'disable_receipt_display','texengine',
1.114 raeburn 514: 'tthoptions','uselcmath','usejsme',
515: 'inline_chem','extresource'],
1.3 raeburn 516: itemtext => {
1.17 faziophi 517: default_xml_style => 'Default XML style file',
1.20 faziophi 518: pageseparators => 'Visibly Separate Items on Pages',
519: disable_receipt_display => 'Disable display of problem receipts',
520: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 521: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.69 raeburn 522: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
523: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.95 raeburn 524: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.124 raeburn 525: extresource => 'Display of external resources',
1.3 raeburn 526: },
1.1 raeburn 527: },
528: 'grading' =>
529: { text => 'Grading',
1.44 www 530: help => 'Course_Prefs_Grading',
1.1 raeburn 531: ordered => ['grading','rndseed',
532: 'receiptalg','disablesigfigs'],
1.3 raeburn 533: itemtext => {
1.20 faziophi 534: grading => 'Grading',
535: rndseed => 'Randomization algorithm used',
536: receiptalg => 'Receipt algorithm used',
537: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 538: },
539:
1.1 raeburn 540: },
541: 'printouts' =>
1.20 faziophi 542: { text => 'Printout generation',
1.44 www 543: help => 'Course_Prefs_Printouts',
1.1 raeburn 544: ordered => ['problem_stream_switch','suppress_tries',
545: 'default_paper_size','print_header_format',
1.14 raeburn 546: 'disableexampointprint','canuse_pdfforms'],
1.3 raeburn 547: itemtext => {
548: problem_stream_switch => 'Allow problems to be split over pages',
549: suppress_tries => 'Suppress number of tries in printing',
550: default_paper_size => 'Default paper type',
551: print_header_format => 'Print header format',
1.51 bisitz 552: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 553: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 554: },
1.1 raeburn 555: },
556: 'spreadsheet' =>
557: { text => 'Spreadsheets',
1.44 www 558: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 559: ordered => ['spreadsheet_default_classcalc',
560: 'spreadsheet_default_studentcalc',
561: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 562: itemtext => {
1.9 raeburn 563: spreadsheet_default_classcalc => $lt{'defc'},
564: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 565: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
566: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
567: },
1.1 raeburn 568: },
569: 'bridgetasks' =>
570: { text => 'Bridge tasks',
1.44 www 571: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 572: ordered => ['task_messages','task_grading',
573: 'suppress_embed_prompt'],
1.3 raeburn 574: itemtext => {
1.9 raeburn 575: task_messages => $lt{'seme'},
1.3 raeburn 576: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 577: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 578: },
1.1 raeburn 579: },
1.87 raeburn 580: 'lti' =>
581: {
582: text => 'LTI provider settings',
583: help => 'Course_Prefs_LTIProvider',
584: ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'],
585: itemtext => {
586: 'lti.override' => 'Override domain defaults',
587: 'lti.topmenu' => 'Display LON-CAPA page header',
588: 'lti.inlinemenu' => 'Display LON-CAPA inline menu',
589: 'lti.lcmenu' => 'Menu items',
590: },
591: },
1.91 raeburn 592: 'menuitems' =>
593: {
594: text => 'Menu display',
595: help => 'Course_Prefs_Menus',
596: header => [{col1 => 'Default Menu',
597: col2 => 'Value',},
598: {col1 => 'Menu collections',
599: col2 => 'Settings',
600: }],
601: ordered => ['menudefault','menucollections'],
602: itemtext => {
603: menudefault => 'Choose default collection of menu items for course',
604: menucollections => 'Menu collections',
605: },
606: },
1.102 raeburn 607: 'linkprot' =>
1.93 raeburn 608: {
609: text => 'Link protection',
610: help => 'Course_Prefs_Linkprotection',
611: header => [{col1 => 'Item',
612: col2 => 'Settings',
613: }],
614: },
1.118 raeburn 615: 'ltitools' =>
616: {
617: text => 'External tools',
618: help => 'Course_Prefs_ExternalTools',
619: header => [{col1 => 'Item',
620: col2 => 'Settings',
621: }],
622: },
1.1 raeburn 623: 'other' =>
624: { text => 'Other settings',
1.44 www 625: help => 'Course_Prefs_Other',
1.1 raeburn 626: header => [ {col1 => 'Item',
627: col2 => 'Value',
628: }],
629: },
630: );
1.80 raeburn 631: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 632: my @allitems = &get_allitems(%prefs);
1.108 raeburn 633: my $result = &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
634: \@prefs_order,\%prefs,\%values,
635: $cnum,undef,\@allitems,
636: 'coursepref',$parm_permission);
637: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
638: $r->rflush();
639: &devalidate_remote_courseprefs($cdom,$cnum,$result);
640: }
1.80 raeburn 641: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.91 raeburn 642: my $noedit;
643: if (ref($parm_permission) eq 'HASH') {
644: unless ($parm_permission->{'process'}) {
645: $noedit = 1;
646: }
647: }
648: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 649: my @allitems = &get_allitems(%prefs);
1.1 raeburn 650: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.99 raeburn 651: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.80 raeburn 652: 'coursepref',$parm_permission);
1.1 raeburn 653: } else {
654: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.80 raeburn 655: \@prefs_order,\%prefs,
656: 'coursepref',$parm_permission);
1.1 raeburn 657: }
658: return OK;
659: }
660:
1.80 raeburn 661: sub get_permission {
662: my ($cid) = @_;
663: my %permission;
664: my $allowed = 0;
665: return (\%permission,$allowed) unless ($cid);
666: if (&Apache::lonnet::allowed('opa',$cid)) {
667: %permission= (
668: 'pickactions' => 1,
669: 'categorizecourse' => 1,
670: 'releaseinfo' => 1,
671: 'process' => 1,
672: 'display' => 1,
673: );
674: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
675: %permission = (
676: 'pickactions' => 1,
677: 'releaseinfo' => 1,
678: 'display' => 1,
679: );
680: }
681: foreach my $perm (values(%permission)) {
682: if ($perm) { $allowed=1; last; }
683: }
684: return (\%permission,$allowed);
685: }
686:
1.3 raeburn 687: sub get_allitems {
688: my (%prefs) = @_;
689: my @allitems;
690: foreach my $item (keys(%prefs)) {
691: if (ref($prefs{$item}) eq 'HASH') {
692: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
693: push(@allitems,@{$prefs{$item}{'ordered'}});
694: if ($item eq 'feedback') {
695: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
696: }
1.126 raeburn 697: } elsif (($item eq 'linkprot') || ($item eq 'ltitools')) {
698: push(@allitems,$item);
1.3 raeburn 699: }
700: }
701: }
702: return @allitems;
703: }
704:
1.1 raeburn 705: sub print_config_box {
1.99 raeburn 706: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 707: my $ordered = $item->{'ordered'};
1.3 raeburn 708: my $itemtext = $item->{'itemtext'};
1.80 raeburn 709: my $noedit;
710: if (ref($parm_permission) eq 'HASH') {
711: unless ($parm_permission->{'process'}) {
712: $noedit = 1;
713: }
714: }
1.1 raeburn 715: my $rowtotal = 0;
716: my $output =
1.45 www 717: '<table class="LC_nested_outer">
718: <tr>
719: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 720: &mt($item->{text});
721: if ($item->{'help'}) {
1.53 raeburn 722: $output .= ' '.
1.52 raeburn 723: &Apache::loncommon::help_open_topic($item->{'help'});
724: }
725: $output .= '</span></th>'."\n".
726: '</tr>';
1.91 raeburn 727: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 728: $output .= '
1.45 www 729: <tr>
730: <td>
1.18 faziophi 731: <table class="LC_nested">';
732: if (exists $item->{'header'}->[0]->{'col1'} ||
733: exists $item->{'header'}->[0]->{'col2'}) {
734: $output .= '
735: <tr class="LC_info_row">
1.56 raeburn 736: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
737: if ($action eq 'feedback') {
738: $output .= '
739: <td class="LC_right_item" colspan="2">';
740: } else {
741: $output .= '
742: <td class="LC_right_item">';
743: }
744: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 745: </tr>';
746: }
1.1 raeburn 747: $rowtotal ++;
748: if ($action eq 'feedback') {
1.80 raeburn 749: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 750: } elsif ($action eq 'classlists') {
1.80 raeburn 751: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 752: } elsif ($action eq 'menuitems') {
753: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 754: }
755: $output .= '
756: </table>
1.45 www 757: </td>
758: </tr>
759: <tr>
760: <td>
1.1 raeburn 761: <table class="LC_nested">
762: <tr class="LC_info_row">
763: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 764: if ($action eq 'classlists') {
765: $output .= '
766: <td class="LC_right_item" colspan="2">';
767: } else {
768: $output .= '
769: <td class="LC_right_item">';
770: }
771: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 772: </tr>';
773: if ($action eq 'classlists') {
1.80 raeburn 774: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 775: '
776: </table>
1.45 www 777: </td>
778: </tr>
779: <tr>
780: <td>
1.18 faziophi 781: <table class="LC_nested">';
1.43 www 782: if (exists $item->{'header'}->[2]->{'col1'} ||
783: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 784: $output .= '
785: <tr class="LC_info_row">
1.43 www 786: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
787: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 788: </tr>';
789: }
1.1 raeburn 790: }
791: } else {
792: $output .= '
1.45 www 793: <tr>
794: <td>
1.18 faziophi 795: <table class="LC_nested">';
796: if (exists $item->{'header'}->[0]->{'col1'} ||
797: exists $item->{'header'}->[0]->{'col2'}) {
798: $output .= '
799: <tr class="LC_info_row">
1.56 raeburn 800: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
801: if (($action eq 'courseinfo') || ($action eq 'localization') ||
802: ($action eq 'print_discussion')) {
803: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
804: } else {
805: $output .= '<td class="LC_right_item" valign="top">';
806: }
807: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 808: </tr>';
809: }
1.1 raeburn 810: }
811: $rowtotal ++;
812: if ($action eq 'courseinfo') {
1.80 raeburn 813: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 814: } elsif ($action eq 'localization') {
1.80 raeburn 815: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 816: } elsif ($action eq 'feedback') {
1.80 raeburn 817: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 818: } elsif ($action eq 'discussion') {
1.80 raeburn 819: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 820: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 821: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 822: } elsif ($action eq 'appearance') {
1.80 raeburn 823: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 824: } elsif ($action eq 'grading') {
1.127 raeburn 825: $output .= &print_grading($cdom,$cnum,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 826: } elsif ($action eq 'printouts') {
1.80 raeburn 827: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 828: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 829: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 830: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 831: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.118 raeburn 832: } elsif ($action eq 'ltitools') {
833: my $currtools = {};
834: if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
835: $currtools = $settings->{'ltitools'};
836: }
837: $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
1.87 raeburn 838: } elsif ($action eq 'lti') {
839: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 840: } elsif ($action eq 'menuitems') {
841: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 842: } elsif ($action eq 'linkprot') {
843: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 844: } elsif ($action eq 'other') {
1.80 raeburn 845: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 846: }
847: $output .= '
848: </table>
1.45 www 849: </td>
850: </tr>
851: </table><br />';
1.1 raeburn 852: return ($output,$rowtotal);
853: }
854:
855: sub process_changes {
1.108 raeburn 856: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 857: my (%newvalues,$errors);
1.3 raeburn 858: if (ref($item) eq 'HASH') {
859: if (ref($changes) eq 'HASH') {
860: my @ordered;
861: if ($action eq 'other') {
862: @ordered = &get_other_items($cdom,$values,$allitems);
863: if ($env{'form.newp_name'} ne '') {
864: my $newp = $env{'form.newp_name'};
865: if ($env{'form.newp_value'} ne '') {
866: if (ref($allitems) eq 'ARRAY') {
867: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
868: (grep(/^\Q$newp\E$/,@{$allitems}))) {
869: $changes->{$newp} = $env{'form.newp_value'};
870: }
871: }
872: }
873: }
1.118 raeburn 874: } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.99 raeburn 875: if (ref($values->{$action}) eq 'HASH') {
876: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 877: if ($id =~ /^\d+$/) {
878: push(@ordered,$id);
879: }
880: }
881: }
882: @ordered = sort { $a <=> $b } @ordered;
1.118 raeburn 883: if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
884: push(@ordered,$env{'form.'.$action.'_maxnum'});
1.93 raeburn 885: }
1.3 raeburn 886: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 887: if ($action eq 'courseinfo') {
888: my ($can_toggle_cat,$can_categorize) =
889: &can_modify_catsettings($cdom,$crstype);
890: foreach my $entry (@{$item->{'ordered'}}) {
891: next if (($entry eq 'hidefromcat') &&
892: (!$can_toggle_cat));
893: next if (($entry eq 'categories') &&
894: (!$can_categorize));
895: next if (($entry eq 'loncaparev') ||
1.63 raeburn 896: ($entry eq 'owner') ||
1.88 raeburn 897: ($entry eq 'clonedfrom') ||
898: ($entry eq 'syllabus'));
1.49 raeburn 899: push(@ordered,$entry);
900: }
1.55 raeburn 901: } elsif ($action eq 'classlists') {
902: foreach my $entry (@{$item->{'ordered'}}) {
903: next if ($entry eq 'defaultcredits');
904: push(@ordered,$entry);
905: }
1.49 raeburn 906: } else {
907: @ordered = @{$item->{'ordered'}};
908: }
1.3 raeburn 909: }
910: if (@ordered > 0) {
911: if ($action eq 'feedback') {
912: foreach my $entry (@ordered) {
913: my $userstr = '';
914: my $total = $env{'form.'.$entry.'_total'};
915: if ($total) {
916: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
917: for (my $i=0; $i<$total; $i++) {
918: unless (grep(/^$i$/,@deletes)) {
919: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
920: &get_sec_str($entry,$i).',';
921: }
922: }
923: } else {
924: $total = 0;
925: }
926: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
927: my $uname = $env{'form.'.$entry.'_uname_'.$total};
928: my $udom = $env{'form.'.$entry.'_udom_'.$total};
929: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
930: $userstr =~ s/,$//;
931: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
932: } else {
933: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
934: }
935: } else {
936: $userstr =~ s/,$//;
937: }
938: $newvalues{$entry} = $userstr;
939: if ($newvalues{$entry} ne $values->{$entry}) {
940: $changes->{$entry} = $newvalues{$entry};
941: }
942: my $ext_entry = $entry.'.text';
943: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
944: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
945: $changes->{$ext_entry} = $newvalues{$ext_entry};
946: }
947: }
1.91 raeburn 948: } elsif ($action eq 'menuitems') {
949: my (%current,@colls);
950: my $next = 1;
951: if ($values->{'menucollections'}) {
952: foreach my $item (split(/;/,$values->{'menucollections'})) {
953: my ($num,$value) = split(/\%/,$item);
954: if ($num =~ /^\d+$/) {
955: unless (grep(/^$num$/,@colls)) {
956: push(@colls,$num);
957: }
958: my @entries = split(/\&/,$value);
959: foreach my $entry (@entries) {
960: my ($name,$fields) = split(/=/,$entry);
961: $current{$num}{$name} = $fields;
962: }
963: }
964: }
965: }
966: if (@colls) {
967: @colls = sort { $a <=> $b } @colls;
968: $next += $colls[-1];
969: }
970: if ($env{'form.menucollections_add'} eq $next) {
971: push(@colls,$next);
972: }
973: my $currdef = $values->{'menudefault'};
974: my $possdef = $env{'form.menudefault'};
975: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 976: if ($currdef ne $possdef) {
1.91 raeburn 977: $changes->{'menudefault'} = $possdef;
978: }
1.92 raeburn 979: } elsif ($currdef) {
1.91 raeburn 980: $changes->{'menudefault'} = '';
981: }
982: my $menucoll;
983: if (@colls) {
984: my ($ordered,$cats) = &menuitems_categories();
985: my %shortcats = &menuitems_abbreviations();
986: foreach my $num (@colls) {
987: my ($entry,%include);
988: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
989: foreach my $item (@{$ordered}) {
990: if ($item eq 'shown') {
991: foreach my $type (@{$cats->{$item}}) {
992: $entry .= $type.'=';
993: if ($include{$type}) {
994: $entry .= 'y';
995: } else {
996: $entry .= 'n';
997: }
998: $entry .= '&';
999: }
1000: } else {
1001: $entry .= $shortcats{$item}.'=';
1002: foreach my $type (@{$cats->{$item}}) {
1003: if ($include{$type}) {
1004: $entry .= $type.',';
1005: }
1006: }
1007: $entry =~ s/,$//;
1008: $entry .= '&';
1009: }
1010: }
1011: $entry =~ s/\&$//;
1012: if ($menucoll) {
1013: $menucoll .= ';';
1014: }
1015: $menucoll .= $num.'%'.$entry;
1016: }
1017: if ($menucoll ne $values->{'menucollections'}) {
1018: $changes->{'menucollections'} = $menucoll;
1019: }
1020: } elsif ($values->{'menucollections'}) {
1021: $changes->{'menucollections'} = '';
1022: }
1.102 raeburn 1023: } elsif ($action eq 'linkprot') {
1024: if (ref($values) eq 'HASH') {
1.108 raeburn 1025: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 1026: }
1.118 raeburn 1027: } elsif ($action eq 'ltitools') {
1028: if (ref($values) eq 'HASH') {
1029: my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1030: $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1031: 'ok','','ok');
1032: }
1.3 raeburn 1033: } else {
1034: foreach my $entry (@ordered) {
1035: if ($entry eq 'cloners') {
1036: if ($env{'form.cloners_all'}) {
1037: $newvalues{$entry} = '*';
1038: } else {
1039: my @clonedoms;
1040: if (exists($env{'form.cloners_activate'})) {
1041: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1042: if ($actnum ne '-1') {
1.33 raeburn 1043: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1044: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1045: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1046: $newvalues{$entry} = '*:'.$clonedom;
1047: push(@clonedoms,$newvalues{$entry});
1048: }
1049: }
1050: }
1051: } else {
1052: my $num = $env{'form.cloners_total'};
1053: my @deletes =
1054: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1055: for (my $i=0; $i<$num; $i++) {
1056: if (!grep(/^$i$/,@deletes)) {
1057: my $clonedom = $env{'form.cloners_dom_'.$i};
1058: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1059: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1060: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1061: }
1062: }
1063: }
1064: }
1065: if (@clonedoms) {
1066: $newvalues{$entry}=join(',',@clonedoms);
1067: }
1068: }
1069: if ($env{'form.cloners_newdom'} ne '') {
1070: my $clonedom = $env{'form.cloners_newdom'};
1071: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1072: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1073: if (@clonedoms) {
1.3 raeburn 1074: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1075: $newvalues{$entry} .= ','.$newdom;
1076: }
1077: } else {
1078: $newvalues{$entry} = $newdom;
1079: }
1080: }
1081: }
1082: if ($env{'form.'.$entry} ne '') {
1083: my @cloners = split(',',$env{'form.'.$entry});
1084: my @okcloners;
1085: foreach my $cloner (@cloners) {
1.23 raeburn 1086: $cloner =~ s/^\s+//;
1087: $cloner =~ s/\s+$//;
1088: unless ($cloner eq '') {
1089: my ($uname,$udom) = split(':',$cloner);
1090: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1091: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1092: push(@okcloners,$cloner);
1093: }
1.3 raeburn 1094: }
1095: }
1096: }
1097: if (@okcloners) {
1098: my $okclonestr = join(',',@okcloners);
1099: if ($newvalues{$entry} ne '') {
1100: $newvalues{$entry} .= ','.$okclonestr;
1101: } else {
1102: $newvalues{$entry} = $okclonestr;
1103: }
1104: }
1105: }
1.71 raeburn 1106: if (ref($values) eq 'HASH') {
1107: my (@code_order,%codedefaults);
1108: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1109: \@code_order);
1110: my $clonebycode;
1111: if ($env{'form.cloners_instcode'}) {
1112: if (@code_order > 0) {
1113: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1114: my %local_to_standard;
1115: for (my $i=0; $i<@code_order; $i++) {
1116: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1117: }
1118: foreach my $item (@code_order) {
1119: my $key = $local_to_standard{$item};
1120: if ($key ne '') {
1121: if ($env{'form.'.$key}) {
1122: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1123: }
1124: }
1125: }
1126: $clonebycode =~ s/\&$//;
1127: }
1128: }
1129: if ($clonebycode) {
1130: if ($newvalues{$entry}) {
1131: $newvalues{$entry} .= ','.$clonebycode;
1132: } else {
1133: $newvalues{$entry} = $clonebycode;
1134: }
1135: }
1136: }
1.3 raeburn 1137: }
1138: if (ref($disallowed) eq 'HASH') {
1139: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1140: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1141: $disallowed->{'cloners'}{$key} =~ s/,$//;
1142: }
1143: }
1144: }
1.25 raeburn 1145: } elsif ($entry eq 'co-owners') {
1146: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1147: my $coowners = $values->{'internal.co-owners'};
1148: my @currcoown;
1149: if ($coowners) {
1150: @currcoown = split(',',$coowners);
1151: }
1152: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1153: my $autocoowner;
1154: if (($crstype eq 'Course') &&
1155: ($values->{'internal.coursecode'})) {
1156: my %domconf =
1157: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1158: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1159: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1160: }
1161: }
1.96 raeburn 1162: if ($autocoowner) {
1163: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1164: } else {
1.25 raeburn 1165: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1166: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1167: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1168: if (@invitecoowners) {
1169: push(@pendingcoowners,@invitecoowners);
1170: }
1171: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1172: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1173: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1174: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1175: push(@{$changes->{$entry}{'changed'}},'co-owners');
1176: }
1177: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1178: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1179: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1180: }
1181: }
1182: } else {
1183: my (@newpending,@newcoown);
1184: my $uname = $env{'user.name'};
1185: my $udom = $env{'user.domain'};
1186: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1187: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1188: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1189: foreach my $item (@pendingcoown) {
1190: unless ($item eq $uname.':'.$udom) {
1191: push(@newpending,$item);
1192: }
1193: }
1194: @newcoown = @currcoown;
1.90 raeburn 1195: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1196: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1197: push(@newcoown,$uname.':'.$udom);
1198: }
1199: }
1.90 raeburn 1200: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1201: foreach my $item (@currcoown) {
1202: unless ($item eq $uname.':'.$udom) {
1203: push(@newcoown,$item);
1204: }
1205: }
1206: if ($pendingcoowners ne '') {
1207: @newpending = @pendingcoown;
1208: }
1.96 raeburn 1209: } else {
1210: @newcoown = @currcoown;
1.25 raeburn 1211: }
1212: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1213: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1214: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1215: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1216: push(@{$changes->{$entry}{'changed'}},'co-owners');
1217: }
1218: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1219: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1220: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1221: }
1222: }
1.3 raeburn 1223: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1224: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1225: } elsif ($entry eq 'rolenames') {
1226: my %adv_roles =
1227: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1228: my @stds;
1229: if ($crstype eq 'Community') {
1230: @stds = ('co');
1231: } else {
1232: @stds = ('cc');
1233: }
1234: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1235: my (@replacements,@regulars);
1236: foreach my $role (@stds) {
1237: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1238: push(@replacements,$role);
1.3 raeburn 1239: } else {
1240: push(@regulars,$role);
1241: }
1.9 raeburn 1242: }
1.3 raeburn 1243: foreach my $stdrole (@stds) {
1244: my $ext_entry = $entry.'_'.$stdrole;
1245: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1246: $env{'request.course.id'},1);
1247: if ($env{'form.'.$ext_entry} eq $stdname) {
1248: $newvalues{$ext_entry} = '';
1249: } else {
1250: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1251: }
1252: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1253: my $dupname = 0;
1254: if ($newvalues{$ext_entry} ne '') {
1255: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1256: $dupname = 1;
1257: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1258: }
1259: if (!$dupname) {
1260: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1261: $dupname = 1;
1262: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1263: }
1264: }
1265: if (!$dupname) {
1266: foreach my $role (keys(%adv_roles)) {
1267: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1268: $dupname = 1;
1269: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1270: last;
1271: }
1272: }
1273: }
1274: }
1275: if (!$dupname) {
1276: $changes->{$ext_entry} = $newvalues{$ext_entry};
1277: }
1278: }
1279: }
1.77 raeburn 1280: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1281: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1282: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1283: @denied = sort(@denied);
1284: my $deniedstr = '';
1285: if (@denied > 0) {
1286: $deniedstr = join(',',@denied);
1287: }
1288: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1289: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1290: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1291: my $total = $env{'form.'.$entry.'_total'};
1292: my $userstr = '';
1293: my @denied;
1294: if ($total > 0) {
1295: my @deletes =
1296: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1297: for (my $i=0; $i<$total; $i++) {
1298: unless (grep(/^$i$/,@deletes)) {
1299: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1300: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1301: }
1302: }
1303: } else {
1304: $total = 0;
1305: }
1306: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1307: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1308: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1309: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1310: $userstr =~ s/,$//;
1311: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1312: } else {
1313: my $newuser .= $uname.':'.$udom;
1314: if (grep(/^\Q$newuser\E$/,@denied)) {
1315: $userstr =~ s/,$//;
1316: } else {
1317: $userstr .= $newuser;
1318: }
1319: }
1320: } else {
1321: $userstr =~ s/,$//;
1322: }
1323: $newvalues{$entry} = $userstr;
1324: } elsif ($entry eq 'allow_discussion_post_editing') {
1325: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1326: @canedit = sort(@canedit);
1327: foreach my $role (@canedit) {
1328: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1329: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1330: $newvalues{$entry} .= $role.',';
1331: } else {
1332: foreach my $sec (@secs) {
1333: $newvalues{$entry} .= $role.':'.$sec.',';
1334: }
1335: }
1336: }
1337: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1338: } elsif ($entry eq 'discussion_post_fonts') {
1339: my ($classorder,$classtitles) = &discussion_vote_classes();
1340: my $fontchange = 0;
1341: foreach my $class (@{$classorder}) {
1.124 raeburn 1342: my $ext_entry = $entry.'_'.$class;
1.50 raeburn 1343: my $size = $env{'form.'.$ext_entry.'_size'};
1344: my $unit = $env{'form.'.$ext_entry.'_unit'};
1345: my $weight = $env{'form.'.$ext_entry.'_weight'};
1346: my $style = $env{'form.'.$ext_entry.'_style'};
1347: my $other = $env{'form.'.$ext_entry.'_other'};
1348: $size =~ s/,//g;
1.124 raeburn 1349: $unit =~ s/,//g;
1.50 raeburn 1350: $weight =~ s/,//g;
1351: $style =~ s/,//g;
1352: $other =~ s/[^\w;:\s\-\%.]//g;
1353: $other =~ s/(^\s+|\s+$)//g;
1354: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1355: my $current = $values->{$ext_entry};
1356: if ($values->{$ext_entry} eq '') {
1.124 raeburn 1357: $current = ',,,';
1.50 raeburn 1358: }
1359: if ($newvalues{$ext_entry} ne $current) {
1360: $changes->{$ext_entry} = $newvalues{$ext_entry};
1361: $fontchange ++;
1362: }
1363: }
1364: if ($fontchange) {
1365: $changes->{$entry} = 1;
1.124 raeburn 1366: }
1.3 raeburn 1367: } elsif ($entry eq 'nothideprivileged') {
1368: my @curr_nothide;
1369: my @new_nothide;
1370: if ($values->{$entry} ne '') {
1371: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1372: my $nothide;
1373: if ($user !~ /:/) {
1374: $nothide = join(':',split(/[\@]/,$user));
1375: } else {
1376: $nothide = $user;
1377: }
1378: if ((defined($nothide)) &&
1379: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1380: push(@curr_nothide,$nothide);
1381: }
1382: }
1383: }
1384: foreach my $key (keys(%env)) {
1385: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1386: if ($env{$key}) {
1.3 raeburn 1387: my $nothide = $1;
1388: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1389: push(@new_nothide,$nothide);
1390: }
1391: }
1392: }
1393: }
1394: @new_nothide = sort(@new_nothide);
1395: my @differences =
1396: &Apache::loncommon::compare_arrays(\@curr_nothide,
1397: \@new_nothide);
1398: if (@differences > 0) {
1399: if (@new_nothide > 0) {
1400: $newvalues{$entry} = join(',',@new_nothide);
1401: } else {
1402: $newvalues{$entry} = '';
1403: }
1404: } else {
1405: $newvalues{$entry} = $values->{$entry};
1406: }
1407: } elsif ($entry eq 'print_header_format') {
1408: my $maxnum = $env{'form.printfmthdr_maxnum'};
1409: my @newhdr;
1410: if ($maxnum > 2) {
1411: for (my $i=0; $i<$maxnum-2; $i++) {
1412: if ($env{'form.printfmthdr_del_'.$i}) {
1413: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1414: } else {
1415: my $hdr;
1416: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1417: $hdr = '%';
1418: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1419: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1420: }
1421: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1422: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1423: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1424: }
1425: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1426: }
1427: }
1428: }
1429: my $newsub = $maxnum-2;
1430: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1431: my $hdr = '%';
1432: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1433: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1434: }
1435: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1436: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1437: }
1438: my $newtext = $maxnum-1;
1439: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1440: $newvalues{$entry} = join('',@newhdr);
1.124 raeburn 1441: } elsif (($entry eq 'languages') ||
1.56 raeburn 1442: ($entry eq 'checkforpriv')) {
1443: my $settings;
1.3 raeburn 1444: my $total = $env{'form.'.$entry.'_total'};
1445: if ($total) {
1446: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1447: for (my $i=0; $i<$total; $i++) {
1448: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1449: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1450: }
1451: }
1452: } else {
1453: $total = 0;
1454: }
1455: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1456: my $new = $env{'form.'.$entry.'_'.$total};
1.124 raeburn 1457: if ($entry eq 'languages') {
1.56 raeburn 1458: my %langchoices = &get_lang_choices();
1459: if ($langchoices{$new}) {
1460: $settings .= $new;
1461: } else {
1462: $settings =~ s/,$//;
1463: $disallowed->{'localization'}{$entry} = $new;
1464: }
1.3 raeburn 1465: } else {
1.56 raeburn 1466: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1467: if ($domains{$new}) {
1468: $settings .= $new;
1469: } else {
1470: $settings =~ s/,$//;
1471: $disallowed->{'classlists'}{$entry} = $new;
1472: }
1.3 raeburn 1473: }
1474: } else {
1.56 raeburn 1475: $settings =~ s/,$//;
1.3 raeburn 1476: }
1.56 raeburn 1477: $newvalues{$entry} = $settings;
1.87 raeburn 1478: } elsif ($action eq 'lti') {
1479: if ($entry eq 'lti.override') {
1480: $newvalues{$entry} = $env{'form.'.$entry};
1481: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1482: if ($env{'form.lti.override'}) {
1483: $newvalues{$entry} = $env{'form.'.$entry};
1484: } else {
1485: $newvalues{$entry} = '';
1486: }
1487: } elsif ($entry eq 'lti.lcmenu') {
1488: if (($env{'form.lti.override'}) &&
1489: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1490: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1491: my @newlcmenu;
1492: if (@lcmenu) {
1493: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1494: foreach my $item (@menuitems) {
1495: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1496: if (grep(/^\Q$item\E$/,@lcmenu)) {
1497: push(@newlcmenu,$item);
1498: }
1499: }
1500: }
1501: if (@newlcmenu) {
1502: $newvalues{$entry} = join(',',@newlcmenu);
1503: } else {
1504: $newvalues{$entry} = 'none';
1505: }
1506: } else {
1507: $newvalues{$entry} = '';
1508: }
1509: }
1.114 raeburn 1510: } elsif ($entry eq 'extresource') {
1511: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1512: $newvalues{$entry} = $env{'form.'.$entry};
1513: if ($env{'form.'.$entry} ne 'iframe') {
1514: if ($env{'form.extwintabreuse'}) {
1515: $newvalues{$entry} .= ':1';
1516: } else {
1517: $newvalues{$entry} .= ':0';
1518: }
1519: if ($env{'form.'.$entry} eq 'window') {
1520: foreach my $dim ('width','height') {
1521: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1522: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1523: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1524: } else {
1525: $newvalues{$entry} .= ':';
1526: }
1527: }
1528: }
1529: }
1530: }
1531: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1532: if ($newvalues{$entry} ne $values->{$entry}) {
1533: $changes->{$entry} = $newvalues{$entry};
1534: }
1535: }
1.115 raeburn 1536: } elsif ($entry eq 'timezone') {
1537: if ($env{'form.'.$entry}) {
1538: $newvalues{$entry} = $env{'form.'.$entry};
1539: if ($newvalues{$entry} ne $values->{$entry}) {
1540: $changes->{$entry} = $newvalues{$entry};
1541: }
1542: if ($env{'form.tzover'}) {
1543: $newvalues{'tzover'} = $env{'form.tzover'};
1544: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1545: $changes->{'tzover'} = $newvalues{'tzover'};
1546: }
1547: } elsif ($values->{'tzover'}) {
1548: $changes->{'tzover'} = '';
1549: }
1550: } elsif ($values->{$entry}) {
1551: $changes->{$entry} = '';
1552: }
1.127 raeburn 1553: } elsif ($entry eq 'grading') {
1554: if ($env{'form.'.$entry} eq 'standard') {
1555: if ($env{'form.hidetotals'}) {
1556: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1557: if (keys(%sections)) {
1558: my @secs = &Apache::loncommon::get_env_multiple('form.hidetotals_sections');
1559: if (grep(/^all$/,@secs)) {
1560: $newvalues{'hidetotals'} = 'all';
1561: } elsif (@secs) {
1562: $newvalues{'hidetotals'} = '';
1563: foreach my $sec (sort {$a <=> $b} @secs) {
1564: if (exists($sections{$sec})) {
1565: $newvalues{'hidetotals'} .= $sec.','
1566: }
1567: }
1568: $newvalues{'hidetotals'} =~ s/,$//;
1569: }
1570: } else {
1571: $newvalues{'hidetotals'} = 'all';
1572: }
1573: }
1574: }
1575: if ($newvalues{'hidetotals'} ne $values->{'hidetotals'}) {
1576: $changes->{'hidetotals'} = $newvalues{'hidetotals'};
1577: $changes->{'grading'} = $env{'form.'.$entry};
1578: }
1579: $newvalues{$entry} = $env{'form.'.$entry};
1.3 raeburn 1580: } else {
1581: $newvalues{$entry} = $env{'form.'.$entry};
1582: }
1.124 raeburn 1583: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1.115 raeburn 1584: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1585: if ($newvalues{$entry} ne $values->{$entry}) {
1586: $changes->{$entry} = $newvalues{$entry};
1587: }
1.3 raeburn 1588: }
1589: }
1590: }
1591: }
1592: }
1593: }
1.93 raeburn 1594: return $errors;
1595: }
1596:
1.102 raeburn 1597: sub process_linkprot {
1.108 raeburn 1598: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.118 raeburn 1599: my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1600: if (ref($values) eq 'HASH') {
1601: foreach my $id (keys(%{$values})) {
1602: if ($id =~ /^\d+$/) {
1603: unless (ref($values->{$id}) eq 'HASH') {
1604: $linkprot{$id} = '';
1605: }
1606: }
1607: }
1608: }
1.118 raeburn 1609: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.102 raeburn 1610: if ($context eq 'domain') {
1611: $dest = '/adm/domainprefs';
1612: $ltiauth = 1;
1613: } else {
1614: $dest = '/adm/courseprefs';
1615: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1616: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1617: } else {
1618: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1619: $ltiauth = $domdefs{'crsltiauth'};
1620: }
1621: }
1622: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1623: my (@items,%deletions,%itemids,%haschanges);
1624: if ($env{'form.linkprot_add'}) {
1625: my $name = $env{'form.linkprot_name_add'};
1626: $name =~ s/(`)/'/g;
1627: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1628: if ($newid) {
1629: $itemids{'add'} = $newid;
1630: push(@items,'add');
1631: $haschanges{$newid} = 1;
1632: } else {
1633: $errors .= '<span class="LC_error">'.
1634: &mt('Failed to acquire unique ID for link protection').
1635: '</span>';
1636: }
1637: }
1638: if (ref($values) eq 'HASH') {
1639: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1640: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1641: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1642: my $itemid = $env{'form.linkprot_id_'.$i};
1643: $itemid =~ s/\D+//g;
1644: if ($itemid) {
1645: if (ref($values->{$itemid}) eq 'HASH') {
1646: push(@items,$i);
1647: $itemids{$i} = $itemid;
1648: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1649: $deletions{$itemid} = $values->{$itemid}->{'name'};
1650: }
1651: }
1652: }
1653: }
1654: }
1655: foreach my $idx (@items) {
1656: my $itemid = $itemids{$idx};
1657: next unless ($itemid);
1658: if (exists($deletions{$itemid})) {
1659: $linkprot{$itemid} = $deletions{$itemid};
1660: $haschanges{$itemid} = 1;
1661: next;
1662: }
1663: my %current;
1664: if (ref($values) eq 'HASH') {
1665: if (ref($values->{$itemid}) eq 'HASH') {
1666: foreach my $key (keys(%{$values->{$itemid}})) {
1667: $current{$key} = $values->{$itemid}->{$key};
1668: }
1669: }
1670: }
1671: foreach my $inner ('name','lifetime','version') {
1672: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1673: $env{$formitem} =~ s/(`)/'/g;
1674: if ($inner eq 'lifetime') {
1675: $env{$formitem} =~ s/[^\d.]//g;
1676: }
1677: unless ($idx eq 'add') {
1678: if ($current{$inner} ne $env{$formitem}) {
1679: $haschanges{$itemid} = 1;
1680: }
1681: }
1682: if ($env{$formitem} ne '') {
1683: $linkprot{$itemid}{$inner} = $env{$formitem};
1684: }
1685: }
1.112 raeburn 1686: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1687: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1688: if ($env{$urlitem} == 1) {
1689: $env{$urlparamname} =~ s/(`)/'/g;
1690: } elsif (exists($env{$urlparamname})) {
1691: $env{$urlparamname} = '';
1692: }
1.122 raeburn 1693: my $passback = 'form.linkprot_passback_'.$idx;
1694: my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
1695: if ($env{$passback} == 1) {
1696: unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
1697: $env{$passbackparamname} = '';
1698: }
1699: } elsif (exists($env{$passbackparamname})) {
1700: $env{$passbackparamname} = '';
1701: }
1.112 raeburn 1702: unless ($idx eq 'add') {
1703: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1704: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1705: $haschanges{$itemid} = 1;
1706: }
1.122 raeburn 1707: if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
1708: ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
1709: $haschanges{$itemid} = 1;
1710: }
1.112 raeburn 1711: }
1.123 raeburn 1712: if ($env{$urlparamname} ne '') {
1713: $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1714: }
1.122 raeburn 1715: if ($env{$passbackparamname} ne '') {
1716: $linkprot{$itemid}{'passback'} = 1;
1717: $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1.112 raeburn 1718: }
1.102 raeburn 1719: if ($ltiauth) {
1720: my $reqitem = 'form.linkprot_requser_'.$idx;
1721: $env{$reqitem} =~ s/(`)/'/g;
1722: unless ($idx eq 'add') {
1.104 raeburn 1723: if ((!$current{'requser'} && $env{$reqitem}) ||
1724: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1725: $haschanges{$itemid} = 1;
1726: }
1727: }
1728: if ($env{$reqitem} == 1) {
1729: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1730: foreach my $inner ('mapuser','notstudent') {
1731: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1732: $env{$formitem} =~ s/(`)/'/g;
1733: if ($inner eq 'mapuser') {
1734: if ($env{$formitem} eq 'other') {
1735: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1736: $mapuser =~ s/(`)/'/g;
1737: $mapuser =~ s/^\s+|\s+$//g;
1738: if ($mapuser ne '') {
1739: $linkprot{$itemid}{$inner} = $mapuser;
1740: } else {
1741: delete($linkprot{$itemid}{'requser'});
1742: last;
1743: }
1744: } elsif ($env{$formitem} eq 'sourcedid') {
1745: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1746: } elsif ($env{$formitem} eq 'email') {
1747: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1748: }
1749: } else {
1750: $linkprot{$itemid}{$inner} = $env{$formitem};
1751: }
1752: unless ($idx eq 'add') {
1753: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1754: $haschanges{$itemid} = 1;
1755: }
1756: }
1757: }
1758: }
1759: }
1760: unless ($switchserver) {
1761: my $keyitem = 'form.linkprot_key_'.$idx;
1762: $env{$keyitem} =~ s/(`)/'/g;
1763: unless ($idx eq 'add') {
1764: if ($current{'key'} ne $env{$keyitem}) {
1765: $haschanges{$itemid} = 1;
1766: }
1767: }
1768: if ($env{$keyitem} ne '') {
1769: $linkprot{$itemid}{'key'} = $env{$keyitem};
1770: }
1771: my $secretitem = 'form.linkprot_secret_'.$idx;
1772: $env{$secretitem} =~ s/(`)/'/g;
1773: if ($current{'usable'}) {
1774: if ($env{'form.linkprot_changesecret_'.$idx}) {
1775: if ($env{$secretitem} ne '') {
1.103 raeburn 1776: if ($privnum && $cipher) {
1777: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1778: $linkprot{$itemid}{'cipher'} = $privnum;
1779: } else {
1780: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1781: }
1.102 raeburn 1782: $haschanges{$itemid} = 1;
1783: }
1784: } else {
1785: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1786: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1787: }
1788: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1789: if ($privnum && $cipher) {
1790: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1791: $linkprot{$itemid}{'cipher'} = $privnum;
1792: } else {
1793: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1794: }
1.102 raeburn 1795: $haschanges{$itemid} = 1;
1796: }
1797: }
1798: }
1799: if (keys(%haschanges)) {
1800: foreach my $entry (keys(%haschanges)) {
1801: $changes->{$entry} = $linkprot{$entry};
1802: }
1.108 raeburn 1803: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1804: $lastactref->{'courselti'} = 1;
1.108 raeburn 1805: }
1.102 raeburn 1806: }
1807: return $errors;
1808: }
1809:
1810: sub get_linkprot_id {
1811: my ($cdom,$cnum,$name,$context) = @_;
1812: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1813: my $lockhash = {
1814: lock => $env{'user.name'}.
1815: ':'.$env{'user.domain'},
1816: };
1817: my $tries = 0;
1.102 raeburn 1818: my $gotlock;
1819: if ($context eq 'domain') {
1820: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1821: } else {
1822: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1823: }
1.93 raeburn 1824: my ($id,$error);
1825: while (($gotlock ne 'ok') && ($tries<10)) {
1826: $tries ++;
1827: sleep (0.1);
1.102 raeburn 1828: if ($context eq 'domain') {
1.124 raeburn 1829: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1.102 raeburn 1830: } else {
1831: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1832: }
1.93 raeburn 1833: }
1834: if ($gotlock eq 'ok') {
1.102 raeburn 1835: my %currids;
1836: if ($context eq 'domain') {
1837: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1838: } else {
1839: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1840: }
1.93 raeburn 1841: if ($currids{'lock'}) {
1842: delete($currids{'lock'});
1843: if (keys(%currids)) {
1844: my @curr = sort { $a <=> $b } keys(%currids);
1845: if ($curr[-1] =~ /^\d+$/) {
1846: $id = 1 + $curr[-1];
1847: } else {
1848: $id = 1;
1849: }
1850: } else {
1851: $id = 1;
1852: }
1853: if ($id) {
1.102 raeburn 1854: if ($context eq 'domain') {
1855: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1856: $error = 'nostore';
1857: }
1858: } else {
1859: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1860: $error = 'nostore';
1861: }
1.93 raeburn 1862: }
1863: } else {
1864: $error = 'nonumber';
1865: }
1866: }
1.124 raeburn 1867: my $dellockoutcome;
1.102 raeburn 1868: if ($context eq 'domain') {
1869: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1870: } else {
1871: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1872: }
1.93 raeburn 1873: } else {
1874: $error = 'nolock';
1875: }
1876: return ($id,$error);
1.3 raeburn 1877: }
1878:
1.118 raeburn 1879: sub get_credentials {
1880: my ($cdom,$cnum,$type,$context) = @_;
1881: my ($cipher,$privnum,$home);
1882: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1883: my @ids=&Apache::lonnet::current_machine_ids();
1884: if ($context eq 'domain') {
1885: $home = &Apache::lonnet::domain($cdom,'primary');
1886: } else {
1887: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1888: }
1889: my ($hostskey,$domkey,$crskey);
1890: if ($type eq 'ltitools') {
1891: $hostskey = 'toolprivhosts';
1892: $domkey = 'toolenc_dom';
1893: $crskey = 'toolenc_crs';
1894: } else {
1895: $hostskey = 'ltiprivhosts';
1896: $domkey = 'linkprotenc_dom';
1897: $crskey = 'linkprotenc_crs';
1898: }
1899: if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1900: (($context eq 'course') && ($domdefs{$crskey}))) {
1901: unless (($home eq 'no_host') || ($home eq '')) {
1902: if (grep(/^\Q$home\E$/,@ids)) {
1903: if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1904: if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1905: my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1906: my $privkey = $privhash{'key'};
1907: $privnum = $privhash{'version'};
1908: if (($privnum) && ($privkey ne '')) {
1909: $cipher = Crypt::CBC->new({'key' => $privkey,
1910: 'cipher' => 'DES'});
1911: }
1912: }
1913: }
1914: }
1915: }
1916: }
1917: return ($cipher,$privnum);
1918: }
1919:
1920: sub process_ltitools {
1921: my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1922: $author_ok,$confname) = @_;
1923: my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1924:
1925: my (%posslti,%possfield);
1926: my @courseroles = ('cc','in','ta','ep','st');
1927: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1928: map { $posslti{$_} = 1; } @ltiroles;
1929: my @allfields = ('fullname','firstname','lastname','email','user','roles');
1930: map { $possfield{$_} = 1; } @allfields;
1931:
1.120 raeburn 1932: my ($dest,$privnum,$cipher);
1.118 raeburn 1933:
1934: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1935: if ($context eq 'domain') {
1936: $dest = '/adm/domainprefs';
1937: } else {
1938: $dest = '/adm/courseprefs';
1939: }
1940: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1941:
1942: my (@allpos,@items,%deletions,%itemids,%haschanges);
1943: if ($env{'form.ltitools_add'}) {
1944: my $title = $env{'form.ltitools_add_title'};
1945: $title =~ s/(`)/'/g;
1.125 raeburn 1946: my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
1.118 raeburn 1947: if ($newid) {
1948: my $position = $env{'form.ltitools_add_pos'};
1949: $position =~ s/\D+//g;
1950: if ($position ne '') {
1951: $allpos[$position] = $newid;
1952: }
1953: $haschanges{$newid} = 1;
1954: foreach my $item ('title','url','lifetime') {
1955: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1956: if ($item eq 'lifetime') {
1957: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1958: }
1959: if ($env{'form.ltitools_add_'.$item}) {
1960: $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1961: }
1962: }
1963: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1964: $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1965: }
1966: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1967: $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1968: }
1969: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1970: $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1971: } else {
1972: $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1973: }
1974: foreach my $item ('width','height','linktext','explanation') {
1975: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1976: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1977: if (($item eq 'width') || ($item eq 'height')) {
1978: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1979: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1980: }
1981: } else {
1982: if ($env{'form.ltitools_add_'.$item} ne '') {
1983: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1984: }
1985: }
1986: }
1987: if ($env{'form.ltitools_add_target'} eq 'window') {
1988: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1989: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1990: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1991: } else {
1992: $ltitools{$newid}{'display'}{'target'} = 'iframe';
1993: }
1994: foreach my $item ('passback','roster') {
1995: if ($env{'form.ltitools_'.$item.'_add'}) {
1996: $ltitools{$newid}{$item} = 1;
1997: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1998: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1999: $lifetime =~ s/^\s+|\s+$//g;
2000: if ($lifetime =~ /^\d+\.?\d*$/) {
2001: $ltitools{$newid}{$item.'valid'} = $lifetime;
2002: }
2003: }
2004: }
2005: }
2006: if ($env{'form.ltitools_add_image.filename'} ne '') {
2007: my ($imageurl,$error) =
2008: &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
2009: $newid,$configuserok,$lonhost,$author_ok);
2010: if ($imageurl) {
2011: $ltitools{$newid}{'image'} = $imageurl;
2012: }
2013: if ($error) {
2014: &Apache::lonnet::logthis($error);
2015: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2016: }
2017: }
2018: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
2019: foreach my $field (@fields) {
2020: if ($possfield{$field}) {
2021: if ($field eq 'roles') {
2022: foreach my $role (@courseroles) {
2023: my $choice = $env{'form.ltitools_add_roles_'.$role};
2024: if (($choice ne '') && ($posslti{$choice})) {
2025: $ltitools{$newid}{'roles'}{$role} = $choice;
2026: if ($role eq 'cc') {
2027: $ltitools{$newid}{'roles'}{'co'} = $choice;
2028: }
2029: }
2030: }
2031: } else {
2032: $ltitools{$newid}{'fields'}{$field} = 1;
2033: }
2034: }
2035: }
2036: if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
2037: if ($ltitools{$newid}{'fields'}{'user'}) {
2038: if ($env{'form.ltitools_add_userincdom'}) {
2039: $ltitools{$newid}{'incdom'} = 1;
2040: }
2041: }
2042: }
2043: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
2044: foreach my $item (@courseconfig) {
2045: $ltitools{$newid}{'crsconf'}{$item} = 1;
2046: }
2047: if ($env{'form.ltitools_add_custom'}) {
2048: my $name = $env{'form.ltitools_add_custom_name'};
2049: my $value = $env{'form.ltitools_add_custom_value'};
2050: $value =~ s/(`)/'/g;
2051: $name =~ s/(`)/'/g;
2052: $ltitools{$newid}{'custom'}{$name} = $value;
2053: }
2054: unless ($switchserver) {
2055: my $keyitem = 'form.ltitools_add_key';
2056: $env{$keyitem} =~ s/(`)/'/g;
2057: if ($env{$keyitem} ne '') {
2058: $ltitools{$newid}{'key'} = $env{$keyitem};
2059: }
1.119 raeburn 2060: my $secretitem = 'form.ltitools_secret_add';
1.118 raeburn 2061: $env{$secretitem} =~ s/(`)/'/g;
2062: if ($env{$secretitem} ne '') {
2063: if ($privnum && $cipher) {
2064: $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2065: $ltitools{$newid}{'cipher'} = $privnum;
2066: } else {
2067: $ltitools{$newid}{'secret'} = $env{$secretitem};
2068: }
2069: }
2070: }
2071: } else {
2072: $errors .= '<li><span class="LC_error">'.
2073: &mt('Failed to acquire unique ID for new external tool').
2074: '</span></li>';
2075: }
2076: }
2077: if (ref($values) eq 'HASH') {
2078: my %deletions;
2079: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2080: if (@todelete) {
2081: map { $deletions{$_} = 1; } @todelete;
2082: }
2083: my %customadds;
2084: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2085: if (@newcustom) {
2086: map { $customadds{$_} = 1; } @newcustom;
2087: }
2088: my %imgdeletions;
2089: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2090: if (@todeleteimages) {
2091: map { $imgdeletions{$_} = 1; } @todeleteimages;
2092: }
2093: my $maxnum = $env{'form.ltitools_maxnum'};
2094: for (my $i=0; $i<=$maxnum; $i++) {
2095: my $itemid = $env{'form.ltitools_id_'.$i};
2096: $itemid =~ s/\D+//g;
2097: if (ref($values->{$itemid}) eq 'HASH') {
2098: if ($deletions{$itemid}) {
2099: if ($values->{$itemid}{'image'}) {
2100: #FIXME need to obsolete item in RES space
2101: }
2102: $haschanges{$itemid} = $values->{$itemid}{'title'};
2103: next;
2104: } else {
2105: my $newpos = $env{'form.ltitools_'.$itemid};
2106: $newpos =~ s/\D+//g;
2107: foreach my $item ('title','url','lifetime') {
2108: $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2109: if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2110: $haschanges{$itemid} = 1;
2111: }
2112: }
2113: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2114: $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2115: }
2116: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2117: $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2118: }
2119: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2120: $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2121: } else {
2122: $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2123: }
2124: if ($values->{$itemid}{'sigmethod'} eq '') {
2125: if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2126: $haschanges{$itemid} = 1;
2127: }
2128: } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2129: $haschanges{$itemid} = 1;
2130: }
2131: foreach my $size ('width','height') {
2132: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2133: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2134: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2135: $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2136: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2137: if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2138: $haschanges{$itemid} = 1;
2139: }
2140: } else {
2141: $haschanges{$itemid} = 1;
2142: }
2143: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2144: if ($values->{$itemid}{'display'}{$size} ne '') {
2145: $haschanges{$itemid} = 1;
2146: }
2147: }
2148: }
2149: foreach my $item ('linktext','explanation') {
2150: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2151: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2152: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2153: $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2154: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2155: if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2156: $haschanges{$itemid} = 1;
2157: }
2158: } else {
2159: $haschanges{$itemid} = 1;
2160: }
2161: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2162: if ($values->{$itemid}{'display'}{$item} ne '') {
2163: $haschanges{$itemid} = 1;
2164: }
2165: }
2166: }
2167: if ($env{'form.ltitools_target_'.$i} eq 'window') {
2168: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2169: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2170: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2171: } else {
2172: $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2173: }
2174: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2175: if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2176: $haschanges{$itemid} = 1;
2177: }
2178: } else {
2179: $haschanges{$itemid} = 1;
2180: }
2181: foreach my $extra ('passback','roster') {
2182: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2183: $ltitools{$itemid}{$extra} = 1;
2184: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2185: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2186: $lifetime =~ s/^\s+|\s+$//g;
2187: if ($lifetime =~ /^\d+\.?\d*$/) {
2188: $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2189: }
2190: }
2191: }
2192: if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2193: $haschanges{$itemid} = 1;
2194: }
2195: if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2196: $haschanges{$itemid} = 1;
2197: }
2198: }
2199: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2200: foreach my $item ('label','title','target','linktext','explanation','append') {
2201: if (grep(/^\Q$item\E$/,@courseconfig)) {
2202: $ltitools{$itemid}{'crsconf'}{$item} = 1;
2203: if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2204: if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2205: $haschanges{$itemid} = 1;
2206: }
2207: } else {
2208: $haschanges{$itemid} = 1;
2209: }
2210: }
2211: }
2212: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2213: foreach my $field (@fields) {
2214: if ($possfield{$field}) {
2215: if ($field eq 'roles') {
2216: foreach my $role (@courseroles) {
2217: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2218: if (($choice ne '') && ($posslti{$choice})) {
2219: $ltitools{$itemid}{'roles'}{$role} = $choice;
2220: if ($role eq 'cc') {
2221: $ltitools{$itemid}{'roles'}{'co'} = $choice;
2222: }
2223: }
2224: if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2225: if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2226: $haschanges{$itemid} = 1;
2227: }
2228: } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2229: $haschanges{$itemid} = 1;
2230: }
2231: }
2232: } else {
2233: $ltitools{$itemid}{'fields'}{$field} = 1;
2234: if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2235: if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2236: $haschanges{$itemid} = 1;
2237: }
2238: } else {
2239: $haschanges{$itemid} = 1;
2240: }
2241: }
2242: }
2243: }
2244: if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2245: if ($ltitools{$itemid}{'fields'}{'user'}) {
2246: if ($env{'form.ltitools_userincdom_'.$i}) {
2247: $ltitools{$itemid}{'incdom'} = 1;
2248: }
2249: if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2250: $haschanges{$itemid} = 1;
2251: }
2252: }
2253: }
2254: $allpos[$newpos] = $itemid;
2255: }
2256: if ($imgdeletions{$itemid}) {
2257: $haschanges{$itemid} = 1;
2258: if ($context eq 'course') {
2259: my $currimgurl = $values->{$itemid}{'image'};
2260: if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2261: my ($path,$imagefile) = ($1,$2);
2262: if ($imagefile =~ /^tn\-(.+)$/) {
2263: my $origimg = $1;
2264: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2265: }
2266: &Apache::lonnet::removeuploadedurl($currimgurl);
2267: }
2268: }
2269: #FIXME need to obsolete item in RES space
2270: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2271: my $currimgurl = $values->{$itemid}{'image'};
2272: my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2273: $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2274: if ($imgurl) {
2275: $ltitools{$itemid}{'image'} = $imgurl;
2276: $haschanges{$itemid} = 1;
2277: }
2278: if ($error) {
2279: &Apache::lonnet::logthis($error);
2280: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2281: }
2282: } elsif ($values->{$itemid}{'image'}) {
2283: $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2284: }
2285: if ($customadds{$i}) {
2286: my $name = $env{'form.ltitools_custom_name_'.$i};
2287: $name =~ s/(`)/'/g;
2288: $name =~ s/^\s+//;
2289: $name =~ s/\s+$//;
2290: my $value = $env{'form.ltitools_custom_value_'.$i};
2291: $value =~ s/(`)/'/g;
2292: $value =~ s/^\s+//;
2293: $value =~ s/\s+$//;
2294: if ($name ne '') {
2295: $ltitools{$itemid}{'custom'}{$name} = $value;
2296: $haschanges{$itemid} = 1;
2297: }
2298: }
2299: my %customdels;
2300: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2301: if (@customdeletions) {
2302: $haschanges{$itemid} = 1;
2303: }
2304: map { $customdels{$_} = 1; } @customdeletions;
2305: if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2306: foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2307: unless ($customdels{$key}) {
2308: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2309: $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2310: }
2311: if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2312: $haschanges{$itemid} = 1;
2313: }
2314: }
2315: }
2316: }
2317: unless ($switchserver) {
2318: my $keyitem = 'form.ltitools_key_'.$i;
2319: $env{$keyitem} =~ s/(`)/'/g;
2320: if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2321: $haschanges{$itemid} = 1;
2322: }
2323: if ($env{$keyitem} ne '') {
2324: $ltitools{$itemid}{'key'} = $env{$keyitem};
2325: }
2326: my $secretitem = 'form.ltitools_secret_'.$i;
2327: $env{$secretitem} =~ s/(`)/'/g;
2328: if ($values->{$itemid}{'usable'}) {
2329: if ($env{'form.ltitools_changesecret_'.$i}) {
2330: if ($env{$secretitem} ne '') {
2331: if ($privnum && $cipher) {
2332: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2333: $ltitools{$itemid}{'cipher'} = $privnum;
2334: } else {
2335: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2336: }
2337: $haschanges{$itemid} = 1;
2338: }
2339: } else {
2340: $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2341: $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2342: }
2343: } elsif ($env{$secretitem} ne '') {
2344: if ($privnum && $cipher) {
2345: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2346: $ltitools{$itemid}{'cipher'} = $privnum;
2347: } else {
2348: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2349: }
2350: $haschanges{$itemid} = 1;
2351: }
2352: }
2353: unless ($haschanges{$itemid}) {
2354: foreach my $key (keys(%{$values->{$itemid}})) {
2355: if (ref($values->{$itemid}{$key}) eq 'HASH') {
2356: if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2357: foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2358: unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2359: $haschanges{$itemid} = 1;
2360: last;
2361: }
2362: }
2363: } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2364: $haschanges{$itemid} = 1;
2365: }
2366: }
2367: last if ($haschanges{$itemid});
2368: }
2369: }
2370: }
2371: }
2372: }
2373: if (@allpos > 0) {
2374: my $idx = 0;
2375: foreach my $itemid (@allpos) {
2376: if ($itemid ne '') {
2377: $ltitools{$itemid}{'order'} = $idx;
2378: if (ref($values) eq 'HASH') {
2379: if (ref($values->{$itemid}) eq 'HASH') {
2380: if ($values->{$itemid}{'order'} ne $idx) {
2381: $haschanges{$itemid} = 1;
2382: }
2383: }
2384: }
2385: $idx ++;
2386: }
2387: }
2388: }
2389: if (keys(%haschanges)) {
2390: foreach my $entry (keys(%haschanges)) {
2391: $changes->{$entry} = $ltitools{$entry};
2392: }
2393: if (ref($lastactref) eq 'HASH') {
2394: $lastactref->{'courseltitools'} = 1;
2395: }
2396: }
2397: return $errors;
2398: }
2399:
2400: sub process_ltitools_image {
2401: my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2402: my $filename = $env{'form.'.$caller.'.filename'};
2403: my ($error,$url);
2404: my ($width,$height) = (21,21);
2405: if ($configuserok eq 'ok') {
2406: if ($switch) {
2407: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2408: $switch);
2409: } elsif ($author_ok eq 'ok') {
2410: my ($result,$imageurl,$madethumb);
2411: if ($context eq 'domain') {
2412: ($result,$imageurl,$madethumb) =
2413: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2414: "ltitools/$itemid/icon",$width,$height);
2415: } else {
2416: ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2417: }
2418: if ($result eq 'ok') {
2419: if ($madethumb) {
2420: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2421: my $imagethumb = "$path/tn-".$imagefile;
2422: $url = $imagethumb;
2423: } else {
2424: $url = $imageurl;
2425: }
2426: } else {
2427: if ($context eq 'domain') {
2428: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2429: } else {
2430: $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2431: }
2432: }
2433: } else {
2434: $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);
2435: }
2436: } else {
2437: $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);
2438: }
2439: return ($url,$error);
2440: }
2441:
2442: sub processlogo {
2443: my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2444: my ($result,$imageurl,$madethumb);
2445: if ($env{"form.$caller.filename"} ne '') {
2446: unless ($caller eq 'ltitools_add_image') {
2447: if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2448: my ($path,$imagefile) = ($1,$2);
2449: if ($imagefile =~ /^tn\-(.+)$/) {
2450: my $origimg = $1;
2451: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2452: }
2453: &Apache::lonnet::removeuploadedurl($currimg);
2454: }
2455: }
2456: $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2457: '','','',$cnum,$dom,$width,$height);
2458: if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2459: my ($path,$imagefile) = ($1,$2);
2460: $result = 'ok';
2461: my $thumburl = "$path/tn-".$imagefile;
2462: my ($rtncode,$info);
2463: my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2464: if ($res eq 'ok') {
2465: $madethumb = 1;
2466: }
2467: } elsif ($imageurl eq '/adm/notfound.html') {
2468: undef($imageurl);
2469: $result = 'store failed';
2470: } elsif ($imageurl =~ /^error: (.+)$/) {
2471: $result = $1;
2472: }
2473: }
2474: return ($result,$imageurl,$madethumb);
2475: }
2476:
1.3 raeburn 2477: sub get_sec_str {
2478: my ($entry,$num) = @_;
2479: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2480: my $secstr;
2481: if (grep(/^\s*$/,@secs)) {
2482: $secstr = '';
2483: } elsif (@secs > 0) {
2484: $secstr = join(';',@secs);
2485: }
2486: if ($secstr ne '') {
2487: return '('.$secstr.')';
2488: }
2489: return;
2490: }
2491:
2492: sub check_clone {
2493: my ($clonedom,$disallowed,$clonename) = @_;
2494: return if (ref($disallowed) ne 'HASH');
2495: if ($clonedom !~ /^$match_domain$/) {
2496: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2497: return;
2498: } elsif (!&Apache::lonnet::domain($clonedom)) {
2499: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2500: return;
2501: }
2502: if ($clonename ne '') {
2503: if ($clonename !~ /^$match_username$/) {
2504: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2505: return;
2506: } else {
2507: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2508: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2509: return;
2510: }
2511: }
2512: }
2513: return 'ok';
2514: }
2515:
2516: sub store_changes {
1.9 raeburn 2517: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2518: my ($chome,$output);
1.118 raeburn 2519: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2520: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 2521: if (ref($values->{'linkprot'}) eq 'HASH') {
2522: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 2523: }
1.102 raeburn 2524: delete($values->{'linkprot'});
1.118 raeburn 2525: if (ref($values->{'ltitools'}) eq 'HASH') {
2526: %oldltitools = %{$values->{'ltitools'}};
2527: }
1.3 raeburn 2528: %storehash = %{$values};
2529: } else {
1.9 raeburn 2530: if ($crstype eq 'Community') {
2531: $output = &mt('No changes made to community settings.');
2532: } else {
2533: $output = &mt('No changes made to course settings.');
2534: }
2535: return $output;
1.3 raeburn 2536: }
1.93 raeburn 2537: my ($numchanges,$skipstore);
2538: if (ref($changes) eq 'HASH') {
2539: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 2540: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 2541: $skipstore = 1;
1.118 raeburn 2542: } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2543: $skipstore = 1;
1.93 raeburn 2544: } elsif (!$numchanges) {
2545: if ($crstype eq 'Community') {
2546: $output = &mt('No changes made to community settings.');
2547: } else {
2548: $output = &mt('No changes made to course settings.');
2549: }
2550: return $output;
2551: }
2552: }
1.3 raeburn 2553: my %yesno = (
2554: hidefromcat => '1',
2555: problem_stream_switch => '1',
2556: suppress_tries => '1',
2557: disableexampointprint => '1',
2558: hideemptyrows => '1',
2559: suppress_embed_prompt => '1',
2560: );
2561: foreach my $item (@{$prefs_order}) {
2562: if (grep(/^\Q$item\E$/,@{$actions})) {
2563: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2564: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 2565: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2566: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2567: if ($item eq 'other') {
2568: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2569: $storehash{$key} = $changes->{$item}{$key};
2570: if ($changes->{$item}{$key} eq '') {
2571: push(@delkeys,$key);
1.22 wenzelju 2572: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2573: } else {
1.22 wenzelju 2574: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2575: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2576: }
2577: }
1.102 raeburn 2578: } elsif ($item eq 'linkprot') {
2579: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.118 raeburn 2580: } elsif ($item eq 'ltitools') {
2581: $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2582: } else {
2583: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2584: my @settings = @{$prefs->{$item}->{'ordered'}};
2585: if ($item eq 'feedback') {
2586: push(@settings,(map { $_.'.text'; } @settings));
2587: }
2588: foreach my $key (@settings) {
2589: if ($key eq 'rolenames') {
2590: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2591: my $msg;
1.9 raeburn 2592: my @roles;
2593: if ($crstype eq 'Community') {
2594: @roles = ('co');
2595: } else {
2596: @roles = ('cc');
2597: }
2598: push(@roles,('in','ta','ep','ad','st'));
2599: foreach my $role (@roles) {
1.3 raeburn 2600: next if (!exists($changes->{$item}{$key.'_'.$role}));
2601: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2602: my $newname = $changes->{$item}{$key.'_'.$role};
2603: $storehash{$role.'.plaintext'} = $newname;
2604: if ($newname eq '') {
2605: $newname = $stdname;
2606: }
2607: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2608: "'<b>".$newname."</b>'").'</li>';
2609: }
2610: if ($msg ne '') {
1.22 wenzelju 2611: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2612: }
1.115 raeburn 2613: } elsif ($key eq 'timezone') {
2614: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2615: my ($displayname,$text);
2616: $text = $prefs->{$item}->{'itemtext'}{$key};
2617: my $displayval;
2618: if (exists($changes->{$item}{$key})) {
2619: $displayname = &mt($text);
2620: $storehash{$key} = $changes->{$item}{$key};
2621: if ($changes->{$item}{$key} ne '') {
2622: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2623: } else {
2624: push(@delkeys,$key);
2625: if (exists($values->{'tzover'})) {
2626: push(@delkeys,'tzover');
2627: }
2628: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2629: '<i>'.$displayname.'</i>')).'</li>';
2630: }
2631: }
2632: unless (grep(/^\Q$key\E$/,@delkeys)) {
2633: if (exists($changes->{$item}{'tzover'})) {
2634: $storehash{'tzover'} = $changes->{$item}{'tzover'};
2635: my $tzovertext;
2636: if ($changes->{$item}{'tzover'} ne '') {
2637: $tzovertext = &mt('Course Time Zone overrides individual user preference');
2638: } else {
2639: push(@delkeys,'tzover');
2640: $tzovertext = &mt('Course Time Zone does not override individual user preference');
2641: }
2642: if ($displayval eq '') {
2643: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2644: } else {
2645: $displayval .= '<br />'.(' 'x5).$tzovertext;
2646: }
2647: }
2648: if ($displayval ne '') {
2649: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2650: '<i>'.$displayname.'</i>',$displayval)).'</li>';
2651: }
2652: }
1.3 raeburn 2653: } else {
2654: next if (!exists($changes->{$item}{$key}));
2655: my ($displayname,$text);
2656: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2657: my $displayval;
1.114 raeburn 2658: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2659: $displayval = $changes->{$item}{$key};
2660: }
1.127 raeburn 2661: if (($item eq 'grading') && ($key eq 'grading')) {
2662: if ($displayval eq 'standard') {
2663: my $hidetotals;
2664: if (exists($changes->{$item}{'hidetotals'})) {
2665: if ($changes->{$item}{'hidetotals'} eq '') {
2666: if (exists($values->{'hidetotals'})) {
2667: push(@delkeys,'hidetotals');
2668: }
2669: } else {
2670: $hidetotals = $changes->{$item}{'hidetotals'};
2671: }
2672: } elsif (exists($values->{'hidetotals'})) {
2673: $hidetotals = $values->{'hidetotals'};
2674: }
2675: if ($hidetotals eq '') {
2676: $displayval = &mt('standard with "hide course totals" set to "No"');
2677: if (exists($values->{'hidetotals'})) {
2678: push(@delkeys,'hidetotals');
2679: }
2680: } elsif ($hidetotals =~ /^([\w,]+)$/) {
2681: my $secstr = $1;
2682: my @secs = split(/,/,$secstr);
2683: if (grep(/^all$/,@secs)) {
2684: $displayval = &mt('standard with "hide course totals" set to "Yes" for all users');
2685: $hidetotals = 'all';
2686: } else {
2687: $displayval = &mt('standard with "hide course totals" set to "Yes" for users in section(s): [_1]',join(', ',@secs));
2688: }
2689: $storehash{'hidetotals'} = $hidetotals;
2690: }
2691: } elsif (exists($values->{'hidetotals'})) {
2692: push(@delkeys,'hidetotals');
2693: }
2694: }
1.3 raeburn 2695: if ($item eq 'feedback') {
2696: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2697: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2698: $displayname = &mt('Custom text for '.$text.' questions');
2699: } else {
2700: $displayname = &mt('Recipients of '.$text.' questions');
2701: }
2702: } elsif ($item eq 'discussion') {
2703: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2704: $displayname = &mt("$text (role-based)");
2705: if ($displayval ne '') {
2706: my @roles = split(',',$displayval);
2707: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2708: $displayval = join(', ',@roles);
2709: }
2710: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2711: $displayname = &mt("$text (specific user(s))");
2712: } else {
2713: if ($key eq 'allow_discussion_post_editing') {
2714: if ($displayval ne '') {
2715: my @roles = split(',',$displayval);
2716: my @longroles;
2717: foreach my $role (@roles) {
2718: my ($trole,$sec) = split(':',$role);
2719: my $rolename =
2720: &Apache::lonnet::plaintext($trole);
2721: if ($sec ne '') {
2722: $rolename .= ':'.$sec;
2723: }
2724: push(@longroles,$rolename);
2725: }
2726: $displayval = join(', ',@longroles);
2727: }
1.50 raeburn 2728: } elsif ($key eq 'discussion_post_fonts') {
2729: my ($classorder,$classtitles)=&discussion_vote_classes();
2730: my ($styleorder,$styleitems)=&discussion_vote_styles();
2731: my $count = 1;
2732: my $total = scalar(keys(%{$changes->{$item}}));
2733: foreach my $class (@{$classorder}) {
2734: $count ++;
2735: next unless ($changes->{$item}{$key.'_'.$class});
2736: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2737: my $showval = '';
2738: for (my $i=0; $i<@{$styleorder}; $i++) {
2739: if ($vals[$i] ne '') {
2740: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2741: }
2742: }
2743: if ($vals[3] ne '') {
2744: $showval .= $vals[3];
2745: }
2746: if ($showval ne '') {
2747: $displayval .= $classtitles->{$class}.':{ '.
2748: $showval.'}';
2749: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2750: } else {
2751: $displayval .= $classtitles->{$class}.': '.&mt('None');
2752: push(@delkeys,$key.'_'.$class);
2753: }
2754: unless ($count == $total) {
2755: $displayval .= (' 'x2);
2756: }
2757: }
1.3 raeburn 2758: }
2759: $displayname = &mt($text);
2760: }
2761: } elsif ($item eq 'spreadsheet') {
2762: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2763: my $sheettype = $1;
2764: if ($sheettype eq 'studentcalc') {
2765: &Apache::lonnet::expirespread('','','studentcalc');
2766: } else {
2767: &Apache::lonnet::expirespread('','','assesscalc');
2768: &Apache::lonnet::expirespread('','','studentcalc');
2769: }
2770: }
2771: $displayname = &mt($text);
1.87 raeburn 2772: } elsif ($item eq 'lti') {
2773: if ($key eq 'lti.lcmenu') {
2774: if ($changes->{$item}{$key} eq 'none') {
2775: $displayval = &mt('None of the configurable menu items displayed');
2776: } else {
2777: my %ltititles = <imenu_titles();
2778: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2779: }
2780: } else {
2781: if ($changes->{$item}{$key} eq '1') {
2782: $displayval = &mt('Yes');
2783: } elsif ($changes->{$item}{$key} eq '') {
2784: $displayval = &mt('No');
2785: }
2786: }
2787: $displayname = &mt($text);
1.91 raeburn 2788: } elsif ($item eq 'menuitems') {
2789: unless ($changes->{$item}{$key} eq '') {
2790: if ($key eq 'menudefault') {
2791: $displayname = &mt('Default collection of menu items');
2792: $displayval = &mt('Collection: [_1]',
2793: $changes->{$item}{$key});
2794: } elsif ($key eq 'menucollections') {
2795: $displayval = &menucollections_display($changes->{$item}{$key});
2796: }
2797: }
1.3 raeburn 2798: } else {
2799: $displayname = &mt($text);
2800: }
2801: if (defined($yesno{$key})) {
1.14 raeburn 2802: $displayval = &mt('No');
1.3 raeburn 2803: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2804: $displayval = &mt('Yes');
1.3 raeburn 2805: }
2806: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2807: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2808: } elsif ($key eq 'categories') {
2809: $displayval = $env{'form.categories_display'};
1.95 raeburn 2810: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2811: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2812: if ($changes->{$item}{$key} eq '1') {
2813: $displayval = &mt('Yes');
2814: } elsif ($changes->{$item}{$key} eq '0') {
2815: $displayval = &mt('No');
2816: }
1.114 raeburn 2817: } elsif ($key eq 'extresource') {
2818: if ($changes->{$item}{$key} eq 'iframe') {
2819: $displayval = &mt('In iframe');
2820: } else {
2821: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2822: if ($selected eq 'tab') {
2823: if ($reuse) {
2824: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2825: "'<b>","</b>'",'<br />');
2826: } else {
2827: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2828: "'<b>","</b>'",'<br />');
2829: }
2830: } elsif ($selected eq 'window') {
2831: if ($reuse) {
2832: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2833: "'<b>","</b>'",'<br />');
2834: } else {
2835: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2836: "'<b>","</b>'",'<br />');
2837: }
2838: if (($width ne '') || ($height ne '')) {
2839: if ($width ne '') {
2840: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2841: }
2842: if ($height ne '') {
2843: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2844: }
2845: }
2846: }
2847: }
1.14 raeburn 2848: }
1.25 raeburn 2849: if ($key eq 'co-owners') {
2850: if (ref($changes->{$item}{$key}) eq 'HASH') {
2851: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2852: foreach my $type ('co-owners','pendingco-owners') {
2853: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2854: if ($type eq 'pendingco-owners') {
2855: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2856: $displayname = &mt('Invited as co-owners, pending acceptance');
2857: }
2858: }
2859: if ($changes->{$item}{$key}{$type} eq '') {
2860: push(@delkeys,'internal.'.$type);
2861: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2862: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2863: '<i>'.$displayname.'</i>')).'</li>';
2864: }
2865: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2866: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2867: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2868: '<i>'.$displayname.'</i>',
2869: "'<b>$displayval</b>'")).'</li>';
2870: }
2871: }
2872: }
2873: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2874: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2875: $displayval = &mt('on');
1.90 raeburn 2876: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2877: $displayval = '';
2878: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2879: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2880: $displayval = &mt('off');
2881: }
2882: if ($displayval) {
2883: $displayname = &mt('Your co-ownership status');
2884: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2885: '<i>'.$displayname.'</i>',
2886: "'<b>$displayval</b>'")).'</li>';
2887: }
2888: }
2889: }
2890: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2891: push(@delkeys,$key);
1.87 raeburn 2892: if ($item eq 'lti') {
2893: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2894: if (($key eq 'lti.lcmenu') &&
2895: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2896: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2897: } else {
2898: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2899: '<i>'.$displayname.'</i>',
2900: "'<b>$displayval</b>'")).'</li>';
2901: }
2902: } elsif (!exists($changes->{$item}{'lti.override'})) {
2903: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2904: }
1.91 raeburn 2905: } elsif ($item eq 'menuitems') {
2906: if ($key eq 'menudefault') {
2907: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2908: } elsif ($key eq 'menucollections') {
2909: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2910: }
1.87 raeburn 2911: } else {
2912: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2913: '<i>'.$displayname.'</i>')).'</li>';
2914: }
1.91 raeburn 2915: } elsif ($key eq 'menucollections') {
2916: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2917: $displayval.'</li>';
1.3 raeburn 2918: } else {
1.114 raeburn 2919: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2920: $displayval = "'<b>$displayval</b>'";
2921: }
1.22 wenzelju 2922: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2923: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2924: if ($key eq 'url') {
2925: my $bkuptime=time;
2926: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2927: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2928: }
2929: $output .= '</li>';
2930: }
1.25 raeburn 2931: if ($key eq 'co-owners') {
2932: if (ref($changes->{$item}{$key}) eq 'HASH') {
2933: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2934: foreach my $type ('co-owners','pendingco-owners') {
2935: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2936: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2937: }
2938: }
2939: }
2940: } else {
1.50 raeburn 2941: unless ($key eq 'discussion_post_fonts') {
2942: $storehash{$key} = $changes->{$item}{$key};
2943: }
1.25 raeburn 2944: }
1.3 raeburn 2945: }
1.23 raeburn 2946: if ($key eq 'cloners') {
2947: # Get existing cloners
2948: my %clonenames =
2949: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2950: if ($clonenames{'cloners'} =~ /,/) {
2951: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2952: } else {
2953: $oldcloner[0] = $clonenames{'cloners'};
2954: }
2955: }
1.3 raeburn 2956: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2957: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2958: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2959: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2960: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2961: push(@need_env_update,$key);
2962: }
2963: }
2964: }
2965: }
2966: $output .= '</ul>';
2967: } else {
1.9 raeburn 2968: if ($crstype eq 'Community') {
1.46 raeburn 2969: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2970: } else {
1.46 raeburn 2971: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2972: }
1.3 raeburn 2973: }
2974: }
2975: }
2976: }
1.93 raeburn 2977: if ($skipstore) {
2978: return $output;
2979: }
1.3 raeburn 2980: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2981: if (ref($changes) eq 'HASH') {
2982: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2983: if (exists($changes->{'courseinfo'}{'cloners'})) {
2984: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2985: \@oldcloner);
2986: }
2987: }
2988: }
1.3 raeburn 2989: if (@delkeys) {
2990: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2991: $output .= '<br /><span class="LC_error">';
2992: if ($crstype eq 'Community') {
2993: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2994: } else {
2995: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2996: }
2997: $output .= '</span>';
1.14 raeburn 2998: } else {
2999: foreach my $key (@delkeys) {
3000: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
3001: }
1.3 raeburn 3002: }
3003: }
3004: if (@need_env_update) {
3005: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
3006: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
3007: }
3008: &Apache::lonnet::coursedescription($env{'request.course.id'},
3009: {'freshen_cache' => 1});
3010: } else {
1.9 raeburn 3011: $output = '<span class="LC_error">';
3012: if ($crstype eq 'Community') {
3013: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
3014: } else {
3015: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
3016: }
3017: $output .= '</span>';
1.3 raeburn 3018: }
3019: return $output;
3020: }
3021:
1.102 raeburn 3022: sub store_linkprot {
3023: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 3024: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 3025: if ($context eq 'domain') {
3026: $ltiauth = 1;
1.103 raeburn 3027: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 3028: } else {
1.103 raeburn 3029: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 3030: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
3031: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
3032: } else {
3033: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
3034: $ltiauth = $domdefs{'crsltiauth'};
3035: }
3036: }
3037: if (ref($changes) eq 'HASH') {
3038: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3039: if (ref($changes->{$id}) eq 'HASH') {
3040: if (exists($changes->{$id}->{'key'})) {
3041: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
3042: delete($changes->{$id}->{'key'});
3043: }
3044: if (exists($changes->{$id}->{'secret'})) {
3045: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
3046: delete($changes->{$id}->{'secret'});
3047: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3048: if (exists($oldlinkprot->{$id}{'usable'})) {
3049: $changes->{$id}->{'usable'} = 1;
3050: }
1.109 raeburn 3051: if (exists($oldlinkprot->{$id}{'cipher'})) {
3052: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
3053: }
1.102 raeburn 3054: }
3055: }
3056: }
3057: }
3058: my @ids=&Apache::lonnet::current_machine_ids();
3059: if (keys(%ltienc) > 0) {
3060: if ($context eq 'domain') {
3061: foreach my $id (keys(%ltienc)) {
3062: if (exists($ltienc{$id}{'secret'})) {
3063: $changes->{$id}->{'usable'} = 1;
3064: }
3065: }
3066: } else {
1.103 raeburn 3067: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 3068: my $allowed;
3069: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3070: if ($allowed) {
3071: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
3072: foreach my $id (keys(%ltienc)) {
3073: if (exists($ltienc{$id}{'secret'})) {
3074: $changes->{$id}->{'usable'} = 1;
3075: }
3076: }
3077: } else {
3078: $lti_save_error = 1;
3079: }
3080: }
3081: }
3082: }
3083: }
3084: unless ($lti_save_error) {
3085: if ($context eq 'course') {
3086: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3087: my $hashid=$cdom.'_'.$cnum;
3088: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 3089: unless (($home eq 'no_host') || ($home eq '')) {
3090: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 3091: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3092: }
3093: }
3094: } else {
3095: $lti_save_error = 1;
3096: }
3097: }
3098: unless ($lti_save_error) {
3099: foreach my $id (sort { $a <=> $b } %{$changes}) {
3100: if (ref($changes->{$id}) eq 'HASH') {
3101: my %values = %{$changes->{$id}};
3102: my %desc = &linkprot_names();
3103: my $display;
1.122 raeburn 3104: foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.102 raeburn 3105: if (($title eq 'key') || ($title eq 'secret')) {
3106: if (ref($ltienc{$id}) eq 'HASH') {
3107: if (exists($ltienc{$id}{$title})) {
3108: if ($title eq 'secret') {
3109: my $length = length($ltienc{$id}{$title});
1.103 raeburn 3110: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 3111: } else {
3112: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3113: }
3114: }
3115: }
3116: } elsif ($title eq 'version') {
3117: if ($values{$title} eq 'LTI-1p0') {
3118: $display .= $desc{$title}.': 1.1, ';
3119: }
1.112 raeburn 3120: } elsif ($title eq 'returnurl') {
3121: if ($values{$title}) {
1.124 raeburn 3122: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
1.112 raeburn 3123: }
1.122 raeburn 3124: } elsif ($title eq 'passbackformat') {
3125: if ($values{$title} eq '1.0') {
3126: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
3127: } elsif ($values{$title} eq '1.1') {
3128: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
3129: }
1.102 raeburn 3130: } else {
3131: $display .= $desc{$title}.': '.$values{$title}.', ';
3132: }
3133: }
3134: if ($ltiauth) {
3135: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3136: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3137: $display .= &mt('Source of username: Email address [_1]',
3138: '(lis_person_contact_email_primary)').', ';
3139: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3140: $display .= &mt('Source of username: User ID [_1]',
3141: '(lis_person_sourcedid)').', ';
3142: } else {
3143: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3144: }
3145: if ($values{'notstudent'} eq 'auth') {
3146: $display .= &mt('Display LON-CAPA login page if no match').', ';
3147: } elsif ($values{'notstudent'} eq 'reject') {
3148: $display .= &mt('Discontinue launch if no match').', ';
3149: }
3150: }
3151: }
3152: $display =~ s/, $//;
3153: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3154: "'$display'")).'</li>';
3155: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3156: my $oldname = $oldlinkprot->{$id}{'name'};
3157: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3158: }
3159: }
3160: } else {
3161: $lti_save_error = 1;
3162: }
3163: }
3164: unless ($lti_save_error) {
3165: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3166: unless (ref($changes->{$id}) eq 'HASH') {
3167: push(@deletions,$id);
3168: }
3169: }
3170: if (@deletions) {
3171: if ($context eq 'course') {
3172: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3173: }
3174: }
3175: }
3176: if ($lti_save_error) {
3177: $output .= '<li>'.
3178: '<span class="LC_error">'.
3179: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3180: '</span>'.
3181: '</li>';
3182: }
3183: return $output;
3184: }
3185:
1.118 raeburn 3186: sub store_ltitools {
3187: my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3188: my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3189: my %lt = <itools_names();
3190: my @courseroles = ('cc','in','ta','ep','st');
3191: my @allfields = ('fullname','firstname','lastname','email','user','roles');
3192: if ($context eq 'domain') {
3193: $home = &Apache::lonnet::domain($cdom,'primary');
3194: } else {
3195: $home = &Apache::lonnet::homeserver($cnum,$cdom);
3196: }
3197: if (ref($changes) eq 'HASH') {
3198: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3199: if (ref($changes->{$id}) eq 'HASH') {
3200: if (exists($changes->{$id}->{'key'})) {
3201: $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3202: delete($changes->{$id}->{'key'});
3203: }
3204: if (exists($changes->{$id}->{'secret'})) {
3205: $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3206: delete($changes->{$id}->{'secret'});
3207: } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3208: if (exists($oldltitools->{$id}{'usable'})) {
3209: $changes->{$id}->{'usable'} = 1;
3210: }
3211: if (exists($oldltitools->{$id}{'cipher'})) {
3212: $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3213: }
3214: }
3215: }
3216: }
3217: }
3218: my @ids=&Apache::lonnet::current_machine_ids();
3219: if (keys(%toolsenc) > 0) {
3220: unless (($home eq 'no_host') || ($home eq '')) {
3221: my $allowed;
3222: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3223: if ($allowed) {
3224: if (($context eq 'domain') ||
3225: (($context eq 'course') &&
3226: (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3227: foreach my $id (keys(%toolsenc)) {
3228: if (exists($toolsenc{$id}{'secret'})) {
3229: $changes->{$id}->{'usable'} = 1;
3230: }
3231: }
3232: } else {
3233: $ltitools_save_error = 1;
3234: }
3235: }
3236: }
3237: }
3238: unless ($ltitools_save_error) {
3239: if ($context eq 'course') {
3240: if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3241: my $hashid=$cdom.'_'.$cnum;
3242: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3243: unless (($home eq 'no_host') || ($home eq '')) {
3244: if (grep(/^\Q$home\E$/,@ids)) {
1.120 raeburn 3245: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
1.118 raeburn 3246: }
3247: }
3248: } else {
3249: $ltitools_save_error = 1;
3250: }
3251: }
3252: unless ($ltitools_save_error) {
3253: my %bynum;
3254: foreach my $itemid (sort(keys(%{$changes}))) {
3255: my $position = $changes->{$itemid}{'order'};
3256: $bynum{$position} = $itemid;
3257: }
3258: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3259: my $itemid = $bynum{$pos};
3260: if (ref($changes->{$itemid}) ne 'HASH') {
3261: $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3262: } else {
3263: $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3264: if ($changes->{$itemid}{'image'}) {
3265: $output .= ' '.
3266: '<img src="'.$changes->{$itemid}{'image'}.'"'.
3267: ' alt="'.&mt('Tool Provider icon').'" />';
3268: }
3269: $output .= '</li><ul>';
3270: my $position = $pos + 1;
3271: $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3272: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3273: if ($changes->{$itemid}{$item} ne '') {
3274: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3275: }
3276: }
3277: if (ref($toolsenc{$itemid}) eq 'HASH') {
3278: foreach my $item ('key','secret') {
3279: if (exists($toolsenc{$itemid}{$item})) {
3280: if ($item eq 'secret') {
3281: $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3282: } else {
3283: $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3284: }
3285: }
3286: }
3287: }
1.129 ! raeburn 3288: $output .= '<li>';
! 3289: if ($context eq 'domain') {
! 3290: $output .= &mt('Configurable in course');
! 3291: } else {
! 3292: $output .= &mt('Configurable for each instance of tool in course');
! 3293: }
! 3294: $output .= ':';
1.118 raeburn 3295: my @possconfig = ('label','title','target','linktext','explanation','append');
3296: my $numconfig = 0;
3297: if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3298: foreach my $item (@possconfig) {
3299: if ($changes->{$itemid}{'crsconf'}{$item}) {
3300: $numconfig ++;
3301: $output .= ' "'.$lt{'crs'.$item}.'"';
3302: }
3303: }
3304: }
3305: if (!$numconfig) {
3306: $output .= ' '.&mt('None');
3307: }
3308: $output .= '</li>';
3309: foreach my $item ('passback','roster') {
3310: $output .= '<li>'.$lt{$item}.' ';
3311: if ($changes->{$itemid}{$item}) {
3312: $output .= &mt('Yes');
3313: if ($changes->{$itemid}{$item.'valid'}) {
3314: if ($item eq 'passback') {
3315: $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3316: $changes->{$itemid}{$item.'valid'});
3317: } else {
3318: $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3319: $changes->{$itemid}{$item.'valid'});
3320: }
3321: }
3322: } else {
3323: $output .= &mt('No');
3324: }
3325: $output .= '</li>';
3326: }
3327: if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3328: my $displaylist;
3329: if ($changes->{$itemid}{'display'}{'target'}) {
3330: $displaylist = &mt('Display target').': '.
3331: $changes->{$itemid}{'display'}{'target'}.',';
3332: }
3333: foreach my $size ('width','height') {
3334: if ($changes->{$itemid}{'display'}{$size}) {
3335: $displaylist .= (' 'x2).$lt{$size}.': '.
3336: $changes->{$itemid}{'display'}{$size}.',';
3337: }
3338: }
3339: if ($displaylist) {
3340: $displaylist =~ s/,$//;
3341: $output .= '<li>'.$displaylist.'</li>';
3342: }
3343: foreach my $item ('linktext','explanation') {
3344: if ($changes->{$itemid}{'display'}{$item}) {
3345: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3346: }
3347: }
3348: }
3349: if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3350: my $fieldlist;
3351: foreach my $field (@allfields) {
3352: if ($changes->{$itemid}{'fields'}{$field}) {
3353: $fieldlist .= (' 'x2).$lt{$field}.',';
3354: }
3355: }
3356: if ($fieldlist) {
3357: $fieldlist =~ s/,$//;
3358: if ($changes->{$itemid}{'fields'}{'user'}) {
3359: if ($changes->{$itemid}{'incdom'}) {
3360: $fieldlist .= ' ('.&mt('username:domain').')';
3361: } else {
3362: $fieldlist .= ' ('.&mt('username').')';
3363: }
3364: }
3365: $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3366: }
3367: }
3368: if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3369: my $rolemaps;
3370: foreach my $role (@courseroles) {
3371: if ($changes->{$itemid}{'roles'}{$role}) {
3372: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3373: $changes->{$itemid}{'roles'}{$role}.',';
3374: }
3375: }
3376: if ($rolemaps) {
3377: $rolemaps =~ s/,$//;
3378: $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3379: }
3380: }
3381: if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3382: my $customlist;
3383: if (keys(%{$changes->{$itemid}{'custom'}})) {
3384: foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3385: $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3386: }
3387: }
3388: if ($customlist) {
3389: $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3390: }
3391: }
3392: $output .= '</ul></li>';
3393: }
3394: }
3395: }
3396: }
3397: return $output;
3398: }
3399:
1.3 raeburn 3400: sub update_env {
3401: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3402: my $count = 0;
3403: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3404: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3405: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3406: foreach my $key (@{$need_env_update}) {
3407: if ($key eq 'description' && defined($storehash->{$key})) {
3408: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3409: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3410: $count ++;
3411: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3412: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3413: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3414: $count ++;
1.25 raeburn 3415: } elsif ($key eq 'co-owners') {
3416: if ($storehash->{'internal.co-owners'} ne '') {
3417: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3418: }
3419: if ($storehash->{'internal.pendingco-owners'} ne '') {
3420: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3421: }
3422: my @coowners = split(',',$storehash->{'internal.'.$key});
3423: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3424: $count ++;
1.87 raeburn 3425: } elsif ($key =~ /^lti\./) {
3426: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 3427: }
3428: }
3429: if ($count) {
3430: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3431: }
3432: }
3433: }
3434: return;
3435: }
3436:
3437: sub display_disallowed {
1.9 raeburn 3438: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3439: my $output;
3440: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3441: if (keys(%{$disallowed})) {
3442: if ($item eq 'cloners') {
3443: my @fails;
3444: my %lt = &Apache::lonlocal::texthash (
3445: format => 'Invalid format',
3446: domain => 'Domain does not exist',
3447: newuser => 'LON-CAPA user(s) do(es) not exist.',
3448: );
3449: foreach my $error ('format','domain','newuser') {
3450: if (defined($disallowed->{$error})) {
3451: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3452: $lt{$error};
3453: if ($error eq 'newuser') {
1.9 raeburn 3454: $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 3455: }
3456: push(@fails,$msg);
3457: }
3458: }
3459: if (@fails) {
3460: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3461: '</span>'.join('; ',@fails).'.<br />';
3462: }
3463: } elsif ($item eq 'rolenames') {
3464: my %lt = &Apache::lonlocal::texthash (
3465: replacements => 'Name already used to replace a different standard role name',
3466: regulars => 'Name already used as a standard role name',
3467: customrole => 'Name already used as the name of a custom role',
3468: );
3469: my @fails;
3470: foreach my $error ('replacements','regulars','customrole') {
3471: if (ref($disallowed->{$error}) eq 'ARRAY') {
3472: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3473: '</b>, '.&mt('reason').' - '.$lt{'error'});
3474: }
3475: }
3476: if (@fails) {
3477: $output .= '<span class="LC_warning">'.
3478: &mt('Unable to include amongst replacements for role names: ').
3479: '</span>'.join('; ',@fails).'.<br />';
3480: }
3481:
3482: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3483: $output .= '<span class="LC_warning">';
3484: if ($item eq 'feedback') {
1.9 raeburn 3485: if ($crstype eq 'Community') {
3486: $output .= &mt('Unable to include as a recipient of community feedback for:');
3487: } else {
3488: $output .= &mt('Unable to include as a recipient of course feedback for:');
3489: }
1.3 raeburn 3490: } elsif ($item eq 'discussion') {
3491: $output .= &mt('Unable to include in user-based access control for:');
3492: } elsif ($item eq 'localization') {
1.9 raeburn 3493: if ($crstype eq 'Community') {
3494: $output .= &mt('Unable to include in community localization:');
3495: } else {
3496: $output .= &mt('Unable to include in course localization:');
3497: }
1.3 raeburn 3498: }
3499: $output .= '</span><ul>';
3500: foreach my $key (sort(keys(%{$disallowed}))) {
3501: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3502: $output .= '<li><i>'.$itemtext.'</i> - ';
3503: if ($item eq 'localization') {
3504: $output .= &mt('reason - unsupported language: [_1]',
3505: '<b>'.$disallowed->{$key}.'</b>');
3506: } else {
3507: $output .= &mt('reason - invalid user: [_1]',
3508: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3509: }
3510: }
3511: $output .= '</ul><br />';
3512: }
3513: }
1.1 raeburn 3514: }
1.3 raeburn 3515: return $output;
1.1 raeburn 3516: }
3517:
3518: sub get_course {
3519: my ($courseid) = @_;
3520: if (!defined($courseid)) {
3521: $courseid = $env{'request.course.id'};
3522: }
3523: my $cdom=$env{'course.'.$courseid.'.domain'};
3524: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 3525: my $chome=$env{'course.'.$courseid.'.home'};
3526: return ($cnum,$cdom,$chome);
1.1 raeburn 3527: }
3528:
3529: sub get_jscript {
1.91 raeburn 3530: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3531: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 raeburn 3532: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3533: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3534: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3535: my $cloners_js = &cloners_javascript($phase);
1.118 raeburn 3536: my $currltitools;
3537: if (ref($settings) eq 'HASH') {
3538: $currltitools = $settings->{'ltitools'};
3539: }
3540: my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.71 raeburn 3541: my @code_order;
3542: if ($crstype ne 'Community') {
3543: if (ref($settings) eq 'HASH') {
3544: my %codedefaults;
3545: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3546: \@code_order);
3547: if (@code_order > 0) {
3548: if ($phase eq 'display') {
3549: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3550: if (grep(/^courseinfo$/,@actions)) {
3551: if ($settings->{'cloners'} ne '') {
3552: unless ($settings->{'cloners'} eq '*') {
3553: my @cloners = split(/,/,$settings->{'cloners'});
3554: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3555: my %local_to_standard;
3556: for (my $i=0; $i<@code_order; $i++) {
3557: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3558: }
3559: foreach my $cloner (@cloners) {
1.124 raeburn 3560: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
1.71 raeburn 3561: ($cloner !~ /^$match_username\:$match_domain$/)) {
3562: foreach my $item (split(/\&/,$cloner)) {
3563: my ($key,$val) = split(/\=/,$item);
3564: $val = &unescape($val);
3565: foreach my $code (@code_order) {
3566: if ($key eq $local_to_standard{$code}) {
3567: $env{'form.'.$key} = $val;
3568: }
3569: }
3570: }
3571: }
3572: }
3573: }
3574: }
3575: }
3576: }
3577: my @codetitles;
3578: (undef,$instcode_js) =
3579: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3580: \@codetitles);
3581: $instcode_js .= <<ENDSCRIPT;
3582: function toggleCloners(callerradio) {
3583: if (document.getElementById('LC_cloners_instcode')) {
3584: if (callerradio.value == 1) {
3585: document.getElementById('LC_cloners_instcode').style.display = "block";
3586: } else {
3587: uncheckOfficialLists();
3588: document.getElementById('LC_cloners_instcode').style.display = "none";
3589: }
3590: }
3591: }
3592:
3593: if (!document.getElementsByClassName) {
3594: function getElementsByClassName(node, classname) {
3595: var a = [];
3596: var re = new RegExp('(^| )'+classname+'( |$)');
3597: var els = node.getElementsByTagName("*");
3598: for(var i=0,j=els.length; i<j; i++)
3599: if(re.test(els[i].className))a.push(els[i]);
3600: return a;
3601: }
3602: }
3603:
3604: function uncheckOfficialLists() {
3605: var codepicks;
3606: if (document.getElementsByClassName) {
3607: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3608: } else {
3609: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3610: }
3611: if (codepicks.length) {
3612: for (var i=0; i<codepicks.length; i++) {
3613: codepicks[i].selectedIndex = 0;
3614: }
3615: }
3616: }
3617:
3618: ENDSCRIPT
3619: }
3620: }
3621: }
1.1 raeburn 3622: if ($can_categorize) {
3623: $categorize_js = <<ENDSCRIPT;
3624: function catsbrowser() {
3625: var catswin = null;
3626: var url = '/adm/courseprefs?phase=categorizecourse';
3627: if (!catswin || catswin.closed) {
3628: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3629: } else {
3630: catswin.focus();
3631: }
3632: }
3633: ENDSCRIPT
3634: }
1.36 raeburn 3635: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3636: if ($loncaparev) {
3637: $loncaparev_js = <<ENDSCRIPT;
3638: function loncaparevinfo() {
3639: var lcrevwin = null;
3640: var url = '/adm/courseprefs?phase=releaseinfo';
3641: if (!lcrevwin || lcrevwin.closed) {
3642: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3643: } else {
3644: lcrevwin.focus();
3645: }
3646: }
3647: ENDSCRIPT
3648: }
1.60 raeburn 3649: my $cnum = $env{'course.'.$cid.'.num'};
3650: my $syllabus_js = <<ENDSCRIPT;
3651: function syllabusinfo() {
3652: var syllwin = null;
3653: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3654: if (!syllwin || syllwin.closed) {
3655: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3656: } else {
3657: syllwin.focus();
3658: }
3659: }
3660: ENDSCRIPT
1.127 raeburn 3661: my ($menuitems_js,$grading_js);
1.91 raeburn 3662: unless ($noedit) {
3663: my $collections;
3664: my $next = 1;
3665: if (ref($settings) eq 'HASH') {
3666: if ($settings->{'menucollections'} ne '') {
3667: my @current;
3668: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3669: my ($num) = split(/\%/,$item);
3670: if ($num =~ /^\d+$/) {
3671: push(@current,$num);
3672: }
3673: }
3674: $collections = join("','",sort { $a <=> $b } @current);
3675: if ($collections) {
3676: $collections = "'$collections'";
3677: }
3678: $next += $current[-1];
3679: }
3680: }
3681: my $deftext = &mt('Standard (all menus shown)');
3682: $menuitems_js = <<ENDSCRIPT;
3683: function toggleAddmenucoll() {
3684: if (document.getElementById('menucollections_add')) {
3685: var state = 'none';
3686: var add = document.getElementById('menucollections_add').checked;
3687: if (add) {
3688: state = 'inline-block';
3689: }
3690: var fieldsets = new Array('shown','text','links','list','inline');
3691: for (var i=0; i<fieldsets.length; i++) {
3692: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3693: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3694: }
3695: }
3696: var box = document.getElementsByClassName('LC_menucoll_add');
3697: if (box.length) {
3698: for (var i=0; i<box.length; i++) {
3699: if (add) {
3700: box[i].checked = true;
3701: } else {
3702: box[i].checked = false;
3703: }
3704: }
3705: }
3706: if (document.getElementById('menudefault')) {
3707: var menudef = document.getElementById('menudefault');
3708: var currsel = menudef.selectedIndex;
3709: var colls = new Array($collections);
3710: menudef.options.length = 0;
3711: if (!add) {
3712: if (currsel == 1 + colls.length) {
3713: currsel = 0;
3714: }
3715: }
3716: if (currsel == 0) {
3717: menudef.options[0] = new Option('$deftext','',true,true);
3718: } else {
3719: menudef.options[0] = new Option('$deftext','',false,false);
3720: }
3721: if (colls.length) {
3722: for (var i=0; i<colls.length; i++) {
3723: var idx = i+1;
3724: if (currsel == colls[i]) {
3725: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3726: } else {
3727: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3728: }
3729: }
3730: }
3731: if (add) {
3732: var addidx = 1 + colls.length;
3733: if (currsel == addidx) {
3734: menudef.options[addidx] = new Option('$next','$next',true,true);
3735: } else {
3736: menudef.options[addidx] = new Option('$next','$next',false,false);
3737: }
3738: }
3739: }
3740: }
3741: }
3742: ENDSCRIPT
1.127 raeburn 3743: $grading_js = <<"ENDSCRIPT";
3744: function toggleGrading(form) {
3745: if (document.getElementById('hidetotalsdiv')) {
3746: var totalsdivid = document.getElementById('hidetotalsdiv');
3747: var selname = form.elements['grading'];
3748: if (selname) {
3749: var current = selname.options[selname.selectedIndex].value
3750: if (current == 'standard') {
3751: totalsdivid.style.display = 'inline-block';
3752: } else {
3753: totalsdivid.style.display = 'none';
3754: }
3755: }
3756: }
3757: return;
3758: }
3759:
3760: function toggleHiddenTotalsSec(form) {
3761: if (document.getElementById('sectotalsdiv')) {
3762: var sectotalsdivid = document.getElementById('sectotalsdiv');
3763: var radioname = form.elements['hidetotals'];
3764: if (radioname) {
3765: if (radioname.length > 0) {
3766: var setvis;
3767: for (var i=0; i<radioname.length; i++) {
3768: if (radioname[i].checked == true) {
3769: if (radioname[i].value == 1) {
3770: sectotalsdivid.style.display = 'inline-block';
3771: setvis = 1;
3772: }
3773: break;
3774: }
3775: }
3776: if (!setvis) {
3777: sectotalsdivid.style.display = 'none';
3778: }
3779: }
3780: }
3781: }
3782: return;
3783: }
3784: ENDSCRIPT
1.91 raeburn 3785: }
1.114 raeburn 3786: $extresource_js = <<"ENDSCRIPT";
3787: function toggleExtRes() {
3788: if (document.getElementById('LC_extresource')) {
3789: var extressel = document.getElementById('LC_extresource').value;
3790: if (document.getElementById('LC_extresreusediv')) {
3791: var extresreuse = document.getElementById('LC_extresreusediv');
3792: if (document.getElementById('LC_extressize')) {
3793: var extressize = document.getElementById('LC_extressize');
3794: var setvis;
3795: if ((extressel == 'tab') || (extressel == 'window')) {
3796: extresreuse.style.display = 'inline-block';
3797: setvis = 1;
3798: if (extressel == 'window') {
3799: extressize.style.display = 'inline-block';
3800: } else {
3801: extressize.style.display = 'none';
3802: }
3803: }
3804: if (!setvis) {
3805: extresreuse.style.display = 'none';
3806: extressize.style.display = 'none';
3807: }
3808: }
3809: }
3810: }
3811: }
3812: ENDSCRIPT
1.115 raeburn 3813: $localization_js = <<"ENDSCRIPT";
3814: function toggleTimeZone() {
3815: if (document.getElementById('LC_set_timezone')) {
3816: var timezonesel = document.getElementById('LC_set_timezone').value;
3817: if (document.getElementById('LC_tzoverdiv')) {
3818: var tzoverdiv = document.getElementById('LC_tzoverdiv');
3819: if (timezonesel == '') {
3820: tzoverdiv.style.display = 'none';
3821: } else {
3822: tzoverdiv.style.display = 'block';
3823: }
3824: }
3825: }
3826: }
3827: ENDSCRIPT
1.1 raeburn 3828: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.124 raeburn 3829: '// <![CDATA['."\n".
1.36 raeburn 3830: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 raeburn 3831: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 3832: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.127 raeburn 3833: $grading_js."\n".&linkprot_javascript()."\n".'//]]>'."\n".
1.118 raeburn 3834: '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3835: return $jscript;
3836: }
3837:
1.3 raeburn 3838: sub cloners_javascript {
3839: my ($formname) = @_;
3840: return <<"ENDSCRIPT";
3841:
3842: function update_cloners(caller,num) {
3843: var delidx = getIndexByName('cloners_delete');
3844: var actidx = getIndexByName('cloners_activate');
3845: if (caller == 'cloners_all') {
3846: var selall;
3847: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3848: if (document.$formname.cloners_all[i].checked) {
3849: selall = document.$formname.cloners_all[i].value;
3850: }
3851: }
3852: if (selall == 1) {
3853: if (delidx != -1) {
3854: if (document.$formname.cloners_delete.length) {
3855: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3856: document.$formname.cloners_delete[j].checked = true;
3857: }
3858: } else {
3859: document.$formname.elements[delidx].checked = true;
3860: }
3861: }
3862: if (actidx != -1) {
3863: if (document.$formname.cloners_activate.length) {
3864: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3865: if (document.$formname.cloners_activate[i].value == '0') {
3866: document.$formname.cloners_activate[i].checked = false;
3867: }
1.71 raeburn 3868: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3869: document.$formname.cloners_activate[i].checked = true;
3870: }
3871: }
3872: }
3873: }
3874: document.$formname.cloners_newdom.selectedIndex = 0;
3875: }
3876: }
3877: if (caller == 'cloners_activate') {
3878: if (document.$formname.cloners_activate.length) {
3879: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3880: if (document.$formname.cloners_activate[j].value == num) {
3881: if (document.$formname.cloners_activate[j].checked) {
3882: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3883: if (document.$formname.cloners_all[i].value == '1') {
3884: document.$formname.cloners_all[i].checked = false;
3885: }
3886: if (document.$formname.cloners_all[i].value == '0') {
3887: document.$formname.cloners_all[i].checked = true;
3888: }
3889: }
3890: }
3891: }
3892: }
3893: } else {
3894: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3895: if (document.$formname.cloners_all[i].value == '1') {
3896: document.$formname.cloners_all[i].checked = false;
3897: }
3898: if (document.$formname.cloners_all[i].value == '0') {
3899: document.$formname.cloners_all[i].checked = true;
3900: }
3901: }
3902: }
3903: }
3904: return;
3905: }
3906:
3907: function getIndexByName(item) {
3908: for (var i=0;i<document.$formname.elements.length;i++) {
3909: if (document.$formname.elements[i].name == item) {
3910: return i;
3911: }
3912: }
3913: return -1;
3914: }
3915:
3916: ENDSCRIPT
3917: }
3918:
1.102 raeburn 3919: sub linkprot_javascript {
3920: return <<"ENDSCRIPT";
1.112 raeburn 3921: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 3922: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3923: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3924: var itemname = form.elements['linkprot_'+item+'_'+num];
3925: if (itemname) {
3926: if (itemname.length > 0) {
3927: var setvis;
3928: for (var i=0; i<itemname.length; i++) {
3929: if (itemname[i].checked == true) {
3930: if (itemname[i].value == valon) {
3931: extraid.style.display = styleon;
3932: setvis = 1;
3933: }
3934: break;
3935: }
3936: }
3937: if (!setvis) {
3938: extraid.style.display = 'none';
3939: }
3940: }
3941: }
3942: }
3943: return;
3944: }
1.106 raeburn 3945:
1.102 raeburn 3946: ENDSCRIPT
3947:
3948: }
3949:
1.1 raeburn 3950: sub print_courseinfo {
1.80 raeburn 3951: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3952: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3953: return;
3954: }
1.83 raeburn 3955: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3956: if ($noedit) {
3957: $disabled = ' disabled="disabled"';
3958: }
1.1 raeburn 3959: my %domconf =
1.71 raeburn 3960: &Apache::lonnet::get_dom('configuration',
3961: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3962: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3963: $cathash = $domconf{'coursecategories'}{'cats'};
3964: if (ref($cathash) eq 'HASH') {
3965: $categoriesform =
3966: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 3967: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3968: }
3969: }
1.25 raeburn 3970: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3971: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3972: }
1.71 raeburn 3973: my ($currcanclone,@code_order,$cloner_instcode);
3974: my %codedefaults;
3975: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3976: \@code_order);
3977: if ($settings->{'cloners'}) {
3978: unless ($settings->{'cloners'} eq '*') {
3979: my @currclone = split(/,/,$settings->{'cloners'});
3980: foreach my $item (@currclone) {
3981: unless ($item eq '*') {
3982: if (($item !~ /\:/) && ($item =~ /=/)) {
3983: $cloner_instcode = 1;
3984: }
3985: }
3986: }
3987: }
3988: }
3989: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3990: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3991: if (ref($canclone) eq 'HASH') {
3992: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3993: if ($settings->{'internal.coursecode'}) {
3994: my @posscodes;
3995: if (@code_order > 0) {
3996: $currcanclone = 'instcode';
3997: foreach my $item (@{$canclone->{'instcode'}}) {
3998: if (grep(/^\Q$item\E$/,@code_order)) {
3999: push(@posscodes,$item);
4000: }
4001: }
4002: my $codestr = join(' + ',@posscodes);
4003: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
4004: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
4005: }
4006: }
4007: }
4008: } elsif ($canclone eq 'domain') {
4009: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
4010: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
4011: $currcanclone = 'domain';
4012: }
4013: if ($clonedefaults) {
4014: if ($settings->{'cloners'} ne '') {
4015: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
4016: } else {
4017: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
4018: }
4019: $clonedefaults = '<br /><br />'.$clonedefaults;
4020: }
4021: }
1.1 raeburn 4022: if (!defined($categoriesform)) {
1.15 raeburn 4023: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 4024: }
1.12 raeburn 4025: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 4026: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 4027:
1.9 raeburn 4028: my $replace;
4029: if ($crstype eq 'Community') {
4030: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
4031: } else {
4032: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
4033: }
1.84 raeburn 4034: my ($editmap,$editsyllabus);
4035: unless ($noedit) {
4036: $editmap = (' 'x2).
4037: '<a href="javascript:openbrowser'.
4038: "('display','url','sequence')\">".
4039: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
4040: &mt('Modification may make assessment data inaccessible!').
4041: '</span>';
4042: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
1.124 raeburn 4043: '</a>');
1.84 raeburn 4044: }
1.1 raeburn 4045: my %items = (
1.3 raeburn 4046: 'url' => {
1.84 raeburn 4047: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 4048: input => 'textbox',
1.55 raeburn 4049: size => '55',
1.19 faziophi 4050: advanced => 1
1.1 raeburn 4051: },
4052: 'description' => {
1.3 raeburn 4053: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 4054: input => 'textbox',
1.55 raeburn 4055: size => '55',
1.1 raeburn 4056: },
1.24 raeburn 4057: 'owner' => {
4058: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
4059: },
1.25 raeburn 4060: 'co-owners' => {
4061: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
4062: },
1.63 raeburn 4063: 'clonedfrom' => {
4064: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
4065: },
1.1 raeburn 4066: 'courseid' => {
1.3 raeburn 4067: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
4068: &mt('internal, optional').')',
1.1 raeburn 4069: input => 'textbox',
4070: size => '25',
4071: },
1.64 raeburn 4072: 'uniquecode' => {
4073: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
4074: },
1.1 raeburn 4075: 'cloners' => {
1.3 raeburn 4076: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 4077: &mt('Owner and Coordinators included automatically').
4078: $clonedefaults,
1.1 raeburn 4079: input => 'textbox',
1.41 www 4080: size => '40'
1.1 raeburn 4081: },
4082: 'rolenames' => {
1.3 raeburn 4083: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 4084: '('.$replace.')',
1.1 raeburn 4085: input => 'textbox',
4086: size => '20',
1.19 faziophi 4087: advanced => 1
1.1 raeburn 4088: },
1.88 raeburn 4089: 'syllabus' => {
4090: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 4091: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 4092: $editsyllabus,
1.1 raeburn 4093: },
4094: 'hidefromcat' => {
1.3 raeburn 4095: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 4096: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
4097: input => 'radio',
4098: },
4099: 'categories' => {
1.3 raeburn 4100: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 4101: &mt('Display Categories').'</a>',
4102: input => 'textbox',
4103: size => '25',
4104: },
1.35 raeburn 4105: 'loncaparev' => {
4106: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
4107: },
1.55 raeburn 4108: 'defaultcredits' => {
4109: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4110: },
1.1 raeburn 4111: );
4112: my $datatable;
4113: my $count = 0;
4114: foreach my $item (@{$ordered}) {
1.56 raeburn 4115: my $colspan;
1.1 raeburn 4116: if ($item eq 'hidefromcat') {
4117: next if (!$can_toggle_cat);
4118: } elsif ($item eq 'categories') {
4119: next if (!$can_categorize);
1.64 raeburn 4120: } elsif ($item eq 'uniquecode') {
4121: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4122: }
1.56 raeburn 4123: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
1.124 raeburn 4124: $colspan = 2;
1.56 raeburn 4125: }
1.1 raeburn 4126: $count ++;
1.19 faziophi 4127: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 4128: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4129: } else {
1.56 raeburn 4130: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4131: }
1.1 raeburn 4132: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 4133: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4134: } elsif ($item eq 'cloners') {
4135: my $includeempty = 1;
4136: my $num = 0;
1.56 raeburn 4137: $datatable .= '</td><td align="right">'.
4138: &Apache::loncommon::start_data_table().
1.1 raeburn 4139: &Apache::loncommon::start_data_table_row().
4140: '<td><span class="LC_nobreak"><label>'.
4141: &mt('Any user in any domain:').
4142: ' <input type="radio" name="cloners_all" value="1" ';
4143: if ($settings->{$item} eq '*') {
4144: $datatable .= ' checked="checked" ';
4145: }
4146: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 4147: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4148: (' 'x2).'<label>'.
4149: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4150: if ($settings->{$item} ne '*') {
4151: $datatable .= ' checked="checked" ';
4152: }
4153: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 4154: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4155: &Apache::loncommon::end_data_table_row().
4156: &Apache::loncommon::end_data_table().
1.56 raeburn 4157: '<table><tr><td align="left"><b>'.&mt('Or').
4158: '</b></td></tr></table>'.
1.1 raeburn 4159: &Apache::loncommon::start_data_table();
4160: my @cloners;
4161: if ($settings->{$item} eq '') {
1.80 raeburn 4162: unless ($noedit) {
4163: my $default;
4164: if ($currcanclone eq 'domain') {
4165: $default = '0';
4166: }
4167: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 4168: }
1.1 raeburn 4169: } elsif ($settings->{$item} ne '*') {
4170: my @entries = split(/,/,$settings->{$item});
4171: if (@entries > 0) {
4172: foreach my $entry (@entries) {
4173: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4174: if ($udom =~ /^$match_domain$/) {
4175: unless (&Apache::lonnet::domain($udom)) {
4176: next;
4177: }
4178: } else {
4179: next;
4180: }
1.1 raeburn 4181: if ($uname eq '*') {
4182: $datatable .=
4183: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4184: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4185: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4186: '</b><input type="hidden" name="cloners_dom_'.$num.
4187: '" value="'.$udom.'" /></span><br />'.
4188: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4189: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4190: &mt('Delete').'</label></span></td>'.
4191: &Apache::loncommon::end_data_table_row();
4192: $num ++;
1.23 raeburn 4193: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4194: unless (grep(/^\Q$entry\E$/,@cloners)) {
4195: push(@cloners,$entry);
4196: }
1.1 raeburn 4197: }
4198: }
4199: }
4200: }
4201: my $add_domtitle = &mt('Any user in additional domain:');
4202: if ($settings->{$item} eq '*') {
4203: $add_domtitle = &mt('Any user in specific domain:');
4204: } elsif ($settings->{$item} eq '') {
4205: $add_domtitle = &mt('Any user in other domain:');
4206: }
4207: my $cloners_str = join(',',@cloners);
4208: $datatable .= &Apache::loncommon::start_data_table_row().
4209: '<td align="left"><span class="LC_nobreak">'.
4210: $add_domtitle.'</span><br />'.
4211: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 4212: $includeempty,undef,undef,
4213: undef,undef,$noedit).
1.1 raeburn 4214: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4215: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4216: &Apache::loncommon::end_data_table().
1.56 raeburn 4217: '<table><tr><td align="left"><b>'.&mt('And').
4218: '</b></td></tr></table>'.
1.1 raeburn 4219: &Apache::loncommon::start_data_table().
4220: &Apache::loncommon::start_data_table_row().
4221: '<td align="left">'.
4222: &mt('Specific users').' (<tt>'.
4223: &mt('user:domain,user:domain').'</tt>)<br />'.
4224: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 4225: $items{$item}{'size'},$disabled).
1.1 raeburn 4226: '</td>'.&Apache::loncommon::end_data_table_row().
4227: &Apache::loncommon::end_data_table();
1.71 raeburn 4228: if (@code_order > 0) {
4229: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4230: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4231: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4232: \%cat_items,\@codetitles,
4233: \%cat_titles,\%cat_order);
4234: my $showncodes = 'off';
4235: my $checkedoff = ' checked="checked"';
4236: my $checkedon = '';
4237: if ($cloner_instcode) {
4238: $checkedon = $checkedoff;
4239: $checkedoff = '';
4240: $showncodes = 'on';
4241: }
4242: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4243: '</b></td></tr></table>'.
4244: &Apache::loncommon::start_data_table().
4245: &Apache::loncommon::start_data_table_row().
4246: '<td align="left"><span class="LC_nobreak">'.
4247: &mt('Cloning by official course(s) based on course category').(' 'x2).
4248: '<label>'.
1.80 raeburn 4249: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4250: (' ').
4251: '<label>'.
1.80 raeburn 4252: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 4253: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4254: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 4255: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 4256: '</td>'.&Apache::loncommon::end_data_table_row().
4257: &Apache::loncommon::end_data_table();
4258: }
1.1 raeburn 4259: } elsif ($item eq 'rolenames') {
1.56 raeburn 4260: $datatable .= '</td><td align="right">'.
4261: &Apache::loncommon::start_data_table();
1.9 raeburn 4262: my @roles;
4263: if ($crstype eq 'Community') {
4264: @roles = ('co');
4265: } else {
4266: @roles = ('cc');
4267: }
4268: push (@roles,('in','ta','ep','ad','st'));
4269: foreach my $role (@roles) {
1.1 raeburn 4270: $datatable .= &Apache::loncommon::start_data_table_row().
4271: '<td align="left"><span class="LC_nobreak">'.
4272: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4273: '</span></td><td align="left">'.
4274: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4275: $settings->{$role.'.plaintext'},
1.80 raeburn 4276: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4277: &Apache::loncommon::end_data_table_row();
4278: }
4279: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4280: } elsif ($item eq 'categories') {
1.80 raeburn 4281: my $launcher;
4282: if ($noedit) {
4283: $launcher = $disabled;
4284: } else {
4285: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4286: }
1.3 raeburn 4287: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4288: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4289: $items{$item}{size},$launcher);
1.24 raeburn 4290: } elsif ($item eq 'owner') {
4291: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4292: if ($owner =~ /:/) {
4293: my ($ownername,$ownerdom) = split(':',$owner);
4294: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4295: } elsif ($owner ne '') {
4296: $owner = &Apache::loncommon::plainname($owner,$cdom);
4297: } else {
4298: $owner = &mt('None specified');
4299: }
4300: $datatable .= $owner;
1.63 raeburn 4301: } elsif ($item eq 'clonedfrom') {
4302: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4303: my $clonedfrom = &mt('None');
4304: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 4305: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 4306: if ($clonesrcinfo{'description'}) {
1.124 raeburn 4307: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
1.63 raeburn 4308: }
4309: }
4310: $datatable .= $clonedfrom;
1.64 raeburn 4311: } elsif ($item eq 'uniquecode') {
1.124 raeburn 4312: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
1.64 raeburn 4313: if ($code) {
4314: $datatable .= $code;
4315: }
1.25 raeburn 4316: } elsif ($item eq 'co-owners') {
4317: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4318: my @currcoown;
4319: if ($coowners) {
4320: @currcoown = split(',',$coowners);
4321: }
4322: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4323: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4324: $datatable .= &show_autocoowners(@currcoown);
4325: } else {
1.80 raeburn 4326: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4327: }
4328: } else {
4329: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4330: $datatable .= &show_autocoowners(@currcoown);
4331: } else {
1.80 raeburn 4332: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4333: }
4334: }
1.88 raeburn 4335: } elsif ($item eq 'syllabus') {
1.60 raeburn 4336: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4337: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4338: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4339: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4340: if ($minimal =~/\w/) {
4341: if ($external =~ m{\Q$minimal\E$}) {
4342: undef($external);
4343: }
4344: } elsif ($uploaded =~/\w/) {
4345: if ($external =~ m{\Q$uploaded\E$}) {
4346: undef($external);
4347: }
4348: }
4349: } elsif ($external!~/\w/) {
4350: undef($external);
4351: }
4352: if ($external) {
4353: $datatable .= &mt('External URL');
4354: } elsif ($minimal) {
4355: $datatable .= &mt('Minimal template');
4356: } elsif ($uploaded) {
4357: $datatable .= &mt('Uploaded file');
4358: } else {
1.124 raeburn 4359: $datatable .= &mt('Standard template');
1.60 raeburn 4360: }
4361: $datatable .= (' ' x 2).
4362: &mt('[_1]View[_2]',
4363: '<a href="javascript:syllabusinfo();">',
1.124 raeburn 4364: '</a>');
1.35 raeburn 4365: } elsif ($item eq 'loncaparev') {
4366: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4367: my $showreqd;
4368: if ($loncaparev) {
1.36 raeburn 4369: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4370: &mt('Details').'</a>';
1.35 raeburn 4371: } else {
4372: $showreqd = &mt('No specific version required');
4373: }
4374: $datatable .= $showreqd;
1.1 raeburn 4375: } else {
1.80 raeburn 4376: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4377: }
4378: $datatable .= &item_table_row_end();
4379: }
4380: $$rowtotal += scalar(@{$ordered});
4381: return $datatable;
4382: }
4383:
4384: sub new_cloners_dom_row {
1.71 raeburn 4385: my ($newdom,$num,$default) = @_;
4386: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4387: if ($newdom ne '') {
1.71 raeburn 4388: if ($num eq $default) {
1.124 raeburn 4389: $checkedon = 'checked="checked" ';
1.71 raeburn 4390: } else {
4391: $checkedoff = 'checked="checked" ';
4392: }
1.1 raeburn 4393: $output .= &Apache::loncommon::start_data_table_row().
4394: '<td valign="top"><span class="LC_nobreak">'.
4395: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4396: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 4397: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4398: 'onchange="javascript:update_cloners('.
1.1 raeburn 4399: "'cloners_activate','$num'".');" />'.
4400: &mt('Yes').'</label>'.(' 'x2).
4401: '<label><input type="radio" '.
1.71 raeburn 4402: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4403: 'onchange="javascript:update_cloners('.
1.1 raeburn 4404: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4405: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4406: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4407: &Apache::loncommon::end_data_table_row();
4408: }
4409: return $output;
4410: }
4411:
4412: sub can_modify_catsettings {
1.12 raeburn 4413: my ($dom,$crstype) = @_;
1.1 raeburn 4414: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4415: my ($can_toggle_cat,$can_categorize);
4416: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4417: if ($crstype eq 'Community') {
4418: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4419: $can_toggle_cat = 1;
4420: }
4421: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4422: $can_categorize = 1;
4423: }
4424: } else {
4425: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4426: $can_toggle_cat = 1;
4427: }
4428: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4429: $can_categorize = 1;
4430: }
1.1 raeburn 4431: }
4432: }
4433: return ($can_toggle_cat,$can_categorize);
4434: }
4435:
4436: sub assign_course_categories {
1.9 raeburn 4437: my ($r,$crstype) = @_;
1.1 raeburn 4438: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4439: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4440: my $hascats = 0;
4441: my $cathash;
4442: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4443: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4444: $cathash = $domconf{'coursecategories'}{'cats'};
4445: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4446: foreach my $cat (keys(%{$cathash})) {
4447: next if ($cat eq 'instcode::0');
4448: unless ($crstype eq 'Community') {
4449: next if ($cat eq 'communities::0');
4450: }
4451: $hascats ++;
4452: }
1.1 raeburn 4453: }
4454: }
4455: my $catwin_js;
4456: if ($hascats) {
1.9 raeburn 4457: my $alert;
4458: if ($crstype eq 'Community') {
4459: $alert = &mt("Use 'Save' in the main window to save community categories");
4460: } else {
4461: $alert = &mt("Use 'Save' in the main window to save course categories");
4462: }
1.72 damieng 4463: &js_escape(\$alert);
1.1 raeburn 4464: $catwin_js = <<ENDSCRIPT;
4465: <script type="text/javascript">
4466:
4467: function updateCategories() {
4468: var newcategories = '';
4469: var unescapedcats = '';
4470: if (document.chgcats.usecategory.length) {
4471: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4472: if (document.chgcats.usecategory[i].checked == true) {
4473: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4474: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4475: }
4476: }
4477: if (newcategories.length > 0) {
4478: newcategories = newcategories.slice(0,-1);
4479: }
4480: if (unescapedcats.length > 0) {
4481: unescapedcats = unescapedcats.slice(0,-3);
4482: }
4483: } else {
4484: if (document.chgcats.usecategory.checked == true) {
4485: newcategories = document.chgcats.usecategory.value;
4486: unescapedcats = document.chgcats.catname.value;
4487: }
4488: }
4489: opener.document.display.categories.value = newcategories;
4490: opener.document.display.categories_display.value = unescapedcats;
4491: alert("$alert");
4492: self.close();
4493: return;
4494: }
4495:
4496: </script>
4497: ENDSCRIPT
4498: } else {
4499: my $onload;
4500: }
1.9 raeburn 4501: my ($crscat,$catcrs,$assign);
4502: if ($crstype eq 'Community') {
4503: $crscat = 'Community Categories';
4504: $catcrs = &mt('Categorize Community');
4505: $assign = &mt('Assign one or more categories to this community.')
4506: } else {
4507: $crscat = 'Course Categories';
4508: $catcrs = &mt('Categorize Course');
4509: $assign = &mt('Assign one or more categories to this course.')
4510: }
1.1 raeburn 4511: my $start_page =
1.9 raeburn 4512: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4513: {'only_body' => 1,});
4514: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4515: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4516: if ($hascats) {
4517: my %currsettings =
4518: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4519: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4520: $currsettings{'categories'},$crstype);
4521: if ($cattable eq '') {
4522: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4523: } else {
4524: $categoriesform .= $assign.'<br /><br />'.
4525: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4526: $cattable."\n".
4527: '<br /><input type="button" name="changes" value="'.
4528: &mt('Copy to main window').'" '.
4529: 'onclick="javascript:updateCategories()" /></form><br />';
4530: }
1.1 raeburn 4531: } else {
1.12 raeburn 4532: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4533: }
4534: $r->print($start_page.$categoriesform.$end_page);
4535: return;
4536: }
4537:
1.36 raeburn 4538: sub display_loncaparev_constraints {
4539: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.124 raeburn 4540: my ($reqdmajor,$reqdminor);
1.36 raeburn 4541: my $cid = $env{'request.course.id'};
4542: my $cdom = $env{'course.'.$cid.'.domain'};
4543: my $cnum = $env{'course.'.$cid.'.num'};
4544: my $output;
1.39 raeburn 4545: my %lt = &Apache::lonlocal::texthash (
4546: 'all' => 'all',
4547: 'section/group' => 'section/group',
4548: 'user' => 'user',
4549: );
1.66 raeburn 4550: &Apache::lonrelrequtils::init_global_hashes();
4551: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4552: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4553: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 4554: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4555: }
4556: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 4557: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 4558: @scopeorder = ('all','section/group','user');
1.67 raeburn 4559: my $now = time;
1.36 raeburn 4560: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4561: if (ref($resourcedata) eq 'HASH') {
4562: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 4563: my %found;
1.66 raeburn 4564: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4565: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 4566: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
4567: my $value = $resourcedata->{$key};
4568: if ($item eq 'examcode') {
4569: if (&Apache::lonnet::validCODE($value)) {
4570: $value = 'valid';
4571: } else {
4572: $value = '';
4573: }
4574: } elsif ($item eq 'printstartdate') {
1.67 raeburn 4575: if ($value =~ /^\d+$/) {
1.70 raeburn 4576: if ($value > $now) {
4577: $value = 'future';
4578: }
4579: }
4580: } elsif ($item eq 'printenddate') {
4581: if ($value =~ /^\d+$/) {
4582: if ($value < $now) {
4583: $value = 'past';
4584: }
4585: }
4586: }
4587: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
4588: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4589: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 4590: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 4591: }
4592: }
4593: }
4594: }
1.79 raeburn 4595: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
4596: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 4597: my $value = $resourcedata->{$key};
1.79 raeburn 4598: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 4599: if ($value =~ /$valuematch/) {
4600: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 4601: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 4602: $found{$item}{'rev'} =
1.76 raeburn 4603: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 4604: last;
4605: }
4606: }
4607: }
4608: }
1.76 raeburn 4609: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
4610: my $regexp;
4611: if ($item eq 'maplevelrecurse') {
4612: $regexp = '\.(?:sequence|page)___\(rec\)\.';
4613: }
4614: if ($regexp ne '') {
4615: if ($key =~ /$regexp.*\.(\w+)$/) {
4616: my $name = $1;
4617: my $value = $resourcedata->{$key};
4618: if ($name eq 'type') {
4619: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
4620: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
4621: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
4622: }
4623: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
4624: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
4625: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
4626: $found{$name}{'rev'} =
4627: $Apache::lonnet::needsrelease{'parameter::::'.$item};
4628: }
4629: }
4630: }
1.70 raeburn 4631: foreach my $item (keys(%found)) {
4632: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4633: my $rev = $found{$item}{'rev'};
4634: my $valname = $found{$item}{'valname'};
1.76 raeburn 4635: my $extra = $found{$item}{'extra'};
1.70 raeburn 4636: my ($middle,$scope,$which,$level,$map,$resource);
4637: my $start = $cid.'.';
4638: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4639: $middle = $1;
4640: $which = $2;
4641: $scope = 'user';
4642: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4643: $middle = $1;
4644: $which = $2;
4645: $scope = 'section/group';
4646: } else {
4647: $scope = 'all';
4648: }
4649: my $what="$stdname=$valname";
1.76 raeburn 4650: if ($extra) {
4651: $what .= "<br/>$extra<br />";
4652: }
1.70 raeburn 4653: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4654: $level = 'general';
4655: if ($scope eq 'all') {
4656: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4657: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4658: push(@{$fromparam{$rev}{$scope}},$what);
4659: }
4660: } else {
4661: push(@{$fromparam{$rev}{$scope}},$what);
4662: }
4663: } else {
4664: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4665: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4666: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4667: }
4668: } else {
4669: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4670: }
4671: }
4672: $rowspan{$rev} ++;
1.76 raeburn 4673: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 4674: $level = 'folder';
4675: $map = $1;
4676: if ($scope eq 'all') {
4677: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4678: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4679: push(@{$bymap{$map}{$rev}{$scope}},$what);
4680: }
4681: } else {
4682: push(@{$bymap{$map}{$rev}{$scope}},$what);
4683: }
4684: } else {
4685: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4686: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4687: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4688: }
4689: } else {
4690: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4691: }
4692: }
4693: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4694: $level = 'resource';
4695: $resource = $1;
4696: if ($scope eq 'all') {
4697: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4698: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4699: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4700: }
4701: } else {
4702: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4703: }
4704: } else {
4705: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4706: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4707: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4708: }
4709: } else {
4710: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 4711: }
4712: }
4713: }
4714: }
4715: }
4716: if (keys(%fromparam)) {
4717: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4718: &Apache::loncommon::start_data_table().
4719: &Apache::loncommon::start_data_table_header_row().
4720: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4721: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4722: &Apache::loncommon::end_data_table_header_row();
4723: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 4724: my ($major,$minor) = split(/\./,$rev);
4725: ($reqdmajor,$reqdminor) =
4726: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4727: $output .= &Apache::loncommon::start_data_table_row().
4728: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4729: my $newrow;
4730: foreach my $scope (@scopeorder) {
4731: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4732: if ($newrow) {
4733: $output .= &Apache::loncommon::continue_data_table_row();
4734: }
1.39 raeburn 4735: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4736: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4737: $output .= '<td>'.$which.'</td><td>'.
4738: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4739: }
4740: $output .= &Apache::loncommon::end_data_table_row();
4741: $newrow = 1;
4742: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4743: if ($newrow) {
4744: $output .= &Apache::loncommon::continue_data_table_row();
4745: }
1.39 raeburn 4746: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4747: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4748: &Apache::loncommon::end_data_table_row();
4749: $newrow = 1;
4750: }
4751: }
4752: }
4753: $output .= &Apache::loncommon::end_data_table().'<br />';
4754: }
4755: }
4756:
1.66 raeburn 4757: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4758: my $now = time;
4759: if (keys(%comm_blocks) > 0) {
4760: foreach my $block (keys(%comm_blocks)) {
4761: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 4762: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 4763: if (ref($comm_blocks{$block}) eq 'HASH') {
4764: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4765: ' '.&mt('set by [_1]',
4766: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4767: }
4768: next;
4769: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4770: my ($start,$end) = ($1,$2);
4771: next if ($end < $now);
4772: }
4773: if (ref($comm_blocks{$block}) eq 'HASH') {
4774: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4775: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4776: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 4777: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 4778: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4779: ' '.
4780: &mt('set by [_1]',
4781: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4782: }
4783: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 4784: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 4785: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4786: ' '.
4787: &mt('set by [_1]',
4788: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4789:
4790: }
4791: }
4792: }
4793: }
4794: if (keys(%fromblocks)) {
4795: my %lt = (
4796: docs => 'Content blocking',
4797: printout => 'Printout generation',
4798: timer => 'Timed quiz trigger',
4799: );
4800: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4801: &Apache::loncommon::start_data_table().
4802: &Apache::loncommon::start_data_table_header_row().
4803: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4804: '<th>'.&mt('Event(s)').'</th>'.
4805: &Apache::loncommon::end_data_table_header_row();
4806: foreach my $type ('docs','printout','timer') {
4807: if (ref($fromblocks{$type}) eq 'HASH') {
4808: foreach my $rev (keys(%{$fromblocks{$type}})) {
4809: my ($major,$minor) = split(/\./,$rev);
1.124 raeburn 4810: ($reqdmajor,$reqdminor) =
1.66 raeburn 4811: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4812: $output .= &Apache::loncommon::start_data_table_row().
4813: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4814: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4815: $output .= $event.'<br />';
4816: }
4817: $output =~ s{\Q<br />\E$}{};
4818: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4819: }
4820: }
4821: }
4822: $output .= &Apache::loncommon::end_data_table().'<br />';
4823: }
4824: }
4825:
1.36 raeburn 4826: if (defined($navmap)) {
4827: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 4828: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 4829: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 4830: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 4831: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 4832: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4833: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4834: my $valanon=&get_param_description($stdtype,'anonsurvey');
4835: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 4836: my %checkedrev;
1.85 raeburn 4837: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 4838: my @parts = @{$res->parts()};
4839: my $symb = $res->symb();
4840: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 4841: if ($res->is_tool()) {
4842: my $rev = $rev_exttool;
4843: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
4844: $allmaps{$enclosing_map} = 1;
4845: next;
4846: }
1.36 raeburn 4847: foreach my $part (@parts) {
4848: if (exists($anonsubms{$symb."\0".$part})) {
4849: my $rev = $rev_anonsurv;
4850: my $what="$stdname=$valanon";
4851: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4852: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4853: push(@{$bysubmission{$symb}{$rev}},$what);
4854: }
4855: } else {
4856: push(@{$bysubmission{$symb}{$rev}},$what);
4857: }
4858: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4859: unless ($checkedrev{'anonsurvey'}) {
4860: my ($major,$minor) = split(/\./,$rev);
4861: ($reqdmajor,$reqdminor) =
4862: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4863: $reqdmajor,$reqdminor);
4864: $checkedrev{'anonsurvey'} = 1;
4865: }
1.36 raeburn 4866: }
4867: if (exists($randtrysubms{$symb."\0".$part})) {
4868: my $rev = $rev_randtry;
4869: my $what="$stdname=$valrandtry";
4870: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4871: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4872: push(@{$bysubmission{$symb}{$rev}},$what);
4873: }
4874: } else {
4875: push(@{$bysubmission{$symb}{$rev}},$what);
4876: }
4877: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4878: unless ($checkedrev{'randomizetry'}) {
4879: my ($major,$minor) = split(/\./,$rev);
4880: ($reqdmajor,$reqdminor) =
4881: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4882: $reqdmajor,$reqdminor);
4883: $checkedrev{'randomizetry'} = 1;
4884: }
1.36 raeburn 4885: }
4886: }
4887: my %responses = $res->responseTypes();
4888: foreach my $key (keys(%responses)) {
1.66 raeburn 4889: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4890: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4891: unless ($checkedrev{$key}) {
4892: my ($major,$minor) = split(/\./,$rev);
4893: ($reqdmajor,$reqdminor) =
4894: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4895: $reqdmajor,$reqdminor);
4896: $checkedrev{$key} = 1;
1.124 raeburn 4897: }
1.66 raeburn 4898: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4899: $allmaps{$enclosing_map} = 1;
4900: }
4901: }
4902: }
4903: if (keys(%byresource) > 0) {
4904: foreach my $symb (keys(%byresource)) {
4905: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4906: $allmaps{$map} = 1;
4907: }
4908: }
4909: if (keys(%bymap) > 0) {
4910: foreach my $map (keys(%bymap)) {
4911: $allmaps{$map} = 1;
4912: }
4913: }
4914: foreach my $map (keys(%allmaps)) {
4915: my $mapres = $navmap->getResourceByUrl($map);
4916: if (ref($mapres)) {
1.68 raeburn 4917: my $mapsymb = $mapres->symb();
4918: $toshow{$mapsymb} = 1;
1.36 raeburn 4919: my $pcslist = $mapres->map_hierarchy();
4920: if ($pcslist ne '') {
4921: foreach my $pc (split(/,/,$pcslist)) {
4922: my $res = $navmap->getByMapPc($pc);
4923: if (ref($res)) {
4924: my $symb = $res->symb();
4925: unless ($symb eq '______') {
4926: $toshow{$symb} = 1;
4927: }
4928: }
4929: }
4930: }
4931: }
4932: }
4933: }
1.117 raeburn 4934: my $supptools = &Apache::lonnet::count_supptools($cnum,$cdom,1,1);
1.36 raeburn 4935: my $mapres_header = '<h4>'.
4936: &mt('Requirements for specific folders or resources').
4937: '</h4>';
4938: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4939: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4940: $output .= $mapres_header;
4941: }
4942: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4943: my $title = 'Version Constraints';
4944: my $start_page =
4945: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4946: $r->print($start_page.$top_header);
4947: if ($output) {
4948: $r->print($output);
1.86 raeburn 4949: if (defined($navmap) || $supptools) {
1.36 raeburn 4950: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4951: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4952: }
4953: $r->print('<br /><br />');
4954: } else {
4955: $r->print('<p class="LC_info">'.
4956: &mt('No version requirements from resource content or settings.').
4957: '</p>');
4958: }
4959: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4960: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4961: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4962: return 1;
4963: }
1.36 raeburn 4964: return;
4965: }
4966:
4967: sub show_contents_view {
1.39 raeburn 4968: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 4969: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
4970: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4971: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4972: my $showmaincontent;
4973: if ((ref($navmap)) &&
4974: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4975: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
4976: (keys(%{$bycrsrestype}) > 0))) {
4977: $showmaincontent = 1;
4978: }
4979: if ($showmaincontent || $supptools) {
4980: $r->print(&Apache::loncommon::start_data_table());
4981: }
4982: if ($showmaincontent) {
4983: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 4984: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 4985: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 4986: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4987: '<th>'.&mt('Attribute/Setting').'</th>'.
4988: &Apache::loncommon::end_data_table_header_row().
4989: &Apache::loncommon::start_data_table_row().
1.58 raeburn 4990: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 4991: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
4992: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4993: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4994: my $curRes;
4995: my $depth = 0;
4996: my %parent = ();
4997: my $startcount = 5;
4998: my $lastcontainer = $startcount;
4999: while ($curRes = $it->next()) {
5000: if ($curRes == $it->BEGIN_MAP()) {
5001: $depth++;
5002: $parent{$depth}= $lastcontainer;
5003: }
5004: if ($curRes == $it->END_MAP()) {
5005: $depth--;
5006: $lastcontainer = $parent{$depth};
5007: }
5008: my $indent;
5009: for (my $i=0; $i<$depth; $i++) {
5010: $indent.= $whitespace;
5011: }
5012: if (ref($curRes)) {
5013: my $symb = $curRes->symb();
5014: my $ressymb = $symb;
5015: my $srcf = $curRes->src();
5016: my $title = &Apache::lonnet::gettitle($srcf);
5017: if (($curRes->is_sequence()) || ($curRes->is_page())) {
5018: next unless($toshow->{$symb});
5019: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
5020: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5021: if ($curRes->is_page()) {
5022: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
5023: }
5024: my $rowspan = 1;
5025: if (ref($bymap->{$url}) eq 'HASH') {
5026: $rowspan = scalar(keys(%{$bymap->{$url}}));
5027: }
5028: $r->print(&Apache::loncommon::start_data_table_row().
5029: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 5030: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 5031: $r->print(&Apache::loncommon::end_data_table_row());
5032: } else {
5033: my $rowspan;
5034: if (ref($byresource->{$symb}) eq 'HASH') {
5035: $rowspan += scalar(keys(%{$byresource->{$symb}}));
5036: }
5037: if (ref($bysubmission->{$symb}) eq 'HASH') {
5038: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
5039: }
5040: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5041: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
5042: }
1.85 raeburn 5043: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5044: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
5045: }
1.36 raeburn 5046: next if (!$rowspan);
5047: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
5048: &mt('Problem').'" />';
5049: $r->print(&Apache::loncommon::start_data_table_row().
5050: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
5051: my $newrow;
5052: if (ref($byresource->{$symb}) eq 'HASH') {
5053: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
5054: if ($newrow) {
5055: $r->print(&Apache::loncommon::continue_data_table_row());
5056: }
5057: $r->print('<td valign="middle">'.$rev.'</td><td>');
5058: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
5059: $r->print('<table border="0">');
5060: foreach my $scope (@{$scopeorder}) {
5061: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5062: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5063: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
5064: $r->print('<td>'.$which.'</td><td>'.
5065: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
5066: '</td>');
5067: }
5068: $r->print('</tr>');
5069: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5070: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 5071: '<td> </td><td>'.
5072: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
5073: }
5074: }
5075: $r->print('</table>');
5076: }
5077: $r->print('</td>');
5078: $r->print(&Apache::loncommon::end_data_table_row());
5079: $newrow = 1;
5080: }
5081: }
5082: if (ref($bysubmission->{$symb}) eq 'HASH') {
5083: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
5084: if ($newrow) {
5085: $r->print(&Apache::loncommon::continue_data_table_row());
5086: }
5087: $r->print('<td>'.$rev.'</td><td>');
5088: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
5089: $r->print(&mt('Submissions to: ').' '.
5090: join(', ',@{$bysubmission->{$symb}{$rev}}));
5091: }
5092: $r->print('</td>');
5093: $r->print(&Apache::loncommon::end_data_table_row());
5094: $newrow = 1;
5095: }
5096: }
5097: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5098: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
5099: if ($newrow) {
5100: $r->print(&Apache::loncommon::continue_data_table_row());
5101: }
5102: $r->print('<td>'.$rev.'</td><td>');
5103: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
5104: $r->print(&mt('Response Type(s): ').' '.
5105: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
5106: }
5107: $r->print('</td>');
5108: }
5109: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 5110: $newrow = 1;
5111: }
5112: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5113: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
5114: if ($newrow) {
5115: $r->print(&Apache::loncommon::continue_data_table_row());
5116: }
5117: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
5118: }
1.86 raeburn 5119: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5120: }
5121: }
5122: }
5123: }
1.86 raeburn 5124: }
5125: if ($supptools) {
5126: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5127: $r->print(&Apache::loncommon::start_data_table_header_row().
5128: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5129: '<th>'.&mt('Resource Type').'</th>'.
5130: &Apache::loncommon::end_data_table_header_row().
5131: &Apache::loncommon::start_data_table_row().
5132: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
5133: '<td valign="middle">'.
5134: $Apache::lonrelrequtils::exttool{'major'}.'.'.
5135: $Apache::lonrelrequtils::exttool{'minor'}.
5136: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
5137: $supptools).'</td>'.
5138: &Apache::loncommon::end_data_table_row());
5139: }
5140: if ($showmaincontent || $supptools) {
1.36 raeburn 5141: $r->print(&Apache::loncommon::end_data_table());
5142: }
1.66 raeburn 5143: return;
1.36 raeburn 5144: }
5145:
5146: sub releases_by_map {
1.39 raeburn 5147: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 5148: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.124 raeburn 5149: my $newrow = 0;
1.36 raeburn 5150: if (ref($bymap->{$url}) eq 'HASH') {
5151: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 5152: if ($newrow) {
5153: $r->print(&Apache::loncommon::end_data_table_row().
5154: &Apache::loncommon::continue_data_table_row());
5155: }
1.36 raeburn 5156: $r->print('<td valign="middle">'.$rev.'</td><td>');
5157: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
5158: $r->print('<table border="0">');
5159: foreach my $scope (@{$scopeorder}) {
5160: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5161: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5162: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
5163: $r->print('<td>'.$which.'</td><td>'.
5164: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
5165: '</td>');
5166: }
5167: $r->print('</tr>');
5168: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5169: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 5170: '</td><td> </td><td>'.
5171: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
5172: }
5173: }
5174: $r->print('</table>');
5175: }
5176: $r->print('</td>');
1.73 raeburn 5177: $newrow = 1;
1.36 raeburn 5178: }
5179: } else {
5180: $r->print('<td colspan="2"> </td>');
5181: }
5182: return;
5183: }
5184:
5185: sub get_param_description {
1.70 raeburn 5186: my ($stdtype,$value,$regexp) = @_;
5187: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 5188: if ($stdtype =~ /^string/) {
5189: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5190: } elsif ($stdtype eq 'date_interval') {
5191: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
5192: }
1.70 raeburn 5193: if ($regexp) {
1.74 raeburn 5194: if ($stdtype =~ /^string/) {
5195: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
5196: } elsif ($stdtype eq 'date_interval') {
5197: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
5198: }
1.70 raeburn 5199: if (ref($parammatches) eq 'ARRAY') {
5200: @possibles = @{$parammatches};
5201: } else {
5202: undef($regexp);
5203: $name = $value;
5204: }
5205: }
5206: unless ($regexp) {
5207: $name = $value;
5208: if (ref($paramstrings) eq 'ARRAY') {
5209: @possibles = @{$paramstrings};
5210: } else {
1.76 raeburn 5211: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
5212: if ($name == 0) {
5213: $name = &mt('Never');
5214: } elsif (($name ne '') && ($name !~ /\D/)) {
5215: $name = &Apache::lonlocal::locallocaltime($name);
5216: }
5217: }
1.70 raeburn 5218: return $name;
5219: }
1.36 raeburn 5220: }
1.70 raeburn 5221: foreach my $possibilities (@possibles) {
1.36 raeburn 5222: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 5223: my $gotregexmatch = '';
5224: if ($regexp) {
5225: last if ($gotregexmatch);
5226: my ($item,$pattern) = @{ $possibilities };
5227: if ($value =~ /$pattern/) {
5228: if (ref($paramstrings) eq 'ARRAY') {
5229: foreach my $possibles (@{$paramstrings}) {
5230: next unless (ref($possibles) eq 'ARRAY');
5231: my ($thing,$description) = @{$possibles};
5232: if ($thing eq $item) {
5233: $name = $description;
5234: $gotregexmatch = 1;
5235: last;
5236: }
5237: }
5238: last if ($gotregexmatch);
5239: }
5240: }
5241: } else {
5242: my ($thing,$description) = @{ $possibilities };
5243: if ($thing eq $value) {
5244: $name = $description;
5245: last;
5246: }
1.36 raeburn 5247: }
5248: }
5249: return $name;
5250: }
5251:
1.66 raeburn 5252: sub update_releasereq {
5253: my $readmap = 1;
5254: my $getrelreq = 1;
5255: if (ref($modified_courses) eq 'ARRAY') {
5256: foreach my $item (@{$modified_courses}) {
5257: if (ref($item) eq 'ARRAY') {
5258: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5259: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5260: $chome,$crstype,$cdom.'_'.$cnum,
5261: $readmap,$getrelreq);
5262: }
5263: }
5264: $modified_courses = [];
5265: }
5266: undef($registered_cleanup);
5267: return;
5268: }
5269:
1.25 raeburn 5270: sub show_autocoowners {
5271: my (@currcoown) = @_;
1.56 raeburn 5272: 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 5273: if (@currcoown > 0) {
5274: $output .= '<br />'.&mt('Current co-owners are:').' '.
5275: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5276: } else {
5277: $output .= '<br />'.&mt('Currently no co-owners.');
5278: }
5279: return $output;
5280: }
5281:
5282: sub coowner_invitations {
1.80 raeburn 5283: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5284: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5285: my $pendingcoowners =
5286: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5287: if ($pendingcoowners) {
5288: @pendingcoown = split(',',$pendingcoowners);
5289: }
1.80 raeburn 5290: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5291: @currcoown = @{$currcoownref};
1.80 raeburn 5292: }
5293: my $disabled;
5294: if ($noedit) {
5295: $disabled = ' disabled="disabled"';
5296: }
1.25 raeburn 5297: my $ccrole = 'cc';
5298: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5299: foreach my $key (sort(keys(%ccroles))) {
5300: my ($ccname,$ccdom,$role) = split(':',$key);
5301: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5302: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5303: push(@othercoords,$ccname.':'.$ccdom);
5304: }
5305: }
5306: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5307: if ($coowner_rows) {
5308: $output .= &Apache::loncommon::start_data_table();
5309: if (@currcoown) {
5310: $output .= &Apache::loncommon::start_data_table_row().
5311: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5312: foreach my $person (@currcoown) {
5313: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5314: $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 5315: }
5316: $output .= '</td>'.
5317: &Apache::loncommon::end_data_table_row();
5318: }
5319: if ($pendingcoowners) {
5320: $output .= &Apache::loncommon::start_data_table_row().
5321: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5322: foreach my $person (@pendingcoown) {
5323: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5324: $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 5325: }
5326: $output .= '</td>'.
5327: &Apache::loncommon::end_data_table_row();
5328: }
5329: if (@othercoords) {
5330: $output .= &Apache::loncommon::start_data_table_row().
5331: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5332: foreach my $person (@othercoords) {
5333: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5334: $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 5335: }
5336: $output .= '</td>'.
5337: &Apache::loncommon::end_data_table_row();
5338: }
5339: $output .= &Apache::loncommon::end_data_table();
5340: } else {
5341: $output = &mt('There are no coordinators to select as co-owners');
5342: }
5343: return $output;
5344: }
5345:
5346: sub manage_coownership {
1.80 raeburn 5347: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5348: my (@pendingcoown,@currcoown);
1.25 raeburn 5349: my $pendingcoowners =
5350: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5351: if ($pendingcoowners) {
5352: @pendingcoown = split(',',$pendingcoowners);
5353: }
1.80 raeburn 5354: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5355: @currcoown = @{$currcoownref};
1.80 raeburn 5356: }
5357: my $disabled;
5358: if ($noedit) {
5359: $disabled = ' disabled="disabled"';
5360: }
1.25 raeburn 5361: my ($is_coowner,$is_pending,$output);
5362: my $uname = $env{'user.name'};
5363: my $udom = $env{'user.domain'};
5364: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5365: $is_coowner = 1;
5366: }
5367: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5368: $is_pending = 1;
5369: }
5370: if (@currcoown && ($is_coowner || $is_pending)) {
5371: $output = &Apache::loncommon::start_data_table();
5372: }
5373: if (@currcoown) {
5374: if ($is_coowner || $is_pending) {
5375: $output .= &Apache::loncommon::start_data_table().
5376: &Apache::loncommon::start_data_table_row().'<td>';
5377: }
5378: $output .= &mt('Current co-owners are:').' '.
5379: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5380: if ($is_coowner || $is_pending) {
5381: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5382: }
5383: }
5384: if ($is_coowner || $is_pending) {
5385: if (@currcoown) {
5386: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5387: }
5388: $output .= '<span class="LC_nobreak">';
5389: if ($is_coowner) {
1.90 raeburn 5390: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5391: } else {
1.90 raeburn 5392: $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).
5393: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5394: }
5395: $output .= '</span>';
5396: if (@currcoown) {
5397: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5398: }
5399: }
5400: if (@currcoown && ($is_coowner || $is_pending)) {
5401: $output .= &Apache::loncommon::end_data_table();
5402: }
5403: return $output;
5404: }
5405:
1.1 raeburn 5406: sub print_localization {
1.80 raeburn 5407: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5408: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5409: return;
5410: }
5411: my %items = (
5412: languages => {
1.17 faziophi 5413: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5414: &mt("(overrides individual user preference)"),
1.1 raeburn 5415: input => 'selectbox',
5416: },
5417: timezone => {
1.17 faziophi 5418: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5419: input => 'selectbox',
5420: },
5421: datelocale => {
1.17 faziophi 5422: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5423: input => 'selectbox',
5424: },
5425: );
1.80 raeburn 5426: my ($datatable,$disabled);
1.1 raeburn 5427: my $count = 0;
1.80 raeburn 5428: if ($noedit) {
5429: $disabled = ' disabled="disabled"';
5430: }
1.1 raeburn 5431: foreach my $item (@{$ordered}) {
5432: $count ++;
1.56 raeburn 5433: my $colspan;
5434: unless ($item eq 'languages') {
1.80 raeburn 5435: $colspan = 2;
1.56 raeburn 5436: }
5437: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5438: if ($item eq 'timezone') {
5439: my $includeempty = 1;
5440: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5441: my $onchange;
5442: unless ($noedit) {
5443: $onchange = ' onchange="javascript:toggleTimeZone();"';
5444: }
5445: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5446: $datatable .=
1.115 raeburn 5447: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5448: $includeempty,$id,$disabled);
5449: my $tzsty = 'none';
5450: if ($timezone ne '') {
5451: $tzsty = 'block';
5452: }
5453: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5454: '<span class="LC_nobreak">'.
5455: &mt('Override individual user preference?').
5456: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5457: '</span></div>';
1.1 raeburn 5458: } elsif ($item eq 'datelocale') {
5459: my $includeempty = 1;
5460: my $locale_obj = &Apache::lonlocal::getdatelocale();
5461: my $currdatelocale;
5462: if (ref($locale_obj)) {
5463: $currdatelocale = $locale_obj->id();
5464: }
5465: $datatable .=
5466: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5467: undef,$includeempty,$disabled);
1.1 raeburn 5468: } else {
5469: if ($settings->{$item} eq '') {
1.124 raeburn 5470: unless ($noedit) {
1.80 raeburn 5471: $datatable .= '</td><td align="right">'.
5472: &Apache::loncommon::select_language('languages_0','',1);
5473: }
1.1 raeburn 5474: } else {
5475: my $num = 0;
1.3 raeburn 5476: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5477: $datatable .= '</td><td align="right"><br />'.
5478: &Apache::loncommon::start_data_table();
1.1 raeburn 5479: if (@languages > 0) {
1.3 raeburn 5480: my %langchoices = &get_lang_choices();
1.1 raeburn 5481: foreach my $lang (@languages) {
5482: my $showlang = $lang;
1.3 raeburn 5483: if (exists($langchoices{$lang})) {
5484: $showlang = $langchoices{$lang};
1.1 raeburn 5485: }
5486: $datatable .=
5487: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5488: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5489: &mt('Language:').'<b> '.$showlang.
5490: '</b><input type="hidden" name="languages_'.$num.
5491: '" value="'.$lang.'" /></span><br />'.
5492: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5493: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5494: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5495: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5496: $num ++;
5497: }
5498: }
1.80 raeburn 5499: unless ($noedit) {
5500: $datatable .=
5501: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5502: '<td align="left"><span class="LC_nobreak">'.
5503: &mt('Additional language:'). '</span><br />'.
5504: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5505: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5506: '</td>'.&Apache::loncommon::end_data_table_row();
1.124 raeburn 5507: }
5508: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5509: }
5510: }
5511: $datatable .= &item_table_row_end();
5512: }
5513: $$rowtotal += scalar(@{$ordered});
5514: return $datatable;
5515: }
5516:
1.3 raeburn 5517: sub get_lang_choices {
5518: my %langchoices;
5519: foreach my $id (&Apache::loncommon::languageids()) {
5520: my $code = &Apache::loncommon::supportedlanguagecode($id);
5521: if ($code) {
5522: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5523: }
5524: }
5525: return %langchoices;
5526: }
5527:
1.1 raeburn 5528: sub print_feedback {
1.80 raeburn 5529: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5530: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5531: return;
5532: }
5533: my %items = (
1.3 raeburn 5534: 'question.email' => {
5535: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5536: input => 'textbox',
5537: size => '50',
5538: },
5539:
1.3 raeburn 5540: 'comment.email' => {
5541: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5542: input => 'textbox',
5543: size => '50',
5544: },
5545:
1.3 raeburn 5546: 'policy.email' => {
5547: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5548: input => 'textbox',
5549: size => '50',
5550: },
5551: );
5552: my $datatable;
5553: my $count = 0;
5554: my ($cnum) = &get_course();
5555: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5556: my @sections = sort( { $a <=> $b } keys(%sections));
5557: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5558: currone => 'Current recipient:',
5559: currmult => 'Current recipients:',
5560: add => 'Additional recipient:',
5561: del => 'Delete?',
5562: sec => 'Sections:',
1.1 raeburn 5563: );
1.80 raeburn 5564: my $disabled;
5565: if ($noedit) {
5566: $disabled = ' disabled="disabled"';
5567: }
1.1 raeburn 5568: foreach my $item (@{$ordered}) {
5569: $count ++;
1.20 faziophi 5570: if ($position eq 'top') {
5571: $datatable .= &item_table_row_start($items{$item}{text},$count);
5572: } else {
1.56 raeburn 5573: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5574: }
1.1 raeburn 5575: if ($position eq 'top') {
5576: my $includeempty = 0;
1.94 raeburn 5577: $datatable .= '</td><td align="right">'.
5578: &user_table($cdom,$item,\@sections,
1.80 raeburn 5579: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5580: } else {
1.3 raeburn 5581: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5582: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5583: }
5584: $datatable .= &item_table_row_end();
5585: }
5586: $$rowtotal += scalar(@{$ordered});
5587: return $datatable;
5588: }
5589:
5590: sub user_table {
1.80 raeburn 5591: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5592: my $output;
5593: if ($currvalue eq '') {
1.80 raeburn 5594: unless ($noedit) {
5595: $output .= &select_recipient($item,'0',$cdom,$sections);
5596: }
1.1 raeburn 5597: } else {
5598: my $num = 0;
5599: my @curr = split(/,/,$currvalue);
1.56 raeburn 5600: $output .= '<table class="LC_data_table">';
1.1 raeburn 5601: my ($currusers);
1.80 raeburn 5602: my $disabled;
5603: if ($noedit) {
5604: $disabled = ' disabled="disabled"';
5605: }
1.1 raeburn 5606: foreach my $val (@curr) {
5607: next if ($val eq '');
5608: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5609: my @selsec;
5610: if ($seclist) {
5611: $seclist =~ s/(^\(|\)$)//g;
5612: @selsec = split(/\s*;\s*/,$seclist);
5613: }
5614: $currusers .= '<tr>'.
5615: '<td valign="top"><span class="LC_nobreak">'.
5616: '<label><input type="checkbox" '.
1.80 raeburn 5617: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5618: $lt->{'del'}.'</label>'.
5619: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5620: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5621: &Apache::loncommon::aboutmewrapper(
5622: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5623: $uname,$udom,'aboutuser');
5624: if (ref($sections) eq 'ARRAY') {
5625: if (@{$sections}) {
5626: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5627: &select_sections($item,$num,$sections,
1.80 raeburn 5628: \@selsec,$noedit);
1.1 raeburn 5629: }
5630: }
5631: $currusers .= '</span></td></tr>';
5632: $num ++;
5633: }
5634: if ($num) {
1.10 raeburn 5635: $output .= '<tr>'.
1.1 raeburn 5636: '<td align="left"><i>';
1.20 faziophi 5637: if ($num == 1) {
1.1 raeburn 5638: $output .= $lt->{'currone'};
5639: } else {
1.21 raeburn 5640: $output .= $lt->{'currmult'};
1.1 raeburn 5641: }
5642: $output .= '</i><br />'.
5643: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5644: '</tr>';
1.1 raeburn 5645: }
1.80 raeburn 5646: unless ($noedit) {
5647: $output .=
5648: '<tr>'.
1.1 raeburn 5649: '<td align="left"><span class="LC_nobreak"><i>'.
5650: $lt->{'add'}.'</i></span><br />'.
5651: &select_recipient($item,$num,$cdom,$sections).
5652: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5653: '</td></tr>';
5654: }
5655: $output .= '</table>';
1.1 raeburn 5656: }
5657: return $output;
5658: }
5659:
5660: sub select_recipient {
5661: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5662: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5663: my $selectlink =
5664: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5665: $item.'_udom_'.$num,'only');
1.1 raeburn 5666: my $output =
1.10 raeburn 5667: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5668: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5669: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5670: if (ref($sections) eq 'ARRAY') {
5671: if (@{$sections}) {
5672: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5673: &select_sections($item,$num,$sections,$selected).'</td>';
5674: }
5675: }
5676: $output .= '<td valign="top">'.
5677: $selectlink.'</td></tr></table>';
5678: return $output;
5679: }
5680:
5681: sub select_sections {
1.127 raeburn 5682: my ($item,$num,$sections,$selected,$noedit,$allval) = @_;
1.80 raeburn 5683: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5684: if (ref($selected) eq 'ARRAY') {
5685: @currsecs = @{$selected};
5686: }
5687: if (!@currsecs) {
5688: $allsec = ' selected="selected"';
5689: }
1.80 raeburn 5690: if ($noedit) {
5691: $disabled = ' disabled="disabled"';
5692: }
1.1 raeburn 5693: if (ref($sections) eq 'ARRAY') {
5694: if (@{$sections}) {
5695: my $mult;
5696: if (@{$sections} > 1) {
5697: $mult = ' multiple="multiple"';
1.127 raeburn 5698: my $size;
1.1 raeburn 5699: if (@{$sections} > 3) {
1.127 raeburn 5700: $size = 4;
5701: } else {
5702: $size = 1 + scalar(@{$sections});
1.1 raeburn 5703: }
1.127 raeburn 5704: $mult .= ' size="'.$size.'"';
5705: }
5706: my $name = $item.'_sections';
5707: unless ($item eq 'hidetotals') {
5708: $name .= '_'.$num;
1.1 raeburn 5709: }
1.127 raeburn 5710: $output = '<select name="'.$name.'"'.$mult.$disabled.'>'.
5711: ' <option value="'.$allval.'"'.$allsec.'>'.&mt('All').'</option>';
1.1 raeburn 5712: foreach my $sec (@{$sections}) {
5713: my $is_sel;
5714: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
1.127 raeburn 5715: $is_sel = ' selected="selected"';
1.1 raeburn 5716: }
5717: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5718: }
5719: $output .= '</select>';
5720: }
5721: }
5722: return $output;
5723: }
5724:
5725: sub print_discussion {
1.80 raeburn 5726: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5727: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5728: return;
5729: }
5730: my %items = (
5731: 'plc.roles.denied' => {
1.10 raeburn 5732: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5733: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5734: &mt('(role-based)'),
1.1 raeburn 5735: input => 'checkbox',
5736: },
5737:
5738: 'plc.users.denied' => {
1.3 raeburn 5739: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5740: &mt('(specific user(s))'),
1.1 raeburn 5741: input => 'checkbox',
5742: },
5743:
5744: 'pch.roles.denied' => {
1.10 raeburn 5745: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5746: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5747: &mt('(role-based)'),
1.1 raeburn 5748: input => 'checkbox',
5749: },
5750:
5751: 'pch.users.denied' => {
1.3 raeburn 5752: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5753: &mt('(specific user(s))'),
1.1 raeburn 5754: input => 'checkbox',
5755: },
1.77 raeburn 5756:
5757: 'pac.roles.denied' => {
5758: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5759: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5760: &mt('(role-based)'),
5761: input => 'checkbox',
5762: },
5763:
5764: 'pac.users.denied' => {
5765: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5766: &mt('(specific user(s))'),
5767: input => 'checkbox',
5768: },
5769:
1.1 raeburn 5770: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5771: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5772: input => 'radio',
5773: },
5774:
5775: 'allow_discussion_post_editing' => {
1.3 raeburn 5776: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5777: input => 'checkbox',
5778: },
1.50 raeburn 5779: 'discussion_post_fonts' => {
5780: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5781: input => 'textbox',
5782: size => '20',
5783: },
1.1 raeburn 5784: );
5785: my $datatable;
5786: my $count;
5787: my ($cnum) = &get_course();
5788: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5789: my @sections = sort( { $a <=> $b } keys(%sections));
5790: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5791: currone => 'Disallowed:',
5792: currmult => 'Disallowed:',
5793: add => 'Disallow more:',
5794: del => 'Delete?',
5795: sec => 'Sections:',
1.1 raeburn 5796: );
5797: foreach my $item (@{$ordered}) {
5798: $count ++;
1.56 raeburn 5799: my $colspan;
5800: if ($item eq 'allow_limited_html_in_feedback') {
5801: $colspan = 2;
1.124 raeburn 5802: }
1.56 raeburn 5803: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5804: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5805: $datatable .= '</td><td align="right">'.
1.80 raeburn 5806: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5807: '</table>';
5808: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5809: $datatable .= '</td><td align="right">'.
5810: &user_table($cdom,$item,undef,
1.80 raeburn 5811: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5812: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5813: $datatable .= '</td><td align="right">'.
1.80 raeburn 5814: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5815: '</table>';
5816: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5817: $datatable .= '</td><td align="right">'.
5818: &user_table($cdom,$item,undef,
1.80 raeburn 5819: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5820: } elsif ($item eq 'pac.roles.denied') {
5821: $datatable .= '</td><td align="right">'.
1.80 raeburn 5822: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5823: '</table>';
5824: } elsif ($item eq 'pac.users.denied') {
5825: $datatable .= '</td><td align="right">'.
5826: &user_table($cdom,$item,undef,
1.80 raeburn 5827: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5828: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5829: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5830: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5831: $datatable .= '</td><td align="right"><br />'.
5832: &Apache::loncommon::start_data_table().
1.1 raeburn 5833: &Apache::loncommon::start_data_table_row().
5834: '<th align="left">'.&mt('Role').'</th><th>'.
5835: &mt('Sections').'</th>'.
5836: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5837: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5838: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5839: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5840: $datatable .= '</td><td align="right"><br />'.
5841: &Apache::loncommon::start_data_table().
1.50 raeburn 5842: &Apache::loncommon::start_data_table_row().
5843: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5844: '<th align="center">'.&mt('font-size').'</th>'.
5845: '<th align="center">'.&mt('font-weight').'</th>'.
5846: '<th align="center">'.&mt('font-style').'</th>'.
1.124 raeburn 5847: '<th align="center">'.&mt('Other css').'</th>'.
1.50 raeburn 5848: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5849: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5850: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5851: }
5852: $datatable .= &item_table_row_end();
5853: }
5854: $$rowtotal += scalar(@{$ordered});
5855: return $datatable;
5856: }
5857:
5858: sub role_checkboxes {
1.80 raeburn 5859: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5860: my @roles = ('st','ad','ta','ep','in');
5861: if ($crstype eq 'Community') {
5862: push(@roles,'co');
5863: } else {
5864: push(@roles,'cc');
5865: }
1.1 raeburn 5866: my $output;
5867: my (@current,@curr_roles,%currsec,@sections);
5868: if ($showsections) {
5869: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5870: @sections = sort( { $a <=> $b } keys(%sections));
5871: }
5872: if (ref($settings) eq 'HASH') {
5873: if ($settings->{$item}) {
5874: @current = split(',',$settings->{$item});
5875: if ($showsections) {
5876: foreach my $role (@current) {
5877: if ($role =~ /:/) {
5878: my ($trole,$sec) = split(':',$role);
5879: push(@curr_roles,$trole);
5880: if (ref($currsec{$trole}) eq 'ARRAY') {
5881: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5882: push(@{$currsec{$trole}},$sec);
5883: }
1.3 raeburn 5884: } else {
5885: $currsec{$trole} = [$sec];
1.1 raeburn 5886: }
5887: } else {
5888: push(@curr_roles,$role);
5889: }
5890: }
5891: @current = @curr_roles;
5892: }
5893: }
5894: }
5895: my $numinrow = 3;
5896: my $count = 0;
1.80 raeburn 5897: my $disabled;
5898: if ($noedit) {
1.124 raeburn 5899: $disabled = ' disabled="disabled"';
1.80 raeburn 5900: }
1.1 raeburn 5901: foreach my $role (@roles) {
5902: my $checked = '';
5903: if (grep(/^\Q$role\E$/,@current)) {
5904: $checked = ' checked="checked" ';
5905: }
1.9 raeburn 5906: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5907: if ($showsections) {
5908: $output .= &Apache::loncommon::start_data_table_row();
5909: } else {
5910: my $rem = $count%($numinrow);
5911: if ($rem == 0) {
5912: if ($count > 0) {
5913: $output .= '</tr>';
5914: }
5915: $output .= '<tr>';
5916: }
5917: }
1.30 raeburn 5918: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5919: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5920: $plrole.'</label></span></td>';
5921: if ($showsections) {
5922: $output .= '<td align="left">'.
1.80 raeburn 5923: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5924: '</td></tr>';
5925: }
5926: $count ++;
5927: }
5928: my %adv_roles =
5929: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5930: my $total = @roles;
5931: foreach my $role (sort(keys(%adv_roles))) {
5932: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5933: my $rolename = $3;
5934: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5935: my $checked = '';
5936: if (grep(/^\Q$value\E$/,@current)) {
5937: $checked = ' checked="checked" ';
5938: }
5939: if ($showsections) {
5940: $output .= &Apache::loncommon::start_data_table_row();
5941: } else {
5942: my $rem = $count%($numinrow);
5943: if ($rem == 0) {
5944: if ($count > 0) {
5945: $output .= '</tr>';
5946: }
5947: $output .= '<tr>';
5948: }
5949: }
1.30 raeburn 5950: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5951: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5952: '</label></span></td>';
5953: if ($showsections) {
5954: $output .= '<td>'.
1.80 raeburn 5955: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5956: '</td>'.&Apache::loncommon::end_data_table_row();
5957: }
5958: $total ++;
5959: $count ++;
5960: }
5961: }
5962: if (!$showsections) {
5963: my $rem = $total%($numinrow);
5964: my $colsleft = $numinrow - $rem;
5965: if ($colsleft > 1 ) {
5966: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5967: ' </td>';
5968: } elsif ($colsleft == 1) {
5969: $output .= '<td class="LC_left_item"> </td>';
5970: }
5971: $output .= '</tr>';
5972: }
5973: return $output;
5974: }
5975:
1.50 raeburn 5976: sub set_discussion_fonts {
1.80 raeburn 5977: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 5978: my ($classorder,$classtitles) = &discussion_vote_classes();
5979: my ($styleorder,$styleitems) = &discussion_vote_styles();
5980: my $output;
5981: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 5982: my $disabled;
5983: if ($noedit) {
5984: $disabled = ' disabled="disabled"';
5985: }
1.50 raeburn 5986: foreach my $cat (@{$classorder}) {
5987: my %curr = ();
5988: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5989: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5990: $output .= &Apache::loncommon::start_data_table_row().
5991: '<td>'.$classtitles->{$cat}.'</td>';
5992: if (ref($styleorder) eq 'ARRAY') {
5993: foreach my $item (@{$styleorder}) {
5994: $output .= '<td><span class="LC_nobreak">';
5995: my $selitem = $item;
5996: if ($item eq 'size') {
5997: my ($currsize,$currunit);
5998: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5999: ($currsize,$currunit) = ($1,$2);
6000: $curr{'size'} = $currunit;
6001: }
1.81 raeburn 6002: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 6003: ' ';
6004: $selitem = 'unit';
6005: }
6006: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 6007: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 6008: foreach my $val (@{$styleitems->{$item}}) {
6009: my $sel;
6010: if ($val eq $curr{$item}) {
6011: $sel = ' selected="selected"';
6012: }
6013: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
6014: }
6015: }
6016: }
6017: }
1.80 raeburn 6018: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 6019: }
6020: $output .= &Apache::loncommon::end_data_table_row();
6021: }
6022: return $output;
6023: }
6024:
6025: sub discussion_vote_classes {
6026: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
1.124 raeburn 6027: my %classtitles = &Apache::lonlocal::texthash(
1.50 raeburn 6028: 'twoplus' => 'Two sigma above mean',
6029: 'oneplus' => 'One sigma above mean',
6030: 'zero' => 'Within one sigma of mean',
6031: 'oneminus' => 'One sigma below mean',
6032: 'twominus' => 'Two sigma below mean',
6033: );
6034: return ($classorder,\%classtitles);
6035: }
6036:
6037: sub discussion_vote_styles {
6038: my $styleorder = ['size','weight','style'];
6039: my $styleitems = {
6040: size => ['','px','%','xx-small','x-small','small','medium','large',
6041: 'x-large','xx-large','smaller','larger'],
6042: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
6043: '500','600','700','800','900'],
6044: style => ['','normal','italic','oblique'],
6045: };
6046: return ($styleorder,$styleitems);
6047: }
6048:
1.1 raeburn 6049: sub print_classlists {
1.80 raeburn 6050: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 6051: my @ordered;
6052: if ($position eq 'top') {
6053: @ordered = ('default_enrollment_start_date',
6054: 'default_enrollment_end_date');
1.55 raeburn 6055: if ($crstype eq 'Course') {
6056: push(@ordered,'defaultcredits');
6057: }
1.1 raeburn 6058: } elsif ($position eq 'middle') {
1.56 raeburn 6059: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 6060: } else {
6061: @ordered = ('student_classlist_view',
1.26 raeburn 6062: 'student_classlist_opt_in',
6063: 'student_classlist_portfiles');
1.1 raeburn 6064: }
1.9 raeburn 6065: my %lt;
6066:
6067: if ($crstype eq 'Community') {
6068: %lt = &Apache::lonlocal::texthash (
6069: disabled => 'No viewable membership list',
6070: section => "Membership of viewer's section",
6071: all => 'List of all members',
6072: );
6073: } else {
6074: %lt = &Apache::lonlocal::texthash (
6075: disabled => 'No viewable classlist',
6076: section => "Classlist of viewer's section",
6077: all => 'Classlist of all students',
6078: );
6079: }
6080:
1.1 raeburn 6081: my %items = (
6082: 'default_enrollment_start_date' => {
1.3 raeburn 6083: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 6084: input => 'dates',
6085: },
6086: 'default_enrollment_end_date' => {
1.3 raeburn 6087: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 6088: input => 'dates',
6089: },
1.55 raeburn 6090: 'defaultcredits' => {
6091: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
6092: },
1.124 raeburn 6093:
1.1 raeburn 6094: 'nothideprivileged' => {
1.3 raeburn 6095: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 6096: input => 'checkbox',
6097: },
6098:
1.56 raeburn 6099: 'checkforpriv' => {
6100: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
6101: input => 'selectbox',
6102: },
6103:
1.1 raeburn 6104: 'student_classlist_view' => {
1.3 raeburn 6105: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 6106: input => 'selectbox',
1.9 raeburn 6107: options => \%lt,
1.1 raeburn 6108: order => ['disabled','all','section'],
6109: },
1.26 raeburn 6110: 'student_classlist_opt_in' => {
6111: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 6112: input => 'radio',
6113: },
6114:
6115: 'student_classlist_portfiles' => {
1.3 raeburn 6116: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 6117: input => 'radio',
6118: },
6119: );
6120: unless (($settings->{'student_classlist_view'} eq 'all') ||
6121: ($settings->{'student_classlist_view'} eq 'section')) {
6122: $settings->{'student_classlist_view'} = 'disabled';
6123: }
1.80 raeburn 6124: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6125: }
6126:
6127: sub print_appearance {
1.80 raeburn 6128: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6129: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6130: return;
6131: }
1.9 raeburn 6132: my $mathdef;
6133: if ($crstype eq 'Community') {
6134: $mathdef = &mt("None specified - use member's choice");
6135: } else {
6136: $mathdef = &mt("None specified - use student's choice");
6137: }
1.1 raeburn 6138: my %items = (
6139: 'default_xml_style' => {
1.3 raeburn 6140: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6141: '<a href="javascript:openbrowser'.
6142: "('display','default_xml_style'".
6143: ",'sty')".'">'.&mt('Select Style File').'</a>',
6144: input => 'textbox',
6145: size => 35,
6146: },
6147:
6148: 'pageseparators' => {
1.3 raeburn 6149: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6150: input => 'radio',
6151: },
6152: 'disable_receipt_display' => {
1.3 raeburn 6153: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6154: input => 'radio',
6155: },
6156: 'texengine' => {
1.3 raeburn 6157: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6158: input => 'selectbox',
6159: options => {
1.61 raeburn 6160: MathJax => 'MathJax',
1.1 raeburn 6161: mimetex => &mt('Convert to Images'),
6162: tth => &mt('TeX to HTML'),
6163: },
1.75 raeburn 6164: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6165: nullval => $mathdef,
1.1 raeburn 6166: },
6167: 'tthoptions' => {
1.3 raeburn 6168: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6169: input => 'textbox',
6170: size => 40,
6171: },
1.69 raeburn 6172: 'uselcmath' => {
6173: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6174: input => 'radio',
6175: },
6176: 'usejsme' => {
6177: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6178: input => 'radio',
6179: },
1.95 raeburn 6180: 'inline_chem' => {
6181: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6182: input => 'radio',
6183: },
1.114 raeburn 6184: 'extresource' => {
6185: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6186: input => 'selectbox',
6187: options => {
6188: iframe => 'In iframe',
6189: tab => 'In new tab',
6190: window => 'In pop-up window',
6191: },
6192: order => ['iframe','tab','window'],
6193: },
1.1 raeburn 6194: );
1.80 raeburn 6195: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6196: }
6197:
6198: sub print_grading {
1.127 raeburn 6199: my ($cdom,$cnum,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6200: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6201: return;
6202: }
6203: my %items = (
6204: 'grading' => {
1.3 raeburn 6205: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6206: &Apache::loncommon::help_open_topic('GradingOptions'),
6207: input => 'selectbox',
6208: options => {
6209: standard => &mt('Standard: shows points'),
1.34 www 6210: categories => &mt('Categories: shows points according to categories'),
1.11 www 6211: external => &mt('External: shows number of completed parts and totals'),
6212: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6213: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6214: },
1.34 www 6215: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6216: },
6217: 'rndseed' => {
1.3 raeburn 6218: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.127 raeburn 6219: '<br /><span class="LC_warning LC_nobreak">'.
1.1 raeburn 6220: &mt('Modifying this will make problems have different numbers and answers!').
6221: '</span>',
6222: input => 'selectbox',
6223: options => {
6224: '32bit' => '32bit',
6225: '64bit' => '64bit',
6226: '64bit2' => '64bit2',
6227: '64bit3' => '64bit3',
6228: '64bit4' => '64bit4',
6229: '64bit5' => '64bit5',
6230: },
6231: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6232: advanced => 1
1.1 raeburn 6233: },
6234: 'receiptalg' => {
1.3 raeburn 6235: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6236: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6237: input => 'selectbox',
6238: options => {
6239: receipt => 'receipt',
6240: receipt2 => 'receipt2',
6241: receipt3 => 'receipt3',
6242: },
6243: order => ['receipt','receipt2','receipt3'],
1.41 www 6244: advanced => 1
1.1 raeburn 6245: },
6246: 'disablesigfigs' => {
1.3 raeburn 6247: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6248: input => 'radio',
6249: },
6250: );
1.127 raeburn 6251: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit,$cnum);
1.1 raeburn 6252: }
6253:
6254: sub print_printouts {
1.80 raeburn 6255: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6256: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6257: return;
6258: }
6259: my %items = (
6260: problem_stream_switch => {
1.3 raeburn 6261: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6262: input => 'radio',
6263: },
6264: suppress_tries => {
1.3 raeburn 6265: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6266: input => 'radio',
6267: },
6268: default_paper_size => {
1.3 raeburn 6269: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6270: input => 'selectbox',
6271: options => {
6272: Letter => &mt('Letter').' [8 1/2x11 in]',
6273: Legal => &mt('Legal').' [8 1/2x14 in]',
6274: Tabloid => &mt('Tabloid').' [11x17 in]',
6275: Executive => &mt('Executive').' [7 1/2x10 in]',
6276: A2 => &mt('A2').' [420x594 mm]',
6277: A3 => &mt('A3').' [297x420 mm]',
6278: A4 => &mt('A4').' [210x297 mm]',
6279: A5 => &mt('A5').' [148x210 mm]',
6280: A6 => &mt('A6').' [105x148 mm]',
6281: },
6282: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6283: nullval => &mt('None specified'),
1.1 raeburn 6284: },
6285: print_header_format => {
1.3 raeburn 6286: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6287: input => 'checkbox',
6288: },
6289: disableexampointprint => {
1.3 raeburn 6290: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6291: input => 'radio',
6292: },
1.14 raeburn 6293: canuse_pdfforms => {
6294: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6295: input => 'selectbox',
6296: options => {
6297: 1 => &mt('Yes'),
6298: 0 => &mt('No'),
6299: },
6300: order => ['1','0'],
1.54 bisitz 6301: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6302: }
1.1 raeburn 6303: );
1.80 raeburn 6304: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6305: }
6306:
6307: sub print_spreadsheet {
1.80 raeburn 6308: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6309: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6310: return;
6311: }
6312: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6313: my %items = (
6314: spreadsheet_default_classcalc => {
1.3 raeburn 6315: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6316: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6317: "('display','spreadsheet_default_classcalc'".
6318: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6319: input => 'textbox',
6320: },
6321: spreadsheet_default_studentcalc => {
1.3 raeburn 6322: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6323: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6324: "('display','spreadsheet_default_calc'".
6325: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6326: input => 'textbox',
6327: },
6328: spreadsheet_default_assesscalc => {
1.3 raeburn 6329: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6330: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6331: "('display','spreadsheet_default_assesscalc'".
6332: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6333: input => 'textbox',
6334: },
6335: hideemptyrows => {
1.3 raeburn 6336: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6337: input => 'radio',
6338: },
6339: );
1.80 raeburn 6340: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6341: }
1.1 raeburn 6342:
6343: sub print_bridgetasks {
1.80 raeburn 6344: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6345: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6346: return;
6347: }
1.9 raeburn 6348: my ($stumsg,$msgnote);
6349: if ($crstype eq 'Community') {
6350: $stumsg = &mt('Send message to member');
6351: $msgnote = &mt('Message to member and add to user notes');
6352: } else {
6353: $stumsg = &mt('Send message to student');
6354: $msgnote = &mt('Message to student and add to user notes');
6355: }
1.1 raeburn 6356: my %items = (
6357: task_messages => {
1.3 raeburn 6358: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6359: input => 'selectbox',
6360: options => {
1.9 raeburn 6361: only_student => $stumsg,
6362: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6363: },
6364: order => ['only_student','student_and_user_notes_screen'],
6365: nullval => &mt('No message or record in user notes'),
6366: },
6367: task_grading => {
1.3 raeburn 6368: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6369: input => 'selectbox',
6370: options => {
6371: any => &mt('Grade BTs in any section'),
6372: section => &mt('Grade BTs only in own section')
6373: },
6374: order => ['any','section'],
6375: },
6376: suppress_embed_prompt => {
1.3 raeburn 6377: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6378: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6379: input => 'radio',
6380: },
6381: );
1.80 raeburn 6382: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6383: }
6384:
1.118 raeburn 6385: sub print_ltitools {
6386: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6387: my ($datatable,$disabled,$css_class,$dest);
1.121 raeburn 6388: if ($noedit) {
6389: $disabled = ' disabled="disabled"';
6390: }
1.120 raeburn 6391: my $itemcount = 1;
6392: unless ($context eq 'domain') {
6393: my %tooltypes = &Apache::loncommon::usable_exttools();
6394: unless ($tooltypes{'crs'}) {
6395: my $showtype = 'course';
6396: if ($crstype eq 'Community') {
6397: $showtype = lc($crstype);
6398: }
6399: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6400: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6401: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6402: if ($tooltypes{'dom'}) {
6403: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6404: '<i>'.$cdom.'</i>').
6405: '<br /><br />'.
6406: &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.");
6407: } else {
6408: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6409: '<br /><br />'.
6410: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6411: '<i>'.$cdom.'</i>');
6412:
6413: }
6414: $datatable .= '</tr>';
6415: $itemcount ++;
6416: return $datatable;
6417: }
6418: }
1.118 raeburn 6419: my %lt = <itools_names();
6420: my $maxnum = 0;
6421: my %ordered;
6422: if (ref($settings) eq 'HASH') {
6423: foreach my $item (keys(%{$settings})) {
6424: if (ref($settings->{$item}) eq 'HASH') {
6425: my $num = $settings->{$item}{'order'};
6426: $ordered{$num} = $item;
6427: }
6428: }
6429: }
6430:
6431: if ($context eq 'domain') {
6432: $dest = '/adm/domainprefs';
6433: } else {
6434: $dest = '/adm/courseprefs';
6435: }
6436: my ($switchserver,$switchmessage);
6437: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6438: if ($switchserver) {
6439: if ($context eq 'domain') {
6440: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6441: } elsif ($crstype eq 'Community') {
6442: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6443: } else {
6444: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6445: }
6446: }
6447: my $maxnum = scalar(keys(%ordered));
6448: my @courseroles = ('cc','in','ta','ep','st');
6449: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6450: my @fields = ('fullname','firstname','lastname','email','roles','user');
6451: if (keys(%ordered)) {
6452: my @items = sort { $a <=> $b } keys(%ordered);
6453: for (my $i=0; $i<@items; $i++) {
6454: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6455: my $item = $ordered{$items[$i]};
6456: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6457: if (ref($settings->{$item}) eq 'HASH') {
6458: $title = $settings->{$item}->{'title'};
6459: $url = $settings->{$item}->{'url'};
6460: $key = $settings->{$item}->{'key'};
6461: $usable = $settings->{$item}->{'usable'};
6462: $lifetime = $settings->{$item}->{'lifetime'};
6463: my $image = $settings->{$item}->{'image'};
6464: if ($image ne '') {
6465: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6466: }
6467: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6468: $sigsel{'HMAC-256'} = ' selected="selected"';
6469: } else {
6470: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6471: }
6472: }
6473: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6474: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6475: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6476: for (my $k=0; $k<=$maxnum; $k++) {
6477: my $vpos = $k+1;
6478: my $selstr;
6479: if ($k == $i) {
6480: $selstr = ' selected="selected" ';
6481: }
6482: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6483: }
6484: $datatable .= '</select>'.(' 'x2).
6485: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6486: &mt('Delete?').'</label></span></td>'.
6487: '<td colspan="2">'.
6488: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6489: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6490: (' 'x2).
6491: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6492: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6493: (' 'x2).
6494: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6495: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6496: (' 'x2).
6497: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6498: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6499: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6500: '<br /><br />'.
1.120 raeburn 6501: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6502: ' value="'.$url.'" /></span>'.
6503: (' 'x2).
6504: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6505: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6506: if ($key ne '') {
6507: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6508: if ($noedit) {
6509: $datatable .= ': ['.&mt('not shown').']';
6510: } elsif ($switchserver) {
6511: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6512: } else {
6513: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6514: }
6515: $datatable .= '</span> '.(' 'x2);
6516: } elsif (!$switchserver) {
6517: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6518: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6519: '</span> '.(' 'x2);
6520: }
6521: if ($switchserver) {
6522: if ($usable ne '') {
6523: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6524: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6525: '<span class="LC_nobreak">'.&mt('Change secret?').
6526: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6527: (' 'x2).
6528: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6529: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6530: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6531: '</div>';
6532: } elsif ($key eq '') {
6533: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6534: } else {
6535: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6536: }
6537: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6538: } else {
6539: if ($usable ne '') {
6540: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6541: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6542: '<span class="LC_nobreak">'.&mt('Change?').
6543: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6544: (' 'x2).
6545: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6546: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6547: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6548: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6549: '<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>'.
6550: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6551: } else {
6552: $datatable .=
6553: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6554: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6555: '<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>'.
6556: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6557: }
6558: }
6559: $datatable .= '</fieldset>'.
6560: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6561: '<span class="LC_nobreak">'.&mt('Display target:');
6562: my %currdisp;
6563: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6564: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6565: $currdisp{'window'} = ' checked="checked"';
6566: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6567: $currdisp{'tab'} = ' checked="checked"';
6568: } else {
6569: $currdisp{'iframe'} = ' checked="checked"';
6570: }
6571: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6572: $currdisp{'width'} = $1;
6573: }
6574: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6575: $currdisp{'height'} = $1;
6576: }
6577: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6578: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6579: } else {
6580: $currdisp{'iframe'} = ' checked="checked"';
6581: }
6582: foreach my $disp ('iframe','tab','window') {
6583: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6584: $lt{$disp}.'</label>'.(' 'x2);
6585: }
6586: $datatable .= (' 'x4);
6587: foreach my $dimen ('width','height') {
6588: $datatable .= '<label>'.$lt{$dimen}.' '.
6589: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6590: (' 'x2);
6591: }
6592: $datatable .= '</span><br />'.
6593: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6594: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6595: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6596: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6597: '</textarea></div><div style=""></div><br />';
6598: my %units = (
6599: 'passback' => 'days',
6600: 'roster' => 'seconds',
6601: );
6602: foreach my $extra ('passback','roster') {
6603: my $validsty = 'none';
6604: my $currvalid;
6605: my $checkedon = '';
6606: my $checkedoff = ' checked="checked"';
6607: if ($settings->{$item}->{$extra}) {
6608: $checkedon = $checkedoff;
6609: $checkedoff = '';
6610: $validsty = 'inline-block';
6611: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6612: $currvalid = $settings->{$item}->{$extra.'valid'};
6613: }
6614: }
6615: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6616: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6617: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6618: &mt('No').'</label>'.(' 'x2).
6619: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6620: &mt('Yes').'</label></span></div>'.
6621: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6622: '<span class="LC_nobreak">'.
6623: &mt("until at least [_1] $units{$extra} after launch",
6624: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6625: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6626: }
6627: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6628: if ($imgsrc) {
6629: $datatable .= $imgsrc.
6630: '<label><input type="checkbox" name="ltitools_image_del"'.
6631: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6632: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6633: } else {
6634: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6635: }
6636: if ($switchserver) {
6637: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6638: } else {
6639: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6640: }
6641: $datatable .= '</span></fieldset>';
6642: my (%checkedfields,%rolemaps,$userincdom);
6643: if (ref($settings->{$item}) eq 'HASH') {
6644: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6645: %checkedfields = %{$settings->{$item}->{'fields'}};
6646: }
6647: $userincdom = $settings->{$item}->{'incdom'};
6648: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6649: %rolemaps = %{$settings->{$item}->{'roles'}};
6650: $checkedfields{'roles'} = 1;
6651: }
6652: }
6653: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6654: '<span class="LC_nobreak">';
6655: my $userfieldstyle = 'display:none;';
6656: my $seluserdom = '';
6657: my $unseluserdom = ' selected="selected"';
6658: foreach my $field (@fields) {
6659: my ($checked,$onclick,$id,$spacer);
6660: if ($checkedfields{$field}) {
6661: $checked = ' checked="checked"';
6662: }
6663: if ($field eq 'user') {
6664: $id = ' id="ltitools_user_field_'.$i.'"';
6665: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6666: if ($checked) {
6667: $userfieldstyle = 'display:inline-block';
6668: if ($userincdom) {
6669: $seluserdom = $unseluserdom;
6670: $unseluserdom = '';
6671: }
6672: }
6673: } else {
6674: $spacer = (' ' x2);
6675: }
6676: $datatable .= '<label>'.
6677: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6678: $lt{$field}.'</label>'.$spacer;
6679: }
6680: $datatable .= '</span>';
6681: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6682: '<span class="LC_nobreak"> : '.
6683: '<select name="ltitools_userincdom_'.$i.'">'.
6684: '<option value="">'.&mt('Select').'</option>'.
6685: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6686: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6687: '</select></span></div>';
6688: $datatable .= '</fieldset>'.
6689: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6690: foreach my $role (@courseroles) {
6691: my ($selected,$selectnone);
6692: if (!$rolemaps{$role}) {
6693: $selectnone = ' selected="selected"';
6694: }
6695: $datatable .= '<td style="text-align: center">'.
6696: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6697: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6698: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6699: foreach my $ltirole (@ltiroles) {
6700: unless ($selectnone) {
6701: if ($rolemaps{$role} eq $ltirole) {
6702: $selected = ' selected="selected"';
6703: } else {
6704: $selected = '';
6705: }
6706: }
6707: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6708: }
6709: $datatable .= '</select></td>';
6710: }
6711: $datatable .= '</tr></table></fieldset>';
6712: my %courseconfig;
6713: if (ref($settings->{$item}) eq 'HASH') {
6714: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6715: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6716: }
6717: }
1.129 ! raeburn 6718: $datatable .= '<fieldset><legend>';
! 6719: if ($context eq 'domain') {
! 6720: $datatable .= &mt('Configurable in course');
! 6721: } else {
! 6722: $datatable .= &mt('Configurable for each instance of tool in course');
! 6723: }
! 6724: $datatable .= '</legend><span class="LC_nobreak">';
1.118 raeburn 6725: foreach my $item ('label','title','target','linktext','explanation','append') {
6726: my $checked;
6727: if ($courseconfig{$item}) {
6728: $checked = ' checked="checked"';
6729: }
6730: $datatable .= '<label>'.
6731: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6732: $lt{'crs'.$item}.'</label> '."\n";
6733: }
6734: $datatable .= '</span></fieldset>'.
6735: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6736: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6737: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6738: my %custom = %{$settings->{$item}->{'custom'}};
6739: if (keys(%custom) > 0) {
6740: foreach my $key (sort(keys(%custom))) {
6741: $datatable .= '<tr><td><span class="LC_nobreak">'.
6742: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6743: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6744: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6745: ' value="'.$custom{$key}.'" /></td></tr>';
6746: }
6747: }
6748: }
6749: $datatable .= '<tr><td><span class="LC_nobreak">'.
6750: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6751: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6752: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6753: $datatable .= '</table></fieldset></td></tr>'."\n";
6754: $itemcount ++;
6755: }
6756: }
6757: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6758: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6759: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6760: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6761: '<select name="ltitools_add_pos"'.$chgstr.'>';
6762: for (my $k=0; $k<$maxnum+1; $k++) {
6763: my $vpos = $k+1;
6764: my $selstr;
6765: if ($k == $maxnum) {
6766: $selstr = ' selected="selected" ';
6767: }
6768: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6769: }
6770: $datatable .= '</select> '."\n".
6771: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6772: '<td colspan="2">'.
6773: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6774: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6775: (' 'x2).
6776: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6777: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6778: (' 'x2).
6779: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6780: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6781: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6782: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6783: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6784: '<br />'.
1.120 raeburn 6785: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6786: (' 'x2).
6787: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6788: if ($switchserver) {
6789: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6790: } else {
6791: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6792: (' 'x2).
1.119 raeburn 6793: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6794: '<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 6795: }
6796: $datatable .= '<br /><br />'.
6797: '</fieldset>'.
6798: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6799: '<span class="LC_nobreak">'.&mt('Display target:');
6800: my %defaultdisp;
6801: $defaultdisp{'iframe'} = ' checked="checked"';
6802: foreach my $disp ('iframe','tab','window') {
6803: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6804: $lt{$disp}.'</label>'.(' 'x2);
6805: }
6806: $datatable .= (' 'x4);
6807: foreach my $dimen ('width','height') {
6808: $datatable .= '<label>'.$lt{$dimen}.' '.
6809: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6810: (' 'x2);
6811: }
6812: $datatable .= '</span><br />'.
6813: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6814: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6815: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6816: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6817: '</div><div style=""></div><br />';
6818: my %units = (
6819: 'passback' => 'days',
6820: 'roster' => 'seconds',
6821: );
6822: my %defaulttimes = (
6823: 'passback' => '7',
6824: 'roster' => '300',
6825: );
6826: foreach my $extra ('passback','roster') {
6827: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6828: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6829: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6830: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6831: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6832: &mt('Yes').'</label></span></div>'.
6833: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6834: '<span class="LC_nobreak">'.
6835: &mt("until at least [_1] $units{$extra} after launch",
6836: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6837: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6838: }
6839: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6840: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6841: if ($switchserver) {
6842: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6843: } else {
6844: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6845: }
6846: $datatable .= '</span></fieldset>'.
6847: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6848: '<span class="LC_nobreak">';
6849: foreach my $field (@fields) {
6850: my ($id,$onclick,$spacer);
6851: if ($field eq 'user') {
6852: $id = ' id="ltitools_user_field_add"';
6853: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6854: } else {
6855: $spacer = (' ' x2);
6856: }
6857: $datatable .= '<label>'.
6858: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6859: $lt{$field}.'</label>'.$spacer;
6860: }
6861: $datatable .= '</span>'.
6862: '<div style="display:none;" id="ltitools_user_div_add">'.
6863: '<span class="LC_nobreak"> : '.
6864: '<select name="ltitools_add_userincdom">'.
6865: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6866: '<option value="0">'.&mt('username').'</option>'.
6867: '<option value="1">'.&mt('username:domain').'</option>'.
6868: '</select></span></div></fieldset>';
6869: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6870: foreach my $role (@courseroles) {
6871: my ($checked,$checkednone);
6872: $datatable .= '<td style="text-align: center">'.
6873: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6874: '<select name="ltitools_add_roles_'.$role.'">'.
6875: '<option value="" selected="selected">'.&mt('Select').'</option>';
6876: foreach my $ltirole (@ltiroles) {
6877: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6878: }
6879: $datatable .= '</select></td>';
6880: }
6881: $datatable .= '</tr></table></fieldset>'.
1.129 ! raeburn 6882: '<fieldset><legend>';
! 6883: if ($context eq 'domain') {
! 6884: $datatable .= &mt('Configurable in course');
! 6885: } else {
! 6886: $datatable .= &mt('Configurable for each instance of tool in course');
! 6887: }
! 6888: $datatable .= '</legend><span class="LC_nobreak">';
1.118 raeburn 6889: foreach my $item ('label','title','target','linktext','explanation','append') {
6890: $datatable .= '<label>'.
6891: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6892: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6893: }
6894: $datatable .= '</span></fieldset>'.
6895: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6896: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6897: '<tr><td><span class="LC_nobreak">'.
6898: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6899: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6900: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6901: '</table></fieldset>'."\n".
6902: '</td>'."\n".
6903: '</tr>'."\n";
6904: $itemcount ++;
6905: return $datatable;
6906: }
6907:
6908: sub ltitools_names {
6909: my %lt = &Apache::lonlocal::texthash(
6910: 'title' => 'Title',
6911: 'version' => 'Version',
6912: 'msgtype' => 'Message Type',
6913: 'sigmethod' => 'Signature Method',
6914: 'url' => 'URL',
6915: 'key' => 'Key',
6916: 'lifetime' => 'Nonce lifetime (s)',
6917: 'secret' => 'Secret',
6918: 'icon' => 'Icon',
6919: 'user' => 'User',
6920: 'fullname' => 'Full Name',
6921: 'firstname' => 'First Name',
6922: 'lastname' => 'Last Name',
6923: 'email' => 'E-mail',
6924: 'roles' => 'Role',
6925: 'window' => 'Window',
6926: 'tab' => 'Tab',
6927: 'iframe' => 'iFrame',
6928: 'height' => 'Height',
6929: 'width' => 'Width',
6930: 'linktext' => 'Default Link Text',
6931: 'explanation' => 'Default Explanation',
6932: 'passback' => 'Tool can return grades:',
6933: 'roster' => 'Tool can retrieve roster:',
6934: 'crstarget' => 'Display target',
6935: 'crslabel' => 'Course label',
6936: 'crstitle' => 'Course title',
6937: 'crslinktext' => 'Link Text',
6938: 'crsexplanation' => 'Explanation',
6939: 'crsappend' => 'Provider URL',
6940: );
6941: return %lt;
6942: }
6943:
1.87 raeburn 6944: sub print_lti {
6945: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6946: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6947: return;
6948: }
6949: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6950: my %menutitles = <imenu_titles();
6951: my ($domdefs,$displaydefs);
6952: if ($env{'request.lti.login'}) {
6953: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6954: my @domdefsmenu;
6955: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6956: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6957: $domdefs = &mt('Header shown').', ';
6958: }
6959: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6960: $domdefs .= &mt('Inline menu shown');
6961: }
6962: $domdefs =~ s/,\s$//;
6963: if (!$domdefs) {
6964: $domdefs = &mt('No header or inline menu shown');
6965: }
6966: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
6967: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6968: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6969: }
6970: }
6971: $displaydefs = &mt('Domain defaults');
6972: if (@domdefsmenu) {
6973: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
6974: if (@diffs) {
6975: my $missing;
6976: foreach my $item (@menuitems) {
6977: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
6978: $missing .= ' '.$menutitles{$item}.',';
6979: }
6980: }
6981: $missing =~ s/,$//;
6982: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
6983: } else {
6984: $displaydefs .= ': '.&mt('All shown');
6985: }
6986: } else {
6987: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
6988: }
6989: } else {
6990: $displaydefs = &mt('Domain defaults only available in LTI context');
6991: }
6992: my %items = (
6993: 'lti.override' => {
6994: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
6995: input => 'radio',
6996: },
6997: 'lti.topmenu' => {
6998: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
6999: input => 'radio',
7000: },
7001: 'lti.inlinemenu' => {
7002: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
7003: input => 'radio',
7004: },
7005: 'lti.lcmenu' => {
7006: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
7007: input => 'custom',
7008: },
7009: );
7010: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
7011: }
7012:
7013: sub lcmenu_checkboxes {
7014: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
7015: my @menuitems = ('fullname','coursetitle','role','logout','grades');
7016: my %menutitles = <imenu_titles();
7017: my (@current,@domdefs);
7018: if ($env{'request.lti.login'}) {
7019: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
7020: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
7021: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
7022: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
7023: }
7024: }
7025: }
7026: if (ref($settings) eq 'HASH') {
7027: if ($settings->{'lti.lcmenu'}) {
7028: unless ($settings->{'lti.lcmenu'} eq 'none') {
7029: @current = split(',',$settings->{'lti.lcmenu'});
7030: }
7031: } else {
7032: @current = @domdefs;
7033: }
7034: } else {
7035: @current = @domdefs;
7036: }
7037: my $numinrow = 3;
7038: my $count = 0;
7039: my $disabled;
7040: if ($noedit) {
7041: $disabled = ' disabled="disabled"';
7042: }
7043: my $output = '<table>';
7044: foreach my $item (@menuitems) {
7045: my $checked = '';
7046: if (grep(/^\Q$item\E$/,@current)) {
7047: $checked = ' checked="checked" ';
7048: }
7049: my $rem = $count%($numinrow);
7050: if ($rem == 0) {
7051: if ($count > 0) {
7052: $output .= '</tr>';
7053: }
7054: $output .= '<tr>';
7055: }
7056: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
7057: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
7058: $menutitles{$item}.'</label></span></td>';
7059: $count ++;
7060: }
7061: my $rem = $count%($numinrow);
7062: my $colsleft = $numinrow - $rem;
7063: if ($colsleft > 1 ) {
7064: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7065: ' </td>';
7066: } elsif ($colsleft == 1) {
7067: $output .= '<td class="LC_left_item"> </td>';
7068: }
7069: $output .= '</tr></table>';
7070: }
7071:
7072: sub ltimenu_titles {
7073: return &Apache::lonlocal::texthash(
7074: fullname => 'Full name',
7075: coursetitle => 'Course title',
7076: role => 'Role',
7077: logout => 'Logout',
7078: grades => 'Grades',
7079: );
7080: }
7081:
1.91 raeburn 7082: sub print_menuitems {
7083: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
7084: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
7085: return;
7086: }
7087: if ($position eq 'top') {
7088: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
7089: if ($settings->{'menucollections'} ne '') {
7090: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7091: my ($num,$value) = split(/\%/,$item);
7092: if ($num =~ /^\d+$/) {
7093: $defaultmenu_options{$num} = $num;
7094: }
7095: }
7096: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
7097: $addcollection = $defaultmenu_order[-1] + 1;
7098: } else {
7099: $addcollection = 1;
7100: }
7101: $defaultmenu_options{$addcollection} = $addcollection;
7102: my %items = (
7103: 'menudefault' => {
7104: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
7105: &mt("(can be overriden in deep-link context)"),
7106: input => 'selectbox',
7107: options => \%defaultmenu_options,
7108: order => \@defaultmenu_order,
7109: nullval => &mt('Standard (all menus shown)'),
7110: },
7111: );
7112: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
7113: } else {
7114: my %menu;
7115: my $count = 0;
7116: my $next = 1;
7117: my ($datatable,$disabled);
7118: if ($noedit) {
7119: $disabled = ' disabled="disabled"';
7120: }
7121:
7122: my ($ordered,$cats) = &menuitems_categories();
7123: my @order = @{$ordered};
7124: my %categories = %{$cats};
7125: my %menutitles = &menuitems_titles();
7126: my %menufields = &menuitems_fields();
7127:
7128: if ($settings->{'menucollections'} ne '') {
7129: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7130: my ($num,$value) = split(/\%/,$item);
7131: if ($num =~ /^\d+$/) {
7132: my @entries = split(/\&/,$value);
7133: foreach my $entry (@entries) {
7134: my ($name,$fields) = split(/=/,$entry);
7135: $menu{$num}{$name} = $fields;
7136: }
7137: }
7138: }
7139: if (keys(%menu)) {
7140: my @current = sort { $a <=> $b } keys(%menu);
7141: $next += $current[-1];
7142: foreach my $num (@current) {
7143: my %checked;
7144: my $on = ' checked="checked"';
7145: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7146: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7147: if ($menu{$num}{$key} eq 'y') {
7148: $checked{$key} = $on;
7149: }
7150: } else {
7151: foreach my $field (split(/,/,$menu{$num}{$key})) {
7152: if (exists($menufields{$field})) {
7153: $checked{$field} = $on;
7154: }
7155: }
7156: }
7157: }
7158: if (ref($menu{$num}) eq 'HASH') {
7159: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7160: foreach my $category (@order) {
7161: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7162: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7163: if ($category eq 'text') {
7164: $datatable .= '<i>'.&mt('Header').'</i><br />';
7165: }
1.91 raeburn 7166: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7167: if ($field eq 'disc') {
7168: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7169: }
1.91 raeburn 7170: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7171: $menufields{$field}.'</label><br />';
7172: }
7173: $datatable .= '</fieldset>';
7174: }
7175: }
7176: $datatable .= &item_table_row_end();
7177: $count ++;
7178: }
7179: }
7180: }
7181: } elsif ($noedit) {
7182: my $text = &mt('No menu collections defined for this course.');
7183: $datatable .= &item_table_row_start($text,$count);
7184: }
7185: unless ($noedit) {
7186: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7187: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7188: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7189: foreach my $category (@order) {
7190: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7191: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7192: foreach my $field (@{$categories{$category}}) {
7193: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7194: $menufields{$field}.'</label><br />';
7195: }
7196: $datatable .= '</fieldset>';
7197: }
7198: }
7199: $datatable .= &item_table_row_end();
7200: $count ++;
7201: }
7202: return $datatable;
7203: }
7204: }
7205:
7206: sub menuitems_abbreviations {
7207: my %briefcats = (
7208: text => 'pt',
7209: links => 'p',
7210: list => 'ps',
7211: inline => 's',
7212: );
7213: return %briefcats;
7214: }
7215:
7216: sub menuitems_categories {
7217: my @order = ('shown','text','links','list','inline');
7218: my %categories = (
1.94 raeburn 7219: shown => ['top','inline','foot','main'],
7220: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7221: links => ['pers','logo','menu','comm','roles','help','logout'],
1.128 raeburn 7222: list => ['about','prefs','port','wish','anno','rss','srch','brse'],
1.91 raeburn 7223: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7224: );
7225: return (\@order,\%categories);
7226: }
7227:
7228: sub menuitems_titles {
7229: return &Apache::lonlocal::texthash (
7230: shown => 'Hierarchy',
1.94 raeburn 7231: text => 'Text',
1.91 raeburn 7232: links => 'Header links',
7233: list => 'Drop-down list',
7234: inline => 'Inline links',
7235: );
7236: }
7237:
7238: sub menuitems_fields {
7239: return &Apache::lonlocal::texthash (
7240: top => 'Display header',
7241: inline => 'Display inline menu',
1.94 raeburn 7242: foot => 'Display footer',
1.91 raeburn 7243: main => 'Access to main menu',
1.92 raeburn 7244: pers => 'Personal',
7245: logo => 'LON-CAPA',
1.91 raeburn 7246: menu => 'Home',
7247: comm => 'Messages',
7248: roles => 'Roles/Courses',
7249: help => 'Help',
7250: logout => 'Logout',
7251: name => 'Fullname',
7252: crs => 'Course Title',
7253: role => 'Current Role',
1.94 raeburn 7254: disc => 'Discussion',
7255: fdbk => 'Feedback',
1.91 raeburn 7256: about => 'Information',
7257: prefs => 'Preferences',
7258: port => 'Portfolio',
7259: wish => 'Stored Links',
7260: anno => 'Calendar',
7261: rss => 'RSS Feeds',
1.128 raeburn 7262: srch => 'Search Library',
7263: brse => 'Browse Library',
1.91 raeburn 7264: cont => 'Contents',
7265: grades => 'Grades',
7266: chat => 'Chat',
7267: people => 'People',
7268: groups => 'Groups',
7269: resv => 'Reservations',
7270: syll => 'Syllabus',
7271: feeds => 'Feeds',
7272: );
7273: }
7274:
7275: sub menucollections_display {
7276: my ($collections) = @_;
7277: my %menu;
7278: my ($ordered,$cats) = &menuitems_categories();
7279: my @order = @{$ordered};
7280: my %categories = %{$cats};
7281: my %menutitles = &menuitems_titles();
7282: my %menufields = &menuitems_fields();
7283: foreach my $item (split(/;/,$collections)) {
7284: my ($num,$value) = split(/\%/,$item);
7285: if ($num =~ /^\d+$/) {
7286: my @entries = split(/\&/,$value);
7287: foreach my $entry (@entries) {
7288: my ($name,$fields) = split(/=/,$entry);
7289: $menu{$num}{$name} = $fields;
7290: }
7291: }
7292: }
7293: my $output = '';
7294: if (keys(%menu)) {
7295: my @current = sort { $a <=> $b } keys(%menu);
7296: foreach my $num (@current) {
7297: my %checked;
7298: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7299: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7300: if ($menu{$num}{$key} eq 'y') {
7301: $checked{$key} = 1;
7302: }
7303: } else {
7304: foreach my $field (split(/,/,$menu{$num}{$key})) {
7305: if (exists($menufields{$field})) {
7306: $checked{$field} = 1;
7307: }
7308: }
7309: }
7310: }
7311: if (ref($menu{$num}) eq 'HASH') {
7312: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7313: foreach my $category (@order) {
7314: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7315: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7316: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7317: if ($category eq 'text') {
7318: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
1.124 raeburn 7319: }
1.91 raeburn 7320: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7321: if ($field eq 'disc') {
7322: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7323: }
1.91 raeburn 7324: if ($checked{$field}) {
7325: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7326: } else {
7327: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7328: }
7329: $output .= '<br />';
7330: }
7331: $output .= '</fieldset>';
7332: }
7333: }
7334: $output .= '</fieldset>';
7335: }
7336: }
7337: }
7338: return $output;
7339: }
7340:
1.93 raeburn 7341: sub print_linkprotection {
1.102 raeburn 7342: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7343:
7344: my %linkprotection;
7345: my $count = 0;
7346: my $next = 1;
1.102 raeburn 7347: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7348: if ($noedit) {
7349: $disabled = ' disabled="disabled"';
7350: }
1.100 raeburn 7351: my %desc = &linkprot_names();
7352: my %lt = &Apache::lonlocal::texthash (
7353: 'requ' => 'Required settings',
7354: 'opti' => 'Optional settings',
7355: );
1.93 raeburn 7356: my $itemcount = 0;
7357:
1.100 raeburn 7358: my $ltiauth;
1.102 raeburn 7359: if ($context eq 'domain') {
7360: $ltiauth = 1;
7361: } else {
7362: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7363: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7364: } else {
7365: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7366: $ltiauth = $domdefs{'crsltiauth'};
7367: }
7368: }
7369: if ($context eq 'domain') {
7370: $dest = '/adm/domainprefs';
1.100 raeburn 7371: } else {
1.102 raeburn 7372: $dest = '/adm/courseprefs';
7373: }
1.124 raeburn 7374:
1.102 raeburn 7375: my ($switchserver,$switchmessage);
7376: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7377: if ($switchserver) {
7378: if ($context eq 'domain') {
1.124 raeburn 7379: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.102 raeburn 7380: } elsif ($crstype eq 'Community') {
7381: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7382: } else {
7383: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7384: }
1.100 raeburn 7385: }
1.99 raeburn 7386:
1.105 raeburn 7387: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7388: if (keys(%{$settings->{'linkprot'}})) {
7389: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7390: $next += $current[-1];
7391: for (my $i=0; $i<@current; $i++) {
7392: my $num = $current[$i];
7393: my %values;
1.102 raeburn 7394: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7395: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7396: } else {
7397: next;
7398: }
7399: my $selected;
7400: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7401: $selected = ' selected="selected"';
7402: }
7403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7404: $datatable .=
7405: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7406: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7407: &mt('Delete?').'</label></span></td><td>';
1.122 raeburn 7408: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7409: $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
7410: $passbacksty = 'none';
7411: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
7412: %checkedpassback = (
7413: 'no' => ' checked="checked"',
7414: 'yes' => '',
1.124 raeburn 7415: );
1.122 raeburn 7416: %checkedpassbackfmt = (
7417: '1p1' => ' checked="checked"',
7418: '1p0' => '',
7419: );
7420: if ($values{'passback'} ne '') {
7421: $passbacksty = 'inline-block';
7422: $checkedpassback{'yes'} = ' checked="checked"';
7423: $checkedpassback{'no'} = '';
7424: if ($values{'passbackformat'} eq '1.0') {
7425: $checkedpassbackfmt{'1p0'} = ' checked="checked"';
7426: $checkedpassbackfmt{'1p1'} = '';
7427: }
7428: }
1.100 raeburn 7429: if ($ltiauth) {
7430: $usersty = 'display:none';
1.112 raeburn 7431: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7432: %checkedrequser = (
7433: no => ' checked="checked"',
7434: yes => '',
7435: );
7436: if ($values{'requser'}) {
7437: $checkedrequser{'yes'} = $checkedrequser{'no'};
7438: $checkedrequser{'no'} = '';
7439: }
7440: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
1.124 raeburn 7441: if ($values{'requser'}) {
1.100 raeburn 7442: $usersty = 'display:inline-block';
7443: }
7444: }
1.112 raeburn 7445: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7446: %checkedreturnurl = (
7447: no => ' checked="checked"',
7448: yes => '',
7449: );
7450: if ($values{'returnurl'} ne '') {
7451: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7452: $checkedreturnurl{'no'} = '';
7453: }
1.100 raeburn 7454: $datatable .=
7455: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7456: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7457: (' 'x2).
1.100 raeburn 7458: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7459: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7460: (' 'x2).
1.100 raeburn 7461: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7462: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7463: if ($values{'key'} ne '') {
1.100 raeburn 7464: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7465: if ($noedit) {
7466: $datatable .= ': ['.&mt('not shown').']';
7467: } elsif ($switchserver) {
7468: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7469: } else {
7470: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7471: }
7472: $datatable .= '</span> '.(' 'x2);
7473: } elsif (!$switchserver) {
1.100 raeburn 7474: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7475: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7476: '</span> '.(' 'x2);
7477: }
7478: if ($switchserver) {
7479: if ($values{'usable'} ne '') {
7480: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7481: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7482: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7483: '<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 7484: (' 'x2).
1.118 raeburn 7485: '<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 7486: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7487: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7488: '</div>';
7489: } elsif ($values{'key'} eq '') {
1.102 raeburn 7490: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7491: } else {
1.102 raeburn 7492: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7493: }
1.111 raeburn 7494: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7495: } else {
7496: if ($values{'usable'} ne '') {
7497: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7498: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7499: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7500: '<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 7501: (' 'x2).
1.118 raeburn 7502: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7503: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7504: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7505: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7506: '<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 7507: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7508: } else {
7509: $datatable .=
1.100 raeburn 7510: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7511: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7512: '<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 7513: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7514: }
7515: }
1.112 raeburn 7516: $datatable .= '<br /><br />'.
1.122 raeburn 7517: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7518: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7519: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7520: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7521: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7522: '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7523: '<span class="LC_nobreak">'.&mt('Grade format').
7524: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7525: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7526: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7527: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7528: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7529: '<br />'.
1.112 raeburn 7530: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7531: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7532: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7533: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7534: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7535: ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7536: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7537: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7538: '</span></div> ';
1.100 raeburn 7539: if ($ltiauth) {
1.112 raeburn 7540: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7541: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7542: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7543: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7544: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7545: '</fieldset>'.
7546: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7547: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7548: '</fieldset>';
7549: }
1.99 raeburn 7550: $datatable .= '</td></tr>';
1.93 raeburn 7551: $itemcount ++;
7552: }
7553: }
7554: }
7555: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7556: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7557: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7558: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7559: '<td width="100%">';
1.122 raeburn 7560: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7561: $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.100 raeburn 7562: if ($ltiauth) {
7563: $usersty = 'display:none';
1.112 raeburn 7564: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7565: %checkedrequser = (
7566: no => ' checked="checked"',
7567: yes => '',
7568: );
7569: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7570: }
1.122 raeburn 7571: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7572: %checkedpassback = (
7573: 'no' => ' checked="checked"',
7574: 'yes' => '',
7575: );
7576: %checkedpassbackfmt = (
7577: '1p1' => ' checked="checked"',
7578: '1p0' => '',
7579: );
1.112 raeburn 7580: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7581: %checkedreturnurl = (
7582: no => ' checked="checked"',
7583: yes => '',
7584: );
1.100 raeburn 7585: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7586: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7587: (' 'x2).
1.100 raeburn 7588: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7589: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7590: (' 'x2).
1.112 raeburn 7591: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7592: '<br /><br />';
1.99 raeburn 7593: if ($switchserver) {
1.102 raeburn 7594: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7595: } else {
1.100 raeburn 7596: $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 7597: (' 'x2).
1.116 raeburn 7598: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7599: '<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 7600: }
1.112 raeburn 7601: $datatable .= '<br /><br />'.
1.122 raeburn 7602: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7603: '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7604: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7605: '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7606: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7607: '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none" />'.
7608: '<span class="LC_nobreak">'.&mt('Grade format').
7609: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7610: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7611: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7612: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7613: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7614: '<br />'.
1.112 raeburn 7615: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7616: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7617: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7618: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7619: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7620: ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7621: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7622: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7623: '</span></div> ';
7624: if ($ltiauth) {
7625: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7626: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7627: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7628: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7629: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7630: '</fieldset>'.
1.100 raeburn 7631: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7632: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7633: '</fieldset>';
7634: }
1.99 raeburn 7635: $datatable .= '</td></tr>';
1.93 raeburn 7636: $$rowtotal ++;
1.101 raeburn 7637: return $datatable;
1.93 raeburn 7638: }
7639:
7640: sub linkprot_names {
1.100 raeburn 7641: return &Apache::lonlocal::texthash(
1.93 raeburn 7642: 'version' => 'LTI Version',
7643: 'key' => 'Key',
7644: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7645: 'name' => 'Launcher Application',
1.93 raeburn 7646: 'secret' => 'Secret',
1.122 raeburn 7647: 'passback' => 'Can return grades to Launcher',
1.112 raeburn 7648: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7649: 'requser' => 'Use identity',
7650: 'email' => 'Email address',
7651: 'sourcedid' => 'User ID',
7652: 'other' => 'Other',
7653: 'auth' => 'Display LON-CAPA login page',
7654: 'reject' => 'Discontinue launch process',
1.93 raeburn 7655: );
7656: }
7657:
1.99 raeburn 7658: sub check_switchserver {
1.102 raeburn 7659: my ($cdom,$cnum,$context,$dest) = @_;
7660: my ($allowed,$switchserver,$home);
7661: if ($context eq 'domain') {
7662: $home = &Apache::lonnet::domain($cdom,'primary');
7663: } else {
7664: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7665: }
7666: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7667: my @ids=&Apache::lonnet::current_machine_ids();
7668: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7669: if (!$allowed) {
7670: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7671: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7672: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7673: }
7674: }
7675: return $switchserver;
7676: }
7677:
1.100 raeburn 7678: sub linkprot_options {
7679: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7680: my %lt;
7681: if (ref($desc) eq 'HASH') {
7682: %lt = %{$desc};
7683: }
7684: my $userfieldsty = 'none';
7685: my (%checked,$userfield);
7686: $checked{'sourcedid'} = ' checked="checked"';
7687: $checked{'reject'} = ' checked="checked"';
7688: if (ref($current) eq 'HASH') {
7689: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7690: $checked{'sourcedid'} = '';
7691: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7692: $checked{'email'} = ' checked="checked"';
7693: } else {
7694: $checked{'other'} = ' checked="checked"';
7695: $userfield = $current->{'mapuser'};
7696: $userfieldsty = 'inline-block';
7697: }
7698: }
7699: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7700: $checked{'reject'} = '';
7701: $checked{'auth'} = ' checked="checked"';
7702: }
7703: }
1.112 raeburn 7704: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7705: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7706: &mt('Source of LON-CAPA username in LTI request').': ';
7707: foreach my $option ('sourcedid','email','other') {
7708: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7709: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7710: ($option eq 'other' ? '' : (' 'x2) );
7711: }
7712: $output .= '</span></div>'.
7713: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7714: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7715: 'value="'.$userfield.'"'.$disabled.' /></div>';
7716: $output .= '<br />'.
7717: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7718: &mt('Action when username is not for an enrolled student').': ';
7719: foreach my $option ('reject','auth') {
7720: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7721: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7722: ($option eq 'auth' ? '' : (' 'x2) );
7723: }
7724: $output .= '</span></div>';
7725: return $output;
7726: }
7727:
1.114 raeburn 7728: sub print_extresource_row {
7729: my ($item,$config,$curr,$noedit) = @_;
7730: my $onchange;
7731: unless ($noedit) {
7732: $onchange = ' onchange="javascript:toggleExtRes();"';
7733: }
7734: my $id = 'LC_'.$item;
7735: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7736: my $output = &select_from_options($item,$config->{'order'},
7737: $config->{'options'},$selected,
7738: $config->{'nullval'},
7739: undef,undef,$onchange,$noedit,$id);
1.124 raeburn 7740: my ($checked,$reusesty,$sizesty);
1.114 raeburn 7741: if ($reuse) {
7742: $checked = ' checked="checked"';
7743: }
7744: $reusesty = 'none';
7745: $sizesty = 'none';
7746: if (($selected eq 'window') || ($selected eq 'tab')) {
7747: $reusesty = 'inline-block';
7748: if ($selected eq 'window') {
7749: $sizesty = 'inline-block';
7750: }
7751: }
7752: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7753: '<span class="LC_nobreak">'.
7754: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7755: &mt('Re-use tab/window').'</label>'.
7756: '</span></div>'.
7757: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7758: '<legend>'.&mt('Window size (optional)').'</legend>'.
7759: '<span class="LC_nobreak">'.
7760: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7761: (' ' x 3).
7762: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7763: '</span></fieldset>';
7764: return $output;
7765: }
7766:
1.1 raeburn 7767: sub print_other {
1.80 raeburn 7768: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7769: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7770: return;
7771: }
1.3 raeburn 7772: my @ordered = &get_other_items($cdom,$settings,$allitems);
7773: my %items;
7774: foreach my $parameter (@ordered) {
7775: $items{$parameter} = {
7776: text => '<b>'.$parameter.'</b>',
7777: input => 'textbox',
7778: size => '15',
7779: },
7780: }
7781: push (@ordered,'newp_value');
7782: $items{'newp_value'} = {
7783: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7784: '<input type="textbox" name="newp_name"'.
7785: ' value="" size="30" />',
7786: input => 'textbox',
7787: size => '30',
7788: };
1.93 raeburn 7789: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7790: }
7791:
7792: sub get_other_items {
7793: my ($cdom,$settings,$allitems) = @_;
7794: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7795: return;
7796: }
1.1 raeburn 7797: my @ordered;
7798: if (ref($settings) eq 'HASH') {
7799: foreach my $parameter (sort(keys(%{$settings}))) {
7800: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7801: next if (($parameter eq 'course.helper.not.run') &&
7802: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7803: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7804: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7805: || ($parameter eq 'type') ||
1.50 raeburn 7806: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7807: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7808: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7809: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7810: push(@ordered,$parameter);
7811: }
7812: }
7813: }
1.3 raeburn 7814: return @ordered;
1.1 raeburn 7815: }
7816:
7817: sub item_table_row_start {
1.91 raeburn 7818: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7819: my $output;
1.56 raeburn 7820: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7821: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7822: if ($leftclass eq '') {
7823: $leftclass = 'LC_left_item';
7824: }
7825: if ($rightclass eq '') {
7826: $rightclass = 'LC_right_item';
7827: }
1.56 raeburn 7828: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7829: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7830: '</td>';
1.91 raeburn 7831: if ($colspan > 1) {
7832: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7833: } else {
1.91 raeburn 7834: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7835: }
1.1 raeburn 7836: return $output;
7837: }
7838:
7839: sub item_table_row_end {
7840: return '</td></tr>';
7841: }
7842:
7843: sub yesno_radio {
1.127 raeburn 7844: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit,$onclick,$reverse) = @_;
1.1 raeburn 7845: my $itemon = ' ';
7846: my $itemoff = ' checked="checked" ';
1.69 raeburn 7847: if (($valueyes eq '') && ($valueno eq '')) {
7848: $valueyes = 'yes';
7849: $valueno = '';
7850: }
1.1 raeburn 7851: if (ref($settings) eq 'HASH') {
1.69 raeburn 7852: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7853: $itemon = $itemoff;
7854: $itemoff = ' ';
7855: }
1.69 raeburn 7856: unless (exists($settings->{$item})) {
7857: if ($unsetdefault eq $valueyes) {
7858: $itemon = $itemoff;
7859: $itemoff = ' ';
7860: }
7861: }
1.1 raeburn 7862: }
1.80 raeburn 7863: my $disabled;
7864: if ($noedit) {
7865: $disabled = ' disabled="disabled"';
1.127 raeburn 7866: } elsif ($onclick) {
7867: $onclick = ' onclick="'.$onclick.'"';
7868: }
7869: if ($reverse) {
7870: return '<span class="LC_nobreak"><label>'.
7871: '<input type="radio" name="'.$item.'"'.
7872: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label> '.
7873: '<label><input type="radio" name="'.$item.'"'.
7874: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label></span>';
7875: } else {
7876: return '<span class="LC_nobreak"><label>'.
7877: '<input type="radio" name="'.$item.'"'.
7878: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label> '.
7879: '<label><input type="radio" name="'.$item.'"'.
7880: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label></span>';
1.80 raeburn 7881: }
1.1 raeburn 7882: }
7883:
7884: sub select_from_options {
1.91 raeburn 7885: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7886: my $output;
1.80 raeburn 7887: my $disabled;
7888: if ($noedit) {
7889: $disabled = ' disabled=disabled"';
7890: }
1.1 raeburn 7891: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7892: $output='<select name="'.$item.'" '.$onchange;
7893: if ($multiple) {
7894: $output .= ' multiple="multiple"';
7895: my $num = @{$order};
7896: $num ++ if ($nullval ne '');
7897: if (($maxsize) && ($maxsize < $num)) {
7898: $output .= ' size="'.$maxsize.'"';
7899: }
7900: }
1.91 raeburn 7901: if ($id ne '') {
7902: $output .= ' id="'.$id.'"';
7903: }
1.80 raeburn 7904: $output .= $disabled.'>'."\n";
1.1 raeburn 7905: if ($nullval ne '') {
7906: $output .= '<option value=""';
7907: if (ref($curr) eq 'ARRAY') {
7908: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7909: $output .= ' selected="selected" ';
7910: }
7911: } else {
7912: if ($curr eq '') {
7913: $output .= ' selected="selected" ';
7914: }
7915: }
7916: $output .= '>'.$nullval.'</option>';
7917: }
7918: foreach my $option (@{$order}) {
7919: $output.= '<option value="'.$option.'"';
7920: if (ref($curr) eq 'ARRAY') {
7921: if (grep(/^\Q$option\E$/,@{$curr})) {
7922: $output .= ' selected="selected" ';
7923: }
7924: } else {
7925: if ($option eq $curr) {
7926: $output.=' selected="selected"';
7927: }
7928: }
7929: $output.=">$options->{$option}</option>\n";
7930: }
7931: $output.="</select>";
7932: }
7933: return $output;
7934: }
7935:
7936: sub make_item_rows {
1.127 raeburn 7937: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit,$cnum) = @_;
1.1 raeburn 7938: my $datatable;
7939: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7940: my $count = 0;
7941: foreach my $item (@{$ordered}) {
7942: $count ++;
1.56 raeburn 7943: my $colspan;
7944: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7945: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7946: $colspan = 2;
7947: }
1.114 raeburn 7948: my $rowdesc;
7949: if ($caller eq 'appearance') {
7950: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7951: } else {
7952: $rowdesc = $items->{$item}{text};
7953: }
1.41 www 7954: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7955: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7956: } else {
1.114 raeburn 7957: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7958: }
1.55 raeburn 7959: if ($item eq 'defaultcredits') {
7960: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7961: my $showcredits;
7962: if ($defaultcredits ne '') {
7963: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7964: } else {
7965: $showcredits = &mt('No default set');
7966: }
7967: $datatable .= $showcredits;
7968: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 7969: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 7970: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 7971: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7972: } elsif ($item eq 'print_header_format') {
1.80 raeburn 7973: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 7974: } elsif ($item eq 'lti.lcmenu') {
7975: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 7976: } elsif ($item eq 'extresource') {
7977: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7978: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 7979: my $disabled;
7980: if ($noedit) {
7981: $disabled = ' disabled="disabled"';
7982: }
1.1 raeburn 7983: $datatable .=
7984: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 7985: $settings->{$item},$disabled);
1.1 raeburn 7986: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 7987: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 7988: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 7989: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7990: unless ($domdefs{$item} eq '0') {
7991: $unsetdefault = 1;
7992: }
7993: $valueyes = "1";
7994: $valueno = "0";
1.87 raeburn 7995: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
7996: $valueyes = '1';
1.69 raeburn 7997: }
1.80 raeburn 7998: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7999: } elsif ($items->{$item}{input} eq 'selectbox') {
1.127 raeburn 8000: my ($id,$onchange);
1.91 raeburn 8001: if ($caller eq 'menuitems') {
8002: $id = $item;
1.127 raeburn 8003: } elsif ($caller eq 'grading') {
8004: if ($item eq 'grading') {
8005: $onchange = ' onchange="javascript:toggleGrading(this.form);"';
8006: $id = $item;
8007: }
1.91 raeburn 8008: }
1.1 raeburn 8009: my $curr = $settings->{$item};
8010: $datatable .=
8011: &select_from_options($item,$items->{$item}{'order'},
8012: $items->{$item}{'options'},$curr,
1.80 raeburn 8013: $items->{$item}{'nullval'},
1.127 raeburn 8014: undef,undef,$onchange,$noedit,$id);
8015: if ($item eq 'grading') {
8016: my ($unsetdefault,$valueyes,$valueno,$sectionbox);
8017: my $gradingsty = 'none';
8018: my $gradingsecsty = 'none';
8019: $unsetdefault = 0;
8020: my (@selsec,@sections,%current);
8021: if ($curr eq 'standard') {
8022: $gradingsty = 'inline-block';
8023: if (ref($settings) eq 'HASH') {
8024: $current{'hidetotals'} = $settings->{'hidetotals'};
8025: if ($settings->{'hidetotals'} =~ /^([\w,]+)$/) {
8026: my $secstr = $1;
8027: unless ($secstr eq 'all') {
8028: @selsec = split(/,/,$secstr);
8029: }
8030: $current{'hidetotals'} = 1;
8031: }
8032: }
8033: }
8034: $valueyes = "1";
8035: $valueno = "0";
8036: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
8037: if (keys(%sections)) {
8038: @sections = sort( { $a <=> $b } keys(%sections));
8039: }
8040: my $onclick = 'javascript:toggleHiddenTotalsSec(this.form);';
8041: my $sectionbox = '<div id="sectotalsdiv" style="display:'.$gradingsecsty.'; float:right">';
8042: my $reverse = 1;
8043: if (@sections) {
8044: $sectionbox .= ' ... '.&mt('hidden in sections').': '.
8045: '<div style="position: relative; top: 0%;">'.
8046: &select_sections('hidetotals','',\@sections,\@selsec,$noedit,'all').
8047: '</div>';
8048: }
8049: $sectionbox .= '</div>';
8050: $datatable .= '<fieldset id="hidetotalsdiv" style="display:'.$gradingsty.';">'.
8051: '<legend style="font-weight: normal;">'.
8052: &mt('Hide Course Points Totals').'</legend>'.
8053: '<div style="position: relative; top: 0%; float:left">'.
8054: &yesno_radio('hidetotals',\%current,$unsetdefault,$valueyes,$valueno,$noedit,
8055: $onclick,$reverse).'</div>'.
8056: $sectionbox.
8057: '</fieldset><div style="padding:0;clear:both;margin:0;border:0"></div>';
8058: }
1.1 raeburn 8059: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 8060: my $disabled;
8061: if ($noedit) {
8062: $disabled = ' disabled=disabled"';
8063: }
1.1 raeburn 8064: $datatable .=
8065: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 8066: $items->{$item}{size},
8067: $disabled);
1.1 raeburn 8068: }
8069: $datatable .= &item_table_row_end();
8070: }
8071: if (ref($rowtotal)) {
8072: $$rowtotal += scalar(@{$ordered});
8073: }
8074: }
8075: return $datatable;
8076: }
8077:
8078: sub nothidepriv_row {
1.80 raeburn 8079: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 8080: my ($cnum) = &get_course();
1.56 raeburn 8081: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 8082: if (ref($settings) eq 'HASH') {
8083: if ($settings->{$item} ne '') {
8084: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
8085: if ($user !~ /:/) {
8086: $nothide{join(':',split(/[\@]/,$user))}=1;
8087: } else {
8088: $nothide{$user} = 1;
8089: }
8090: }
8091: }
1.56 raeburn 8092: if ($settings->{'checkforpriv'}) {
1.124 raeburn 8093: @checkdoms = split(/,/,$settings->{'checkforpriv'});
1.56 raeburn 8094: }
1.1 raeburn 8095: }
1.56 raeburn 8096: push(@checkdoms,$cdom);
8097: my %coursepersonnel =
8098: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 8099: my @privusers;
8100: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 8101: my ($uname,$udom,$role) = split(/:/,$person);
8102: my $user = $uname.':'.$udom;
8103: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 8104: if ($end == -1 || $start == -1) {
8105: next;
8106: }
1.124 raeburn 8107: foreach my $dom (@checkdoms) {
1.56 raeburn 8108: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
8109: unless (grep(/^\Q$user\E$/,@privusers)) {
8110: push(@privusers,$user);
1.3 raeburn 8111: }
8112: }
8113: }
1.1 raeburn 8114: }
1.56 raeburn 8115: if (@privusers > 0) {
1.80 raeburn 8116: my $disabled;
8117: if ($noedit) {
8118: $disabled = ' disabled="disabled"';
8119: }
1.1 raeburn 8120: $datatable .= '<table align="right">';
8121: foreach my $user (sort(@privusers)) {
8122: my $hideon = ' checked="checked" ';
8123: my $hideoff = '';
8124: if ($nothide{$user}) {
8125: $hideoff = $hideon;
8126: $hideon = '';
8127: }
8128: my ($uname,$udom) = split(':',$user);
8129: $datatable .= '<tr><td align="left">'.
8130: &Apache::loncommon::aboutmewrapper(
8131: &Apache::loncommon::plainname($uname,$udom,'firstname'),
8132: $uname,$udom,'aboutuser').
8133: '</td><td align="left">'.
8134: '<span class="LC_nobreak"><label>'.
8135: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8136: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 8137: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8138: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 8139: '</tr>';
8140: }
8141: $datatable .= '</table>';
8142: } else {
1.9 raeburn 8143: if ($crstype eq 'Community') {
8144: $datatable .= &mt('No Domain Coordinators have community roles');
8145: } else {
8146: $datatable .= &mt('No Domain Coordinators have course roles');
8147: }
1.1 raeburn 8148: }
8149: return $datatable;
8150: }
8151:
1.56 raeburn 8152: sub checkforpriv_row {
1.80 raeburn 8153: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 8154: my $datatable;
8155: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8156: if (keys(%domains) == 1) {
8157: $datatable = '</td><td align="right">'.
8158: &mt("Course's domain is only domain");
8159: return $datatable;
8160: }
8161: my @excdoms = ($cdom);
8162: my $num = 0;
8163: if ($settings->{$item} eq '') {
8164: $datatable = '</td><td align="right">'.
8165: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 8166: 1,1,undef,undef,\@excdoms,
8167: $noedit);
1.56 raeburn 8168: } else {
8169: my @privdoms = split(/,/,$settings->{$item});
8170: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8171: $datatable = '</td><td align="right"><br />'.
8172: &Apache::loncommon::start_data_table();
1.80 raeburn 8173: my $disabled;
8174: if ($noedit) {
8175: $disabled = ' disabled="disabled"';
8176: }
1.56 raeburn 8177: if (@privdoms > 0) {
8178: foreach my $currdom (@privdoms) {
8179: next unless ($domains{$currdom});
8180: my $domdesc = &Apache::lonnet::domain($currdom,'description');
8181: if ($domdesc eq '') {
8182: $domdesc = $currdom;
1.124 raeburn 8183: }
1.56 raeburn 8184: $datatable .=
8185: &Apache::loncommon::start_data_table_row().
8186: '<td align="left"><span class="LC_nobreak">'.
8187: &mt('Domain:').'<b> '.$domdesc.
8188: '</b><input type="hidden" name="checkforpriv_'.$num.
8189: '" value="'.$currdom.'" /></span><br />'.
8190: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 8191: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
8192: &mt('Delete').'</label></span></td>'.
1.56 raeburn 8193: &Apache::loncommon::end_data_table_row();
8194: $num ++;
1.124 raeburn 8195: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
1.56 raeburn 8196: push(@excdoms,$currdom);
8197: }
8198: }
8199: }
8200: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
1.124 raeburn 8201: $datatable .=
1.56 raeburn 8202: &Apache::loncommon::start_data_table_row().
8203: '<td align="left"><span class="LC_nobreak">'.
8204: &mt('Additional domain:'). '</span><br />'.
8205: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8206: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8207: '</td>'.&Apache::loncommon::end_data_table_row();
8208: }
8209: $datatable .= &Apache::loncommon::end_data_table().
8210: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8211: '<br />';
8212: }
8213: return $datatable;
8214: }
8215:
1.1 raeburn 8216: sub print_hdrfmt_row {
1.80 raeburn 8217: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8218: my @curr;
8219: my $currnum = 0;
8220: my $maxnum = 2;
8221: my $currstr;
8222: if ($settings->{$item} ne '') {
8223: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8224: $settings->{$item}.'</tt></span></b><br />';
8225: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8226: foreach my $val (@current) {
8227: unless ($val eq '') {
8228: push(@curr,$val);
1.1 raeburn 8229: }
8230: }
8231: $currnum = @curr;
8232: $maxnum += $currnum;
8233: }
8234:
8235: my $output = <<ENDJS;
8236:
8237: <script type="text/javascript" language="Javascript">
8238:
8239: function reOrder(chgnum) {
8240: var maxnum = $maxnum;
8241: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8242: var newidx = 'printfmthdr_pos_'+chgnum;
8243: oldidx = getIndexByName(oldidx);
8244: newidx = getIndexByName(newidx);
8245: var oldpos = document.display.elements[oldidx].value;
8246: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8247: document.display.elements[oldidx].value = newpos;
8248: var chgtype = 'up';
8249: if (newpos < oldpos) {
8250: chgtype = 'down';
8251: }
8252: for (var j=0; j<maxnum; j++) {
8253: if (j != chgnum) {
8254: oldidx = 'printfmthdr_oldpos_'+j;
8255: newidx = 'printfmthdr_pos_'+j;
8256: oldidx = getIndexByName(oldidx);
8257: newidx = getIndexByName(newidx);
8258: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8259: var currsel = document.display.elements[newidx].selectedIndex;
8260: if (chgtype == 'up') {
8261: if ((currpos > oldpos) && (currpos <= newpos)) {
8262: document.display.elements[newidx].selectedIndex = currsel-1;
8263: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8264: }
8265: } else {
8266: if ((currpos >= newpos) && (currpos < oldpos)) {
8267: document.display.elements[newidx].selectedIndex = currsel+1;
8268: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8269: }
8270: }
8271: }
8272: }
8273: return;
8274: }
8275:
8276: function getIndexByName(item) {
8277: for (var i=0;i<document.display.elements.length;i++) {
8278: if (document.display.elements[i].name == item) {
8279: return i;
8280: }
8281: }
8282: return -1;
8283: }
8284:
8285: </script>
8286:
8287: ENDJS
1.56 raeburn 8288: $output .= '</td><td align="right"><br />'.
8289: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8290: my $disabled;
8291: if ($noedit) {
8292: $disabled = ' disabled="disabled"';
8293: }
1.1 raeburn 8294: if (@curr > 0) {
8295: for (my $i=0; $i<@curr; $i++) {
8296: my $pos = $i+1;
1.10 raeburn 8297: $output .= '<tr>'.
1.1 raeburn 8298: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8299: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8300: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8301: '"'.$disabled.' /></span></td>';
1.1 raeburn 8302: if ($curr[$i] =~ /^%\d*[nca]$/) {
8303: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8304: $output .= '<td align="left">'.
1.80 raeburn 8305: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8306: } else {
8307: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8308: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8309: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8310: }
1.10 raeburn 8311: $output .= '</tr>';
1.1 raeburn 8312: }
8313: }
1.80 raeburn 8314: my $pos = $currnum+1;
1.124 raeburn 8315: unless ($noedit) {
1.80 raeburn 8316: $output .=
8317: '<tr>'.
1.1 raeburn 8318: '<td align="left"><span class="LC_nobreak">'.
8319: &position_selector($pos,$currnum,$maxnum).
8320: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8321: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8322: '</tr>';
1.80 raeburn 8323: $pos ++;
1.82 raeburn 8324: $currnum ++;
8325: $output .=
1.80 raeburn 8326: '<tr>'.
1.1 raeburn 8327: '<td align="left"><span class="LC_nobreak">'.
8328: &position_selector($pos,$currnum,$maxnum).
8329: '<b>'.&mt('New').'</b></span></td>'.
8330: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8331: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8332: '" value="" size ="25" />'.
8333: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8334: $maxnum.'" /></td>'.
1.80 raeburn 8335: '</tr>';
8336: }
8337: $output .= '</table><br />';
1.1 raeburn 8338: return $output;
8339: }
8340:
8341: sub position_selector {
1.80 raeburn 8342: my ($pos,$num,$maxnum,$disabled) = @_;
8343: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8344: for (my $j=1; $j<=$maxnum; $j++) {
8345: my $sel = '';
8346: if ($pos == $j) {
8347: $sel = ' selected="selected"';
8348: }
8349: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8350: }
8351: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8352: '" value="'.$pos.'" />';
8353: return $output;
8354: }
8355:
8356: sub substitution_selector {
1.80 raeburn 8357: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8358: my ($stunametxt,$crsidtxt);
8359: if ($crstype eq 'Community') {
8360: $stunametxt = 'member name';
8361: $crsidtxt = 'community ID',
8362: } else {
8363: $stunametxt = 'student name';
8364: $crsidtxt = 'course ID',
8365: }
1.1 raeburn 8366: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8367: n => $stunametxt,
8368: c => $crsidtxt,
1.1 raeburn 8369: a => 'assignment note',
8370: );
8371: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8372: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8373: if ($subst eq '') {
8374: $output .= '<option value="" selected="selected"> </option>';
8375: }
8376: foreach my $field ('n','c','a') {
8377: my $sel ='';
8378: if ($subst eq $field) {
8379: $sel = ' selected="selected"';
8380: }
8381: $output .= '<option value="'.$field.'"'.$sel.'>'.
8382: $lt{$field}.'</option>';
8383: }
8384: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8385: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8386: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8387: return $output;
8388: }
8389:
1.23 raeburn 8390: sub change_clone {
8391: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8392: my $clone_crs = $cnum.':'.$cdom;
8393: if ($cnum && $cdom) {
8394: my $clone_crs = $cnum.':'.$cdom;
8395: my @allowclone;
8396: if ($clonelist =~ /,/) {
8397: @allowclone = split(',',$clonelist);
8398: } else {
8399: $allowclone[0] = $clonelist;
8400: }
8401: foreach my $currclone (@allowclone) {
8402: if (!grep(/^$currclone$/,@$oldcloner)) {
8403: if ($currclone ne '*') {
1.71 raeburn 8404: if ($currclone =~ /:/) {
8405: my ($uname,$udom) = split(/:/,$currclone);
8406: if ($uname && $udom && $uname ne '*') {
8407: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8408: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8409: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8410: if ($currclonecrs{'cloneable'} eq '') {
8411: $currclonecrs{'cloneable'} = $clone_crs;
8412: } else {
8413: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8414: }
8415: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8416: }
8417: }
8418: }
8419: }
8420: }
8421: }
8422: }
8423: foreach my $oldclone (@$oldcloner) {
8424: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8425: if ($oldclone ne '*') {
1.71 raeburn 8426: if ($oldclone =~ /:/) {
8427: my ($uname,$udom) = split(/:/,$oldclone);
8428: if ($uname && $udom && $uname ne '*' ) {
8429: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8430: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8431: my %newclonecrs = ();
8432: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8433: if ($currclonecrs{'cloneable'} =~ /,/) {
8434: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8435: foreach my $crs (@currclonecrs) {
8436: if ($crs ne $clone_crs) {
8437: $newclonecrs{'cloneable'} .= $crs.',';
8438: }
1.23 raeburn 8439: }
1.71 raeburn 8440: $newclonecrs{'cloneable'} =~ s/,$//;
8441: } else {
8442: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8443: }
1.71 raeburn 8444: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8445: }
8446: }
8447: }
8448: }
8449: }
8450: }
8451: }
8452: }
8453: return;
8454: }
8455:
1.108 raeburn 8456: sub devalidate_remote_courseprefs {
8457: my ($cdom,$cnum,$cachekeys) = @_;
8458: return unless (ref($cachekeys) eq 'HASH');
8459: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8460: my %thismachine;
8461: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8462: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8463: if (keys(%servers)) {
8464: foreach my $server (keys(%servers)) {
8465: next if ($thismachine{$server});
8466: my @cached;
8467: foreach my $name (@posscached) {
8468: if ($cachekeys->{$name}) {
8469: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8470: }
8471: }
8472: if (@cached) {
8473: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8474: }
8475: }
8476: }
8477: return;
8478: }
8479:
1.1 raeburn 8480: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>