Annotation of loncom/interface/courseprefs.pm, revision 1.49.2.28.2.18
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.49.2.28.2.1 (raeburn 4:): # $Id: courseprefs.pm,v 1.49.2.28.2.17 2023/09/06 13:32:28 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.49.2.28.2.5 (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.49.2.28.2.5 (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.49.2.28.2.1 (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.49.2.21 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.49.2.14 raeburn 222: use Apache::lonrelrequtils;
1.36 raeburn 223: use Apache::lonparmset;
1.49.2.18 raeburn 224: use Apache::courseclassifier;
1.1 raeburn 225: use Apache::lonlocal;
226: use LONCAPA qw(:DEFAULT :match);
1.49.2.28.2.5 (raeburn 227:: use Crypt::CBC;
1.49.2.28.2.1 (raeburn 228:): use Time::HiRes qw( sleep );
1.1 raeburn 229:
1.49.2.14 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.49.2.14 raeburn 242: my ($cnum,$cdom,$chome) = &get_course($cid);
1.1 raeburn 243: my $crstype = &Apache::loncommon::course_type();
1.49.2.21 raeburn 244: my ($parm_permission,$allowed) = &get_permission($cid);
1.1 raeburn 245: my $navmap = Apache::lonnavmaps::navmap->new();
1.49.2.21 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.49.2.14 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.49.2.12 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.49.2.28.2.1 (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.49.2.7 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.49.2.12 raeburn 317: unco => 'Unique code',
1.20 faziophi 318: desc => 'Course Description',
1.49.2.6 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.49.2.28.2.1 (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.49.2.7 raeburn 335: prus => 'Privileged users (Domain Coordinators) in staff listing',
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.49.2.21 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.49.2.21 raeburn 358: if (($phase eq 'releaseinfo') && ($parm_permission->{'releaseinfo'})) {
1.36 raeburn 359: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
360: if ($loncaparev) {
1.49.2.14 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.49.2.28.2.5 (raeburn 374:: my %linkprot=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1.49.2.28.2.3 (raeburn 375:: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
1.49.2.28.2.1 (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.49.2.28.2.5 (raeburn 378:: foreach my $id (keys(%linkprot)) {
379:: if (ref($linkprot{$id}) eq 'HASH') {
1.49.2.28.2.3 (raeburn 380:: if (ref($ltienc{$id}) eq 'HASH') {
1.49.2.28.2.5 (raeburn 381:: $values{'linkprot'}{$id} = { %{$linkprot{$id}}, %{$ltienc{$id}} };
1.49.2.28.2.3 (raeburn 382:: } else {
1.49.2.28.2.5 (raeburn 383:: $values{'linkprot'}{$id} = $linkprot{$id};
1.49.2.28.2.3 (raeburn 384:: }
385:: }
386:: unless ($phase eq 'process') {
1.49.2.28.2.5 (raeburn 387:: if (ref($values{'linkprot'}{$id}) eq 'HASH') {
388:: delete($values{'linkprot'}{$id}{'secret'});
1.49.2.28.2.3 (raeburn 389:: }
390:: }
391:: }
1.49.2.28.2.5 (raeburn 392:: if ($linkprot{'lock'}) {
393:: delete($linkprot{'lock'});
1.49.2.28.2.1 (raeburn 394:: }
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.49.2.28.2.1 (raeburn 414:): 'menuitems','ltitools','linkprot','spreadsheet',
415:): 'bridgetasks','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.49.2.12 raeburn 421: 'clonedfrom','courseid','uniquecode','categories',
1.49.2.24 raeburn 422: 'hidefromcat','syllabus','cloners','url',
1.49.2.12 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.49.2.28.2.1 (raeburn 429:): 'uniquecode' => $lt{'unco'},
1.25 raeburn 430: 'categories' => $lt{'catg'},
431: 'hidefromcat' => $lt{'excc'},
432: 'cloners' => $lt{'clon'},
1.49.2.24 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.49.2.11 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',
466: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 467: 'allow_limited_html_in_feedback',
1.49.2.3 raeburn 468: 'allow_discussion_post_editing',
469: 'discussion_post_fonts'],
1.3 raeburn 470: itemtext => {
1.31 raeburn 471: 'pch.roles.denied' => 'No Resource Discussion',
472: 'pch.users.denied' => 'No Resource Discussion',
473: 'plc.roles.denied' => 'No Chat room use',
474: 'plc.users.denied' => 'No Chat room use',
1.20 faziophi 475: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
476: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.49.2.28.2.1 (raeburn 477:): discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 478: },
1.1 raeburn 479: },
480: 'classlists' =>
1.9 raeburn 481: { text => $lt{'clas'},
1.44 www 482: help => 'Course_Prefs_Classlists',
1.1 raeburn 483: header => [{col1 => 'Type',
1.9 raeburn 484: col2 => $lt{'defd'}},
1.1 raeburn 485: {col1 => 'Setting',
1.9 raeburn 486: col2 => $lt{'priv'}},
1.1 raeburn 487: {col1 => 'Setting',
1.9 raeburn 488: col2 => $lt{'stuv'}}],
1.1 raeburn 489: ordered => ['default_enrollment_start_date',
490: 'default_enrollment_end_date',
1.49.2.6 raeburn 491: 'defaultcredits',
1.49.2.7 raeburn 492: 'nothideprivileged','checkforpriv',
493: 'student_classlist_view',
1.26 raeburn 494: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 495: itemtext => {
496: default_enrollment_start_date => 'Start date',
497: default_enrollment_end_date => 'End date',
1.49.2.7 raeburn 498: nothideprivileged => $lt{'prus'},
499: checkforpriv => $lt{'prdo'},
1.9 raeburn 500: student_classlist_view => $lt{'stuv'},
1.26 raeburn 501: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 502: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.49.2.6 raeburn 503: defaultcredits => $lt{'cred'},
1.3 raeburn 504: },
1.1 raeburn 505: },
506: 'appearance' =>
1.20 faziophi 507: { text => 'Display of resources ',
1.44 www 508: help => 'Course_Prefs_Display',
1.1 raeburn 509: ordered => ['default_xml_style','pageseparators',
510: 'disable_receipt_display','texengine',
1.49.2.28.2.1 (raeburn 511:): 'tthoptions','uselcmath','usejsme',
512:): 'inline_chem','extresource'],
1.3 raeburn 513: itemtext => {
1.17 faziophi 514: default_xml_style => 'Default XML style file',
1.20 faziophi 515: pageseparators => 'Visibly Separate Items on Pages',
516: disable_receipt_display => 'Disable display of problem receipts',
517: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 518: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.49.2.17 raeburn 519: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
520: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.49.2.28 raeburn 521: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.49.2.28.2.1 (raeburn 522:): extresource => 'Display of external resources',
1.3 raeburn 523: },
1.1 raeburn 524: },
525: 'grading' =>
526: { text => 'Grading',
1.44 www 527: help => 'Course_Prefs_Grading',
1.1 raeburn 528: ordered => ['grading','rndseed',
529: 'receiptalg','disablesigfigs'],
1.3 raeburn 530: itemtext => {
1.20 faziophi 531: grading => 'Grading',
532: rndseed => 'Randomization algorithm used',
533: receiptalg => 'Receipt algorithm used',
534: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 535: },
536:
1.1 raeburn 537: },
538: 'printouts' =>
1.20 faziophi 539: { text => 'Printout generation',
1.44 www 540: help => 'Course_Prefs_Printouts',
1.1 raeburn 541: ordered => ['problem_stream_switch','suppress_tries',
542: 'default_paper_size','print_header_format',
1.49.2.1 raeburn 543: 'disableexampointprint'],
1.3 raeburn 544: itemtext => {
545: problem_stream_switch => 'Allow problems to be split over pages',
546: suppress_tries => 'Suppress number of tries in printing',
547: default_paper_size => 'Default paper type',
548: print_header_format => 'Print header format',
1.49.2.4 raeburn 549: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 550: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 551: },
1.1 raeburn 552: },
553: 'spreadsheet' =>
554: { text => 'Spreadsheets',
1.44 www 555: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 556: ordered => ['spreadsheet_default_classcalc',
557: 'spreadsheet_default_studentcalc',
558: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 559: itemtext => {
1.9 raeburn 560: spreadsheet_default_classcalc => $lt{'defc'},
561: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 562: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
563: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
564: },
1.1 raeburn 565: },
566: 'bridgetasks' =>
567: { text => 'Bridge tasks',
1.44 www 568: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 569: ordered => ['task_messages','task_grading',
570: 'suppress_embed_prompt'],
1.3 raeburn 571: itemtext => {
1.9 raeburn 572: task_messages => $lt{'seme'},
1.3 raeburn 573: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 574: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 575: },
1.1 raeburn 576: },
1.49.2.28.2.1 (raeburn 577:: 'menuitems' =>
578:: {
579:: text => 'Menu display',
580:: help => 'Course_Prefs_Menus',
581:: header => [{col1 => 'Default Menu',
582:: col2 => 'Value',},
583:: {col1 => 'Menu collections',
584:: col2 => 'Settings',
585:: }],
586:: ordered => ['menudefault','menucollections'],
587:: itemtext => {
588:: menudefault => 'Choose default collection of menu items for course',
589:: menucollections => 'Menu collections',
590:: },
591:: },
1.49.2.28.2.5 (raeburn 592:: 'linkprot' =>
1.49.2.28.2.1 (raeburn 593:: {
594:: text => 'Link protection',
595:: help => 'Course_Prefs_Linkprotection',
596:: header => [{col1 => 'Item',
597:: col2 => 'Settings',
598:: }],
599:: },
600:): 'ltitools' =>
601:): {
602:): text => 'External tools',
603:): help => 'Course_Prefs_ExternalTools',
604:): header => [{col1 => 'Item',
605:): col2 => 'Settings',
606:): }],
607:): },
1.1 raeburn 608: 'other' =>
609: { text => 'Other settings',
1.44 www 610: help => 'Course_Prefs_Other',
1.1 raeburn 611: header => [ {col1 => 'Item',
612: col2 => 'Value',
613: }],
614: },
615: );
1.49.2.21 raeburn 616: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 617: my @allitems = &get_allitems(%prefs);
1.49.2.28.2.8 (raeburn 618:: my $result = &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
619:: \@prefs_order,\%prefs,\%values,
620:: $cnum,undef,\@allitems,
621:: 'coursepref',$parm_permission);
622:: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
623:: $r->rflush();
624:: &devalidate_remote_courseprefs($cdom,$cnum,$result);
625:: }
1.49.2.21 raeburn 626: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.49.2.28.2.1 (raeburn 627:: my $noedit;
628:: if (ref($parm_permission) eq 'HASH') {
629:: unless ($parm_permission->{'process'}) {
630:: $noedit = 1;
631:: }
632:: }
633:: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 634: my @allitems = &get_allitems(%prefs);
1.1 raeburn 635: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.49.2.28.2.3 (raeburn 636:: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.49.2.21 raeburn 637: 'coursepref',$parm_permission);
1.1 raeburn 638: } else {
639: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.49.2.21 raeburn 640: \@prefs_order,\%prefs,
641: 'coursepref',$parm_permission);
1.1 raeburn 642: }
643: return OK;
644: }
645:
1.49.2.21 raeburn 646: sub get_permission {
647: my ($cid) = @_;
648: my %permission;
649: my $allowed = 0;
650: return (\%permission,$allowed) unless ($cid);
651: if (&Apache::lonnet::allowed('opa',$cid)) {
652: %permission= (
653: 'pickactions' => 1,
654: 'categorizecourse' => 1,
655: 'releaseinfo' => 1,
656: 'process' => 1,
657: 'display' => 1,
658: );
659: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
660: %permission = (
661: 'pickactions' => 1,
662: 'releaseinfo' => 1,
663: 'display' => 1,
664: );
665: }
666: foreach my $perm (values(%permission)) {
667: if ($perm) { $allowed=1; last; }
668: }
669: return (\%permission,$allowed);
670: }
671:
1.3 raeburn 672: sub get_allitems {
673: my (%prefs) = @_;
674: my @allitems;
675: foreach my $item (keys(%prefs)) {
676: if (ref($prefs{$item}) eq 'HASH') {
677: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
678: push(@allitems,@{$prefs{$item}{'ordered'}});
679: if ($item eq 'feedback') {
680: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
681: }
1.49.2.28.2.1 (raeburn 682:): } elsif (($item eq 'linkprot') || ($item eq 'ltitools')) {
683:): push(@allitems,$item);
1.3 raeburn 684: }
685: }
686: }
687: return @allitems;
688: }
689:
1.1 raeburn 690: sub print_config_box {
1.49.2.28.2.3 (raeburn 691:: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 692: my $ordered = $item->{'ordered'};
1.3 raeburn 693: my $itemtext = $item->{'itemtext'};
1.49.2.21 raeburn 694: my $noedit;
695: if (ref($parm_permission) eq 'HASH') {
696: unless ($parm_permission->{'process'}) {
697: $noedit = 1;
698: }
699: }
1.1 raeburn 700: my $rowtotal = 0;
701: my $output =
1.45 www 702: '<table class="LC_nested_outer">
703: <tr>
704: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.49.2.4 raeburn 705: &mt($item->{text});
706: if ($item->{'help'}) {
707: $output .= ' '.
708: &Apache::loncommon::help_open_topic($item->{'help'});
709: }
710: $output .= '</span></th>'."\n".
711: '</tr>';
1.49.2.28.2.1 (raeburn 712:: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 713: $output .= '
1.45 www 714: <tr>
715: <td>
1.18 faziophi 716: <table class="LC_nested">';
717: if (exists $item->{'header'}->[0]->{'col1'} ||
718: exists $item->{'header'}->[0]->{'col2'}) {
719: $output .= '
720: <tr class="LC_info_row">
1.49.2.7 raeburn 721: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
722: if ($action eq 'feedback') {
723: $output .= '
724: <td class="LC_right_item" colspan="2">';
725: } else {
726: $output .= '
727: <td class="LC_right_item">';
728: }
729: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 730: </tr>';
731: }
1.1 raeburn 732: $rowtotal ++;
733: if ($action eq 'feedback') {
1.49.2.21 raeburn 734: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 735: } elsif ($action eq 'classlists') {
1.49.2.21 raeburn 736: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.49.2.28.2.1 (raeburn 737:: } elsif ($action eq 'menuitems') {
738:: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 739: }
740: $output .= '
741: </table>
1.45 www 742: </td>
743: </tr>
744: <tr>
745: <td>
1.1 raeburn 746: <table class="LC_nested">
747: <tr class="LC_info_row">
748: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.49.2.7 raeburn 749: if ($action eq 'classlists') {
750: $output .= '
751: <td class="LC_right_item" colspan="2">';
752: } else {
753: $output .= '
754: <td class="LC_right_item">';
755: }
756: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 757: </tr>';
758: if ($action eq 'classlists') {
1.49.2.21 raeburn 759: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 760: '
761: </table>
1.45 www 762: </td>
763: </tr>
764: <tr>
765: <td>
1.18 faziophi 766: <table class="LC_nested">';
1.43 www 767: if (exists $item->{'header'}->[2]->{'col1'} ||
768: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 769: $output .= '
770: <tr class="LC_info_row">
1.43 www 771: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
772: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 773: </tr>';
774: }
1.1 raeburn 775: }
776: } else {
777: $output .= '
1.45 www 778: <tr>
779: <td>
1.18 faziophi 780: <table class="LC_nested">';
781: if (exists $item->{'header'}->[0]->{'col1'} ||
782: exists $item->{'header'}->[0]->{'col2'}) {
783: $output .= '
784: <tr class="LC_info_row">
1.49.2.7 raeburn 785: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
786: if (($action eq 'courseinfo') || ($action eq 'localization') ||
787: ($action eq 'print_discussion')) {
788: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
789: } else {
790: $output .= '<td class="LC_right_item" valign="top">';
791: }
792: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 793: </tr>';
794: }
1.1 raeburn 795: }
796: $rowtotal ++;
797: if ($action eq 'courseinfo') {
1.49.2.21 raeburn 798: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 799: } elsif ($action eq 'localization') {
1.49.2.21 raeburn 800: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 801: } elsif ($action eq 'feedback') {
1.49.2.21 raeburn 802: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 803: } elsif ($action eq 'discussion') {
1.49.2.21 raeburn 804: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.49.2.4 raeburn 805: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.49.2.21 raeburn 806: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 807: } elsif ($action eq 'appearance') {
1.49.2.21 raeburn 808: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 809: } elsif ($action eq 'grading') {
1.49.2.28.2.1 (raeburn 810:): $output .= &print_grading($cdom,$cnum,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 811: } elsif ($action eq 'printouts') {
1.49.2.21 raeburn 812: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 813: } elsif ($action eq 'spreadsheet') {
1.49.2.21 raeburn 814: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 815: } elsif ($action eq 'bridgetasks') {
1.49.2.21 raeburn 816: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.49.2.28.2.1 (raeburn 817:): } elsif ($action eq 'ltitools') {
818:): my $currtools = {};
819:): if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
820:): $currtools = $settings->{'ltitools'};
821:): }
822:): $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
823:: } elsif ($action eq 'menuitems') {
824:: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.49.2.28.2.5 (raeburn 825:: } elsif ($action eq 'linkprot') {
826:: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 827: } elsif ($action eq 'other') {
1.49.2.21 raeburn 828: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 829: }
830: $output .= '
831: </table>
1.45 www 832: </td>
833: </tr>
834: </table><br />';
1.1 raeburn 835: return ($output,$rowtotal);
836: }
837:
838: sub process_changes {
1.49.2.28.2.8 (raeburn 839:: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.49.2.28.2.5 (raeburn 840:: my (%newvalues,$errors);
1.3 raeburn 841: if (ref($item) eq 'HASH') {
842: if (ref($changes) eq 'HASH') {
843: my @ordered;
844: if ($action eq 'other') {
845: @ordered = &get_other_items($cdom,$values,$allitems);
846: if ($env{'form.newp_name'} ne '') {
847: my $newp = $env{'form.newp_name'};
848: if ($env{'form.newp_value'} ne '') {
849: if (ref($allitems) eq 'ARRAY') {
850: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
851: (grep(/^\Q$newp\E$/,@{$allitems}))) {
852: $changes->{$newp} = $env{'form.newp_value'};
853: }
854: }
855: }
856: }
1.49.2.28.2.1 (raeburn 857:): } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.49.2.28.2.3 (raeburn 858:: if (ref($values->{$action}) eq 'HASH') {
859:: foreach my $id (keys(%{$values->{$action}})) {
1.49.2.28.2.1 (raeburn 860:: if ($id =~ /^\d+$/) {
861:: push(@ordered,$id);
862:: }
863:: }
864:: }
865:: @ordered = sort { $a <=> $b } @ordered;
866:): if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
867:): push(@ordered,$env{'form.'.$action.'_maxnum'});
868:: }
1.3 raeburn 869: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 870: if ($action eq 'courseinfo') {
871: my ($can_toggle_cat,$can_categorize) =
872: &can_modify_catsettings($cdom,$crstype);
873: foreach my $entry (@{$item->{'ordered'}}) {
874: next if (($entry eq 'hidefromcat') &&
875: (!$can_toggle_cat));
876: next if (($entry eq 'categories') &&
877: (!$can_categorize));
878: next if (($entry eq 'loncaparev') ||
1.49.2.11 raeburn 879: ($entry eq 'owner') ||
1.49.2.24 raeburn 880: ($entry eq 'clonedfrom') ||
881: ($entry eq 'syllabus'));
1.49 raeburn 882: push(@ordered,$entry);
883: }
1.49.2.6 raeburn 884: } elsif ($action eq 'classlists') {
885: foreach my $entry (@{$item->{'ordered'}}) {
886: next if ($entry eq 'defaultcredits');
887: push(@ordered,$entry);
888: }
1.49 raeburn 889: } else {
890: @ordered = @{$item->{'ordered'}};
891: }
1.3 raeburn 892: }
893: if (@ordered > 0) {
894: if ($action eq 'feedback') {
895: foreach my $entry (@ordered) {
896: my $userstr = '';
897: my $total = $env{'form.'.$entry.'_total'};
898: if ($total) {
899: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
900: for (my $i=0; $i<$total; $i++) {
901: unless (grep(/^$i$/,@deletes)) {
902: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
903: &get_sec_str($entry,$i).',';
904: }
905: }
906: } else {
907: $total = 0;
908: }
909: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
910: my $uname = $env{'form.'.$entry.'_uname_'.$total};
911: my $udom = $env{'form.'.$entry.'_udom_'.$total};
912: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
913: $userstr =~ s/,$//;
914: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
915: } else {
916: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
917: }
918: } else {
919: $userstr =~ s/,$//;
920: }
921: $newvalues{$entry} = $userstr;
922: if ($newvalues{$entry} ne $values->{$entry}) {
923: $changes->{$entry} = $newvalues{$entry};
924: }
925: my $ext_entry = $entry.'.text';
926: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
927: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
928: $changes->{$ext_entry} = $newvalues{$ext_entry};
929: }
930: }
1.49.2.28.2.1 (raeburn 931:: } elsif ($action eq 'menuitems') {
932:: my (%current,@colls);
933:: my $next = 1;
934:: if ($values->{'menucollections'}) {
935:: foreach my $item (split(/;/,$values->{'menucollections'})) {
936:: my ($num,$value) = split(/\%/,$item);
937:: if ($num =~ /^\d+$/) {
938:: unless (grep(/^$num$/,@colls)) {
939:: push(@colls,$num);
940:: }
941:: my @entries = split(/\&/,$value);
942:: foreach my $entry (@entries) {
943:: my ($name,$fields) = split(/=/,$entry);
944:: $current{$num}{$name} = $fields;
945:: }
946:: }
947:: }
948:: }
949:: if (@colls) {
950:: @colls = sort { $a <=> $b } @colls;
951:: $next += $colls[-1];
952:: }
953:: if ($env{'form.menucollections_add'} eq $next) {
954:: push(@colls,$next);
955:: }
956:: my $currdef = $values->{'menudefault'};
957:: my $possdef = $env{'form.menudefault'};
958:: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
959:: if ($currdef ne $possdef) {
960:: $changes->{'menudefault'} = $possdef;
961:: }
962:: } elsif ($currdef) {
963:: $changes->{'menudefault'} = '';
964:: }
965:: my $menucoll;
966:: if (@colls) {
967:: my ($ordered,$cats) = &menuitems_categories();
968:: my %shortcats = &menuitems_abbreviations();
969:: foreach my $num (@colls) {
970:: my ($entry,%include);
971:: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
972:: foreach my $item (@{$ordered}) {
973:: if ($item eq 'shown') {
974:: foreach my $type (@{$cats->{$item}}) {
975:: $entry .= $type.'=';
976:: if ($include{$type}) {
977:: $entry .= 'y';
978:: } else {
979:: $entry .= 'n';
980:: }
981:: $entry .= '&';
982:: }
983:: } else {
984:: $entry .= $shortcats{$item}.'=';
985:: foreach my $type (@{$cats->{$item}}) {
986:: if ($include{$type}) {
987:: $entry .= $type.',';
988:: }
989:: }
990:: $entry =~ s/,$//;
991:: $entry .= '&';
992:: }
993:: }
994:: $entry =~ s/\&$//;
995:: if ($menucoll) {
996:: $menucoll .= ';';
997:: }
998:: $menucoll .= $num.'%'.$entry;
999:: }
1000:: if ($menucoll ne $values->{'menucollections'}) {
1001:: $changes->{'menucollections'} = $menucoll;
1002:: }
1003:: } elsif ($values->{'menucollections'}) {
1004:: $changes->{'menucollections'} = '';
1005:: }
1.49.2.28.2.5 (raeburn 1006:: } elsif ($action eq 'linkprot') {
1007:: if (ref($values) eq 'HASH') {
1.49.2.28.2.8 (raeburn 1008:: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.49.2.28.2.1 (raeburn 1009:: }
1010:): } elsif ($action eq 'ltitools') {
1011:): if (ref($values) eq 'HASH') {
1012:): my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1013:): $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1014:): 'ok','','ok');
1015:): }
1.3 raeburn 1016: } else {
1017: foreach my $entry (@ordered) {
1018: if ($entry eq 'cloners') {
1019: if ($env{'form.cloners_all'}) {
1020: $newvalues{$entry} = '*';
1021: } else {
1022: my @clonedoms;
1023: if (exists($env{'form.cloners_activate'})) {
1024: my $actnum = $env{'form.cloners_activate'};
1.49.2.18 raeburn 1025: if ($actnum ne '-1') {
1.33 raeburn 1026: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1027: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1028: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1029: $newvalues{$entry} = '*:'.$clonedom;
1030: push(@clonedoms,$newvalues{$entry});
1031: }
1032: }
1033: }
1034: } else {
1035: my $num = $env{'form.cloners_total'};
1036: my @deletes =
1037: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1038: for (my $i=0; $i<$num; $i++) {
1039: if (!grep(/^$i$/,@deletes)) {
1040: my $clonedom = $env{'form.cloners_dom_'.$i};
1041: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1042: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.49.2.18 raeburn 1043: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1044: }
1045: }
1046: }
1047: }
1048: if (@clonedoms) {
1049: $newvalues{$entry}=join(',',@clonedoms);
1050: }
1051: }
1052: if ($env{'form.cloners_newdom'} ne '') {
1053: my $clonedom = $env{'form.cloners_newdom'};
1054: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1055: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.49.2.28.2.1 (raeburn 1056:: if (@clonedoms) {
1.3 raeburn 1057: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1058: $newvalues{$entry} .= ','.$newdom;
1059: }
1060: } else {
1061: $newvalues{$entry} = $newdom;
1062: }
1063: }
1064: }
1065: if ($env{'form.'.$entry} ne '') {
1066: my @cloners = split(',',$env{'form.'.$entry});
1067: my @okcloners;
1068: foreach my $cloner (@cloners) {
1.23 raeburn 1069: $cloner =~ s/^\s+//;
1070: $cloner =~ s/\s+$//;
1071: unless ($cloner eq '') {
1072: my ($uname,$udom) = split(':',$cloner);
1073: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1074: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1075: push(@okcloners,$cloner);
1076: }
1.3 raeburn 1077: }
1078: }
1079: }
1080: if (@okcloners) {
1081: my $okclonestr = join(',',@okcloners);
1082: if ($newvalues{$entry} ne '') {
1083: $newvalues{$entry} .= ','.$okclonestr;
1084: } else {
1085: $newvalues{$entry} = $okclonestr;
1086: }
1087: }
1088: }
1.49.2.18 raeburn 1089: if (ref($values) eq 'HASH') {
1090: my (@code_order,%codedefaults);
1091: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1092: \@code_order);
1093: my $clonebycode;
1094: if ($env{'form.cloners_instcode'}) {
1095: if (@code_order > 0) {
1096: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1097: my %local_to_standard;
1098: for (my $i=0; $i<@code_order; $i++) {
1099: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1100: }
1101: foreach my $item (@code_order) {
1102: my $key = $local_to_standard{$item};
1103: if ($key ne '') {
1104: if ($env{'form.'.$key}) {
1105: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1106: }
1107: }
1108: }
1109: $clonebycode =~ s/\&$//;
1110: }
1111: }
1112: if ($clonebycode) {
1113: if ($newvalues{$entry}) {
1114: $newvalues{$entry} .= ','.$clonebycode;
1115: } else {
1116: $newvalues{$entry} = $clonebycode;
1117: }
1118: }
1119: }
1.3 raeburn 1120: }
1121: if (ref($disallowed) eq 'HASH') {
1122: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1123: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1124: $disallowed->{'cloners'}{$key} =~ s/,$//;
1125: }
1126: }
1127: }
1.25 raeburn 1128: } elsif ($entry eq 'co-owners') {
1129: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1130: my $coowners = $values->{'internal.co-owners'};
1131: my @currcoown;
1132: if ($coowners) {
1133: @currcoown = split(',',$coowners);
1134: }
1135: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1136: my $autocoowner;
1137: if (($crstype eq 'Course') &&
1138: ($values->{'internal.coursecode'})) {
1139: my %domconf =
1140: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1141: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1142: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1143: }
1144: }
1.49.2.28.2.2 (raeburn 1145:: if ($autocoowner) {
1146:: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1147:: } else {
1.25 raeburn 1148: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1149: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1150: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1151: if (@invitecoowners) {
1152: push(@pendingcoowners,@invitecoowners);
1153: }
1154: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1155: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1156: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1157: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1158: push(@{$changes->{$entry}{'changed'}},'co-owners');
1159: }
1160: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1161: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1162: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1163: }
1164: }
1165: } else {
1166: my (@newpending,@newcoown);
1167: my $uname = $env{'user.name'};
1168: my $udom = $env{'user.domain'};
1169: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1170: my @pendingcoown = split(',',$pendingcoowners);
1.49.2.26 raeburn 1171: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1172: foreach my $item (@pendingcoown) {
1173: unless ($item eq $uname.':'.$udom) {
1174: push(@newpending,$item);
1175: }
1176: }
1177: @newcoown = @currcoown;
1.49.2.26 raeburn 1178: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1179: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1180: push(@newcoown,$uname.':'.$udom);
1181: }
1182: }
1.49.2.26 raeburn 1183: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1184: foreach my $item (@currcoown) {
1185: unless ($item eq $uname.':'.$udom) {
1186: push(@newcoown,$item);
1187: }
1188: }
1189: if ($pendingcoowners ne '') {
1190: @newpending = @pendingcoown;
1191: }
1.49.2.28.2.2 (raeburn 1192:: } else {
1193:: @newcoown = @currcoown;
1.25 raeburn 1194: }
1195: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1196: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1197: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1198: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1199: push(@{$changes->{$entry}{'changed'}},'co-owners');
1200: }
1201: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1202: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1203: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1204: }
1205: }
1.3 raeburn 1206: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1207: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1208: } elsif ($entry eq 'rolenames') {
1209: my %adv_roles =
1210: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1211: my @stds;
1212: if ($crstype eq 'Community') {
1213: @stds = ('co');
1214: } else {
1215: @stds = ('cc');
1216: }
1217: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1218: my (@replacements,@regulars);
1219: foreach my $role (@stds) {
1220: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1221: push(@replacements,$role);
1.3 raeburn 1222: } else {
1223: push(@regulars,$role);
1224: }
1.9 raeburn 1225: }
1.3 raeburn 1226: foreach my $stdrole (@stds) {
1227: my $ext_entry = $entry.'_'.$stdrole;
1228: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1229: $env{'request.course.id'},1);
1230: if ($env{'form.'.$ext_entry} eq $stdname) {
1231: $newvalues{$ext_entry} = '';
1232: } else {
1233: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1234: }
1235: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1236: my $dupname = 0;
1237: if ($newvalues{$ext_entry} ne '') {
1238: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1239: $dupname = 1;
1240: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1241: }
1242: if (!$dupname) {
1243: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1244: $dupname = 1;
1245: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1246: }
1247: }
1248: if (!$dupname) {
1249: foreach my $role (keys(%adv_roles)) {
1250: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1251: $dupname = 1;
1252: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1253: last;
1254: }
1255: }
1256: }
1257: }
1258: if (!$dupname) {
1259: $changes->{$ext_entry} = $newvalues{$ext_entry};
1260: }
1261: }
1262: }
1263: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied')) {
1264: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1265: @denied = sort(@denied);
1266: my $deniedstr = '';
1267: if (@denied > 0) {
1268: $deniedstr = join(',',@denied);
1269: }
1270: $newvalues{$entry} = $deniedstr;
1271: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied')) {
1272: my $total = $env{'form.'.$entry.'_total'};
1273: my $userstr = '';
1274: my @denied;
1275: if ($total > 0) {
1276: my @deletes =
1277: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1278: for (my $i=0; $i<$total; $i++) {
1279: unless (grep(/^$i$/,@deletes)) {
1280: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1281: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1282: }
1283: }
1284: } else {
1285: $total = 0;
1286: }
1287: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1288: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1289: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1290: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1291: $userstr =~ s/,$//;
1292: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1293: } else {
1294: my $newuser .= $uname.':'.$udom;
1295: if (grep(/^\Q$newuser\E$/,@denied)) {
1296: $userstr =~ s/,$//;
1297: } else {
1298: $userstr .= $newuser;
1299: }
1300: }
1301: } else {
1302: $userstr =~ s/,$//;
1303: }
1304: $newvalues{$entry} = $userstr;
1305: } elsif ($entry eq 'allow_discussion_post_editing') {
1306: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1307: @canedit = sort(@canedit);
1308: foreach my $role (@canedit) {
1309: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1310: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1311: $newvalues{$entry} .= $role.',';
1312: } else {
1313: foreach my $sec (@secs) {
1314: $newvalues{$entry} .= $role.':'.$sec.',';
1315: }
1316: }
1317: }
1318: $newvalues{$entry} =~ s/,$//;
1.49.2.3 raeburn 1319: } elsif ($entry eq 'discussion_post_fonts') {
1320: my ($classorder,$classtitles) = &discussion_vote_classes();
1321: my $fontchange = 0;
1322: foreach my $class (@{$classorder}) {
1323: my $ext_entry = $entry.'_'.$class;
1324: my $size = $env{'form.'.$ext_entry.'_size'};
1325: my $unit = $env{'form.'.$ext_entry.'_unit'};
1326: my $weight = $env{'form.'.$ext_entry.'_weight'};
1327: my $style = $env{'form.'.$ext_entry.'_style'};
1328: my $other = $env{'form.'.$ext_entry.'_other'};
1329: $size =~ s/,//g;
1330: $unit =~ s/,//g;
1331: $weight =~ s/,//g;
1332: $style =~ s/,//g;
1333: $other =~ s/[^\w;:\s\-\%.]//g;
1334: $other =~ s/(^\s+|\s+$)//g;
1335: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1336: my $current = $values->{$ext_entry};
1337: if ($values->{$ext_entry} eq '') {
1338: $current = ',,,';
1339: }
1340: if ($newvalues{$ext_entry} ne $current) {
1341: $changes->{$ext_entry} = $newvalues{$ext_entry};
1342: $fontchange ++;
1343: }
1344: }
1345: if ($fontchange) {
1346: $changes->{$entry} = 1;
1347: }
1.3 raeburn 1348: } elsif ($entry eq 'nothideprivileged') {
1349: my @curr_nothide;
1350: my @new_nothide;
1351: if ($values->{$entry} ne '') {
1352: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1353: my $nothide;
1354: if ($user !~ /:/) {
1355: $nothide = join(':',split(/[\@]/,$user));
1356: } else {
1357: $nothide = $user;
1358: }
1359: if ((defined($nothide)) &&
1360: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1361: push(@curr_nothide,$nothide);
1362: }
1363: }
1364: }
1365: foreach my $key (keys(%env)) {
1366: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1367: if ($env{$key}) {
1.3 raeburn 1368: my $nothide = $1;
1369: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1370: push(@new_nothide,$nothide);
1371: }
1372: }
1373: }
1374: }
1375: @new_nothide = sort(@new_nothide);
1376: my @differences =
1377: &Apache::loncommon::compare_arrays(\@curr_nothide,
1378: \@new_nothide);
1379: if (@differences > 0) {
1380: if (@new_nothide > 0) {
1381: $newvalues{$entry} = join(',',@new_nothide);
1382: } else {
1383: $newvalues{$entry} = '';
1384: }
1385: } else {
1386: $newvalues{$entry} = $values->{$entry};
1387: }
1388: } elsif ($entry eq 'print_header_format') {
1389: my $maxnum = $env{'form.printfmthdr_maxnum'};
1390: my @newhdr;
1391: if ($maxnum > 2) {
1392: for (my $i=0; $i<$maxnum-2; $i++) {
1393: if ($env{'form.printfmthdr_del_'.$i}) {
1394: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1395: } else {
1396: my $hdr;
1397: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1398: $hdr = '%';
1399: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1400: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1401: }
1402: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1403: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1404: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1405: }
1406: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1407: }
1408: }
1409: }
1410: my $newsub = $maxnum-2;
1411: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1412: my $hdr = '%';
1413: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1414: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1415: }
1416: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1417: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1418: }
1419: my $newtext = $maxnum-1;
1420: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1421: $newvalues{$entry} = join('',@newhdr);
1.49.2.7 raeburn 1422: } elsif (($entry eq 'languages') ||
1423: ($entry eq 'checkforpriv')) {
1424: my $settings;
1.3 raeburn 1425: my $total = $env{'form.'.$entry.'_total'};
1426: if ($total) {
1427: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1428: for (my $i=0; $i<$total; $i++) {
1429: unless (grep(/^$i$/,@deletes)) {
1.49.2.7 raeburn 1430: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1431: }
1432: }
1433: } else {
1434: $total = 0;
1435: }
1436: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.49.2.7 raeburn 1437: my $new = $env{'form.'.$entry.'_'.$total};
1438: if ($entry eq 'languages') {
1439: my %langchoices = &get_lang_choices();
1440: if ($langchoices{$new}) {
1441: $settings .= $new;
1442: } else {
1443: $settings =~ s/,$//;
1444: $disallowed->{'localization'}{$entry} = $new;
1445: }
1.3 raeburn 1446: } else {
1.49.2.7 raeburn 1447: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1448: if ($domains{$new}) {
1449: $settings .= $new;
1450: } else {
1451: $settings =~ s/,$//;
1452: $disallowed->{'classlists'}{$entry} = $new;
1453: }
1.3 raeburn 1454: }
1455: } else {
1.49.2.7 raeburn 1456: $settings =~ s/,$//;
1.3 raeburn 1457: }
1.49.2.7 raeburn 1458: $newvalues{$entry} = $settings;
1.49.2.28.2.1 (raeburn 1459:): } elsif ($entry eq 'extresource') {
1460:): if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1461:): $newvalues{$entry} = $env{'form.'.$entry};
1462:): if ($env{'form.'.$entry} ne 'iframe') {
1463:): if ($env{'form.extwintabreuse'}) {
1464:): $newvalues{$entry} .= ':1';
1465:): } else {
1466:): $newvalues{$entry} .= ':0';
1467:): }
1468:): if ($env{'form.'.$entry} eq 'window') {
1469:): foreach my $dim ('width','height') {
1470:): $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1471:): if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1472:): $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1473:): } else {
1474:): $newvalues{$entry} .= ':';
1475:): }
1476:): }
1477:): }
1478:): }
1479:): }
1480:): unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1481:): if ($newvalues{$entry} ne $values->{$entry}) {
1482:): $changes->{$entry} = $newvalues{$entry};
1483:): }
1484:): }
1485:): } elsif ($entry eq 'timezone') {
1486:): if ($env{'form.'.$entry}) {
1487:): $newvalues{$entry} = $env{'form.'.$entry};
1488:): if ($newvalues{$entry} ne $values->{$entry}) {
1489:): $changes->{$entry} = $newvalues{$entry};
1490:): }
1491:): if ($env{'form.tzover'}) {
1492:): $newvalues{'tzover'} = $env{'form.tzover'};
1493:): if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1494:): $changes->{'tzover'} = $newvalues{'tzover'};
1495:): }
1496:): } elsif ($values->{'tzover'}) {
1497:): $changes->{'tzover'} = '';
1498:): }
1499:): } elsif ($values->{$entry}) {
1500:): $changes->{$entry} = '';
1501:): }
1502:): } elsif ($entry eq 'grading') {
1503:): if ($env{'form.'.$entry} eq 'standard') {
1504:): if ($env{'form.hidetotals'}) {
1505:): my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1506:): if (keys(%sections)) {
1507:): my @secs = &Apache::loncommon::get_env_multiple('form.hidetotals_sections');
1508:): if (grep(/^all$/,@secs)) {
1509:): $newvalues{'hidetotals'} = 'all';
1510:): } elsif (@secs) {
1511:): $newvalues{'hidetotals'} = '';
1512:): foreach my $sec (sort {$a <=> $b} @secs) {
1513:): if (exists($sections{$sec})) {
1514:): $newvalues{'hidetotals'} .= $sec.','
1515:): }
1516:): }
1517:): $newvalues{'hidetotals'} =~ s/,$//;
1518:): }
1519:): } else {
1520:): $newvalues{'hidetotals'} = 'all';
1521:): }
1522:): }
1523:): }
1524:): if ($newvalues{'hidetotals'} ne $values->{'hidetotals'}) {
1525:): $changes->{'hidetotals'} = $newvalues{'hidetotals'};
1526:): $changes->{'grading'} = $env{'form.'.$entry};
1527:): }
1528:): $newvalues{$entry} = $env{'form.'.$entry};
1.3 raeburn 1529: } else {
1530: $newvalues{$entry} = $env{'form.'.$entry};
1531: }
1.49.2.28.2.1 (raeburn 1532:): unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1533:): ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1534: if ($newvalues{$entry} ne $values->{$entry}) {
1535: $changes->{$entry} = $newvalues{$entry};
1536: }
1.3 raeburn 1537: }
1538: }
1539: }
1540: }
1541: }
1542: }
1.49.2.28.2.1 (raeburn 1543:: return $errors;
1544:: }
1545::
1.49.2.28.2.5 (raeburn 1546:: sub process_linkprot {
1.49.2.28.2.8 (raeburn 1547:: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.49.2.28.2.1 (raeburn 1548:): my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.49.2.28.2.5 (raeburn 1549:: if (ref($values) eq 'HASH') {
1550:: foreach my $id (keys(%{$values})) {
1551:: if ($id =~ /^\d+$/) {
1552:: unless (ref($values->{$id}) eq 'HASH') {
1553:: $linkprot{$id} = '';
1554:: }
1555:: }
1556:: }
1557:: }
1.49.2.28.2.1 (raeburn 1558:): ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.49.2.28.2.5 (raeburn 1559:: if ($context eq 'domain') {
1560:: $dest = '/adm/domainprefs';
1561:: $ltiauth = 1;
1562:: } else {
1563:: $dest = '/adm/courseprefs';
1564:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1565:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1566:: } else {
1567:: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1568:: $ltiauth = $domdefs{'crsltiauth'};
1569:: }
1570:: }
1571:: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1572:: my (@items,%deletions,%itemids,%haschanges);
1573:: if ($env{'form.linkprot_add'}) {
1574:: my $name = $env{'form.linkprot_name_add'};
1575:: $name =~ s/(`)/'/g;
1576:: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1577:: if ($newid) {
1578:: $itemids{'add'} = $newid;
1579:: push(@items,'add');
1580:: $haschanges{$newid} = 1;
1581:: } else {
1582:: $errors .= '<span class="LC_error">'.
1583:: &mt('Failed to acquire unique ID for link protection').
1584:: '</span>';
1585:: }
1586:: }
1587:: if (ref($values) eq 'HASH') {
1588:: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1589:: my $maxnum = $env{'form.linkprot_maxnum'};
1.49.2.28.2.1 (raeburn 1590:): for (my $i=0; $i<$maxnum; $i++) {
1.49.2.28.2.5 (raeburn 1591:: my $itemid = $env{'form.linkprot_id_'.$i};
1592:: $itemid =~ s/\D+//g;
1593:: if ($itemid) {
1594:: if (ref($values->{$itemid}) eq 'HASH') {
1595:: push(@items,$i);
1596:: $itemids{$i} = $itemid;
1597:: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1598:: $deletions{$itemid} = $values->{$itemid}->{'name'};
1599:: }
1600:: }
1601:: }
1602:: }
1603:: }
1604:: foreach my $idx (@items) {
1605:: my $itemid = $itemids{$idx};
1606:: next unless ($itemid);
1607:: if (exists($deletions{$itemid})) {
1608:: $linkprot{$itemid} = $deletions{$itemid};
1609:: $haschanges{$itemid} = 1;
1610:: next;
1611:: }
1612:: my %current;
1613:: if (ref($values) eq 'HASH') {
1614:: if (ref($values->{$itemid}) eq 'HASH') {
1615:: foreach my $key (keys(%{$values->{$itemid}})) {
1616:: $current{$key} = $values->{$itemid}->{$key};
1617:: }
1618:: }
1619:: }
1620:: foreach my $inner ('name','lifetime','version') {
1621:: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1622:: $env{$formitem} =~ s/(`)/'/g;
1623:: if ($inner eq 'lifetime') {
1624:: $env{$formitem} =~ s/[^\d.]//g;
1625:: }
1626:: unless ($idx eq 'add') {
1627:: if ($current{$inner} ne $env{$formitem}) {
1628:: $haschanges{$itemid} = 1;
1629:: }
1630:: }
1631:: if ($env{$formitem} ne '') {
1632:: $linkprot{$itemid}{$inner} = $env{$formitem};
1633:: }
1634:: }
1.49.2.28.2.1 (raeburn 1635:): my $urlitem = 'form.linkprot_returnurl_'.$idx;
1636:): my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1637:): if ($env{$urlitem} == 1) {
1638:): $env{$urlparamname} =~ s/(`)/'/g;
1639:): } elsif (exists($env{$urlparamname})) {
1640:): $env{$urlparamname} = '';
1641:): }
1642:): my $passback = 'form.linkprot_passback_'.$idx;
1643:): my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
1644:): if ($env{$passback} == 1) {
1645:): unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
1646:): $env{$passbackparamname} = '';
1647:): }
1648:): } elsif (exists($env{$passbackparamname})) {
1649:): $env{$passbackparamname} = '';
1650:): }
1651:): unless ($idx eq 'add') {
1652:): if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1653:): ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1654:): $haschanges{$itemid} = 1;
1655:): }
1656:): if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
1657:): ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
1658:): $haschanges{$itemid} = 1;
1659:): }
1660:): }
1661:): if ($env{$urlparamname} ne '') {
1662:): $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1663:): }
1664:): if ($env{$passbackparamname} ne '') {
1665:): $linkprot{$itemid}{'passback'} = 1;
1666:): $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1667:): }
1.49.2.28.2.5 (raeburn 1668:: if ($ltiauth) {
1669:: my $reqitem = 'form.linkprot_requser_'.$idx;
1670:: $env{$reqitem} =~ s/(`)/'/g;
1671:: unless ($idx eq 'add') {
1672:: if ((!$current{'requser'} && $env{$reqitem}) ||
1673:: ($current{'requser'} && !$env{$reqitem})) {
1674:: $haschanges{$itemid} = 1;
1675:: }
1676:: }
1677:: if ($env{$reqitem} == 1) {
1678:: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1679:: foreach my $inner ('mapuser','notstudent') {
1680:: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1681:: $env{$formitem} =~ s/(`)/'/g;
1682:: if ($inner eq 'mapuser') {
1683:: if ($env{$formitem} eq 'other') {
1684:: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1685:: $mapuser =~ s/(`)/'/g;
1686:: $mapuser =~ s/^\s+|\s+$//g;
1687:: if ($mapuser ne '') {
1688:: $linkprot{$itemid}{$inner} = $mapuser;
1689:: } else {
1690:: delete($linkprot{$itemid}{'requser'});
1691:: last;
1692:: }
1693:: } elsif ($env{$formitem} eq 'sourcedid') {
1694:: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1695:: } elsif ($env{$formitem} eq 'email') {
1696:: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1697:: }
1698:: } else {
1699:: $linkprot{$itemid}{$inner} = $env{$formitem};
1700:: }
1701:: unless ($idx eq 'add') {
1702:: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1703:: $haschanges{$itemid} = 1;
1704:: }
1705:: }
1706:: }
1707:: }
1708:: }
1709:: unless ($switchserver) {
1710:: my $keyitem = 'form.linkprot_key_'.$idx;
1711:: $env{$keyitem} =~ s/(`)/'/g;
1712:: unless ($idx eq 'add') {
1713:: if ($current{'key'} ne $env{$keyitem}) {
1714:: $haschanges{$itemid} = 1;
1715:: }
1716:: }
1717:: if ($env{$keyitem} ne '') {
1718:: $linkprot{$itemid}{'key'} = $env{$keyitem};
1719:: }
1720:: my $secretitem = 'form.linkprot_secret_'.$idx;
1721:: $env{$secretitem} =~ s/(`)/'/g;
1722:: if ($current{'usable'}) {
1723:: if ($env{'form.linkprot_changesecret_'.$idx}) {
1724:: if ($env{$secretitem} ne '') {
1725:: if ($privnum && $cipher) {
1726:: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1727:: $linkprot{$itemid}{'cipher'} = $privnum;
1728:: } else {
1729:: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1730:: }
1731:: $haschanges{$itemid} = 1;
1732:: }
1733:: } else {
1734:: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.49.2.28.2.1 (raeburn 1735:): $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.49.2.28.2.5 (raeburn 1736:: }
1737:: } elsif ($env{$secretitem} ne '') {
1738:: if ($privnum && $cipher) {
1739:: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1740:: $linkprot{$itemid}{'cipher'} = $privnum;
1741:: } else {
1742:: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1743:: }
1744:: $haschanges{$itemid} = 1;
1745:: }
1746:: }
1747:: }
1748:: if (keys(%haschanges)) {
1749:: foreach my $entry (keys(%haschanges)) {
1750:: $changes->{$entry} = $linkprot{$entry};
1751:: }
1.49.2.28.2.8 (raeburn 1752:: if (ref($lastactref) eq 'HASH') {
1.49.2.28.2.9 (raeburn 1753:: $lastactref->{'courselti'} = 1;
1.49.2.28.2.8 (raeburn 1754:: }
1.49.2.28.2.5 (raeburn 1755:: }
1756:: return $errors;
1757:: }
1758::
1759:: sub get_linkprot_id {
1760:: my ($cdom,$cnum,$name,$context) = @_;
1761:: # get lock on lti db in course or linkprot db in domain
1.49.2.28.2.1 (raeburn 1762:: my $lockhash = {
1763:: lock => $env{'user.name'}.
1764:: ':'.$env{'user.domain'},
1765:: };
1766:: my $tries = 0;
1.49.2.28.2.5 (raeburn 1767:: my $gotlock;
1768:: if ($context eq 'domain') {
1.49.2.28.2.1 (raeburn 1769:): $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1770:): } else {
1771:): $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1772:): }
1773:): my ($id,$error);
1774:): while (($gotlock ne 'ok') && ($tries<10)) {
1775:): $tries ++;
1776:): sleep (0.1);
1777:): if ($context eq 'domain') {
1778:): $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1779:): } else {
1780:): $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1781:): }
1782:): }
1783:): if ($gotlock eq 'ok') {
1784:): my %currids;
1785:): if ($context eq 'domain') {
1786:): %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1787:): } else {
1788:): %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1789:): }
1790:): if ($currids{'lock'}) {
1791:): delete($currids{'lock'});
1792:): if (keys(%currids)) {
1793:): my @curr = sort { $a <=> $b } keys(%currids);
1794:): if ($curr[-1] =~ /^\d+$/) {
1795:): $id = 1 + $curr[-1];
1796:): } else {
1797:): $id = 1;
1798:): }
1799:): } else {
1800:): $id = 1;
1801:): }
1802:): if ($id) {
1803:): if ($context eq 'domain') {
1804:): unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1805:): $error = 'nostore';
1806:): }
1807:): } else {
1808:): unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1809:): $error = 'nostore';
1810:): }
1811:): }
1812:): } else {
1813:): $error = 'nonumber';
1814:): }
1815:): }
1816:): my $dellockoutcome;
1817:): if ($context eq 'domain') {
1818:): $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1819:): } else {
1820:): $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1821:): }
1822:): } else {
1823:): $error = 'nolock';
1824:): }
1825:): return ($id,$error);
1826:): }
1827:):
1828:): sub get_credentials {
1829:): my ($cdom,$cnum,$type,$context) = @_;
1830:): my ($cipher,$privnum,$home);
1831:): my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1832:): my @ids=&Apache::lonnet::current_machine_ids();
1833:): if ($context eq 'domain') {
1834:): $home = &Apache::lonnet::domain($cdom,'primary');
1835:): } else {
1836:): $home = &Apache::lonnet::homeserver($cnum,$cdom);
1837:): }
1838:): my ($hostskey,$domkey,$crskey);
1839:): if ($type eq 'ltitools') {
1840:): $hostskey = 'toolprivhosts';
1841:): $domkey = 'toolenc_dom';
1842:): $crskey = 'toolenc_crs';
1843:): } else {
1844:): $hostskey = 'ltiprivhosts';
1845:): $domkey = 'linkprotenc_dom';
1846:): $crskey = 'linkprotenc_crs';
1847:): }
1848:): if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1849:): (($context eq 'course') && ($domdefs{$crskey}))) {
1850:): unless (($home eq 'no_host') || ($home eq '')) {
1851:): if (grep(/^\Q$home\E$/,@ids)) {
1852:): if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1853:): if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1854:): my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1855:): my $privkey = $privhash{'key'};
1856:): $privnum = $privhash{'version'};
1857:): if (($privnum) && ($privkey ne '')) {
1858:): $cipher = Crypt::CBC->new({'key' => $privkey,
1859:): 'cipher' => 'DES'});
1860:): }
1861:): }
1862:): }
1863:): }
1864:): }
1865:): }
1866:): return ($cipher,$privnum);
1867:): }
1868:):
1869:): sub process_ltitools {
1870:): my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1871:): $author_ok,$confname) = @_;
1872:): my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1873:):
1874:): my (%posslti,%possfield);
1875:): my @courseroles = ('cc','in','ta','ep','st');
1876:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1877:): map { $posslti{$_} = 1; } @ltiroles;
1878:): my @allfields = ('fullname','firstname','lastname','email','user','roles');
1879:): map { $possfield{$_} = 1; } @allfields;
1880:):
1881:): my ($dest,$privnum,$cipher);
1882:):
1883:): ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1884:): if ($context eq 'domain') {
1885:): $dest = '/adm/domainprefs';
1886:): } else {
1887:): $dest = '/adm/courseprefs';
1888:): }
1889:): my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1890:):
1891:): my (@allpos,@items,%deletions,%itemids,%haschanges);
1892:): if ($env{'form.ltitools_add'}) {
1893:): my $title = $env{'form.ltitools_add_title'};
1894:): $title =~ s/(`)/'/g;
1895:): my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
1896:): if ($newid) {
1897:): my $position = $env{'form.ltitools_add_pos'};
1898:): $position =~ s/\D+//g;
1899:): if ($position ne '') {
1900:): $allpos[$position] = $newid;
1901:): }
1902:): $haschanges{$newid} = 1;
1903:): foreach my $item ('title','url','lifetime') {
1904:): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1905:): if ($item eq 'lifetime') {
1906:): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1907:): }
1908:): if ($env{'form.ltitools_add_'.$item}) {
1909:): $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1910:): }
1911:): }
1912:): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1913:): $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1914:): }
1915:): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1916:): $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1917:): }
1918:): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1919:): $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1920:): } else {
1921:): $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1922:): }
1923:): foreach my $item ('width','height','linktext','explanation') {
1924:): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1925:): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1926:): if (($item eq 'width') || ($item eq 'height')) {
1927:): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1928:): $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1929:): }
1930:): } else {
1931:): if ($env{'form.ltitools_add_'.$item} ne '') {
1932:): $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1933:): }
1934:): }
1935:): }
1936:): if ($env{'form.ltitools_add_target'} eq 'window') {
1937:): $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1938:): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1939:): $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1940:): } else {
1941:): $ltitools{$newid}{'display'}{'target'} = 'iframe';
1942:): }
1943:): foreach my $item ('passback','roster') {
1944:): if ($env{'form.ltitools_'.$item.'_add'}) {
1945:): $ltitools{$newid}{$item} = 1;
1946:): if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1947:): my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1948:): $lifetime =~ s/^\s+|\s+$//g;
1949:): if ($lifetime =~ /^\d+\.?\d*$/) {
1950:): $ltitools{$newid}{$item.'valid'} = $lifetime;
1951:): }
1952:): }
1953:): }
1954:): }
1955:): if ($env{'form.ltitools_add_image.filename'} ne '') {
1956:): my ($imageurl,$error) =
1957:): &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
1958:): $newid,$configuserok,$lonhost,$author_ok);
1959:): if ($imageurl) {
1960:): $ltitools{$newid}{'image'} = $imageurl;
1961:): }
1962:): if ($error) {
1963:): &Apache::lonnet::logthis($error);
1964:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1965:): }
1966:): }
1967:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
1968:): foreach my $field (@fields) {
1969:): if ($possfield{$field}) {
1970:): if ($field eq 'roles') {
1971:): foreach my $role (@courseroles) {
1972:): my $choice = $env{'form.ltitools_add_roles_'.$role};
1973:): if (($choice ne '') && ($posslti{$choice})) {
1974:): $ltitools{$newid}{'roles'}{$role} = $choice;
1975:): if ($role eq 'cc') {
1976:): $ltitools{$newid}{'roles'}{'co'} = $choice;
1977:): }
1978:): }
1979:): }
1980:): } else {
1981:): $ltitools{$newid}{'fields'}{$field} = 1;
1982:): }
1983:): }
1984:): }
1985:): if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
1986:): if ($ltitools{$newid}{'fields'}{'user'}) {
1987:): if ($env{'form.ltitools_add_userincdom'}) {
1988:): $ltitools{$newid}{'incdom'} = 1;
1989:): }
1990:): }
1991:): }
1992:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
1993:): foreach my $item (@courseconfig) {
1994:): $ltitools{$newid}{'crsconf'}{$item} = 1;
1995:): }
1996:): if ($env{'form.ltitools_add_custom'}) {
1997:): my $name = $env{'form.ltitools_add_custom_name'};
1998:): my $value = $env{'form.ltitools_add_custom_value'};
1999:): $value =~ s/(`)/'/g;
2000:): $name =~ s/(`)/'/g;
2001:): $ltitools{$newid}{'custom'}{$name} = $value;
2002:): }
2003:): unless ($switchserver) {
2004:): my $keyitem = 'form.ltitools_add_key';
2005:): $env{$keyitem} =~ s/(`)/'/g;
2006:): if ($env{$keyitem} ne '') {
2007:): $ltitools{$newid}{'key'} = $env{$keyitem};
2008:): }
2009:): my $secretitem = 'form.ltitools_secret_add';
2010:): $env{$secretitem} =~ s/(`)/'/g;
2011:): if ($env{$secretitem} ne '') {
2012:): if ($privnum && $cipher) {
2013:): $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2014:): $ltitools{$newid}{'cipher'} = $privnum;
2015:): } else {
2016:): $ltitools{$newid}{'secret'} = $env{$secretitem};
2017:): }
2018:): }
2019:): }
2020:): } else {
2021:): $errors .= '<li><span class="LC_error">'.
2022:): &mt('Failed to acquire unique ID for new external tool').
2023:): '</span></li>';
2024:): }
2025:): }
2026:): if (ref($values) eq 'HASH') {
2027:): my %deletions;
2028:): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2029:): if (@todelete) {
2030:): map { $deletions{$_} = 1; } @todelete;
2031:): }
2032:): my %customadds;
2033:): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2034:): if (@newcustom) {
2035:): map { $customadds{$_} = 1; } @newcustom;
2036:): }
2037:): my %imgdeletions;
2038:): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2039:): if (@todeleteimages) {
2040:): map { $imgdeletions{$_} = 1; } @todeleteimages;
2041:): }
2042:): my $maxnum = $env{'form.ltitools_maxnum'};
2043:): for (my $i=0; $i<=$maxnum; $i++) {
2044:): my $itemid = $env{'form.ltitools_id_'.$i};
2045:): $itemid =~ s/\D+//g;
2046:): if (ref($values->{$itemid}) eq 'HASH') {
2047:): if ($deletions{$itemid}) {
2048:): if ($values->{$itemid}{'image'}) {
2049:): #FIXME need to obsolete item in RES space
2050:): }
2051:): $haschanges{$itemid} = $values->{$itemid}{'title'};
2052:): next;
2053:): } else {
2054:): my $newpos = $env{'form.ltitools_'.$itemid};
2055:): $newpos =~ s/\D+//g;
2056:): foreach my $item ('title','url','lifetime') {
2057:): $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2058:): if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2059:): $haschanges{$itemid} = 1;
2060:): }
2061:): }
2062:): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2063:): $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2064:): }
2065:): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2066:): $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2067:): }
2068:): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2069:): $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2070:): } else {
2071:): $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2072:): }
2073:): if ($values->{$itemid}{'sigmethod'} eq '') {
2074:): if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2075:): $haschanges{$itemid} = 1;
2076:): }
2077:): } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2078:): $haschanges{$itemid} = 1;
2079:): }
2080:): foreach my $size ('width','height') {
2081:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2082:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2083:): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2084:): $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2085:): if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2086:): if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2087:): $haschanges{$itemid} = 1;
2088:): }
2089:): } else {
2090:): $haschanges{$itemid} = 1;
2091:): }
2092:): } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2093:): if ($values->{$itemid}{'display'}{$size} ne '') {
2094:): $haschanges{$itemid} = 1;
2095:): }
2096:): }
2097:): }
2098:): foreach my $item ('linktext','explanation') {
2099:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2100:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2101:): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2102:): $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2103:): if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2104:): if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2105:): $haschanges{$itemid} = 1;
2106:): }
2107:): } else {
2108:): $haschanges{$itemid} = 1;
2109:): }
2110:): } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2111:): if ($values->{$itemid}{'display'}{$item} ne '') {
2112:): $haschanges{$itemid} = 1;
2113:): }
2114:): }
2115:): }
2116:): if ($env{'form.ltitools_target_'.$i} eq 'window') {
2117:): $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2118:): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2119:): $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2120:): } else {
2121:): $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2122:): }
2123:): if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2124:): if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2125:): $haschanges{$itemid} = 1;
2126:): }
2127:): } else {
2128:): $haschanges{$itemid} = 1;
2129:): }
2130:): foreach my $extra ('passback','roster') {
2131:): if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2132:): $ltitools{$itemid}{$extra} = 1;
2133:): if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2134:): my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2135:): $lifetime =~ s/^\s+|\s+$//g;
2136:): if ($lifetime =~ /^\d+\.?\d*$/) {
2137:): $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2138:): }
2139:): }
2140:): }
2141:): if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2142:): $haschanges{$itemid} = 1;
2143:): }
2144:): if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2145:): $haschanges{$itemid} = 1;
2146:): }
2147:): }
2148:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2149:): foreach my $item ('label','title','target','linktext','explanation','append') {
2150:): if (grep(/^\Q$item\E$/,@courseconfig)) {
2151:): $ltitools{$itemid}{'crsconf'}{$item} = 1;
2152:): if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2153:): if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2154:): $haschanges{$itemid} = 1;
2155:): }
2156:): } else {
2157:): $haschanges{$itemid} = 1;
2158:): }
2159:): }
2160:): }
2161:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2162:): foreach my $field (@fields) {
2163:): if ($possfield{$field}) {
2164:): if ($field eq 'roles') {
2165:): foreach my $role (@courseroles) {
2166:): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2167:): if (($choice ne '') && ($posslti{$choice})) {
2168:): $ltitools{$itemid}{'roles'}{$role} = $choice;
2169:): if ($role eq 'cc') {
2170:): $ltitools{$itemid}{'roles'}{'co'} = $choice;
2171:): }
2172:): }
2173:): if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2174:): if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2175:): $haschanges{$itemid} = 1;
2176:): }
2177:): } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2178:): $haschanges{$itemid} = 1;
2179:): }
2180:): }
2181:): } else {
2182:): $ltitools{$itemid}{'fields'}{$field} = 1;
2183:): if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2184:): if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2185:): $haschanges{$itemid} = 1;
2186:): }
2187:): } else {
2188:): $haschanges{$itemid} = 1;
2189:): }
2190:): }
2191:): }
2192:): }
2193:): if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2194:): if ($ltitools{$itemid}{'fields'}{'user'}) {
2195:): if ($env{'form.ltitools_userincdom_'.$i}) {
2196:): $ltitools{$itemid}{'incdom'} = 1;
2197:): }
2198:): if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2199:): $haschanges{$itemid} = 1;
2200:): }
2201:): }
2202:): }
2203:): $allpos[$newpos] = $itemid;
2204:): }
2205:): if ($imgdeletions{$itemid}) {
2206:): $haschanges{$itemid} = 1;
2207:): if ($context eq 'course') {
2208:): my $currimgurl = $values->{$itemid}{'image'};
2209:): if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2210:): my ($path,$imagefile) = ($1,$2);
2211:): if ($imagefile =~ /^tn\-(.+)$/) {
2212:): my $origimg = $1;
2213:): &Apache::lonnet::removeuploadedurl("$path/$origimg");
2214:): }
2215:): &Apache::lonnet::removeuploadedurl($currimgurl);
2216:): }
2217:): }
2218:): #FIXME need to obsolete item in RES space
2219:): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2220:): my $currimgurl = $values->{$itemid}{'image'};
2221:): my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2222:): $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2223:): if ($imgurl) {
2224:): $ltitools{$itemid}{'image'} = $imgurl;
2225:): $haschanges{$itemid} = 1;
2226:): }
2227:): if ($error) {
2228:): &Apache::lonnet::logthis($error);
2229:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2230:): }
2231:): } elsif ($values->{$itemid}{'image'}) {
2232:): $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2233:): }
2234:): if ($customadds{$i}) {
2235:): my $name = $env{'form.ltitools_custom_name_'.$i};
2236:): $name =~ s/(`)/'/g;
2237:): $name =~ s/^\s+//;
2238:): $name =~ s/\s+$//;
2239:): my $value = $env{'form.ltitools_custom_value_'.$i};
2240:): $value =~ s/(`)/'/g;
2241:): $value =~ s/^\s+//;
2242:): $value =~ s/\s+$//;
2243:): if ($name ne '') {
2244:): $ltitools{$itemid}{'custom'}{$name} = $value;
2245:): $haschanges{$itemid} = 1;
2246:): }
2247:): }
2248:): my %customdels;
2249:): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2250:): if (@customdeletions) {
2251:): $haschanges{$itemid} = 1;
2252:): }
2253:): map { $customdels{$_} = 1; } @customdeletions;
2254:): if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2255:): foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2256:): unless ($customdels{$key}) {
2257:): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2258:): $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2259:): }
2260:): if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2261:): $haschanges{$itemid} = 1;
2262:): }
2263:): }
2264:): }
2265:): }
2266:): unless ($switchserver) {
2267:): my $keyitem = 'form.ltitools_key_'.$i;
2268:): $env{$keyitem} =~ s/(`)/'/g;
2269:): if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2270:): $haschanges{$itemid} = 1;
2271:): }
2272:): if ($env{$keyitem} ne '') {
2273:): $ltitools{$itemid}{'key'} = $env{$keyitem};
2274:): }
2275:): my $secretitem = 'form.ltitools_secret_'.$i;
2276:): $env{$secretitem} =~ s/(`)/'/g;
2277:): if ($values->{$itemid}{'usable'}) {
2278:): if ($env{'form.ltitools_changesecret_'.$i}) {
2279:): if ($env{$secretitem} ne '') {
2280:): if ($privnum && $cipher) {
2281:): $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2282:): $ltitools{$itemid}{'cipher'} = $privnum;
2283:): } else {
2284:): $ltitools{$itemid}{'secret'} = $env{$secretitem};
2285:): }
2286:): $haschanges{$itemid} = 1;
2287:): }
2288:): } else {
2289:): $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2290:): $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2291:): }
2292:): } elsif ($env{$secretitem} ne '') {
2293:): if ($privnum && $cipher) {
2294:): $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2295:): $ltitools{$itemid}{'cipher'} = $privnum;
2296:): } else {
2297:): $ltitools{$itemid}{'secret'} = $env{$secretitem};
2298:): }
2299:): $haschanges{$itemid} = 1;
2300:): }
2301:): }
2302:): unless ($haschanges{$itemid}) {
2303:): foreach my $key (keys(%{$values->{$itemid}})) {
2304:): if (ref($values->{$itemid}{$key}) eq 'HASH') {
2305:): if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2306:): foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2307:): unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2308:): $haschanges{$itemid} = 1;
2309:): last;
2310:): }
2311:): }
2312:): } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2313:): $haschanges{$itemid} = 1;
2314:): }
2315:): }
2316:): last if ($haschanges{$itemid});
2317:): }
2318:): }
2319:): }
2320:): }
2321:): }
2322:): if (@allpos > 0) {
2323:): my $idx = 0;
2324:): foreach my $itemid (@allpos) {
2325:): if ($itemid ne '') {
2326:): $ltitools{$itemid}{'order'} = $idx;
2327:): if (ref($values) eq 'HASH') {
2328:): if (ref($values->{$itemid}) eq 'HASH') {
2329:): if ($values->{$itemid}{'order'} ne $idx) {
2330:): $haschanges{$itemid} = 1;
2331:): }
2332:): }
2333:): }
2334:): $idx ++;
2335:): }
2336:): }
2337:): }
2338:): if (keys(%haschanges)) {
2339:): foreach my $entry (keys(%haschanges)) {
2340:): $changes->{$entry} = $ltitools{$entry};
2341:): }
2342:): if (ref($lastactref) eq 'HASH') {
2343:): $lastactref->{'courseltitools'} = 1;
2344:): }
2345:): }
2346:): return $errors;
2347:): }
2348:):
2349:): sub process_ltitools_image {
2350:): my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2351:): my $filename = $env{'form.'.$caller.'.filename'};
2352:): my ($error,$url);
2353:): my ($width,$height) = (21,21);
2354:): if ($configuserok eq 'ok') {
2355:): if ($switch) {
2356:): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2357:): $switch);
2358:): } elsif ($author_ok eq 'ok') {
2359:): my ($result,$imageurl,$madethumb);
2360:): if ($context eq 'domain') {
2361:): ($result,$imageurl,$madethumb) =
2362:): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2363:): "ltitools/$itemid/icon",$width,$height);
2364:): } else {
2365:): ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2366:): }
2367:): if ($result eq 'ok') {
2368:): if ($madethumb) {
2369:): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2370:): my $imagethumb = "$path/tn-".$imagefile;
2371:): $url = $imagethumb;
2372:): } else {
2373:): $url = $imageurl;
2374:): }
2375:): } else {
2376:): if ($context eq 'domain') {
2377:): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2378:): } else {
2379:): $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2380:): }
2381:): }
2382:): } else {
2383:): $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);
2384:): }
2385:): } else {
2386:): $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);
2387:): }
2388:): return ($url,$error);
2389:): }
2390:):
2391:): sub processlogo {
2392:): my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2393:): my ($result,$imageurl,$madethumb);
2394:): if ($env{"form.$caller.filename"} ne '') {
2395:): unless ($caller eq 'ltitools_add_image') {
2396:): if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2397:): my ($path,$imagefile) = ($1,$2);
2398:): if ($imagefile =~ /^tn\-(.+)$/) {
2399:): my $origimg = $1;
2400:): &Apache::lonnet::removeuploadedurl("$path/$origimg");
2401:): }
2402:): &Apache::lonnet::removeuploadedurl($currimg);
2403:): }
2404:): }
2405:): $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2406:): '','','',$cnum,$dom,$width,$height);
2407:): if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2408:): my ($path,$imagefile) = ($1,$2);
2409:): $result = 'ok';
2410:): my $thumburl = "$path/tn-".$imagefile;
2411:): my ($rtncode,$info);
2412:): my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2413:): if ($res eq 'ok') {
2414:): $madethumb = 1;
2415:): }
2416:): } elsif ($imageurl eq '/adm/notfound.html') {
2417:): undef($imageurl);
2418:): $result = 'store failed';
2419:): } elsif ($imageurl =~ /^error: (.+)$/) {
2420:): $result = $1;
2421:): }
2422:): }
2423:): return ($result,$imageurl,$madethumb);
2424:): }
2425:):
1.3 raeburn 2426: sub get_sec_str {
2427: my ($entry,$num) = @_;
2428: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2429: my $secstr;
2430: if (grep(/^\s*$/,@secs)) {
2431: $secstr = '';
2432: } elsif (@secs > 0) {
2433: $secstr = join(';',@secs);
2434: }
2435: if ($secstr ne '') {
2436: return '('.$secstr.')';
2437: }
2438: return;
2439: }
2440:
2441: sub check_clone {
2442: my ($clonedom,$disallowed,$clonename) = @_;
2443: return if (ref($disallowed) ne 'HASH');
2444: if ($clonedom !~ /^$match_domain$/) {
2445: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2446: return;
2447: } elsif (!&Apache::lonnet::domain($clonedom)) {
2448: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2449: return;
2450: }
2451: if ($clonename ne '') {
2452: if ($clonename !~ /^$match_username$/) {
2453: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2454: return;
2455: } else {
2456: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2457: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2458: return;
2459: }
2460: }
2461: }
2462: return 'ok';
2463: }
2464:
2465: sub store_changes {
1.9 raeburn 2466: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2467: my ($chome,$output);
1.49.2.28.2.1 (raeburn 2468:): my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2469: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.49.2.28.2.5 (raeburn 2470:: if (ref($values->{'linkprot'}) eq 'HASH') {
2471:: %oldlinkprot = %{$values->{'linkprot'}};
1.49.2.28.2.1 (raeburn 2472:: }
1.49.2.28.2.5 (raeburn 2473:: delete($values->{'linkprot'});
1.49.2.28.2.1 (raeburn 2474:): if (ref($values->{'ltitools'}) eq 'HASH') {
2475:): %oldltitools = %{$values->{'ltitools'}};
2476:): }
1.3 raeburn 2477: %storehash = %{$values};
2478: } else {
1.9 raeburn 2479: if ($crstype eq 'Community') {
2480: $output = &mt('No changes made to community settings.');
2481: } else {
2482: $output = &mt('No changes made to course settings.');
2483: }
2484: return $output;
1.3 raeburn 2485: }
1.49.2.28.2.1 (raeburn 2486:: my ($numchanges,$skipstore);
2487:: if (ref($changes) eq 'HASH') {
2488:: $numchanges = scalar(keys(%{$changes}));
1.49.2.28.2.5 (raeburn 2489:: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.49.2.28.2.1 (raeburn 2490:: $skipstore = 1;
2491:): } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2492:): $skipstore = 1;
2493:: } elsif (!$numchanges) {
2494:: if ($crstype eq 'Community') {
2495:: $output = &mt('No changes made to community settings.');
2496:: } else {
2497:: $output = &mt('No changes made to course settings.');
2498:: }
2499:: return $output;
2500:: }
2501:: }
1.3 raeburn 2502: my %yesno = (
2503: hidefromcat => '1',
2504: problem_stream_switch => '1',
2505: suppress_tries => '1',
2506: disableexampointprint => '1',
2507: hideemptyrows => '1',
2508: suppress_embed_prompt => '1',
2509: );
2510: foreach my $item (@{$prefs_order}) {
2511: if (grep(/^\Q$item\E$/,@{$actions})) {
2512: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2513: if (ref($changes->{$item}) eq 'HASH') {
1.49.2.28.2.3 (raeburn 2514:: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2515: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2516: if ($item eq 'other') {
2517: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2518: $storehash{$key} = $changes->{$item}{$key};
2519: if ($changes->{$item}{$key} eq '') {
2520: push(@delkeys,$key);
1.22 wenzelju 2521: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2522: } else {
1.22 wenzelju 2523: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2524: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2525: }
2526: }
1.49.2.28.2.5 (raeburn 2527:: } elsif ($item eq 'linkprot') {
2528:: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.49.2.28.2.1 (raeburn 2529:): } elsif ($item eq 'ltitools') {
2530:): $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2531: } else {
2532: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2533: my @settings = @{$prefs->{$item}->{'ordered'}};
2534: if ($item eq 'feedback') {
2535: push(@settings,(map { $_.'.text'; } @settings));
2536: }
2537: foreach my $key (@settings) {
2538: if ($key eq 'rolenames') {
2539: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2540: my $msg;
1.9 raeburn 2541: my @roles;
2542: if ($crstype eq 'Community') {
2543: @roles = ('co');
2544: } else {
2545: @roles = ('cc');
2546: }
2547: push(@roles,('in','ta','ep','ad','st'));
2548: foreach my $role (@roles) {
1.3 raeburn 2549: next if (!exists($changes->{$item}{$key.'_'.$role}));
2550: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2551: my $newname = $changes->{$item}{$key.'_'.$role};
2552: $storehash{$role.'.plaintext'} = $newname;
2553: if ($newname eq '') {
2554: $newname = $stdname;
2555: }
2556: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2557: "'<b>".$newname."</b>'").'</li>';
2558: }
2559: if ($msg ne '') {
1.22 wenzelju 2560: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2561: }
1.49.2.28.2.1 (raeburn 2562:): } elsif ($key eq 'timezone') {
2563:): next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2564:): my ($displayname,$text);
2565:): $text = $prefs->{$item}->{'itemtext'}{$key};
2566:): my $displayval;
2567:): if (exists($changes->{$item}{$key})) {
2568:): $displayname = &mt($text);
2569:): $storehash{$key} = $changes->{$item}{$key};
2570:): if ($changes->{$item}{$key} ne '') {
2571:): $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2572:): } else {
2573:): push(@delkeys,$key);
2574:): if (exists($values->{'tzover'})) {
2575:): push(@delkeys,'tzover');
2576:): }
2577:): $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2578:): '<i>'.$displayname.'</i>')).'</li>';
2579:): }
2580:): }
2581:): unless (grep(/^\Q$key\E$/,@delkeys)) {
2582:): if (exists($changes->{$item}{'tzover'})) {
2583:): $storehash{'tzover'} = $changes->{$item}{'tzover'};
2584:): my $tzovertext;
2585:): if ($changes->{$item}{'tzover'} ne '') {
2586:): $tzovertext = &mt('Course Time Zone overrides individual user preference');
2587:): } else {
2588:): push(@delkeys,'tzover');
2589:): $tzovertext = &mt('Course Time Zone does not override individual user preference');
2590:): }
2591:): if ($displayval eq '') {
2592:): $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2593:): } else {
2594:): $displayval .= '<br />'.(' 'x5).$tzovertext;
2595:): }
2596:): }
2597:): if ($displayval ne '') {
2598:): $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2599:): '<i>'.$displayname.'</i>',$displayval)).'</li>';
2600:): }
2601:): }
1.3 raeburn 2602: } else {
2603: next if (!exists($changes->{$item}{$key}));
2604: my ($displayname,$text);
2605: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2606: my $displayval;
1.49.2.28.2.1 (raeburn 2607:): unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2608: $displayval = $changes->{$item}{$key};
2609: }
1.49.2.28.2.1 (raeburn 2610:): if (($item eq 'grading') && ($key eq 'grading')) {
2611:): if ($displayval eq 'standard') {
2612:): my $hidetotals;
2613:): if (exists($changes->{$item}{'hidetotals'})) {
2614:): if ($changes->{$item}{'hidetotals'} eq '') {
2615:): if (exists($values->{'hidetotals'})) {
2616:): push(@delkeys,'hidetotals');
2617:): }
2618:): } else {
2619:): $hidetotals = $changes->{$item}{'hidetotals'};
2620:): }
2621:): } elsif (exists($values->{'hidetotals'})) {
2622:): $hidetotals = $values->{'hidetotals'};
2623:): }
2624:): if ($hidetotals eq '') {
2625:): $displayval = &mt('standard with "hide course totals" set to "No"');
2626:): if (exists($values->{'hidetotals'})) {
2627:): push(@delkeys,'hidetotals');
2628:): }
2629:): } elsif ($hidetotals =~ /^([\w,]+)$/) {
2630:): my $secstr = $1;
2631:): my @secs = split(/,/,$secstr);
2632:): if (grep(/^all$/,@secs)) {
2633:): $displayval = &mt('standard with "hide course totals" set to "Yes" for all users');
2634:): $hidetotals = 'all';
2635:): } else {
2636:): $displayval = &mt('standard with "hide course totals" set to "Yes" for users in section(s): [_1]',join(', ',@secs));
2637:): }
2638:): $storehash{'hidetotals'} = $hidetotals;
2639:): }
2640:): } elsif (exists($values->{'hidetotals'})) {
2641:): push(@delkeys,'hidetotals');
2642:): }
2643:): }
1.3 raeburn 2644: if ($item eq 'feedback') {
2645: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2646: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2647: $displayname = &mt('Custom text for '.$text.' questions');
2648: } else {
2649: $displayname = &mt('Recipients of '.$text.' questions');
2650: }
2651: } elsif ($item eq 'discussion') {
2652: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2653: $displayname = &mt("$text (role-based)");
2654: if ($displayval ne '') {
2655: my @roles = split(',',$displayval);
2656: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2657: $displayval = join(', ',@roles);
2658: }
2659: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2660: $displayname = &mt("$text (specific user(s))");
2661: } else {
2662: if ($key eq 'allow_discussion_post_editing') {
2663: if ($displayval ne '') {
2664: my @roles = split(',',$displayval);
2665: my @longroles;
2666: foreach my $role (@roles) {
2667: my ($trole,$sec) = split(':',$role);
2668: my $rolename =
2669: &Apache::lonnet::plaintext($trole);
2670: if ($sec ne '') {
2671: $rolename .= ':'.$sec;
2672: }
2673: push(@longroles,$rolename);
2674: }
2675: $displayval = join(', ',@longroles);
2676: }
1.49.2.3 raeburn 2677: } elsif ($key eq 'discussion_post_fonts') {
2678: my ($classorder,$classtitles)=&discussion_vote_classes();
2679: my ($styleorder,$styleitems)=&discussion_vote_styles();
2680: my $count = 1;
2681: my $total = scalar(keys(%{$changes->{$item}}));
2682: foreach my $class (@{$classorder}) {
2683: $count ++;
2684: next unless ($changes->{$item}{$key.'_'.$class});
2685: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2686: my $showval = '';
2687: for (my $i=0; $i<@{$styleorder}; $i++) {
2688: if ($vals[$i] ne '') {
2689: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2690: }
2691: }
2692: if ($vals[3] ne '') {
2693: $showval .= $vals[3];
2694: }
2695: if ($showval ne '') {
2696: $displayval .= $classtitles->{$class}.':{ '.
2697: $showval.'}';
2698: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2699: } else {
2700: $displayval .= $classtitles->{$class}.': '.&mt('None');
2701: push(@delkeys,$key.'_'.$class);
2702: }
2703: unless ($count == $total) {
2704: $displayval .= (' 'x2);
2705: }
2706: }
1.3 raeburn 2707: }
2708: $displayname = &mt($text);
2709: }
2710: } elsif ($item eq 'spreadsheet') {
2711: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2712: my $sheettype = $1;
2713: if ($sheettype eq 'studentcalc') {
2714: &Apache::lonnet::expirespread('','','studentcalc');
2715: } else {
2716: &Apache::lonnet::expirespread('','','assesscalc');
2717: &Apache::lonnet::expirespread('','','studentcalc');
2718: }
2719: }
2720: $displayname = &mt($text);
1.49.2.28.2.1 (raeburn 2721:: } elsif ($item eq 'menuitems') {
2722:: unless ($changes->{$item}{$key} eq '') {
2723:: if ($key eq 'menudefault') {
2724:: $displayname = &mt('Default collection of menu items');
2725:: $displayval = &mt('Collection: [_1]',
2726:: $changes->{$item}{$key});
2727:: } elsif ($key eq 'menucollections') {
2728:: $displayval = &menucollections_display($changes->{$item}{$key});
2729:: }
2730:: }
1.3 raeburn 2731: } else {
2732: $displayname = &mt($text);
2733: }
2734: if (defined($yesno{$key})) {
1.14 raeburn 2735: $displayval = &mt('No');
1.3 raeburn 2736: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2737: $displayval = &mt('Yes');
1.3 raeburn 2738: }
2739: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2740: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2741: } elsif ($key eq 'categories') {
2742: $displayval = $env{'form.categories_display'};
1.49.2.28 raeburn 2743: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2744: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2745: if ($changes->{$item}{$key} eq '1') {
2746: $displayval = &mt('Yes');
2747: } elsif ($changes->{$item}{$key} eq '0') {
2748: $displayval = &mt('No');
2749: }
1.49.2.28.2.1 (raeburn 2750:): } elsif ($key eq 'extresource') {
2751:): if ($changes->{$item}{$key} eq 'iframe') {
2752:): $displayval = &mt('In iframe');
2753:): } else {
2754:): my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2755:): if ($selected eq 'tab') {
2756:): if ($reuse) {
2757:): $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2758:): "'<b>","</b>'",'<br />');
2759:): } else {
2760:): $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2761:): "'<b>","</b>'",'<br />');
2762:): }
2763:): } elsif ($selected eq 'window') {
2764:): if ($reuse) {
2765:): $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2766:): "'<b>","</b>'",'<br />');
2767:): } else {
2768:): $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2769:): "'<b>","</b>'",'<br />');
2770:): }
2771:): if (($width ne '') || ($height ne '')) {
2772:): if ($width ne '') {
2773:): $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2774:): }
2775:): if ($height ne '') {
2776:): $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2777:): }
2778:): }
2779:): }
2780:): }
1.14 raeburn 2781: }
1.25 raeburn 2782: if ($key eq 'co-owners') {
2783: if (ref($changes->{$item}{$key}) eq 'HASH') {
2784: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2785: foreach my $type ('co-owners','pendingco-owners') {
2786: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2787: if ($type eq 'pendingco-owners') {
2788: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2789: $displayname = &mt('Invited as co-owners, pending acceptance');
2790: }
2791: }
2792: if ($changes->{$item}{$key}{$type} eq '') {
2793: push(@delkeys,'internal.'.$type);
2794: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2795: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2796: '<i>'.$displayname.'</i>')).'</li>';
2797: }
2798: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2799: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2800: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2801: '<i>'.$displayname.'</i>',
2802: "'<b>$displayval</b>'")).'</li>';
2803: }
2804: }
2805: }
2806: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.49.2.26 raeburn 2807: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2808: $displayval = &mt('on');
1.49.2.26 raeburn 2809: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2810: $displayval = '';
2811: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.49.2.26 raeburn 2812: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2813: $displayval = &mt('off');
2814: }
2815: if ($displayval) {
2816: $displayname = &mt('Your co-ownership status');
2817: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2818: '<i>'.$displayname.'</i>',
2819: "'<b>$displayval</b>'")).'</li>';
2820: }
2821: }
2822: }
2823: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2824: push(@delkeys,$key);
1.49.2.28.2.1 (raeburn 2825:: if ($item eq 'menuitems') {
2826:: if ($key eq 'menudefault') {
2827:: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2828:: } elsif ($key eq 'menucollections') {
2829:: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2830:: }
2831:: } else {
2832:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2833:: '<i>'.$displayname.'</i>')).'</li>';
2834:: }
2835:: } elsif ($key eq 'menucollections') {
2836:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2837:: $displayval.'</li>';
1.3 raeburn 2838: } else {
1.49.2.28.2.1 (raeburn 2839:): unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2840:): $displayval = "'<b>$displayval</b>'";
2841:): }
1.22 wenzelju 2842: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.49.2.28.2.1 (raeburn 2843:): '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2844: if ($key eq 'url') {
2845: my $bkuptime=time;
2846: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2847: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2848: }
2849: $output .= '</li>';
2850: }
1.25 raeburn 2851: if ($key eq 'co-owners') {
2852: if (ref($changes->{$item}{$key}) eq 'HASH') {
2853: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2854: foreach my $type ('co-owners','pendingco-owners') {
2855: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2856: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2857: }
2858: }
2859: }
2860: } else {
1.49.2.3 raeburn 2861: unless ($key eq 'discussion_post_fonts') {
2862: $storehash{$key} = $changes->{$item}{$key};
2863: }
1.25 raeburn 2864: }
1.3 raeburn 2865: }
1.23 raeburn 2866: if ($key eq 'cloners') {
2867: # Get existing cloners
2868: my %clonenames =
2869: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2870: if ($clonenames{'cloners'} =~ /,/) {
2871: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2872: } else {
2873: $oldcloner[0] = $clonenames{'cloners'};
2874: }
2875: }
1.3 raeburn 2876: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2877: ($key eq 'hidefromcat') || ($key eq 'categories') ||
2878: ($key eq 'co-owners')) {
1.3 raeburn 2879: push(@need_env_update,$key);
2880: }
2881: }
2882: }
2883: }
2884: $output .= '</ul>';
2885: } else {
1.9 raeburn 2886: if ($crstype eq 'Community') {
1.46 raeburn 2887: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2888: } else {
1.46 raeburn 2889: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2890: }
1.3 raeburn 2891: }
2892: }
2893: }
2894: }
1.49.2.28.2.1 (raeburn 2895:: if ($skipstore) {
2896:: return $output;
2897:: }
1.3 raeburn 2898: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2899: if (ref($changes) eq 'HASH') {
2900: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2901: if (exists($changes->{'courseinfo'}{'cloners'})) {
2902: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2903: \@oldcloner);
2904: }
2905: }
2906: }
1.3 raeburn 2907: if (@delkeys) {
2908: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2909: $output .= '<br /><span class="LC_error">';
2910: if ($crstype eq 'Community') {
2911: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2912: } else {
2913: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2914: }
2915: $output .= '</span>';
1.14 raeburn 2916: } else {
2917: foreach my $key (@delkeys) {
2918: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
2919: }
1.3 raeburn 2920: }
2921: }
2922: if (@need_env_update) {
2923: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2924: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
2925: }
2926: &Apache::lonnet::coursedescription($env{'request.course.id'},
2927: {'freshen_cache' => 1});
2928: } else {
1.9 raeburn 2929: $output = '<span class="LC_error">';
2930: if ($crstype eq 'Community') {
2931: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
2932: } else {
2933: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
2934: }
2935: $output .= '</span>';
1.3 raeburn 2936: }
2937: return $output;
2938: }
2939:
1.49.2.28.2.5 (raeburn 2940:: sub store_linkprot {
2941:: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
2942:: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
2943:: if ($context eq 'domain') {
2944:: $ltiauth = 1;
2945:: $home = &Apache::lonnet::domain($cdom,'primary');
2946:: } else {
2947:: $home = &Apache::lonnet::homeserver($cnum,$cdom);
2948:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
2949:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
2950:: } else {
2951:: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
2952:: $ltiauth = $domdefs{'crsltiauth'};
2953:: }
2954:: }
2955:: if (ref($changes) eq 'HASH') {
2956:: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
2957:: if (ref($changes->{$id}) eq 'HASH') {
2958:: if (exists($changes->{$id}->{'key'})) {
2959:: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
2960:: delete($changes->{$id}->{'key'});
2961:: }
2962:: if (exists($changes->{$id}->{'secret'})) {
2963:: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
2964:: delete($changes->{$id}->{'secret'});
2965:: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
2966:: if (exists($oldlinkprot->{$id}{'usable'})) {
2967:: $changes->{$id}->{'usable'} = 1;
2968:: }
1.49.2.28.2.8 (raeburn 2969:: if (exists($oldlinkprot->{$id}{'cipher'})) {
2970:: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
2971:: }
1.49.2.28.2.5 (raeburn 2972:: }
2973:: }
2974:: }
2975:: }
2976:: my @ids=&Apache::lonnet::current_machine_ids();
2977:: if (keys(%ltienc) > 0) {
2978:: if ($context eq 'domain') {
2979:: foreach my $id (keys(%ltienc)) {
2980:: if (exists($ltienc{$id}{'secret'})) {
2981:: $changes->{$id}->{'usable'} = 1;
2982:: }
2983:: }
2984:: } else {
2985:: unless (($home eq 'no_host') || ($home eq '')) {
2986:: my $allowed;
2987:: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2988:: if ($allowed) {
2989:: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
2990:: foreach my $id (keys(%ltienc)) {
2991:: if (exists($ltienc{$id}{'secret'})) {
2992:: $changes->{$id}->{'usable'} = 1;
2993:: }
2994:: }
2995:: } else {
2996:: $lti_save_error = 1;
2997:: }
2998:: }
2999:: }
3000:: }
3001:: }
3002:: unless ($lti_save_error) {
3003:: if ($context eq 'course') {
3004:: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3005:: my $hashid=$cdom.'_'.$cnum;
3006:: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
3007:: unless (($home eq 'no_host') || ($home eq '')) {
3008:: if (grep(/^\Q$home\E$/,@ids)) {
3009:: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3010:: }
3011:: }
3012:: } else {
3013:: $lti_save_error = 1;
3014:: }
3015:: }
3016:: unless ($lti_save_error) {
3017:: foreach my $id (sort { $a <=> $b } %{$changes}) {
3018:: if (ref($changes->{$id}) eq 'HASH') {
3019:: my %values = %{$changes->{$id}};
3020:: my %desc = &linkprot_names();
3021:: my $display;
1.49.2.28.2.1 (raeburn 3022:): foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.49.2.28.2.5 (raeburn 3023:: if (($title eq 'key') || ($title eq 'secret')) {
3024:: if (ref($ltienc{$id}) eq 'HASH') {
3025:: if (exists($ltienc{$id}{$title})) {
3026:: if ($title eq 'secret') {
3027:: my $length = length($ltienc{$id}{$title});
3028:: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
3029:: } else {
3030:: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3031:: }
3032:: }
3033:: }
3034:: } elsif ($title eq 'version') {
3035:: if ($values{$title} eq 'LTI-1p0') {
3036:: $display .= $desc{$title}.': 1.1, ';
3037:: }
1.49.2.28.2.1 (raeburn 3038:): } elsif ($title eq 'returnurl') {
3039:): if ($values{$title}) {
3040:): $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
3041:): }
3042:): } elsif ($title eq 'passbackformat') {
3043:): if ($values{$title} eq '1.0') {
3044:): $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
3045:): } elsif ($values{$title} eq '1.1') {
3046:): $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
3047:): }
1.49.2.28.2.5 (raeburn 3048:: } else {
3049:: $display .= $desc{$title}.': '.$values{$title}.', ';
3050:: }
3051:: }
3052:: if ($ltiauth) {
3053:: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3054:: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3055:: $display .= &mt('Source of username: Email address [_1]',
3056:: '(lis_person_contact_email_primary)').', ';
3057:: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3058:: $display .= &mt('Source of username: User ID [_1]',
3059:: '(lis_person_sourcedid)').', ';
3060:: } else {
3061:: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3062:: }
3063:: if ($values{'notstudent'} eq 'auth') {
3064:: $display .= &mt('Display LON-CAPA login page if no match').', ';
3065:: } elsif ($values{'notstudent'} eq 'reject') {
3066:: $display .= &mt('Discontinue launch if no match').', ';
3067:: }
3068:: }
3069:: }
3070:: $display =~ s/, $//;
3071:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3072:: "'$display'")).'</li>';
3073:: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3074:: my $oldname = $oldlinkprot->{$id}{'name'};
3075:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3076:: }
3077:: }
3078:: } else {
3079:: $lti_save_error = 1;
3080:: }
3081:: }
3082:: unless ($lti_save_error) {
3083:: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3084:: unless (ref($changes->{$id}) eq 'HASH') {
3085:: push(@deletions,$id);
3086:: }
3087:: }
3088:: if (@deletions) {
3089:: if ($context eq 'course') {
3090:: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3091:: }
3092:: }
3093:: }
3094:: if ($lti_save_error) {
3095:: $output .= '<li>'.
3096:: '<span class="LC_error">'.
3097:: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3098:: '</span>'.
3099:: '</li>';
3100:: }
3101:: return $output;
3102:: }
3103::
1.49.2.28.2.1 (raeburn 3104:): sub store_ltitools {
3105:): my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3106:): my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3107:): my %lt = <itools_names();
3108:): my @courseroles = ('cc','in','ta','ep','st');
3109:): my @allfields = ('fullname','firstname','lastname','email','user','roles');
3110:): if ($context eq 'domain') {
3111:): $home = &Apache::lonnet::domain($cdom,'primary');
3112:): } else {
3113:): $home = &Apache::lonnet::homeserver($cnum,$cdom);
3114:): }
3115:): if (ref($changes) eq 'HASH') {
3116:): foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3117:): if (ref($changes->{$id}) eq 'HASH') {
3118:): if (exists($changes->{$id}->{'key'})) {
3119:): $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3120:): delete($changes->{$id}->{'key'});
3121:): }
3122:): if (exists($changes->{$id}->{'secret'})) {
3123:): $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3124:): delete($changes->{$id}->{'secret'});
3125:): } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3126:): if (exists($oldltitools->{$id}{'usable'})) {
3127:): $changes->{$id}->{'usable'} = 1;
3128:): }
3129:): if (exists($oldltitools->{$id}{'cipher'})) {
3130:): $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3131:): }
3132:): }
3133:): }
3134:): }
3135:): }
3136:): my @ids=&Apache::lonnet::current_machine_ids();
3137:): if (keys(%toolsenc) > 0) {
3138:): unless (($home eq 'no_host') || ($home eq '')) {
3139:): my $allowed;
3140:): foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3141:): if ($allowed) {
3142:): if (($context eq 'domain') ||
3143:): (($context eq 'course') &&
3144:): (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3145:): foreach my $id (keys(%toolsenc)) {
3146:): if (exists($toolsenc{$id}{'secret'})) {
3147:): $changes->{$id}->{'usable'} = 1;
3148:): }
3149:): }
3150:): } else {
3151:): $ltitools_save_error = 1;
3152:): }
3153:): }
3154:): }
3155:): }
3156:): unless ($ltitools_save_error) {
3157:): if ($context eq 'course') {
3158:): if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3159:): my $hashid=$cdom.'_'.$cnum;
3160:): &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3161:): unless (($home eq 'no_host') || ($home eq '')) {
3162:): if (grep(/^\Q$home\E$/,@ids)) {
3163:): &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
3164:): }
3165:): }
3166:): } else {
3167:): $ltitools_save_error = 1;
3168:): }
3169:): }
3170:): unless ($ltitools_save_error) {
3171:): my %bynum;
3172:): foreach my $itemid (sort(keys(%{$changes}))) {
3173:): my $position = $changes->{$itemid}{'order'};
3174:): $bynum{$position} = $itemid;
3175:): }
3176:): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3177:): my $itemid = $bynum{$pos};
3178:): if (ref($changes->{$itemid}) ne 'HASH') {
3179:): $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3180:): } else {
3181:): $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3182:): if ($changes->{$itemid}{'image'}) {
3183:): $output .= ' '.
3184:): '<img src="'.$changes->{$itemid}{'image'}.'"'.
3185:): ' alt="'.&mt('Tool Provider icon').'" />';
3186:): }
3187:): $output .= '</li><ul>';
3188:): my $position = $pos + 1;
3189:): $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3190:): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3191:): if ($changes->{$itemid}{$item} ne '') {
3192:): $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3193:): }
3194:): }
3195:): if (ref($toolsenc{$itemid}) eq 'HASH') {
3196:): foreach my $item ('key','secret') {
3197:): if (exists($toolsenc{$itemid}{$item})) {
3198:): if ($item eq 'secret') {
3199:): $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3200:): } else {
3201:): $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3202:): }
3203:): }
3204:): }
3205:): }
3206:): $output .= '<li>'.&mt('Configurable in course:');
3207:): my @possconfig = ('label','title','target','linktext','explanation','append');
3208:): my $numconfig = 0;
3209:): if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3210:): foreach my $item (@possconfig) {
3211:): if ($changes->{$itemid}{'crsconf'}{$item}) {
3212:): $numconfig ++;
3213:): $output .= ' "'.$lt{'crs'.$item}.'"';
3214:): }
3215:): }
3216:): }
3217:): if (!$numconfig) {
3218:): $output .= ' '.&mt('None');
3219:): }
3220:): $output .= '</li>';
3221:): foreach my $item ('passback','roster') {
3222:): $output .= '<li>'.$lt{$item}.' ';
3223:): if ($changes->{$itemid}{$item}) {
3224:): $output .= &mt('Yes');
3225:): if ($changes->{$itemid}{$item.'valid'}) {
3226:): if ($item eq 'passback') {
3227:): $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3228:): $changes->{$itemid}{$item.'valid'});
3229:): } else {
3230:): $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3231:): $changes->{$itemid}{$item.'valid'});
3232:): }
3233:): }
3234:): } else {
3235:): $output .= &mt('No');
3236:): }
3237:): $output .= '</li>';
3238:): }
3239:): if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3240:): my $displaylist;
3241:): if ($changes->{$itemid}{'display'}{'target'}) {
3242:): $displaylist = &mt('Display target').': '.
3243:): $changes->{$itemid}{'display'}{'target'}.',';
3244:): }
3245:): foreach my $size ('width','height') {
3246:): if ($changes->{$itemid}{'display'}{$size}) {
3247:): $displaylist .= (' 'x2).$lt{$size}.': '.
3248:): $changes->{$itemid}{'display'}{$size}.',';
3249:): }
3250:): }
3251:): if ($displaylist) {
3252:): $displaylist =~ s/,$//;
3253:): $output .= '<li>'.$displaylist.'</li>';
3254:): }
3255:): foreach my $item ('linktext','explanation') {
3256:): if ($changes->{$itemid}{'display'}{$item}) {
3257:): $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3258:): }
3259:): }
3260:): }
3261:): if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3262:): my $fieldlist;
3263:): foreach my $field (@allfields) {
3264:): if ($changes->{$itemid}{'fields'}{$field}) {
3265:): $fieldlist .= (' 'x2).$lt{$field}.',';
3266:): }
3267:): }
3268:): if ($fieldlist) {
3269:): $fieldlist =~ s/,$//;
3270:): if ($changes->{$itemid}{'fields'}{'user'}) {
3271:): if ($changes->{$itemid}{'incdom'}) {
3272:): $fieldlist .= ' ('.&mt('username:domain').')';
3273:): } else {
3274:): $fieldlist .= ' ('.&mt('username').')';
3275:): }
3276:): }
3277:): $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3278:): }
3279:): }
3280:): if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3281:): my $rolemaps;
3282:): foreach my $role (@courseroles) {
3283:): if ($changes->{$itemid}{'roles'}{$role}) {
3284:): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3285:): $changes->{$itemid}{'roles'}{$role}.',';
3286:): }
3287:): }
3288:): if ($rolemaps) {
3289:): $rolemaps =~ s/,$//;
3290:): $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3291:): }
3292:): }
3293:): if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3294:): my $customlist;
3295:): if (keys(%{$changes->{$itemid}{'custom'}})) {
3296:): foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3297:): $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3298:): }
3299:): }
3300:): if ($customlist) {
3301:): $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3302:): }
3303:): }
3304:): $output .= '</ul></li>';
3305:): }
3306:): }
3307:): }
3308:): }
3309:): return $output;
3310:): }
3311:):
1.3 raeburn 3312: sub update_env {
3313: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3314: my $count = 0;
3315: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3316: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3317: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3318: foreach my $key (@{$need_env_update}) {
3319: if ($key eq 'description' && defined($storehash->{$key})) {
3320: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3321: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3322: $count ++;
3323: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3324: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3325: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3326: $count ++;
1.25 raeburn 3327: } elsif ($key eq 'co-owners') {
3328: if ($storehash->{'internal.co-owners'} ne '') {
3329: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3330: }
3331: if ($storehash->{'internal.pendingco-owners'} ne '') {
3332: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3333: }
3334: my @coowners = split(',',$storehash->{'internal.'.$key});
3335: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3336: $count ++;
1.3 raeburn 3337: }
3338: }
3339: if ($count) {
3340: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3341: }
3342: }
3343: }
3344: return;
3345: }
3346:
3347: sub display_disallowed {
1.9 raeburn 3348: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3349: my $output;
3350: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3351: if (keys(%{$disallowed})) {
3352: if ($item eq 'cloners') {
3353: my @fails;
3354: my %lt = &Apache::lonlocal::texthash (
3355: format => 'Invalid format',
3356: domain => 'Domain does not exist',
3357: newuser => 'LON-CAPA user(s) do(es) not exist.',
3358: );
3359: foreach my $error ('format','domain','newuser') {
3360: if (defined($disallowed->{$error})) {
3361: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3362: $lt{$error};
3363: if ($error eq 'newuser') {
1.9 raeburn 3364: $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 3365: }
3366: push(@fails,$msg);
3367: }
3368: }
3369: if (@fails) {
3370: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3371: '</span>'.join('; ',@fails).'.<br />';
3372: }
3373: } elsif ($item eq 'rolenames') {
3374: my %lt = &Apache::lonlocal::texthash (
3375: replacements => 'Name already used to replace a different standard role name',
3376: regulars => 'Name already used as a standard role name',
3377: customrole => 'Name already used as the name of a custom role',
3378: );
3379: my @fails;
3380: foreach my $error ('replacements','regulars','customrole') {
3381: if (ref($disallowed->{$error}) eq 'ARRAY') {
3382: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3383: '</b>, '.&mt('reason').' - '.$lt{'error'});
3384: }
3385: }
3386: if (@fails) {
3387: $output .= '<span class="LC_warning">'.
3388: &mt('Unable to include amongst replacements for role names: ').
3389: '</span>'.join('; ',@fails).'.<br />';
3390: }
3391:
3392: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3393: $output .= '<span class="LC_warning">';
3394: if ($item eq 'feedback') {
1.9 raeburn 3395: if ($crstype eq 'Community') {
3396: $output .= &mt('Unable to include as a recipient of community feedback for:');
3397: } else {
3398: $output .= &mt('Unable to include as a recipient of course feedback for:');
3399: }
1.3 raeburn 3400: } elsif ($item eq 'discussion') {
3401: $output .= &mt('Unable to include in user-based access control for:');
3402: } elsif ($item eq 'localization') {
1.9 raeburn 3403: if ($crstype eq 'Community') {
3404: $output .= &mt('Unable to include in community localization:');
3405: } else {
3406: $output .= &mt('Unable to include in course localization:');
3407: }
1.3 raeburn 3408: }
3409: $output .= '</span><ul>';
3410: foreach my $key (sort(keys(%{$disallowed}))) {
3411: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3412: $output .= '<li><i>'.$itemtext.'</i> - ';
3413: if ($item eq 'localization') {
3414: $output .= &mt('reason - unsupported language: [_1]',
3415: '<b>'.$disallowed->{$key}.'</b>');
3416: } else {
3417: $output .= &mt('reason - invalid user: [_1]',
3418: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3419: }
3420: }
3421: $output .= '</ul><br />';
3422: }
3423: }
1.1 raeburn 3424: }
1.3 raeburn 3425: return $output;
1.1 raeburn 3426: }
3427:
3428: sub get_course {
3429: my ($courseid) = @_;
3430: if (!defined($courseid)) {
3431: $courseid = $env{'request.course.id'};
3432: }
3433: my $cdom=$env{'course.'.$courseid.'.domain'};
3434: my $cnum=$env{'course.'.$courseid.'.num'};
1.49.2.14 raeburn 3435: my $chome=$env{'course.'.$courseid.'.home'};
3436: return ($cnum,$cdom,$chome);
1.1 raeburn 3437: }
3438:
3439: sub get_jscript {
1.49.2.28.2.1 (raeburn 3440:: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3441: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.49.2.28.2.1 (raeburn 3442:): my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3443: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3444: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3445: my $cloners_js = &cloners_javascript($phase);
1.49.2.28.2.1 (raeburn 3446:): my $currltitools;
3447:): if (ref($settings) eq 'HASH') {
3448:): $currltitools = $settings->{'ltitools'};
3449:): }
3450:): my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.49.2.18 raeburn 3451: my @code_order;
3452: if ($crstype ne 'Community') {
3453: if (ref($settings) eq 'HASH') {
3454: my %codedefaults;
3455: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3456: \@code_order);
3457: if (@code_order > 0) {
3458: if ($phase eq 'display') {
3459: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3460: if (grep(/^courseinfo$/,@actions)) {
3461: if ($settings->{'cloners'} ne '') {
3462: unless ($settings->{'cloners'} eq '*') {
3463: my @cloners = split(/,/,$settings->{'cloners'});
3464: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3465: my %local_to_standard;
3466: for (my $i=0; $i<@code_order; $i++) {
3467: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3468: }
3469: foreach my $cloner (@cloners) {
3470: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
3471: ($cloner !~ /^$match_username\:$match_domain$/)) {
3472: foreach my $item (split(/\&/,$cloner)) {
3473: my ($key,$val) = split(/\=/,$item);
3474: $val = &unescape($val);
3475: foreach my $code (@code_order) {
3476: if ($key eq $local_to_standard{$code}) {
3477: $env{'form.'.$key} = $val;
3478: }
3479: }
3480: }
3481: }
3482: }
3483: }
3484: }
3485: }
3486: }
3487: my @codetitles;
3488: (undef,$instcode_js) =
3489: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3490: \@codetitles);
3491: $instcode_js .= <<ENDSCRIPT;
3492: function toggleCloners(callerradio) {
3493: if (document.getElementById('LC_cloners_instcode')) {
3494: if (callerradio.value == 1) {
3495: document.getElementById('LC_cloners_instcode').style.display = "block";
3496: } else {
3497: uncheckOfficialLists();
3498: document.getElementById('LC_cloners_instcode').style.display = "none";
3499: }
3500: }
3501: }
3502:
3503: if (!document.getElementsByClassName) {
3504: function getElementsByClassName(node, classname) {
3505: var a = [];
3506: var re = new RegExp('(^| )'+classname+'( |$)');
3507: var els = node.getElementsByTagName("*");
3508: for(var i=0,j=els.length; i<j; i++)
3509: if(re.test(els[i].className))a.push(els[i]);
3510: return a;
3511: }
3512: }
3513:
3514: function uncheckOfficialLists() {
3515: var codepicks;
3516: if (document.getElementsByClassName) {
3517: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3518: } else {
3519: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3520: }
3521: if (codepicks.length) {
3522: for (var i=0; i<codepicks.length; i++) {
3523: codepicks[i].selectedIndex = 0;
3524: }
3525: }
3526: }
3527:
3528: ENDSCRIPT
3529: }
3530: }
3531: }
1.1 raeburn 3532: if ($can_categorize) {
3533: $categorize_js = <<ENDSCRIPT;
3534: function catsbrowser() {
3535: var catswin = null;
3536: var url = '/adm/courseprefs?phase=categorizecourse';
3537: if (!catswin || catswin.closed) {
3538: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3539: } else {
3540: catswin.focus();
3541: }
3542: }
3543: ENDSCRIPT
3544: }
1.36 raeburn 3545: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3546: if ($loncaparev) {
3547: $loncaparev_js = <<ENDSCRIPT;
3548: function loncaparevinfo() {
3549: var lcrevwin = null;
3550: var url = '/adm/courseprefs?phase=releaseinfo';
3551: if (!lcrevwin || lcrevwin.closed) {
3552: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3553: } else {
3554: lcrevwin.focus();
3555: }
3556: }
3557: ENDSCRIPT
3558: }
1.49.2.10 raeburn 3559: my $cnum = $env{'course.'.$cid.'.num'};
3560: my $syllabus_js = <<ENDSCRIPT;
3561: function syllabusinfo() {
3562: var syllwin = null;
3563: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3564: if (!syllwin || syllwin.closed) {
3565: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3566: } else {
3567: syllwin.focus();
3568: }
3569: }
3570: ENDSCRIPT
1.49.2.28.2.1 (raeburn 3571:): my ($menuitems_js,$grading_js);
3572:: unless ($noedit) {
3573:: my $collections;
3574:: my $next = 1;
3575:: if (ref($settings) eq 'HASH') {
3576:: if ($settings->{'menucollections'} ne '') {
3577:: my @current;
3578:: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3579:: my ($num) = split(/\%/,$item);
3580:: if ($num =~ /^\d+$/) {
3581:: push(@current,$num);
3582:: }
3583:: }
3584:: $collections = join("','",sort { $a <=> $b } @current);
3585:: if ($collections) {
3586:: $collections = "'$collections'";
3587:: }
3588:: $next += $current[-1];
3589:: }
3590:: }
3591:: my $deftext = &mt('Standard (all menus shown)');
3592:: $menuitems_js = <<ENDSCRIPT;
3593:: function toggleAddmenucoll() {
3594:: if (document.getElementById('menucollections_add')) {
3595:: var state = 'none';
3596:: var add = document.getElementById('menucollections_add').checked;
3597:: if (add) {
3598:: state = 'inline-block';
3599:: }
3600:: var fieldsets = new Array('shown','text','links','list','inline');
3601:: for (var i=0; i<fieldsets.length; i++) {
3602:: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3603:: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3604:: }
3605:: }
3606:: var box = document.getElementsByClassName('LC_menucoll_add');
3607:: if (box.length) {
3608:: for (var i=0; i<box.length; i++) {
3609:: if (add) {
3610:: box[i].checked = true;
3611:: } else {
3612:: box[i].checked = false;
3613:: }
3614:: }
3615:: }
3616:: if (document.getElementById('menudefault')) {
3617:: var menudef = document.getElementById('menudefault');
3618:: var currsel = menudef.selectedIndex;
3619:: var colls = new Array($collections);
3620:: menudef.options.length = 0;
3621:: if (!add) {
3622:: if (currsel == 1 + colls.length) {
3623:: currsel = 0;
3624:: }
3625:: }
3626:: if (currsel == 0) {
3627:: menudef.options[0] = new Option('$deftext','',true,true);
3628:: } else {
3629:: menudef.options[0] = new Option('$deftext','',false,false);
3630:: }
3631:: if (colls.length) {
3632:: for (var i=0; i<colls.length; i++) {
3633:: var idx = i+1;
3634:: if (currsel == colls[i]) {
3635:: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3636:: } else {
3637:: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3638:: }
3639:: }
3640:: }
3641:: if (add) {
3642:: var addidx = 1 + colls.length;
3643:: if (currsel == addidx) {
3644:: menudef.options[addidx] = new Option('$next','$next',true,true);
3645:: } else {
3646:: menudef.options[addidx] = new Option('$next','$next',false,false);
3647:: }
3648:: }
3649:: }
3650:: }
3651:: }
3652:: ENDSCRIPT
3653:): $grading_js = <<"ENDSCRIPT";
3654:): function toggleGrading(form) {
3655:): if (document.getElementById('hidetotalsdiv')) {
3656:): var totalsdivid = document.getElementById('hidetotalsdiv');
3657:): var selname = form.elements['grading'];
3658:): if (selname) {
3659:): var current = selname.options[selname.selectedIndex].value
3660:): if (current == 'standard') {
3661:): totalsdivid.style.display = 'inline-block';
3662:): } else {
3663:): totalsdivid.style.display = 'none';
3664:): }
3665:): }
3666:): }
3667:): return;
3668:): }
3669:):
3670:): function toggleHiddenTotalsSec(form) {
3671:): if (document.getElementById('sectotalsdiv')) {
3672:): var sectotalsdivid = document.getElementById('sectotalsdiv');
3673:): var radioname = form.elements['hidetotals'];
3674:): if (radioname) {
3675:): if (radioname.length > 0) {
3676:): var setvis;
3677:): for (var i=0; i<radioname.length; i++) {
3678:): if (radioname[i].checked == true) {
3679:): if (radioname[i].value == 1) {
3680:): sectotalsdivid.style.display = 'inline-block';
3681:): setvis = 1;
3682:): }
3683:): break;
3684:): }
3685:): }
3686:): if (!setvis) {
3687:): sectotalsdivid.style.display = 'none';
3688:): }
3689:): }
3690:): }
3691:): }
3692:): return;
3693:): }
3694:): ENDSCRIPT
3695:: }
3696:): $extresource_js = <<"ENDSCRIPT";
3697:): function toggleExtRes() {
3698:): if (document.getElementById('LC_extresource')) {
3699:): var extressel = document.getElementById('LC_extresource').value;
3700:): if (document.getElementById('LC_extresreusediv')) {
3701:): var extresreuse = document.getElementById('LC_extresreusediv');
3702:): if (document.getElementById('LC_extressize')) {
3703:): var extressize = document.getElementById('LC_extressize');
3704:): var setvis;
3705:): if ((extressel == 'tab') || (extressel == 'window')) {
3706:): extresreuse.style.display = 'inline-block';
3707:): setvis = 1;
3708:): if (extressel == 'window') {
3709:): extressize.style.display = 'inline-block';
3710:): } else {
3711:): extressize.style.display = 'none';
3712:): }
3713:): }
3714:): if (!setvis) {
3715:): extresreuse.style.display = 'none';
3716:): extressize.style.display = 'none';
3717:): }
3718:): }
3719:): }
3720:): }
3721:): }
3722:): ENDSCRIPT
3723:): $localization_js = <<"ENDSCRIPT";
3724:): function toggleTimeZone() {
3725:): if (document.getElementById('LC_set_timezone')) {
3726:): var timezonesel = document.getElementById('LC_set_timezone').value;
3727:): if (document.getElementById('LC_tzoverdiv')) {
3728:): var tzoverdiv = document.getElementById('LC_tzoverdiv');
3729:): if (timezonesel == '') {
3730:): tzoverdiv.style.display = 'none';
3731:): } else {
3732:): tzoverdiv.style.display = 'block';
3733:): }
3734:): }
3735:): }
3736:): }
3737:): ENDSCRIPT
1.1 raeburn 3738: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.49.2.7 raeburn 3739: '// <![CDATA['."\n".
1.36 raeburn 3740: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.49.2.28.2.1 (raeburn 3741:): $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
3742:): $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
3743:): $grading_js."\n".&linkprot_javascript()."\n".'//]]>'."\n".
3744:): '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3745: return $jscript;
3746: }
3747:
1.3 raeburn 3748: sub cloners_javascript {
3749: my ($formname) = @_;
3750: return <<"ENDSCRIPT";
3751:
3752: function update_cloners(caller,num) {
3753: var delidx = getIndexByName('cloners_delete');
3754: var actidx = getIndexByName('cloners_activate');
3755: if (caller == 'cloners_all') {
3756: var selall;
3757: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3758: if (document.$formname.cloners_all[i].checked) {
3759: selall = document.$formname.cloners_all[i].value;
3760: }
3761: }
3762: if (selall == 1) {
3763: if (delidx != -1) {
3764: if (document.$formname.cloners_delete.length) {
3765: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3766: document.$formname.cloners_delete[j].checked = true;
3767: }
3768: } else {
3769: document.$formname.elements[delidx].checked = true;
3770: }
3771: }
3772: if (actidx != -1) {
3773: if (document.$formname.cloners_activate.length) {
3774: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3775: if (document.$formname.cloners_activate[i].value == '0') {
3776: document.$formname.cloners_activate[i].checked = false;
3777: }
1.49.2.18 raeburn 3778: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3779: document.$formname.cloners_activate[i].checked = true;
3780: }
3781: }
3782: }
3783: }
3784: document.$formname.cloners_newdom.selectedIndex = 0;
3785: }
3786: }
3787: if (caller == 'cloners_activate') {
3788: if (document.$formname.cloners_activate.length) {
3789: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3790: if (document.$formname.cloners_activate[j].value == num) {
3791: if (document.$formname.cloners_activate[j].checked) {
3792: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3793: if (document.$formname.cloners_all[i].value == '1') {
3794: document.$formname.cloners_all[i].checked = false;
3795: }
3796: if (document.$formname.cloners_all[i].value == '0') {
3797: document.$formname.cloners_all[i].checked = true;
3798: }
3799: }
3800: }
3801: }
3802: }
3803: } else {
3804: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3805: if (document.$formname.cloners_all[i].value == '1') {
3806: document.$formname.cloners_all[i].checked = false;
3807: }
3808: if (document.$formname.cloners_all[i].value == '0') {
3809: document.$formname.cloners_all[i].checked = true;
3810: }
3811: }
3812: }
3813: }
3814: return;
3815: }
3816:
3817: function getIndexByName(item) {
3818: for (var i=0;i<document.$formname.elements.length;i++) {
3819: if (document.$formname.elements[i].name == item) {
3820: return i;
3821: }
3822: }
3823: return -1;
3824: }
3825:
3826: ENDSCRIPT
3827: }
3828:
1.49.2.28.2.5 (raeburn 3829:: sub linkprot_javascript {
3830:: return <<"ENDSCRIPT";
1.49.2.28.2.1 (raeburn 3831:): function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.49.2.28.2.5 (raeburn 3832:: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3833:: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3834:: var itemname = form.elements['linkprot_'+item+'_'+num];
3835:: if (itemname) {
3836:: if (itemname.length > 0) {
3837:: var setvis;
3838:: for (var i=0; i<itemname.length; i++) {
3839:: if (itemname[i].checked == true) {
3840:: if (itemname[i].value == valon) {
3841:: extraid.style.display = styleon;
3842:: setvis = 1;
3843:: }
3844:: break;
3845:: }
3846:: }
3847:: if (!setvis) {
3848:: extraid.style.display = 'none';
3849:: }
3850:: }
3851:: }
3852:: }
3853:: return;
3854:: }
1.49.2.28.2.7 (raeburn 3855::
1.49.2.28.2.5 (raeburn 3856:: ENDSCRIPT
3857::
3858:: }
3859::
1.1 raeburn 3860: sub print_courseinfo {
1.49.2.21 raeburn 3861: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3862: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3863: return;
3864: }
1.49.2.22 raeburn 3865: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3866: if ($noedit) {
3867: $disabled = ' disabled="disabled"';
3868: }
1.1 raeburn 3869: my %domconf =
1.49.2.18 raeburn 3870: &Apache::lonnet::get_dom('configuration',
3871: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3872: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3873: $cathash = $domconf{'coursecategories'}{'cats'};
3874: if (ref($cathash) eq 'HASH') {
3875: $categoriesform =
3876: &Apache::loncommon::assign_categories_table($cathash,
1.49.2.22 raeburn 3877: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3878: }
3879: }
1.25 raeburn 3880: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3881: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3882: }
1.49.2.18 raeburn 3883: my ($currcanclone,@code_order,$cloner_instcode);
3884: my %codedefaults;
3885: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3886: \@code_order);
3887: if ($settings->{'cloners'}) {
3888: unless ($settings->{'cloners'} eq '*') {
3889: my @currclone = split(/,/,$settings->{'cloners'});
3890: foreach my $item (@currclone) {
3891: unless ($item eq '*') {
3892: if (($item !~ /\:/) && ($item =~ /=/)) {
3893: $cloner_instcode = 1;
3894: }
3895: }
3896: }
3897: }
3898: }
3899: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3900: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3901: if (ref($canclone) eq 'HASH') {
3902: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3903: if ($settings->{'internal.coursecode'}) {
3904: my @posscodes;
3905: if (@code_order > 0) {
3906: $currcanclone = 'instcode';
3907: foreach my $item (@{$canclone->{'instcode'}}) {
3908: if (grep(/^\Q$item\E$/,@code_order)) {
3909: push(@posscodes,$item);
3910: }
3911: }
3912: my $codestr = join(' + ',@posscodes);
3913: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3914: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3915: }
3916: }
3917: }
3918: } elsif ($canclone eq 'domain') {
3919: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
3920: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
3921: $currcanclone = 'domain';
3922: }
3923: if ($clonedefaults) {
3924: if ($settings->{'cloners'} ne '') {
3925: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
3926: } else {
3927: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
3928: }
3929: $clonedefaults = '<br /><br />'.$clonedefaults;
3930: }
3931: }
1.1 raeburn 3932: if (!defined($categoriesform)) {
1.15 raeburn 3933: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 3934: }
1.12 raeburn 3935: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.49.2.10 raeburn 3936: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 3937:
1.9 raeburn 3938: my $replace;
3939: if ($crstype eq 'Community') {
3940: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3941: } else {
3942: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3943: }
1.49.2.23 raeburn 3944: my ($editmap,$editsyllabus);
3945: unless ($noedit) {
3946: $editmap = (' 'x2).
3947: '<a href="javascript:openbrowser'.
3948: "('display','url','sequence')\">".
3949: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
3950: &mt('Modification may make assessment data inaccessible!').
3951: '</span>';
3952: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
3953: '</a>');
3954: }
1.1 raeburn 3955: my %items = (
1.3 raeburn 3956: 'url' => {
1.49.2.23 raeburn 3957: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 3958: input => 'textbox',
1.49.2.6 raeburn 3959: size => '55',
1.19 faziophi 3960: advanced => 1
1.1 raeburn 3961: },
3962: 'description' => {
1.3 raeburn 3963: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 3964: input => 'textbox',
1.49.2.6 raeburn 3965: size => '55',
1.1 raeburn 3966: },
1.24 raeburn 3967: 'owner' => {
3968: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
3969: },
1.25 raeburn 3970: 'co-owners' => {
3971: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
3972: },
1.49.2.11 raeburn 3973: 'clonedfrom' => {
3974: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
3975: },
1.1 raeburn 3976: 'courseid' => {
1.3 raeburn 3977: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
3978: &mt('internal, optional').')',
1.1 raeburn 3979: input => 'textbox',
3980: size => '25',
3981: },
1.49.2.12 raeburn 3982: 'uniquecode' => {
3983: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
3984: },
1.1 raeburn 3985: 'cloners' => {
1.3 raeburn 3986: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.49.2.18 raeburn 3987: &mt('Owner and Coordinators included automatically').
3988: $clonedefaults,
1.1 raeburn 3989: input => 'textbox',
1.41 www 3990: size => '40'
1.1 raeburn 3991: },
3992: 'rolenames' => {
1.3 raeburn 3993: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 3994: '('.$replace.')',
1.1 raeburn 3995: input => 'textbox',
3996: size => '20',
1.19 faziophi 3997: advanced => 1
1.1 raeburn 3998: },
1.49.2.24 raeburn 3999: 'syllabus' => {
4000: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.49.2.10 raeburn 4001: &mt('(Syllabus type in use)').(' ' x2).
1.49.2.23 raeburn 4002: $editsyllabus,
1.1 raeburn 4003: },
4004: 'hidefromcat' => {
1.3 raeburn 4005: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 4006: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
4007: input => 'radio',
4008: },
4009: 'categories' => {
1.3 raeburn 4010: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 4011: &mt('Display Categories').'</a>',
4012: input => 'textbox',
4013: size => '25',
4014: },
1.35 raeburn 4015: 'loncaparev' => {
4016: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
4017: },
1.49.2.6 raeburn 4018: 'defaultcredits' => {
4019: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4020: },
1.1 raeburn 4021: );
4022: my $datatable;
4023: my $count = 0;
4024: foreach my $item (@{$ordered}) {
1.49.2.7 raeburn 4025: my $colspan;
1.1 raeburn 4026: if ($item eq 'hidefromcat') {
4027: next if (!$can_toggle_cat);
4028: } elsif ($item eq 'categories') {
4029: next if (!$can_categorize);
1.49.2.12 raeburn 4030: } elsif ($item eq 'uniquecode') {
4031: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4032: }
1.49.2.7 raeburn 4033: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
4034: $colspan = 2;
4035: }
1.1 raeburn 4036: $count ++;
1.19 faziophi 4037: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.49.2.7 raeburn 4038: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4039: } else {
1.49.2.7 raeburn 4040: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4041: }
1.1 raeburn 4042: if ($items{$item}{input} eq 'radio') {
1.49.2.21 raeburn 4043: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4044: } elsif ($item eq 'cloners') {
4045: my $includeempty = 1;
4046: my $num = 0;
1.49.2.7 raeburn 4047: $datatable .= '</td><td align="right">'.
4048: &Apache::loncommon::start_data_table().
1.1 raeburn 4049: &Apache::loncommon::start_data_table_row().
4050: '<td><span class="LC_nobreak"><label>'.
4051: &mt('Any user in any domain:').
4052: ' <input type="radio" name="cloners_all" value="1" ';
4053: if ($settings->{$item} eq '*') {
4054: $datatable .= ' checked="checked" ';
4055: }
4056: $datatable .= 'onchange="javascript:update_cloners('.
1.49.2.21 raeburn 4057: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.49.2.18 raeburn 4058: (' 'x2).'<label>'.
4059: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4060: if ($settings->{$item} ne '*') {
4061: $datatable .= ' checked="checked" ';
4062: }
4063: $datatable .= ' onchange="javascript:update_cloners('.
1.49.2.21 raeburn 4064: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4065: &Apache::loncommon::end_data_table_row().
4066: &Apache::loncommon::end_data_table().
1.49.2.7 raeburn 4067: '<table><tr><td align="left"><b>'.&mt('Or').
4068: '</b></td></tr></table>'.
1.1 raeburn 4069: &Apache::loncommon::start_data_table();
4070: my @cloners;
4071: if ($settings->{$item} eq '') {
1.49.2.21 raeburn 4072: unless ($noedit) {
4073: my $default;
4074: if ($currcanclone eq 'domain') {
4075: $default = '0';
4076: }
4077: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.49.2.28.2.1 (raeburn 4078:): }
1.1 raeburn 4079: } elsif ($settings->{$item} ne '*') {
4080: my @entries = split(/,/,$settings->{$item});
4081: if (@entries > 0) {
4082: foreach my $entry (@entries) {
4083: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4084: if ($udom =~ /^$match_domain$/) {
4085: unless (&Apache::lonnet::domain($udom)) {
4086: next;
4087: }
4088: } else {
4089: next;
4090: }
1.1 raeburn 4091: if ($uname eq '*') {
4092: $datatable .=
4093: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4094: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4095: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4096: '</b><input type="hidden" name="cloners_dom_'.$num.
4097: '" value="'.$udom.'" /></span><br />'.
4098: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.49.2.21 raeburn 4099: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4100: &mt('Delete').'</label></span></td>'.
4101: &Apache::loncommon::end_data_table_row();
4102: $num ++;
1.23 raeburn 4103: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4104: unless (grep(/^\Q$entry\E$/,@cloners)) {
4105: push(@cloners,$entry);
4106: }
1.1 raeburn 4107: }
4108: }
4109: }
4110: }
4111: my $add_domtitle = &mt('Any user in additional domain:');
4112: if ($settings->{$item} eq '*') {
4113: $add_domtitle = &mt('Any user in specific domain:');
4114: } elsif ($settings->{$item} eq '') {
4115: $add_domtitle = &mt('Any user in other domain:');
4116: }
4117: my $cloners_str = join(',',@cloners);
4118: $datatable .= &Apache::loncommon::start_data_table_row().
4119: '<td align="left"><span class="LC_nobreak">'.
4120: $add_domtitle.'</span><br />'.
4121: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.49.2.21 raeburn 4122: $includeempty,undef,undef,
4123: undef,undef,$noedit).
1.1 raeburn 4124: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4125: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4126: &Apache::loncommon::end_data_table().
1.49.2.7 raeburn 4127: '<table><tr><td align="left"><b>'.&mt('And').
4128: '</b></td></tr></table>'.
1.1 raeburn 4129: &Apache::loncommon::start_data_table().
4130: &Apache::loncommon::start_data_table_row().
4131: '<td align="left">'.
4132: &mt('Specific users').' (<tt>'.
4133: &mt('user:domain,user:domain').'</tt>)<br />'.
4134: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.49.2.21 raeburn 4135: $items{$item}{'size'},$disabled).
1.1 raeburn 4136: '</td>'.&Apache::loncommon::end_data_table_row().
4137: &Apache::loncommon::end_data_table();
1.49.2.18 raeburn 4138: if (@code_order > 0) {
4139: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4140: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4141: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4142: \%cat_items,\@codetitles,
4143: \%cat_titles,\%cat_order);
4144: my $showncodes = 'off';
4145: my $checkedoff = ' checked="checked"';
4146: my $checkedon = '';
4147: if ($cloner_instcode) {
4148: $checkedon = $checkedoff;
4149: $checkedoff = '';
4150: $showncodes = 'on';
4151: }
4152: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4153: '</b></td></tr></table>'.
4154: &Apache::loncommon::start_data_table().
4155: &Apache::loncommon::start_data_table_row().
4156: '<td align="left"><span class="LC_nobreak">'.
4157: &mt('Cloning by official course(s) based on course category').(' 'x2).
4158: '<label>'.
1.49.2.21 raeburn 4159: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.49.2.18 raeburn 4160: (' ').
4161: '<label>'.
1.49.2.21 raeburn 4162: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.49.2.18 raeburn 4163: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4164: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.49.2.21 raeburn 4165: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.49.2.18 raeburn 4166: '</td>'.&Apache::loncommon::end_data_table_row().
4167: &Apache::loncommon::end_data_table();
4168: }
1.1 raeburn 4169: } elsif ($item eq 'rolenames') {
1.49.2.7 raeburn 4170: $datatable .= '</td><td align="right">'.
4171: &Apache::loncommon::start_data_table();
1.9 raeburn 4172: my @roles;
4173: if ($crstype eq 'Community') {
4174: @roles = ('co');
4175: } else {
4176: @roles = ('cc');
4177: }
4178: push (@roles,('in','ta','ep','ad','st'));
4179: foreach my $role (@roles) {
1.1 raeburn 4180: $datatable .= &Apache::loncommon::start_data_table_row().
4181: '<td align="left"><span class="LC_nobreak">'.
4182: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4183: '</span></td><td align="left">'.
4184: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4185: $settings->{$role.'.plaintext'},
1.49.2.21 raeburn 4186: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4187: &Apache::loncommon::end_data_table_row();
4188: }
4189: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4190: } elsif ($item eq 'categories') {
1.49.2.21 raeburn 4191: my $launcher;
4192: if ($noedit) {
4193: $launcher = $disabled;
4194: } else {
4195: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4196: }
1.3 raeburn 4197: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4198: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4199: $items{$item}{size},$launcher);
1.24 raeburn 4200: } elsif ($item eq 'owner') {
4201: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4202: if ($owner =~ /:/) {
4203: my ($ownername,$ownerdom) = split(':',$owner);
4204: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4205: } elsif ($owner ne '') {
4206: $owner = &Apache::loncommon::plainname($owner,$cdom);
4207: } else {
4208: $owner = &mt('None specified');
4209: }
4210: $datatable .= $owner;
1.49.2.11 raeburn 4211: } elsif ($item eq 'clonedfrom') {
4212: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4213: my $clonedfrom = &mt('None');
4214: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.49.2.13 raeburn 4215: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.49.2.11 raeburn 4216: if ($clonesrcinfo{'description'}) {
4217: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
4218: }
4219: }
4220: $datatable .= $clonedfrom;
1.49.2.12 raeburn 4221: } elsif ($item eq 'uniquecode') {
4222: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
4223: if ($code) {
4224: $datatable .= $code;
4225: }
1.25 raeburn 4226: } elsif ($item eq 'co-owners') {
4227: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4228: my @currcoown;
4229: if ($coowners) {
4230: @currcoown = split(',',$coowners);
4231: }
4232: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4233: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4234: $datatable .= &show_autocoowners(@currcoown);
4235: } else {
1.49.2.21 raeburn 4236: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4237: }
4238: } else {
4239: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4240: $datatable .= &show_autocoowners(@currcoown);
4241: } else {
1.49.2.21 raeburn 4242: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4243: }
4244: }
1.49.2.24 raeburn 4245: } elsif ($item eq 'syllabus') {
1.49.2.10 raeburn 4246: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4247: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4248: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4249: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4250: if ($minimal =~/\w/) {
4251: if ($external =~ m{\Q$minimal\E$}) {
4252: undef($external);
4253: }
4254: } elsif ($uploaded =~/\w/) {
4255: if ($external =~ m{\Q$uploaded\E$}) {
4256: undef($external);
4257: }
4258: }
4259: } elsif ($external!~/\w/) {
4260: undef($external);
4261: }
4262: if ($external) {
4263: $datatable .= &mt('External URL');
4264: } elsif ($minimal) {
4265: $datatable .= &mt('Minimal template');
4266: } elsif ($uploaded) {
4267: $datatable .= &mt('Uploaded file');
4268: } else {
4269: $datatable .= &mt('Standard template');
4270: }
4271: $datatable .= (' ' x 2).
4272: &mt('[_1]View[_2]',
4273: '<a href="javascript:syllabusinfo();">',
4274: '</a>');
1.35 raeburn 4275: } elsif ($item eq 'loncaparev') {
4276: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4277: my $showreqd;
4278: if ($loncaparev) {
1.36 raeburn 4279: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4280: &mt('Details').'</a>';
1.35 raeburn 4281: } else {
4282: $showreqd = &mt('No specific version required');
4283: }
4284: $datatable .= $showreqd;
1.1 raeburn 4285: } else {
1.49.2.21 raeburn 4286: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4287: }
4288: $datatable .= &item_table_row_end();
4289: }
4290: $$rowtotal += scalar(@{$ordered});
4291: return $datatable;
4292: }
4293:
4294: sub new_cloners_dom_row {
1.49.2.18 raeburn 4295: my ($newdom,$num,$default) = @_;
4296: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4297: if ($newdom ne '') {
1.49.2.18 raeburn 4298: if ($num eq $default) {
4299: $checkedon = 'checked="checked" ';
4300: } else {
4301: $checkedoff = 'checked="checked" ';
4302: }
1.1 raeburn 4303: $output .= &Apache::loncommon::start_data_table_row().
4304: '<td valign="top"><span class="LC_nobreak">'.
4305: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4306: (' 'x2).'<label><input type="radio" '.
1.49.2.18 raeburn 4307: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4308: 'onchange="javascript:update_cloners('.
1.1 raeburn 4309: "'cloners_activate','$num'".');" />'.
4310: &mt('Yes').'</label>'.(' 'x2).
4311: '<label><input type="radio" '.
1.49.2.18 raeburn 4312: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4313: 'onchange="javascript:update_cloners('.
1.1 raeburn 4314: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4315: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4316: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4317: &Apache::loncommon::end_data_table_row();
4318: }
4319: return $output;
4320: }
4321:
4322: sub can_modify_catsettings {
1.12 raeburn 4323: my ($dom,$crstype) = @_;
1.1 raeburn 4324: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4325: my ($can_toggle_cat,$can_categorize);
4326: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4327: if ($crstype eq 'Community') {
4328: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4329: $can_toggle_cat = 1;
4330: }
4331: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4332: $can_categorize = 1;
4333: }
4334: } else {
4335: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4336: $can_toggle_cat = 1;
4337: }
4338: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4339: $can_categorize = 1;
4340: }
1.1 raeburn 4341: }
4342: }
4343: return ($can_toggle_cat,$can_categorize);
4344: }
4345:
4346: sub assign_course_categories {
1.9 raeburn 4347: my ($r,$crstype) = @_;
1.1 raeburn 4348: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4349: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4350: my $hascats = 0;
4351: my $cathash;
4352: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4353: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4354: $cathash = $domconf{'coursecategories'}{'cats'};
4355: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4356: foreach my $cat (keys(%{$cathash})) {
4357: next if ($cat eq 'instcode::0');
4358: unless ($crstype eq 'Community') {
4359: next if ($cat eq 'communities::0');
4360: }
4361: $hascats ++;
4362: }
1.1 raeburn 4363: }
4364: }
4365: my $catwin_js;
4366: if ($hascats) {
1.9 raeburn 4367: my $alert;
4368: if ($crstype eq 'Community') {
4369: $alert = &mt("Use 'Save' in the main window to save community categories");
4370: } else {
4371: $alert = &mt("Use 'Save' in the main window to save course categories");
4372: }
1.49.2.19 raeburn 4373: &js_escape(\$alert);
1.1 raeburn 4374: $catwin_js = <<ENDSCRIPT;
4375: <script type="text/javascript">
4376:
4377: function updateCategories() {
4378: var newcategories = '';
4379: var unescapedcats = '';
4380: if (document.chgcats.usecategory.length) {
4381: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4382: if (document.chgcats.usecategory[i].checked == true) {
4383: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4384: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4385: }
4386: }
4387: if (newcategories.length > 0) {
4388: newcategories = newcategories.slice(0,-1);
4389: }
4390: if (unescapedcats.length > 0) {
4391: unescapedcats = unescapedcats.slice(0,-3);
4392: }
4393: } else {
4394: if (document.chgcats.usecategory.checked == true) {
4395: newcategories = document.chgcats.usecategory.value;
4396: unescapedcats = document.chgcats.catname.value;
4397: }
4398: }
4399: opener.document.display.categories.value = newcategories;
4400: opener.document.display.categories_display.value = unescapedcats;
4401: alert("$alert");
4402: self.close();
4403: return;
4404: }
4405:
4406: </script>
4407: ENDSCRIPT
4408: } else {
4409: my $onload;
4410: }
1.9 raeburn 4411: my ($crscat,$catcrs,$assign);
4412: if ($crstype eq 'Community') {
4413: $crscat = 'Community Categories';
4414: $catcrs = &mt('Categorize Community');
4415: $assign = &mt('Assign one or more categories to this community.')
4416: } else {
4417: $crscat = 'Course Categories';
4418: $catcrs = &mt('Categorize Course');
4419: $assign = &mt('Assign one or more categories to this course.')
4420: }
1.1 raeburn 4421: my $start_page =
1.9 raeburn 4422: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4423: {'only_body' => 1,});
4424: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4425: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4426: if ($hascats) {
4427: my %currsettings =
4428: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4429: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4430: $currsettings{'categories'},$crstype);
4431: if ($cattable eq '') {
4432: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4433: } else {
4434: $categoriesform .= $assign.'<br /><br />'.
4435: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4436: $cattable."\n".
4437: '<br /><input type="button" name="changes" value="'.
4438: &mt('Copy to main window').'" '.
4439: 'onclick="javascript:updateCategories()" /></form><br />';
4440: }
1.1 raeburn 4441: } else {
1.12 raeburn 4442: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4443: }
4444: $r->print($start_page.$categoriesform.$end_page);
4445: return;
4446: }
4447:
1.36 raeburn 4448: sub display_loncaparev_constraints {
4449: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.49.2.14 raeburn 4450: my ($reqdmajor,$reqdminor);
1.36 raeburn 4451: my $cid = $env{'request.course.id'};
4452: my $cdom = $env{'course.'.$cid.'.domain'};
4453: my $cnum = $env{'course.'.$cid.'.num'};
4454: my $output;
1.39 raeburn 4455: my %lt = &Apache::lonlocal::texthash (
4456: 'all' => 'all',
4457: 'section/group' => 'section/group',
4458: 'user' => 'user',
4459: );
1.49.2.14 raeburn 4460: &Apache::lonrelrequtils::init_global_hashes();
4461: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4462: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4463: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.49.2.14 raeburn 4464: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4465: }
4466: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.49.2.14 raeburn 4467: %byresponsetype,%bysubmission,%fromblocks);
1.39 raeburn 4468: @scopeorder = ('all','section/group','user');
1.49.2.15 raeburn 4469: my $now = time;
1.36 raeburn 4470: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4471: if (ref($resourcedata) eq 'HASH') {
4472: foreach my $key (keys(%{$resourcedata})) {
1.49.2.14 raeburn 4473: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4474: if ($key =~ /(\Q$item\E)$/) {
1.49.2.14 raeburn 4475: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
1.36 raeburn 4476: my $value = $resourcedata->{$key};
1.49.2.9 raeburn 4477: if ($item eq 'examcode') {
4478: if (&Apache::lonnet::validCODE($value)) {
4479: $value = 'valid';
4480: } else {
4481: $value = '';
4482: }
1.49.2.15 raeburn 4483: } elsif ($item eq 'printstartdate') {
4484: if ($value =~ /^\d+$/) {
4485: if ($value > $now) {
4486: $value = 'future';
4487: }
4488: }
4489: } elsif ($item eq 'printenddate') {
4490: if ($value =~ /^\d+$/) {
4491: if ($value < $now) {
4492: $value = 'past';
4493: }
4494: }
4495:
1.49.2.9 raeburn 4496: }
1.36 raeburn 4497: my ($middle,$scope,$which,$level,$map,$resource);
1.49.2.14 raeburn 4498: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
1.36 raeburn 4499: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4500: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4501: my $valname = &get_param_description($stdtype,$value);
4502: my $rev = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value};
4503: my $start = $cid.'.';
4504: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4505: $middle = $1;
4506: $which = $2;
4507: $scope = 'user';
4508: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4509: $middle = $1;
4510: $which = $2;
4511: $scope = 'section/group';
4512: } else {
1.39 raeburn 4513: $scope = 'all';
1.36 raeburn 4514: }
4515: my $what="$stdname=$valname";
4516: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4517: $level = 'general';
1.39 raeburn 4518: if ($scope eq 'all') {
1.36 raeburn 4519: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4520: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4521: push(@{$fromparam{$rev}{$scope}},$what);
4522: }
4523: } else {
4524: push(@{$fromparam{$rev}{$scope}},$what);
4525: }
4526: } else {
4527: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4528: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4529: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4530: }
4531: } else {
4532: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4533: }
4534: }
4535: $rowspan{$rev} ++;
4536: } elsif ($key =~ /^\Q$start$middle\E(.+)___\(all\).\w+\.\Q$item\E$/) {
4537: $level = 'folder';
4538: $map = $1;
1.39 raeburn 4539: if ($scope eq 'all') {
1.36 raeburn 4540: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4541: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4542: push(@{$bymap{$map}{$rev}{$scope}},$what);
4543: }
4544: } else {
4545: push(@{$bymap{$map}{$rev}{$scope}},$what);
4546: }
4547: } else {
4548: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4549: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4550: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4551: }
4552: } else {
4553: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4554: }
4555: }
4556: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4557: $level = 'resource';
4558: $resource = $1;
1.39 raeburn 4559: if ($scope eq 'all') {
1.36 raeburn 4560: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4561: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4562: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4563: }
4564: } else {
4565: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4566: }
4567: } else {
4568: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4569: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4570: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4571: }
4572: } else {
4573: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4574: }
4575: }
4576: }
4577: }
4578: }
4579: }
4580: }
4581: }
4582: if (keys(%fromparam)) {
4583: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4584: &Apache::loncommon::start_data_table().
4585: &Apache::loncommon::start_data_table_header_row().
4586: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4587: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4588: &Apache::loncommon::end_data_table_header_row();
4589: foreach my $rev (keys(%fromparam)) {
1.49.2.14 raeburn 4590: my ($major,$minor) = split(/\./,$rev);
4591: ($reqdmajor,$reqdminor) =
4592: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4593: $output .= &Apache::loncommon::start_data_table_row().
4594: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4595: my $newrow;
4596: foreach my $scope (@scopeorder) {
4597: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4598: if ($newrow) {
4599: $output .= &Apache::loncommon::continue_data_table_row();
4600: }
1.39 raeburn 4601: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4602: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4603: $output .= '<td>'.$which.'</td><td>'.
4604: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4605: }
4606: $output .= &Apache::loncommon::end_data_table_row();
4607: $newrow = 1;
4608: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4609: if ($newrow) {
4610: $output .= &Apache::loncommon::continue_data_table_row();
4611: }
1.39 raeburn 4612: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4613: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4614: &Apache::loncommon::end_data_table_row();
4615: $newrow = 1;
4616: }
4617: }
4618: }
4619: $output .= &Apache::loncommon::end_data_table().'<br />';
4620: }
4621: }
4622:
1.49.2.14 raeburn 4623: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4624: my $now = time;
4625: if (keys(%comm_blocks) > 0) {
4626: foreach my $block (keys(%comm_blocks)) {
4627: if ($block =~ /^firstaccess____(.+)$/) {
4628: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
4629: if (ref($comm_blocks{$block}) eq 'HASH') {
4630: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4631: ' '.&mt('set by [_1]',
4632: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4633: }
4634: next;
4635: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4636: my ($start,$end) = ($1,$2);
4637: next if ($end < $now);
4638: }
4639: if (ref($comm_blocks{$block}) eq 'HASH') {
4640: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4641: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4642: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
4643: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
4644: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4645: ' '.
4646: &mt('set by [_1]',
4647: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4648: }
4649: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
4650: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
4651: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4652: ' '.
4653: &mt('set by [_1]',
4654: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4655:
4656: }
4657: }
4658: }
4659: }
4660: if (keys(%fromblocks)) {
4661: my %lt = (
4662: docs => 'Content blocking',
4663: printout => 'Printout generation',
4664: timer => 'Timed quiz trigger',
4665: );
4666: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4667: &Apache::loncommon::start_data_table().
4668: &Apache::loncommon::start_data_table_header_row().
4669: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4670: '<th>'.&mt('Event(s)').'</th>'.
4671: &Apache::loncommon::end_data_table_header_row();
4672: foreach my $type ('docs','printout','timer') {
4673: if (ref($fromblocks{$type}) eq 'HASH') {
4674: foreach my $rev (keys(%{$fromblocks{$type}})) {
4675: my ($major,$minor) = split(/\./,$rev);
4676: ($reqdmajor,$reqdminor) =
4677: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4678: $output .= &Apache::loncommon::start_data_table_row().
4679: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4680: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4681: $output .= $event.'<br />';
4682: }
4683: $output =~ s{\Q<br />\E$}{};
4684: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4685: }
4686: }
4687: }
4688: $output .= &Apache::loncommon::end_data_table().'<br />';
4689: }
4690: }
4691:
1.36 raeburn 4692: if (defined($navmap)) {
4693: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
4694: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'};
4695: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
4696: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry'};
4697: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4698: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4699: my $valanon=&get_param_description($stdtype,'anonsurvey');
4700: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.49.2.14 raeburn 4701: my %checkedrev;
1.36 raeburn 4702: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
4703: my @parts = @{$res->parts()};
4704: my $symb = $res->symb();
4705: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
4706: foreach my $part (@parts) {
4707: if (exists($anonsubms{$symb."\0".$part})) {
4708: my $rev = $rev_anonsurv;
4709: my $what="$stdname=$valanon";
4710: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4711: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4712: push(@{$bysubmission{$symb}{$rev}},$what);
4713: }
4714: } else {
4715: push(@{$bysubmission{$symb}{$rev}},$what);
4716: }
4717: $allmaps{$enclosing_map} = 1;
1.49.2.14 raeburn 4718: unless ($checkedrev{'anonsurvey'}) {
4719: my ($major,$minor) = split(/\./,$rev);
4720: ($reqdmajor,$reqdminor) =
4721: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4722: $reqdmajor,$reqdminor);
4723: $checkedrev{'anonsurvey'} = 1;
4724: }
1.36 raeburn 4725: }
4726: if (exists($randtrysubms{$symb."\0".$part})) {
4727: my $rev = $rev_randtry;
4728: my $what="$stdname=$valrandtry";
4729: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4730: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4731: push(@{$bysubmission{$symb}{$rev}},$what);
4732: }
4733: } else {
4734: push(@{$bysubmission{$symb}{$rev}},$what);
4735: }
4736: $allmaps{$enclosing_map} = 1;
1.49.2.14 raeburn 4737: unless ($checkedrev{'randomizetry'}) {
4738: my ($major,$minor) = split(/\./,$rev);
4739: ($reqdmajor,$reqdminor) =
4740: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4741: $reqdmajor,$reqdminor);
4742: $checkedrev{'randomizetry'} = 1;
4743: }
1.36 raeburn 4744: }
4745: }
4746: my %responses = $res->responseTypes();
4747: foreach my $key (keys(%responses)) {
1.49.2.14 raeburn 4748: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4749: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4750: unless ($checkedrev{$key}) {
4751: my ($major,$minor) = split(/\./,$rev);
4752: ($reqdmajor,$reqdminor) =
4753: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4754: $reqdmajor,$reqdminor);
4755: $checkedrev{$key} = 1;
4756: }
4757: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4758: $allmaps{$enclosing_map} = 1;
4759: }
4760: }
4761: }
4762: if (keys(%byresource) > 0) {
4763: foreach my $symb (keys(%byresource)) {
4764: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4765: $allmaps{$map} = 1;
4766: }
4767: }
4768: if (keys(%bymap) > 0) {
4769: foreach my $map (keys(%bymap)) {
4770: $allmaps{$map} = 1;
4771: }
4772: }
4773: foreach my $map (keys(%allmaps)) {
4774: my $mapres = $navmap->getResourceByUrl($map);
4775: if (ref($mapres)) {
1.49.2.16 raeburn 4776: my $mapsymb = $mapres->symb();
4777: $toshow{$mapsymb} = 1;
1.36 raeburn 4778: my $pcslist = $mapres->map_hierarchy();
4779: if ($pcslist ne '') {
4780: foreach my $pc (split(/,/,$pcslist)) {
4781: my $res = $navmap->getByMapPc($pc);
4782: if (ref($res)) {
4783: my $symb = $res->symb();
4784: unless ($symb eq '______') {
4785: $toshow{$symb} = 1;
4786: }
4787: }
4788: }
4789: }
4790: }
4791: }
4792: }
4793: my $mapres_header = '<h4>'.
4794: &mt('Requirements for specific folders or resources').
4795: '</h4>';
4796: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4797: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4798: $output .= $mapres_header;
4799: }
4800: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4801: my $title = 'Version Constraints';
4802: my $start_page =
4803: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4804: $r->print($start_page.$top_header);
4805: if ($output) {
4806: $r->print($output);
4807: if (defined($navmap)) {
4808: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.39 raeburn 4809: \%byresponsetype,\@scopeorder,\%lt);
1.36 raeburn 4810: }
4811: $r->print('<br /><br />');
4812: } else {
4813: $r->print('<p class="LC_info">'.
4814: &mt('No version requirements from resource content or settings.').
4815: '</p>');
4816: }
4817: $r->print(&Apache::loncommon::end_page());
1.49.2.14 raeburn 4818: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4819: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4820: return 1;
4821: }
1.36 raeburn 4822: return;
4823: }
4824:
4825: sub show_contents_view {
1.39 raeburn 4826: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
4827: $scopeorder,$lt) = @_;
1.36 raeburn 4828: if ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4829: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0)) {
4830: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4831: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4832: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4833: my $topmap = $env{'course.'.$cid.'.url'};
4834: $r->print(&Apache::loncommon::start_data_table().
4835: &Apache::loncommon::start_data_table_header_row().
4836: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4837: '<th>'.&mt('Attribute/Setting').'</th>'.
4838: &Apache::loncommon::end_data_table_header_row().
4839: &Apache::loncommon::start_data_table_row().
1.49.2.8 raeburn 4840: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.39 raeburn 4841: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
1.36 raeburn 4842: $r->print(&Apache::loncommon::end_data_table_row());
4843: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4844: my $curRes;
4845: my $depth = 0;
4846: my %parent = ();
4847: my $startcount = 5;
4848: my $lastcontainer = $startcount;
4849: while ($curRes = $it->next()) {
4850: if ($curRes == $it->BEGIN_MAP()) {
4851: $depth++;
4852: $parent{$depth}= $lastcontainer;
4853: }
4854: if ($curRes == $it->END_MAP()) {
4855: $depth--;
4856: $lastcontainer = $parent{$depth};
4857: }
4858: my $indent;
4859: for (my $i=0; $i<$depth; $i++) {
4860: $indent.= $whitespace;
4861: }
4862: if (ref($curRes)) {
4863: my $symb = $curRes->symb();
4864: my $ressymb = $symb;
4865: my $srcf = $curRes->src();
4866: my $title = &Apache::lonnet::gettitle($srcf);
4867: if (($curRes->is_sequence()) || ($curRes->is_page())) {
4868: next unless($toshow->{$symb});
4869: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
4870: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4871: if ($curRes->is_page()) {
4872: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
4873: }
4874: my $rowspan = 1;
4875: if (ref($bymap->{$url}) eq 'HASH') {
4876: $rowspan = scalar(keys(%{$bymap->{$url}}));
4877: }
4878: $r->print(&Apache::loncommon::start_data_table_row().
4879: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 4880: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 4881: $r->print(&Apache::loncommon::end_data_table_row());
4882: } else {
4883: my $rowspan;
4884: if (ref($byresource->{$symb}) eq 'HASH') {
4885: $rowspan += scalar(keys(%{$byresource->{$symb}}));
4886: }
4887: if (ref($bysubmission->{$symb}) eq 'HASH') {
4888: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
4889: }
4890: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4891: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
4892: }
4893: next if (!$rowspan);
4894: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
4895: &mt('Problem').'" />';
4896: $r->print(&Apache::loncommon::start_data_table_row().
4897: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
4898: my $newrow;
4899: if (ref($byresource->{$symb}) eq 'HASH') {
4900: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
4901: if ($newrow) {
4902: $r->print(&Apache::loncommon::continue_data_table_row());
4903: }
4904: $r->print('<td valign="middle">'.$rev.'</td><td>');
4905: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
4906: $r->print('<table border="0">');
4907: foreach my $scope (@{$scopeorder}) {
4908: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4909: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4910: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
4911: $r->print('<td>'.$which.'</td><td>'.
4912: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
4913: '</td>');
4914: }
4915: $r->print('</tr>');
4916: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4917: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 4918: '<td> </td><td>'.
4919: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
4920: }
4921: }
4922: $r->print('</table>');
4923: }
4924: $r->print('</td>');
4925: $r->print(&Apache::loncommon::end_data_table_row());
4926: $newrow = 1;
4927: }
4928: }
4929: if (ref($bysubmission->{$symb}) eq 'HASH') {
4930: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
4931: if ($newrow) {
4932: $r->print(&Apache::loncommon::continue_data_table_row());
4933: }
4934: $r->print('<td>'.$rev.'</td><td>');
4935: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
4936: $r->print(&mt('Submissions to: ').' '.
4937: join(', ',@{$bysubmission->{$symb}{$rev}}));
4938: }
4939: $r->print('</td>');
4940: $r->print(&Apache::loncommon::end_data_table_row());
4941: $newrow = 1;
4942: }
4943: }
4944: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4945: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
4946: if ($newrow) {
4947: $r->print(&Apache::loncommon::continue_data_table_row());
4948: }
4949: $r->print('<td>'.$rev.'</td><td>');
4950: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
4951: $r->print(&mt('Response Type(s): ').' '.
4952: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
4953: }
4954: $r->print('</td>');
4955: }
4956: $r->print(&Apache::loncommon::end_data_table_row());
4957: }
4958: }
4959: }
4960: }
4961: $r->print(&Apache::loncommon::end_data_table());
4962: }
1.49.2.14 raeburn 4963: return;
1.36 raeburn 4964: }
4965:
4966: sub releases_by_map {
1.39 raeburn 4967: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 4968: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.49.2.19 raeburn 4969: my $newrow = 0;
1.36 raeburn 4970: if (ref($bymap->{$url}) eq 'HASH') {
4971: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.49.2.19 raeburn 4972: if ($newrow) {
4973: $r->print(&Apache::loncommon::end_data_table_row().
4974: &Apache::loncommon::continue_data_table_row());
4975: }
1.36 raeburn 4976: $r->print('<td valign="middle">'.$rev.'</td><td>');
4977: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
4978: $r->print('<table border="0">');
4979: foreach my $scope (@{$scopeorder}) {
4980: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4981: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4982: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
4983: $r->print('<td>'.$which.'</td><td>'.
4984: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
4985: '</td>');
4986: }
4987: $r->print('</tr>');
4988: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4989: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 4990: '</td><td> </td><td>'.
4991: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
4992: }
4993: }
4994: $r->print('</table>');
4995: }
4996: $r->print('</td>');
1.49.2.19 raeburn 4997: $newrow = 1;
1.36 raeburn 4998: }
4999: } else {
5000: $r->print('<td colspan="2"> </td>');
5001: }
5002: return;
5003: }
5004:
5005: sub get_param_description {
5006: my ($stdtype,$value) = @_;
5007: my $name = $value;
5008: my $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5009: unless (ref($paramstrings) eq 'ARRAY') {
5010: return $name;
5011: }
5012: foreach my $possibilities (@{$paramstrings}) {
5013: next unless (ref($possibilities) eq 'ARRAY');
5014: my ($thing, $description) = @{ $possibilities };
5015: if ($thing eq $value) {
5016: $name = $description;
5017: last;
5018: }
5019: }
5020: return $name;
5021: }
5022:
1.49.2.14 raeburn 5023: sub update_releasereq {
5024: my $readmap = 1;
5025: my $getrelreq = 1;
5026: if (ref($modified_courses) eq 'ARRAY') {
5027: foreach my $item (@{$modified_courses}) {
5028: if (ref($item) eq 'ARRAY') {
5029: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5030: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5031: $chome,$crstype,$cdom.'_'.$cnum,
5032: $readmap,$getrelreq);
5033: }
5034: }
5035: $modified_courses = [];
5036: }
5037: undef($registered_cleanup);
5038: return;
5039: }
5040:
1.25 raeburn 5041: sub show_autocoowners {
5042: my (@currcoown) = @_;
1.49.2.7 raeburn 5043: 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 5044: if (@currcoown > 0) {
5045: $output .= '<br />'.&mt('Current co-owners are:').' '.
5046: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5047: } else {
5048: $output .= '<br />'.&mt('Currently no co-owners.');
5049: }
5050: return $output;
5051: }
5052:
5053: sub coowner_invitations {
1.49.2.21 raeburn 5054: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5055: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5056: my $pendingcoowners =
5057: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5058: if ($pendingcoowners) {
5059: @pendingcoown = split(',',$pendingcoowners);
5060: }
1.49.2.21 raeburn 5061: if (ref($currcoownref) eq 'ARRAY') {
1.49.2.28.2.2 (raeburn 5062:: @currcoown = @{$currcoownref};
1.49.2.21 raeburn 5063: }
5064: my $disabled;
5065: if ($noedit) {
5066: $disabled = ' disabled="disabled"';
5067: }
1.25 raeburn 5068: my $ccrole = 'cc';
5069: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5070: foreach my $key (sort(keys(%ccroles))) {
5071: my ($ccname,$ccdom,$role) = split(':',$key);
5072: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5073: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5074: push(@othercoords,$ccname.':'.$ccdom);
5075: }
5076: }
5077: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5078: if ($coowner_rows) {
5079: $output .= &Apache::loncommon::start_data_table();
5080: if (@currcoown) {
5081: $output .= &Apache::loncommon::start_data_table_row().
5082: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5083: foreach my $person (@currcoown) {
5084: my ($co_uname,$co_dom) = split(':',$person);
1.49.2.21 raeburn 5085: $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 5086: }
5087: $output .= '</td>'.
5088: &Apache::loncommon::end_data_table_row();
5089: }
5090: if ($pendingcoowners) {
5091: $output .= &Apache::loncommon::start_data_table_row().
5092: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5093: foreach my $person (@pendingcoown) {
5094: my ($co_uname,$co_dom) = split(':',$person);
1.49.2.21 raeburn 5095: $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 5096: }
5097: $output .= '</td>'.
5098: &Apache::loncommon::end_data_table_row();
5099: }
5100: if (@othercoords) {
5101: $output .= &Apache::loncommon::start_data_table_row().
5102: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5103: foreach my $person (@othercoords) {
5104: my ($co_uname,$co_dom) = split(':',$person);
1.49.2.21 raeburn 5105: $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 5106: }
5107: $output .= '</td>'.
5108: &Apache::loncommon::end_data_table_row();
5109: }
5110: $output .= &Apache::loncommon::end_data_table();
5111: } else {
5112: $output = &mt('There are no coordinators to select as co-owners');
5113: }
5114: return $output;
5115: }
5116:
5117: sub manage_coownership {
1.49.2.21 raeburn 5118: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5119: my (@pendingcoown,@currcoown);
1.25 raeburn 5120: my $pendingcoowners =
5121: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5122: if ($pendingcoowners) {
5123: @pendingcoown = split(',',$pendingcoowners);
5124: }
1.49.2.21 raeburn 5125: if (ref($currcoownref) eq 'ARRAY') {
1.49.2.28.2.2 (raeburn 5126:: @currcoown = @{$currcoownref};
1.49.2.21 raeburn 5127: }
5128: my $disabled;
5129: if ($noedit) {
5130: $disabled = ' disabled="disabled"';
5131: }
1.25 raeburn 5132: my ($is_coowner,$is_pending,$output);
5133: my $uname = $env{'user.name'};
5134: my $udom = $env{'user.domain'};
5135: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5136: $is_coowner = 1;
5137: }
5138: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5139: $is_pending = 1;
5140: }
5141: if (@currcoown && ($is_coowner || $is_pending)) {
5142: $output = &Apache::loncommon::start_data_table();
5143: }
5144: if (@currcoown) {
5145: if ($is_coowner || $is_pending) {
5146: $output .= &Apache::loncommon::start_data_table().
5147: &Apache::loncommon::start_data_table_row().'<td>';
5148: }
5149: $output .= &mt('Current co-owners are:').' '.
5150: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5151: if ($is_coowner || $is_pending) {
5152: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5153: }
5154: }
5155: if ($is_coowner || $is_pending) {
5156: if (@currcoown) {
5157: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5158: }
5159: $output .= '<span class="LC_nobreak">';
5160: if ($is_coowner) {
1.49.2.26 raeburn 5161: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5162: } else {
1.49.2.26 raeburn 5163: $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).
5164: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5165: }
5166: $output .= '</span>';
5167: if (@currcoown) {
5168: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5169: }
5170: }
5171: if (@currcoown && ($is_coowner || $is_pending)) {
5172: $output .= &Apache::loncommon::end_data_table();
5173: }
5174: return $output;
5175: }
5176:
1.1 raeburn 5177: sub print_localization {
1.49.2.21 raeburn 5178: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5179: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5180: return;
5181: }
5182: my %items = (
5183: languages => {
1.17 faziophi 5184: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5185: &mt("(overrides individual user preference)"),
1.1 raeburn 5186: input => 'selectbox',
5187: },
5188: timezone => {
1.17 faziophi 5189: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5190: input => 'selectbox',
5191: },
5192: datelocale => {
1.17 faziophi 5193: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5194: input => 'selectbox',
5195: },
5196: );
1.49.2.21 raeburn 5197: my ($datatable,$disabled);
1.1 raeburn 5198: my $count = 0;
1.49.2.21 raeburn 5199: if ($noedit) {
5200: $disabled = ' disabled="disabled"';
5201: }
1.1 raeburn 5202: foreach my $item (@{$ordered}) {
5203: $count ++;
1.49.2.7 raeburn 5204: my $colspan;
5205: unless ($item eq 'languages') {
5206: $colspan = 2;
5207: }
5208: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5209: if ($item eq 'timezone') {
5210: my $includeempty = 1;
5211: my $timezone = &Apache::lonlocal::gettimezone();
1.49.2.28.2.1 (raeburn 5212:): my $onchange;
5213:): unless ($noedit) {
5214:): $onchange = ' onchange="javascript:toggleTimeZone();"';
5215:): }
5216:): my $id = ' id="LC_set_timezone"';
1.1 raeburn 5217: $datatable .=
1.49.2.28.2.1 (raeburn 5218:): &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5219:): $includeempty,$id,$disabled);
5220:): my $tzsty = 'none';
5221:): if ($timezone ne '') {
5222:): $tzsty = 'block';
5223:): }
5224:): $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5225:): '<span class="LC_nobreak">'.
5226:): &mt('Override individual user preference?').
5227:): &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5228:): '</span></div>';
1.1 raeburn 5229: } elsif ($item eq 'datelocale') {
5230: my $includeempty = 1;
5231: my $locale_obj = &Apache::lonlocal::getdatelocale();
5232: my $currdatelocale;
5233: if (ref($locale_obj)) {
5234: $currdatelocale = $locale_obj->id();
5235: }
5236: $datatable .=
5237: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.49.2.21 raeburn 5238: undef,$includeempty,$disabled);
1.1 raeburn 5239: } else {
5240: if ($settings->{$item} eq '') {
1.49.2.21 raeburn 5241: unless ($noedit) {
5242: $datatable .= '</td><td align="right">'.
5243: &Apache::loncommon::select_language('languages_0','',1);
5244: }
1.1 raeburn 5245: } else {
5246: my $num = 0;
1.3 raeburn 5247: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.49.2.7 raeburn 5248: $datatable .= '</td><td align="right"><br />'.
5249: &Apache::loncommon::start_data_table();
1.1 raeburn 5250: if (@languages > 0) {
1.3 raeburn 5251: my %langchoices = &get_lang_choices();
1.1 raeburn 5252: foreach my $lang (@languages) {
5253: my $showlang = $lang;
1.3 raeburn 5254: if (exists($langchoices{$lang})) {
5255: $showlang = $langchoices{$lang};
1.1 raeburn 5256: }
5257: $datatable .=
5258: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5259: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5260: &mt('Language:').'<b> '.$showlang.
5261: '</b><input type="hidden" name="languages_'.$num.
5262: '" value="'.$lang.'" /></span><br />'.
5263: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.49.2.21 raeburn 5264: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5265: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5266: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5267: $num ++;
5268: }
5269: }
1.49.2.21 raeburn 5270: unless ($noedit) {
1.49.2.28.2.1 (raeburn 5271:): $datatable .=
1.49.2.21 raeburn 5272: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5273: '<td align="left"><span class="LC_nobreak">'.
5274: &mt('Additional language:'). '</span><br />'.
5275: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5276: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.49.2.21 raeburn 5277: '</td>'.&Apache::loncommon::end_data_table_row();
5278: }
5279: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5280: }
5281: }
5282: $datatable .= &item_table_row_end();
5283: }
5284: $$rowtotal += scalar(@{$ordered});
5285: return $datatable;
5286: }
5287:
1.3 raeburn 5288: sub get_lang_choices {
5289: my %langchoices;
5290: foreach my $id (&Apache::loncommon::languageids()) {
5291: my $code = &Apache::loncommon::supportedlanguagecode($id);
5292: if ($code) {
5293: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5294: }
5295: }
5296: return %langchoices;
5297: }
5298:
1.1 raeburn 5299: sub print_feedback {
1.49.2.21 raeburn 5300: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5301: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5302: return;
5303: }
5304: my %items = (
1.3 raeburn 5305: 'question.email' => {
5306: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5307: input => 'textbox',
5308: size => '50',
5309: },
5310:
1.3 raeburn 5311: 'comment.email' => {
5312: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5313: input => 'textbox',
5314: size => '50',
5315: },
5316:
1.3 raeburn 5317: 'policy.email' => {
5318: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5319: input => 'textbox',
5320: size => '50',
5321: },
5322: );
5323: my $datatable;
5324: my $count = 0;
5325: my ($cnum) = &get_course();
5326: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5327: my @sections = sort( { $a <=> $b } keys(%sections));
5328: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5329: currone => 'Current recipient:',
5330: currmult => 'Current recipients:',
5331: add => 'Additional recipient:',
5332: del => 'Delete?',
5333: sec => 'Sections:',
1.1 raeburn 5334: );
1.49.2.21 raeburn 5335: my $disabled;
5336: if ($noedit) {
5337: $disabled = ' disabled="disabled"';
5338: }
1.1 raeburn 5339: foreach my $item (@{$ordered}) {
5340: $count ++;
1.20 faziophi 5341: if ($position eq 'top') {
5342: $datatable .= &item_table_row_start($items{$item}{text},$count);
5343: } else {
1.49.2.7 raeburn 5344: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5345: }
1.1 raeburn 5346: if ($position eq 'top') {
5347: my $includeempty = 0;
1.49.2.7 raeburn 5348: $datatable .= '</td><td align="right">'.
5349: &user_table($cdom,$item,\@sections,
1.49.2.21 raeburn 5350: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5351: } else {
1.3 raeburn 5352: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.49.2.21 raeburn 5353: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5354: }
5355: $datatable .= &item_table_row_end();
5356: }
5357: $$rowtotal += scalar(@{$ordered});
5358: return $datatable;
5359: }
5360:
5361: sub user_table {
1.49.2.21 raeburn 5362: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5363: my $output;
5364: if ($currvalue eq '') {
1.49.2.21 raeburn 5365: unless ($noedit) {
5366: $output .= &select_recipient($item,'0',$cdom,$sections);
1.49.2.28.2.1 (raeburn 5367:): }
1.1 raeburn 5368: } else {
5369: my $num = 0;
5370: my @curr = split(/,/,$currvalue);
1.49.2.7 raeburn 5371: $output .= '<table class="LC_data_table">';
1.1 raeburn 5372: my ($currusers);
1.49.2.21 raeburn 5373: my $disabled;
5374: if ($noedit) {
5375: $disabled = ' disabled="disabled"';
5376: }
1.1 raeburn 5377: foreach my $val (@curr) {
5378: next if ($val eq '');
5379: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5380: my @selsec;
5381: if ($seclist) {
5382: $seclist =~ s/(^\(|\)$)//g;
5383: @selsec = split(/\s*;\s*/,$seclist);
5384: }
5385: $currusers .= '<tr>'.
5386: '<td valign="top"><span class="LC_nobreak">'.
5387: '<label><input type="checkbox" '.
1.49.2.21 raeburn 5388: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5389: $lt->{'del'}.'</label>'.
5390: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5391: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5392: &Apache::loncommon::aboutmewrapper(
5393: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5394: $uname,$udom,'aboutuser');
5395: if (ref($sections) eq 'ARRAY') {
5396: if (@{$sections}) {
5397: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5398: &select_sections($item,$num,$sections,
1.49.2.21 raeburn 5399: \@selsec,$noedit);
1.1 raeburn 5400: }
5401: }
5402: $currusers .= '</span></td></tr>';
5403: $num ++;
5404: }
5405: if ($num) {
1.10 raeburn 5406: $output .= '<tr>'.
1.1 raeburn 5407: '<td align="left"><i>';
1.20 faziophi 5408: if ($num == 1) {
1.1 raeburn 5409: $output .= $lt->{'currone'};
5410: } else {
1.21 raeburn 5411: $output .= $lt->{'currmult'};
1.1 raeburn 5412: }
5413: $output .= '</i><br />'.
5414: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5415: '</tr>';
1.1 raeburn 5416: }
1.49.2.21 raeburn 5417: unless ($noedit) {
5418: $output .=
5419: '<tr>'.
1.1 raeburn 5420: '<td align="left"><span class="LC_nobreak"><i>'.
5421: $lt->{'add'}.'</i></span><br />'.
5422: &select_recipient($item,$num,$cdom,$sections).
5423: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.49.2.21 raeburn 5424: '</td></tr>';
5425: }
5426: $output .= '</table>';
1.1 raeburn 5427: }
5428: return $output;
5429: }
5430:
5431: sub select_recipient {
5432: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5433: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5434: my $selectlink =
5435: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.49.2.25 raeburn 5436: $item.'_udom_'.$num,'only');
1.1 raeburn 5437: my $output =
1.10 raeburn 5438: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5439: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5440: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5441: if (ref($sections) eq 'ARRAY') {
5442: if (@{$sections}) {
5443: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5444: &select_sections($item,$num,$sections,$selected).'</td>';
5445: }
5446: }
5447: $output .= '<td valign="top">'.
5448: $selectlink.'</td></tr></table>';
5449: return $output;
5450: }
5451:
5452: sub select_sections {
1.49.2.28.2.1 (raeburn 5453:): my ($item,$num,$sections,$selected,$noedit,$allval) = @_;
1.49.2.21 raeburn 5454: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5455: if (ref($selected) eq 'ARRAY') {
5456: @currsecs = @{$selected};
5457: }
5458: if (!@currsecs) {
5459: $allsec = ' selected="selected"';
5460: }
1.49.2.21 raeburn 5461: if ($noedit) {
5462: $disabled = ' disabled="disabled"';
5463: }
1.1 raeburn 5464: if (ref($sections) eq 'ARRAY') {
5465: if (@{$sections}) {
5466: my $mult;
5467: if (@{$sections} > 1) {
5468: $mult = ' multiple="multiple"';
1.49.2.28.2.1 (raeburn 5469:): my $size;
1.1 raeburn 5470: if (@{$sections} > 3) {
1.49.2.28.2.1 (raeburn 5471:): $size = 4;
5472:): } else {
5473:): $size = 1 + scalar(@{$sections});
1.1 raeburn 5474: }
1.49.2.28.2.1 (raeburn 5475:): $mult .= ' size="'.$size.'"';
5476:): }
5477:): my $name = $item.'_sections';
5478:): unless ($item eq 'hidetotals') {
5479:): $name .= '_'.$num;
1.1 raeburn 5480: }
1.49.2.28.2.1 (raeburn 5481:): $output = '<select name="'.$name.'"'.$mult.$disabled.'>'.
5482:): ' <option value="'.$allval.'"'.$allsec.'>'.&mt('All').'</option>';
1.1 raeburn 5483: foreach my $sec (@{$sections}) {
5484: my $is_sel;
5485: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
1.49.2.28.2.1 (raeburn 5486:): $is_sel = ' selected="selected"';
1.1 raeburn 5487: }
5488: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5489: }
5490: $output .= '</select>';
5491: }
5492: }
5493: return $output;
5494: }
5495:
5496: sub print_discussion {
1.49.2.21 raeburn 5497: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5498: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5499: return;
5500: }
5501: my %items = (
5502: 'plc.roles.denied' => {
1.10 raeburn 5503: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5504: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5505: &mt('(role-based)'),
1.1 raeburn 5506: input => 'checkbox',
5507: },
5508:
5509: 'plc.users.denied' => {
1.3 raeburn 5510: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5511: &mt('(specific user(s))'),
1.1 raeburn 5512: input => 'checkbox',
5513: },
5514:
5515: 'pch.roles.denied' => {
1.10 raeburn 5516: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5517: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5518: &mt('(role-based)'),
1.1 raeburn 5519: input => 'checkbox',
5520: },
5521:
5522: 'pch.users.denied' => {
1.3 raeburn 5523: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5524: &mt('(specific user(s))'),
1.1 raeburn 5525: input => 'checkbox',
5526: },
5527: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5528: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5529: input => 'radio',
5530: },
5531:
5532: 'allow_discussion_post_editing' => {
1.3 raeburn 5533: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5534: input => 'checkbox',
5535: },
1.49.2.3 raeburn 5536: 'discussion_post_fonts' => {
5537: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5538: input => 'textbox',
5539: size => '20',
5540: },
1.1 raeburn 5541: );
5542: my $datatable;
5543: my $count;
5544: my ($cnum) = &get_course();
5545: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5546: my @sections = sort( { $a <=> $b } keys(%sections));
5547: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5548: currone => 'Disallowed:',
5549: currmult => 'Disallowed:',
5550: add => 'Disallow more:',
5551: del => 'Delete?',
5552: sec => 'Sections:',
1.1 raeburn 5553: );
5554: foreach my $item (@{$ordered}) {
5555: $count ++;
1.49.2.7 raeburn 5556: my $colspan;
5557: if ($item eq 'allow_limited_html_in_feedback') {
5558: $colspan = 2;
5559: }
5560: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5561: if ($item eq 'plc.roles.denied') {
1.49.2.7 raeburn 5562: $datatable .= '</td><td align="right">'.
1.49.2.21 raeburn 5563: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5564: '</table>';
5565: } elsif ($item eq 'plc.users.denied') {
1.49.2.7 raeburn 5566: $datatable .= '</td><td align="right">'.
5567: &user_table($cdom,$item,undef,
1.49.2.21 raeburn 5568: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5569: } elsif ($item eq 'pch.roles.denied') {
1.49.2.7 raeburn 5570: $datatable .= '</td><td align="right">'.
1.49.2.21 raeburn 5571: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5572: '</table>';
5573: } elsif ($item eq 'pch.users.denied') {
1.49.2.7 raeburn 5574: $datatable .= '</td><td align="right">'.
5575: &user_table($cdom,$item,undef,
1.49.2.21 raeburn 5576: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5577: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.49.2.21 raeburn 5578: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5579: } elsif ($item eq 'allow_discussion_post_editing') {
1.49.2.7 raeburn 5580: $datatable .= '</td><td align="right"><br />'.
5581: &Apache::loncommon::start_data_table().
1.1 raeburn 5582: &Apache::loncommon::start_data_table_row().
5583: '<th align="left">'.&mt('Role').'</th><th>'.
5584: &mt('Sections').'</th>'.
5585: &Apache::loncommon::end_data_table_row().
1.49.2.21 raeburn 5586: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.49.2.7 raeburn 5587: &Apache::loncommon::end_data_table().'<br />';
1.49.2.3 raeburn 5588: } elsif ($item eq 'discussion_post_fonts') {
1.49.2.7 raeburn 5589: $datatable .= '</td><td align="right"><br />'.
5590: &Apache::loncommon::start_data_table().
1.49.2.3 raeburn 5591: &Apache::loncommon::start_data_table_row().
5592: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5593: '<th align="center">'.&mt('font-size').'</th>'.
5594: '<th align="center">'.&mt('font-weight').'</th>'.
5595: '<th align="center">'.&mt('font-style').'</th>'.
5596: '<th align="center">'.&mt('Other css').'</th>'.
5597: &Apache::loncommon::end_data_table_row().
1.49.2.21 raeburn 5598: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.49.2.7 raeburn 5599: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5600: }
5601: $datatable .= &item_table_row_end();
5602: }
5603: $$rowtotal += scalar(@{$ordered});
5604: return $datatable;
5605: }
5606:
5607: sub role_checkboxes {
1.49.2.21 raeburn 5608: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5609: my @roles = ('st','ad','ta','ep','in');
5610: if ($crstype eq 'Community') {
5611: push(@roles,'co');
5612: } else {
5613: push(@roles,'cc');
5614: }
1.1 raeburn 5615: my $output;
5616: my (@current,@curr_roles,%currsec,@sections);
5617: if ($showsections) {
5618: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5619: @sections = sort( { $a <=> $b } keys(%sections));
5620: }
5621: if (ref($settings) eq 'HASH') {
5622: if ($settings->{$item}) {
5623: @current = split(',',$settings->{$item});
5624: if ($showsections) {
5625: foreach my $role (@current) {
5626: if ($role =~ /:/) {
5627: my ($trole,$sec) = split(':',$role);
5628: push(@curr_roles,$trole);
5629: if (ref($currsec{$trole}) eq 'ARRAY') {
5630: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5631: push(@{$currsec{$trole}},$sec);
5632: }
1.3 raeburn 5633: } else {
5634: $currsec{$trole} = [$sec];
1.1 raeburn 5635: }
5636: } else {
5637: push(@curr_roles,$role);
5638: }
5639: }
5640: @current = @curr_roles;
5641: }
5642: }
5643: }
5644: my $numinrow = 3;
5645: my $count = 0;
1.49.2.21 raeburn 5646: my $disabled;
5647: if ($noedit) {
5648: $disabled = ' disabled="disabled"';
5649: }
1.1 raeburn 5650: foreach my $role (@roles) {
5651: my $checked = '';
5652: if (grep(/^\Q$role\E$/,@current)) {
5653: $checked = ' checked="checked" ';
5654: }
1.9 raeburn 5655: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5656: if ($showsections) {
5657: $output .= &Apache::loncommon::start_data_table_row();
5658: } else {
5659: my $rem = $count%($numinrow);
5660: if ($rem == 0) {
5661: if ($count > 0) {
5662: $output .= '</tr>';
5663: }
5664: $output .= '<tr>';
5665: }
5666: }
1.30 raeburn 5667: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.49.2.21 raeburn 5668: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5669: $plrole.'</label></span></td>';
5670: if ($showsections) {
5671: $output .= '<td align="left">'.
1.49.2.21 raeburn 5672: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5673: '</td></tr>';
5674: }
5675: $count ++;
5676: }
5677: my %adv_roles =
5678: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5679: my $total = @roles;
5680: foreach my $role (sort(keys(%adv_roles))) {
5681: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5682: my $rolename = $3;
5683: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5684: my $checked = '';
5685: if (grep(/^\Q$value\E$/,@current)) {
5686: $checked = ' checked="checked" ';
5687: }
5688: if ($showsections) {
5689: $output .= &Apache::loncommon::start_data_table_row();
5690: } else {
5691: my $rem = $count%($numinrow);
5692: if ($rem == 0) {
5693: if ($count > 0) {
5694: $output .= '</tr>';
5695: }
5696: $output .= '<tr>';
5697: }
5698: }
1.30 raeburn 5699: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.49.2.21 raeburn 5700: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5701: '</label></span></td>';
5702: if ($showsections) {
5703: $output .= '<td>'.
1.49.2.21 raeburn 5704: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5705: '</td>'.&Apache::loncommon::end_data_table_row();
5706: }
5707: $total ++;
5708: $count ++;
5709: }
5710: }
5711: if (!$showsections) {
5712: my $rem = $total%($numinrow);
5713: my $colsleft = $numinrow - $rem;
5714: if ($colsleft > 1 ) {
5715: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5716: ' </td>';
5717: } elsif ($colsleft == 1) {
5718: $output .= '<td class="LC_left_item"> </td>';
5719: }
5720: $output .= '</tr>';
5721: }
5722: return $output;
5723: }
5724:
1.49.2.3 raeburn 5725: sub set_discussion_fonts {
1.49.2.21 raeburn 5726: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.49.2.3 raeburn 5727: my ($classorder,$classtitles) = &discussion_vote_classes();
5728: my ($styleorder,$styleitems) = &discussion_vote_styles();
5729: my $output;
5730: if (ref($classorder) eq 'ARRAY') {
1.49.2.21 raeburn 5731: my $disabled;
5732: if ($noedit) {
5733: $disabled = ' disabled="disabled"';
5734: }
1.49.2.3 raeburn 5735: foreach my $cat (@{$classorder}) {
5736: my %curr = ();
5737: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5738: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5739: $output .= &Apache::loncommon::start_data_table_row().
5740: '<td>'.$classtitles->{$cat}.'</td>';
5741: if (ref($styleorder) eq 'ARRAY') {
5742: foreach my $item (@{$styleorder}) {
5743: $output .= '<td><span class="LC_nobreak">';
5744: my $selitem = $item;
5745: if ($item eq 'size') {
5746: my ($currsize,$currunit);
5747: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5748: ($currsize,$currunit) = ($1,$2);
5749: $curr{'size'} = $currunit;
5750: }
1.49.2.21 raeburn 5751: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.49.2.3 raeburn 5752: ' ';
5753: $selitem = 'unit';
5754: }
5755: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.49.2.21 raeburn 5756: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.49.2.3 raeburn 5757: foreach my $val (@{$styleitems->{$item}}) {
5758: my $sel;
5759: if ($val eq $curr{$item}) {
5760: $sel = ' selected="selected"';
5761: }
5762: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
5763: }
5764: }
5765: }
5766: }
1.49.2.21 raeburn 5767: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.49.2.3 raeburn 5768: }
5769: $output .= &Apache::loncommon::end_data_table_row();
5770: }
5771: return $output;
5772: }
5773:
5774: sub discussion_vote_classes {
5775: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
5776: my %classtitles = &Apache::lonlocal::texthash(
5777: 'twoplus' => 'Two sigma above mean',
5778: 'oneplus' => 'One sigma above mean',
5779: 'zero' => 'Within one sigma of mean',
5780: 'oneminus' => 'One sigma below mean',
5781: 'twominus' => 'Two sigma below mean',
5782: );
5783: return ($classorder,\%classtitles);
5784: }
5785:
5786: sub discussion_vote_styles {
5787: my $styleorder = ['size','weight','style'];
5788: my $styleitems = {
5789: size => ['','px','%','xx-small','x-small','small','medium','large',
5790: 'x-large','xx-large','smaller','larger'],
5791: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
5792: '500','600','700','800','900'],
5793: style => ['','normal','italic','oblique'],
5794: };
5795: return ($styleorder,$styleitems);
5796: }
5797:
1.1 raeburn 5798: sub print_classlists {
1.49.2.21 raeburn 5799: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5800: my @ordered;
5801: if ($position eq 'top') {
5802: @ordered = ('default_enrollment_start_date',
5803: 'default_enrollment_end_date');
1.49.2.6 raeburn 5804: if ($crstype eq 'Course') {
5805: push(@ordered,'defaultcredits');
5806: }
1.1 raeburn 5807: } elsif ($position eq 'middle') {
1.49.2.7 raeburn 5808: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 5809: } else {
5810: @ordered = ('student_classlist_view',
1.26 raeburn 5811: 'student_classlist_opt_in',
5812: 'student_classlist_portfiles');
1.1 raeburn 5813: }
1.9 raeburn 5814: my %lt;
5815:
5816: if ($crstype eq 'Community') {
5817: %lt = &Apache::lonlocal::texthash (
5818: disabled => 'No viewable membership list',
5819: section => "Membership of viewer's section",
5820: all => 'List of all members',
5821: );
5822: } else {
5823: %lt = &Apache::lonlocal::texthash (
5824: disabled => 'No viewable classlist',
5825: section => "Classlist of viewer's section",
5826: all => 'Classlist of all students',
5827: );
5828: }
5829:
1.1 raeburn 5830: my %items = (
5831: 'default_enrollment_start_date' => {
1.3 raeburn 5832: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 5833: input => 'dates',
5834: },
5835: 'default_enrollment_end_date' => {
1.3 raeburn 5836: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 5837: input => 'dates',
5838: },
1.49.2.7 raeburn 5839: 'defaultcredits' => {
5840: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
5841: },
1.1 raeburn 5842:
5843: 'nothideprivileged' => {
1.3 raeburn 5844: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 5845: input => 'checkbox',
5846: },
5847:
1.49.2.7 raeburn 5848: 'checkforpriv' => {
5849: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
5850: input => 'selectbox',
5851: },
5852:
1.1 raeburn 5853: 'student_classlist_view' => {
1.3 raeburn 5854: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 5855: input => 'selectbox',
1.9 raeburn 5856: options => \%lt,
1.1 raeburn 5857: order => ['disabled','all','section'],
5858: },
1.26 raeburn 5859: 'student_classlist_opt_in' => {
5860: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 5861: input => 'radio',
5862: },
5863:
5864: 'student_classlist_portfiles' => {
1.3 raeburn 5865: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 5866: input => 'radio',
5867: },
5868: );
5869: unless (($settings->{'student_classlist_view'} eq 'all') ||
5870: ($settings->{'student_classlist_view'} eq 'section')) {
5871: $settings->{'student_classlist_view'} = 'disabled';
5872: }
1.49.2.21 raeburn 5873: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 5874: }
5875:
5876: sub print_appearance {
1.49.2.21 raeburn 5877: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5878: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5879: return;
5880: }
1.9 raeburn 5881: my $mathdef;
5882: if ($crstype eq 'Community') {
5883: $mathdef = &mt("None specified - use member's choice");
5884: } else {
5885: $mathdef = &mt("None specified - use student's choice");
5886: }
1.1 raeburn 5887: my %items = (
5888: 'default_xml_style' => {
1.3 raeburn 5889: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 5890: '<a href="javascript:openbrowser'.
5891: "('display','default_xml_style'".
5892: ",'sty')".'">'.&mt('Select Style File').'</a>',
5893: input => 'textbox',
5894: size => 35,
5895: },
5896:
5897: 'pageseparators' => {
1.3 raeburn 5898: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 5899: input => 'radio',
5900: },
5901: 'disable_receipt_display' => {
1.3 raeburn 5902: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 5903: input => 'radio',
5904: },
5905: 'texengine' => {
1.3 raeburn 5906: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 5907: input => 'selectbox',
5908: options => {
1.49.2.11 raeburn 5909: MathJax => 'MathJax',
1.1 raeburn 5910: mimetex => &mt('Convert to Images'),
5911: tth => &mt('TeX to HTML'),
5912: },
1.49.2.20 raeburn 5913: order => ['MathJax','mimetex','tth'],
1.9 raeburn 5914: nullval => $mathdef,
1.1 raeburn 5915: },
5916: 'tthoptions' => {
1.3 raeburn 5917: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 5918: input => 'textbox',
5919: size => 40,
5920: },
1.49.2.17 raeburn 5921: 'uselcmath' => {
5922: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
5923: input => 'radio',
5924: },
5925: 'usejsme' => {
5926: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
5927: input => 'radio',
5928: },
1.49.2.28 raeburn 5929: 'inline_chem' => {
5930: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
5931: input => 'radio',
5932: },
1.49.2.28.2.1 (raeburn 5933:): 'extresource' => {
5934:): text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
5935:): input => 'selectbox',
5936:): options => {
5937:): iframe => 'In iframe',
5938:): tab => 'In new tab',
5939:): window => 'In pop-up window',
5940:): },
5941:): order => ['iframe','tab','window'],
5942:): },
1.1 raeburn 5943: );
1.49.2.21 raeburn 5944: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 5945: }
5946:
5947: sub print_grading {
1.49.2.28.2.1 (raeburn 5948:): my ($cdom,$cnum,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5949: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5950: return;
5951: }
5952: my %items = (
5953: 'grading' => {
1.3 raeburn 5954: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 5955: &Apache::loncommon::help_open_topic('GradingOptions'),
5956: input => 'selectbox',
5957: options => {
5958: standard => &mt('Standard: shows points'),
1.11 www 5959: external => &mt('External: shows number of completed parts and totals'),
5960: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 5961: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
5962: },
1.49.2.2 raeburn 5963: order => ['standard','external','externalnototals','spreadsheet'],
1.1 raeburn 5964: },
5965: 'rndseed' => {
1.3 raeburn 5966: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.49.2.28.2.1 (raeburn 5967:): '<br /><span class="LC_warning LC_nobreak">'.'<br />'.
1.1 raeburn 5968: &mt('Modifying this will make problems have different numbers and answers!').
5969: '</span>',
5970: input => 'selectbox',
5971: options => {
5972: '32bit' => '32bit',
5973: '64bit' => '64bit',
5974: '64bit2' => '64bit2',
5975: '64bit3' => '64bit3',
5976: '64bit4' => '64bit4',
5977: '64bit5' => '64bit5',
5978: },
5979: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 5980: advanced => 1
1.1 raeburn 5981: },
5982: 'receiptalg' => {
1.3 raeburn 5983: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 5984: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 5985: input => 'selectbox',
5986: options => {
5987: receipt => 'receipt',
5988: receipt2 => 'receipt2',
5989: receipt3 => 'receipt3',
5990: },
5991: order => ['receipt','receipt2','receipt3'],
1.41 www 5992: advanced => 1
1.1 raeburn 5993: },
5994: 'disablesigfigs' => {
1.3 raeburn 5995: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 5996: input => 'radio',
5997: },
5998: );
1.49.2.28.2.1 (raeburn 5999:): return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit,$cnum);
1.1 raeburn 6000: }
6001:
6002: sub print_printouts {
1.49.2.21 raeburn 6003: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6004: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6005: return;
6006: }
6007: my %items = (
6008: problem_stream_switch => {
1.3 raeburn 6009: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6010: input => 'radio',
6011: },
6012: suppress_tries => {
1.3 raeburn 6013: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6014: input => 'radio',
6015: },
6016: default_paper_size => {
1.3 raeburn 6017: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6018: input => 'selectbox',
6019: options => {
6020: Letter => &mt('Letter').' [8 1/2x11 in]',
6021: Legal => &mt('Legal').' [8 1/2x14 in]',
6022: Tabloid => &mt('Tabloid').' [11x17 in]',
6023: Executive => &mt('Executive').' [7 1/2x10 in]',
6024: A2 => &mt('A2').' [420x594 mm]',
6025: A3 => &mt('A3').' [297x420 mm]',
6026: A4 => &mt('A4').' [210x297 mm]',
6027: A5 => &mt('A5').' [148x210 mm]',
6028: A6 => &mt('A6').' [105x148 mm]',
6029: },
6030: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.49.2.5 raeburn 6031: nullval => &mt('None specified'),
1.1 raeburn 6032: },
6033: print_header_format => {
1.3 raeburn 6034: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6035: input => 'checkbox',
6036: },
6037: disableexampointprint => {
1.3 raeburn 6038: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6039: input => 'radio',
6040: },
1.14 raeburn 6041: canuse_pdfforms => {
6042: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6043: input => 'selectbox',
6044: options => {
6045: 1 => &mt('Yes'),
6046: 0 => &mt('No'),
6047: },
6048: order => ['1','0'],
1.49.2.5 raeburn 6049: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6050: }
1.1 raeburn 6051: );
1.49.2.21 raeburn 6052: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6053: }
6054:
6055: sub print_spreadsheet {
1.49.2.21 raeburn 6056: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6057: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6058: return;
6059: }
6060: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6061: my %items = (
6062: spreadsheet_default_classcalc => {
1.3 raeburn 6063: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6064: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6065: "('display','spreadsheet_default_classcalc'".
6066: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6067: input => 'textbox',
6068: },
6069: spreadsheet_default_studentcalc => {
1.3 raeburn 6070: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6071: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6072: "('display','spreadsheet_default_calc'".
6073: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6074: input => 'textbox',
6075: },
6076: spreadsheet_default_assesscalc => {
1.3 raeburn 6077: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6078: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6079: "('display','spreadsheet_default_assesscalc'".
6080: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6081: input => 'textbox',
6082: },
6083: hideemptyrows => {
1.3 raeburn 6084: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6085: input => 'radio',
6086: },
6087: );
1.49.2.21 raeburn 6088: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6089: }
1.1 raeburn 6090:
6091: sub print_bridgetasks {
1.49.2.21 raeburn 6092: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6093: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6094: return;
6095: }
1.9 raeburn 6096: my ($stumsg,$msgnote);
6097: if ($crstype eq 'Community') {
6098: $stumsg = &mt('Send message to member');
6099: $msgnote = &mt('Message to member and add to user notes');
6100: } else {
6101: $stumsg = &mt('Send message to student');
6102: $msgnote = &mt('Message to student and add to user notes');
6103: }
1.1 raeburn 6104: my %items = (
6105: task_messages => {
1.3 raeburn 6106: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6107: input => 'selectbox',
6108: options => {
1.9 raeburn 6109: only_student => $stumsg,
6110: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6111: },
6112: order => ['only_student','student_and_user_notes_screen'],
6113: nullval => &mt('No message or record in user notes'),
6114: },
6115: task_grading => {
1.3 raeburn 6116: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6117: input => 'selectbox',
6118: options => {
6119: any => &mt('Grade BTs in any section'),
6120: section => &mt('Grade BTs only in own section')
6121: },
6122: order => ['any','section'],
6123: },
6124: suppress_embed_prompt => {
1.3 raeburn 6125: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6126: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6127: input => 'radio',
6128: },
6129: );
1.49.2.21 raeburn 6130: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6131: }
6132:
1.49.2.28.2.1 (raeburn 6133:): sub print_ltitools {
6134:): my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6135:): my ($datatable,$disabled,$css_class,$dest);
6136:): if ($noedit) {
6137:): $disabled = ' disabled="disabled"';
6138:): }
6139:): my $itemcount = 1;
6140:): unless ($context eq 'domain') {
6141:): my %tooltypes = &Apache::loncommon::usable_exttools();
6142:): unless ($tooltypes{'crs'}) {
6143:): my $showtype = 'course';
6144:): if ($crstype eq 'Community') {
6145:): $showtype = lc($crstype);
6146:): }
6147:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6148:): $datatable = '<tr '.$css_class.'><td colspan="2">'.
6149:): &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6150:): if ($tooltypes{'dom'}) {
6151:): $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6152:): '<i>'.$cdom.'</i>').
6153:): '<br /><br />'.
6154:): &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.");
6155:): } else {
6156:): $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6157:): '<br /><br />'.
6158:): &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6159:): '<i>'.$cdom.'</i>');
6160:):
6161:): }
6162:): $datatable .= '</tr>';
6163:): $itemcount ++;
6164:): return $datatable;
6165:): }
6166:): }
6167:): my %lt = <itools_names();
6168:): my $maxnum = 0;
6169:): my %ordered;
6170:): if (ref($settings) eq 'HASH') {
6171:): foreach my $item (keys(%{$settings})) {
6172:): if (ref($settings->{$item}) eq 'HASH') {
6173:): my $num = $settings->{$item}{'order'};
6174:): $ordered{$num} = $item;
6175:): }
6176:): }
6177:): }
6178:):
6179:): if ($context eq 'domain') {
6180:): $dest = '/adm/domainprefs';
6181:): } else {
6182:): $dest = '/adm/courseprefs';
6183:): }
6184:): my ($switchserver,$switchmessage);
6185:): $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6186:): if ($switchserver) {
6187:): if ($context eq 'domain') {
6188:): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6189:): } elsif ($crstype eq 'Community') {
6190:): $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6191:): } else {
6192:): $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6193:): }
6194:): }
6195:): my $maxnum = scalar(keys(%ordered));
6196:): my @courseroles = ('cc','in','ta','ep','st');
6197:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6198:): my @fields = ('fullname','firstname','lastname','email','roles','user');
6199:): if (keys(%ordered)) {
6200:): my @items = sort { $a <=> $b } keys(%ordered);
6201:): for (my $i=0; $i<@items; $i++) {
6202:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6203:): my $item = $ordered{$items[$i]};
6204:): my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6205:): if (ref($settings->{$item}) eq 'HASH') {
6206:): $title = $settings->{$item}->{'title'};
6207:): $url = $settings->{$item}->{'url'};
6208:): $key = $settings->{$item}->{'key'};
6209:): $usable = $settings->{$item}->{'usable'};
6210:): $lifetime = $settings->{$item}->{'lifetime'};
6211:): my $image = $settings->{$item}->{'image'};
6212:): if ($image ne '') {
6213:): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6214:): }
6215:): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6216:): $sigsel{'HMAC-256'} = ' selected="selected"';
6217:): } else {
6218:): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6219:): }
6220:): }
6221:): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6222:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6223:): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6224:): for (my $k=0; $k<=$maxnum; $k++) {
6225:): my $vpos = $k+1;
6226:): my $selstr;
6227:): if ($k == $i) {
6228:): $selstr = ' selected="selected" ';
6229:): }
6230:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6231:): }
6232:): $datatable .= '</select>'.(' 'x2).
6233:): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6234:): &mt('Delete?').'</label></span></td>'.
6235:): '<td colspan="2">'.
6236:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6237:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6238:): (' 'x2).
6239:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6240:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6241:): (' 'x2).
6242:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6243:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6244:): (' 'x2).
6245:): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6246:): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6247:): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6248:): '<br /><br />'.
6249:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
6250:): ' value="'.$url.'" /></span>'.
6251:): (' 'x2).
6252:): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6253:): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6254:): if ($key ne '') {
6255:): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6256:): if ($noedit) {
6257:): $datatable .= ': ['.&mt('not shown').']';
6258:): } elsif ($switchserver) {
6259:): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6260:): } else {
6261:): $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6262:): }
6263:): $datatable .= '</span> '.(' 'x2);
6264:): } elsif (!$switchserver) {
6265:): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6266:): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6267:): '</span> '.(' 'x2);
6268:): }
6269:): if ($switchserver) {
6270:): if ($usable ne '') {
6271:): $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6272:): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6273:): '<span class="LC_nobreak">'.&mt('Change secret?').
6274:): '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6275:): (' 'x2).
6276:): '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6277:): '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6278:): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6279:): '</div>';
6280:): } elsif ($key eq '') {
6281:): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6282:): } else {
6283:): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6284:): }
6285:): $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6286:): } else {
6287:): if ($usable ne '') {
6288:): $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6289:): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6290:): '<span class="LC_nobreak">'.&mt('Change?').
6291:): '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6292:): (' 'x2).
6293:): '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6294:): '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6295:): '<span class="LC_nobreak">'.&mt('New Secret').':'.
6296:): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6297:): '<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>'.
6298:): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6299:): } else {
6300:): $datatable .=
6301:): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6302:): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6303:): '<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>'.
6304:): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6305:): }
6306:): }
6307:): $datatable .= '</fieldset>'.
6308:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6309:): '<span class="LC_nobreak">'.&mt('Display target:');
6310:): my %currdisp;
6311:): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6312:): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6313:): $currdisp{'window'} = ' checked="checked"';
6314:): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6315:): $currdisp{'tab'} = ' checked="checked"';
6316:): } else {
6317:): $currdisp{'iframe'} = ' checked="checked"';
6318:): }
6319:): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6320:): $currdisp{'width'} = $1;
6321:): }
6322:): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6323:): $currdisp{'height'} = $1;
6324:): }
6325:): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6326:): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6327:): } else {
6328:): $currdisp{'iframe'} = ' checked="checked"';
6329:): }
6330:): foreach my $disp ('iframe','tab','window') {
6331:): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6332:): $lt{$disp}.'</label>'.(' 'x2);
6333:): }
6334:): $datatable .= (' 'x4);
6335:): foreach my $dimen ('width','height') {
6336:): $datatable .= '<label>'.$lt{$dimen}.' '.
6337:): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6338:): (' 'x2);
6339:): }
6340:): $datatable .= '</span><br />'.
6341:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6342:): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6343:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6344:): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6345:): '</textarea></div><div style=""></div><br />';
6346:): my %units = (
6347:): 'passback' => 'days',
6348:): 'roster' => 'seconds',
6349:): );
6350:): foreach my $extra ('passback','roster') {
6351:): my $validsty = 'none';
6352:): my $currvalid;
6353:): my $checkedon = '';
6354:): my $checkedoff = ' checked="checked"';
6355:): if ($settings->{$item}->{$extra}) {
6356:): $checkedon = $checkedoff;
6357:): $checkedoff = '';
6358:): $validsty = 'inline-block';
6359:): if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6360:): $currvalid = $settings->{$item}->{$extra.'valid'};
6361:): }
6362:): }
6363:): my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6364:): $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6365:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6366:): &mt('No').'</label>'.(' 'x2).
6367:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6368:): &mt('Yes').'</label></span></div>'.
6369:): '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6370:): '<span class="LC_nobreak">'.
6371:): &mt("until at least [_1] $units{$extra} after launch",
6372:): '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6373:): '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6374:): }
6375:): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6376:): if ($imgsrc) {
6377:): $datatable .= $imgsrc.
6378:): '<label><input type="checkbox" name="ltitools_image_del"'.
6379:): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6380:): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6381:): } else {
6382:): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6383:): }
6384:): if ($switchserver) {
6385:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6386:): } else {
6387:): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6388:): }
6389:): $datatable .= '</span></fieldset>';
6390:): my (%checkedfields,%rolemaps,$userincdom);
6391:): if (ref($settings->{$item}) eq 'HASH') {
6392:): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6393:): %checkedfields = %{$settings->{$item}->{'fields'}};
6394:): }
6395:): $userincdom = $settings->{$item}->{'incdom'};
6396:): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6397:): %rolemaps = %{$settings->{$item}->{'roles'}};
6398:): $checkedfields{'roles'} = 1;
6399:): }
6400:): }
6401:): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6402:): '<span class="LC_nobreak">';
6403:): my $userfieldstyle = 'display:none;';
6404:): my $seluserdom = '';
6405:): my $unseluserdom = ' selected="selected"';
6406:): foreach my $field (@fields) {
6407:): my ($checked,$onclick,$id,$spacer);
6408:): if ($checkedfields{$field}) {
6409:): $checked = ' checked="checked"';
6410:): }
6411:): if ($field eq 'user') {
6412:): $id = ' id="ltitools_user_field_'.$i.'"';
6413:): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6414:): if ($checked) {
6415:): $userfieldstyle = 'display:inline-block';
6416:): if ($userincdom) {
6417:): $seluserdom = $unseluserdom;
6418:): $unseluserdom = '';
6419:): }
6420:): }
6421:): } else {
6422:): $spacer = (' ' x2);
6423:): }
6424:): $datatable .= '<label>'.
6425:): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6426:): $lt{$field}.'</label>'.$spacer;
6427:): }
6428:): $datatable .= '</span>';
6429:): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6430:): '<span class="LC_nobreak"> : '.
6431:): '<select name="ltitools_userincdom_'.$i.'">'.
6432:): '<option value="">'.&mt('Select').'</option>'.
6433:): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6434:): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6435:): '</select></span></div>';
6436:): $datatable .= '</fieldset>'.
6437:): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6438:): foreach my $role (@courseroles) {
6439:): my ($selected,$selectnone);
6440:): if (!$rolemaps{$role}) {
6441:): $selectnone = ' selected="selected"';
6442:): }
6443:): $datatable .= '<td style="text-align: center">'.
6444:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
6445:): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6446:): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6447:): foreach my $ltirole (@ltiroles) {
6448:): unless ($selectnone) {
6449:): if ($rolemaps{$role} eq $ltirole) {
6450:): $selected = ' selected="selected"';
6451:): } else {
6452:): $selected = '';
6453:): }
6454:): }
6455:): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6456:): }
6457:): $datatable .= '</select></td>';
6458:): }
6459:): $datatable .= '</tr></table></fieldset>';
6460:): my %courseconfig;
6461:): if (ref($settings->{$item}) eq 'HASH') {
6462:): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6463:): %courseconfig = %{$settings->{$item}->{'crsconf'}};
6464:): }
6465:): }
6466:): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6467:): foreach my $item ('label','title','target','linktext','explanation','append') {
6468:): my $checked;
6469:): if ($courseconfig{$item}) {
6470:): $checked = ' checked="checked"';
6471:): }
6472:): $datatable .= '<label>'.
6473:): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6474:): $lt{'crs'.$item}.'</label> '."\n";
6475:): }
6476:): $datatable .= '</span></fieldset>'.
6477:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6478:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6479:): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6480:): my %custom = %{$settings->{$item}->{'custom'}};
6481:): if (keys(%custom) > 0) {
6482:): foreach my $key (sort(keys(%custom))) {
6483:): $datatable .= '<tr><td><span class="LC_nobreak">'.
6484:): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6485:): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6486:): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6487:): ' value="'.$custom{$key}.'" /></td></tr>';
6488:): }
6489:): }
6490:): }
6491:): $datatable .= '<tr><td><span class="LC_nobreak">'.
6492:): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6493:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6494:): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6495:): $datatable .= '</table></fieldset></td></tr>'."\n";
6496:): $itemcount ++;
6497:): }
6498:): }
6499:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6500:): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6501:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6502:): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6503:): '<select name="ltitools_add_pos"'.$chgstr.'>';
6504:): for (my $k=0; $k<$maxnum+1; $k++) {
6505:): my $vpos = $k+1;
6506:): my $selstr;
6507:): if ($k == $maxnum) {
6508:): $selstr = ' selected="selected" ';
6509:): }
6510:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6511:): }
6512:): $datatable .= '</select> '."\n".
6513:): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6514:): '<td colspan="2">'.
6515:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6516:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6517:): (' 'x2).
6518:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6519:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6520:): (' 'x2).
6521:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6522:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6523:): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6524:): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6525:): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6526:): '<br />'.
6527:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
6528:): (' 'x2).
6529:): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6530:): if ($switchserver) {
6531:): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6532:): } else {
6533:): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6534:): (' 'x2).
6535:): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6536:): '<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";
6537:): }
6538:): $datatable .= '<br /><br />'.
6539:): '</fieldset>'.
6540:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6541:): '<span class="LC_nobreak">'.&mt('Display target:');
6542:): my %defaultdisp;
6543:): $defaultdisp{'iframe'} = ' checked="checked"';
6544:): foreach my $disp ('iframe','tab','window') {
6545:): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6546:): $lt{$disp}.'</label>'.(' 'x2);
6547:): }
6548:): $datatable .= (' 'x4);
6549:): foreach my $dimen ('width','height') {
6550:): $datatable .= '<label>'.$lt{$dimen}.' '.
6551:): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6552:): (' 'x2);
6553:): }
6554:): $datatable .= '</span><br />'.
6555:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6556:): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6557:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6558:): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6559:): '</div><div style=""></div><br />';
6560:): my %units = (
6561:): 'passback' => 'days',
6562:): 'roster' => 'seconds',
6563:): );
6564:): my %defaulttimes = (
6565:): 'passback' => '7',
6566:): 'roster' => '300',
6567:): );
6568:): foreach my $extra ('passback','roster') {
6569:): my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6570:): $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6571:): '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6572:): &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6573:): '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6574:): &mt('Yes').'</label></span></div>'.
6575:): '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6576:): '<span class="LC_nobreak">'.
6577:): &mt("until at least [_1] $units{$extra} after launch",
6578:): '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6579:): '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6580:): }
6581:): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6582:): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6583:): if ($switchserver) {
6584:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6585:): } else {
6586:): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6587:): }
6588:): $datatable .= '</span></fieldset>'.
6589:): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6590:): '<span class="LC_nobreak">';
6591:): foreach my $field (@fields) {
6592:): my ($id,$onclick,$spacer);
6593:): if ($field eq 'user') {
6594:): $id = ' id="ltitools_user_field_add"';
6595:): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6596:): } else {
6597:): $spacer = (' ' x2);
6598:): }
6599:): $datatable .= '<label>'.
6600:): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6601:): $lt{$field}.'</label>'.$spacer;
6602:): }
6603:): $datatable .= '</span>'.
6604:): '<div style="display:none;" id="ltitools_user_div_add">'.
6605:): '<span class="LC_nobreak"> : '.
6606:): '<select name="ltitools_add_userincdom">'.
6607:): '<option value="" selected="selected">'.&mt('Select').'</option>'.
6608:): '<option value="0">'.&mt('username').'</option>'.
6609:): '<option value="1">'.&mt('username:domain').'</option>'.
6610:): '</select></span></div></fieldset>';
6611:): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6612:): foreach my $role (@courseroles) {
6613:): my ($checked,$checkednone);
6614:): $datatable .= '<td style="text-align: center">'.
6615:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
6616:): '<select name="ltitools_add_roles_'.$role.'">'.
6617:): '<option value="" selected="selected">'.&mt('Select').'</option>';
6618:): foreach my $ltirole (@ltiroles) {
6619:): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6620:): }
6621:): $datatable .= '</select></td>';
6622:): }
6623:): $datatable .= '</tr></table></fieldset>'.
6624:): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6625:): foreach my $item ('label','title','target','linktext','explanation','append') {
6626:): $datatable .= '<label>'.
6627:): '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6628:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6629:): }
6630:): $datatable .= '</span></fieldset>'.
6631:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6632:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6633:): '<tr><td><span class="LC_nobreak">'.
6634:): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6635:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6636:): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6637:): '</table></fieldset>'."\n".
6638:): '</td>'."\n".
6639:): '</tr>'."\n";
6640:): $itemcount ++;
6641:): return $datatable;
6642:): }
6643:):
6644:): sub ltitools_names {
6645:): my %lt = &Apache::lonlocal::texthash(
6646:): 'title' => 'Title',
6647:): 'version' => 'Version',
6648:): 'msgtype' => 'Message Type',
6649:): 'sigmethod' => 'Signature Method',
6650:): 'url' => 'URL',
6651:): 'key' => 'Key',
6652:): 'lifetime' => 'Nonce lifetime (s)',
6653:): 'secret' => 'Secret',
6654:): 'icon' => 'Icon',
6655:): 'user' => 'User',
6656:): 'fullname' => 'Full Name',
6657:): 'firstname' => 'First Name',
6658:): 'lastname' => 'Last Name',
6659:): 'email' => 'E-mail',
6660:): 'roles' => 'Role',
6661:): 'window' => 'Window',
6662:): 'tab' => 'Tab',
6663:): 'iframe' => 'iFrame',
6664:): 'height' => 'Height',
6665:): 'width' => 'Width',
6666:): 'linktext' => 'Default Link Text',
6667:): 'explanation' => 'Default Explanation',
6668:): 'passback' => 'Tool can return grades:',
6669:): 'roster' => 'Tool can retrieve roster:',
6670:): 'crstarget' => 'Display target',
6671:): 'crslabel' => 'Course label',
6672:): 'crstitle' => 'Course title',
6673:): 'crslinktext' => 'Link Text',
6674:): 'crsexplanation' => 'Explanation',
6675:): 'crsappend' => 'Provider URL',
6676:): );
6677:): return %lt;
6678:): }
6679:):
6680:: sub ltimenu_titles {
6681:: return &Apache::lonlocal::texthash(
6682:: fullname => 'Full name',
6683:: coursetitle => 'Course title',
6684:: role => 'Role',
6685:: logout => 'Logout',
6686:: grades => 'Grades',
6687:: );
6688:: }
6689::
6690:: sub print_menuitems {
6691:: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6692:: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
6693:: return;
6694:: }
6695:: if ($position eq 'top') {
6696:: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
6697:: if ($settings->{'menucollections'} ne '') {
6698:: foreach my $item (split(/;/,$settings->{'menucollections'})) {
6699:: my ($num,$value) = split(/\%/,$item);
6700:: if ($num =~ /^\d+$/) {
6701:: $defaultmenu_options{$num} = $num;
6702:: }
6703:: }
6704:: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
6705:: $addcollection = $defaultmenu_order[-1] + 1;
6706:: } else {
6707:: $addcollection = 1;
6708:: }
6709:: $defaultmenu_options{$addcollection} = $addcollection;
6710:: my %items = (
6711:: 'menudefault' => {
6712:: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
6713:: &mt("(can be overriden in deep-link context)"),
6714:: input => 'selectbox',
6715:: options => \%defaultmenu_options,
6716:: order => \@defaultmenu_order,
6717:: nullval => &mt('Standard (all menus shown)'),
6718:: },
6719:: );
6720:: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
6721:: } else {
6722:: my %menu;
6723:: my $count = 0;
6724:: my $next = 1;
6725:: my ($datatable,$disabled);
6726:: if ($noedit) {
6727:: $disabled = ' disabled="disabled"';
6728:: }
6729::
6730:: my ($ordered,$cats) = &menuitems_categories();
6731:: my @order = @{$ordered};
6732:: my %categories = %{$cats};
6733:: my %menutitles = &menuitems_titles();
6734:: my %menufields = &menuitems_fields();
6735::
6736:: if ($settings->{'menucollections'} ne '') {
6737:: foreach my $item (split(/;/,$settings->{'menucollections'})) {
6738:: my ($num,$value) = split(/\%/,$item);
6739:: if ($num =~ /^\d+$/) {
6740:: my @entries = split(/\&/,$value);
6741:: foreach my $entry (@entries) {
6742:: my ($name,$fields) = split(/=/,$entry);
6743:: $menu{$num}{$name} = $fields;
6744:: }
6745:: }
6746:: }
6747:: if (keys(%menu)) {
6748:: my @current = sort { $a <=> $b } keys(%menu);
6749:: $next += $current[-1];
6750:: foreach my $num (@current) {
6751:: my %checked;
6752:: my $on = ' checked="checked"';
6753:: foreach my $key (keys(%{$menu{$num}})) {
6754:: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
6755:: if ($menu{$num}{$key} eq 'y') {
6756:: $checked{$key} = $on;
6757:: }
6758:: } else {
6759:: foreach my $field (split(/,/,$menu{$num}{$key})) {
6760:: if (exists($menufields{$field})) {
6761:: $checked{$field} = $on;
6762:: }
6763:: }
6764:: }
6765:: }
6766:: if (ref($menu{$num}) eq 'HASH') {
6767:: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
6768:: foreach my $category (@order) {
6769:: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
6770:: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
6771:: if ($category eq 'text') {
6772:: $datatable .= '<i>'.&mt('Header').'</i><br />';
6773:: }
6774:: foreach my $field (@{$categories{$category}}) {
6775:: if ($field eq 'disc') {
6776:: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
6777:: }
6778:: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
6779:: $menufields{$field}.'</label><br />';
6780:: }
6781:: $datatable .= '</fieldset>';
6782:: }
6783:: }
6784:: $datatable .= &item_table_row_end();
6785:: $count ++;
6786:: }
6787:: }
6788:: }
6789:: } elsif ($noedit) {
6790:: my $text = &mt('No menu collections defined for this course.');
6791:: $datatable .= &item_table_row_start($text,$count);
6792:: }
6793:: unless ($noedit) {
6794:: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
6795:: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
6796:: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
6797:: foreach my $category (@order) {
6798:: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
6799:: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
6800:: foreach my $field (@{$categories{$category}}) {
6801:: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
6802:: $menufields{$field}.'</label><br />';
6803:: }
6804:: $datatable .= '</fieldset>';
6805:: }
6806:: }
6807:: $datatable .= &item_table_row_end();
6808:: $count ++;
6809:: }
6810:: return $datatable;
6811:: }
6812:: }
6813::
6814:: sub menuitems_abbreviations {
6815:: my %briefcats = (
6816:: text => 'pt',
6817:: links => 'p',
6818:: list => 'ps',
6819:: inline => 's',
6820:: );
6821:: return %briefcats;
6822:: }
6823::
6824:: sub menuitems_categories {
6825:: my @order = ('shown','text','links','list','inline');
6826:: my %categories = (
6827:: shown => ['top','inline','foot','main'],
6828:: text => ['name','role','crs','disc','fdbk'],
1.49.2.28.2.4 (raeburn 6829:: links => ['pers','logo','comm','roles','help','logout'],
1.49.2.28.2.1 (raeburn 6830:: list => ['about','prefs','port','wish','anno','rss'],
6831:: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
6832:: );
6833:: return (\@order,\%categories);
6834:: }
6835::
6836:: sub menuitems_titles {
6837:: return &Apache::lonlocal::texthash (
6838:: shown => 'Hierarchy',
6839:: text => 'Text',
6840:: links => 'Header links',
6841:: list => 'Drop-down list',
6842:: inline => 'Inline links',
6843:: );
6844:: }
6845::
6846:: sub menuitems_fields {
6847:: return &Apache::lonlocal::texthash (
6848:: top => 'Display header',
6849:: inline => 'Display inline menu',
6850:: foot => 'Display footer',
6851:: main => 'Access to main menu',
6852:: pers => 'Personal',
6853:: logo => 'LON-CAPA',
6854:: comm => 'Messages',
6855:: roles => 'Roles/Courses',
6856:: help => 'Help',
6857:: logout => 'Logout',
6858:: name => 'Fullname',
6859:: crs => 'Course Title',
6860:: role => 'Current Role',
6861:: disc => 'Discussion',
6862:: fdbk => 'Feedback',
6863:: about => 'Information',
6864:: prefs => 'Preferences',
6865:: port => 'Portfolio',
6866:: wish => 'Stored Links',
6867:: anno => 'Calendar',
6868:: rss => 'RSS Feeds',
6869:: cont => 'Contents',
6870:: grades => 'Grades',
6871:: chat => 'Chat',
6872:: people => 'People',
6873:: groups => 'Groups',
6874:: resv => 'Reservations',
6875:: syll => 'Syllabus',
6876:: feeds => 'Feeds',
6877:: );
6878:: }
6879::
6880:: sub menucollections_display {
6881:: my ($collections) = @_;
6882:: my %menu;
6883:: my ($ordered,$cats) = &menuitems_categories();
6884:: my @order = @{$ordered};
6885:: my %categories = %{$cats};
6886:: my %menutitles = &menuitems_titles();
6887:: my %menufields = &menuitems_fields();
6888:: foreach my $item (split(/;/,$collections)) {
6889:: my ($num,$value) = split(/\%/,$item);
6890:: if ($num =~ /^\d+$/) {
6891:: my @entries = split(/\&/,$value);
6892:: foreach my $entry (@entries) {
6893:: my ($name,$fields) = split(/=/,$entry);
6894:: $menu{$num}{$name} = $fields;
6895:: }
6896:: }
6897:: }
6898:: my $output = '';
6899:: if (keys(%menu)) {
6900:: my @current = sort { $a <=> $b } keys(%menu);
6901:: foreach my $num (@current) {
6902:: my %checked;
6903:: foreach my $key (keys(%{$menu{$num}})) {
6904:: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
6905:: if ($menu{$num}{$key} eq 'y') {
6906:: $checked{$key} = 1;
6907:: }
6908:: } else {
6909:: foreach my $field (split(/,/,$menu{$num}{$key})) {
6910:: if (exists($menufields{$field})) {
6911:: $checked{$field} = 1;
6912:: }
6913:: }
6914:: }
6915:: }
6916:: if (ref($menu{$num}) eq 'HASH') {
6917:: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
6918:: foreach my $category (@order) {
6919:: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
6920:: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
6921:: '<legend>'.$menutitles{$category}.'</legend>'."\n";
6922:: if ($category eq 'text') {
6923:: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
6924:: }
6925:: foreach my $field (@{$categories{$category}}) {
6926:: if ($field eq 'disc') {
6927:: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
6928:: }
6929:: if ($checked{$field}) {
6930:: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
6931:: } else {
6932:: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
6933:: }
6934:: $output .= '<br />';
6935:: }
6936:: $output .= '</fieldset>';
6937:: }
6938:: }
6939:: $output .= '</fieldset>';
6940:: }
6941:: }
6942:: }
6943:: return $output;
6944:: }
6945::
6946:: sub print_linkprotection {
1.49.2.28.2.5 (raeburn 6947:: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.49.2.28.2.1 (raeburn 6948::
6949:: my %linkprotection;
6950:: my $count = 0;
6951:: my $next = 1;
1.49.2.28.2.5 (raeburn 6952:: my ($datatable,$disabled,$css_class,$dest);
1.49.2.28.2.1 (raeburn 6953:: if ($noedit) {
6954:: $disabled = ' disabled="disabled"';
6955:: }
1.49.2.28.2.3 (raeburn 6956:: my %desc = &linkprot_names();
6957:: my %lt = &Apache::lonlocal::texthash (
6958:: 'requ' => 'Required settings',
6959:: 'opti' => 'Optional settings',
6960:: );
1.49.2.28.2.1 (raeburn 6961:: my $itemcount = 0;
6962::
1.49.2.28.2.3 (raeburn 6963:: my $ltiauth;
1.49.2.28.2.5 (raeburn 6964:: if ($context eq 'domain') {
6965:: $ltiauth = 1;
1.49.2.28.2.3 (raeburn 6966:: } else {
1.49.2.28.2.5 (raeburn 6967:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
6968:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
6969:: } else {
6970:: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
6971:: $ltiauth = $domdefs{'crsltiauth'};
6972:: }
6973:: }
6974:: if ($context eq 'domain') {
6975:: $dest = '/adm/domainprefs';
6976:: } else {
6977:: $dest = '/adm/courseprefs';
1.49.2.28.2.3 (raeburn 6978:: }
6979::
1.49.2.28.2.5 (raeburn 6980:: my ($switchserver,$switchmessage);
6981:: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6982:: if ($switchserver) {
6983:: if ($context eq 'domain') {
6984:: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6985:: } elsif ($crstype eq 'Community') {
6986:: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6987:: } else {
6988:: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6989:: }
6990:: }
6991::
1.49.2.28.2.6 (raeburn 6992:: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.49.2.28.2.5 (raeburn 6993:: if (keys(%{$settings->{'linkprot'}})) {
6994:: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.49.2.28.2.1 (raeburn 6995:: $next += $current[-1];
6996:: for (my $i=0; $i<@current; $i++) {
6997:: my $num = $current[$i];
6998:: my %values;
1.49.2.28.2.5 (raeburn 6999:: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7000:: %values = %{$settings->{'linkprot'}->{$num}};
1.49.2.28.2.1 (raeburn 7001:: } else {
7002:: next;
7003:: }
7004:: my $selected;
7005:: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7006:: $selected = ' selected="selected"';
7007:: }
7008:: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7009:: $datatable .=
7010:: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7011:: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.49.2.28.2.3 (raeburn 7012:: &mt('Delete?').'</label></span></td><td>';
1.49.2.28.2.1 (raeburn 7013:): my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7014:): $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
7015:): $passbacksty = 'none';
7016:): $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
7017:): %checkedpassback = (
7018:): 'no' => ' checked="checked"',
7019:): 'yes' => '',
7020:): );
7021:): %checkedpassbackfmt = (
7022:): '1p1' => ' checked="checked"',
7023:): '1p0' => '',
7024:): );
7025:): if ($values{'passback'} ne '') {
7026:): $passbacksty = 'inline-block';
7027:): $checkedpassback{'yes'} = ' checked="checked"';
7028:): $checkedpassback{'no'} = '';
7029:): if ($values{'passbackformat'} eq '1.0') {
7030:): $checkedpassbackfmt{'1p0'} = ' checked="checked"';
7031:): $checkedpassbackfmt{'1p1'} = '';
7032:): }
7033:): }
1.49.2.28.2.3 (raeburn 7034:: if ($ltiauth) {
7035:: $usersty = 'display:none';
1.49.2.28.2.1 (raeburn 7036:): $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.49.2.28.2.3 (raeburn 7037:: %checkedrequser = (
7038:: no => ' checked="checked"',
7039:: yes => '',
7040:: );
7041:: if ($values{'requser'}) {
7042:: $checkedrequser{'yes'} = $checkedrequser{'no'};
7043:: $checkedrequser{'no'} = '';
7044:: }
7045:: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7046:: if ($values{'requser'}) {
7047:: $usersty = 'display:inline-block';
7048:: }
7049:: }
1.49.2.28.2.1 (raeburn 7050:): $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7051:): %checkedreturnurl = (
7052:): no => ' checked="checked"',
7053:): yes => '',
7054:): );
7055:): if ($values{'returnurl'} ne '') {
7056:): $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7057:): $checkedreturnurl{'no'} = '';
7058:): }
7059:): $datatable .=
1.49.2.28.2.3 (raeburn 7060:: '<span class="LC_nobreak">'.$desc{'name'}.
7061:: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.49.2.28.2.1 (raeburn 7062:: (' 'x2).
1.49.2.28.2.3 (raeburn 7063:: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.49.2.28.2.1 (raeburn 7064:: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7065:: (' 'x2).
1.49.2.28.2.3 (raeburn 7066:: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.49.2.28.2.1 (raeburn 7067:): ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.49.2.28.2.3 (raeburn 7068:: if ($values{'key'} ne '') {
7069:: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
7070:: if ($noedit) {
7071:: $datatable .= ': ['.&mt('not shown').']';
7072:: } elsif ($switchserver) {
7073:: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7074:: } else {
7075:: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7076:: }
7077:: $datatable .= '</span> '.(' 'x2);
7078:: } elsif (!$switchserver) {
7079:: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
7080:: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7081:: '</span> '.(' 'x2);
7082:: }
7083:: if ($switchserver) {
7084:: if ($values{'usable'} ne '') {
7085:: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
7086:: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
7087:: '<span class="LC_nobreak">'.&mt('Change secret?').
1.49.2.28.2.1 (raeburn 7088:): '<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.49.2.28.2.3 (raeburn 7089:: (' 'x2).
1.49.2.28.2.1 (raeburn 7090:): '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
1.49.2.28.2.3 (raeburn 7091:: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.49.2.28.2.5 (raeburn 7092:: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.49.2.28.2.3 (raeburn 7093:: '</div>';
7094:: } elsif ($values{'key'} eq '') {
1.49.2.28.2.5 (raeburn 7095:: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.49.2.28.2.3 (raeburn 7096:: } else {
1.49.2.28.2.5 (raeburn 7097:: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.49.2.28.2.3 (raeburn 7098:: }
1.49.2.28.2.1 (raeburn 7099:): $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.49.2.28.2.3 (raeburn 7100:: } else {
7101:: if ($values{'usable'} ne '') {
7102:: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
7103:: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
7104:: '<span class="LC_nobreak">'.&mt('Change?').
1.49.2.28.2.1 (raeburn 7105:): '<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.49.2.28.2.3 (raeburn 7106:: (' 'x2).
1.49.2.28.2.1 (raeburn 7107:): '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.49.2.28.2.3 (raeburn 7108:: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7109:: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.49.2.28.2.1 (raeburn 7110:): '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.49.2.28.2.7 (raeburn 7111:: '<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.49.2.28.2.3 (raeburn 7112:: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7113:: } else {
7114:: $datatable .=
7115:: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.49.2.28.2.1 (raeburn 7116:): '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.49.2.28.2.7 (raeburn 7117:: '<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.49.2.28.2.3 (raeburn 7118:: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7119:: }
7120:: }
1.49.2.28.2.1 (raeburn 7121:): $datatable .= '<br /><br />'.
7122:): '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7123:): '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7124:): $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7125:): '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7126:): $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7127:): '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7128:): '<span class="LC_nobreak">'.&mt('Grade format').
7129:): '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7130:): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7131:): '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7132:): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7133:): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7134:): '<br />'.
7135:): '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7136:): '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7137:): $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7138:): '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7139:): $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7140:): ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7141:): '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7142:): '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7143:): '</span></div> ';
1.49.2.28.2.3 (raeburn 7144:: if ($ltiauth) {
1.49.2.28.2.1 (raeburn 7145:): $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7146:): '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7147:): $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7148:): '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7149:): $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.49.2.28.2.3 (raeburn 7150:: '</fieldset>'.
7151:: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7152:: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7153:: '</fieldset>';
7154:: }
7155:: $datatable .= '</td></tr>';
1.49.2.28.2.1 (raeburn 7156:: $itemcount ++;
7157:: }
7158:: }
7159:: }
7160:: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7161:: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7162:: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.49.2.28.2.3 (raeburn 7163:: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.49.2.28.2.6 (raeburn 7164:: '<td width="100%">';
1.49.2.28.2.1 (raeburn 7165:): my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7166:): $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.49.2.28.2.3 (raeburn 7167:: if ($ltiauth) {
7168:: $usersty = 'display:none';
1.49.2.28.2.1 (raeburn 7169:): $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.49.2.28.2.3 (raeburn 7170:: %checkedrequser = (
7171:: no => ' checked="checked"',
7172:: yes => '',
7173:: );
7174:: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7175:: }
1.49.2.28.2.1 (raeburn 7176:): $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7177:): %checkedpassback = (
7178:): 'no' => ' checked="checked"',
7179:): 'yes' => '',
7180:): );
7181:): %checkedpassbackfmt = (
7182:): '1p1' => ' checked="checked"',
7183:): '1p0' => '',
7184:): );
7185:): $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7186:): %checkedreturnurl = (
7187:): no => ' checked="checked"',
7188:): yes => '',
7189:): );
1.49.2.28.2.3 (raeburn 7190:: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
7191:: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.49.2.28.2.1 (raeburn 7192:: (' 'x2).
1.49.2.28.2.3 (raeburn 7193:: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.49.2.28.2.1 (raeburn 7194:: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7195:: (' 'x2).
7196:): '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7197:): '<br /><br />';
1.49.2.28.2.3 (raeburn 7198:: if ($switchserver) {
1.49.2.28.2.5 (raeburn 7199:: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.49.2.28.2.3 (raeburn 7200:: } else {
7201:: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':<input type="text" size="25" name="linkprot_key_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
7202:: (' 'x2).
1.49.2.28.2.1 (raeburn 7203:): '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.49.2.28.2.7 (raeburn 7204:: '<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.49.2.28.2.3 (raeburn 7205:: }
1.49.2.28.2.1 (raeburn 7206:): $datatable .= '<br /><br />'.
7207:): '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7208:): '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7209:): $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7210:): '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7211:): $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7212:): '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none" />'.
7213:): '<span class="LC_nobreak">'.&mt('Grade format').
7214:): '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7215:): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7216:): '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7217:): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7218:): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7219:): '<br />'.
7220:): '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7221:): '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7222:): $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7223:): '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7224:): $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7225:): ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7226:): '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7227:): '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7228:): '</span></div> ';
1.49.2.28.2.3 (raeburn 7229:: if ($ltiauth) {
1.49.2.28.2.1 (raeburn 7230:): $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7231:): '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7232:): $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7233:): '<label><input type="radio" name="linkprot_requser_add" value="1"'.
7234:): $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7235:): '</fieldset>'.
1.49.2.28.2.3 (raeburn 7236:: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7237:: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7238:: '</fieldset>';
7239:: }
7240:: $datatable .= '</td></tr>';
1.49.2.28.2.1 (raeburn 7241:: $$rowtotal ++;
1.49.2.28.2.3 (raeburn 7242:: return $datatable;
1.49.2.28.2.1 (raeburn 7243:: }
7244::
7245:: sub linkprot_names {
1.49.2.28.2.3 (raeburn 7246:: return &Apache::lonlocal::texthash(
1.49.2.28.2.1 (raeburn 7247:: 'version' => 'LTI Version',
7248:: 'key' => 'Key',
7249:: 'lifetime' => 'Nonce lifetime (s)',
1.49.2.28.2.3 (raeburn 7250:: 'name' => 'Launcher Application',
1.49.2.28.2.1 (raeburn 7251:: 'secret' => 'Secret',
7252:): 'passback' => 'Can return grades to Launcher',
7253:): 'returnurl' => 'Launcher return URL',
1.49.2.28.2.3 (raeburn 7254:: 'requser' => 'Use identity',
7255:: 'email' => 'Email address',
7256:: 'sourcedid' => 'User ID',
7257:: 'other' => 'Other',
7258:: 'auth' => 'Display LON-CAPA login page',
7259:: 'reject' => 'Discontinue launch process',
1.49.2.28.2.1 (raeburn 7260:: );
1.49.2.28.2.3 (raeburn 7261:: }
7262::
7263:: sub check_switchserver {
1.49.2.28.2.5 (raeburn 7264:: my ($cdom,$cnum,$context,$dest) = @_;
7265:: my ($allowed,$switchserver,$home);
7266:: if ($context eq 'domain') {
7267:: $home = &Apache::lonnet::domain($cdom,'primary');
7268:: } else {
7269:: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7270:: }
7271:: unless (($home eq 'no_host') || ($home eq '')) {
1.49.2.28.2.3 (raeburn 7272:: my @ids=&Apache::lonnet::current_machine_ids();
7273:: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7274:: if (!$allowed) {
7275:: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7276:: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.49.2.28.2.5 (raeburn 7277:: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.49.2.28.2.3 (raeburn 7278:: }
7279:: }
7280:: return $switchserver;
7281:: }
7282::
7283:: sub linkprot_options {
7284:: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7285:: my %lt;
7286:: if (ref($desc) eq 'HASH') {
7287:: %lt = %{$desc};
7288:: }
7289:: my $userfieldsty = 'none';
7290:: my (%checked,$userfield);
7291:: $checked{'sourcedid'} = ' checked="checked"';
7292:: $checked{'reject'} = ' checked="checked"';
7293:: if (ref($current) eq 'HASH') {
7294:: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7295:: $checked{'sourcedid'} = '';
7296:: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7297:: $checked{'email'} = ' checked="checked"';
7298:: } else {
7299:: $checked{'other'} = ' checked="checked"';
7300:: $userfield = $current->{'mapuser'};
7301:: $userfieldsty = 'inline-block';
7302:: }
7303:: }
7304:: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7305:: $checked{'reject'} = '';
7306:: $checked{'auth'} = ' checked="checked"';
7307:: }
7308:: }
1.49.2.28.2.1 (raeburn 7309:): my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.49.2.28.2.3 (raeburn 7310:: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7311:: &mt('Source of LON-CAPA username in LTI request').': ';
7312:: foreach my $option ('sourcedid','email','other') {
7313:: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7314:: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7315:: ($option eq 'other' ? '' : (' 'x2) );
7316:: }
7317:: $output .= '</span></div>'.
7318:: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7319:: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7320:: 'value="'.$userfield.'"'.$disabled.' /></div>';
7321:: $output .= '<br />'.
7322:: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7323:: &mt('Action when username is not for an enrolled student').': ';
7324:: foreach my $option ('reject','auth') {
7325:: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7326:: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7327:: ($option eq 'auth' ? '' : (' 'x2) );
7328:: }
7329:: $output .= '</span></div>';
7330:: return $output;
1.49.2.28.2.1 (raeburn 7331:: }
7332::
7333:): sub print_extresource_row {
7334:): my ($item,$config,$curr,$noedit) = @_;
7335:): my $onchange;
7336:): unless ($noedit) {
7337:): $onchange = ' onchange="javascript:toggleExtRes();"';
7338:): }
7339:): my $id = 'LC_'.$item;
7340:): my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7341:): my $output = &select_from_options($item,$config->{'order'},
7342:): $config->{'options'},$selected,
7343:): $config->{'nullval'},
7344:): undef,undef,$onchange,$noedit,$id);
7345:): my ($checked,$reusesty,$sizesty);
7346:): if ($reuse) {
7347:): $checked = ' checked="checked"';
7348:): }
7349:): $reusesty = 'none';
7350:): $sizesty = 'none';
7351:): if (($selected eq 'window') || ($selected eq 'tab')) {
7352:): $reusesty = 'inline-block';
7353:): if ($selected eq 'window') {
7354:): $sizesty = 'inline-block';
7355:): }
7356:): }
7357:): $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7358:): '<span class="LC_nobreak">'.
7359:): '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7360:): &mt('Re-use tab/window').'</label>'.
7361:): '</span></div>'.
7362:): '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7363:): '<legend>'.&mt('Window size (optional)').'</legend>'.
7364:): '<span class="LC_nobreak">'.
7365:): &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7366:): (' ' x 3).
7367:): &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7368:): '</span></fieldset>';
7369:): return $output;
7370:): }
7371:):
1.1 raeburn 7372: sub print_other {
1.49.2.21 raeburn 7373: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7374: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7375: return;
7376: }
1.3 raeburn 7377: my @ordered = &get_other_items($cdom,$settings,$allitems);
7378: my %items;
7379: foreach my $parameter (@ordered) {
7380: $items{$parameter} = {
7381: text => '<b>'.$parameter.'</b>',
7382: input => 'textbox',
7383: size => '15',
7384: },
7385: }
7386: push (@ordered,'newp_value');
7387: $items{'newp_value'} = {
7388: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7389: '<input type="textbox" name="newp_name"'.
7390: ' value="" size="30" />',
7391: input => 'textbox',
7392: size => '30',
7393: };
1.49.2.27 raeburn 7394: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7395: }
7396:
7397: sub get_other_items {
7398: my ($cdom,$settings,$allitems) = @_;
7399: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7400: return;
7401: }
1.1 raeburn 7402: my @ordered;
7403: if (ref($settings) eq 'HASH') {
7404: foreach my $parameter (sort(keys(%{$settings}))) {
7405: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7406: next if (($parameter eq 'course.helper.not.run') &&
7407: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7408: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7409: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7410: || ($parameter eq 'type') ||
1.49.2.3 raeburn 7411: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.49.2.11 raeburn 7412: || ($parameter =~ m/^discussion_post_fonts/) ||
7413: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7414: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7415: push(@ordered,$parameter);
7416: }
7417: }
7418: }
1.3 raeburn 7419: return @ordered;
1.1 raeburn 7420: }
7421:
7422: sub item_table_row_start {
1.49.2.28.2.1 (raeburn 7423:: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7424: my $output;
1.49.2.7 raeburn 7425: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7426: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.49.2.28.2.1 (raeburn 7427:: if ($leftclass eq '') {
7428:: $leftclass = 'LC_left_item';
7429:: }
7430:: if ($rightclass eq '') {
7431:: $rightclass = 'LC_right_item';
7432:: }
1.49.2.7 raeburn 7433: $output .= '<tr class="'.$css_class.'">'."\n".
1.49.2.28.2.1 (raeburn 7434:: '<td class="'.$leftclass.'">'.$text.
1.49.2.7 raeburn 7435: '</td>';
1.49.2.28.2.1 (raeburn 7436:: if ($colspan > 1) {
7437:: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.49.2.7 raeburn 7438: } else {
1.49.2.28.2.1 (raeburn 7439:: $output .= '<td class="'.$rightclass.'">';
1.49.2.7 raeburn 7440: }
1.1 raeburn 7441: return $output;
7442: }
7443:
7444: sub item_table_row_end {
7445: return '</td></tr>';
7446: }
7447:
7448: sub yesno_radio {
1.49.2.28.2.1 (raeburn 7449:): my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit,$onclick,$reverse) = @_;
1.1 raeburn 7450: my $itemon = ' ';
7451: my $itemoff = ' checked="checked" ';
1.49.2.17 raeburn 7452: if (($valueyes eq '') && ($valueno eq '')) {
7453: $valueyes = 'yes';
7454: $valueno = '';
7455: }
1.1 raeburn 7456: if (ref($settings) eq 'HASH') {
1.49.2.17 raeburn 7457: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7458: $itemon = $itemoff;
7459: $itemoff = ' ';
7460: }
1.49.2.17 raeburn 7461: unless (exists($settings->{$item})) {
7462: if ($unsetdefault eq $valueyes) {
7463: $itemon = $itemoff;
7464: $itemoff = ' ';
7465: }
7466: }
1.1 raeburn 7467: }
1.49.2.21 raeburn 7468: my $disabled;
7469: if ($noedit) {
7470: $disabled = ' disabled="disabled"';
1.49.2.28.2.1 (raeburn 7471:): } elsif ($onclick) {
7472:): $onclick = ' onclick="'.$onclick.'"';
7473:): }
7474:): if ($reverse) {
7475:): return '<span class="LC_nobreak"><label>'.
7476:): '<input type="radio" name="'.$item.'"'.
7477:): $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label> '.
7478:): '<label><input type="radio" name="'.$item.'"'.
7479:): $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label></span>';
7480:): } else {
7481:): return '<span class="LC_nobreak"><label>'.
7482:): '<input type="radio" name="'.$item.'"'.
7483:): $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label> '.
7484:): '<label><input type="radio" name="'.$item.'"'.
7485:): $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label></span>';
1.49.2.21 raeburn 7486: }
1.1 raeburn 7487: }
7488:
7489: sub select_from_options {
1.49.2.28.2.1 (raeburn 7490:: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7491: my $output;
1.49.2.21 raeburn 7492: my $disabled;
7493: if ($noedit) {
7494: $disabled = ' disabled=disabled"';
7495: }
1.1 raeburn 7496: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7497: $output='<select name="'.$item.'" '.$onchange;
7498: if ($multiple) {
7499: $output .= ' multiple="multiple"';
7500: my $num = @{$order};
7501: $num ++ if ($nullval ne '');
7502: if (($maxsize) && ($maxsize < $num)) {
7503: $output .= ' size="'.$maxsize.'"';
7504: }
7505: }
1.49.2.28.2.1 (raeburn 7506:: if ($id ne '') {
7507:: $output .= ' id="'.$id.'"';
7508:: }
1.49.2.21 raeburn 7509: $output .= $disabled.'>'."\n";
1.1 raeburn 7510: if ($nullval ne '') {
7511: $output .= '<option value=""';
7512: if (ref($curr) eq 'ARRAY') {
7513: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7514: $output .= ' selected="selected" ';
7515: }
7516: } else {
7517: if ($curr eq '') {
7518: $output .= ' selected="selected" ';
7519: }
7520: }
7521: $output .= '>'.$nullval.'</option>';
7522: }
7523: foreach my $option (@{$order}) {
7524: $output.= '<option value="'.$option.'"';
7525: if (ref($curr) eq 'ARRAY') {
7526: if (grep(/^\Q$option\E$/,@{$curr})) {
7527: $output .= ' selected="selected" ';
7528: }
7529: } else {
7530: if ($option eq $curr) {
7531: $output.=' selected="selected"';
7532: }
7533: }
7534: $output.=">$options->{$option}</option>\n";
7535: }
7536: $output.="</select>";
7537: }
7538: return $output;
7539: }
7540:
7541: sub make_item_rows {
1.49.2.28.2.1 (raeburn 7542:): my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit,$cnum) = @_;
1.1 raeburn 7543: my $datatable;
7544: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7545: my $count = 0;
7546: foreach my $item (@{$ordered}) {
7547: $count ++;
1.49.2.7 raeburn 7548: my $colspan;
7549: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7550: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7551: $colspan = 2;
7552: }
1.49.2.28.2.1 (raeburn 7553:): my $rowdesc;
7554:): if ($caller eq 'appearance') {
7555:): $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7556:): } else {
7557:): $rowdesc = $items->{$item}{text};
7558:): }
1.41 www 7559: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.49.2.28.2.1 (raeburn 7560:): $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7561: } else {
1.49.2.28.2.1 (raeburn 7562:): $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7563: }
1.49.2.6 raeburn 7564: if ($item eq 'defaultcredits') {
7565: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7566: my $showcredits;
7567: if ($defaultcredits ne '') {
7568: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7569: } else {
7570: $showcredits = &mt('No default set');
7571: }
7572: $datatable .= $showcredits;
7573: } elsif ($item eq 'nothideprivileged') {
1.49.2.21 raeburn 7574: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.49.2.7 raeburn 7575: } elsif ($item eq 'checkforpriv') {
1.49.2.21 raeburn 7576: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7577: } elsif ($item eq 'print_header_format') {
1.49.2.21 raeburn 7578: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.49.2.28.2.1 (raeburn 7579:): } elsif ($item eq 'extresource') {
7580:): $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7581: } elsif ($items->{$item}{input} eq 'dates') {
1.49.2.21 raeburn 7582: my $disabled;
7583: if ($noedit) {
7584: $disabled = ' disabled="disabled"';
7585: }
1.1 raeburn 7586: $datatable .=
7587: &Apache::lonhtmlcommon::date_setter('display',$item,
1.49.2.21 raeburn 7588: $settings->{$item},$disabled);
1.1 raeburn 7589: } elsif ($items->{$item}{input} eq 'radio') {
1.49.2.17 raeburn 7590: my ($unsetdefault,$valueyes,$valueno);
1.49.2.28 raeburn 7591: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.49.2.17 raeburn 7592: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7593: unless ($domdefs{$item} eq '0') {
7594: $unsetdefault = 1;
7595: }
7596: $valueyes = "1";
7597: $valueno = "0";
7598: }
1.49.2.21 raeburn 7599: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7600: } elsif ($items->{$item}{input} eq 'selectbox') {
1.49.2.28.2.1 (raeburn 7601:): my ($id,$onchange);
7602:: if ($caller eq 'menuitems') {
7603:: $id = $item;
7604:): } elsif ($caller eq 'grading') {
7605:): if ($item eq 'grading') {
7606:): $onchange = ' onchange="javascript:toggleGrading(this.form);"';
7607:): $id = $item;
7608:): }
7609:: }
1.1 raeburn 7610: my $curr = $settings->{$item};
7611: $datatable .=
7612: &select_from_options($item,$items->{$item}{'order'},
7613: $items->{$item}{'options'},$curr,
1.49.2.21 raeburn 7614: $items->{$item}{'nullval'},
1.49.2.28.2.1 (raeburn 7615:): undef,undef,$onchange,$noedit,$id);
7616:): if ($item eq 'grading') {
7617:): my ($unsetdefault,$valueyes,$valueno,$sectionbox);
7618:): my $gradingsty = 'none';
7619:): my $gradingsecsty = 'none';
7620:): $unsetdefault = 0;
7621:): my (@selsec,@sections,%current);
7622:): if ($curr eq 'standard') {
7623:): $gradingsty = 'inline-block';
7624:): if (ref($settings) eq 'HASH') {
7625:): $current{'hidetotals'} = $settings->{'hidetotals'};
7626:): if ($settings->{'hidetotals'} =~ /^([\w,]+)$/) {
7627:): my $secstr = $1;
7628:): unless ($secstr eq 'all') {
7629:): @selsec = split(/,/,$secstr);
7630:): }
7631:): $current{'hidetotals'} = 1;
7632:): }
7633:): }
7634:): }
7635:): $valueyes = "1";
7636:): $valueno = "0";
7637:): my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
7638:): if (keys(%sections)) {
7639:): @sections = sort( { $a <=> $b } keys(%sections));
7640:): }
7641:): my $onclick = 'javascript:toggleHiddenTotalsSec(this.form);';
7642:): my $sectionbox = '<div id="sectotalsdiv" style="display:'.$gradingsecsty.'; float:right">';
7643:): my $reverse = 1;
7644:): if (@sections) {
7645:): $sectionbox .= ' ... '.&mt('hidden in sections').': '.
7646:): '<div style="position: relative; top: 0%;">'.
7647:): &select_sections('hidetotals','',\@sections,\@selsec,$noedit,'all').
7648:): '</div>';
7649:): }
7650:): $sectionbox .= '</div>';
7651:): $datatable .= '<fieldset id="hidetotalsdiv" style="display:'.$gradingsty.';">'.
7652:): '<legend style="font-weight: normal;">'.
7653:): &mt('Hide Course Points Totals').'</legend>'.
7654:): '<div style="position: relative; top: 0%; float:left">'.
7655:): &yesno_radio('hidetotals',\%current,$unsetdefault,$valueyes,$valueno,$noedit,
7656:): $onclick,$reverse).'</div>'.
7657:): $sectionbox.
7658:): '</fieldset><div style="padding:0;clear:both;margin:0;border:0"></div>';
7659:): }
1.1 raeburn 7660: } elsif ($items->{$item}{input} eq 'textbox') {
1.49.2.21 raeburn 7661: my $disabled;
7662: if ($noedit) {
7663: $disabled = ' disabled=disabled"';
7664: }
1.1 raeburn 7665: $datatable .=
7666: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.49.2.21 raeburn 7667: $items->{$item}{size},
7668: $disabled);
1.1 raeburn 7669: }
7670: $datatable .= &item_table_row_end();
7671: }
7672: if (ref($rowtotal)) {
7673: $$rowtotal += scalar(@{$ordered});
7674: }
7675: }
7676: return $datatable;
7677: }
7678:
7679: sub nothidepriv_row {
1.49.2.21 raeburn 7680: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 7681: my ($cnum) = &get_course();
1.49.2.7 raeburn 7682: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 7683: if (ref($settings) eq 'HASH') {
7684: if ($settings->{$item} ne '') {
7685: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
7686: if ($user !~ /:/) {
7687: $nothide{join(':',split(/[\@]/,$user))}=1;
7688: } else {
7689: $nothide{$user} = 1;
7690: }
7691: }
7692: }
1.49.2.7 raeburn 7693: if ($settings->{'checkforpriv'}) {
7694: @checkdoms = split(/,/,$settings->{'checkforpriv'});
7695: }
1.1 raeburn 7696: }
1.49.2.7 raeburn 7697: push(@checkdoms,$cdom);
7698: my %coursepersonnel =
7699: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 7700: my @privusers;
7701: foreach my $person (keys(%coursepersonnel)) {
1.49.2.7 raeburn 7702: my ($uname,$udom,$role) = split(/:/,$person);
7703: my $user = $uname.':'.$udom;
7704: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 7705: if ($end == -1 || $start == -1) {
7706: next;
7707: }
1.49.2.7 raeburn 7708: foreach my $dom (@checkdoms) {
7709: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
7710: unless (grep(/^\Q$user\E$/,@privusers)) {
7711: push(@privusers,$user);
1.3 raeburn 7712: }
7713: }
7714: }
1.1 raeburn 7715: }
1.49.2.7 raeburn 7716: if (@privusers > 0) {
1.49.2.21 raeburn 7717: my $disabled;
7718: if ($noedit) {
7719: $disabled = ' disabled="disabled"';
7720: }
1.1 raeburn 7721: $datatable .= '<table align="right">';
7722: foreach my $user (sort(@privusers)) {
7723: my $hideon = ' checked="checked" ';
7724: my $hideoff = '';
7725: if ($nothide{$user}) {
7726: $hideoff = $hideon;
7727: $hideon = '';
7728: }
7729: my ($uname,$udom) = split(':',$user);
7730: $datatable .= '<tr><td align="left">'.
7731: &Apache::loncommon::aboutmewrapper(
7732: &Apache::loncommon::plainname($uname,$udom,'firstname'),
7733: $uname,$udom,'aboutuser').
7734: '</td><td align="left">'.
7735: '<span class="LC_nobreak"><label>'.
7736: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.49.2.21 raeburn 7737: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.49.2.17 raeburn 7738: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.49.2.21 raeburn 7739: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 7740: '</tr>';
7741: }
7742: $datatable .= '</table>';
7743: } else {
1.9 raeburn 7744: if ($crstype eq 'Community') {
7745: $datatable .= &mt('No Domain Coordinators have community roles');
7746: } else {
7747: $datatable .= &mt('No Domain Coordinators have course roles');
7748: }
1.1 raeburn 7749: }
7750: return $datatable;
7751: }
7752:
1.49.2.7 raeburn 7753: sub checkforpriv_row {
1.49.2.21 raeburn 7754: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.49.2.7 raeburn 7755: my $datatable;
7756: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7757: if (keys(%domains) == 1) {
7758: $datatable = '</td><td align="right">'.
7759: &mt("Course's domain is only domain");
7760: return $datatable;
7761: }
7762: my @excdoms = ($cdom);
7763: my $num = 0;
7764: if ($settings->{$item} eq '') {
7765: $datatable = '</td><td align="right">'.
7766: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.49.2.21 raeburn 7767: 1,1,undef,undef,\@excdoms,
7768: $noedit);
1.49.2.7 raeburn 7769: } else {
7770: my @privdoms = split(/,/,$settings->{$item});
7771: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7772: $datatable = '</td><td align="right"><br />'.
7773: &Apache::loncommon::start_data_table();
1.49.2.21 raeburn 7774: my $disabled;
7775: if ($noedit) {
7776: $disabled = ' disabled="disabled"';
7777: }
1.49.2.7 raeburn 7778: if (@privdoms > 0) {
7779: foreach my $currdom (@privdoms) {
7780: next unless ($domains{$currdom});
7781: my $domdesc = &Apache::lonnet::domain($currdom,'description');
7782: if ($domdesc eq '') {
7783: $domdesc = $currdom;
7784: }
7785: $datatable .=
7786: &Apache::loncommon::start_data_table_row().
7787: '<td align="left"><span class="LC_nobreak">'.
7788: &mt('Domain:').'<b> '.$domdesc.
7789: '</b><input type="hidden" name="checkforpriv_'.$num.
7790: '" value="'.$currdom.'" /></span><br />'.
7791: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.49.2.21 raeburn 7792: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
1.49.2.7 raeburn 7793: &mt('Delete').'</label></span></td>'.
7794: &Apache::loncommon::end_data_table_row();
7795: $num ++;
7796: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
7797: push(@excdoms,$currdom);
7798: }
7799: }
7800: }
7801: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
7802: $datatable .=
7803: &Apache::loncommon::start_data_table_row().
7804: '<td align="left"><span class="LC_nobreak">'.
7805: &mt('Additional domain:'). '</span><br />'.
7806: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.49.2.21 raeburn 7807: 1,undef,undef,\@excdoms,$noedit).
1.49.2.7 raeburn 7808: '</td>'.&Apache::loncommon::end_data_table_row();
7809: }
7810: $datatable .= &Apache::loncommon::end_data_table().
7811: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
7812: '<br />';
7813: }
7814: return $datatable;
7815: }
7816:
1.1 raeburn 7817: sub print_hdrfmt_row {
1.49.2.21 raeburn 7818: my ($item,$settings,$noedit) = @_;
1.1 raeburn 7819: my @curr;
7820: my $currnum = 0;
7821: my $maxnum = 2;
7822: my $currstr;
7823: if ($settings->{$item} ne '') {
7824: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
7825: $settings->{$item}.'</tt></span></b><br />';
7826: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 7827: foreach my $val (@current) {
7828: unless ($val eq '') {
7829: push(@curr,$val);
1.1 raeburn 7830: }
7831: }
7832: $currnum = @curr;
7833: $maxnum += $currnum;
7834: }
7835:
7836: my $output = <<ENDJS;
7837:
7838: <script type="text/javascript" language="Javascript">
7839:
7840: function reOrder(chgnum) {
7841: var maxnum = $maxnum;
7842: var oldidx = 'printfmthdr_oldpos_'+chgnum;
7843: var newidx = 'printfmthdr_pos_'+chgnum;
7844: oldidx = getIndexByName(oldidx);
7845: newidx = getIndexByName(newidx);
7846: var oldpos = document.display.elements[oldidx].value;
7847: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7848: document.display.elements[oldidx].value = newpos;
7849: var chgtype = 'up';
7850: if (newpos < oldpos) {
7851: chgtype = 'down';
7852: }
7853: for (var j=0; j<maxnum; j++) {
7854: if (j != chgnum) {
7855: oldidx = 'printfmthdr_oldpos_'+j;
7856: newidx = 'printfmthdr_pos_'+j;
7857: oldidx = getIndexByName(oldidx);
7858: newidx = getIndexByName(newidx);
7859: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7860: var currsel = document.display.elements[newidx].selectedIndex;
7861: if (chgtype == 'up') {
7862: if ((currpos > oldpos) && (currpos <= newpos)) {
7863: document.display.elements[newidx].selectedIndex = currsel-1;
7864: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7865: }
7866: } else {
7867: if ((currpos >= newpos) && (currpos < oldpos)) {
7868: document.display.elements[newidx].selectedIndex = currsel+1;
7869: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7870: }
7871: }
7872: }
7873: }
7874: return;
7875: }
7876:
7877: function getIndexByName(item) {
7878: for (var i=0;i<document.display.elements.length;i++) {
7879: if (document.display.elements[i].name == item) {
7880: return i;
7881: }
7882: }
7883: return -1;
7884: }
7885:
7886: </script>
7887:
7888: ENDJS
1.49.2.7 raeburn 7889: $output .= '</td><td align="right"><br />'.
7890: $currstr.'<table class="LC_data_table">';
1.49.2.21 raeburn 7891: my $disabled;
7892: if ($noedit) {
7893: $disabled = ' disabled="disabled"';
7894: }
1.1 raeburn 7895: if (@curr > 0) {
7896: for (my $i=0; $i<@curr; $i++) {
7897: my $pos = $i+1;
1.10 raeburn 7898: $output .= '<tr>'.
1.1 raeburn 7899: '<td align="left"><span class="LC_nobreak">'.
1.49.2.21 raeburn 7900: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 7901: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.49.2.21 raeburn 7902: '"'.$disabled.' /></span></td>';
1.1 raeburn 7903: if ($curr[$i] =~ /^%\d*[nca]$/) {
7904: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
7905: $output .= '<td align="left">'.
1.49.2.21 raeburn 7906: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 7907: } else {
7908: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
7909: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.49.2.21 raeburn 7910: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 7911: }
1.10 raeburn 7912: $output .= '</tr>';
1.1 raeburn 7913: }
7914: }
1.49.2.28.2.1 (raeburn 7915:): my $pos = $currnum+1;
1.49.2.21 raeburn 7916: unless ($noedit) {
7917: $output .=
7918: '<tr>'.
1.1 raeburn 7919: '<td align="left"><span class="LC_nobreak">'.
7920: &position_selector($pos,$currnum,$maxnum).
7921: '<b>'.&mt('New').'</b></span></td><td align="left">'.
7922: &substitution_selector($currnum).'</td>'.
1.10 raeburn 7923: '</tr>';
1.49.2.21 raeburn 7924: $pos ++;
7925: $currnum ++;
7926: $output .=
7927: '<tr>'.
1.1 raeburn 7928: '<td align="left"><span class="LC_nobreak">'.
7929: &position_selector($pos,$currnum,$maxnum).
7930: '<b>'.&mt('New').'</b></span></td>'.
7931: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
7932: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 7933: '" value="" size ="25" />'.
7934: '<input type="hidden" name="printfmthdr_maxnum" value="'.
7935: $maxnum.'" /></td>'.
1.49.2.21 raeburn 7936: '</tr>';
7937: }
7938: $output .= '</table><br />';
1.1 raeburn 7939: return $output;
7940: }
7941:
7942: sub position_selector {
1.49.2.21 raeburn 7943: my ($pos,$num,$maxnum,$disabled) = @_;
7944: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 7945: for (my $j=1; $j<=$maxnum; $j++) {
7946: my $sel = '';
7947: if ($pos == $j) {
7948: $sel = ' selected="selected"';
7949: }
7950: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
7951: }
7952: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
7953: '" value="'.$pos.'" />';
7954: return $output;
7955: }
7956:
7957: sub substitution_selector {
1.49.2.21 raeburn 7958: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 7959: my ($stunametxt,$crsidtxt);
7960: if ($crstype eq 'Community') {
7961: $stunametxt = 'member name';
7962: $crsidtxt = 'community ID',
7963: } else {
7964: $stunametxt = 'student name';
7965: $crsidtxt = 'course ID',
7966: }
1.1 raeburn 7967: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 7968: n => $stunametxt,
7969: c => $crsidtxt,
1.1 raeburn 7970: a => 'assignment note',
7971: );
7972: my $output .= &mt('Substitution').'<br />'.
1.49.2.21 raeburn 7973: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 7974: if ($subst eq '') {
7975: $output .= '<option value="" selected="selected"> </option>';
7976: }
7977: foreach my $field ('n','c','a') {
7978: my $sel ='';
7979: if ($subst eq $field) {
7980: $sel = ' selected="selected"';
7981: }
7982: $output .= '<option value="'.$field.'"'.$sel.'>'.
7983: $lt{$field}.'</option>';
7984: }
7985: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
7986: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.49.2.21 raeburn 7987: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 7988: return $output;
7989: }
7990:
1.23 raeburn 7991: sub change_clone {
7992: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
7993: my $clone_crs = $cnum.':'.$cdom;
7994: if ($cnum && $cdom) {
7995: my $clone_crs = $cnum.':'.$cdom;
7996: my @allowclone;
7997: if ($clonelist =~ /,/) {
7998: @allowclone = split(',',$clonelist);
7999: } else {
8000: $allowclone[0] = $clonelist;
8001: }
8002: foreach my $currclone (@allowclone) {
8003: if (!grep(/^$currclone$/,@$oldcloner)) {
8004: if ($currclone ne '*') {
1.49.2.18 raeburn 8005: if ($currclone =~ /:/) {
8006: my ($uname,$udom) = split(/:/,$currclone);
8007: if ($uname && $udom && $uname ne '*') {
8008: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8009: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8010: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8011: if ($currclonecrs{'cloneable'} eq '') {
8012: $currclonecrs{'cloneable'} = $clone_crs;
8013: } else {
8014: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8015: }
8016: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8017: }
8018: }
8019: }
8020: }
8021: }
8022: }
8023: }
8024: foreach my $oldclone (@$oldcloner) {
8025: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8026: if ($oldclone ne '*') {
1.49.2.18 raeburn 8027: if ($oldclone =~ /:/) {
8028: my ($uname,$udom) = split(/:/,$oldclone);
8029: if ($uname && $udom && $uname ne '*' ) {
8030: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8031: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8032: my %newclonecrs = ();
8033: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8034: if ($currclonecrs{'cloneable'} =~ /,/) {
8035: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8036: foreach my $crs (@currclonecrs) {
8037: if ($crs ne $clone_crs) {
8038: $newclonecrs{'cloneable'} .= $crs.',';
8039: }
1.23 raeburn 8040: }
1.49.2.18 raeburn 8041: $newclonecrs{'cloneable'} =~ s/,$//;
8042: } else {
8043: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8044: }
1.49.2.18 raeburn 8045: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8046: }
8047: }
8048: }
8049: }
8050: }
8051: }
8052: }
8053: }
8054: return;
8055: }
8056:
1.49.2.28.2.8 (raeburn 8057:: sub devalidate_remote_courseprefs {
8058:: my ($cdom,$cnum,$cachekeys) = @_;
8059:: return unless (ref($cachekeys) eq 'HASH');
8060:: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8061:: my %thismachine;
8062:: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.49.2.28.2.1 (raeburn 8063:): my @posscached = ('courselti','courseltitools');
1.49.2.28.2.8 (raeburn 8064:: if (keys(%servers)) {
8065:: foreach my $server (keys(%servers)) {
8066:: next if ($thismachine{$server});
8067:: my @cached;
8068:: foreach my $name (@posscached) {
8069:: if ($cachekeys->{$name}) {
8070:: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8071:: }
8072:: }
8073:: if (@cached) {
8074:: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8075:: }
8076:: }
8077:: }
8078:: return;
8079:: }
8080::
1.1 raeburn 8081: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>