Annotation of loncom/interface/courseprefs.pm, revision 1.121
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.121 ! raeburn 4: # $Id: courseprefs.pm,v 1.120 2023/05/22 21:10:55 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.23 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: courseprefs- Handler to set/modify course configuration
36:
37: =head1 SYNOPSIS
38:
39: courseprefs provides an interface for setting general course configuration
40:
41: =head1 DESCRIPTION
42:
43: This module is used for configuration of a course
44:
45: =head1 INTERNAL SUBROUTINES
46:
47: =over
48:
49: =item get_allitems()
50:
51: =item print_config_box()
52:
53: =item process_changes()
54:
1.102 raeburn 55: =item process_linkprot()
56:
1.23 raeburn 57: =item get_sec_str()
58:
59: =item check_clone()
60:
61: =item store_changes()
62:
1.102 raeburn 63: =item store_linkprot()
64:
1.23 raeburn 65: =item update_env()
66:
67: =item display_disallowed()
68:
69: =item get_course()
70:
71: =item get_jscript()
72:
73: =item cloners_javascript()
74:
75: =item print_courseinfo()
76:
77: =item new_cloners_dom_row()
78:
79: =item can_modify_catsettings()
80:
81: =item assign_course_categories()
82:
83: =item print_localization()
84:
85: =item get_lang_choices()
86:
87: =item print_feedback()
88:
89: =item user_table()
90:
91: =item select_recipient()
92:
93: =item select_sections()
94:
95: =item print_discussion()
96:
97: =item role_checkboxes()
98:
99: =item print_classlists()
100:
101: =item print_appearance()
102:
103: =item print_grading()
104:
105: =item print_printouts()
106:
107: =item print_spreadsheet()
108:
109: =item print_bridgetasks()
110:
111: =item print_other()
112:
113: =item get_other_items()
114:
115: =item item_table_row_start()
116:
117: =item item_table_row_end()
118:
1.115 raeburn 119: =item yesno_radio()
1.23 raeburn 120:
121: =item select_from_options()
122:
123: =item make_item_rows()
124:
125: Creates table used to display and set course configuration items.
126:
127: Inputs: $cdom,$items,$ordered,$settings,$rowtotal,$crstype
128: where $cdom is course's domain, $items is HASH ref for current config
129: item, $ordered is ARRAY ref of items to include in row in
130: display order, $settings is HASH ref of current values forrow,
131: $rowtotal is SCALAR ref used to accumulate row count, $crstype is
132: course type.
133:
134: Returns: $datatable
135: HTML mark-up of data table which accumulates individual rows.
136:
137: =item nothidepriv_row()
138:
139: Creates row containing form elements used to display and set
140: whether Domain coordinators who are currently included in
141: advanced course user .db file for a course are to be hidden (e.g.,
142: in syllabus, or from course user lists).
143:
1.80 raeburn 144: Inputs: $cdom,$item,$settings,$crstype,$noedit
1.23 raeburn 145: where $cdom is course domain, item is nothideprivileged, $settings is
146: HASH ref of the current values for nothideprivileged, $crstype is
147: course type (Course or Community).
148:
149: Return: $datatable
150: HTML mark-up for Privileged users (Domain Coordinators) in staff listing.
151:
152: =item print_hdrfmt_row()
153:
154: Creates row containing form elements used to display and set
155: substitution items and text to be used in the header included
156: on printouts.
157:
158: Inputs: $item,$settings
159: where $item is print_header_format, and $settings is a HASH ref
160: of the current values stored for print_header_format.
161:
162: Returns: $output
163: HTML mark-up containing Javascript functions: reOrder() and getIndexByName()
164: used to dynamically update position selectboxes, and HTML table elements
165: for the "Print header format" row.
166:
167: =item position_selector()
168:
169: Creates a select box which can be used to reorder substitutions
170: and text included in a printout header.
171:
172: Inputs: $pos,$num,$maxnum
173: where $pos is current position, $num is the unique identifier,
174: and $maxnum is the total number of items (both substitutions
175: and text in the printout header.
176:
177: Returns: $output
178: HTML mark-up for the selectbox and a hidden form element containing
179: the current position.
180:
181: =item substitution_selector()
182:
183: Creates a combination of select box for choosing an item
184: (student name, course ID or assignment note) to substitute,
185: and a corresponding size limit in the header used for printouts.
186:
187: Inputs: $num,$subst,$limit,$crstype
188: where $num is the unique identifier, $subst is the current
189: substitution (n,c or a, for name, course or note respectively,
190: $limit is the current size limit (integer), and $crstype is
191: course type - course or community.
192:
193: Returns: $output
194: HTML mark-up for selectbox and textbox (separate table cells).
195:
196: =item change_clone()
197:
198: Modifies the list of courses a user can clone (stored
199: in the user's environment.db file), called when a
200: change is made to the list of users allowed to clone
201: a course.
202:
203: Inputs: $action,$cloner
204: where $action is add or drop, and $cloner is identity of
205: user for whom cloning ability is to be changed in course.
206:
207: Returns: nothing
208:
209: =back
210:
211: =cut
212:
213:
1.1 raeburn 214: package Apache::courseprefs;
215:
216: use strict;
217: use Apache::Constants qw(:common :http);
218: use Apache::lonnet;
219: use Apache::loncommon();
220: use Apache::lonhtmlcommon();
221: use Apache::lonconfigsettings;
1.66 raeburn 222: use Apache::lonrelrequtils;
1.36 raeburn 223: use Apache::lonparmset;
1.71 raeburn 224: use Apache::courseclassifier;
1.1 raeburn 225: use Apache::lonlocal;
226: use LONCAPA qw(:DEFAULT :match);
1.103 raeburn 227: use Crypt::CBC;
1.118 raeburn 228: use Time::HiRes qw( sleep );
1.1 raeburn 229:
1.66 raeburn 230: my $registered_cleanup;
231: my $modified_courses;
232:
1.1 raeburn 233: sub handler {
234: my $r=shift;
235: if ($r->header_only) {
236: &Apache::loncommon::content_type($r,'text/html');
237: $r->send_http_header;
238: return OK;
239: }
240: my $context = 'course';
241: my $cid = $env{'request.course.id'};
1.66 raeburn 242: my ($cnum,$cdom,$chome) = &get_course($cid);
1.1 raeburn 243: my $crstype = &Apache::loncommon::course_type();
1.80 raeburn 244: my ($parm_permission,$allowed) = &get_permission($cid);
1.1 raeburn 245: my $navmap = Apache::lonnavmaps::navmap->new();
1.80 raeburn 246: if ($allowed && $navmap) {
1.1 raeburn 247: &Apache::loncommon::content_type($r,'text/html');
248: $r->send_http_header;
249: } else {
250: if ($navmap) {
1.9 raeburn 251: if ($crstype eq 'Community') {
252: $env{'user.error.msg'}=
253: "/adm/courseprefs:opa:0:0:Cannot modify community settings";
254: } else {
255: $env{'user.error.msg'}=
256: "/adm/courseprefs:opa:0:0:Cannot modify course settings";
257: }
1.1 raeburn 258: } else {
1.9 raeburn 259: if ($crstype eq 'Community') {
260: $env{'user.error.msg'}=
261: "/adm/courseprefs::0:1:Course environment gone, reinitialize the community";
262: } else {
263: $env{'user.error.msg'}=
264: "/adm/courseprefs::0:1:Course environment gone, reinitialize the course";
265:
266: }
1.1 raeburn 267: }
268: return HTTP_NOT_ACCEPTABLE;
269: }
270:
1.66 raeburn 271: $registered_cleanup=0;
272: @{$modified_courses}=();
273:
1.4 raeburn 274: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
275: ['phase','actions','origin']);
1.1 raeburn 276: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.4 raeburn 277: if ($env{'form.origin'} eq 'params') {
278: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
279: text=>"Parameter Manager"});
280: }
1.9 raeburn 281: my ($brtext,$brtitle,$crsinfotext,$crsinfodesc,$crscateg,$crshide);
282: my %lt;
283: if ($crstype eq 'Community') {
284: %lt = (
1.40 www 285: conf => 'Community Settings',
286: edit => 'Edit Community Settings',
1.9 raeburn 287: gens => 'General community settings',
288: idnu => 'Community ID or number',
1.64 raeburn 289: unco => 'Unique code',
1.9 raeburn 290: desc => 'Community Description',
1.24 raeburn 291: ownr => 'Community Owner',
1.25 raeburn 292: cown => 'Community Co-owners',
1.9 raeburn 293: catg => 'Categorize community',
294: excc => 'Exclude from community catalog',
295: clon => 'Users allowed to clone community',
296: rept => 'Replacement titles for standard community roles',
1.115 raeburn 297: time => 'Time Zone where the community is located',
1.9 raeburn 298: date => 'Locale used for community calendar',
299: coco => 'Community Content',
300: copo => 'Community Policy',
1.13 bisitz 301: priv => 'Domain Coordinators in community',
1.9 raeburn 302: defd => 'Default dates for member access',
303: stuv => 'Member-viewable membership list options',
304: stul => 'Member agreement needed to be listed',
1.42 www 305: clas => 'Membership and facilitator listing',
1.57 raeburn 306: prus => 'Privileged users (Domain Coordinators) in facilitator listing',
1.9 raeburn 307: defc => 'Default Community Spreadsheet',
308: defs => 'Default User Spreadsheet',
309: seme => 'Send message to member when clicking Done on Tasks'
310: );
311: } else {
312: %lt = (
1.40 www 313: conf => 'Course Settings',
314: edit => 'Edit Course Settings',
1.20 faziophi 315: gens => 'General course settings',
316: idnu => 'Course ID or number',
1.64 raeburn 317: unco => 'Unique code',
1.20 faziophi 318: desc => 'Course Description',
1.55 raeburn 319: cred => 'Student credits',
1.24 raeburn 320: ownr => 'Course Owner',
1.25 raeburn 321: cown => 'Course Co-owners',
1.9 raeburn 322: catg => 'Categorize course',
323: excc => 'Exclude from course catalog',
324: clon => 'Users allowed to clone course',
325: rept => 'Replacement titles for standard course roles',
1.115 raeburn 326: time => 'Time Zone in which the course takes place',
1.20 faziophi 327: date => 'Locale used for course calendar',
1.9 raeburn 328: coco => 'Course Content',
329: copo => 'Course Policy',
1.13 bisitz 330: priv => 'Domain Coordinators in course',
1.9 raeburn 331: defd => 'Default dates for student access',
332: stuv => 'Student-viewable classlist options',
333: stul => 'Student agreement needed to be listed',
1.42 www 334: clas => 'Classlists and staff listing',
1.57 raeburn 335: prus => 'Privileged users (Domain Coordinators) in staff listing',
1.56 raeburn 336: prdo => "Domains to check for privileged users (besides course's domain)",
1.9 raeburn 337: defc => 'Default Course Spreadsheet',
338: defs => 'Default Student Spreadsheet',
339: seme => 'Send message to student when clicking Done on Tasks',
340: );
341: }
1.35 raeburn 342: $lt{'lcrv'} = 'Required LON-CAPA version';
1.1 raeburn 343: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/courseprefs',
1.9 raeburn 344: text=>$lt{'conf'}});
1.1 raeburn 345: my $breadcrumbs =
1.9 raeburn 346: &Apache::lonhtmlcommon::breadcrumbs($lt{'edit'});
1.1 raeburn 347:
348: my $phase = 'pickactions';
349: if ( exists($env{'form.phase'}) ) {
350: $phase = $env{'form.phase'};
351: }
352:
1.80 raeburn 353: if (($phase eq 'categorizecourse') && ($parm_permission->{'categorizecourse'})) {
1.9 raeburn 354: &assign_course_categories($r,$crstype);
1.1 raeburn 355: return OK;
356: }
357:
1.80 raeburn 358: if (($phase eq 'releaseinfo') && ($parm_permission->{'releaseinfo'})) {
1.36 raeburn 359: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
360: if ($loncaparev) {
1.66 raeburn 361: if (&display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype)) {
362: push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
363: unless ($registered_cleanup) {
364: my $handlers = $r->get_handlers('PerlCleanupHandler');
365: $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
366: $registered_cleanup=1;
367: }
368: }
1.36 raeburn 369: return OK;
370: }
371: }
372:
1.1 raeburn 373: my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.102 raeburn 374: my %linkprot=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1.99 raeburn 375: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
1.118 raeburn 376: my %ltitools = &Apache::lonnet::dump('ltitools',$cdom,$cnum,undef,undef,undef,1);
377: my %ltitoolsenc = &Apache::lonnet::dump('nohist_toolsenc',$cdom,$cnum,undef,undef,undef,1);
1.102 raeburn 378: foreach my $id (keys(%linkprot)) {
379: if (ref($linkprot{$id}) eq 'HASH') {
1.99 raeburn 380: if (ref($ltienc{$id}) eq 'HASH') {
1.102 raeburn 381: $values{'linkprot'}{$id} = { %{$linkprot{$id}}, %{$ltienc{$id}} };
1.99 raeburn 382: } else {
1.102 raeburn 383: $values{'linkprot'}{$id} = $linkprot{$id};
1.99 raeburn 384: }
385: }
386: unless ($phase eq 'process') {
1.102 raeburn 387: if (ref($values{'linkprot'}{$id}) eq 'HASH') {
388: delete($values{'linkprot'}{$id}{'secret'});
1.99 raeburn 389: }
390: }
391: }
1.102 raeburn 392: if ($linkprot{'lock'}) {
393: delete($linkprot{'lock'});
1.93 raeburn 394: }
1.118 raeburn 395: foreach my $id (keys(%ltitools)) {
396: if (ref($ltitools{$id}) eq 'HASH') {
397: if (ref($ltitoolsenc{$id}) eq 'HASH') {
398: $values{'ltitools'}{$id} = { %{$ltitools{$id}}, %{$ltitoolsenc{$id}} };
399: } else {
400: $values{'ltitools'}{$id} = $ltitools{$id};
401: }
402: }
403: unless ($phase eq 'process') {
404: if (ref($values{'ltitools'}{$id}) eq 'HASH') {
405: delete($values{'ltitools'}{$id}{'secret'});
406: }
407: }
408: }
409: if ($ltitools{'lock'}) {
410: delete($ltitools{'lock'});
411: }
1.1 raeburn 412: my @prefs_order = ('courseinfo','localization','feedback','discussion',
413: 'classlists','appearance','grading','printouts',
1.118 raeburn 414: 'menuitems','ltitools','linkprot','spreadsheet',
415: 'bridgetasks','lti','other');
1.1 raeburn 416: my %prefs = (
417: 'courseinfo' =>
1.9 raeburn 418: { text => $lt{'gens'},
1.44 www 419: help => 'Course_Prefs_General',
1.35 raeburn 420: ordered => ['owner','co-owners','loncaparev','description',
1.64 raeburn 421: 'clonedfrom','courseid','uniquecode','categories',
1.88 raeburn 422: 'hidefromcat','syllabus','cloners','url',
1.64 raeburn 423: 'rolenames'],
1.3 raeburn 424: itemtext => {
1.25 raeburn 425: 'owner' => $lt{'ownr'},
426: 'co-owners' => $lt{'cown'},
427: 'description' => $lt{'desc'},
428: 'courseid' => $lt{'idnu'},
1.64 raeburn 429: 'uniquecode' => $lt{'unco'},
1.25 raeburn 430: 'categories' => $lt{'catg'},
431: 'hidefromcat' => $lt{'excc'},
432: 'cloners' => $lt{'clon'},
1.88 raeburn 433: 'syllabus' => 'Syllabus status',
1.25 raeburn 434: 'url' => 'Top Level Map',
435: 'rolenames' => $lt{'rept'},
1.35 raeburn 436: 'loncaparev' => $lt{'lcrv'},
1.63 raeburn 437: 'clonedfrom' => 'Cloned from',
1.3 raeburn 438: },
1.1 raeburn 439: },
440: 'localization' =>
1.42 www 441: { text => 'Language and time localization',
1.44 www 442: help => 'Course_Prefs_Language',
1.1 raeburn 443: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 444: itemtext => {
1.20 faziophi 445: languages => 'Languages used',
1.9 raeburn 446: timezone => $lt{'time'},
447: datelocale => $lt{'date'},
1.3 raeburn 448: },
1.1 raeburn 449: },
450: 'feedback' =>
1.20 faziophi 451: { text => 'Feedback messages',
1.44 www 452: help => 'Course_Prefs_Feedback',
1.1 raeburn 453: header => [{col1 => 'Questions about:',
1.20 faziophi 454: col2 => 'Recipients'}],
1.3 raeburn 455: ordered => ['question.email','comment.email','policy.email'],
456: itemtext => {
457: 'question.email' => 'Resource Content',
1.9 raeburn 458: 'comment.email' => $lt{'coco'},
459: 'policy.email' => $lt{'copo'},
1.3 raeburn 460: },
1.1 raeburn 461: },
462: 'discussion' =>
463: { text => 'Discussion and Chat',
1.44 www 464: help => 'Course_Prefs_Discussions',
1.31 raeburn 465: ordered => ['pch.roles.denied','pch.users.denied',
1.77 raeburn 466: 'pac.roles.denied','pac.users.denied',
1.31 raeburn 467: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 468: 'allow_limited_html_in_feedback',
1.50 raeburn 469: 'allow_discussion_post_editing',
470: 'discussion_post_fonts'],
1.3 raeburn 471: itemtext => {
1.31 raeburn 472: 'pch.roles.denied' => 'No Resource Discussion',
473: 'pch.users.denied' => 'No Resource Discussion',
474: 'plc.roles.denied' => 'No Chat room use',
475: 'plc.users.denied' => 'No Chat room use',
1.77 raeburn 476: 'pac.roles.denied' => 'No Anonymous Resource Discussion',
477: 'pac.users.denied' => 'No Anonymous Resource Discussion',
1.20 faziophi 478: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
479: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.77 raeburn 480: discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 481: },
1.1 raeburn 482: },
483: 'classlists' =>
1.9 raeburn 484: { text => $lt{'clas'},
1.44 www 485: help => 'Course_Prefs_Classlists',
1.1 raeburn 486: header => [{col1 => 'Type',
1.9 raeburn 487: col2 => $lt{'defd'}},
1.1 raeburn 488: {col1 => 'Setting',
1.9 raeburn 489: col2 => $lt{'priv'}},
1.1 raeburn 490: {col1 => 'Setting',
1.9 raeburn 491: col2 => $lt{'stuv'}}],
1.1 raeburn 492: ordered => ['default_enrollment_start_date',
493: 'default_enrollment_end_date',
1.55 raeburn 494: 'defaultcredits',
1.56 raeburn 495: 'nothideprivileged','checkforpriv',
496: 'student_classlist_view',
1.26 raeburn 497: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 498: itemtext => {
499: default_enrollment_start_date => 'Start date',
500: default_enrollment_end_date => 'End date',
1.57 raeburn 501: nothideprivileged => $lt{'prus'},
1.56 raeburn 502: checkforpriv => $lt{'prdo'},
1.9 raeburn 503: student_classlist_view => $lt{'stuv'},
1.26 raeburn 504: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 505: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.55 raeburn 506: defaultcredits => $lt{'cred'},
1.3 raeburn 507: },
1.1 raeburn 508: },
509: 'appearance' =>
1.20 faziophi 510: { text => 'Display of resources ',
1.44 www 511: help => 'Course_Prefs_Display',
1.1 raeburn 512: ordered => ['default_xml_style','pageseparators',
513: 'disable_receipt_display','texengine',
1.114 raeburn 514: 'tthoptions','uselcmath','usejsme',
515: 'inline_chem','extresource'],
1.3 raeburn 516: itemtext => {
1.17 faziophi 517: default_xml_style => 'Default XML style file',
1.20 faziophi 518: pageseparators => 'Visibly Separate Items on Pages',
519: disable_receipt_display => 'Disable display of problem receipts',
520: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 521: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.69 raeburn 522: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
523: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.95 raeburn 524: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.114 raeburn 525: extresource => 'Display of external resources',
1.3 raeburn 526: },
1.1 raeburn 527: },
528: 'grading' =>
529: { text => 'Grading',
1.44 www 530: help => 'Course_Prefs_Grading',
1.1 raeburn 531: ordered => ['grading','rndseed',
532: 'receiptalg','disablesigfigs'],
1.3 raeburn 533: itemtext => {
1.20 faziophi 534: grading => 'Grading',
535: rndseed => 'Randomization algorithm used',
536: receiptalg => 'Receipt algorithm used',
537: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 538: },
539:
1.1 raeburn 540: },
541: 'printouts' =>
1.20 faziophi 542: { text => 'Printout generation',
1.44 www 543: help => 'Course_Prefs_Printouts',
1.1 raeburn 544: ordered => ['problem_stream_switch','suppress_tries',
545: 'default_paper_size','print_header_format',
1.14 raeburn 546: 'disableexampointprint','canuse_pdfforms'],
1.3 raeburn 547: itemtext => {
548: problem_stream_switch => 'Allow problems to be split over pages',
549: suppress_tries => 'Suppress number of tries in printing',
550: default_paper_size => 'Default paper type',
551: print_header_format => 'Print header format',
1.51 bisitz 552: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 553: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 554: },
1.1 raeburn 555: },
556: 'spreadsheet' =>
557: { text => 'Spreadsheets',
1.44 www 558: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 559: ordered => ['spreadsheet_default_classcalc',
560: 'spreadsheet_default_studentcalc',
561: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 562: itemtext => {
1.9 raeburn 563: spreadsheet_default_classcalc => $lt{'defc'},
564: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 565: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
566: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
567: },
1.1 raeburn 568: },
569: 'bridgetasks' =>
570: { text => 'Bridge tasks',
1.44 www 571: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 572: ordered => ['task_messages','task_grading',
573: 'suppress_embed_prompt'],
1.3 raeburn 574: itemtext => {
1.9 raeburn 575: task_messages => $lt{'seme'},
1.3 raeburn 576: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 577: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 578: },
1.1 raeburn 579: },
1.87 raeburn 580: 'lti' =>
581: {
582: text => 'LTI provider settings',
583: help => 'Course_Prefs_LTIProvider',
584: ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'],
585: itemtext => {
586: 'lti.override' => 'Override domain defaults',
587: 'lti.topmenu' => 'Display LON-CAPA page header',
588: 'lti.inlinemenu' => 'Display LON-CAPA inline menu',
589: 'lti.lcmenu' => 'Menu items',
590: },
591: },
1.91 raeburn 592: 'menuitems' =>
593: {
594: text => 'Menu display',
595: help => 'Course_Prefs_Menus',
596: header => [{col1 => 'Default Menu',
597: col2 => 'Value',},
598: {col1 => 'Menu collections',
599: col2 => 'Settings',
600: }],
601: ordered => ['menudefault','menucollections'],
602: itemtext => {
603: menudefault => 'Choose default collection of menu items for course',
604: menucollections => 'Menu collections',
605: },
606: },
1.102 raeburn 607: 'linkprot' =>
1.93 raeburn 608: {
609: text => 'Link protection',
610: help => 'Course_Prefs_Linkprotection',
611: header => [{col1 => 'Item',
612: col2 => 'Settings',
613: }],
614: },
1.118 raeburn 615: 'ltitools' =>
616: {
617: text => 'External tools',
618: help => 'Course_Prefs_ExternalTools',
619: header => [{col1 => 'Item',
620: col2 => 'Settings',
621: }],
622: },
1.1 raeburn 623: 'other' =>
624: { text => 'Other settings',
1.44 www 625: help => 'Course_Prefs_Other',
1.1 raeburn 626: header => [ {col1 => 'Item',
627: col2 => 'Value',
628: }],
629: },
630: );
1.80 raeburn 631: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 632: my @allitems = &get_allitems(%prefs);
1.108 raeburn 633: my $result = &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
634: \@prefs_order,\%prefs,\%values,
635: $cnum,undef,\@allitems,
636: 'coursepref',$parm_permission);
637: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
638: $r->rflush();
639: &devalidate_remote_courseprefs($cdom,$cnum,$result);
640: }
1.80 raeburn 641: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.91 raeburn 642: my $noedit;
643: if (ref($parm_permission) eq 'HASH') {
644: unless ($parm_permission->{'process'}) {
645: $noedit = 1;
646: }
647: }
648: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 649: my @allitems = &get_allitems(%prefs);
1.1 raeburn 650: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.99 raeburn 651: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.80 raeburn 652: 'coursepref',$parm_permission);
1.1 raeburn 653: } else {
654: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.80 raeburn 655: \@prefs_order,\%prefs,
656: 'coursepref',$parm_permission);
1.1 raeburn 657: }
658: return OK;
659: }
660:
1.80 raeburn 661: sub get_permission {
662: my ($cid) = @_;
663: my %permission;
664: my $allowed = 0;
665: return (\%permission,$allowed) unless ($cid);
666: if (&Apache::lonnet::allowed('opa',$cid)) {
667: %permission= (
668: 'pickactions' => 1,
669: 'categorizecourse' => 1,
670: 'releaseinfo' => 1,
671: 'process' => 1,
672: 'display' => 1,
673: );
674: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
675: %permission = (
676: 'pickactions' => 1,
677: 'releaseinfo' => 1,
678: 'display' => 1,
679: );
680: }
681: foreach my $perm (values(%permission)) {
682: if ($perm) { $allowed=1; last; }
683: }
684: return (\%permission,$allowed);
685: }
686:
1.3 raeburn 687: sub get_allitems {
688: my (%prefs) = @_;
689: my @allitems;
690: foreach my $item (keys(%prefs)) {
691: if (ref($prefs{$item}) eq 'HASH') {
692: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
693: push(@allitems,@{$prefs{$item}{'ordered'}});
694: if ($item eq 'feedback') {
695: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
696: }
697: }
698: }
699: }
700: return @allitems;
701: }
702:
1.1 raeburn 703: sub print_config_box {
1.99 raeburn 704: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 705: my $ordered = $item->{'ordered'};
1.3 raeburn 706: my $itemtext = $item->{'itemtext'};
1.80 raeburn 707: my $noedit;
708: if (ref($parm_permission) eq 'HASH') {
709: unless ($parm_permission->{'process'}) {
710: $noedit = 1;
711: }
712: }
1.1 raeburn 713: my $rowtotal = 0;
714: my $output =
1.45 www 715: '<table class="LC_nested_outer">
716: <tr>
717: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 718: &mt($item->{text});
719: if ($item->{'help'}) {
1.53 raeburn 720: $output .= ' '.
1.52 raeburn 721: &Apache::loncommon::help_open_topic($item->{'help'});
722: }
723: $output .= '</span></th>'."\n".
724: '</tr>';
1.91 raeburn 725: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 726: $output .= '
1.45 www 727: <tr>
728: <td>
1.18 faziophi 729: <table class="LC_nested">';
730: if (exists $item->{'header'}->[0]->{'col1'} ||
731: exists $item->{'header'}->[0]->{'col2'}) {
732: $output .= '
733: <tr class="LC_info_row">
1.56 raeburn 734: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
735: if ($action eq 'feedback') {
736: $output .= '
737: <td class="LC_right_item" colspan="2">';
738: } else {
739: $output .= '
740: <td class="LC_right_item">';
741: }
742: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 743: </tr>';
744: }
1.1 raeburn 745: $rowtotal ++;
746: if ($action eq 'feedback') {
1.80 raeburn 747: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 748: } elsif ($action eq 'classlists') {
1.80 raeburn 749: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 750: } elsif ($action eq 'menuitems') {
751: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 752: }
753: $output .= '
754: </table>
1.45 www 755: </td>
756: </tr>
757: <tr>
758: <td>
1.1 raeburn 759: <table class="LC_nested">
760: <tr class="LC_info_row">
761: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 762: if ($action eq 'classlists') {
763: $output .= '
764: <td class="LC_right_item" colspan="2">';
765: } else {
766: $output .= '
767: <td class="LC_right_item">';
768: }
769: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 770: </tr>';
771: if ($action eq 'classlists') {
1.80 raeburn 772: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 773: '
774: </table>
1.45 www 775: </td>
776: </tr>
777: <tr>
778: <td>
1.18 faziophi 779: <table class="LC_nested">';
1.43 www 780: if (exists $item->{'header'}->[2]->{'col1'} ||
781: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 782: $output .= '
783: <tr class="LC_info_row">
1.43 www 784: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
785: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 786: </tr>';
787: }
1.1 raeburn 788: }
789: } else {
790: $output .= '
1.45 www 791: <tr>
792: <td>
1.18 faziophi 793: <table class="LC_nested">';
794: if (exists $item->{'header'}->[0]->{'col1'} ||
795: exists $item->{'header'}->[0]->{'col2'}) {
796: $output .= '
797: <tr class="LC_info_row">
1.56 raeburn 798: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
799: if (($action eq 'courseinfo') || ($action eq 'localization') ||
800: ($action eq 'print_discussion')) {
801: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
802: } else {
803: $output .= '<td class="LC_right_item" valign="top">';
804: }
805: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 806: </tr>';
807: }
1.1 raeburn 808: }
809: $rowtotal ++;
810: if ($action eq 'courseinfo') {
1.80 raeburn 811: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 812: } elsif ($action eq 'localization') {
1.80 raeburn 813: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 814: } elsif ($action eq 'feedback') {
1.80 raeburn 815: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 816: } elsif ($action eq 'discussion') {
1.80 raeburn 817: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 818: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 819: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 820: } elsif ($action eq 'appearance') {
1.80 raeburn 821: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 822: } elsif ($action eq 'grading') {
1.80 raeburn 823: $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 824: } elsif ($action eq 'printouts') {
1.80 raeburn 825: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 826: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 827: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 828: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 829: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.118 raeburn 830: } elsif ($action eq 'ltitools') {
831: my $currtools = {};
832: if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
833: $currtools = $settings->{'ltitools'};
834: }
835: $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
1.87 raeburn 836: } elsif ($action eq 'lti') {
837: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 838: } elsif ($action eq 'menuitems') {
839: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 840: } elsif ($action eq 'linkprot') {
841: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 842: } elsif ($action eq 'other') {
1.80 raeburn 843: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 844: }
845: $output .= '
846: </table>
1.45 www 847: </td>
848: </tr>
849: </table><br />';
1.1 raeburn 850: return ($output,$rowtotal);
851: }
852:
853: sub process_changes {
1.108 raeburn 854: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 855: my (%newvalues,$errors);
1.3 raeburn 856: if (ref($item) eq 'HASH') {
857: if (ref($changes) eq 'HASH') {
858: my @ordered;
859: if ($action eq 'other') {
860: @ordered = &get_other_items($cdom,$values,$allitems);
861: if ($env{'form.newp_name'} ne '') {
862: my $newp = $env{'form.newp_name'};
863: if ($env{'form.newp_value'} ne '') {
864: if (ref($allitems) eq 'ARRAY') {
865: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
866: (grep(/^\Q$newp\E$/,@{$allitems}))) {
867: $changes->{$newp} = $env{'form.newp_value'};
868: }
869: }
870: }
871: }
1.118 raeburn 872: } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.99 raeburn 873: if (ref($values->{$action}) eq 'HASH') {
874: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 875: if ($id =~ /^\d+$/) {
876: push(@ordered,$id);
877: }
878: }
879: }
880: @ordered = sort { $a <=> $b } @ordered;
1.118 raeburn 881: if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
882: push(@ordered,$env{'form.'.$action.'_maxnum'});
1.93 raeburn 883: }
1.3 raeburn 884: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 885: if ($action eq 'courseinfo') {
886: my ($can_toggle_cat,$can_categorize) =
887: &can_modify_catsettings($cdom,$crstype);
888: foreach my $entry (@{$item->{'ordered'}}) {
889: next if (($entry eq 'hidefromcat') &&
890: (!$can_toggle_cat));
891: next if (($entry eq 'categories') &&
892: (!$can_categorize));
893: next if (($entry eq 'loncaparev') ||
1.63 raeburn 894: ($entry eq 'owner') ||
1.88 raeburn 895: ($entry eq 'clonedfrom') ||
896: ($entry eq 'syllabus'));
1.49 raeburn 897: push(@ordered,$entry);
898: }
1.55 raeburn 899: } elsif ($action eq 'classlists') {
900: foreach my $entry (@{$item->{'ordered'}}) {
901: next if ($entry eq 'defaultcredits');
902: push(@ordered,$entry);
903: }
1.49 raeburn 904: } else {
905: @ordered = @{$item->{'ordered'}};
906: }
1.3 raeburn 907: }
908: if (@ordered > 0) {
909: if ($action eq 'feedback') {
910: foreach my $entry (@ordered) {
911: my $userstr = '';
912: my $total = $env{'form.'.$entry.'_total'};
913: if ($total) {
914: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
915: for (my $i=0; $i<$total; $i++) {
916: unless (grep(/^$i$/,@deletes)) {
917: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
918: &get_sec_str($entry,$i).',';
919: }
920: }
921: } else {
922: $total = 0;
923: }
924: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
925: my $uname = $env{'form.'.$entry.'_uname_'.$total};
926: my $udom = $env{'form.'.$entry.'_udom_'.$total};
927: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
928: $userstr =~ s/,$//;
929: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
930: } else {
931: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
932: }
933: } else {
934: $userstr =~ s/,$//;
935: }
936: $newvalues{$entry} = $userstr;
937: if ($newvalues{$entry} ne $values->{$entry}) {
938: $changes->{$entry} = $newvalues{$entry};
939: }
940: my $ext_entry = $entry.'.text';
941: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
942: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
943: $changes->{$ext_entry} = $newvalues{$ext_entry};
944: }
945: }
1.91 raeburn 946: } elsif ($action eq 'menuitems') {
947: my (%current,@colls);
948: my $next = 1;
949: if ($values->{'menucollections'}) {
950: foreach my $item (split(/;/,$values->{'menucollections'})) {
951: my ($num,$value) = split(/\%/,$item);
952: if ($num =~ /^\d+$/) {
953: unless (grep(/^$num$/,@colls)) {
954: push(@colls,$num);
955: }
956: my @entries = split(/\&/,$value);
957: foreach my $entry (@entries) {
958: my ($name,$fields) = split(/=/,$entry);
959: $current{$num}{$name} = $fields;
960: }
961: }
962: }
963: }
964: if (@colls) {
965: @colls = sort { $a <=> $b } @colls;
966: $next += $colls[-1];
967: }
968: if ($env{'form.menucollections_add'} eq $next) {
969: push(@colls,$next);
970: }
971: my $currdef = $values->{'menudefault'};
972: my $possdef = $env{'form.menudefault'};
973: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 974: if ($currdef ne $possdef) {
1.91 raeburn 975: $changes->{'menudefault'} = $possdef;
976: }
1.92 raeburn 977: } elsif ($currdef) {
1.91 raeburn 978: $changes->{'menudefault'} = '';
979: }
980: my $menucoll;
981: if (@colls) {
982: my ($ordered,$cats) = &menuitems_categories();
983: my %shortcats = &menuitems_abbreviations();
984: foreach my $num (@colls) {
985: my ($entry,%include);
986: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
987: foreach my $item (@{$ordered}) {
988: if ($item eq 'shown') {
989: foreach my $type (@{$cats->{$item}}) {
990: $entry .= $type.'=';
991: if ($include{$type}) {
992: $entry .= 'y';
993: } else {
994: $entry .= 'n';
995: }
996: $entry .= '&';
997: }
998: } else {
999: $entry .= $shortcats{$item}.'=';
1000: foreach my $type (@{$cats->{$item}}) {
1001: if ($include{$type}) {
1002: $entry .= $type.',';
1003: }
1004: }
1005: $entry =~ s/,$//;
1006: $entry .= '&';
1007: }
1008: }
1009: $entry =~ s/\&$//;
1010: if ($menucoll) {
1011: $menucoll .= ';';
1012: }
1013: $menucoll .= $num.'%'.$entry;
1014: }
1015: if ($menucoll ne $values->{'menucollections'}) {
1016: $changes->{'menucollections'} = $menucoll;
1017: }
1018: } elsif ($values->{'menucollections'}) {
1019: $changes->{'menucollections'} = '';
1020: }
1.102 raeburn 1021: } elsif ($action eq 'linkprot') {
1022: if (ref($values) eq 'HASH') {
1.108 raeburn 1023: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 1024: }
1.118 raeburn 1025: } elsif ($action eq 'ltitools') {
1026: if (ref($values) eq 'HASH') {
1027: my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1028: $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1029: 'ok','','ok');
1030: }
1.3 raeburn 1031: } else {
1032: foreach my $entry (@ordered) {
1033: if ($entry eq 'cloners') {
1034: if ($env{'form.cloners_all'}) {
1035: $newvalues{$entry} = '*';
1036: } else {
1037: my @clonedoms;
1038: if (exists($env{'form.cloners_activate'})) {
1039: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1040: if ($actnum ne '-1') {
1.33 raeburn 1041: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1042: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1043: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1044: $newvalues{$entry} = '*:'.$clonedom;
1045: push(@clonedoms,$newvalues{$entry});
1046: }
1047: }
1048: }
1049: } else {
1050: my $num = $env{'form.cloners_total'};
1051: my @deletes =
1052: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1053: for (my $i=0; $i<$num; $i++) {
1054: if (!grep(/^$i$/,@deletes)) {
1055: my $clonedom = $env{'form.cloners_dom_'.$i};
1056: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1057: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1058: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1059: }
1060: }
1061: }
1062: }
1063: if (@clonedoms) {
1064: $newvalues{$entry}=join(',',@clonedoms);
1065: }
1066: }
1067: if ($env{'form.cloners_newdom'} ne '') {
1068: my $clonedom = $env{'form.cloners_newdom'};
1069: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1070: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1071: if (@clonedoms) {
1.3 raeburn 1072: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1073: $newvalues{$entry} .= ','.$newdom;
1074: }
1075: } else {
1076: $newvalues{$entry} = $newdom;
1077: }
1078: }
1079: }
1080: if ($env{'form.'.$entry} ne '') {
1081: my @cloners = split(',',$env{'form.'.$entry});
1082: my @okcloners;
1083: foreach my $cloner (@cloners) {
1.23 raeburn 1084: $cloner =~ s/^\s+//;
1085: $cloner =~ s/\s+$//;
1086: unless ($cloner eq '') {
1087: my ($uname,$udom) = split(':',$cloner);
1088: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1089: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1090: push(@okcloners,$cloner);
1091: }
1.3 raeburn 1092: }
1093: }
1094: }
1095: if (@okcloners) {
1096: my $okclonestr = join(',',@okcloners);
1097: if ($newvalues{$entry} ne '') {
1098: $newvalues{$entry} .= ','.$okclonestr;
1099: } else {
1100: $newvalues{$entry} = $okclonestr;
1101: }
1102: }
1103: }
1.71 raeburn 1104: if (ref($values) eq 'HASH') {
1105: my (@code_order,%codedefaults);
1106: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1107: \@code_order);
1108: my $clonebycode;
1109: if ($env{'form.cloners_instcode'}) {
1110: if (@code_order > 0) {
1111: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1112: my %local_to_standard;
1113: for (my $i=0; $i<@code_order; $i++) {
1114: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1115: }
1116: foreach my $item (@code_order) {
1117: my $key = $local_to_standard{$item};
1118: if ($key ne '') {
1119: if ($env{'form.'.$key}) {
1120: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1121: }
1122: }
1123: }
1124: $clonebycode =~ s/\&$//;
1125: }
1126: }
1127: if ($clonebycode) {
1128: if ($newvalues{$entry}) {
1129: $newvalues{$entry} .= ','.$clonebycode;
1130: } else {
1131: $newvalues{$entry} = $clonebycode;
1132: }
1133: }
1134: }
1.3 raeburn 1135: }
1136: if (ref($disallowed) eq 'HASH') {
1137: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1138: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1139: $disallowed->{'cloners'}{$key} =~ s/,$//;
1140: }
1141: }
1142: }
1.25 raeburn 1143: } elsif ($entry eq 'co-owners') {
1144: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1145: my $coowners = $values->{'internal.co-owners'};
1146: my @currcoown;
1147: if ($coowners) {
1148: @currcoown = split(',',$coowners);
1149: }
1150: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1151: my $autocoowner;
1152: if (($crstype eq 'Course') &&
1153: ($values->{'internal.coursecode'})) {
1154: my %domconf =
1155: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1156: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1157: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1158: }
1159: }
1.96 raeburn 1160: if ($autocoowner) {
1161: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1162: } else {
1.25 raeburn 1163: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1164: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1165: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1166: if (@invitecoowners) {
1167: push(@pendingcoowners,@invitecoowners);
1168: }
1169: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1170: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1171: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1172: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1173: push(@{$changes->{$entry}{'changed'}},'co-owners');
1174: }
1175: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1176: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1177: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1178: }
1179: }
1180: } else {
1181: my (@newpending,@newcoown);
1182: my $uname = $env{'user.name'};
1183: my $udom = $env{'user.domain'};
1184: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1185: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1186: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1187: foreach my $item (@pendingcoown) {
1188: unless ($item eq $uname.':'.$udom) {
1189: push(@newpending,$item);
1190: }
1191: }
1192: @newcoown = @currcoown;
1.90 raeburn 1193: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1194: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1195: push(@newcoown,$uname.':'.$udom);
1196: }
1197: }
1.90 raeburn 1198: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1199: foreach my $item (@currcoown) {
1200: unless ($item eq $uname.':'.$udom) {
1201: push(@newcoown,$item);
1202: }
1203: }
1204: if ($pendingcoowners ne '') {
1205: @newpending = @pendingcoown;
1206: }
1.96 raeburn 1207: } else {
1208: @newcoown = @currcoown;
1.25 raeburn 1209: }
1210: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1211: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1212: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1213: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1214: push(@{$changes->{$entry}{'changed'}},'co-owners');
1215: }
1216: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1217: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1218: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1219: }
1220: }
1.3 raeburn 1221: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1222: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1223: } elsif ($entry eq 'rolenames') {
1224: my %adv_roles =
1225: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1226: my @stds;
1227: if ($crstype eq 'Community') {
1228: @stds = ('co');
1229: } else {
1230: @stds = ('cc');
1231: }
1232: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1233: my (@replacements,@regulars);
1234: foreach my $role (@stds) {
1235: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1236: push(@replacements,$role);
1.3 raeburn 1237: } else {
1238: push(@regulars,$role);
1239: }
1.9 raeburn 1240: }
1.3 raeburn 1241: foreach my $stdrole (@stds) {
1242: my $ext_entry = $entry.'_'.$stdrole;
1243: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1244: $env{'request.course.id'},1);
1245: if ($env{'form.'.$ext_entry} eq $stdname) {
1246: $newvalues{$ext_entry} = '';
1247: } else {
1248: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1249: }
1250: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1251: my $dupname = 0;
1252: if ($newvalues{$ext_entry} ne '') {
1253: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1254: $dupname = 1;
1255: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1256: }
1257: if (!$dupname) {
1258: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1259: $dupname = 1;
1260: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1261: }
1262: }
1263: if (!$dupname) {
1264: foreach my $role (keys(%adv_roles)) {
1265: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1266: $dupname = 1;
1267: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1268: last;
1269: }
1270: }
1271: }
1272: }
1273: if (!$dupname) {
1274: $changes->{$ext_entry} = $newvalues{$ext_entry};
1275: }
1276: }
1277: }
1.77 raeburn 1278: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1279: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1280: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1281: @denied = sort(@denied);
1282: my $deniedstr = '';
1283: if (@denied > 0) {
1284: $deniedstr = join(',',@denied);
1285: }
1286: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1287: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1288: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1289: my $total = $env{'form.'.$entry.'_total'};
1290: my $userstr = '';
1291: my @denied;
1292: if ($total > 0) {
1293: my @deletes =
1294: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1295: for (my $i=0; $i<$total; $i++) {
1296: unless (grep(/^$i$/,@deletes)) {
1297: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1298: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1299: }
1300: }
1301: } else {
1302: $total = 0;
1303: }
1304: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1305: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1306: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1307: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1308: $userstr =~ s/,$//;
1309: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1310: } else {
1311: my $newuser .= $uname.':'.$udom;
1312: if (grep(/^\Q$newuser\E$/,@denied)) {
1313: $userstr =~ s/,$//;
1314: } else {
1315: $userstr .= $newuser;
1316: }
1317: }
1318: } else {
1319: $userstr =~ s/,$//;
1320: }
1321: $newvalues{$entry} = $userstr;
1322: } elsif ($entry eq 'allow_discussion_post_editing') {
1323: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1324: @canedit = sort(@canedit);
1325: foreach my $role (@canedit) {
1326: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1327: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1328: $newvalues{$entry} .= $role.',';
1329: } else {
1330: foreach my $sec (@secs) {
1331: $newvalues{$entry} .= $role.':'.$sec.',';
1332: }
1333: }
1334: }
1335: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1336: } elsif ($entry eq 'discussion_post_fonts') {
1337: my ($classorder,$classtitles) = &discussion_vote_classes();
1338: my $fontchange = 0;
1339: foreach my $class (@{$classorder}) {
1340: my $ext_entry = $entry.'_'.$class;
1341: my $size = $env{'form.'.$ext_entry.'_size'};
1342: my $unit = $env{'form.'.$ext_entry.'_unit'};
1343: my $weight = $env{'form.'.$ext_entry.'_weight'};
1344: my $style = $env{'form.'.$ext_entry.'_style'};
1345: my $other = $env{'form.'.$ext_entry.'_other'};
1346: $size =~ s/,//g;
1347: $unit =~ s/,//g;
1348: $weight =~ s/,//g;
1349: $style =~ s/,//g;
1350: $other =~ s/[^\w;:\s\-\%.]//g;
1351: $other =~ s/(^\s+|\s+$)//g;
1352: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1353: my $current = $values->{$ext_entry};
1354: if ($values->{$ext_entry} eq '') {
1355: $current = ',,,';
1356: }
1357: if ($newvalues{$ext_entry} ne $current) {
1358: $changes->{$ext_entry} = $newvalues{$ext_entry};
1359: $fontchange ++;
1360: }
1361: }
1362: if ($fontchange) {
1363: $changes->{$entry} = 1;
1364: }
1.3 raeburn 1365: } elsif ($entry eq 'nothideprivileged') {
1366: my @curr_nothide;
1367: my @new_nothide;
1368: if ($values->{$entry} ne '') {
1369: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1370: my $nothide;
1371: if ($user !~ /:/) {
1372: $nothide = join(':',split(/[\@]/,$user));
1373: } else {
1374: $nothide = $user;
1375: }
1376: if ((defined($nothide)) &&
1377: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1378: push(@curr_nothide,$nothide);
1379: }
1380: }
1381: }
1382: foreach my $key (keys(%env)) {
1383: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1384: if ($env{$key}) {
1.3 raeburn 1385: my $nothide = $1;
1386: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1387: push(@new_nothide,$nothide);
1388: }
1389: }
1390: }
1391: }
1392: @new_nothide = sort(@new_nothide);
1393: my @differences =
1394: &Apache::loncommon::compare_arrays(\@curr_nothide,
1395: \@new_nothide);
1396: if (@differences > 0) {
1397: if (@new_nothide > 0) {
1398: $newvalues{$entry} = join(',',@new_nothide);
1399: } else {
1400: $newvalues{$entry} = '';
1401: }
1402: } else {
1403: $newvalues{$entry} = $values->{$entry};
1404: }
1405: } elsif ($entry eq 'print_header_format') {
1406: my $maxnum = $env{'form.printfmthdr_maxnum'};
1407: my @newhdr;
1408: if ($maxnum > 2) {
1409: for (my $i=0; $i<$maxnum-2; $i++) {
1410: if ($env{'form.printfmthdr_del_'.$i}) {
1411: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1412: } else {
1413: my $hdr;
1414: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1415: $hdr = '%';
1416: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1417: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1418: }
1419: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1420: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1421: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1422: }
1423: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1424: }
1425: }
1426: }
1427: my $newsub = $maxnum-2;
1428: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1429: my $hdr = '%';
1430: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1431: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1432: }
1433: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1434: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1435: }
1436: my $newtext = $maxnum-1;
1437: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1438: $newvalues{$entry} = join('',@newhdr);
1.56 raeburn 1439: } elsif (($entry eq 'languages') ||
1440: ($entry eq 'checkforpriv')) {
1441: my $settings;
1.3 raeburn 1442: my $total = $env{'form.'.$entry.'_total'};
1443: if ($total) {
1444: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1445: for (my $i=0; $i<$total; $i++) {
1446: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1447: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1448: }
1449: }
1450: } else {
1451: $total = 0;
1452: }
1453: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1454: my $new = $env{'form.'.$entry.'_'.$total};
1455: if ($entry eq 'languages') {
1456: my %langchoices = &get_lang_choices();
1457: if ($langchoices{$new}) {
1458: $settings .= $new;
1459: } else {
1460: $settings =~ s/,$//;
1461: $disallowed->{'localization'}{$entry} = $new;
1462: }
1.3 raeburn 1463: } else {
1.56 raeburn 1464: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1465: if ($domains{$new}) {
1466: $settings .= $new;
1467: } else {
1468: $settings =~ s/,$//;
1469: $disallowed->{'classlists'}{$entry} = $new;
1470: }
1.3 raeburn 1471: }
1472: } else {
1.56 raeburn 1473: $settings =~ s/,$//;
1.3 raeburn 1474: }
1.56 raeburn 1475: $newvalues{$entry} = $settings;
1.87 raeburn 1476: } elsif ($action eq 'lti') {
1477: if ($entry eq 'lti.override') {
1478: $newvalues{$entry} = $env{'form.'.$entry};
1479: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1480: if ($env{'form.lti.override'}) {
1481: $newvalues{$entry} = $env{'form.'.$entry};
1482: } else {
1483: $newvalues{$entry} = '';
1484: }
1485: } elsif ($entry eq 'lti.lcmenu') {
1486: if (($env{'form.lti.override'}) &&
1487: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1488: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1489: my @newlcmenu;
1490: if (@lcmenu) {
1491: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1492: foreach my $item (@menuitems) {
1493: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1494: if (grep(/^\Q$item\E$/,@lcmenu)) {
1495: push(@newlcmenu,$item);
1496: }
1497: }
1498: }
1499: if (@newlcmenu) {
1500: $newvalues{$entry} = join(',',@newlcmenu);
1501: } else {
1502: $newvalues{$entry} = 'none';
1503: }
1504: } else {
1505: $newvalues{$entry} = '';
1506: }
1507: }
1.114 raeburn 1508: } elsif ($entry eq 'extresource') {
1509: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1510: $newvalues{$entry} = $env{'form.'.$entry};
1511: if ($env{'form.'.$entry} ne 'iframe') {
1512: if ($env{'form.extwintabreuse'}) {
1513: $newvalues{$entry} .= ':1';
1514: } else {
1515: $newvalues{$entry} .= ':0';
1516: }
1517: if ($env{'form.'.$entry} eq 'window') {
1518: foreach my $dim ('width','height') {
1519: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1520: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1521: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1522: } else {
1523: $newvalues{$entry} .= ':';
1524: }
1525: }
1526: }
1527: }
1528: }
1529: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1530: if ($newvalues{$entry} ne $values->{$entry}) {
1531: $changes->{$entry} = $newvalues{$entry};
1532: }
1533: }
1.115 raeburn 1534: } elsif ($entry eq 'timezone') {
1535: if ($env{'form.'.$entry}) {
1536: $newvalues{$entry} = $env{'form.'.$entry};
1537: if ($newvalues{$entry} ne $values->{$entry}) {
1538: $changes->{$entry} = $newvalues{$entry};
1539: }
1540: if ($env{'form.tzover'}) {
1541: $newvalues{'tzover'} = $env{'form.tzover'};
1542: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1543: $changes->{'tzover'} = $newvalues{'tzover'};
1544: }
1545: } elsif ($values->{'tzover'}) {
1546: $changes->{'tzover'} = '';
1547: }
1548: } elsif ($values->{$entry}) {
1549: $changes->{$entry} = '';
1550: }
1.3 raeburn 1551: } else {
1552: $newvalues{$entry} = $env{'form.'.$entry};
1553: }
1.115 raeburn 1554: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1555: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1556: if ($newvalues{$entry} ne $values->{$entry}) {
1557: $changes->{$entry} = $newvalues{$entry};
1558: }
1.3 raeburn 1559: }
1560: }
1561: }
1562: }
1563: }
1564: }
1.93 raeburn 1565: return $errors;
1566: }
1567:
1.102 raeburn 1568: sub process_linkprot {
1.108 raeburn 1569: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.118 raeburn 1570: my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1571: if (ref($values) eq 'HASH') {
1572: foreach my $id (keys(%{$values})) {
1573: if ($id =~ /^\d+$/) {
1574: unless (ref($values->{$id}) eq 'HASH') {
1575: $linkprot{$id} = '';
1576: }
1577: }
1578: }
1579: }
1.118 raeburn 1580: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.102 raeburn 1581: if ($context eq 'domain') {
1582: $dest = '/adm/domainprefs';
1583: $ltiauth = 1;
1584: } else {
1585: $dest = '/adm/courseprefs';
1586: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1587: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1588: } else {
1589: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1590: $ltiauth = $domdefs{'crsltiauth'};
1591: }
1592: }
1593: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1594: my (@items,%deletions,%itemids,%haschanges);
1595: if ($env{'form.linkprot_add'}) {
1596: my $name = $env{'form.linkprot_name_add'};
1597: $name =~ s/(`)/'/g;
1598: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1599: if ($newid) {
1600: $itemids{'add'} = $newid;
1601: push(@items,'add');
1602: $haschanges{$newid} = 1;
1603: } else {
1604: $errors .= '<span class="LC_error">'.
1605: &mt('Failed to acquire unique ID for link protection').
1606: '</span>';
1607: }
1608: }
1609: if (ref($values) eq 'HASH') {
1610: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1611: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1612: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1613: my $itemid = $env{'form.linkprot_id_'.$i};
1614: $itemid =~ s/\D+//g;
1615: if ($itemid) {
1616: if (ref($values->{$itemid}) eq 'HASH') {
1617: push(@items,$i);
1618: $itemids{$i} = $itemid;
1619: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1620: $deletions{$itemid} = $values->{$itemid}->{'name'};
1621: }
1622: }
1623: }
1624: }
1625: }
1626: foreach my $idx (@items) {
1627: my $itemid = $itemids{$idx};
1628: next unless ($itemid);
1629: if (exists($deletions{$itemid})) {
1630: $linkprot{$itemid} = $deletions{$itemid};
1631: $haschanges{$itemid} = 1;
1632: next;
1633: }
1634: my %current;
1635: if (ref($values) eq 'HASH') {
1636: if (ref($values->{$itemid}) eq 'HASH') {
1637: foreach my $key (keys(%{$values->{$itemid}})) {
1638: $current{$key} = $values->{$itemid}->{$key};
1639: }
1640: }
1641: }
1642: foreach my $inner ('name','lifetime','version') {
1643: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1644: $env{$formitem} =~ s/(`)/'/g;
1645: if ($inner eq 'lifetime') {
1646: $env{$formitem} =~ s/[^\d.]//g;
1647: }
1648: unless ($idx eq 'add') {
1649: if ($current{$inner} ne $env{$formitem}) {
1650: $haschanges{$itemid} = 1;
1651: }
1652: }
1653: if ($env{$formitem} ne '') {
1654: $linkprot{$itemid}{$inner} = $env{$formitem};
1655: }
1656: }
1.112 raeburn 1657: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1658: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1659: if ($env{$urlitem} == 1) {
1660: $env{$urlparamname} =~ s/(`)/'/g;
1661: } elsif (exists($env{$urlparamname})) {
1662: $env{$urlparamname} = '';
1663: }
1664: unless ($idx eq 'add') {
1665: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1666: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1667: $haschanges{$itemid} = 1;
1668: }
1669: }
1670: if ($env{$urlparamname} ne '') {
1671: $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1672: }
1.102 raeburn 1673: if ($ltiauth) {
1674: my $reqitem = 'form.linkprot_requser_'.$idx;
1675: $env{$reqitem} =~ s/(`)/'/g;
1676: unless ($idx eq 'add') {
1.104 raeburn 1677: if ((!$current{'requser'} && $env{$reqitem}) ||
1678: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1679: $haschanges{$itemid} = 1;
1680: }
1681: }
1682: if ($env{$reqitem} == 1) {
1683: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1684: foreach my $inner ('mapuser','notstudent') {
1685: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1686: $env{$formitem} =~ s/(`)/'/g;
1687: if ($inner eq 'mapuser') {
1688: if ($env{$formitem} eq 'other') {
1689: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1690: $mapuser =~ s/(`)/'/g;
1691: $mapuser =~ s/^\s+|\s+$//g;
1692: if ($mapuser ne '') {
1693: $linkprot{$itemid}{$inner} = $mapuser;
1694: } else {
1695: delete($linkprot{$itemid}{'requser'});
1696: last;
1697: }
1698: } elsif ($env{$formitem} eq 'sourcedid') {
1699: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1700: } elsif ($env{$formitem} eq 'email') {
1701: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1702: }
1703: } else {
1704: $linkprot{$itemid}{$inner} = $env{$formitem};
1705: }
1706: unless ($idx eq 'add') {
1707: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1708: $haschanges{$itemid} = 1;
1709: }
1710: }
1711: }
1712: }
1713: }
1714: unless ($switchserver) {
1715: my $keyitem = 'form.linkprot_key_'.$idx;
1716: $env{$keyitem} =~ s/(`)/'/g;
1717: unless ($idx eq 'add') {
1718: if ($current{'key'} ne $env{$keyitem}) {
1719: $haschanges{$itemid} = 1;
1720: }
1721: }
1722: if ($env{$keyitem} ne '') {
1723: $linkprot{$itemid}{'key'} = $env{$keyitem};
1724: }
1725: my $secretitem = 'form.linkprot_secret_'.$idx;
1726: $env{$secretitem} =~ s/(`)/'/g;
1727: if ($current{'usable'}) {
1728: if ($env{'form.linkprot_changesecret_'.$idx}) {
1729: if ($env{$secretitem} ne '') {
1.103 raeburn 1730: if ($privnum && $cipher) {
1731: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1732: $linkprot{$itemid}{'cipher'} = $privnum;
1733: } else {
1734: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1735: }
1.102 raeburn 1736: $haschanges{$itemid} = 1;
1737: }
1738: } else {
1739: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1740: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1741: }
1742: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1743: if ($privnum && $cipher) {
1744: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1745: $linkprot{$itemid}{'cipher'} = $privnum;
1746: } else {
1747: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1748: }
1.102 raeburn 1749: $haschanges{$itemid} = 1;
1750: }
1751: }
1752: }
1753: if (keys(%haschanges)) {
1754: foreach my $entry (keys(%haschanges)) {
1755: $changes->{$entry} = $linkprot{$entry};
1756: }
1.108 raeburn 1757: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1758: $lastactref->{'courselti'} = 1;
1.108 raeburn 1759: }
1.102 raeburn 1760: }
1761: return $errors;
1762: }
1763:
1764: sub get_linkprot_id {
1765: my ($cdom,$cnum,$name,$context) = @_;
1766: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1767: my $lockhash = {
1768: lock => $env{'user.name'}.
1769: ':'.$env{'user.domain'},
1770: };
1771: my $tries = 0;
1.102 raeburn 1772: my $gotlock;
1773: if ($context eq 'domain') {
1774: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1775: } else {
1776: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1777: }
1.93 raeburn 1778: my ($id,$error);
1779: while (($gotlock ne 'ok') && ($tries<10)) {
1780: $tries ++;
1781: sleep (0.1);
1.102 raeburn 1782: if ($context eq 'domain') {
1783: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1784: } else {
1785: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1786: }
1.93 raeburn 1787: }
1788: if ($gotlock eq 'ok') {
1.102 raeburn 1789: my %currids;
1790: if ($context eq 'domain') {
1791: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1792: } else {
1793: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1794: }
1.93 raeburn 1795: if ($currids{'lock'}) {
1796: delete($currids{'lock'});
1797: if (keys(%currids)) {
1798: my @curr = sort { $a <=> $b } keys(%currids);
1799: if ($curr[-1] =~ /^\d+$/) {
1800: $id = 1 + $curr[-1];
1801: } else {
1802: $id = 1;
1803: }
1804: } else {
1805: $id = 1;
1806: }
1807: if ($id) {
1.102 raeburn 1808: if ($context eq 'domain') {
1809: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1810: $error = 'nostore';
1811: }
1812: } else {
1813: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1814: $error = 'nostore';
1815: }
1.93 raeburn 1816: }
1817: } else {
1818: $error = 'nonumber';
1819: }
1820: }
1.102 raeburn 1821: my $dellockoutcome;
1822: if ($context eq 'domain') {
1823: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1824: } else {
1825: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1826: }
1.93 raeburn 1827: } else {
1828: $error = 'nolock';
1829: }
1830: return ($id,$error);
1.3 raeburn 1831: }
1832:
1.118 raeburn 1833: sub get_credentials {
1834: my ($cdom,$cnum,$type,$context) = @_;
1835: my ($cipher,$privnum,$home);
1836: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1837: my @ids=&Apache::lonnet::current_machine_ids();
1838: if ($context eq 'domain') {
1839: $home = &Apache::lonnet::domain($cdom,'primary');
1840: } else {
1841: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1842: }
1843: my ($hostskey,$domkey,$crskey);
1844: if ($type eq 'ltitools') {
1845: $hostskey = 'toolprivhosts';
1846: $domkey = 'toolenc_dom';
1847: $crskey = 'toolenc_crs';
1848: } else {
1849: $hostskey = 'ltiprivhosts';
1850: $domkey = 'linkprotenc_dom';
1851: $crskey = 'linkprotenc_crs';
1852: }
1853: if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1854: (($context eq 'course') && ($domdefs{$crskey}))) {
1855: unless (($home eq 'no_host') || ($home eq '')) {
1856: if (grep(/^\Q$home\E$/,@ids)) {
1857: if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1858: if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1859: my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1860: my $privkey = $privhash{'key'};
1861: $privnum = $privhash{'version'};
1862: if (($privnum) && ($privkey ne '')) {
1863: $cipher = Crypt::CBC->new({'key' => $privkey,
1864: 'cipher' => 'DES'});
1865: }
1866: }
1867: }
1868: }
1869: }
1870: }
1871: return ($cipher,$privnum);
1872: }
1873:
1874: sub process_ltitools {
1875: my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1876: $author_ok,$confname) = @_;
1877: my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1878:
1879: my (%posslti,%possfield);
1880: my @courseroles = ('cc','in','ta','ep','st');
1881: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1882: map { $posslti{$_} = 1; } @ltiroles;
1883: my @allfields = ('fullname','firstname','lastname','email','user','roles');
1884: map { $possfield{$_} = 1; } @allfields;
1885:
1.120 raeburn 1886: my ($dest,$privnum,$cipher);
1.118 raeburn 1887:
1888: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1889: if ($context eq 'domain') {
1890: $dest = '/adm/domainprefs';
1891: } else {
1892: $dest = '/adm/courseprefs';
1893: }
1894: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1895:
1896: my (@allpos,@items,%deletions,%itemids,%haschanges);
1897: if ($env{'form.ltitools_add'}) {
1898: my $title = $env{'form.ltitools_add_title'};
1899: $title =~ s/(`)/'/g;
1900: my ($newid,$error) = &get_ltitools_id($context,$cdom,$cnum,$title);
1901: if ($newid) {
1902: my $position = $env{'form.ltitools_add_pos'};
1903: $position =~ s/\D+//g;
1904: if ($position ne '') {
1905: $allpos[$position] = $newid;
1906: }
1907: $haschanges{$newid} = 1;
1908: foreach my $item ('title','url','lifetime') {
1909: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1910: if ($item eq 'lifetime') {
1911: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1912: }
1913: if ($env{'form.ltitools_add_'.$item}) {
1914: $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1915: }
1916: }
1917: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1918: $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1919: }
1920: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1921: $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1922: }
1923: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1924: $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1925: } else {
1926: $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1927: }
1928: foreach my $item ('width','height','linktext','explanation') {
1929: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1930: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1931: if (($item eq 'width') || ($item eq 'height')) {
1932: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1933: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1934: }
1935: } else {
1936: if ($env{'form.ltitools_add_'.$item} ne '') {
1937: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1938: }
1939: }
1940: }
1941: if ($env{'form.ltitools_add_target'} eq 'window') {
1942: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1943: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1944: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1945: } else {
1946: $ltitools{$newid}{'display'}{'target'} = 'iframe';
1947: }
1948: foreach my $item ('passback','roster') {
1949: if ($env{'form.ltitools_'.$item.'_add'}) {
1950: $ltitools{$newid}{$item} = 1;
1951: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1952: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1953: $lifetime =~ s/^\s+|\s+$//g;
1954: if ($lifetime =~ /^\d+\.?\d*$/) {
1955: $ltitools{$newid}{$item.'valid'} = $lifetime;
1956: }
1957: }
1958: }
1959: }
1960: if ($env{'form.ltitools_add_image.filename'} ne '') {
1961: my ($imageurl,$error) =
1962: &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
1963: $newid,$configuserok,$lonhost,$author_ok);
1964: if ($imageurl) {
1965: $ltitools{$newid}{'image'} = $imageurl;
1966: }
1967: if ($error) {
1968: &Apache::lonnet::logthis($error);
1969: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1970: }
1971: }
1972: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
1973: foreach my $field (@fields) {
1974: if ($possfield{$field}) {
1975: if ($field eq 'roles') {
1976: foreach my $role (@courseroles) {
1977: my $choice = $env{'form.ltitools_add_roles_'.$role};
1978: if (($choice ne '') && ($posslti{$choice})) {
1979: $ltitools{$newid}{'roles'}{$role} = $choice;
1980: if ($role eq 'cc') {
1981: $ltitools{$newid}{'roles'}{'co'} = $choice;
1982: }
1983: }
1984: }
1985: } else {
1986: $ltitools{$newid}{'fields'}{$field} = 1;
1987: }
1988: }
1989: }
1990: if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
1991: if ($ltitools{$newid}{'fields'}{'user'}) {
1992: if ($env{'form.ltitools_add_userincdom'}) {
1993: $ltitools{$newid}{'incdom'} = 1;
1994: }
1995: }
1996: }
1997: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
1998: foreach my $item (@courseconfig) {
1999: $ltitools{$newid}{'crsconf'}{$item} = 1;
2000: }
2001: if ($env{'form.ltitools_add_custom'}) {
2002: my $name = $env{'form.ltitools_add_custom_name'};
2003: my $value = $env{'form.ltitools_add_custom_value'};
2004: $value =~ s/(`)/'/g;
2005: $name =~ s/(`)/'/g;
2006: $ltitools{$newid}{'custom'}{$name} = $value;
2007: }
2008: unless ($switchserver) {
2009: my $keyitem = 'form.ltitools_add_key';
2010: $env{$keyitem} =~ s/(`)/'/g;
2011: if ($env{$keyitem} ne '') {
2012: $ltitools{$newid}{'key'} = $env{$keyitem};
2013: }
1.119 raeburn 2014: my $secretitem = 'form.ltitools_secret_add';
1.118 raeburn 2015: $env{$secretitem} =~ s/(`)/'/g;
2016: if ($env{$secretitem} ne '') {
2017: if ($privnum && $cipher) {
2018: $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2019: $ltitools{$newid}{'cipher'} = $privnum;
2020: } else {
2021: $ltitools{$newid}{'secret'} = $env{$secretitem};
2022: }
2023: }
2024: }
2025: } else {
2026: $errors .= '<li><span class="LC_error">'.
2027: &mt('Failed to acquire unique ID for new external tool').
2028: '</span></li>';
2029: }
2030: }
2031: if (ref($values) eq 'HASH') {
2032: my %deletions;
2033: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2034: if (@todelete) {
2035: map { $deletions{$_} = 1; } @todelete;
2036: }
2037: my %customadds;
2038: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2039: if (@newcustom) {
2040: map { $customadds{$_} = 1; } @newcustom;
2041: }
2042: my %imgdeletions;
2043: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2044: if (@todeleteimages) {
2045: map { $imgdeletions{$_} = 1; } @todeleteimages;
2046: }
2047: my $maxnum = $env{'form.ltitools_maxnum'};
2048: for (my $i=0; $i<=$maxnum; $i++) {
2049: my $itemid = $env{'form.ltitools_id_'.$i};
2050: $itemid =~ s/\D+//g;
2051: if (ref($values->{$itemid}) eq 'HASH') {
2052: if ($deletions{$itemid}) {
2053: if ($values->{$itemid}{'image'}) {
2054: #FIXME need to obsolete item in RES space
2055: }
2056: $haschanges{$itemid} = $values->{$itemid}{'title'};
2057: next;
2058: } else {
2059: my $newpos = $env{'form.ltitools_'.$itemid};
2060: $newpos =~ s/\D+//g;
2061: foreach my $item ('title','url','lifetime') {
2062: $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2063: if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2064: $haschanges{$itemid} = 1;
2065: }
2066: }
2067: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2068: $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2069: }
2070: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2071: $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2072: }
2073: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2074: $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2075: } else {
2076: $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2077: }
2078: if ($values->{$itemid}{'sigmethod'} eq '') {
2079: if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2080: $haschanges{$itemid} = 1;
2081: }
2082: } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2083: $haschanges{$itemid} = 1;
2084: }
2085: foreach my $size ('width','height') {
2086: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2087: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2088: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2089: $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2090: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2091: if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2092: $haschanges{$itemid} = 1;
2093: }
2094: } else {
2095: $haschanges{$itemid} = 1;
2096: }
2097: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2098: if ($values->{$itemid}{'display'}{$size} ne '') {
2099: $haschanges{$itemid} = 1;
2100: }
2101: }
2102: }
2103: foreach my $item ('linktext','explanation') {
2104: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2105: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2106: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2107: $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2108: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2109: if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2110: $haschanges{$itemid} = 1;
2111: }
2112: } else {
2113: $haschanges{$itemid} = 1;
2114: }
2115: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2116: if ($values->{$itemid}{'display'}{$item} ne '') {
2117: $haschanges{$itemid} = 1;
2118: }
2119: }
2120: }
2121: if ($env{'form.ltitools_target_'.$i} eq 'window') {
2122: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2123: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2124: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2125: } else {
2126: $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2127: }
2128: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2129: if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2130: $haschanges{$itemid} = 1;
2131: }
2132: } else {
2133: $haschanges{$itemid} = 1;
2134: }
2135: foreach my $extra ('passback','roster') {
2136: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2137: $ltitools{$itemid}{$extra} = 1;
2138: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2139: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2140: $lifetime =~ s/^\s+|\s+$//g;
2141: if ($lifetime =~ /^\d+\.?\d*$/) {
2142: $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2143: }
2144: }
2145: }
2146: if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2147: $haschanges{$itemid} = 1;
2148: }
2149: if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2150: $haschanges{$itemid} = 1;
2151: }
2152: }
2153: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2154: foreach my $item ('label','title','target','linktext','explanation','append') {
2155: if (grep(/^\Q$item\E$/,@courseconfig)) {
2156: $ltitools{$itemid}{'crsconf'}{$item} = 1;
2157: if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2158: if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2159: $haschanges{$itemid} = 1;
2160: }
2161: } else {
2162: $haschanges{$itemid} = 1;
2163: }
2164: }
2165: }
2166: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2167: foreach my $field (@fields) {
2168: if ($possfield{$field}) {
2169: if ($field eq 'roles') {
2170: foreach my $role (@courseroles) {
2171: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2172: if (($choice ne '') && ($posslti{$choice})) {
2173: $ltitools{$itemid}{'roles'}{$role} = $choice;
2174: if ($role eq 'cc') {
2175: $ltitools{$itemid}{'roles'}{'co'} = $choice;
2176: }
2177: }
2178: if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2179: if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2180: $haschanges{$itemid} = 1;
2181: }
2182: } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2183: $haschanges{$itemid} = 1;
2184: }
2185: }
2186: } else {
2187: $ltitools{$itemid}{'fields'}{$field} = 1;
2188: if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2189: if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2190: $haschanges{$itemid} = 1;
2191: }
2192: } else {
2193: $haschanges{$itemid} = 1;
2194: }
2195: }
2196: }
2197: }
2198: if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2199: if ($ltitools{$itemid}{'fields'}{'user'}) {
2200: if ($env{'form.ltitools_userincdom_'.$i}) {
2201: $ltitools{$itemid}{'incdom'} = 1;
2202: }
2203: if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2204: $haschanges{$itemid} = 1;
2205: }
2206: }
2207: }
2208: $allpos[$newpos] = $itemid;
2209: }
2210: if ($imgdeletions{$itemid}) {
2211: $haschanges{$itemid} = 1;
2212: if ($context eq 'course') {
2213: my $currimgurl = $values->{$itemid}{'image'};
2214: if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2215: my ($path,$imagefile) = ($1,$2);
2216: if ($imagefile =~ /^tn\-(.+)$/) {
2217: my $origimg = $1;
2218: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2219: }
2220: &Apache::lonnet::removeuploadedurl($currimgurl);
2221: }
2222: }
2223: #FIXME need to obsolete item in RES space
2224: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2225: my $currimgurl = $values->{$itemid}{'image'};
2226: my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2227: $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2228: if ($imgurl) {
2229: $ltitools{$itemid}{'image'} = $imgurl;
2230: $haschanges{$itemid} = 1;
2231: }
2232: if ($error) {
2233: &Apache::lonnet::logthis($error);
2234: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2235: }
2236: } elsif ($values->{$itemid}{'image'}) {
2237: $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2238: }
2239: if ($customadds{$i}) {
2240: my $name = $env{'form.ltitools_custom_name_'.$i};
2241: $name =~ s/(`)/'/g;
2242: $name =~ s/^\s+//;
2243: $name =~ s/\s+$//;
2244: my $value = $env{'form.ltitools_custom_value_'.$i};
2245: $value =~ s/(`)/'/g;
2246: $value =~ s/^\s+//;
2247: $value =~ s/\s+$//;
2248: if ($name ne '') {
2249: $ltitools{$itemid}{'custom'}{$name} = $value;
2250: $haschanges{$itemid} = 1;
2251: }
2252: }
2253: my %customdels;
2254: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2255: if (@customdeletions) {
2256: $haschanges{$itemid} = 1;
2257: }
2258: map { $customdels{$_} = 1; } @customdeletions;
2259: if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2260: foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2261: unless ($customdels{$key}) {
2262: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2263: $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2264: }
2265: if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2266: $haschanges{$itemid} = 1;
2267: }
2268: }
2269: }
2270: }
2271: unless ($switchserver) {
2272: my $keyitem = 'form.ltitools_key_'.$i;
2273: $env{$keyitem} =~ s/(`)/'/g;
2274: if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2275: $haschanges{$itemid} = 1;
2276: }
2277: if ($env{$keyitem} ne '') {
2278: $ltitools{$itemid}{'key'} = $env{$keyitem};
2279: }
2280: my $secretitem = 'form.ltitools_secret_'.$i;
2281: $env{$secretitem} =~ s/(`)/'/g;
2282: if ($values->{$itemid}{'usable'}) {
2283: if ($env{'form.ltitools_changesecret_'.$i}) {
2284: if ($env{$secretitem} ne '') {
2285: if ($privnum && $cipher) {
2286: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2287: $ltitools{$itemid}{'cipher'} = $privnum;
2288: } else {
2289: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2290: }
2291: $haschanges{$itemid} = 1;
2292: }
2293: } else {
2294: $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2295: $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2296: }
2297: } elsif ($env{$secretitem} ne '') {
2298: if ($privnum && $cipher) {
2299: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2300: $ltitools{$itemid}{'cipher'} = $privnum;
2301: } else {
2302: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2303: }
2304: $haschanges{$itemid} = 1;
2305: }
2306: }
2307: unless ($haschanges{$itemid}) {
2308: foreach my $key (keys(%{$values->{$itemid}})) {
2309: if (ref($values->{$itemid}{$key}) eq 'HASH') {
2310: if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2311: foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2312: unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2313: $haschanges{$itemid} = 1;
2314: last;
2315: }
2316: }
2317: } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2318: $haschanges{$itemid} = 1;
2319: }
2320: }
2321: last if ($haschanges{$itemid});
2322: }
2323: }
2324: }
2325: }
2326: }
2327: if (@allpos > 0) {
2328: my $idx = 0;
2329: foreach my $itemid (@allpos) {
2330: if ($itemid ne '') {
2331: $ltitools{$itemid}{'order'} = $idx;
2332: if (ref($values) eq 'HASH') {
2333: if (ref($values->{$itemid}) eq 'HASH') {
2334: if ($values->{$itemid}{'order'} ne $idx) {
2335: $haschanges{$itemid} = 1;
2336: }
2337: }
2338: }
2339: $idx ++;
2340: }
2341: }
2342: }
2343: if (keys(%haschanges)) {
2344: foreach my $entry (keys(%haschanges)) {
2345: $changes->{$entry} = $ltitools{$entry};
2346: }
2347: if (ref($lastactref) eq 'HASH') {
2348: $lastactref->{'courseltitools'} = 1;
2349: }
2350: }
2351: return $errors;
2352: }
2353:
2354: sub get_ltitools_id {
2355: my ($context,$cdom,$cnum,$title) = @_;
2356: my ($lockhash,$tries,$gotlock,$id,$error);
2357:
2358: # get lock on ltitools db
2359: $lockhash = {
2360: lock => $env{'user.name'}.
2361: ':'.$env{'user.domain'},
2362: };
2363: $tries = 0;
2364: if ($context eq 'domain') {
2365: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
2366: } else {
2367: $gotlock = &Apache::lonnet::newput('ltitools',$lockhash,$cdom,$cnum);
2368: }
2369: while (($gotlock ne 'ok') && ($tries<10)) {
2370: $tries ++;
2371: sleep (0.1);
2372: if ($context eq 'domain') {
2373: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
2374: } else {
2375: $gotlock = &Apache::lonnet::newput('ltitools',$lockhash,$cdom,$cnum);
2376: }
2377: }
2378: if ($gotlock eq 'ok') {
2379: my %currids;
2380: if ($context eq 'domain') {
2381: %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
2382: } else {
2383: %currids = &Apache::lonnet::dump('ltitools',$cdom,$cnum);
2384: }
2385: if ($currids{'lock'}) {
2386: delete($currids{'lock'});
2387: if (keys(%currids)) {
2388: my @curr = sort { $a <=> $b } keys(%currids);
2389: if ($curr[-1] =~ /^\d+$/) {
2390: $id = 1 + $curr[-1];
2391: }
2392: } else {
2393: $id = 1;
2394: }
2395: if ($id) {
2396: if ($context eq 'domain') {
2397: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
2398: $error = 'nostore';
2399: }
2400: } else {
2401: unless (&Apache::lonnet::newput('ltitools',{ $id => $title },$cdom,$cnum) eq 'ok') {
2402: $error = 'nostore';
2403: }
2404: }
2405: } else {
2406: $error = 'nonumber';
2407: }
2408: }
2409: my $dellockoutcome;
2410: if ($context eq 'domain') {
2411: $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
2412: } else {
2413: $dellockoutcome = &Apache::lonnet::del('ltitools',['lock'],$cdom,$cnum);
2414: }
2415: } else {
2416: $error = 'nolock';
2417: }
2418: return ($id,$error);
2419: }
2420:
2421: sub process_ltitools_image {
2422: my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2423: my $filename = $env{'form.'.$caller.'.filename'};
2424: my ($error,$url);
2425: my ($width,$height) = (21,21);
2426: if ($configuserok eq 'ok') {
2427: if ($switch) {
2428: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2429: $switch);
2430: } elsif ($author_ok eq 'ok') {
2431: my ($result,$imageurl,$madethumb);
2432: if ($context eq 'domain') {
2433: ($result,$imageurl,$madethumb) =
2434: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2435: "ltitools/$itemid/icon",$width,$height);
2436: } else {
2437: ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2438: }
2439: if ($result eq 'ok') {
2440: if ($madethumb) {
2441: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2442: my $imagethumb = "$path/tn-".$imagefile;
2443: $url = $imagethumb;
2444: } else {
2445: $url = $imageurl;
2446: }
2447: } else {
2448: if ($context eq 'domain') {
2449: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2450: } else {
2451: $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2452: }
2453: }
2454: } else {
2455: $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);
2456: }
2457: } else {
2458: $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);
2459: }
2460: return ($url,$error);
2461: }
2462:
2463: sub processlogo {
2464: my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2465: my ($result,$imageurl,$madethumb);
2466: if ($env{"form.$caller.filename"} ne '') {
2467: unless ($caller eq 'ltitools_add_image') {
2468: if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2469: my ($path,$imagefile) = ($1,$2);
2470: if ($imagefile =~ /^tn\-(.+)$/) {
2471: my $origimg = $1;
2472: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2473: }
2474: &Apache::lonnet::removeuploadedurl($currimg);
2475: }
2476: }
2477: $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2478: '','','',$cnum,$dom,$width,$height);
2479: if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2480: my ($path,$imagefile) = ($1,$2);
2481: $result = 'ok';
2482: my $thumburl = "$path/tn-".$imagefile;
2483: my ($rtncode,$info);
2484: my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2485: if ($res eq 'ok') {
2486: $madethumb = 1;
2487: }
2488: } elsif ($imageurl eq '/adm/notfound.html') {
2489: undef($imageurl);
2490: $result = 'store failed';
2491: } elsif ($imageurl =~ /^error: (.+)$/) {
2492: $result = $1;
2493: }
2494: }
2495: return ($result,$imageurl,$madethumb);
2496: }
2497:
1.3 raeburn 2498: sub get_sec_str {
2499: my ($entry,$num) = @_;
2500: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2501: my $secstr;
2502: if (grep(/^\s*$/,@secs)) {
2503: $secstr = '';
2504: } elsif (@secs > 0) {
2505: $secstr = join(';',@secs);
2506: }
2507: if ($secstr ne '') {
2508: return '('.$secstr.')';
2509: }
2510: return;
2511: }
2512:
2513: sub check_clone {
2514: my ($clonedom,$disallowed,$clonename) = @_;
2515: return if (ref($disallowed) ne 'HASH');
2516: if ($clonedom !~ /^$match_domain$/) {
2517: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2518: return;
2519: } elsif (!&Apache::lonnet::domain($clonedom)) {
2520: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2521: return;
2522: }
2523: if ($clonename ne '') {
2524: if ($clonename !~ /^$match_username$/) {
2525: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2526: return;
2527: } else {
2528: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2529: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2530: return;
2531: }
2532: }
2533: }
2534: return 'ok';
2535: }
2536:
2537: sub store_changes {
1.9 raeburn 2538: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2539: my ($chome,$output);
1.118 raeburn 2540: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2541: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 2542: if (ref($values->{'linkprot'}) eq 'HASH') {
2543: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 2544: }
1.102 raeburn 2545: delete($values->{'linkprot'});
1.118 raeburn 2546: if (ref($values->{'ltitools'}) eq 'HASH') {
2547: %oldltitools = %{$values->{'ltitools'}};
2548: }
1.3 raeburn 2549: %storehash = %{$values};
2550: } else {
1.9 raeburn 2551: if ($crstype eq 'Community') {
2552: $output = &mt('No changes made to community settings.');
2553: } else {
2554: $output = &mt('No changes made to course settings.');
2555: }
2556: return $output;
1.3 raeburn 2557: }
1.93 raeburn 2558: my ($numchanges,$skipstore);
2559: if (ref($changes) eq 'HASH') {
2560: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 2561: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 2562: $skipstore = 1;
1.118 raeburn 2563: } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2564: $skipstore = 1;
1.93 raeburn 2565: } elsif (!$numchanges) {
2566: if ($crstype eq 'Community') {
2567: $output = &mt('No changes made to community settings.');
2568: } else {
2569: $output = &mt('No changes made to course settings.');
2570: }
2571: return $output;
2572: }
2573: }
1.3 raeburn 2574: my %yesno = (
2575: hidefromcat => '1',
2576: problem_stream_switch => '1',
2577: suppress_tries => '1',
2578: disableexampointprint => '1',
2579: hideemptyrows => '1',
2580: suppress_embed_prompt => '1',
2581: );
2582: foreach my $item (@{$prefs_order}) {
2583: if (grep(/^\Q$item\E$/,@{$actions})) {
2584: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2585: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 2586: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2587: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2588: if ($item eq 'other') {
2589: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2590: $storehash{$key} = $changes->{$item}{$key};
2591: if ($changes->{$item}{$key} eq '') {
2592: push(@delkeys,$key);
1.22 wenzelju 2593: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2594: } else {
1.22 wenzelju 2595: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2596: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2597: }
2598: }
1.102 raeburn 2599: } elsif ($item eq 'linkprot') {
2600: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.118 raeburn 2601: } elsif ($item eq 'ltitools') {
2602: $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2603: } else {
2604: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2605: my @settings = @{$prefs->{$item}->{'ordered'}};
2606: if ($item eq 'feedback') {
2607: push(@settings,(map { $_.'.text'; } @settings));
2608: }
2609: foreach my $key (@settings) {
2610: if ($key eq 'rolenames') {
2611: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2612: my $msg;
1.9 raeburn 2613: my @roles;
2614: if ($crstype eq 'Community') {
2615: @roles = ('co');
2616: } else {
2617: @roles = ('cc');
2618: }
2619: push(@roles,('in','ta','ep','ad','st'));
2620: foreach my $role (@roles) {
1.3 raeburn 2621: next if (!exists($changes->{$item}{$key.'_'.$role}));
2622: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2623: my $newname = $changes->{$item}{$key.'_'.$role};
2624: $storehash{$role.'.plaintext'} = $newname;
2625: if ($newname eq '') {
2626: $newname = $stdname;
2627: }
2628: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2629: "'<b>".$newname."</b>'").'</li>';
2630: }
2631: if ($msg ne '') {
1.22 wenzelju 2632: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2633: }
1.115 raeburn 2634: } elsif ($key eq 'timezone') {
2635: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2636: my ($displayname,$text);
2637: $text = $prefs->{$item}->{'itemtext'}{$key};
2638: my $displayval;
2639: if (exists($changes->{$item}{$key})) {
2640: $displayname = &mt($text);
2641: $storehash{$key} = $changes->{$item}{$key};
2642: if ($changes->{$item}{$key} ne '') {
2643: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2644: } else {
2645: push(@delkeys,$key);
2646: if (exists($values->{'tzover'})) {
2647: push(@delkeys,'tzover');
2648: }
2649: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2650: '<i>'.$displayname.'</i>')).'</li>';
2651: }
2652: }
2653: unless (grep(/^\Q$key\E$/,@delkeys)) {
2654: if (exists($changes->{$item}{'tzover'})) {
2655: $storehash{'tzover'} = $changes->{$item}{'tzover'};
2656: my $tzovertext;
2657: if ($changes->{$item}{'tzover'} ne '') {
2658: $tzovertext = &mt('Course Time Zone overrides individual user preference');
2659: } else {
2660: push(@delkeys,'tzover');
2661: $tzovertext = &mt('Course Time Zone does not override individual user preference');
2662: }
2663: if ($displayval eq '') {
2664: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2665: } else {
2666: $displayval .= '<br />'.(' 'x5).$tzovertext;
2667: }
2668: }
2669: if ($displayval ne '') {
2670: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2671: '<i>'.$displayname.'</i>',$displayval)).'</li>';
2672: }
2673: }
1.3 raeburn 2674: } else {
2675: next if (!exists($changes->{$item}{$key}));
2676: my ($displayname,$text);
2677: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2678: my $displayval;
1.114 raeburn 2679: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2680: $displayval = $changes->{$item}{$key};
2681: }
1.3 raeburn 2682: if ($item eq 'feedback') {
2683: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2684: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2685: $displayname = &mt('Custom text for '.$text.' questions');
2686: } else {
2687: $displayname = &mt('Recipients of '.$text.' questions');
2688: }
2689: } elsif ($item eq 'discussion') {
2690: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2691: $displayname = &mt("$text (role-based)");
2692: if ($displayval ne '') {
2693: my @roles = split(',',$displayval);
2694: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2695: $displayval = join(', ',@roles);
2696: }
2697: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2698: $displayname = &mt("$text (specific user(s))");
2699: } else {
2700: if ($key eq 'allow_discussion_post_editing') {
2701: if ($displayval ne '') {
2702: my @roles = split(',',$displayval);
2703: my @longroles;
2704: foreach my $role (@roles) {
2705: my ($trole,$sec) = split(':',$role);
2706: my $rolename =
2707: &Apache::lonnet::plaintext($trole);
2708: if ($sec ne '') {
2709: $rolename .= ':'.$sec;
2710: }
2711: push(@longroles,$rolename);
2712: }
2713: $displayval = join(', ',@longroles);
2714: }
1.50 raeburn 2715: } elsif ($key eq 'discussion_post_fonts') {
2716: my ($classorder,$classtitles)=&discussion_vote_classes();
2717: my ($styleorder,$styleitems)=&discussion_vote_styles();
2718: my $count = 1;
2719: my $total = scalar(keys(%{$changes->{$item}}));
2720: foreach my $class (@{$classorder}) {
2721: $count ++;
2722: next unless ($changes->{$item}{$key.'_'.$class});
2723: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2724: my $showval = '';
2725: for (my $i=0; $i<@{$styleorder}; $i++) {
2726: if ($vals[$i] ne '') {
2727: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2728: }
2729: }
2730: if ($vals[3] ne '') {
2731: $showval .= $vals[3];
2732: }
2733: if ($showval ne '') {
2734: $displayval .= $classtitles->{$class}.':{ '.
2735: $showval.'}';
2736: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2737: } else {
2738: $displayval .= $classtitles->{$class}.': '.&mt('None');
2739: push(@delkeys,$key.'_'.$class);
2740: }
2741: unless ($count == $total) {
2742: $displayval .= (' 'x2);
2743: }
2744: }
1.3 raeburn 2745: }
2746: $displayname = &mt($text);
2747: }
2748: } elsif ($item eq 'spreadsheet') {
2749: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2750: my $sheettype = $1;
2751: if ($sheettype eq 'studentcalc') {
2752: &Apache::lonnet::expirespread('','','studentcalc');
2753: } else {
2754: &Apache::lonnet::expirespread('','','assesscalc');
2755: &Apache::lonnet::expirespread('','','studentcalc');
2756: }
2757: }
2758: $displayname = &mt($text);
1.87 raeburn 2759: } elsif ($item eq 'lti') {
2760: if ($key eq 'lti.lcmenu') {
2761: if ($changes->{$item}{$key} eq 'none') {
2762: $displayval = &mt('None of the configurable menu items displayed');
2763: } else {
2764: my %ltititles = <imenu_titles();
2765: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2766: }
2767: } else {
2768: if ($changes->{$item}{$key} eq '1') {
2769: $displayval = &mt('Yes');
2770: } elsif ($changes->{$item}{$key} eq '') {
2771: $displayval = &mt('No');
2772: }
2773: }
2774: $displayname = &mt($text);
1.91 raeburn 2775: } elsif ($item eq 'menuitems') {
2776: unless ($changes->{$item}{$key} eq '') {
2777: if ($key eq 'menudefault') {
2778: $displayname = &mt('Default collection of menu items');
2779: $displayval = &mt('Collection: [_1]',
2780: $changes->{$item}{$key});
2781: } elsif ($key eq 'menucollections') {
2782: $displayval = &menucollections_display($changes->{$item}{$key});
2783: }
2784: }
1.3 raeburn 2785: } else {
2786: $displayname = &mt($text);
2787: }
2788: if (defined($yesno{$key})) {
1.14 raeburn 2789: $displayval = &mt('No');
1.3 raeburn 2790: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2791: $displayval = &mt('Yes');
1.3 raeburn 2792: }
2793: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2794: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2795: } elsif ($key eq 'categories') {
2796: $displayval = $env{'form.categories_display'};
1.95 raeburn 2797: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2798: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2799: if ($changes->{$item}{$key} eq '1') {
2800: $displayval = &mt('Yes');
2801: } elsif ($changes->{$item}{$key} eq '0') {
2802: $displayval = &mt('No');
2803: }
1.114 raeburn 2804: } elsif ($key eq 'extresource') {
2805: if ($changes->{$item}{$key} eq 'iframe') {
2806: $displayval = &mt('In iframe');
2807: } else {
2808: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2809: if ($selected eq 'tab') {
2810: if ($reuse) {
2811: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2812: "'<b>","</b>'",'<br />');
2813: } else {
2814: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2815: "'<b>","</b>'",'<br />');
2816: }
2817: } elsif ($selected eq 'window') {
2818: if ($reuse) {
2819: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2820: "'<b>","</b>'",'<br />');
2821: } else {
2822: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2823: "'<b>","</b>'",'<br />');
2824: }
2825: if (($width ne '') || ($height ne '')) {
2826: if ($width ne '') {
2827: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2828: }
2829: if ($height ne '') {
2830: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2831: }
2832: }
2833: }
2834: }
1.14 raeburn 2835: }
1.25 raeburn 2836: if ($key eq 'co-owners') {
2837: if (ref($changes->{$item}{$key}) eq 'HASH') {
2838: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2839: foreach my $type ('co-owners','pendingco-owners') {
2840: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2841: if ($type eq 'pendingco-owners') {
2842: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2843: $displayname = &mt('Invited as co-owners, pending acceptance');
2844: }
2845: }
2846: if ($changes->{$item}{$key}{$type} eq '') {
2847: push(@delkeys,'internal.'.$type);
2848: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2849: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2850: '<i>'.$displayname.'</i>')).'</li>';
2851: }
2852: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2853: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2854: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2855: '<i>'.$displayname.'</i>',
2856: "'<b>$displayval</b>'")).'</li>';
2857: }
2858: }
2859: }
2860: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2861: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2862: $displayval = &mt('on');
1.90 raeburn 2863: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2864: $displayval = '';
2865: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2866: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2867: $displayval = &mt('off');
2868: }
2869: if ($displayval) {
2870: $displayname = &mt('Your co-ownership status');
2871: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2872: '<i>'.$displayname.'</i>',
2873: "'<b>$displayval</b>'")).'</li>';
2874: }
2875: }
2876: }
2877: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2878: push(@delkeys,$key);
1.87 raeburn 2879: if ($item eq 'lti') {
2880: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2881: if (($key eq 'lti.lcmenu') &&
2882: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2883: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2884: } else {
2885: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2886: '<i>'.$displayname.'</i>',
2887: "'<b>$displayval</b>'")).'</li>';
2888: }
2889: } elsif (!exists($changes->{$item}{'lti.override'})) {
2890: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2891: }
1.91 raeburn 2892: } elsif ($item eq 'menuitems') {
2893: if ($key eq 'menudefault') {
2894: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2895: } elsif ($key eq 'menucollections') {
2896: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2897: }
1.87 raeburn 2898: } else {
2899: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2900: '<i>'.$displayname.'</i>')).'</li>';
2901: }
1.91 raeburn 2902: } elsif ($key eq 'menucollections') {
2903: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2904: $displayval.'</li>';
1.3 raeburn 2905: } else {
1.114 raeburn 2906: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2907: $displayval = "'<b>$displayval</b>'";
2908: }
1.22 wenzelju 2909: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2910: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2911: if ($key eq 'url') {
2912: my $bkuptime=time;
2913: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2914: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2915: }
2916: $output .= '</li>';
2917: }
1.25 raeburn 2918: if ($key eq 'co-owners') {
2919: if (ref($changes->{$item}{$key}) eq 'HASH') {
2920: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2921: foreach my $type ('co-owners','pendingco-owners') {
2922: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2923: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2924: }
2925: }
2926: }
2927: } else {
1.50 raeburn 2928: unless ($key eq 'discussion_post_fonts') {
2929: $storehash{$key} = $changes->{$item}{$key};
2930: }
1.25 raeburn 2931: }
1.3 raeburn 2932: }
1.23 raeburn 2933: if ($key eq 'cloners') {
2934: # Get existing cloners
2935: my %clonenames =
2936: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2937: if ($clonenames{'cloners'} =~ /,/) {
2938: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2939: } else {
2940: $oldcloner[0] = $clonenames{'cloners'};
2941: }
2942: }
1.3 raeburn 2943: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2944: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2945: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2946: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2947: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2948: push(@need_env_update,$key);
2949: }
2950: }
2951: }
2952: }
2953: $output .= '</ul>';
2954: } else {
1.9 raeburn 2955: if ($crstype eq 'Community') {
1.46 raeburn 2956: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2957: } else {
1.46 raeburn 2958: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2959: }
1.3 raeburn 2960: }
2961: }
2962: }
2963: }
1.93 raeburn 2964: if ($skipstore) {
2965: return $output;
2966: }
1.3 raeburn 2967: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2968: if (ref($changes) eq 'HASH') {
2969: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2970: if (exists($changes->{'courseinfo'}{'cloners'})) {
2971: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2972: \@oldcloner);
2973: }
2974: }
2975: }
1.3 raeburn 2976: if (@delkeys) {
2977: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2978: $output .= '<br /><span class="LC_error">';
2979: if ($crstype eq 'Community') {
2980: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2981: } else {
2982: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2983: }
2984: $output .= '</span>';
1.14 raeburn 2985: } else {
2986: foreach my $key (@delkeys) {
2987: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
2988: }
1.3 raeburn 2989: }
2990: }
2991: if (@need_env_update) {
2992: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2993: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
2994: }
2995: &Apache::lonnet::coursedescription($env{'request.course.id'},
2996: {'freshen_cache' => 1});
2997: } else {
1.9 raeburn 2998: $output = '<span class="LC_error">';
2999: if ($crstype eq 'Community') {
3000: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
3001: } else {
3002: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
3003: }
3004: $output .= '</span>';
1.3 raeburn 3005: }
3006: return $output;
3007: }
3008:
1.102 raeburn 3009: sub store_linkprot {
3010: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 3011: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 3012: if ($context eq 'domain') {
3013: $ltiauth = 1;
1.103 raeburn 3014: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 3015: } else {
1.103 raeburn 3016: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 3017: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
3018: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
3019: } else {
3020: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
3021: $ltiauth = $domdefs{'crsltiauth'};
3022: }
3023: }
3024: if (ref($changes) eq 'HASH') {
3025: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3026: if (ref($changes->{$id}) eq 'HASH') {
3027: if (exists($changes->{$id}->{'key'})) {
3028: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
3029: delete($changes->{$id}->{'key'});
3030: }
3031: if (exists($changes->{$id}->{'secret'})) {
3032: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
3033: delete($changes->{$id}->{'secret'});
3034: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3035: if (exists($oldlinkprot->{$id}{'usable'})) {
3036: $changes->{$id}->{'usable'} = 1;
3037: }
1.109 raeburn 3038: if (exists($oldlinkprot->{$id}{'cipher'})) {
3039: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
3040: }
1.102 raeburn 3041: }
3042: }
3043: }
3044: }
3045: my @ids=&Apache::lonnet::current_machine_ids();
3046: if (keys(%ltienc) > 0) {
3047: if ($context eq 'domain') {
3048: foreach my $id (keys(%ltienc)) {
3049: if (exists($ltienc{$id}{'secret'})) {
3050: $changes->{$id}->{'usable'} = 1;
3051: }
3052: }
3053: } else {
1.103 raeburn 3054: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 3055: my $allowed;
3056: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3057: if ($allowed) {
3058: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
3059: foreach my $id (keys(%ltienc)) {
3060: if (exists($ltienc{$id}{'secret'})) {
3061: $changes->{$id}->{'usable'} = 1;
3062: }
3063: }
3064: } else {
3065: $lti_save_error = 1;
3066: }
3067: }
3068: }
3069: }
3070: }
3071: unless ($lti_save_error) {
3072: if ($context eq 'course') {
3073: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3074: my $hashid=$cdom.'_'.$cnum;
3075: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 3076: unless (($home eq 'no_host') || ($home eq '')) {
3077: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 3078: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3079: }
3080: }
3081: } else {
3082: $lti_save_error = 1;
3083: }
3084: }
3085: unless ($lti_save_error) {
3086: foreach my $id (sort { $a <=> $b } %{$changes}) {
3087: if (ref($changes->{$id}) eq 'HASH') {
3088: my %values = %{$changes->{$id}};
3089: my %desc = &linkprot_names();
3090: my $display;
1.112 raeburn 3091: foreach my $title ('name','lifetime','version','key','secret','returnurl') {
1.102 raeburn 3092: if (($title eq 'key') || ($title eq 'secret')) {
3093: if (ref($ltienc{$id}) eq 'HASH') {
3094: if (exists($ltienc{$id}{$title})) {
3095: if ($title eq 'secret') {
3096: my $length = length($ltienc{$id}{$title});
1.103 raeburn 3097: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 3098: } else {
3099: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3100: }
3101: }
3102: }
3103: } elsif ($title eq 'version') {
3104: if ($values{$title} eq 'LTI-1p0') {
3105: $display .= $desc{$title}.': 1.1, ';
3106: }
1.112 raeburn 3107: } elsif ($title eq 'returnurl') {
3108: if ($values{$title}) {
3109: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
3110: }
1.102 raeburn 3111: } else {
3112: $display .= $desc{$title}.': '.$values{$title}.', ';
3113: }
3114: }
3115: if ($ltiauth) {
3116: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3117: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3118: $display .= &mt('Source of username: Email address [_1]',
3119: '(lis_person_contact_email_primary)').', ';
3120: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3121: $display .= &mt('Source of username: User ID [_1]',
3122: '(lis_person_sourcedid)').', ';
3123: } else {
3124: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3125: }
3126: if ($values{'notstudent'} eq 'auth') {
3127: $display .= &mt('Display LON-CAPA login page if no match').', ';
3128: } elsif ($values{'notstudent'} eq 'reject') {
3129: $display .= &mt('Discontinue launch if no match').', ';
3130: }
3131: }
3132: }
3133: $display =~ s/, $//;
3134: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3135: "'$display'")).'</li>';
3136: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3137: my $oldname = $oldlinkprot->{$id}{'name'};
3138: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3139: }
3140: }
3141: } else {
3142: $lti_save_error = 1;
3143: }
3144: }
3145: unless ($lti_save_error) {
3146: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3147: unless (ref($changes->{$id}) eq 'HASH') {
3148: push(@deletions,$id);
3149: }
3150: }
3151: if (@deletions) {
3152: if ($context eq 'course') {
3153: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3154: }
3155: }
3156: }
3157: if ($lti_save_error) {
3158: $output .= '<li>'.
3159: '<span class="LC_error">'.
3160: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3161: '</span>'.
3162: '</li>';
3163: }
3164: return $output;
3165: }
3166:
1.118 raeburn 3167: sub store_ltitools {
3168: my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3169: my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3170: my %lt = <itools_names();
3171: my @courseroles = ('cc','in','ta','ep','st');
3172: my @allfields = ('fullname','firstname','lastname','email','user','roles');
3173: if ($context eq 'domain') {
3174: $home = &Apache::lonnet::domain($cdom,'primary');
3175: } else {
3176: $home = &Apache::lonnet::homeserver($cnum,$cdom);
3177: }
3178: if (ref($changes) eq 'HASH') {
3179: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3180: if (ref($changes->{$id}) eq 'HASH') {
3181: if (exists($changes->{$id}->{'key'})) {
3182: $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3183: delete($changes->{$id}->{'key'});
3184: }
3185: if (exists($changes->{$id}->{'secret'})) {
3186: $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3187: delete($changes->{$id}->{'secret'});
3188: } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3189: if (exists($oldltitools->{$id}{'usable'})) {
3190: $changes->{$id}->{'usable'} = 1;
3191: }
3192: if (exists($oldltitools->{$id}{'cipher'})) {
3193: $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3194: }
3195: }
3196: }
3197: }
3198: }
3199: my @ids=&Apache::lonnet::current_machine_ids();
3200: if (keys(%toolsenc) > 0) {
3201: unless (($home eq 'no_host') || ($home eq '')) {
3202: my $allowed;
3203: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3204: if ($allowed) {
3205: if (($context eq 'domain') ||
3206: (($context eq 'course') &&
3207: (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3208: foreach my $id (keys(%toolsenc)) {
3209: if (exists($toolsenc{$id}{'secret'})) {
3210: $changes->{$id}->{'usable'} = 1;
3211: }
3212: }
3213: } else {
3214: $ltitools_save_error = 1;
3215: }
3216: }
3217: }
3218: }
3219: unless ($ltitools_save_error) {
3220: if ($context eq 'course') {
3221: if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3222: my $hashid=$cdom.'_'.$cnum;
3223: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3224: unless (($home eq 'no_host') || ($home eq '')) {
3225: if (grep(/^\Q$home\E$/,@ids)) {
1.120 raeburn 3226: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
1.118 raeburn 3227: }
3228: }
3229: } else {
3230: $ltitools_save_error = 1;
3231: }
3232: }
3233: unless ($ltitools_save_error) {
3234: my %bynum;
3235: foreach my $itemid (sort(keys(%{$changes}))) {
3236: my $position = $changes->{$itemid}{'order'};
3237: $bynum{$position} = $itemid;
3238: }
3239: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3240: my $itemid = $bynum{$pos};
3241: if (ref($changes->{$itemid}) ne 'HASH') {
3242: $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3243: } else {
3244: $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3245: if ($changes->{$itemid}{'image'}) {
3246: $output .= ' '.
3247: '<img src="'.$changes->{$itemid}{'image'}.'"'.
3248: ' alt="'.&mt('Tool Provider icon').'" />';
3249: }
3250: $output .= '</li><ul>';
3251: my $position = $pos + 1;
3252: $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3253: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3254: if ($changes->{$itemid}{$item} ne '') {
3255: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3256: }
3257: }
3258: if (ref($toolsenc{$itemid}) eq 'HASH') {
3259: foreach my $item ('key','secret') {
3260: if (exists($toolsenc{$itemid}{$item})) {
3261: if ($item eq 'secret') {
3262: $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3263: } else {
3264: $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3265: }
3266: }
3267: }
3268: }
3269: $output .= '<li>'.&mt('Configurable in course:');
3270: my @possconfig = ('label','title','target','linktext','explanation','append');
3271: my $numconfig = 0;
3272: if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3273: foreach my $item (@possconfig) {
3274: if ($changes->{$itemid}{'crsconf'}{$item}) {
3275: $numconfig ++;
3276: $output .= ' "'.$lt{'crs'.$item}.'"';
3277: }
3278: }
3279: }
3280: if (!$numconfig) {
3281: $output .= ' '.&mt('None');
3282: }
3283: $output .= '</li>';
3284: foreach my $item ('passback','roster') {
3285: $output .= '<li>'.$lt{$item}.' ';
3286: if ($changes->{$itemid}{$item}) {
3287: $output .= &mt('Yes');
3288: if ($changes->{$itemid}{$item.'valid'}) {
3289: if ($item eq 'passback') {
3290: $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3291: $changes->{$itemid}{$item.'valid'});
3292: } else {
3293: $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3294: $changes->{$itemid}{$item.'valid'});
3295: }
3296: }
3297: } else {
3298: $output .= &mt('No');
3299: }
3300: $output .= '</li>';
3301: }
3302: if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3303: my $displaylist;
3304: if ($changes->{$itemid}{'display'}{'target'}) {
3305: $displaylist = &mt('Display target').': '.
3306: $changes->{$itemid}{'display'}{'target'}.',';
3307: }
3308: foreach my $size ('width','height') {
3309: if ($changes->{$itemid}{'display'}{$size}) {
3310: $displaylist .= (' 'x2).$lt{$size}.': '.
3311: $changes->{$itemid}{'display'}{$size}.',';
3312: }
3313: }
3314: if ($displaylist) {
3315: $displaylist =~ s/,$//;
3316: $output .= '<li>'.$displaylist.'</li>';
3317: }
3318: foreach my $item ('linktext','explanation') {
3319: if ($changes->{$itemid}{'display'}{$item}) {
3320: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3321: }
3322: }
3323: }
3324: if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3325: my $fieldlist;
3326: foreach my $field (@allfields) {
3327: if ($changes->{$itemid}{'fields'}{$field}) {
3328: $fieldlist .= (' 'x2).$lt{$field}.',';
3329: }
3330: }
3331: if ($fieldlist) {
3332: $fieldlist =~ s/,$//;
3333: if ($changes->{$itemid}{'fields'}{'user'}) {
3334: if ($changes->{$itemid}{'incdom'}) {
3335: $fieldlist .= ' ('.&mt('username:domain').')';
3336: } else {
3337: $fieldlist .= ' ('.&mt('username').')';
3338: }
3339: }
3340: $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3341: }
3342: }
3343: if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3344: my $rolemaps;
3345: foreach my $role (@courseroles) {
3346: if ($changes->{$itemid}{'roles'}{$role}) {
3347: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3348: $changes->{$itemid}{'roles'}{$role}.',';
3349: }
3350: }
3351: if ($rolemaps) {
3352: $rolemaps =~ s/,$//;
3353: $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3354: }
3355: }
3356: if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3357: my $customlist;
3358: if (keys(%{$changes->{$itemid}{'custom'}})) {
3359: foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3360: $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3361: }
3362: }
3363: if ($customlist) {
3364: $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3365: }
3366: }
3367: $output .= '</ul></li>';
3368: }
3369: }
3370: }
3371: }
3372: return $output;
3373: }
3374:
1.3 raeburn 3375: sub update_env {
3376: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3377: my $count = 0;
3378: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3379: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3380: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3381: foreach my $key (@{$need_env_update}) {
3382: if ($key eq 'description' && defined($storehash->{$key})) {
3383: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3384: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3385: $count ++;
3386: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3387: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3388: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3389: $count ++;
1.25 raeburn 3390: } elsif ($key eq 'co-owners') {
3391: if ($storehash->{'internal.co-owners'} ne '') {
3392: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3393: }
3394: if ($storehash->{'internal.pendingco-owners'} ne '') {
3395: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3396: }
3397: my @coowners = split(',',$storehash->{'internal.'.$key});
3398: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3399: $count ++;
1.87 raeburn 3400: } elsif ($key =~ /^lti\./) {
3401: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 3402: }
3403: }
3404: if ($count) {
3405: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3406: }
3407: }
3408: }
3409: return;
3410: }
3411:
3412: sub display_disallowed {
1.9 raeburn 3413: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3414: my $output;
3415: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3416: if (keys(%{$disallowed})) {
3417: if ($item eq 'cloners') {
3418: my @fails;
3419: my %lt = &Apache::lonlocal::texthash (
3420: format => 'Invalid format',
3421: domain => 'Domain does not exist',
3422: newuser => 'LON-CAPA user(s) do(es) not exist.',
3423: );
3424: foreach my $error ('format','domain','newuser') {
3425: if (defined($disallowed->{$error})) {
3426: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3427: $lt{$error};
3428: if ($error eq 'newuser') {
1.9 raeburn 3429: $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 3430: }
3431: push(@fails,$msg);
3432: }
3433: }
3434: if (@fails) {
3435: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3436: '</span>'.join('; ',@fails).'.<br />';
3437: }
3438: } elsif ($item eq 'rolenames') {
3439: my %lt = &Apache::lonlocal::texthash (
3440: replacements => 'Name already used to replace a different standard role name',
3441: regulars => 'Name already used as a standard role name',
3442: customrole => 'Name already used as the name of a custom role',
3443: );
3444: my @fails;
3445: foreach my $error ('replacements','regulars','customrole') {
3446: if (ref($disallowed->{$error}) eq 'ARRAY') {
3447: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3448: '</b>, '.&mt('reason').' - '.$lt{'error'});
3449: }
3450: }
3451: if (@fails) {
3452: $output .= '<span class="LC_warning">'.
3453: &mt('Unable to include amongst replacements for role names: ').
3454: '</span>'.join('; ',@fails).'.<br />';
3455: }
3456:
3457: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3458: $output .= '<span class="LC_warning">';
3459: if ($item eq 'feedback') {
1.9 raeburn 3460: if ($crstype eq 'Community') {
3461: $output .= &mt('Unable to include as a recipient of community feedback for:');
3462: } else {
3463: $output .= &mt('Unable to include as a recipient of course feedback for:');
3464: }
1.3 raeburn 3465: } elsif ($item eq 'discussion') {
3466: $output .= &mt('Unable to include in user-based access control for:');
3467: } elsif ($item eq 'localization') {
1.9 raeburn 3468: if ($crstype eq 'Community') {
3469: $output .= &mt('Unable to include in community localization:');
3470: } else {
3471: $output .= &mt('Unable to include in course localization:');
3472: }
1.3 raeburn 3473: }
3474: $output .= '</span><ul>';
3475: foreach my $key (sort(keys(%{$disallowed}))) {
3476: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3477: $output .= '<li><i>'.$itemtext.'</i> - ';
3478: if ($item eq 'localization') {
3479: $output .= &mt('reason - unsupported language: [_1]',
3480: '<b>'.$disallowed->{$key}.'</b>');
3481: } else {
3482: $output .= &mt('reason - invalid user: [_1]',
3483: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3484: }
3485: }
3486: $output .= '</ul><br />';
3487: }
3488: }
1.1 raeburn 3489: }
1.3 raeburn 3490: return $output;
1.1 raeburn 3491: }
3492:
3493: sub get_course {
3494: my ($courseid) = @_;
3495: if (!defined($courseid)) {
3496: $courseid = $env{'request.course.id'};
3497: }
3498: my $cdom=$env{'course.'.$courseid.'.domain'};
3499: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 3500: my $chome=$env{'course.'.$courseid.'.home'};
3501: return ($cnum,$cdom,$chome);
1.1 raeburn 3502: }
3503:
3504: sub get_jscript {
1.91 raeburn 3505: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3506: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 raeburn 3507: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3508: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3509: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3510: my $cloners_js = &cloners_javascript($phase);
1.118 raeburn 3511: my $currltitools;
3512: if (ref($settings) eq 'HASH') {
3513: $currltitools = $settings->{'ltitools'};
3514: }
3515: my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.71 raeburn 3516: my @code_order;
3517: if ($crstype ne 'Community') {
3518: if (ref($settings) eq 'HASH') {
3519: my %codedefaults;
3520: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3521: \@code_order);
3522: if (@code_order > 0) {
3523: if ($phase eq 'display') {
3524: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3525: if (grep(/^courseinfo$/,@actions)) {
3526: if ($settings->{'cloners'} ne '') {
3527: unless ($settings->{'cloners'} eq '*') {
3528: my @cloners = split(/,/,$settings->{'cloners'});
3529: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3530: my %local_to_standard;
3531: for (my $i=0; $i<@code_order; $i++) {
3532: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3533: }
3534: foreach my $cloner (@cloners) {
3535: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
3536: ($cloner !~ /^$match_username\:$match_domain$/)) {
3537: foreach my $item (split(/\&/,$cloner)) {
3538: my ($key,$val) = split(/\=/,$item);
3539: $val = &unescape($val);
3540: foreach my $code (@code_order) {
3541: if ($key eq $local_to_standard{$code}) {
3542: $env{'form.'.$key} = $val;
3543: }
3544: }
3545: }
3546: }
3547: }
3548: }
3549: }
3550: }
3551: }
3552: my @codetitles;
3553: (undef,$instcode_js) =
3554: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3555: \@codetitles);
3556: $instcode_js .= <<ENDSCRIPT;
3557: function toggleCloners(callerradio) {
3558: if (document.getElementById('LC_cloners_instcode')) {
3559: if (callerradio.value == 1) {
3560: document.getElementById('LC_cloners_instcode').style.display = "block";
3561: } else {
3562: uncheckOfficialLists();
3563: document.getElementById('LC_cloners_instcode').style.display = "none";
3564: }
3565: }
3566: }
3567:
3568: if (!document.getElementsByClassName) {
3569: function getElementsByClassName(node, classname) {
3570: var a = [];
3571: var re = new RegExp('(^| )'+classname+'( |$)');
3572: var els = node.getElementsByTagName("*");
3573: for(var i=0,j=els.length; i<j; i++)
3574: if(re.test(els[i].className))a.push(els[i]);
3575: return a;
3576: }
3577: }
3578:
3579: function uncheckOfficialLists() {
3580: var codepicks;
3581: if (document.getElementsByClassName) {
3582: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3583: } else {
3584: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3585: }
3586: if (codepicks.length) {
3587: for (var i=0; i<codepicks.length; i++) {
3588: codepicks[i].selectedIndex = 0;
3589: }
3590: }
3591: }
3592:
3593: ENDSCRIPT
3594: }
3595: }
3596: }
1.1 raeburn 3597: if ($can_categorize) {
3598: $categorize_js = <<ENDSCRIPT;
3599: function catsbrowser() {
3600: var catswin = null;
3601: var url = '/adm/courseprefs?phase=categorizecourse';
3602: if (!catswin || catswin.closed) {
3603: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3604: } else {
3605: catswin.focus();
3606: }
3607: }
3608: ENDSCRIPT
3609: }
1.36 raeburn 3610: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3611: if ($loncaparev) {
3612: $loncaparev_js = <<ENDSCRIPT;
3613: function loncaparevinfo() {
3614: var lcrevwin = null;
3615: var url = '/adm/courseprefs?phase=releaseinfo';
3616: if (!lcrevwin || lcrevwin.closed) {
3617: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3618: } else {
3619: lcrevwin.focus();
3620: }
3621: }
3622: ENDSCRIPT
3623: }
1.60 raeburn 3624: my $cnum = $env{'course.'.$cid.'.num'};
3625: my $syllabus_js = <<ENDSCRIPT;
3626: function syllabusinfo() {
3627: var syllwin = null;
3628: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3629: if (!syllwin || syllwin.closed) {
3630: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3631: } else {
3632: syllwin.focus();
3633: }
3634: }
3635: ENDSCRIPT
1.91 raeburn 3636: my $menuitems_js;
3637: unless ($noedit) {
3638: my $collections;
3639: my $next = 1;
3640: if (ref($settings) eq 'HASH') {
3641: if ($settings->{'menucollections'} ne '') {
3642: my @current;
3643: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3644: my ($num) = split(/\%/,$item);
3645: if ($num =~ /^\d+$/) {
3646: push(@current,$num);
3647: }
3648: }
3649: $collections = join("','",sort { $a <=> $b } @current);
3650: if ($collections) {
3651: $collections = "'$collections'";
3652: }
3653: $next += $current[-1];
3654: }
3655: }
3656: my $deftext = &mt('Standard (all menus shown)');
3657: $menuitems_js = <<ENDSCRIPT;
3658: function toggleAddmenucoll() {
3659: if (document.getElementById('menucollections_add')) {
3660: var state = 'none';
3661: var add = document.getElementById('menucollections_add').checked;
3662: if (add) {
3663: state = 'inline-block';
3664: }
3665: var fieldsets = new Array('shown','text','links','list','inline');
3666: for (var i=0; i<fieldsets.length; i++) {
3667: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3668: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3669: }
3670: }
3671: var box = document.getElementsByClassName('LC_menucoll_add');
3672: if (box.length) {
3673: for (var i=0; i<box.length; i++) {
3674: if (add) {
3675: box[i].checked = true;
3676: } else {
3677: box[i].checked = false;
3678: }
3679: }
3680: }
3681: if (document.getElementById('menudefault')) {
3682: var menudef = document.getElementById('menudefault');
3683: var currsel = menudef.selectedIndex;
3684: var colls = new Array($collections);
3685: menudef.options.length = 0;
3686: if (!add) {
3687: if (currsel == 1 + colls.length) {
3688: currsel = 0;
3689: }
3690: }
3691: if (currsel == 0) {
3692: menudef.options[0] = new Option('$deftext','',true,true);
3693: } else {
3694: menudef.options[0] = new Option('$deftext','',false,false);
3695: }
3696: if (colls.length) {
3697: for (var i=0; i<colls.length; i++) {
3698: var idx = i+1;
3699: if (currsel == colls[i]) {
3700: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3701: } else {
3702: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3703: }
3704: }
3705: }
3706: if (add) {
3707: var addidx = 1 + colls.length;
3708: if (currsel == addidx) {
3709: menudef.options[addidx] = new Option('$next','$next',true,true);
3710: } else {
3711: menudef.options[addidx] = new Option('$next','$next',false,false);
3712: }
3713: }
3714: }
3715: }
3716: }
3717: ENDSCRIPT
3718: }
1.114 raeburn 3719: $extresource_js = <<"ENDSCRIPT";
3720: function toggleExtRes() {
3721: if (document.getElementById('LC_extresource')) {
3722: var extressel = document.getElementById('LC_extresource').value;
3723: if (document.getElementById('LC_extresreusediv')) {
3724: var extresreuse = document.getElementById('LC_extresreusediv');
3725: if (document.getElementById('LC_extressize')) {
3726: var extressize = document.getElementById('LC_extressize');
3727: var setvis;
3728: if ((extressel == 'tab') || (extressel == 'window')) {
3729: extresreuse.style.display = 'inline-block';
3730: setvis = 1;
3731: if (extressel == 'window') {
3732: extressize.style.display = 'inline-block';
3733: } else {
3734: extressize.style.display = 'none';
3735: }
3736: }
3737: if (!setvis) {
3738: extresreuse.style.display = 'none';
3739: extressize.style.display = 'none';
3740: }
3741: }
3742: }
3743: }
3744: }
3745: ENDSCRIPT
1.115 raeburn 3746: $localization_js = <<"ENDSCRIPT";
3747: function toggleTimeZone() {
3748: if (document.getElementById('LC_set_timezone')) {
3749: var timezonesel = document.getElementById('LC_set_timezone').value;
3750: if (document.getElementById('LC_tzoverdiv')) {
3751: var tzoverdiv = document.getElementById('LC_tzoverdiv');
3752: if (timezonesel == '') {
3753: tzoverdiv.style.display = 'none';
3754: } else {
3755: tzoverdiv.style.display = 'block';
3756: }
3757: }
3758: }
3759: }
3760: ENDSCRIPT
1.1 raeburn 3761: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.56 raeburn 3762: '// <![CDATA['."\n".
1.36 raeburn 3763: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 raeburn 3764: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 3765: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.102 raeburn 3766: &linkprot_javascript()."\n".'//]]>'."\n".
1.118 raeburn 3767: '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3768: return $jscript;
3769: }
3770:
1.3 raeburn 3771: sub cloners_javascript {
3772: my ($formname) = @_;
3773: return <<"ENDSCRIPT";
3774:
3775: function update_cloners(caller,num) {
3776: var delidx = getIndexByName('cloners_delete');
3777: var actidx = getIndexByName('cloners_activate');
3778: if (caller == 'cloners_all') {
3779: var selall;
3780: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3781: if (document.$formname.cloners_all[i].checked) {
3782: selall = document.$formname.cloners_all[i].value;
3783: }
3784: }
3785: if (selall == 1) {
3786: if (delidx != -1) {
3787: if (document.$formname.cloners_delete.length) {
3788: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3789: document.$formname.cloners_delete[j].checked = true;
3790: }
3791: } else {
3792: document.$formname.elements[delidx].checked = true;
3793: }
3794: }
3795: if (actidx != -1) {
3796: if (document.$formname.cloners_activate.length) {
3797: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3798: if (document.$formname.cloners_activate[i].value == '0') {
3799: document.$formname.cloners_activate[i].checked = false;
3800: }
1.71 raeburn 3801: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3802: document.$formname.cloners_activate[i].checked = true;
3803: }
3804: }
3805: }
3806: }
3807: document.$formname.cloners_newdom.selectedIndex = 0;
3808: }
3809: }
3810: if (caller == 'cloners_activate') {
3811: if (document.$formname.cloners_activate.length) {
3812: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3813: if (document.$formname.cloners_activate[j].value == num) {
3814: if (document.$formname.cloners_activate[j].checked) {
3815: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3816: if (document.$formname.cloners_all[i].value == '1') {
3817: document.$formname.cloners_all[i].checked = false;
3818: }
3819: if (document.$formname.cloners_all[i].value == '0') {
3820: document.$formname.cloners_all[i].checked = true;
3821: }
3822: }
3823: }
3824: }
3825: }
3826: } else {
3827: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3828: if (document.$formname.cloners_all[i].value == '1') {
3829: document.$formname.cloners_all[i].checked = false;
3830: }
3831: if (document.$formname.cloners_all[i].value == '0') {
3832: document.$formname.cloners_all[i].checked = true;
3833: }
3834: }
3835: }
3836: }
3837: return;
3838: }
3839:
3840: function getIndexByName(item) {
3841: for (var i=0;i<document.$formname.elements.length;i++) {
3842: if (document.$formname.elements[i].name == item) {
3843: return i;
3844: }
3845: }
3846: return -1;
3847: }
3848:
3849: ENDSCRIPT
3850: }
3851:
1.102 raeburn 3852: sub linkprot_javascript {
3853: return <<"ENDSCRIPT";
1.112 raeburn 3854: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 3855: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3856: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3857: var itemname = form.elements['linkprot_'+item+'_'+num];
3858: if (itemname) {
3859: if (itemname.length > 0) {
3860: var setvis;
3861: for (var i=0; i<itemname.length; i++) {
3862: if (itemname[i].checked == true) {
3863: if (itemname[i].value == valon) {
3864: extraid.style.display = styleon;
3865: setvis = 1;
3866: }
3867: break;
3868: }
3869: }
3870: if (!setvis) {
3871: extraid.style.display = 'none';
3872: }
3873: }
3874: }
3875: }
3876: return;
3877: }
1.106 raeburn 3878:
1.102 raeburn 3879: ENDSCRIPT
3880:
3881: }
3882:
1.1 raeburn 3883: sub print_courseinfo {
1.80 raeburn 3884: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3885: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3886: return;
3887: }
1.83 raeburn 3888: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3889: if ($noedit) {
3890: $disabled = ' disabled="disabled"';
3891: }
1.1 raeburn 3892: my %domconf =
1.71 raeburn 3893: &Apache::lonnet::get_dom('configuration',
3894: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3895: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3896: $cathash = $domconf{'coursecategories'}{'cats'};
3897: if (ref($cathash) eq 'HASH') {
3898: $categoriesform =
3899: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 3900: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3901: }
3902: }
1.25 raeburn 3903: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3904: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3905: }
1.71 raeburn 3906: my ($currcanclone,@code_order,$cloner_instcode);
3907: my %codedefaults;
3908: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3909: \@code_order);
3910: if ($settings->{'cloners'}) {
3911: unless ($settings->{'cloners'} eq '*') {
3912: my @currclone = split(/,/,$settings->{'cloners'});
3913: foreach my $item (@currclone) {
3914: unless ($item eq '*') {
3915: if (($item !~ /\:/) && ($item =~ /=/)) {
3916: $cloner_instcode = 1;
3917: }
3918: }
3919: }
3920: }
3921: }
3922: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3923: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3924: if (ref($canclone) eq 'HASH') {
3925: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3926: if ($settings->{'internal.coursecode'}) {
3927: my @posscodes;
3928: if (@code_order > 0) {
3929: $currcanclone = 'instcode';
3930: foreach my $item (@{$canclone->{'instcode'}}) {
3931: if (grep(/^\Q$item\E$/,@code_order)) {
3932: push(@posscodes,$item);
3933: }
3934: }
3935: my $codestr = join(' + ',@posscodes);
3936: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3937: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3938: }
3939: }
3940: }
3941: } elsif ($canclone eq 'domain') {
3942: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
3943: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
3944: $currcanclone = 'domain';
3945: }
3946: if ($clonedefaults) {
3947: if ($settings->{'cloners'} ne '') {
3948: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
3949: } else {
3950: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
3951: }
3952: $clonedefaults = '<br /><br />'.$clonedefaults;
3953: }
3954: }
1.1 raeburn 3955: if (!defined($categoriesform)) {
1.15 raeburn 3956: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 3957: }
1.12 raeburn 3958: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 3959: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 3960:
1.9 raeburn 3961: my $replace;
3962: if ($crstype eq 'Community') {
3963: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3964: } else {
3965: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3966: }
1.84 raeburn 3967: my ($editmap,$editsyllabus);
3968: unless ($noedit) {
3969: $editmap = (' 'x2).
3970: '<a href="javascript:openbrowser'.
3971: "('display','url','sequence')\">".
3972: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
3973: &mt('Modification may make assessment data inaccessible!').
3974: '</span>';
3975: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
3976: '</a>');
3977: }
1.1 raeburn 3978: my %items = (
1.3 raeburn 3979: 'url' => {
1.84 raeburn 3980: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 3981: input => 'textbox',
1.55 raeburn 3982: size => '55',
1.19 faziophi 3983: advanced => 1
1.1 raeburn 3984: },
3985: 'description' => {
1.3 raeburn 3986: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 3987: input => 'textbox',
1.55 raeburn 3988: size => '55',
1.1 raeburn 3989: },
1.24 raeburn 3990: 'owner' => {
3991: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
3992: },
1.25 raeburn 3993: 'co-owners' => {
3994: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
3995: },
1.63 raeburn 3996: 'clonedfrom' => {
3997: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
3998: },
1.1 raeburn 3999: 'courseid' => {
1.3 raeburn 4000: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
4001: &mt('internal, optional').')',
1.1 raeburn 4002: input => 'textbox',
4003: size => '25',
4004: },
1.64 raeburn 4005: 'uniquecode' => {
4006: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
4007: },
1.1 raeburn 4008: 'cloners' => {
1.3 raeburn 4009: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 4010: &mt('Owner and Coordinators included automatically').
4011: $clonedefaults,
1.1 raeburn 4012: input => 'textbox',
1.41 www 4013: size => '40'
1.1 raeburn 4014: },
4015: 'rolenames' => {
1.3 raeburn 4016: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 4017: '('.$replace.')',
1.1 raeburn 4018: input => 'textbox',
4019: size => '20',
1.19 faziophi 4020: advanced => 1
1.1 raeburn 4021: },
1.88 raeburn 4022: 'syllabus' => {
4023: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 4024: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 4025: $editsyllabus,
1.1 raeburn 4026: },
4027: 'hidefromcat' => {
1.3 raeburn 4028: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 4029: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
4030: input => 'radio',
4031: },
4032: 'categories' => {
1.3 raeburn 4033: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 4034: &mt('Display Categories').'</a>',
4035: input => 'textbox',
4036: size => '25',
4037: },
1.35 raeburn 4038: 'loncaparev' => {
4039: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
4040: },
1.55 raeburn 4041: 'defaultcredits' => {
4042: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4043: },
1.1 raeburn 4044: );
4045: my $datatable;
4046: my $count = 0;
4047: foreach my $item (@{$ordered}) {
1.56 raeburn 4048: my $colspan;
1.1 raeburn 4049: if ($item eq 'hidefromcat') {
4050: next if (!$can_toggle_cat);
4051: } elsif ($item eq 'categories') {
4052: next if (!$can_categorize);
1.64 raeburn 4053: } elsif ($item eq 'uniquecode') {
4054: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4055: }
1.56 raeburn 4056: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
4057: $colspan = 2;
4058: }
1.1 raeburn 4059: $count ++;
1.19 faziophi 4060: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 4061: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4062: } else {
1.56 raeburn 4063: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4064: }
1.1 raeburn 4065: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 4066: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4067: } elsif ($item eq 'cloners') {
4068: my $includeempty = 1;
4069: my $num = 0;
1.56 raeburn 4070: $datatable .= '</td><td align="right">'.
4071: &Apache::loncommon::start_data_table().
1.1 raeburn 4072: &Apache::loncommon::start_data_table_row().
4073: '<td><span class="LC_nobreak"><label>'.
4074: &mt('Any user in any domain:').
4075: ' <input type="radio" name="cloners_all" value="1" ';
4076: if ($settings->{$item} eq '*') {
4077: $datatable .= ' checked="checked" ';
4078: }
4079: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 4080: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4081: (' 'x2).'<label>'.
4082: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4083: if ($settings->{$item} ne '*') {
4084: $datatable .= ' checked="checked" ';
4085: }
4086: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 4087: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4088: &Apache::loncommon::end_data_table_row().
4089: &Apache::loncommon::end_data_table().
1.56 raeburn 4090: '<table><tr><td align="left"><b>'.&mt('Or').
4091: '</b></td></tr></table>'.
1.1 raeburn 4092: &Apache::loncommon::start_data_table();
4093: my @cloners;
4094: if ($settings->{$item} eq '') {
1.80 raeburn 4095: unless ($noedit) {
4096: my $default;
4097: if ($currcanclone eq 'domain') {
4098: $default = '0';
4099: }
4100: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 4101: }
1.1 raeburn 4102: } elsif ($settings->{$item} ne '*') {
4103: my @entries = split(/,/,$settings->{$item});
4104: if (@entries > 0) {
4105: foreach my $entry (@entries) {
4106: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4107: if ($udom =~ /^$match_domain$/) {
4108: unless (&Apache::lonnet::domain($udom)) {
4109: next;
4110: }
4111: } else {
4112: next;
4113: }
1.1 raeburn 4114: if ($uname eq '*') {
4115: $datatable .=
4116: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4117: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4118: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4119: '</b><input type="hidden" name="cloners_dom_'.$num.
4120: '" value="'.$udom.'" /></span><br />'.
4121: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4122: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4123: &mt('Delete').'</label></span></td>'.
4124: &Apache::loncommon::end_data_table_row();
4125: $num ++;
1.23 raeburn 4126: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4127: unless (grep(/^\Q$entry\E$/,@cloners)) {
4128: push(@cloners,$entry);
4129: }
1.1 raeburn 4130: }
4131: }
4132: }
4133: }
4134: my $add_domtitle = &mt('Any user in additional domain:');
4135: if ($settings->{$item} eq '*') {
4136: $add_domtitle = &mt('Any user in specific domain:');
4137: } elsif ($settings->{$item} eq '') {
4138: $add_domtitle = &mt('Any user in other domain:');
4139: }
4140: my $cloners_str = join(',',@cloners);
4141: $datatable .= &Apache::loncommon::start_data_table_row().
4142: '<td align="left"><span class="LC_nobreak">'.
4143: $add_domtitle.'</span><br />'.
4144: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 4145: $includeempty,undef,undef,
4146: undef,undef,$noedit).
1.1 raeburn 4147: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4148: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4149: &Apache::loncommon::end_data_table().
1.56 raeburn 4150: '<table><tr><td align="left"><b>'.&mt('And').
4151: '</b></td></tr></table>'.
1.1 raeburn 4152: &Apache::loncommon::start_data_table().
4153: &Apache::loncommon::start_data_table_row().
4154: '<td align="left">'.
4155: &mt('Specific users').' (<tt>'.
4156: &mt('user:domain,user:domain').'</tt>)<br />'.
4157: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 4158: $items{$item}{'size'},$disabled).
1.1 raeburn 4159: '</td>'.&Apache::loncommon::end_data_table_row().
4160: &Apache::loncommon::end_data_table();
1.71 raeburn 4161: if (@code_order > 0) {
4162: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4163: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4164: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4165: \%cat_items,\@codetitles,
4166: \%cat_titles,\%cat_order);
4167: my $showncodes = 'off';
4168: my $checkedoff = ' checked="checked"';
4169: my $checkedon = '';
4170: if ($cloner_instcode) {
4171: $checkedon = $checkedoff;
4172: $checkedoff = '';
4173: $showncodes = 'on';
4174: }
4175: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4176: '</b></td></tr></table>'.
4177: &Apache::loncommon::start_data_table().
4178: &Apache::loncommon::start_data_table_row().
4179: '<td align="left"><span class="LC_nobreak">'.
4180: &mt('Cloning by official course(s) based on course category').(' 'x2).
4181: '<label>'.
1.80 raeburn 4182: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4183: (' ').
4184: '<label>'.
1.80 raeburn 4185: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 4186: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4187: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 4188: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 4189: '</td>'.&Apache::loncommon::end_data_table_row().
4190: &Apache::loncommon::end_data_table();
4191: }
1.1 raeburn 4192: } elsif ($item eq 'rolenames') {
1.56 raeburn 4193: $datatable .= '</td><td align="right">'.
4194: &Apache::loncommon::start_data_table();
1.9 raeburn 4195: my @roles;
4196: if ($crstype eq 'Community') {
4197: @roles = ('co');
4198: } else {
4199: @roles = ('cc');
4200: }
4201: push (@roles,('in','ta','ep','ad','st'));
4202: foreach my $role (@roles) {
1.1 raeburn 4203: $datatable .= &Apache::loncommon::start_data_table_row().
4204: '<td align="left"><span class="LC_nobreak">'.
4205: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4206: '</span></td><td align="left">'.
4207: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4208: $settings->{$role.'.plaintext'},
1.80 raeburn 4209: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4210: &Apache::loncommon::end_data_table_row();
4211: }
4212: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4213: } elsif ($item eq 'categories') {
1.80 raeburn 4214: my $launcher;
4215: if ($noedit) {
4216: $launcher = $disabled;
4217: } else {
4218: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4219: }
1.3 raeburn 4220: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4221: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4222: $items{$item}{size},$launcher);
1.24 raeburn 4223: } elsif ($item eq 'owner') {
4224: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4225: if ($owner =~ /:/) {
4226: my ($ownername,$ownerdom) = split(':',$owner);
4227: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4228: } elsif ($owner ne '') {
4229: $owner = &Apache::loncommon::plainname($owner,$cdom);
4230: } else {
4231: $owner = &mt('None specified');
4232: }
4233: $datatable .= $owner;
1.63 raeburn 4234: } elsif ($item eq 'clonedfrom') {
4235: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4236: my $clonedfrom = &mt('None');
4237: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 4238: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 4239: if ($clonesrcinfo{'description'}) {
4240: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
4241: }
4242: }
4243: $datatable .= $clonedfrom;
1.64 raeburn 4244: } elsif ($item eq 'uniquecode') {
4245: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
4246: if ($code) {
4247: $datatable .= $code;
4248: }
1.25 raeburn 4249: } elsif ($item eq 'co-owners') {
4250: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4251: my @currcoown;
4252: if ($coowners) {
4253: @currcoown = split(',',$coowners);
4254: }
4255: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4256: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4257: $datatable .= &show_autocoowners(@currcoown);
4258: } else {
1.80 raeburn 4259: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4260: }
4261: } else {
4262: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4263: $datatable .= &show_autocoowners(@currcoown);
4264: } else {
1.80 raeburn 4265: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4266: }
4267: }
1.88 raeburn 4268: } elsif ($item eq 'syllabus') {
1.60 raeburn 4269: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4270: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4271: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4272: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4273: if ($minimal =~/\w/) {
4274: if ($external =~ m{\Q$minimal\E$}) {
4275: undef($external);
4276: }
4277: } elsif ($uploaded =~/\w/) {
4278: if ($external =~ m{\Q$uploaded\E$}) {
4279: undef($external);
4280: }
4281: }
4282: } elsif ($external!~/\w/) {
4283: undef($external);
4284: }
4285: if ($external) {
4286: $datatable .= &mt('External URL');
4287: } elsif ($minimal) {
4288: $datatable .= &mt('Minimal template');
4289: } elsif ($uploaded) {
4290: $datatable .= &mt('Uploaded file');
4291: } else {
4292: $datatable .= &mt('Standard template');
4293: }
4294: $datatable .= (' ' x 2).
4295: &mt('[_1]View[_2]',
4296: '<a href="javascript:syllabusinfo();">',
4297: '</a>');
1.35 raeburn 4298: } elsif ($item eq 'loncaparev') {
4299: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4300: my $showreqd;
4301: if ($loncaparev) {
1.36 raeburn 4302: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4303: &mt('Details').'</a>';
1.35 raeburn 4304: } else {
4305: $showreqd = &mt('No specific version required');
4306: }
4307: $datatable .= $showreqd;
1.1 raeburn 4308: } else {
1.80 raeburn 4309: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4310: }
4311: $datatable .= &item_table_row_end();
4312: }
4313: $$rowtotal += scalar(@{$ordered});
4314: return $datatable;
4315: }
4316:
4317: sub new_cloners_dom_row {
1.71 raeburn 4318: my ($newdom,$num,$default) = @_;
4319: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4320: if ($newdom ne '') {
1.71 raeburn 4321: if ($num eq $default) {
4322: $checkedon = 'checked="checked" ';
4323: } else {
4324: $checkedoff = 'checked="checked" ';
4325: }
1.1 raeburn 4326: $output .= &Apache::loncommon::start_data_table_row().
4327: '<td valign="top"><span class="LC_nobreak">'.
4328: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4329: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 4330: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4331: 'onchange="javascript:update_cloners('.
1.1 raeburn 4332: "'cloners_activate','$num'".');" />'.
4333: &mt('Yes').'</label>'.(' 'x2).
4334: '<label><input type="radio" '.
1.71 raeburn 4335: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4336: 'onchange="javascript:update_cloners('.
1.1 raeburn 4337: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4338: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4339: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4340: &Apache::loncommon::end_data_table_row();
4341: }
4342: return $output;
4343: }
4344:
4345: sub can_modify_catsettings {
1.12 raeburn 4346: my ($dom,$crstype) = @_;
1.1 raeburn 4347: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4348: my ($can_toggle_cat,$can_categorize);
4349: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4350: if ($crstype eq 'Community') {
4351: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4352: $can_toggle_cat = 1;
4353: }
4354: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4355: $can_categorize = 1;
4356: }
4357: } else {
4358: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4359: $can_toggle_cat = 1;
4360: }
4361: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4362: $can_categorize = 1;
4363: }
1.1 raeburn 4364: }
4365: }
4366: return ($can_toggle_cat,$can_categorize);
4367: }
4368:
4369: sub assign_course_categories {
1.9 raeburn 4370: my ($r,$crstype) = @_;
1.1 raeburn 4371: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4372: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4373: my $hascats = 0;
4374: my $cathash;
4375: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4376: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4377: $cathash = $domconf{'coursecategories'}{'cats'};
4378: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4379: foreach my $cat (keys(%{$cathash})) {
4380: next if ($cat eq 'instcode::0');
4381: unless ($crstype eq 'Community') {
4382: next if ($cat eq 'communities::0');
4383: }
4384: $hascats ++;
4385: }
1.1 raeburn 4386: }
4387: }
4388: my $catwin_js;
4389: if ($hascats) {
1.9 raeburn 4390: my $alert;
4391: if ($crstype eq 'Community') {
4392: $alert = &mt("Use 'Save' in the main window to save community categories");
4393: } else {
4394: $alert = &mt("Use 'Save' in the main window to save course categories");
4395: }
1.72 damieng 4396: &js_escape(\$alert);
1.1 raeburn 4397: $catwin_js = <<ENDSCRIPT;
4398: <script type="text/javascript">
4399:
4400: function updateCategories() {
4401: var newcategories = '';
4402: var unescapedcats = '';
4403: if (document.chgcats.usecategory.length) {
4404: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4405: if (document.chgcats.usecategory[i].checked == true) {
4406: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4407: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4408: }
4409: }
4410: if (newcategories.length > 0) {
4411: newcategories = newcategories.slice(0,-1);
4412: }
4413: if (unescapedcats.length > 0) {
4414: unescapedcats = unescapedcats.slice(0,-3);
4415: }
4416: } else {
4417: if (document.chgcats.usecategory.checked == true) {
4418: newcategories = document.chgcats.usecategory.value;
4419: unescapedcats = document.chgcats.catname.value;
4420: }
4421: }
4422: opener.document.display.categories.value = newcategories;
4423: opener.document.display.categories_display.value = unescapedcats;
4424: alert("$alert");
4425: self.close();
4426: return;
4427: }
4428:
4429: </script>
4430: ENDSCRIPT
4431: } else {
4432: my $onload;
4433: }
1.9 raeburn 4434: my ($crscat,$catcrs,$assign);
4435: if ($crstype eq 'Community') {
4436: $crscat = 'Community Categories';
4437: $catcrs = &mt('Categorize Community');
4438: $assign = &mt('Assign one or more categories to this community.')
4439: } else {
4440: $crscat = 'Course Categories';
4441: $catcrs = &mt('Categorize Course');
4442: $assign = &mt('Assign one or more categories to this course.')
4443: }
1.1 raeburn 4444: my $start_page =
1.9 raeburn 4445: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4446: {'only_body' => 1,});
4447: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4448: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4449: if ($hascats) {
4450: my %currsettings =
4451: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4452: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4453: $currsettings{'categories'},$crstype);
4454: if ($cattable eq '') {
4455: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4456: } else {
4457: $categoriesform .= $assign.'<br /><br />'.
4458: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4459: $cattable."\n".
4460: '<br /><input type="button" name="changes" value="'.
4461: &mt('Copy to main window').'" '.
4462: 'onclick="javascript:updateCategories()" /></form><br />';
4463: }
1.1 raeburn 4464: } else {
1.12 raeburn 4465: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4466: }
4467: $r->print($start_page.$categoriesform.$end_page);
4468: return;
4469: }
4470:
1.36 raeburn 4471: sub display_loncaparev_constraints {
4472: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.66 raeburn 4473: my ($reqdmajor,$reqdminor);
1.36 raeburn 4474: my $cid = $env{'request.course.id'};
4475: my $cdom = $env{'course.'.$cid.'.domain'};
4476: my $cnum = $env{'course.'.$cid.'.num'};
4477: my $output;
1.39 raeburn 4478: my %lt = &Apache::lonlocal::texthash (
4479: 'all' => 'all',
4480: 'section/group' => 'section/group',
4481: 'user' => 'user',
4482: );
1.66 raeburn 4483: &Apache::lonrelrequtils::init_global_hashes();
4484: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4485: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4486: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 4487: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4488: }
4489: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 4490: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 4491: @scopeorder = ('all','section/group','user');
1.67 raeburn 4492: my $now = time;
1.36 raeburn 4493: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4494: if (ref($resourcedata) eq 'HASH') {
4495: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 4496: my %found;
1.66 raeburn 4497: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4498: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 4499: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
4500: my $value = $resourcedata->{$key};
4501: if ($item eq 'examcode') {
4502: if (&Apache::lonnet::validCODE($value)) {
4503: $value = 'valid';
4504: } else {
4505: $value = '';
4506: }
4507: } elsif ($item eq 'printstartdate') {
1.67 raeburn 4508: if ($value =~ /^\d+$/) {
1.70 raeburn 4509: if ($value > $now) {
4510: $value = 'future';
4511: }
4512: }
4513: } elsif ($item eq 'printenddate') {
4514: if ($value =~ /^\d+$/) {
4515: if ($value < $now) {
4516: $value = 'past';
4517: }
4518: }
4519: }
4520: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
4521: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4522: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 4523: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 4524: }
4525: }
4526: }
4527: }
1.79 raeburn 4528: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
4529: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 4530: my $value = $resourcedata->{$key};
1.79 raeburn 4531: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 4532: if ($value =~ /$valuematch/) {
4533: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 4534: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 4535: $found{$item}{'rev'} =
1.76 raeburn 4536: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 4537: last;
4538: }
4539: }
4540: }
4541: }
1.76 raeburn 4542: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
4543: my $regexp;
4544: if ($item eq 'maplevelrecurse') {
4545: $regexp = '\.(?:sequence|page)___\(rec\)\.';
4546: }
4547: if ($regexp ne '') {
4548: if ($key =~ /$regexp.*\.(\w+)$/) {
4549: my $name = $1;
4550: my $value = $resourcedata->{$key};
4551: if ($name eq 'type') {
4552: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
4553: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
4554: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
4555: }
4556: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
4557: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
4558: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
4559: $found{$name}{'rev'} =
4560: $Apache::lonnet::needsrelease{'parameter::::'.$item};
4561: }
4562: }
4563: }
1.70 raeburn 4564: foreach my $item (keys(%found)) {
4565: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4566: my $rev = $found{$item}{'rev'};
4567: my $valname = $found{$item}{'valname'};
1.76 raeburn 4568: my $extra = $found{$item}{'extra'};
1.70 raeburn 4569: my ($middle,$scope,$which,$level,$map,$resource);
4570: my $start = $cid.'.';
4571: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4572: $middle = $1;
4573: $which = $2;
4574: $scope = 'user';
4575: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4576: $middle = $1;
4577: $which = $2;
4578: $scope = 'section/group';
4579: } else {
4580: $scope = 'all';
4581: }
4582: my $what="$stdname=$valname";
1.76 raeburn 4583: if ($extra) {
4584: $what .= "<br/>$extra<br />";
4585: }
1.70 raeburn 4586: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4587: $level = 'general';
4588: if ($scope eq 'all') {
4589: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4590: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4591: push(@{$fromparam{$rev}{$scope}},$what);
4592: }
4593: } else {
4594: push(@{$fromparam{$rev}{$scope}},$what);
4595: }
4596: } else {
4597: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4598: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4599: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4600: }
4601: } else {
4602: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4603: }
4604: }
4605: $rowspan{$rev} ++;
1.76 raeburn 4606: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 4607: $level = 'folder';
4608: $map = $1;
4609: if ($scope eq 'all') {
4610: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4611: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4612: push(@{$bymap{$map}{$rev}{$scope}},$what);
4613: }
4614: } else {
4615: push(@{$bymap{$map}{$rev}{$scope}},$what);
4616: }
4617: } else {
4618: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4619: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4620: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4621: }
4622: } else {
4623: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4624: }
4625: }
4626: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4627: $level = 'resource';
4628: $resource = $1;
4629: if ($scope eq 'all') {
4630: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4631: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4632: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4633: }
4634: } else {
4635: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4636: }
4637: } else {
4638: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4639: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4640: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4641: }
4642: } else {
4643: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 4644: }
4645: }
4646: }
4647: }
4648: }
4649: if (keys(%fromparam)) {
4650: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4651: &Apache::loncommon::start_data_table().
4652: &Apache::loncommon::start_data_table_header_row().
4653: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4654: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4655: &Apache::loncommon::end_data_table_header_row();
4656: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 4657: my ($major,$minor) = split(/\./,$rev);
4658: ($reqdmajor,$reqdminor) =
4659: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4660: $output .= &Apache::loncommon::start_data_table_row().
4661: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4662: my $newrow;
4663: foreach my $scope (@scopeorder) {
4664: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4665: if ($newrow) {
4666: $output .= &Apache::loncommon::continue_data_table_row();
4667: }
1.39 raeburn 4668: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4669: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4670: $output .= '<td>'.$which.'</td><td>'.
4671: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4672: }
4673: $output .= &Apache::loncommon::end_data_table_row();
4674: $newrow = 1;
4675: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4676: if ($newrow) {
4677: $output .= &Apache::loncommon::continue_data_table_row();
4678: }
1.39 raeburn 4679: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4680: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4681: &Apache::loncommon::end_data_table_row();
4682: $newrow = 1;
4683: }
4684: }
4685: }
4686: $output .= &Apache::loncommon::end_data_table().'<br />';
4687: }
4688: }
4689:
1.66 raeburn 4690: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4691: my $now = time;
4692: if (keys(%comm_blocks) > 0) {
4693: foreach my $block (keys(%comm_blocks)) {
4694: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 4695: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 4696: if (ref($comm_blocks{$block}) eq 'HASH') {
4697: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4698: ' '.&mt('set by [_1]',
4699: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4700: }
4701: next;
4702: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4703: my ($start,$end) = ($1,$2);
4704: next if ($end < $now);
4705: }
4706: if (ref($comm_blocks{$block}) eq 'HASH') {
4707: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4708: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4709: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 4710: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 4711: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4712: ' '.
4713: &mt('set by [_1]',
4714: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4715: }
4716: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 4717: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 4718: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4719: ' '.
4720: &mt('set by [_1]',
4721: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4722:
4723: }
4724: }
4725: }
4726: }
4727: if (keys(%fromblocks)) {
4728: my %lt = (
4729: docs => 'Content blocking',
4730: printout => 'Printout generation',
4731: timer => 'Timed quiz trigger',
4732: );
4733: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4734: &Apache::loncommon::start_data_table().
4735: &Apache::loncommon::start_data_table_header_row().
4736: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4737: '<th>'.&mt('Event(s)').'</th>'.
4738: &Apache::loncommon::end_data_table_header_row();
4739: foreach my $type ('docs','printout','timer') {
4740: if (ref($fromblocks{$type}) eq 'HASH') {
4741: foreach my $rev (keys(%{$fromblocks{$type}})) {
4742: my ($major,$minor) = split(/\./,$rev);
4743: ($reqdmajor,$reqdminor) =
4744: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4745: $output .= &Apache::loncommon::start_data_table_row().
4746: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4747: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4748: $output .= $event.'<br />';
4749: }
4750: $output =~ s{\Q<br />\E$}{};
4751: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4752: }
4753: }
4754: }
4755: $output .= &Apache::loncommon::end_data_table().'<br />';
4756: }
4757: }
4758:
1.36 raeburn 4759: if (defined($navmap)) {
4760: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 4761: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 4762: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 4763: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 4764: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 4765: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4766: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4767: my $valanon=&get_param_description($stdtype,'anonsurvey');
4768: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 4769: my %checkedrev;
1.85 raeburn 4770: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 4771: my @parts = @{$res->parts()};
4772: my $symb = $res->symb();
4773: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 4774: if ($res->is_tool()) {
4775: my $rev = $rev_exttool;
4776: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
4777: $allmaps{$enclosing_map} = 1;
4778: next;
4779: }
1.36 raeburn 4780: foreach my $part (@parts) {
4781: if (exists($anonsubms{$symb."\0".$part})) {
4782: my $rev = $rev_anonsurv;
4783: my $what="$stdname=$valanon";
4784: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4785: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4786: push(@{$bysubmission{$symb}{$rev}},$what);
4787: }
4788: } else {
4789: push(@{$bysubmission{$symb}{$rev}},$what);
4790: }
4791: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4792: unless ($checkedrev{'anonsurvey'}) {
4793: my ($major,$minor) = split(/\./,$rev);
4794: ($reqdmajor,$reqdminor) =
4795: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4796: $reqdmajor,$reqdminor);
4797: $checkedrev{'anonsurvey'} = 1;
4798: }
1.36 raeburn 4799: }
4800: if (exists($randtrysubms{$symb."\0".$part})) {
4801: my $rev = $rev_randtry;
4802: my $what="$stdname=$valrandtry";
4803: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4804: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4805: push(@{$bysubmission{$symb}{$rev}},$what);
4806: }
4807: } else {
4808: push(@{$bysubmission{$symb}{$rev}},$what);
4809: }
4810: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4811: unless ($checkedrev{'randomizetry'}) {
4812: my ($major,$minor) = split(/\./,$rev);
4813: ($reqdmajor,$reqdminor) =
4814: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4815: $reqdmajor,$reqdminor);
4816: $checkedrev{'randomizetry'} = 1;
4817: }
1.36 raeburn 4818: }
4819: }
4820: my %responses = $res->responseTypes();
4821: foreach my $key (keys(%responses)) {
1.66 raeburn 4822: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4823: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4824: unless ($checkedrev{$key}) {
4825: my ($major,$minor) = split(/\./,$rev);
4826: ($reqdmajor,$reqdminor) =
4827: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4828: $reqdmajor,$reqdminor);
4829: $checkedrev{$key} = 1;
4830: }
4831: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4832: $allmaps{$enclosing_map} = 1;
4833: }
4834: }
4835: }
4836: if (keys(%byresource) > 0) {
4837: foreach my $symb (keys(%byresource)) {
4838: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4839: $allmaps{$map} = 1;
4840: }
4841: }
4842: if (keys(%bymap) > 0) {
4843: foreach my $map (keys(%bymap)) {
4844: $allmaps{$map} = 1;
4845: }
4846: }
4847: foreach my $map (keys(%allmaps)) {
4848: my $mapres = $navmap->getResourceByUrl($map);
4849: if (ref($mapres)) {
1.68 raeburn 4850: my $mapsymb = $mapres->symb();
4851: $toshow{$mapsymb} = 1;
1.36 raeburn 4852: my $pcslist = $mapres->map_hierarchy();
4853: if ($pcslist ne '') {
4854: foreach my $pc (split(/,/,$pcslist)) {
4855: my $res = $navmap->getByMapPc($pc);
4856: if (ref($res)) {
4857: my $symb = $res->symb();
4858: unless ($symb eq '______') {
4859: $toshow{$symb} = 1;
4860: }
4861: }
4862: }
4863: }
4864: }
4865: }
4866: }
1.117 raeburn 4867: my $supptools = &Apache::lonnet::count_supptools($cnum,$cdom,1,1);
1.36 raeburn 4868: my $mapres_header = '<h4>'.
4869: &mt('Requirements for specific folders or resources').
4870: '</h4>';
4871: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4872: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4873: $output .= $mapres_header;
4874: }
4875: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4876: my $title = 'Version Constraints';
4877: my $start_page =
4878: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4879: $r->print($start_page.$top_header);
4880: if ($output) {
4881: $r->print($output);
1.86 raeburn 4882: if (defined($navmap) || $supptools) {
1.36 raeburn 4883: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4884: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4885: }
4886: $r->print('<br /><br />');
4887: } else {
4888: $r->print('<p class="LC_info">'.
4889: &mt('No version requirements from resource content or settings.').
4890: '</p>');
4891: }
4892: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4893: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4894: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4895: return 1;
4896: }
1.36 raeburn 4897: return;
4898: }
4899:
4900: sub show_contents_view {
1.39 raeburn 4901: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 4902: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
4903: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4904: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4905: my $showmaincontent;
4906: if ((ref($navmap)) &&
4907: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4908: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
4909: (keys(%{$bycrsrestype}) > 0))) {
4910: $showmaincontent = 1;
4911: }
4912: if ($showmaincontent || $supptools) {
4913: $r->print(&Apache::loncommon::start_data_table());
4914: }
4915: if ($showmaincontent) {
4916: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 4917: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 4918: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 4919: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4920: '<th>'.&mt('Attribute/Setting').'</th>'.
4921: &Apache::loncommon::end_data_table_header_row().
4922: &Apache::loncommon::start_data_table_row().
1.58 raeburn 4923: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 4924: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
4925: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4926: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4927: my $curRes;
4928: my $depth = 0;
4929: my %parent = ();
4930: my $startcount = 5;
4931: my $lastcontainer = $startcount;
4932: while ($curRes = $it->next()) {
4933: if ($curRes == $it->BEGIN_MAP()) {
4934: $depth++;
4935: $parent{$depth}= $lastcontainer;
4936: }
4937: if ($curRes == $it->END_MAP()) {
4938: $depth--;
4939: $lastcontainer = $parent{$depth};
4940: }
4941: my $indent;
4942: for (my $i=0; $i<$depth; $i++) {
4943: $indent.= $whitespace;
4944: }
4945: if (ref($curRes)) {
4946: my $symb = $curRes->symb();
4947: my $ressymb = $symb;
4948: my $srcf = $curRes->src();
4949: my $title = &Apache::lonnet::gettitle($srcf);
4950: if (($curRes->is_sequence()) || ($curRes->is_page())) {
4951: next unless($toshow->{$symb});
4952: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
4953: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4954: if ($curRes->is_page()) {
4955: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
4956: }
4957: my $rowspan = 1;
4958: if (ref($bymap->{$url}) eq 'HASH') {
4959: $rowspan = scalar(keys(%{$bymap->{$url}}));
4960: }
4961: $r->print(&Apache::loncommon::start_data_table_row().
4962: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 4963: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 4964: $r->print(&Apache::loncommon::end_data_table_row());
4965: } else {
4966: my $rowspan;
4967: if (ref($byresource->{$symb}) eq 'HASH') {
4968: $rowspan += scalar(keys(%{$byresource->{$symb}}));
4969: }
4970: if (ref($bysubmission->{$symb}) eq 'HASH') {
4971: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
4972: }
4973: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4974: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
4975: }
1.85 raeburn 4976: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
4977: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
4978: }
1.36 raeburn 4979: next if (!$rowspan);
4980: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
4981: &mt('Problem').'" />';
4982: $r->print(&Apache::loncommon::start_data_table_row().
4983: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
4984: my $newrow;
4985: if (ref($byresource->{$symb}) eq 'HASH') {
4986: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
4987: if ($newrow) {
4988: $r->print(&Apache::loncommon::continue_data_table_row());
4989: }
4990: $r->print('<td valign="middle">'.$rev.'</td><td>');
4991: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
4992: $r->print('<table border="0">');
4993: foreach my $scope (@{$scopeorder}) {
4994: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4995: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4996: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
4997: $r->print('<td>'.$which.'</td><td>'.
4998: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
4999: '</td>');
5000: }
5001: $r->print('</tr>');
5002: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5003: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 5004: '<td> </td><td>'.
5005: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
5006: }
5007: }
5008: $r->print('</table>');
5009: }
5010: $r->print('</td>');
5011: $r->print(&Apache::loncommon::end_data_table_row());
5012: $newrow = 1;
5013: }
5014: }
5015: if (ref($bysubmission->{$symb}) eq 'HASH') {
5016: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
5017: if ($newrow) {
5018: $r->print(&Apache::loncommon::continue_data_table_row());
5019: }
5020: $r->print('<td>'.$rev.'</td><td>');
5021: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
5022: $r->print(&mt('Submissions to: ').' '.
5023: join(', ',@{$bysubmission->{$symb}{$rev}}));
5024: }
5025: $r->print('</td>');
5026: $r->print(&Apache::loncommon::end_data_table_row());
5027: $newrow = 1;
5028: }
5029: }
5030: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5031: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
5032: if ($newrow) {
5033: $r->print(&Apache::loncommon::continue_data_table_row());
5034: }
5035: $r->print('<td>'.$rev.'</td><td>');
5036: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
5037: $r->print(&mt('Response Type(s): ').' '.
5038: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
5039: }
5040: $r->print('</td>');
5041: }
5042: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 5043: $newrow = 1;
5044: }
5045: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5046: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
5047: if ($newrow) {
5048: $r->print(&Apache::loncommon::continue_data_table_row());
5049: }
5050: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
5051: }
1.86 raeburn 5052: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5053: }
5054: }
5055: }
5056: }
1.86 raeburn 5057: }
5058: if ($supptools) {
5059: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5060: $r->print(&Apache::loncommon::start_data_table_header_row().
5061: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5062: '<th>'.&mt('Resource Type').'</th>'.
5063: &Apache::loncommon::end_data_table_header_row().
5064: &Apache::loncommon::start_data_table_row().
5065: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
5066: '<td valign="middle">'.
5067: $Apache::lonrelrequtils::exttool{'major'}.'.'.
5068: $Apache::lonrelrequtils::exttool{'minor'}.
5069: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
5070: $supptools).'</td>'.
5071: &Apache::loncommon::end_data_table_row());
5072: }
5073: if ($showmaincontent || $supptools) {
1.36 raeburn 5074: $r->print(&Apache::loncommon::end_data_table());
5075: }
1.66 raeburn 5076: return;
1.36 raeburn 5077: }
5078:
5079: sub releases_by_map {
1.39 raeburn 5080: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 5081: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.73 raeburn 5082: my $newrow = 0;
1.36 raeburn 5083: if (ref($bymap->{$url}) eq 'HASH') {
5084: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 5085: if ($newrow) {
5086: $r->print(&Apache::loncommon::end_data_table_row().
5087: &Apache::loncommon::continue_data_table_row());
5088: }
1.36 raeburn 5089: $r->print('<td valign="middle">'.$rev.'</td><td>');
5090: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
5091: $r->print('<table border="0">');
5092: foreach my $scope (@{$scopeorder}) {
5093: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5094: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5095: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
5096: $r->print('<td>'.$which.'</td><td>'.
5097: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
5098: '</td>');
5099: }
5100: $r->print('</tr>');
5101: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5102: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 5103: '</td><td> </td><td>'.
5104: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
5105: }
5106: }
5107: $r->print('</table>');
5108: }
5109: $r->print('</td>');
1.73 raeburn 5110: $newrow = 1;
1.36 raeburn 5111: }
5112: } else {
5113: $r->print('<td colspan="2"> </td>');
5114: }
5115: return;
5116: }
5117:
5118: sub get_param_description {
1.70 raeburn 5119: my ($stdtype,$value,$regexp) = @_;
5120: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 5121: if ($stdtype =~ /^string/) {
5122: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5123: } elsif ($stdtype eq 'date_interval') {
5124: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
5125: }
1.70 raeburn 5126: if ($regexp) {
1.74 raeburn 5127: if ($stdtype =~ /^string/) {
5128: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
5129: } elsif ($stdtype eq 'date_interval') {
5130: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
5131: }
1.70 raeburn 5132: if (ref($parammatches) eq 'ARRAY') {
5133: @possibles = @{$parammatches};
5134: } else {
5135: undef($regexp);
5136: $name = $value;
5137: }
5138: }
5139: unless ($regexp) {
5140: $name = $value;
5141: if (ref($paramstrings) eq 'ARRAY') {
5142: @possibles = @{$paramstrings};
5143: } else {
1.76 raeburn 5144: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
5145: if ($name == 0) {
5146: $name = &mt('Never');
5147: } elsif (($name ne '') && ($name !~ /\D/)) {
5148: $name = &Apache::lonlocal::locallocaltime($name);
5149: }
5150: }
1.70 raeburn 5151: return $name;
5152: }
1.36 raeburn 5153: }
1.70 raeburn 5154: foreach my $possibilities (@possibles) {
1.36 raeburn 5155: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 5156: my $gotregexmatch = '';
5157: if ($regexp) {
5158: last if ($gotregexmatch);
5159: my ($item,$pattern) = @{ $possibilities };
5160: if ($value =~ /$pattern/) {
5161: if (ref($paramstrings) eq 'ARRAY') {
5162: foreach my $possibles (@{$paramstrings}) {
5163: next unless (ref($possibles) eq 'ARRAY');
5164: my ($thing,$description) = @{$possibles};
5165: if ($thing eq $item) {
5166: $name = $description;
5167: $gotregexmatch = 1;
5168: last;
5169: }
5170: }
5171: last if ($gotregexmatch);
5172: }
5173: }
5174: } else {
5175: my ($thing,$description) = @{ $possibilities };
5176: if ($thing eq $value) {
5177: $name = $description;
5178: last;
5179: }
1.36 raeburn 5180: }
5181: }
5182: return $name;
5183: }
5184:
1.66 raeburn 5185: sub update_releasereq {
5186: my $readmap = 1;
5187: my $getrelreq = 1;
5188: if (ref($modified_courses) eq 'ARRAY') {
5189: foreach my $item (@{$modified_courses}) {
5190: if (ref($item) eq 'ARRAY') {
5191: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5192: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5193: $chome,$crstype,$cdom.'_'.$cnum,
5194: $readmap,$getrelreq);
5195: }
5196: }
5197: $modified_courses = [];
5198: }
5199: undef($registered_cleanup);
5200: return;
5201: }
5202:
1.25 raeburn 5203: sub show_autocoowners {
5204: my (@currcoown) = @_;
1.56 raeburn 5205: 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 5206: if (@currcoown > 0) {
5207: $output .= '<br />'.&mt('Current co-owners are:').' '.
5208: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5209: } else {
5210: $output .= '<br />'.&mt('Currently no co-owners.');
5211: }
5212: return $output;
5213: }
5214:
5215: sub coowner_invitations {
1.80 raeburn 5216: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5217: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5218: my $pendingcoowners =
5219: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5220: if ($pendingcoowners) {
5221: @pendingcoown = split(',',$pendingcoowners);
5222: }
1.80 raeburn 5223: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5224: @currcoown = @{$currcoownref};
1.80 raeburn 5225: }
5226: my $disabled;
5227: if ($noedit) {
5228: $disabled = ' disabled="disabled"';
5229: }
1.25 raeburn 5230: my $ccrole = 'cc';
5231: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5232: foreach my $key (sort(keys(%ccroles))) {
5233: my ($ccname,$ccdom,$role) = split(':',$key);
5234: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5235: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5236: push(@othercoords,$ccname.':'.$ccdom);
5237: }
5238: }
5239: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5240: if ($coowner_rows) {
5241: $output .= &Apache::loncommon::start_data_table();
5242: if (@currcoown) {
5243: $output .= &Apache::loncommon::start_data_table_row().
5244: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5245: foreach my $person (@currcoown) {
5246: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5247: $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 5248: }
5249: $output .= '</td>'.
5250: &Apache::loncommon::end_data_table_row();
5251: }
5252: if ($pendingcoowners) {
5253: $output .= &Apache::loncommon::start_data_table_row().
5254: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5255: foreach my $person (@pendingcoown) {
5256: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5257: $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 5258: }
5259: $output .= '</td>'.
5260: &Apache::loncommon::end_data_table_row();
5261: }
5262: if (@othercoords) {
5263: $output .= &Apache::loncommon::start_data_table_row().
5264: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5265: foreach my $person (@othercoords) {
5266: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5267: $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 5268: }
5269: $output .= '</td>'.
5270: &Apache::loncommon::end_data_table_row();
5271: }
5272: $output .= &Apache::loncommon::end_data_table();
5273: } else {
5274: $output = &mt('There are no coordinators to select as co-owners');
5275: }
5276: return $output;
5277: }
5278:
5279: sub manage_coownership {
1.80 raeburn 5280: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5281: my (@pendingcoown,@currcoown);
1.25 raeburn 5282: my $pendingcoowners =
5283: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5284: if ($pendingcoowners) {
5285: @pendingcoown = split(',',$pendingcoowners);
5286: }
1.80 raeburn 5287: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5288: @currcoown = @{$currcoownref};
1.80 raeburn 5289: }
5290: my $disabled;
5291: if ($noedit) {
5292: $disabled = ' disabled="disabled"';
5293: }
1.25 raeburn 5294: my ($is_coowner,$is_pending,$output);
5295: my $uname = $env{'user.name'};
5296: my $udom = $env{'user.domain'};
5297: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5298: $is_coowner = 1;
5299: }
5300: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5301: $is_pending = 1;
5302: }
5303: if (@currcoown && ($is_coowner || $is_pending)) {
5304: $output = &Apache::loncommon::start_data_table();
5305: }
5306: if (@currcoown) {
5307: if ($is_coowner || $is_pending) {
5308: $output .= &Apache::loncommon::start_data_table().
5309: &Apache::loncommon::start_data_table_row().'<td>';
5310: }
5311: $output .= &mt('Current co-owners are:').' '.
5312: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5313: if ($is_coowner || $is_pending) {
5314: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5315: }
5316: }
5317: if ($is_coowner || $is_pending) {
5318: if (@currcoown) {
5319: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5320: }
5321: $output .= '<span class="LC_nobreak">';
5322: if ($is_coowner) {
1.90 raeburn 5323: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5324: } else {
1.90 raeburn 5325: $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).
5326: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5327: }
5328: $output .= '</span>';
5329: if (@currcoown) {
5330: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5331: }
5332: }
5333: if (@currcoown && ($is_coowner || $is_pending)) {
5334: $output .= &Apache::loncommon::end_data_table();
5335: }
5336: return $output;
5337: }
5338:
1.1 raeburn 5339: sub print_localization {
1.80 raeburn 5340: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5341: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5342: return;
5343: }
5344: my %items = (
5345: languages => {
1.17 faziophi 5346: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5347: &mt("(overrides individual user preference)"),
1.1 raeburn 5348: input => 'selectbox',
5349: },
5350: timezone => {
1.17 faziophi 5351: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5352: input => 'selectbox',
5353: },
5354: datelocale => {
1.17 faziophi 5355: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5356: input => 'selectbox',
5357: },
5358: );
1.80 raeburn 5359: my ($datatable,$disabled);
1.1 raeburn 5360: my $count = 0;
1.80 raeburn 5361: if ($noedit) {
5362: $disabled = ' disabled="disabled"';
5363: }
1.1 raeburn 5364: foreach my $item (@{$ordered}) {
5365: $count ++;
1.56 raeburn 5366: my $colspan;
5367: unless ($item eq 'languages') {
1.80 raeburn 5368: $colspan = 2;
1.56 raeburn 5369: }
5370: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5371: if ($item eq 'timezone') {
5372: my $includeempty = 1;
5373: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5374: my $onchange;
5375: unless ($noedit) {
5376: $onchange = ' onchange="javascript:toggleTimeZone();"';
5377: }
5378: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5379: $datatable .=
1.115 raeburn 5380: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5381: $includeempty,$id,$disabled);
5382: my $tzsty = 'none';
5383: if ($timezone ne '') {
5384: $tzsty = 'block';
5385: }
5386: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5387: '<span class="LC_nobreak">'.
5388: &mt('Override individual user preference?').
5389: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5390: '</span></div>';
1.1 raeburn 5391: } elsif ($item eq 'datelocale') {
5392: my $includeempty = 1;
5393: my $locale_obj = &Apache::lonlocal::getdatelocale();
5394: my $currdatelocale;
5395: if (ref($locale_obj)) {
5396: $currdatelocale = $locale_obj->id();
5397: }
5398: $datatable .=
5399: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5400: undef,$includeempty,$disabled);
1.1 raeburn 5401: } else {
5402: if ($settings->{$item} eq '') {
1.80 raeburn 5403: unless ($noedit) {
5404: $datatable .= '</td><td align="right">'.
5405: &Apache::loncommon::select_language('languages_0','',1);
5406: }
1.1 raeburn 5407: } else {
5408: my $num = 0;
1.3 raeburn 5409: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5410: $datatable .= '</td><td align="right"><br />'.
5411: &Apache::loncommon::start_data_table();
1.1 raeburn 5412: if (@languages > 0) {
1.3 raeburn 5413: my %langchoices = &get_lang_choices();
1.1 raeburn 5414: foreach my $lang (@languages) {
5415: my $showlang = $lang;
1.3 raeburn 5416: if (exists($langchoices{$lang})) {
5417: $showlang = $langchoices{$lang};
1.1 raeburn 5418: }
5419: $datatable .=
5420: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5421: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5422: &mt('Language:').'<b> '.$showlang.
5423: '</b><input type="hidden" name="languages_'.$num.
5424: '" value="'.$lang.'" /></span><br />'.
5425: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5426: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5427: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5428: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5429: $num ++;
5430: }
5431: }
1.80 raeburn 5432: unless ($noedit) {
5433: $datatable .=
5434: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5435: '<td align="left"><span class="LC_nobreak">'.
5436: &mt('Additional language:'). '</span><br />'.
5437: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5438: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5439: '</td>'.&Apache::loncommon::end_data_table_row();
5440: }
5441: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5442: }
5443: }
5444: $datatable .= &item_table_row_end();
5445: }
5446: $$rowtotal += scalar(@{$ordered});
5447: return $datatable;
5448: }
5449:
1.3 raeburn 5450: sub get_lang_choices {
5451: my %langchoices;
5452: foreach my $id (&Apache::loncommon::languageids()) {
5453: my $code = &Apache::loncommon::supportedlanguagecode($id);
5454: if ($code) {
5455: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5456: }
5457: }
5458: return %langchoices;
5459: }
5460:
1.1 raeburn 5461: sub print_feedback {
1.80 raeburn 5462: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5463: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5464: return;
5465: }
5466: my %items = (
1.3 raeburn 5467: 'question.email' => {
5468: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5469: input => 'textbox',
5470: size => '50',
5471: },
5472:
1.3 raeburn 5473: 'comment.email' => {
5474: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5475: input => 'textbox',
5476: size => '50',
5477: },
5478:
1.3 raeburn 5479: 'policy.email' => {
5480: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5481: input => 'textbox',
5482: size => '50',
5483: },
5484: );
5485: my $datatable;
5486: my $count = 0;
5487: my ($cnum) = &get_course();
5488: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5489: my @sections = sort( { $a <=> $b } keys(%sections));
5490: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5491: currone => 'Current recipient:',
5492: currmult => 'Current recipients:',
5493: add => 'Additional recipient:',
5494: del => 'Delete?',
5495: sec => 'Sections:',
1.1 raeburn 5496: );
1.80 raeburn 5497: my $disabled;
5498: if ($noedit) {
5499: $disabled = ' disabled="disabled"';
5500: }
1.1 raeburn 5501: foreach my $item (@{$ordered}) {
5502: $count ++;
1.20 faziophi 5503: if ($position eq 'top') {
5504: $datatable .= &item_table_row_start($items{$item}{text},$count);
5505: } else {
1.56 raeburn 5506: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5507: }
1.1 raeburn 5508: if ($position eq 'top') {
5509: my $includeempty = 0;
1.94 raeburn 5510: $datatable .= '</td><td align="right">'.
5511: &user_table($cdom,$item,\@sections,
1.80 raeburn 5512: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5513: } else {
1.3 raeburn 5514: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5515: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5516: }
5517: $datatable .= &item_table_row_end();
5518: }
5519: $$rowtotal += scalar(@{$ordered});
5520: return $datatable;
5521: }
5522:
5523: sub user_table {
1.80 raeburn 5524: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5525: my $output;
5526: if ($currvalue eq '') {
1.80 raeburn 5527: unless ($noedit) {
5528: $output .= &select_recipient($item,'0',$cdom,$sections);
5529: }
1.1 raeburn 5530: } else {
5531: my $num = 0;
5532: my @curr = split(/,/,$currvalue);
1.56 raeburn 5533: $output .= '<table class="LC_data_table">';
1.1 raeburn 5534: my ($currusers);
1.80 raeburn 5535: my $disabled;
5536: if ($noedit) {
5537: $disabled = ' disabled="disabled"';
5538: }
1.1 raeburn 5539: foreach my $val (@curr) {
5540: next if ($val eq '');
5541: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5542: my @selsec;
5543: if ($seclist) {
5544: $seclist =~ s/(^\(|\)$)//g;
5545: @selsec = split(/\s*;\s*/,$seclist);
5546: }
5547: $currusers .= '<tr>'.
5548: '<td valign="top"><span class="LC_nobreak">'.
5549: '<label><input type="checkbox" '.
1.80 raeburn 5550: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5551: $lt->{'del'}.'</label>'.
5552: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5553: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5554: &Apache::loncommon::aboutmewrapper(
5555: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5556: $uname,$udom,'aboutuser');
5557: if (ref($sections) eq 'ARRAY') {
5558: if (@{$sections}) {
5559: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5560: &select_sections($item,$num,$sections,
1.80 raeburn 5561: \@selsec,$noedit);
1.1 raeburn 5562: }
5563: }
5564: $currusers .= '</span></td></tr>';
5565: $num ++;
5566: }
5567: if ($num) {
1.10 raeburn 5568: $output .= '<tr>'.
1.1 raeburn 5569: '<td align="left"><i>';
1.20 faziophi 5570: if ($num == 1) {
1.1 raeburn 5571: $output .= $lt->{'currone'};
5572: } else {
1.21 raeburn 5573: $output .= $lt->{'currmult'};
1.1 raeburn 5574: }
5575: $output .= '</i><br />'.
5576: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5577: '</tr>';
1.1 raeburn 5578: }
1.80 raeburn 5579: unless ($noedit) {
5580: $output .=
5581: '<tr>'.
1.1 raeburn 5582: '<td align="left"><span class="LC_nobreak"><i>'.
5583: $lt->{'add'}.'</i></span><br />'.
5584: &select_recipient($item,$num,$cdom,$sections).
5585: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5586: '</td></tr>';
5587: }
5588: $output .= '</table>';
1.1 raeburn 5589: }
5590: return $output;
5591: }
5592:
5593: sub select_recipient {
5594: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5595: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5596: my $selectlink =
5597: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5598: $item.'_udom_'.$num,'only');
1.1 raeburn 5599: my $output =
1.10 raeburn 5600: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5601: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5602: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5603: if (ref($sections) eq 'ARRAY') {
5604: if (@{$sections}) {
5605: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5606: &select_sections($item,$num,$sections,$selected).'</td>';
5607: }
5608: }
5609: $output .= '<td valign="top">'.
5610: $selectlink.'</td></tr></table>';
5611: return $output;
5612: }
5613:
5614: sub select_sections {
1.80 raeburn 5615: my ($item,$num,$sections,$selected,$noedit) = @_;
5616: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5617: if (ref($selected) eq 'ARRAY') {
5618: @currsecs = @{$selected};
5619: }
5620: if (!@currsecs) {
5621: $allsec = ' selected="selected"';
5622: }
1.80 raeburn 5623: if ($noedit) {
5624: $disabled = ' disabled="disabled"';
5625: }
1.1 raeburn 5626: if (ref($sections) eq 'ARRAY') {
5627: if (@{$sections}) {
5628: my $mult;
5629: if (@{$sections} > 1) {
5630: $mult = ' multiple="multiple"';
5631: if (@{$sections} > 3) {
5632: $mult .= ' size="4"';
5633: }
5634: }
1.80 raeburn 5635: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
1.1 raeburn 5636: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
5637: foreach my $sec (@{$sections}) {
5638: my $is_sel;
5639: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
5640: $is_sel = 'selected="selected"';
5641: }
5642: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5643: }
5644: $output .= '</select>';
5645: }
5646: }
5647: return $output;
5648: }
5649:
5650: sub print_discussion {
1.80 raeburn 5651: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5652: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5653: return;
5654: }
5655: my %items = (
5656: 'plc.roles.denied' => {
1.10 raeburn 5657: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5658: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5659: &mt('(role-based)'),
1.1 raeburn 5660: input => 'checkbox',
5661: },
5662:
5663: 'plc.users.denied' => {
1.3 raeburn 5664: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5665: &mt('(specific user(s))'),
1.1 raeburn 5666: input => 'checkbox',
5667: },
5668:
5669: 'pch.roles.denied' => {
1.10 raeburn 5670: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5671: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5672: &mt('(role-based)'),
1.1 raeburn 5673: input => 'checkbox',
5674: },
5675:
5676: 'pch.users.denied' => {
1.3 raeburn 5677: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5678: &mt('(specific user(s))'),
1.1 raeburn 5679: input => 'checkbox',
5680: },
1.77 raeburn 5681:
5682: 'pac.roles.denied' => {
5683: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5684: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5685: &mt('(role-based)'),
5686: input => 'checkbox',
5687: },
5688:
5689: 'pac.users.denied' => {
5690: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5691: &mt('(specific user(s))'),
5692: input => 'checkbox',
5693: },
5694:
1.1 raeburn 5695: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5696: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5697: input => 'radio',
5698: },
5699:
5700: 'allow_discussion_post_editing' => {
1.3 raeburn 5701: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5702: input => 'checkbox',
5703: },
1.50 raeburn 5704: 'discussion_post_fonts' => {
5705: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5706: input => 'textbox',
5707: size => '20',
5708: },
1.1 raeburn 5709: );
5710: my $datatable;
5711: my $count;
5712: my ($cnum) = &get_course();
5713: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5714: my @sections = sort( { $a <=> $b } keys(%sections));
5715: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5716: currone => 'Disallowed:',
5717: currmult => 'Disallowed:',
5718: add => 'Disallow more:',
5719: del => 'Delete?',
5720: sec => 'Sections:',
1.1 raeburn 5721: );
5722: foreach my $item (@{$ordered}) {
5723: $count ++;
1.56 raeburn 5724: my $colspan;
5725: if ($item eq 'allow_limited_html_in_feedback') {
5726: $colspan = 2;
5727: }
5728: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5729: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5730: $datatable .= '</td><td align="right">'.
1.80 raeburn 5731: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5732: '</table>';
5733: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5734: $datatable .= '</td><td align="right">'.
5735: &user_table($cdom,$item,undef,
1.80 raeburn 5736: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5737: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5738: $datatable .= '</td><td align="right">'.
1.80 raeburn 5739: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5740: '</table>';
5741: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5742: $datatable .= '</td><td align="right">'.
5743: &user_table($cdom,$item,undef,
1.80 raeburn 5744: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5745: } elsif ($item eq 'pac.roles.denied') {
5746: $datatable .= '</td><td align="right">'.
1.80 raeburn 5747: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5748: '</table>';
5749: } elsif ($item eq 'pac.users.denied') {
5750: $datatable .= '</td><td align="right">'.
5751: &user_table($cdom,$item,undef,
1.80 raeburn 5752: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5753: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5754: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5755: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5756: $datatable .= '</td><td align="right"><br />'.
5757: &Apache::loncommon::start_data_table().
1.1 raeburn 5758: &Apache::loncommon::start_data_table_row().
5759: '<th align="left">'.&mt('Role').'</th><th>'.
5760: &mt('Sections').'</th>'.
5761: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5762: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5763: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5764: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5765: $datatable .= '</td><td align="right"><br />'.
5766: &Apache::loncommon::start_data_table().
1.50 raeburn 5767: &Apache::loncommon::start_data_table_row().
5768: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5769: '<th align="center">'.&mt('font-size').'</th>'.
5770: '<th align="center">'.&mt('font-weight').'</th>'.
5771: '<th align="center">'.&mt('font-style').'</th>'.
5772: '<th align="center">'.&mt('Other css').'</th>'.
5773: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5774: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5775: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5776: }
5777: $datatable .= &item_table_row_end();
5778: }
5779: $$rowtotal += scalar(@{$ordered});
5780: return $datatable;
5781: }
5782:
5783: sub role_checkboxes {
1.80 raeburn 5784: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5785: my @roles = ('st','ad','ta','ep','in');
5786: if ($crstype eq 'Community') {
5787: push(@roles,'co');
5788: } else {
5789: push(@roles,'cc');
5790: }
1.1 raeburn 5791: my $output;
5792: my (@current,@curr_roles,%currsec,@sections);
5793: if ($showsections) {
5794: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5795: @sections = sort( { $a <=> $b } keys(%sections));
5796: }
5797: if (ref($settings) eq 'HASH') {
5798: if ($settings->{$item}) {
5799: @current = split(',',$settings->{$item});
5800: if ($showsections) {
5801: foreach my $role (@current) {
5802: if ($role =~ /:/) {
5803: my ($trole,$sec) = split(':',$role);
5804: push(@curr_roles,$trole);
5805: if (ref($currsec{$trole}) eq 'ARRAY') {
5806: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5807: push(@{$currsec{$trole}},$sec);
5808: }
1.3 raeburn 5809: } else {
5810: $currsec{$trole} = [$sec];
1.1 raeburn 5811: }
5812: } else {
5813: push(@curr_roles,$role);
5814: }
5815: }
5816: @current = @curr_roles;
5817: }
5818: }
5819: }
5820: my $numinrow = 3;
5821: my $count = 0;
1.80 raeburn 5822: my $disabled;
5823: if ($noedit) {
5824: $disabled = ' disabled="disabled"';
5825: }
1.1 raeburn 5826: foreach my $role (@roles) {
5827: my $checked = '';
5828: if (grep(/^\Q$role\E$/,@current)) {
5829: $checked = ' checked="checked" ';
5830: }
1.9 raeburn 5831: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5832: if ($showsections) {
5833: $output .= &Apache::loncommon::start_data_table_row();
5834: } else {
5835: my $rem = $count%($numinrow);
5836: if ($rem == 0) {
5837: if ($count > 0) {
5838: $output .= '</tr>';
5839: }
5840: $output .= '<tr>';
5841: }
5842: }
1.30 raeburn 5843: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5844: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5845: $plrole.'</label></span></td>';
5846: if ($showsections) {
5847: $output .= '<td align="left">'.
1.80 raeburn 5848: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5849: '</td></tr>';
5850: }
5851: $count ++;
5852: }
5853: my %adv_roles =
5854: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5855: my $total = @roles;
5856: foreach my $role (sort(keys(%adv_roles))) {
5857: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5858: my $rolename = $3;
5859: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5860: my $checked = '';
5861: if (grep(/^\Q$value\E$/,@current)) {
5862: $checked = ' checked="checked" ';
5863: }
5864: if ($showsections) {
5865: $output .= &Apache::loncommon::start_data_table_row();
5866: } else {
5867: my $rem = $count%($numinrow);
5868: if ($rem == 0) {
5869: if ($count > 0) {
5870: $output .= '</tr>';
5871: }
5872: $output .= '<tr>';
5873: }
5874: }
1.30 raeburn 5875: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5876: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5877: '</label></span></td>';
5878: if ($showsections) {
5879: $output .= '<td>'.
1.80 raeburn 5880: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5881: '</td>'.&Apache::loncommon::end_data_table_row();
5882: }
5883: $total ++;
5884: $count ++;
5885: }
5886: }
5887: if (!$showsections) {
5888: my $rem = $total%($numinrow);
5889: my $colsleft = $numinrow - $rem;
5890: if ($colsleft > 1 ) {
5891: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5892: ' </td>';
5893: } elsif ($colsleft == 1) {
5894: $output .= '<td class="LC_left_item"> </td>';
5895: }
5896: $output .= '</tr>';
5897: }
5898: return $output;
5899: }
5900:
1.50 raeburn 5901: sub set_discussion_fonts {
1.80 raeburn 5902: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 5903: my ($classorder,$classtitles) = &discussion_vote_classes();
5904: my ($styleorder,$styleitems) = &discussion_vote_styles();
5905: my $output;
5906: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 5907: my $disabled;
5908: if ($noedit) {
5909: $disabled = ' disabled="disabled"';
5910: }
1.50 raeburn 5911: foreach my $cat (@{$classorder}) {
5912: my %curr = ();
5913: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5914: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5915: $output .= &Apache::loncommon::start_data_table_row().
5916: '<td>'.$classtitles->{$cat}.'</td>';
5917: if (ref($styleorder) eq 'ARRAY') {
5918: foreach my $item (@{$styleorder}) {
5919: $output .= '<td><span class="LC_nobreak">';
5920: my $selitem = $item;
5921: if ($item eq 'size') {
5922: my ($currsize,$currunit);
5923: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5924: ($currsize,$currunit) = ($1,$2);
5925: $curr{'size'} = $currunit;
5926: }
1.81 raeburn 5927: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 5928: ' ';
5929: $selitem = 'unit';
5930: }
5931: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 5932: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 5933: foreach my $val (@{$styleitems->{$item}}) {
5934: my $sel;
5935: if ($val eq $curr{$item}) {
5936: $sel = ' selected="selected"';
5937: }
5938: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
5939: }
5940: }
5941: }
5942: }
1.80 raeburn 5943: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 5944: }
5945: $output .= &Apache::loncommon::end_data_table_row();
5946: }
5947: return $output;
5948: }
5949:
5950: sub discussion_vote_classes {
5951: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
5952: my %classtitles = &Apache::lonlocal::texthash(
5953: 'twoplus' => 'Two sigma above mean',
5954: 'oneplus' => 'One sigma above mean',
5955: 'zero' => 'Within one sigma of mean',
5956: 'oneminus' => 'One sigma below mean',
5957: 'twominus' => 'Two sigma below mean',
5958: );
5959: return ($classorder,\%classtitles);
5960: }
5961:
5962: sub discussion_vote_styles {
5963: my $styleorder = ['size','weight','style'];
5964: my $styleitems = {
5965: size => ['','px','%','xx-small','x-small','small','medium','large',
5966: 'x-large','xx-large','smaller','larger'],
5967: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
5968: '500','600','700','800','900'],
5969: style => ['','normal','italic','oblique'],
5970: };
5971: return ($styleorder,$styleitems);
5972: }
5973:
1.1 raeburn 5974: sub print_classlists {
1.80 raeburn 5975: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5976: my @ordered;
5977: if ($position eq 'top') {
5978: @ordered = ('default_enrollment_start_date',
5979: 'default_enrollment_end_date');
1.55 raeburn 5980: if ($crstype eq 'Course') {
5981: push(@ordered,'defaultcredits');
5982: }
1.1 raeburn 5983: } elsif ($position eq 'middle') {
1.56 raeburn 5984: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 5985: } else {
5986: @ordered = ('student_classlist_view',
1.26 raeburn 5987: 'student_classlist_opt_in',
5988: 'student_classlist_portfiles');
1.1 raeburn 5989: }
1.9 raeburn 5990: my %lt;
5991:
5992: if ($crstype eq 'Community') {
5993: %lt = &Apache::lonlocal::texthash (
5994: disabled => 'No viewable membership list',
5995: section => "Membership of viewer's section",
5996: all => 'List of all members',
5997: );
5998: } else {
5999: %lt = &Apache::lonlocal::texthash (
6000: disabled => 'No viewable classlist',
6001: section => "Classlist of viewer's section",
6002: all => 'Classlist of all students',
6003: );
6004: }
6005:
1.1 raeburn 6006: my %items = (
6007: 'default_enrollment_start_date' => {
1.3 raeburn 6008: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 6009: input => 'dates',
6010: },
6011: 'default_enrollment_end_date' => {
1.3 raeburn 6012: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 6013: input => 'dates',
6014: },
1.55 raeburn 6015: 'defaultcredits' => {
6016: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
6017: },
6018:
1.1 raeburn 6019: 'nothideprivileged' => {
1.3 raeburn 6020: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 6021: input => 'checkbox',
6022: },
6023:
1.56 raeburn 6024: 'checkforpriv' => {
6025: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
6026: input => 'selectbox',
6027: },
6028:
1.1 raeburn 6029: 'student_classlist_view' => {
1.3 raeburn 6030: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 6031: input => 'selectbox',
1.9 raeburn 6032: options => \%lt,
1.1 raeburn 6033: order => ['disabled','all','section'],
6034: },
1.26 raeburn 6035: 'student_classlist_opt_in' => {
6036: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 6037: input => 'radio',
6038: },
6039:
6040: 'student_classlist_portfiles' => {
1.3 raeburn 6041: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 6042: input => 'radio',
6043: },
6044: );
6045: unless (($settings->{'student_classlist_view'} eq 'all') ||
6046: ($settings->{'student_classlist_view'} eq 'section')) {
6047: $settings->{'student_classlist_view'} = 'disabled';
6048: }
1.80 raeburn 6049: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6050: }
6051:
6052: sub print_appearance {
1.80 raeburn 6053: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6054: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6055: return;
6056: }
1.9 raeburn 6057: my $mathdef;
6058: if ($crstype eq 'Community') {
6059: $mathdef = &mt("None specified - use member's choice");
6060: } else {
6061: $mathdef = &mt("None specified - use student's choice");
6062: }
1.1 raeburn 6063: my %items = (
6064: 'default_xml_style' => {
1.3 raeburn 6065: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6066: '<a href="javascript:openbrowser'.
6067: "('display','default_xml_style'".
6068: ",'sty')".'">'.&mt('Select Style File').'</a>',
6069: input => 'textbox',
6070: size => 35,
6071: },
6072:
6073: 'pageseparators' => {
1.3 raeburn 6074: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6075: input => 'radio',
6076: },
6077: 'disable_receipt_display' => {
1.3 raeburn 6078: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6079: input => 'radio',
6080: },
6081: 'texengine' => {
1.3 raeburn 6082: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6083: input => 'selectbox',
6084: options => {
1.61 raeburn 6085: MathJax => 'MathJax',
1.1 raeburn 6086: mimetex => &mt('Convert to Images'),
6087: tth => &mt('TeX to HTML'),
6088: },
1.75 raeburn 6089: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6090: nullval => $mathdef,
1.1 raeburn 6091: },
6092: 'tthoptions' => {
1.3 raeburn 6093: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6094: input => 'textbox',
6095: size => 40,
6096: },
1.69 raeburn 6097: 'uselcmath' => {
6098: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6099: input => 'radio',
6100: },
6101: 'usejsme' => {
6102: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6103: input => 'radio',
6104: },
1.95 raeburn 6105: 'inline_chem' => {
6106: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6107: input => 'radio',
6108: },
1.114 raeburn 6109: 'extresource' => {
6110: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6111: input => 'selectbox',
6112: options => {
6113: iframe => 'In iframe',
6114: tab => 'In new tab',
6115: window => 'In pop-up window',
6116: },
6117: order => ['iframe','tab','window'],
6118: },
1.1 raeburn 6119: );
1.80 raeburn 6120: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6121: }
6122:
6123: sub print_grading {
1.80 raeburn 6124: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6125: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6126: return;
6127: }
6128: my %items = (
6129: 'grading' => {
1.3 raeburn 6130: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6131: &Apache::loncommon::help_open_topic('GradingOptions'),
6132: input => 'selectbox',
6133: options => {
6134: standard => &mt('Standard: shows points'),
1.34 www 6135: categories => &mt('Categories: shows points according to categories'),
1.11 www 6136: external => &mt('External: shows number of completed parts and totals'),
6137: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6138: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6139: },
1.34 www 6140: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6141: },
6142: 'rndseed' => {
1.3 raeburn 6143: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 6144: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 6145: &mt('Modifying this will make problems have different numbers and answers!').
6146: '</span>',
6147: input => 'selectbox',
6148: options => {
6149: '32bit' => '32bit',
6150: '64bit' => '64bit',
6151: '64bit2' => '64bit2',
6152: '64bit3' => '64bit3',
6153: '64bit4' => '64bit4',
6154: '64bit5' => '64bit5',
6155: },
6156: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6157: advanced => 1
1.1 raeburn 6158: },
6159: 'receiptalg' => {
1.3 raeburn 6160: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6161: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6162: input => 'selectbox',
6163: options => {
6164: receipt => 'receipt',
6165: receipt2 => 'receipt2',
6166: receipt3 => 'receipt3',
6167: },
6168: order => ['receipt','receipt2','receipt3'],
1.41 www 6169: advanced => 1
1.1 raeburn 6170: },
6171: 'disablesigfigs' => {
1.3 raeburn 6172: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6173: input => 'radio',
6174: },
6175: );
1.80 raeburn 6176: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
1.1 raeburn 6177: }
6178:
6179: sub print_printouts {
1.80 raeburn 6180: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6181: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6182: return;
6183: }
6184: my %items = (
6185: problem_stream_switch => {
1.3 raeburn 6186: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6187: input => 'radio',
6188: },
6189: suppress_tries => {
1.3 raeburn 6190: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6191: input => 'radio',
6192: },
6193: default_paper_size => {
1.3 raeburn 6194: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6195: input => 'selectbox',
6196: options => {
6197: Letter => &mt('Letter').' [8 1/2x11 in]',
6198: Legal => &mt('Legal').' [8 1/2x14 in]',
6199: Tabloid => &mt('Tabloid').' [11x17 in]',
6200: Executive => &mt('Executive').' [7 1/2x10 in]',
6201: A2 => &mt('A2').' [420x594 mm]',
6202: A3 => &mt('A3').' [297x420 mm]',
6203: A4 => &mt('A4').' [210x297 mm]',
6204: A5 => &mt('A5').' [148x210 mm]',
6205: A6 => &mt('A6').' [105x148 mm]',
6206: },
6207: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6208: nullval => &mt('None specified'),
1.1 raeburn 6209: },
6210: print_header_format => {
1.3 raeburn 6211: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6212: input => 'checkbox',
6213: },
6214: disableexampointprint => {
1.3 raeburn 6215: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6216: input => 'radio',
6217: },
1.14 raeburn 6218: canuse_pdfforms => {
6219: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6220: input => 'selectbox',
6221: options => {
6222: 1 => &mt('Yes'),
6223: 0 => &mt('No'),
6224: },
6225: order => ['1','0'],
1.54 bisitz 6226: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6227: }
1.1 raeburn 6228: );
1.80 raeburn 6229: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6230: }
6231:
6232: sub print_spreadsheet {
1.80 raeburn 6233: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6234: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6235: return;
6236: }
6237: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6238: my %items = (
6239: spreadsheet_default_classcalc => {
1.3 raeburn 6240: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6241: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6242: "('display','spreadsheet_default_classcalc'".
6243: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6244: input => 'textbox',
6245: },
6246: spreadsheet_default_studentcalc => {
1.3 raeburn 6247: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6248: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6249: "('display','spreadsheet_default_calc'".
6250: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6251: input => 'textbox',
6252: },
6253: spreadsheet_default_assesscalc => {
1.3 raeburn 6254: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6255: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6256: "('display','spreadsheet_default_assesscalc'".
6257: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6258: input => 'textbox',
6259: },
6260: hideemptyrows => {
1.3 raeburn 6261: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6262: input => 'radio',
6263: },
6264: );
1.80 raeburn 6265: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6266: }
1.1 raeburn 6267:
6268: sub print_bridgetasks {
1.80 raeburn 6269: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6270: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6271: return;
6272: }
1.9 raeburn 6273: my ($stumsg,$msgnote);
6274: if ($crstype eq 'Community') {
6275: $stumsg = &mt('Send message to member');
6276: $msgnote = &mt('Message to member and add to user notes');
6277: } else {
6278: $stumsg = &mt('Send message to student');
6279: $msgnote = &mt('Message to student and add to user notes');
6280: }
1.1 raeburn 6281: my %items = (
6282: task_messages => {
1.3 raeburn 6283: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6284: input => 'selectbox',
6285: options => {
1.9 raeburn 6286: only_student => $stumsg,
6287: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6288: },
6289: order => ['only_student','student_and_user_notes_screen'],
6290: nullval => &mt('No message or record in user notes'),
6291: },
6292: task_grading => {
1.3 raeburn 6293: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6294: input => 'selectbox',
6295: options => {
6296: any => &mt('Grade BTs in any section'),
6297: section => &mt('Grade BTs only in own section')
6298: },
6299: order => ['any','section'],
6300: },
6301: suppress_embed_prompt => {
1.3 raeburn 6302: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6303: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6304: input => 'radio',
6305: },
6306: );
1.80 raeburn 6307: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6308: }
6309:
1.118 raeburn 6310: sub print_ltitools {
6311: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6312: my ($datatable,$disabled,$css_class,$dest);
1.121 ! raeburn 6313: if ($noedit) {
! 6314: $disabled = ' disabled="disabled"';
! 6315: }
1.120 raeburn 6316: my $itemcount = 1;
6317: unless ($context eq 'domain') {
6318: my %tooltypes = &Apache::loncommon::usable_exttools();
6319: unless ($tooltypes{'crs'}) {
6320: my $showtype = 'course';
6321: if ($crstype eq 'Community') {
6322: $showtype = lc($crstype);
6323: }
6324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6325: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6326: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6327: if ($tooltypes{'dom'}) {
6328: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6329: '<i>'.$cdom.'</i>').
6330: '<br /><br />'.
6331: &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.");
6332: } else {
6333: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6334: '<br /><br />'.
6335: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6336: '<i>'.$cdom.'</i>');
6337:
6338: }
6339: $datatable .= '</tr>';
6340: $itemcount ++;
6341: return $datatable;
6342: }
6343: }
1.118 raeburn 6344: my %lt = <itools_names();
6345: my $maxnum = 0;
6346: my %ordered;
6347: if (ref($settings) eq 'HASH') {
6348: foreach my $item (keys(%{$settings})) {
6349: if (ref($settings->{$item}) eq 'HASH') {
6350: my $num = $settings->{$item}{'order'};
6351: $ordered{$num} = $item;
6352: }
6353: }
6354: }
6355:
6356: if ($context eq 'domain') {
6357: $dest = '/adm/domainprefs';
6358: } else {
6359: $dest = '/adm/courseprefs';
6360: }
6361: my ($switchserver,$switchmessage);
6362: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6363: if ($switchserver) {
6364: if ($context eq 'domain') {
6365: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6366: } elsif ($crstype eq 'Community') {
6367: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6368: } else {
6369: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6370: }
6371: }
6372: my $maxnum = scalar(keys(%ordered));
6373: my @courseroles = ('cc','in','ta','ep','st');
6374: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6375: my @fields = ('fullname','firstname','lastname','email','roles','user');
6376: if (keys(%ordered)) {
6377: my @items = sort { $a <=> $b } keys(%ordered);
6378: for (my $i=0; $i<@items; $i++) {
6379: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6380: my $item = $ordered{$items[$i]};
6381: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6382: if (ref($settings->{$item}) eq 'HASH') {
6383: $title = $settings->{$item}->{'title'};
6384: $url = $settings->{$item}->{'url'};
6385: $key = $settings->{$item}->{'key'};
6386: $usable = $settings->{$item}->{'usable'};
6387: $lifetime = $settings->{$item}->{'lifetime'};
6388: my $image = $settings->{$item}->{'image'};
6389: if ($image ne '') {
6390: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6391: }
6392: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6393: $sigsel{'HMAC-256'} = ' selected="selected"';
6394: } else {
6395: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6396: }
6397: }
6398: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6399: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6400: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6401: for (my $k=0; $k<=$maxnum; $k++) {
6402: my $vpos = $k+1;
6403: my $selstr;
6404: if ($k == $i) {
6405: $selstr = ' selected="selected" ';
6406: }
6407: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6408: }
6409: $datatable .= '</select>'.(' 'x2).
6410: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6411: &mt('Delete?').'</label></span></td>'.
6412: '<td colspan="2">'.
6413: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6414: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6415: (' 'x2).
6416: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6417: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6418: (' 'x2).
6419: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6420: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6421: (' 'x2).
6422: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6423: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6424: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6425: '<br /><br />'.
1.120 raeburn 6426: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6427: ' value="'.$url.'" /></span>'.
6428: (' 'x2).
6429: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6430: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6431: if ($key ne '') {
6432: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6433: if ($noedit) {
6434: $datatable .= ': ['.&mt('not shown').']';
6435: } elsif ($switchserver) {
6436: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6437: } else {
6438: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6439: }
6440: $datatable .= '</span> '.(' 'x2);
6441: } elsif (!$switchserver) {
6442: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6443: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6444: '</span> '.(' 'x2);
6445: }
6446: if ($switchserver) {
6447: if ($usable ne '') {
6448: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6449: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6450: '<span class="LC_nobreak">'.&mt('Change secret?').
6451: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6452: (' 'x2).
6453: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6454: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6455: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6456: '</div>';
6457: } elsif ($key eq '') {
6458: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6459: } else {
6460: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6461: }
6462: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6463: } else {
6464: if ($usable ne '') {
6465: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6466: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6467: '<span class="LC_nobreak">'.&mt('Change?').
6468: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6469: (' 'x2).
6470: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6471: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6472: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6473: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6474: '<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>'.
6475: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6476: } else {
6477: $datatable .=
6478: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6479: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6480: '<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>'.
6481: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6482: }
6483: }
6484: $datatable .= '</fieldset>'.
6485: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6486: '<span class="LC_nobreak">'.&mt('Display target:');
6487: my %currdisp;
6488: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6489: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6490: $currdisp{'window'} = ' checked="checked"';
6491: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6492: $currdisp{'tab'} = ' checked="checked"';
6493: } else {
6494: $currdisp{'iframe'} = ' checked="checked"';
6495: }
6496: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6497: $currdisp{'width'} = $1;
6498: }
6499: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6500: $currdisp{'height'} = $1;
6501: }
6502: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6503: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6504: } else {
6505: $currdisp{'iframe'} = ' checked="checked"';
6506: }
6507: foreach my $disp ('iframe','tab','window') {
6508: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6509: $lt{$disp}.'</label>'.(' 'x2);
6510: }
6511: $datatable .= (' 'x4);
6512: foreach my $dimen ('width','height') {
6513: $datatable .= '<label>'.$lt{$dimen}.' '.
6514: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6515: (' 'x2);
6516: }
6517: $datatable .= '</span><br />'.
6518: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6519: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6520: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6521: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6522: '</textarea></div><div style=""></div><br />';
6523: my %units = (
6524: 'passback' => 'days',
6525: 'roster' => 'seconds',
6526: );
6527: foreach my $extra ('passback','roster') {
6528: my $validsty = 'none';
6529: my $currvalid;
6530: my $checkedon = '';
6531: my $checkedoff = ' checked="checked"';
6532: if ($settings->{$item}->{$extra}) {
6533: $checkedon = $checkedoff;
6534: $checkedoff = '';
6535: $validsty = 'inline-block';
6536: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6537: $currvalid = $settings->{$item}->{$extra.'valid'};
6538: }
6539: }
6540: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6541: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6542: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6543: &mt('No').'</label>'.(' 'x2).
6544: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6545: &mt('Yes').'</label></span></div>'.
6546: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6547: '<span class="LC_nobreak">'.
6548: &mt("until at least [_1] $units{$extra} after launch",
6549: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6550: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6551: }
6552: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6553: if ($imgsrc) {
6554: $datatable .= $imgsrc.
6555: '<label><input type="checkbox" name="ltitools_image_del"'.
6556: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6557: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6558: } else {
6559: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6560: }
6561: if ($switchserver) {
6562: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6563: } else {
6564: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6565: }
6566: $datatable .= '</span></fieldset>';
6567: my (%checkedfields,%rolemaps,$userincdom);
6568: if (ref($settings->{$item}) eq 'HASH') {
6569: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6570: %checkedfields = %{$settings->{$item}->{'fields'}};
6571: }
6572: $userincdom = $settings->{$item}->{'incdom'};
6573: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6574: %rolemaps = %{$settings->{$item}->{'roles'}};
6575: $checkedfields{'roles'} = 1;
6576: }
6577: }
6578: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6579: '<span class="LC_nobreak">';
6580: my $userfieldstyle = 'display:none;';
6581: my $seluserdom = '';
6582: my $unseluserdom = ' selected="selected"';
6583: foreach my $field (@fields) {
6584: my ($checked,$onclick,$id,$spacer);
6585: if ($checkedfields{$field}) {
6586: $checked = ' checked="checked"';
6587: }
6588: if ($field eq 'user') {
6589: $id = ' id="ltitools_user_field_'.$i.'"';
6590: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6591: if ($checked) {
6592: $userfieldstyle = 'display:inline-block';
6593: if ($userincdom) {
6594: $seluserdom = $unseluserdom;
6595: $unseluserdom = '';
6596: }
6597: }
6598: } else {
6599: $spacer = (' ' x2);
6600: }
6601: $datatable .= '<label>'.
6602: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6603: $lt{$field}.'</label>'.$spacer;
6604: }
6605: $datatable .= '</span>';
6606: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6607: '<span class="LC_nobreak"> : '.
6608: '<select name="ltitools_userincdom_'.$i.'">'.
6609: '<option value="">'.&mt('Select').'</option>'.
6610: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6611: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6612: '</select></span></div>';
6613: $datatable .= '</fieldset>'.
6614: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6615: foreach my $role (@courseroles) {
6616: my ($selected,$selectnone);
6617: if (!$rolemaps{$role}) {
6618: $selectnone = ' selected="selected"';
6619: }
6620: $datatable .= '<td style="text-align: center">'.
6621: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6622: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6623: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6624: foreach my $ltirole (@ltiroles) {
6625: unless ($selectnone) {
6626: if ($rolemaps{$role} eq $ltirole) {
6627: $selected = ' selected="selected"';
6628: } else {
6629: $selected = '';
6630: }
6631: }
6632: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6633: }
6634: $datatable .= '</select></td>';
6635: }
6636: $datatable .= '</tr></table></fieldset>';
6637: my %courseconfig;
6638: if (ref($settings->{$item}) eq 'HASH') {
6639: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6640: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6641: }
6642: }
6643: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6644: foreach my $item ('label','title','target','linktext','explanation','append') {
6645: my $checked;
6646: if ($courseconfig{$item}) {
6647: $checked = ' checked="checked"';
6648: }
6649: $datatable .= '<label>'.
6650: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6651: $lt{'crs'.$item}.'</label> '."\n";
6652: }
6653: $datatable .= '</span></fieldset>'.
6654: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6655: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6656: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6657: my %custom = %{$settings->{$item}->{'custom'}};
6658: if (keys(%custom) > 0) {
6659: foreach my $key (sort(keys(%custom))) {
6660: $datatable .= '<tr><td><span class="LC_nobreak">'.
6661: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6662: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6663: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6664: ' value="'.$custom{$key}.'" /></td></tr>';
6665: }
6666: }
6667: }
6668: $datatable .= '<tr><td><span class="LC_nobreak">'.
6669: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6670: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6671: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6672: $datatable .= '</table></fieldset></td></tr>'."\n";
6673: $itemcount ++;
6674: }
6675: }
6676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6677: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6678: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6679: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6680: '<select name="ltitools_add_pos"'.$chgstr.'>';
6681: for (my $k=0; $k<$maxnum+1; $k++) {
6682: my $vpos = $k+1;
6683: my $selstr;
6684: if ($k == $maxnum) {
6685: $selstr = ' selected="selected" ';
6686: }
6687: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6688: }
6689: $datatable .= '</select> '."\n".
6690: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6691: '<td colspan="2">'.
6692: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6693: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6694: (' 'x2).
6695: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6696: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6697: (' 'x2).
6698: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6699: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6700: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6701: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6702: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6703: '<br />'.
1.120 raeburn 6704: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6705: (' 'x2).
6706: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6707: if ($switchserver) {
6708: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6709: } else {
6710: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6711: (' 'x2).
1.119 raeburn 6712: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6713: '<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 6714: }
6715: $datatable .= '<br /><br />'.
6716: '</fieldset>'.
6717: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6718: '<span class="LC_nobreak">'.&mt('Display target:');
6719: my %defaultdisp;
6720: $defaultdisp{'iframe'} = ' checked="checked"';
6721: foreach my $disp ('iframe','tab','window') {
6722: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6723: $lt{$disp}.'</label>'.(' 'x2);
6724: }
6725: $datatable .= (' 'x4);
6726: foreach my $dimen ('width','height') {
6727: $datatable .= '<label>'.$lt{$dimen}.' '.
6728: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6729: (' 'x2);
6730: }
6731: $datatable .= '</span><br />'.
6732: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6733: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6734: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6735: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6736: '</div><div style=""></div><br />';
6737: my %units = (
6738: 'passback' => 'days',
6739: 'roster' => 'seconds',
6740: );
6741: my %defaulttimes = (
6742: 'passback' => '7',
6743: 'roster' => '300',
6744: );
6745: foreach my $extra ('passback','roster') {
6746: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6747: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6748: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6749: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6750: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6751: &mt('Yes').'</label></span></div>'.
6752: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6753: '<span class="LC_nobreak">'.
6754: &mt("until at least [_1] $units{$extra} after launch",
6755: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6756: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6757: }
6758: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6759: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6760: if ($switchserver) {
6761: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6762: } else {
6763: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6764: }
6765: $datatable .= '</span></fieldset>'.
6766: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6767: '<span class="LC_nobreak">';
6768: foreach my $field (@fields) {
6769: my ($id,$onclick,$spacer);
6770: if ($field eq 'user') {
6771: $id = ' id="ltitools_user_field_add"';
6772: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6773: } else {
6774: $spacer = (' ' x2);
6775: }
6776: $datatable .= '<label>'.
6777: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6778: $lt{$field}.'</label>'.$spacer;
6779: }
6780: $datatable .= '</span>'.
6781: '<div style="display:none;" id="ltitools_user_div_add">'.
6782: '<span class="LC_nobreak"> : '.
6783: '<select name="ltitools_add_userincdom">'.
6784: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6785: '<option value="0">'.&mt('username').'</option>'.
6786: '<option value="1">'.&mt('username:domain').'</option>'.
6787: '</select></span></div></fieldset>';
6788: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6789: foreach my $role (@courseroles) {
6790: my ($checked,$checkednone);
6791: $datatable .= '<td style="text-align: center">'.
6792: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6793: '<select name="ltitools_add_roles_'.$role.'">'.
6794: '<option value="" selected="selected">'.&mt('Select').'</option>';
6795: foreach my $ltirole (@ltiroles) {
6796: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6797: }
6798: $datatable .= '</select></td>';
6799: }
6800: $datatable .= '</tr></table></fieldset>'.
6801: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6802: foreach my $item ('label','title','target','linktext','explanation','append') {
6803: $datatable .= '<label>'.
6804: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6805: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6806: }
6807: $datatable .= '</span></fieldset>'.
6808: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6809: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6810: '<tr><td><span class="LC_nobreak">'.
6811: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6812: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6813: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6814: '</table></fieldset>'."\n".
6815: '</td>'."\n".
6816: '</tr>'."\n";
6817: $itemcount ++;
6818: return $datatable;
6819: }
6820:
6821: sub ltitools_names {
6822: my %lt = &Apache::lonlocal::texthash(
6823: 'title' => 'Title',
6824: 'version' => 'Version',
6825: 'msgtype' => 'Message Type',
6826: 'sigmethod' => 'Signature Method',
6827: 'url' => 'URL',
6828: 'key' => 'Key',
6829: 'lifetime' => 'Nonce lifetime (s)',
6830: 'secret' => 'Secret',
6831: 'icon' => 'Icon',
6832: 'user' => 'User',
6833: 'fullname' => 'Full Name',
6834: 'firstname' => 'First Name',
6835: 'lastname' => 'Last Name',
6836: 'email' => 'E-mail',
6837: 'roles' => 'Role',
6838: 'window' => 'Window',
6839: 'tab' => 'Tab',
6840: 'iframe' => 'iFrame',
6841: 'height' => 'Height',
6842: 'width' => 'Width',
6843: 'linktext' => 'Default Link Text',
6844: 'explanation' => 'Default Explanation',
6845: 'passback' => 'Tool can return grades:',
6846: 'roster' => 'Tool can retrieve roster:',
6847: 'crstarget' => 'Display target',
6848: 'crslabel' => 'Course label',
6849: 'crstitle' => 'Course title',
6850: 'crslinktext' => 'Link Text',
6851: 'crsexplanation' => 'Explanation',
6852: 'crsappend' => 'Provider URL',
6853: );
6854: return %lt;
6855: }
6856:
1.87 raeburn 6857: sub print_lti {
6858: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6859: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6860: return;
6861: }
6862: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6863: my %menutitles = <imenu_titles();
6864: my ($domdefs,$displaydefs);
6865: if ($env{'request.lti.login'}) {
6866: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6867: my @domdefsmenu;
6868: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6869: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6870: $domdefs = &mt('Header shown').', ';
6871: }
6872: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6873: $domdefs .= &mt('Inline menu shown');
6874: }
6875: $domdefs =~ s/,\s$//;
6876: if (!$domdefs) {
6877: $domdefs = &mt('No header or inline menu shown');
6878: }
6879: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
6880: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6881: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6882: }
6883: }
6884: $displaydefs = &mt('Domain defaults');
6885: if (@domdefsmenu) {
6886: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
6887: if (@diffs) {
6888: my $missing;
6889: foreach my $item (@menuitems) {
6890: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
6891: $missing .= ' '.$menutitles{$item}.',';
6892: }
6893: }
6894: $missing =~ s/,$//;
6895: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
6896: } else {
6897: $displaydefs .= ': '.&mt('All shown');
6898: }
6899: } else {
6900: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
6901: }
6902: } else {
6903: $displaydefs = &mt('Domain defaults only available in LTI context');
6904: }
6905: my %items = (
6906: 'lti.override' => {
6907: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
6908: input => 'radio',
6909: },
6910: 'lti.topmenu' => {
6911: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
6912: input => 'radio',
6913: },
6914: 'lti.inlinemenu' => {
6915: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
6916: input => 'radio',
6917: },
6918: 'lti.lcmenu' => {
6919: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
6920: input => 'custom',
6921: },
6922: );
6923: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
6924: }
6925:
6926: sub lcmenu_checkboxes {
6927: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
6928: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6929: my %menutitles = <imenu_titles();
6930: my (@current,@domdefs);
6931: if ($env{'request.lti.login'}) {
6932: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6933: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6934: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6935: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6936: }
6937: }
6938: }
6939: if (ref($settings) eq 'HASH') {
6940: if ($settings->{'lti.lcmenu'}) {
6941: unless ($settings->{'lti.lcmenu'} eq 'none') {
6942: @current = split(',',$settings->{'lti.lcmenu'});
6943: }
6944: } else {
6945: @current = @domdefs;
6946: }
6947: } else {
6948: @current = @domdefs;
6949: }
6950: my $numinrow = 3;
6951: my $count = 0;
6952: my $disabled;
6953: if ($noedit) {
6954: $disabled = ' disabled="disabled"';
6955: }
6956: my $output = '<table>';
6957: foreach my $item (@menuitems) {
6958: my $checked = '';
6959: if (grep(/^\Q$item\E$/,@current)) {
6960: $checked = ' checked="checked" ';
6961: }
6962: my $rem = $count%($numinrow);
6963: if ($rem == 0) {
6964: if ($count > 0) {
6965: $output .= '</tr>';
6966: }
6967: $output .= '<tr>';
6968: }
6969: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
6970: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
6971: $menutitles{$item}.'</label></span></td>';
6972: $count ++;
6973: }
6974: my $rem = $count%($numinrow);
6975: my $colsleft = $numinrow - $rem;
6976: if ($colsleft > 1 ) {
6977: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6978: ' </td>';
6979: } elsif ($colsleft == 1) {
6980: $output .= '<td class="LC_left_item"> </td>';
6981: }
6982: $output .= '</tr></table>';
6983: }
6984:
6985: sub ltimenu_titles {
6986: return &Apache::lonlocal::texthash(
6987: fullname => 'Full name',
6988: coursetitle => 'Course title',
6989: role => 'Role',
6990: logout => 'Logout',
6991: grades => 'Grades',
6992: );
6993: }
6994:
1.91 raeburn 6995: sub print_menuitems {
6996: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6997: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
6998: return;
6999: }
7000: if ($position eq 'top') {
7001: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
7002: if ($settings->{'menucollections'} ne '') {
7003: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7004: my ($num,$value) = split(/\%/,$item);
7005: if ($num =~ /^\d+$/) {
7006: $defaultmenu_options{$num} = $num;
7007: }
7008: }
7009: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
7010: $addcollection = $defaultmenu_order[-1] + 1;
7011: } else {
7012: $addcollection = 1;
7013: }
7014: $defaultmenu_options{$addcollection} = $addcollection;
7015: my %items = (
7016: 'menudefault' => {
7017: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
7018: &mt("(can be overriden in deep-link context)"),
7019: input => 'selectbox',
7020: options => \%defaultmenu_options,
7021: order => \@defaultmenu_order,
7022: nullval => &mt('Standard (all menus shown)'),
7023: },
7024: );
7025: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
7026: } else {
7027: my %menu;
7028: my $count = 0;
7029: my $next = 1;
7030: my ($datatable,$disabled);
7031: if ($noedit) {
7032: $disabled = ' disabled="disabled"';
7033: }
7034:
7035: my ($ordered,$cats) = &menuitems_categories();
7036: my @order = @{$ordered};
7037: my %categories = %{$cats};
7038: my %menutitles = &menuitems_titles();
7039: my %menufields = &menuitems_fields();
7040:
7041: if ($settings->{'menucollections'} ne '') {
7042: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7043: my ($num,$value) = split(/\%/,$item);
7044: if ($num =~ /^\d+$/) {
7045: my @entries = split(/\&/,$value);
7046: foreach my $entry (@entries) {
7047: my ($name,$fields) = split(/=/,$entry);
7048: $menu{$num}{$name} = $fields;
7049: }
7050: }
7051: }
7052: if (keys(%menu)) {
7053: my @current = sort { $a <=> $b } keys(%menu);
7054: $next += $current[-1];
7055: foreach my $num (@current) {
7056: my %checked;
7057: my $on = ' checked="checked"';
7058: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7059: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7060: if ($menu{$num}{$key} eq 'y') {
7061: $checked{$key} = $on;
7062: }
7063: } else {
7064: foreach my $field (split(/,/,$menu{$num}{$key})) {
7065: if (exists($menufields{$field})) {
7066: $checked{$field} = $on;
7067: }
7068: }
7069: }
7070: }
7071: if (ref($menu{$num}) eq 'HASH') {
7072: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7073: foreach my $category (@order) {
7074: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7075: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7076: if ($category eq 'text') {
7077: $datatable .= '<i>'.&mt('Header').'</i><br />';
7078: }
1.91 raeburn 7079: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7080: if ($field eq 'disc') {
7081: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7082: }
1.91 raeburn 7083: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7084: $menufields{$field}.'</label><br />';
7085: }
7086: $datatable .= '</fieldset>';
7087: }
7088: }
7089: $datatable .= &item_table_row_end();
7090: $count ++;
7091: }
7092: }
7093: }
7094: } elsif ($noedit) {
7095: my $text = &mt('No menu collections defined for this course.');
7096: $datatable .= &item_table_row_start($text,$count);
7097: }
7098: unless ($noedit) {
7099: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7100: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7101: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7102: foreach my $category (@order) {
7103: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7104: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7105: foreach my $field (@{$categories{$category}}) {
7106: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7107: $menufields{$field}.'</label><br />';
7108: }
7109: $datatable .= '</fieldset>';
7110: }
7111: }
7112: $datatable .= &item_table_row_end();
7113: $count ++;
7114: }
7115: return $datatable;
7116: }
7117: }
7118:
7119: sub menuitems_abbreviations {
7120: my %briefcats = (
7121: text => 'pt',
7122: links => 'p',
7123: list => 'ps',
7124: inline => 's',
7125: );
7126: return %briefcats;
7127: }
7128:
7129: sub menuitems_categories {
7130: my @order = ('shown','text','links','list','inline');
7131: my %categories = (
1.94 raeburn 7132: shown => ['top','inline','foot','main'],
7133: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7134: links => ['pers','logo','menu','comm','roles','help','logout'],
1.91 raeburn 7135: list => ['about','prefs','port','wish','anno','rss'],
7136: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7137: );
7138: return (\@order,\%categories);
7139: }
7140:
7141: sub menuitems_titles {
7142: return &Apache::lonlocal::texthash (
7143: shown => 'Hierarchy',
1.94 raeburn 7144: text => 'Text',
1.91 raeburn 7145: links => 'Header links',
7146: list => 'Drop-down list',
7147: inline => 'Inline links',
7148: );
7149: }
7150:
7151: sub menuitems_fields {
7152: return &Apache::lonlocal::texthash (
7153: top => 'Display header',
7154: inline => 'Display inline menu',
1.94 raeburn 7155: foot => 'Display footer',
1.91 raeburn 7156: main => 'Access to main menu',
1.92 raeburn 7157: pers => 'Personal',
7158: logo => 'LON-CAPA',
1.91 raeburn 7159: menu => 'Home',
7160: comm => 'Messages',
7161: roles => 'Roles/Courses',
7162: help => 'Help',
7163: logout => 'Logout',
7164: name => 'Fullname',
7165: crs => 'Course Title',
7166: role => 'Current Role',
1.94 raeburn 7167: disc => 'Discussion',
7168: fdbk => 'Feedback',
1.91 raeburn 7169: about => 'Information',
7170: prefs => 'Preferences',
7171: port => 'Portfolio',
7172: wish => 'Stored Links',
7173: anno => 'Calendar',
7174: rss => 'RSS Feeds',
7175: cont => 'Contents',
7176: grades => 'Grades',
7177: chat => 'Chat',
7178: people => 'People',
7179: groups => 'Groups',
7180: resv => 'Reservations',
7181: syll => 'Syllabus',
7182: feeds => 'Feeds',
7183: );
7184: }
7185:
7186: sub menucollections_display {
7187: my ($collections) = @_;
7188: my %menu;
7189: my ($ordered,$cats) = &menuitems_categories();
7190: my @order = @{$ordered};
7191: my %categories = %{$cats};
7192: my %menutitles = &menuitems_titles();
7193: my %menufields = &menuitems_fields();
7194: foreach my $item (split(/;/,$collections)) {
7195: my ($num,$value) = split(/\%/,$item);
7196: if ($num =~ /^\d+$/) {
7197: my @entries = split(/\&/,$value);
7198: foreach my $entry (@entries) {
7199: my ($name,$fields) = split(/=/,$entry);
7200: $menu{$num}{$name} = $fields;
7201: }
7202: }
7203: }
7204: my $output = '';
7205: if (keys(%menu)) {
7206: my @current = sort { $a <=> $b } keys(%menu);
7207: foreach my $num (@current) {
7208: my %checked;
7209: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7210: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7211: if ($menu{$num}{$key} eq 'y') {
7212: $checked{$key} = 1;
7213: }
7214: } else {
7215: foreach my $field (split(/,/,$menu{$num}{$key})) {
7216: if (exists($menufields{$field})) {
7217: $checked{$field} = 1;
7218: }
7219: }
7220: }
7221: }
7222: if (ref($menu{$num}) eq 'HASH') {
7223: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7224: foreach my $category (@order) {
7225: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7226: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7227: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7228: if ($category eq 'text') {
7229: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
7230: }
1.91 raeburn 7231: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7232: if ($field eq 'disc') {
7233: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7234: }
1.91 raeburn 7235: if ($checked{$field}) {
7236: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7237: } else {
7238: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7239: }
7240: $output .= '<br />';
7241: }
7242: $output .= '</fieldset>';
7243: }
7244: }
7245: $output .= '</fieldset>';
7246: }
7247: }
7248: }
7249: return $output;
7250: }
7251:
1.93 raeburn 7252: sub print_linkprotection {
1.102 raeburn 7253: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7254:
7255: my %linkprotection;
7256: my $count = 0;
7257: my $next = 1;
1.102 raeburn 7258: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7259: if ($noedit) {
7260: $disabled = ' disabled="disabled"';
7261: }
1.100 raeburn 7262: my %desc = &linkprot_names();
7263: my %lt = &Apache::lonlocal::texthash (
7264: 'requ' => 'Required settings',
7265: 'opti' => 'Optional settings',
7266: );
1.93 raeburn 7267: my $itemcount = 0;
7268:
1.100 raeburn 7269: my $ltiauth;
1.102 raeburn 7270: if ($context eq 'domain') {
7271: $ltiauth = 1;
7272: } else {
7273: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7274: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7275: } else {
7276: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7277: $ltiauth = $domdefs{'crsltiauth'};
7278: }
7279: }
7280: if ($context eq 'domain') {
7281: $dest = '/adm/domainprefs';
1.100 raeburn 7282: } else {
1.102 raeburn 7283: $dest = '/adm/courseprefs';
7284: }
7285:
7286: my ($switchserver,$switchmessage);
7287: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7288: if ($switchserver) {
7289: if ($context eq 'domain') {
7290: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
7291: } elsif ($crstype eq 'Community') {
7292: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7293: } else {
7294: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7295: }
1.100 raeburn 7296: }
1.99 raeburn 7297:
1.105 raeburn 7298: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7299: if (keys(%{$settings->{'linkprot'}})) {
7300: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7301: $next += $current[-1];
7302: for (my $i=0; $i<@current; $i++) {
7303: my $num = $current[$i];
7304: my %values;
1.102 raeburn 7305: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7306: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7307: } else {
7308: next;
7309: }
7310: my $selected;
7311: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7312: $selected = ' selected="selected"';
7313: }
7314: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7315: $datatable .=
7316: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7317: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7318: &mt('Delete?').'</label></span></td><td>';
1.112 raeburn 7319: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl);
1.100 raeburn 7320: if ($ltiauth) {
7321: $usersty = 'display:none';
1.112 raeburn 7322: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7323: %checkedrequser = (
7324: no => ' checked="checked"',
7325: yes => '',
7326: );
7327: if ($values{'requser'}) {
7328: $checkedrequser{'yes'} = $checkedrequser{'no'};
7329: $checkedrequser{'no'} = '';
7330: }
7331: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7332: if ($values{'requser'}) {
7333: $usersty = 'display:inline-block';
7334: }
7335: }
1.112 raeburn 7336: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7337: %checkedreturnurl = (
7338: no => ' checked="checked"',
7339: yes => '',
7340: );
7341: if ($values{'returnurl'} ne '') {
7342: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7343: $checkedreturnurl{'no'} = '';
7344: }
1.100 raeburn 7345: $datatable .=
7346: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7347: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7348: (' 'x2).
1.100 raeburn 7349: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7350: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7351: (' 'x2).
1.100 raeburn 7352: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7353: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7354: if ($values{'key'} ne '') {
1.100 raeburn 7355: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7356: if ($noedit) {
7357: $datatable .= ': ['.&mt('not shown').']';
7358: } elsif ($switchserver) {
7359: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7360: } else {
7361: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7362: }
7363: $datatable .= '</span> '.(' 'x2);
7364: } elsif (!$switchserver) {
1.100 raeburn 7365: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7366: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7367: '</span> '.(' 'x2);
7368: }
7369: if ($switchserver) {
7370: if ($values{'usable'} ne '') {
7371: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7372: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7373: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7374: '<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 7375: (' 'x2).
1.118 raeburn 7376: '<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 7377: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7378: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7379: '</div>';
7380: } elsif ($values{'key'} eq '') {
1.102 raeburn 7381: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7382: } else {
1.102 raeburn 7383: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7384: }
1.111 raeburn 7385: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7386: } else {
7387: if ($values{'usable'} ne '') {
7388: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7389: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7390: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7391: '<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 7392: (' 'x2).
1.118 raeburn 7393: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7394: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7395: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7396: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7397: '<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 7398: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7399: } else {
7400: $datatable .=
1.100 raeburn 7401: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7402: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7403: '<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 7404: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7405: }
7406: }
1.112 raeburn 7407: $datatable .= '<br /><br />'.
7408: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7409: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7410: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7411: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7412: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7413: ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7414: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7415: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7416: '</span></div> ';
1.100 raeburn 7417: if ($ltiauth) {
1.112 raeburn 7418: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7419: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7420: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7421: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7422: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7423: '</fieldset>'.
7424: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7425: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7426: '</fieldset>';
7427: }
1.99 raeburn 7428: $datatable .= '</td></tr>';
1.93 raeburn 7429: $itemcount ++;
7430: }
7431: }
7432: }
7433: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7434: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7435: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7436: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7437: '<td width="100%">';
1.112 raeburn 7438: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl);
1.100 raeburn 7439: if ($ltiauth) {
7440: $usersty = 'display:none';
1.112 raeburn 7441: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7442: %checkedrequser = (
7443: no => ' checked="checked"',
7444: yes => '',
7445: );
7446: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7447: }
1.112 raeburn 7448: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7449: %checkedreturnurl = (
7450: no => ' checked="checked"',
7451: yes => '',
7452: );
1.100 raeburn 7453: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7454: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7455: (' 'x2).
1.100 raeburn 7456: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7457: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7458: (' 'x2).
1.112 raeburn 7459: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7460: '<br /><br />';
1.99 raeburn 7461: if ($switchserver) {
1.102 raeburn 7462: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7463: } else {
1.100 raeburn 7464: $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 7465: (' 'x2).
1.116 raeburn 7466: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7467: '<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 7468: }
1.112 raeburn 7469: $datatable .= '<br /><br />'.
7470: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7471: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7472: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7473: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7474: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7475: ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7476: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7477: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7478: '</span></div> ';
7479: if ($ltiauth) {
7480: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7481: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7482: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7483: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7484: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7485: '</fieldset>'.
1.100 raeburn 7486: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7487: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7488: '</fieldset>';
7489: }
1.99 raeburn 7490: $datatable .= '</td></tr>';
1.93 raeburn 7491: $$rowtotal ++;
1.101 raeburn 7492: return $datatable;
1.93 raeburn 7493: }
7494:
7495: sub linkprot_names {
1.100 raeburn 7496: return &Apache::lonlocal::texthash(
1.93 raeburn 7497: 'version' => 'LTI Version',
7498: 'key' => 'Key',
7499: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7500: 'name' => 'Launcher Application',
1.93 raeburn 7501: 'secret' => 'Secret',
1.112 raeburn 7502: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7503: 'requser' => 'Use identity',
7504: 'email' => 'Email address',
7505: 'sourcedid' => 'User ID',
7506: 'other' => 'Other',
7507: 'auth' => 'Display LON-CAPA login page',
7508: 'reject' => 'Discontinue launch process',
1.93 raeburn 7509: );
7510: }
7511:
1.99 raeburn 7512: sub check_switchserver {
1.102 raeburn 7513: my ($cdom,$cnum,$context,$dest) = @_;
7514: my ($allowed,$switchserver,$home);
7515: if ($context eq 'domain') {
7516: $home = &Apache::lonnet::domain($cdom,'primary');
7517: } else {
7518: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7519: }
7520: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7521: my @ids=&Apache::lonnet::current_machine_ids();
7522: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7523: if (!$allowed) {
7524: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7525: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7526: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7527: }
7528: }
7529: return $switchserver;
7530: }
7531:
1.100 raeburn 7532: sub linkprot_options {
7533: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7534: my %lt;
7535: if (ref($desc) eq 'HASH') {
7536: %lt = %{$desc};
7537: }
7538: my $userfieldsty = 'none';
7539: my (%checked,$userfield);
7540: $checked{'sourcedid'} = ' checked="checked"';
7541: $checked{'reject'} = ' checked="checked"';
7542: if (ref($current) eq 'HASH') {
7543: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7544: $checked{'sourcedid'} = '';
7545: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7546: $checked{'email'} = ' checked="checked"';
7547: } else {
7548: $checked{'other'} = ' checked="checked"';
7549: $userfield = $current->{'mapuser'};
7550: $userfieldsty = 'inline-block';
7551: }
7552: }
7553: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7554: $checked{'reject'} = '';
7555: $checked{'auth'} = ' checked="checked"';
7556: }
7557: }
1.112 raeburn 7558: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7559: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7560: &mt('Source of LON-CAPA username in LTI request').': ';
7561: foreach my $option ('sourcedid','email','other') {
7562: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7563: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7564: ($option eq 'other' ? '' : (' 'x2) );
7565: }
7566: $output .= '</span></div>'.
7567: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7568: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7569: 'value="'.$userfield.'"'.$disabled.' /></div>';
7570: $output .= '<br />'.
7571: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7572: &mt('Action when username is not for an enrolled student').': ';
7573: foreach my $option ('reject','auth') {
7574: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7575: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7576: ($option eq 'auth' ? '' : (' 'x2) );
7577: }
7578: $output .= '</span></div>';
7579: return $output;
7580: }
7581:
1.114 raeburn 7582: sub print_extresource_row {
7583: my ($item,$config,$curr,$noedit) = @_;
7584: my $onchange;
7585: unless ($noedit) {
7586: $onchange = ' onchange="javascript:toggleExtRes();"';
7587: }
7588: my $id = 'LC_'.$item;
7589: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7590: my $output = &select_from_options($item,$config->{'order'},
7591: $config->{'options'},$selected,
7592: $config->{'nullval'},
7593: undef,undef,$onchange,$noedit,$id);
7594: my ($checked,$reusesty,$sizesty);
7595: if ($reuse) {
7596: $checked = ' checked="checked"';
7597: }
7598: $reusesty = 'none';
7599: $sizesty = 'none';
7600: if (($selected eq 'window') || ($selected eq 'tab')) {
7601: $reusesty = 'inline-block';
7602: if ($selected eq 'window') {
7603: $sizesty = 'inline-block';
7604: }
7605: }
7606: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7607: '<span class="LC_nobreak">'.
7608: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7609: &mt('Re-use tab/window').'</label>'.
7610: '</span></div>'.
7611: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7612: '<legend>'.&mt('Window size (optional)').'</legend>'.
7613: '<span class="LC_nobreak">'.
7614: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7615: (' ' x 3).
7616: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7617: '</span></fieldset>';
7618: return $output;
7619: }
7620:
1.1 raeburn 7621: sub print_other {
1.80 raeburn 7622: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7623: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7624: return;
7625: }
1.3 raeburn 7626: my @ordered = &get_other_items($cdom,$settings,$allitems);
7627: my %items;
7628: foreach my $parameter (@ordered) {
7629: $items{$parameter} = {
7630: text => '<b>'.$parameter.'</b>',
7631: input => 'textbox',
7632: size => '15',
7633: },
7634: }
7635: push (@ordered,'newp_value');
7636: $items{'newp_value'} = {
7637: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7638: '<input type="textbox" name="newp_name"'.
7639: ' value="" size="30" />',
7640: input => 'textbox',
7641: size => '30',
7642: };
1.93 raeburn 7643: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7644: }
7645:
7646: sub get_other_items {
7647: my ($cdom,$settings,$allitems) = @_;
7648: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7649: return;
7650: }
1.1 raeburn 7651: my @ordered;
7652: if (ref($settings) eq 'HASH') {
7653: foreach my $parameter (sort(keys(%{$settings}))) {
7654: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7655: next if (($parameter eq 'course.helper.not.run') &&
7656: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7657: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7658: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7659: || ($parameter eq 'type') ||
1.50 raeburn 7660: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7661: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7662: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7663: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7664: push(@ordered,$parameter);
7665: }
7666: }
7667: }
1.3 raeburn 7668: return @ordered;
1.1 raeburn 7669: }
7670:
7671: sub item_table_row_start {
1.91 raeburn 7672: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7673: my $output;
1.56 raeburn 7674: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7675: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7676: if ($leftclass eq '') {
7677: $leftclass = 'LC_left_item';
7678: }
7679: if ($rightclass eq '') {
7680: $rightclass = 'LC_right_item';
7681: }
1.56 raeburn 7682: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7683: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7684: '</td>';
1.91 raeburn 7685: if ($colspan > 1) {
7686: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7687: } else {
1.91 raeburn 7688: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7689: }
1.1 raeburn 7690: return $output;
7691: }
7692:
7693: sub item_table_row_end {
7694: return '</td></tr>';
7695: }
7696:
7697: sub yesno_radio {
1.80 raeburn 7698: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
1.1 raeburn 7699: my $itemon = ' ';
7700: my $itemoff = ' checked="checked" ';
1.69 raeburn 7701: if (($valueyes eq '') && ($valueno eq '')) {
7702: $valueyes = 'yes';
7703: $valueno = '';
7704: }
1.1 raeburn 7705: if (ref($settings) eq 'HASH') {
1.69 raeburn 7706: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7707: $itemon = $itemoff;
7708: $itemoff = ' ';
7709: }
1.69 raeburn 7710: unless (exists($settings->{$item})) {
7711: if ($unsetdefault eq $valueyes) {
7712: $itemon = $itemoff;
7713: $itemoff = ' ';
7714: }
7715: }
1.1 raeburn 7716: }
1.80 raeburn 7717: my $disabled;
7718: if ($noedit) {
7719: $disabled = ' disabled="disabled"';
7720: }
1.1 raeburn 7721: return '<span class="LC_nobreak"><label>'.
7722: '<input type="radio" name="'.$item.'"'.
1.80 raeburn 7723: $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
1.1 raeburn 7724: '<label><input type="radio" name="'.$item.'"'.
1.80 raeburn 7725: $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
1.1 raeburn 7726: }
7727:
7728: sub select_from_options {
1.91 raeburn 7729: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7730: my $output;
1.80 raeburn 7731: my $disabled;
7732: if ($noedit) {
7733: $disabled = ' disabled=disabled"';
7734: }
1.1 raeburn 7735: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7736: $output='<select name="'.$item.'" '.$onchange;
7737: if ($multiple) {
7738: $output .= ' multiple="multiple"';
7739: my $num = @{$order};
7740: $num ++ if ($nullval ne '');
7741: if (($maxsize) && ($maxsize < $num)) {
7742: $output .= ' size="'.$maxsize.'"';
7743: }
7744: }
1.91 raeburn 7745: if ($id ne '') {
7746: $output .= ' id="'.$id.'"';
7747: }
1.80 raeburn 7748: $output .= $disabled.'>'."\n";
1.1 raeburn 7749: if ($nullval ne '') {
7750: $output .= '<option value=""';
7751: if (ref($curr) eq 'ARRAY') {
7752: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7753: $output .= ' selected="selected" ';
7754: }
7755: } else {
7756: if ($curr eq '') {
7757: $output .= ' selected="selected" ';
7758: }
7759: }
7760: $output .= '>'.$nullval.'</option>';
7761: }
7762: foreach my $option (@{$order}) {
7763: $output.= '<option value="'.$option.'"';
7764: if (ref($curr) eq 'ARRAY') {
7765: if (grep(/^\Q$option\E$/,@{$curr})) {
7766: $output .= ' selected="selected" ';
7767: }
7768: } else {
7769: if ($option eq $curr) {
7770: $output.=' selected="selected"';
7771: }
7772: }
7773: $output.=">$options->{$option}</option>\n";
7774: }
7775: $output.="</select>";
7776: }
7777: return $output;
7778: }
7779:
7780: sub make_item_rows {
1.80 raeburn 7781: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
1.1 raeburn 7782: my $datatable;
7783: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7784: my $count = 0;
7785: foreach my $item (@{$ordered}) {
7786: $count ++;
1.56 raeburn 7787: my $colspan;
7788: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7789: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7790: $colspan = 2;
7791: }
1.114 raeburn 7792: my $rowdesc;
7793: if ($caller eq 'appearance') {
7794: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7795: } else {
7796: $rowdesc = $items->{$item}{text};
7797: }
1.41 www 7798: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7799: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7800: } else {
1.114 raeburn 7801: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7802: }
1.55 raeburn 7803: if ($item eq 'defaultcredits') {
7804: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7805: my $showcredits;
7806: if ($defaultcredits ne '') {
7807: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7808: } else {
7809: $showcredits = &mt('No default set');
7810: }
7811: $datatable .= $showcredits;
7812: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 7813: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 7814: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 7815: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7816: } elsif ($item eq 'print_header_format') {
1.80 raeburn 7817: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 7818: } elsif ($item eq 'lti.lcmenu') {
7819: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 7820: } elsif ($item eq 'extresource') {
7821: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7822: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 7823: my $disabled;
7824: if ($noedit) {
7825: $disabled = ' disabled="disabled"';
7826: }
1.1 raeburn 7827: $datatable .=
7828: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 7829: $settings->{$item},$disabled);
1.1 raeburn 7830: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 7831: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 7832: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 7833: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7834: unless ($domdefs{$item} eq '0') {
7835: $unsetdefault = 1;
7836: }
7837: $valueyes = "1";
7838: $valueno = "0";
1.87 raeburn 7839: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
7840: $valueyes = '1';
1.69 raeburn 7841: }
1.80 raeburn 7842: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7843: } elsif ($items->{$item}{input} eq 'selectbox') {
1.91 raeburn 7844: my $id;
7845: if ($caller eq 'menuitems') {
7846: $id = $item;
7847: }
1.1 raeburn 7848: my $curr = $settings->{$item};
7849: $datatable .=
7850: &select_from_options($item,$items->{$item}{'order'},
7851: $items->{$item}{'options'},$curr,
1.80 raeburn 7852: $items->{$item}{'nullval'},
1.91 raeburn 7853: undef,undef,undef,$noedit,$id);
1.1 raeburn 7854: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 7855: my $disabled;
7856: if ($noedit) {
7857: $disabled = ' disabled=disabled"';
7858: }
1.1 raeburn 7859: $datatable .=
7860: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 7861: $items->{$item}{size},
7862: $disabled);
1.1 raeburn 7863: }
7864: $datatable .= &item_table_row_end();
7865: }
7866: if (ref($rowtotal)) {
7867: $$rowtotal += scalar(@{$ordered});
7868: }
7869: }
7870: return $datatable;
7871: }
7872:
7873: sub nothidepriv_row {
1.80 raeburn 7874: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 7875: my ($cnum) = &get_course();
1.56 raeburn 7876: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 7877: if (ref($settings) eq 'HASH') {
7878: if ($settings->{$item} ne '') {
7879: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
7880: if ($user !~ /:/) {
7881: $nothide{join(':',split(/[\@]/,$user))}=1;
7882: } else {
7883: $nothide{$user} = 1;
7884: }
7885: }
7886: }
1.56 raeburn 7887: if ($settings->{'checkforpriv'}) {
7888: @checkdoms = split(/,/,$settings->{'checkforpriv'});
7889: }
1.1 raeburn 7890: }
1.56 raeburn 7891: push(@checkdoms,$cdom);
7892: my %coursepersonnel =
7893: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 7894: my @privusers;
7895: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 7896: my ($uname,$udom,$role) = split(/:/,$person);
7897: my $user = $uname.':'.$udom;
7898: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 7899: if ($end == -1 || $start == -1) {
7900: next;
7901: }
1.56 raeburn 7902: foreach my $dom (@checkdoms) {
7903: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
7904: unless (grep(/^\Q$user\E$/,@privusers)) {
7905: push(@privusers,$user);
1.3 raeburn 7906: }
7907: }
7908: }
1.1 raeburn 7909: }
1.56 raeburn 7910: if (@privusers > 0) {
1.80 raeburn 7911: my $disabled;
7912: if ($noedit) {
7913: $disabled = ' disabled="disabled"';
7914: }
1.1 raeburn 7915: $datatable .= '<table align="right">';
7916: foreach my $user (sort(@privusers)) {
7917: my $hideon = ' checked="checked" ';
7918: my $hideoff = '';
7919: if ($nothide{$user}) {
7920: $hideoff = $hideon;
7921: $hideon = '';
7922: }
7923: my ($uname,$udom) = split(':',$user);
7924: $datatable .= '<tr><td align="left">'.
7925: &Apache::loncommon::aboutmewrapper(
7926: &Apache::loncommon::plainname($uname,$udom,'firstname'),
7927: $uname,$udom,'aboutuser').
7928: '</td><td align="left">'.
7929: '<span class="LC_nobreak"><label>'.
7930: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 7931: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 7932: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 7933: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 7934: '</tr>';
7935: }
7936: $datatable .= '</table>';
7937: } else {
1.9 raeburn 7938: if ($crstype eq 'Community') {
7939: $datatable .= &mt('No Domain Coordinators have community roles');
7940: } else {
7941: $datatable .= &mt('No Domain Coordinators have course roles');
7942: }
1.1 raeburn 7943: }
7944: return $datatable;
7945: }
7946:
1.56 raeburn 7947: sub checkforpriv_row {
1.80 raeburn 7948: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 7949: my $datatable;
7950: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7951: if (keys(%domains) == 1) {
7952: $datatable = '</td><td align="right">'.
7953: &mt("Course's domain is only domain");
7954: return $datatable;
7955: }
7956: my @excdoms = ($cdom);
7957: my $num = 0;
7958: if ($settings->{$item} eq '') {
7959: $datatable = '</td><td align="right">'.
7960: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 7961: 1,1,undef,undef,\@excdoms,
7962: $noedit);
1.56 raeburn 7963: } else {
7964: my @privdoms = split(/,/,$settings->{$item});
7965: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7966: $datatable = '</td><td align="right"><br />'.
7967: &Apache::loncommon::start_data_table();
1.80 raeburn 7968: my $disabled;
7969: if ($noedit) {
7970: $disabled = ' disabled="disabled"';
7971: }
1.56 raeburn 7972: if (@privdoms > 0) {
7973: foreach my $currdom (@privdoms) {
7974: next unless ($domains{$currdom});
7975: my $domdesc = &Apache::lonnet::domain($currdom,'description');
7976: if ($domdesc eq '') {
7977: $domdesc = $currdom;
7978: }
7979: $datatable .=
7980: &Apache::loncommon::start_data_table_row().
7981: '<td align="left"><span class="LC_nobreak">'.
7982: &mt('Domain:').'<b> '.$domdesc.
7983: '</b><input type="hidden" name="checkforpriv_'.$num.
7984: '" value="'.$currdom.'" /></span><br />'.
7985: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 7986: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
7987: &mt('Delete').'</label></span></td>'.
1.56 raeburn 7988: &Apache::loncommon::end_data_table_row();
7989: $num ++;
7990: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
7991: push(@excdoms,$currdom);
7992: }
7993: }
7994: }
7995: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
7996: $datatable .=
7997: &Apache::loncommon::start_data_table_row().
7998: '<td align="left"><span class="LC_nobreak">'.
7999: &mt('Additional domain:'). '</span><br />'.
8000: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8001: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8002: '</td>'.&Apache::loncommon::end_data_table_row();
8003: }
8004: $datatable .= &Apache::loncommon::end_data_table().
8005: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8006: '<br />';
8007: }
8008: return $datatable;
8009: }
8010:
1.1 raeburn 8011: sub print_hdrfmt_row {
1.80 raeburn 8012: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8013: my @curr;
8014: my $currnum = 0;
8015: my $maxnum = 2;
8016: my $currstr;
8017: if ($settings->{$item} ne '') {
8018: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8019: $settings->{$item}.'</tt></span></b><br />';
8020: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8021: foreach my $val (@current) {
8022: unless ($val eq '') {
8023: push(@curr,$val);
1.1 raeburn 8024: }
8025: }
8026: $currnum = @curr;
8027: $maxnum += $currnum;
8028: }
8029:
8030: my $output = <<ENDJS;
8031:
8032: <script type="text/javascript" language="Javascript">
8033:
8034: function reOrder(chgnum) {
8035: var maxnum = $maxnum;
8036: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8037: var newidx = 'printfmthdr_pos_'+chgnum;
8038: oldidx = getIndexByName(oldidx);
8039: newidx = getIndexByName(newidx);
8040: var oldpos = document.display.elements[oldidx].value;
8041: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8042: document.display.elements[oldidx].value = newpos;
8043: var chgtype = 'up';
8044: if (newpos < oldpos) {
8045: chgtype = 'down';
8046: }
8047: for (var j=0; j<maxnum; j++) {
8048: if (j != chgnum) {
8049: oldidx = 'printfmthdr_oldpos_'+j;
8050: newidx = 'printfmthdr_pos_'+j;
8051: oldidx = getIndexByName(oldidx);
8052: newidx = getIndexByName(newidx);
8053: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8054: var currsel = document.display.elements[newidx].selectedIndex;
8055: if (chgtype == 'up') {
8056: if ((currpos > oldpos) && (currpos <= newpos)) {
8057: document.display.elements[newidx].selectedIndex = currsel-1;
8058: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8059: }
8060: } else {
8061: if ((currpos >= newpos) && (currpos < oldpos)) {
8062: document.display.elements[newidx].selectedIndex = currsel+1;
8063: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8064: }
8065: }
8066: }
8067: }
8068: return;
8069: }
8070:
8071: function getIndexByName(item) {
8072: for (var i=0;i<document.display.elements.length;i++) {
8073: if (document.display.elements[i].name == item) {
8074: return i;
8075: }
8076: }
8077: return -1;
8078: }
8079:
8080: </script>
8081:
8082: ENDJS
1.56 raeburn 8083: $output .= '</td><td align="right"><br />'.
8084: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8085: my $disabled;
8086: if ($noedit) {
8087: $disabled = ' disabled="disabled"';
8088: }
1.1 raeburn 8089: if (@curr > 0) {
8090: for (my $i=0; $i<@curr; $i++) {
8091: my $pos = $i+1;
1.10 raeburn 8092: $output .= '<tr>'.
1.1 raeburn 8093: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8094: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8095: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8096: '"'.$disabled.' /></span></td>';
1.1 raeburn 8097: if ($curr[$i] =~ /^%\d*[nca]$/) {
8098: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8099: $output .= '<td align="left">'.
1.80 raeburn 8100: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8101: } else {
8102: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8103: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8104: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8105: }
1.10 raeburn 8106: $output .= '</tr>';
1.1 raeburn 8107: }
8108: }
1.80 raeburn 8109: my $pos = $currnum+1;
8110: unless ($noedit) {
8111: $output .=
8112: '<tr>'.
1.1 raeburn 8113: '<td align="left"><span class="LC_nobreak">'.
8114: &position_selector($pos,$currnum,$maxnum).
8115: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8116: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8117: '</tr>';
1.80 raeburn 8118: $pos ++;
1.82 raeburn 8119: $currnum ++;
8120: $output .=
1.80 raeburn 8121: '<tr>'.
1.1 raeburn 8122: '<td align="left"><span class="LC_nobreak">'.
8123: &position_selector($pos,$currnum,$maxnum).
8124: '<b>'.&mt('New').'</b></span></td>'.
8125: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8126: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8127: '" value="" size ="25" />'.
8128: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8129: $maxnum.'" /></td>'.
1.80 raeburn 8130: '</tr>';
8131: }
8132: $output .= '</table><br />';
1.1 raeburn 8133: return $output;
8134: }
8135:
8136: sub position_selector {
1.80 raeburn 8137: my ($pos,$num,$maxnum,$disabled) = @_;
8138: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8139: for (my $j=1; $j<=$maxnum; $j++) {
8140: my $sel = '';
8141: if ($pos == $j) {
8142: $sel = ' selected="selected"';
8143: }
8144: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8145: }
8146: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8147: '" value="'.$pos.'" />';
8148: return $output;
8149: }
8150:
8151: sub substitution_selector {
1.80 raeburn 8152: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8153: my ($stunametxt,$crsidtxt);
8154: if ($crstype eq 'Community') {
8155: $stunametxt = 'member name';
8156: $crsidtxt = 'community ID',
8157: } else {
8158: $stunametxt = 'student name';
8159: $crsidtxt = 'course ID',
8160: }
1.1 raeburn 8161: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8162: n => $stunametxt,
8163: c => $crsidtxt,
1.1 raeburn 8164: a => 'assignment note',
8165: );
8166: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8167: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8168: if ($subst eq '') {
8169: $output .= '<option value="" selected="selected"> </option>';
8170: }
8171: foreach my $field ('n','c','a') {
8172: my $sel ='';
8173: if ($subst eq $field) {
8174: $sel = ' selected="selected"';
8175: }
8176: $output .= '<option value="'.$field.'"'.$sel.'>'.
8177: $lt{$field}.'</option>';
8178: }
8179: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8180: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8181: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8182: return $output;
8183: }
8184:
1.23 raeburn 8185: sub change_clone {
8186: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8187: my $clone_crs = $cnum.':'.$cdom;
8188: if ($cnum && $cdom) {
8189: my $clone_crs = $cnum.':'.$cdom;
8190: my @allowclone;
8191: if ($clonelist =~ /,/) {
8192: @allowclone = split(',',$clonelist);
8193: } else {
8194: $allowclone[0] = $clonelist;
8195: }
8196: foreach my $currclone (@allowclone) {
8197: if (!grep(/^$currclone$/,@$oldcloner)) {
8198: if ($currclone ne '*') {
1.71 raeburn 8199: if ($currclone =~ /:/) {
8200: my ($uname,$udom) = split(/:/,$currclone);
8201: if ($uname && $udom && $uname ne '*') {
8202: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8203: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8204: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8205: if ($currclonecrs{'cloneable'} eq '') {
8206: $currclonecrs{'cloneable'} = $clone_crs;
8207: } else {
8208: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8209: }
8210: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8211: }
8212: }
8213: }
8214: }
8215: }
8216: }
8217: }
8218: foreach my $oldclone (@$oldcloner) {
8219: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8220: if ($oldclone ne '*') {
1.71 raeburn 8221: if ($oldclone =~ /:/) {
8222: my ($uname,$udom) = split(/:/,$oldclone);
8223: if ($uname && $udom && $uname ne '*' ) {
8224: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8225: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8226: my %newclonecrs = ();
8227: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8228: if ($currclonecrs{'cloneable'} =~ /,/) {
8229: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8230: foreach my $crs (@currclonecrs) {
8231: if ($crs ne $clone_crs) {
8232: $newclonecrs{'cloneable'} .= $crs.',';
8233: }
1.23 raeburn 8234: }
1.71 raeburn 8235: $newclonecrs{'cloneable'} =~ s/,$//;
8236: } else {
8237: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8238: }
1.71 raeburn 8239: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8240: }
8241: }
8242: }
8243: }
8244: }
8245: }
8246: }
8247: }
8248: return;
8249: }
8250:
1.108 raeburn 8251: sub devalidate_remote_courseprefs {
8252: my ($cdom,$cnum,$cachekeys) = @_;
8253: return unless (ref($cachekeys) eq 'HASH');
8254: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8255: my %thismachine;
8256: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8257: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8258: if (keys(%servers)) {
8259: foreach my $server (keys(%servers)) {
8260: next if ($thismachine{$server});
8261: my @cached;
8262: foreach my $name (@posscached) {
8263: if ($cachekeys->{$name}) {
8264: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8265: }
8266: }
8267: if (@cached) {
8268: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8269: }
8270: }
8271: }
8272: return;
8273: }
8274:
1.1 raeburn 8275: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>