Annotation of loncom/interface/courseprefs.pm, revision 1.49.2.28.2.17
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.16 2023/09/02 16:12:21 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.21 raeburn 810: $output .= &print_grading($cdom,$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:): }
1.3 raeburn 1502: } else {
1503: $newvalues{$entry} = $env{'form.'.$entry};
1504: }
1.49.2.28.2.1 (raeburn 1505:): unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1506:): ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1507: if ($newvalues{$entry} ne $values->{$entry}) {
1508: $changes->{$entry} = $newvalues{$entry};
1509: }
1.3 raeburn 1510: }
1511: }
1512: }
1513: }
1514: }
1515: }
1.49.2.28.2.1 (raeburn 1516:: return $errors;
1517:: }
1518::
1.49.2.28.2.5 (raeburn 1519:: sub process_linkprot {
1.49.2.28.2.8 (raeburn 1520:: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.49.2.28.2.1 (raeburn 1521:): my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.49.2.28.2.5 (raeburn 1522:: if (ref($values) eq 'HASH') {
1523:: foreach my $id (keys(%{$values})) {
1524:: if ($id =~ /^\d+$/) {
1525:: unless (ref($values->{$id}) eq 'HASH') {
1526:: $linkprot{$id} = '';
1527:: }
1528:: }
1529:: }
1530:: }
1.49.2.28.2.1 (raeburn 1531:): ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.49.2.28.2.5 (raeburn 1532:: if ($context eq 'domain') {
1533:: $dest = '/adm/domainprefs';
1534:: $ltiauth = 1;
1535:: } else {
1536:: $dest = '/adm/courseprefs';
1537:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1538:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1539:: } else {
1540:: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1541:: $ltiauth = $domdefs{'crsltiauth'};
1542:: }
1543:: }
1544:: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1545:: my (@items,%deletions,%itemids,%haschanges);
1546:: if ($env{'form.linkprot_add'}) {
1547:: my $name = $env{'form.linkprot_name_add'};
1548:: $name =~ s/(`)/'/g;
1549:: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1550:: if ($newid) {
1551:: $itemids{'add'} = $newid;
1552:: push(@items,'add');
1553:: $haschanges{$newid} = 1;
1554:: } else {
1555:: $errors .= '<span class="LC_error">'.
1556:: &mt('Failed to acquire unique ID for link protection').
1557:: '</span>';
1558:: }
1559:: }
1560:: if (ref($values) eq 'HASH') {
1561:: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1562:: my $maxnum = $env{'form.linkprot_maxnum'};
1.49.2.28.2.1 (raeburn 1563:): for (my $i=0; $i<$maxnum; $i++) {
1.49.2.28.2.5 (raeburn 1564:: my $itemid = $env{'form.linkprot_id_'.$i};
1565:: $itemid =~ s/\D+//g;
1566:: if ($itemid) {
1567:: if (ref($values->{$itemid}) eq 'HASH') {
1568:: push(@items,$i);
1569:: $itemids{$i} = $itemid;
1570:: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1571:: $deletions{$itemid} = $values->{$itemid}->{'name'};
1572:: }
1573:: }
1574:: }
1575:: }
1576:: }
1577:: foreach my $idx (@items) {
1578:: my $itemid = $itemids{$idx};
1579:: next unless ($itemid);
1580:: if (exists($deletions{$itemid})) {
1581:: $linkprot{$itemid} = $deletions{$itemid};
1582:: $haschanges{$itemid} = 1;
1583:: next;
1584:: }
1585:: my %current;
1586:: if (ref($values) eq 'HASH') {
1587:: if (ref($values->{$itemid}) eq 'HASH') {
1588:: foreach my $key (keys(%{$values->{$itemid}})) {
1589:: $current{$key} = $values->{$itemid}->{$key};
1590:: }
1591:: }
1592:: }
1593:: foreach my $inner ('name','lifetime','version') {
1594:: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1595:: $env{$formitem} =~ s/(`)/'/g;
1596:: if ($inner eq 'lifetime') {
1597:: $env{$formitem} =~ s/[^\d.]//g;
1598:: }
1599:: unless ($idx eq 'add') {
1600:: if ($current{$inner} ne $env{$formitem}) {
1601:: $haschanges{$itemid} = 1;
1602:: }
1603:: }
1604:: if ($env{$formitem} ne '') {
1605:: $linkprot{$itemid}{$inner} = $env{$formitem};
1606:: }
1607:: }
1.49.2.28.2.1 (raeburn 1608:): my $urlitem = 'form.linkprot_returnurl_'.$idx;
1609:): my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1610:): if ($env{$urlitem} == 1) {
1611:): $env{$urlparamname} =~ s/(`)/'/g;
1612:): } elsif (exists($env{$urlparamname})) {
1613:): $env{$urlparamname} = '';
1614:): }
1615:): my $passback = 'form.linkprot_passback_'.$idx;
1616:): my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
1617:): if ($env{$passback} == 1) {
1618:): unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
1619:): $env{$passbackparamname} = '';
1620:): }
1621:): } elsif (exists($env{$passbackparamname})) {
1622:): $env{$passbackparamname} = '';
1623:): }
1624:): unless ($idx eq 'add') {
1625:): if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1626:): ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1627:): $haschanges{$itemid} = 1;
1628:): }
1629:): if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
1630:): ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
1631:): $haschanges{$itemid} = 1;
1632:): }
1633:): }
1634:): if ($env{$urlparamname} ne '') {
1635:): $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1636:): }
1637:): if ($env{$passbackparamname} ne '') {
1638:): $linkprot{$itemid}{'passback'} = 1;
1639:): $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1640:): }
1.49.2.28.2.5 (raeburn 1641:: if ($ltiauth) {
1642:: my $reqitem = 'form.linkprot_requser_'.$idx;
1643:: $env{$reqitem} =~ s/(`)/'/g;
1644:: unless ($idx eq 'add') {
1645:: if ((!$current{'requser'} && $env{$reqitem}) ||
1646:: ($current{'requser'} && !$env{$reqitem})) {
1647:: $haschanges{$itemid} = 1;
1648:: }
1649:: }
1650:: if ($env{$reqitem} == 1) {
1651:: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1652:: foreach my $inner ('mapuser','notstudent') {
1653:: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1654:: $env{$formitem} =~ s/(`)/'/g;
1655:: if ($inner eq 'mapuser') {
1656:: if ($env{$formitem} eq 'other') {
1657:: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1658:: $mapuser =~ s/(`)/'/g;
1659:: $mapuser =~ s/^\s+|\s+$//g;
1660:: if ($mapuser ne '') {
1661:: $linkprot{$itemid}{$inner} = $mapuser;
1662:: } else {
1663:: delete($linkprot{$itemid}{'requser'});
1664:: last;
1665:: }
1666:: } elsif ($env{$formitem} eq 'sourcedid') {
1667:: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1668:: } elsif ($env{$formitem} eq 'email') {
1669:: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1670:: }
1671:: } else {
1672:: $linkprot{$itemid}{$inner} = $env{$formitem};
1673:: }
1674:: unless ($idx eq 'add') {
1675:: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1676:: $haschanges{$itemid} = 1;
1677:: }
1678:: }
1679:: }
1680:: }
1681:: }
1682:: unless ($switchserver) {
1683:: my $keyitem = 'form.linkprot_key_'.$idx;
1684:: $env{$keyitem} =~ s/(`)/'/g;
1685:: unless ($idx eq 'add') {
1686:: if ($current{'key'} ne $env{$keyitem}) {
1687:: $haschanges{$itemid} = 1;
1688:: }
1689:: }
1690:: if ($env{$keyitem} ne '') {
1691:: $linkprot{$itemid}{'key'} = $env{$keyitem};
1692:: }
1693:: my $secretitem = 'form.linkprot_secret_'.$idx;
1694:: $env{$secretitem} =~ s/(`)/'/g;
1695:: if ($current{'usable'}) {
1696:: if ($env{'form.linkprot_changesecret_'.$idx}) {
1697:: if ($env{$secretitem} ne '') {
1698:: if ($privnum && $cipher) {
1699:: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1700:: $linkprot{$itemid}{'cipher'} = $privnum;
1701:: } else {
1702:: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1703:: }
1704:: $haschanges{$itemid} = 1;
1705:: }
1706:: } else {
1707:: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.49.2.28.2.1 (raeburn 1708:): $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.49.2.28.2.5 (raeburn 1709:: }
1710:: } elsif ($env{$secretitem} ne '') {
1711:: if ($privnum && $cipher) {
1712:: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1713:: $linkprot{$itemid}{'cipher'} = $privnum;
1714:: } else {
1715:: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1716:: }
1717:: $haschanges{$itemid} = 1;
1718:: }
1719:: }
1720:: }
1721:: if (keys(%haschanges)) {
1722:: foreach my $entry (keys(%haschanges)) {
1723:: $changes->{$entry} = $linkprot{$entry};
1724:: }
1.49.2.28.2.8 (raeburn 1725:: if (ref($lastactref) eq 'HASH') {
1.49.2.28.2.9 (raeburn 1726:: $lastactref->{'courselti'} = 1;
1.49.2.28.2.8 (raeburn 1727:: }
1.49.2.28.2.5 (raeburn 1728:: }
1729:: return $errors;
1730:: }
1731::
1732:: sub get_linkprot_id {
1733:: my ($cdom,$cnum,$name,$context) = @_;
1734:: # get lock on lti db in course or linkprot db in domain
1.49.2.28.2.1 (raeburn 1735:: my $lockhash = {
1736:: lock => $env{'user.name'}.
1737:: ':'.$env{'user.domain'},
1738:: };
1739:: my $tries = 0;
1.49.2.28.2.5 (raeburn 1740:: my $gotlock;
1741:: if ($context eq 'domain') {
1.49.2.28.2.1 (raeburn 1742:): $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1743:): } else {
1744:): $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1745:): }
1746:): my ($id,$error);
1747:): while (($gotlock ne 'ok') && ($tries<10)) {
1748:): $tries ++;
1749:): sleep (0.1);
1750:): if ($context eq 'domain') {
1751:): $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1752:): } else {
1753:): $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1754:): }
1755:): }
1756:): if ($gotlock eq 'ok') {
1757:): my %currids;
1758:): if ($context eq 'domain') {
1759:): %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1760:): } else {
1761:): %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1762:): }
1763:): if ($currids{'lock'}) {
1764:): delete($currids{'lock'});
1765:): if (keys(%currids)) {
1766:): my @curr = sort { $a <=> $b } keys(%currids);
1767:): if ($curr[-1] =~ /^\d+$/) {
1768:): $id = 1 + $curr[-1];
1769:): } else {
1770:): $id = 1;
1771:): }
1772:): } else {
1773:): $id = 1;
1774:): }
1775:): if ($id) {
1776:): if ($context eq 'domain') {
1777:): unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1778:): $error = 'nostore';
1779:): }
1780:): } else {
1781:): unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1782:): $error = 'nostore';
1783:): }
1784:): }
1785:): } else {
1786:): $error = 'nonumber';
1787:): }
1788:): }
1789:): my $dellockoutcome;
1790:): if ($context eq 'domain') {
1791:): $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1792:): } else {
1793:): $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1794:): }
1795:): } else {
1796:): $error = 'nolock';
1797:): }
1798:): return ($id,$error);
1799:): }
1800:):
1801:): sub get_credentials {
1802:): my ($cdom,$cnum,$type,$context) = @_;
1803:): my ($cipher,$privnum,$home);
1804:): my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1805:): my @ids=&Apache::lonnet::current_machine_ids();
1806:): if ($context eq 'domain') {
1807:): $home = &Apache::lonnet::domain($cdom,'primary');
1808:): } else {
1809:): $home = &Apache::lonnet::homeserver($cnum,$cdom);
1810:): }
1811:): my ($hostskey,$domkey,$crskey);
1812:): if ($type eq 'ltitools') {
1813:): $hostskey = 'toolprivhosts';
1814:): $domkey = 'toolenc_dom';
1815:): $crskey = 'toolenc_crs';
1816:): } else {
1817:): $hostskey = 'ltiprivhosts';
1818:): $domkey = 'linkprotenc_dom';
1819:): $crskey = 'linkprotenc_crs';
1820:): }
1821:): if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1822:): (($context eq 'course') && ($domdefs{$crskey}))) {
1823:): unless (($home eq 'no_host') || ($home eq '')) {
1824:): if (grep(/^\Q$home\E$/,@ids)) {
1825:): if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1826:): if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1827:): my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1828:): my $privkey = $privhash{'key'};
1829:): $privnum = $privhash{'version'};
1830:): if (($privnum) && ($privkey ne '')) {
1831:): $cipher = Crypt::CBC->new({'key' => $privkey,
1832:): 'cipher' => 'DES'});
1833:): }
1834:): }
1835:): }
1836:): }
1837:): }
1838:): }
1839:): return ($cipher,$privnum);
1840:): }
1841:):
1842:): sub process_ltitools {
1843:): my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1844:): $author_ok,$confname) = @_;
1845:): my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1846:):
1847:): my (%posslti,%possfield);
1848:): my @courseroles = ('cc','in','ta','ep','st');
1849:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1850:): map { $posslti{$_} = 1; } @ltiroles;
1851:): my @allfields = ('fullname','firstname','lastname','email','user','roles');
1852:): map { $possfield{$_} = 1; } @allfields;
1853:):
1854:): my ($dest,$privnum,$cipher);
1855:):
1856:): ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1857:): if ($context eq 'domain') {
1858:): $dest = '/adm/domainprefs';
1859:): } else {
1860:): $dest = '/adm/courseprefs';
1861:): }
1862:): my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1863:):
1864:): my (@allpos,@items,%deletions,%itemids,%haschanges);
1865:): if ($env{'form.ltitools_add'}) {
1866:): my $title = $env{'form.ltitools_add_title'};
1867:): $title =~ s/(`)/'/g;
1868:): my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
1869:): if ($newid) {
1870:): my $position = $env{'form.ltitools_add_pos'};
1871:): $position =~ s/\D+//g;
1872:): if ($position ne '') {
1873:): $allpos[$position] = $newid;
1874:): }
1875:): $haschanges{$newid} = 1;
1876:): foreach my $item ('title','url','lifetime') {
1877:): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1878:): if ($item eq 'lifetime') {
1879:): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1880:): }
1881:): if ($env{'form.ltitools_add_'.$item}) {
1882:): $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1883:): }
1884:): }
1885:): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1886:): $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1887:): }
1888:): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1889:): $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1890:): }
1891:): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1892:): $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1893:): } else {
1894:): $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1895:): }
1896:): foreach my $item ('width','height','linktext','explanation') {
1897:): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1898:): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1899:): if (($item eq 'width') || ($item eq 'height')) {
1900:): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1901:): $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1902:): }
1903:): } else {
1904:): if ($env{'form.ltitools_add_'.$item} ne '') {
1905:): $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1906:): }
1907:): }
1908:): }
1909:): if ($env{'form.ltitools_add_target'} eq 'window') {
1910:): $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1911:): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1912:): $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1913:): } else {
1914:): $ltitools{$newid}{'display'}{'target'} = 'iframe';
1915:): }
1916:): foreach my $item ('passback','roster') {
1917:): if ($env{'form.ltitools_'.$item.'_add'}) {
1918:): $ltitools{$newid}{$item} = 1;
1919:): if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1920:): my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1921:): $lifetime =~ s/^\s+|\s+$//g;
1922:): if ($lifetime =~ /^\d+\.?\d*$/) {
1923:): $ltitools{$newid}{$item.'valid'} = $lifetime;
1924:): }
1925:): }
1926:): }
1927:): }
1928:): if ($env{'form.ltitools_add_image.filename'} ne '') {
1929:): my ($imageurl,$error) =
1930:): &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
1931:): $newid,$configuserok,$lonhost,$author_ok);
1932:): if ($imageurl) {
1933:): $ltitools{$newid}{'image'} = $imageurl;
1934:): }
1935:): if ($error) {
1936:): &Apache::lonnet::logthis($error);
1937:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1938:): }
1939:): }
1940:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
1941:): foreach my $field (@fields) {
1942:): if ($possfield{$field}) {
1943:): if ($field eq 'roles') {
1944:): foreach my $role (@courseroles) {
1945:): my $choice = $env{'form.ltitools_add_roles_'.$role};
1946:): if (($choice ne '') && ($posslti{$choice})) {
1947:): $ltitools{$newid}{'roles'}{$role} = $choice;
1948:): if ($role eq 'cc') {
1949:): $ltitools{$newid}{'roles'}{'co'} = $choice;
1950:): }
1951:): }
1952:): }
1953:): } else {
1954:): $ltitools{$newid}{'fields'}{$field} = 1;
1955:): }
1956:): }
1957:): }
1958:): if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
1959:): if ($ltitools{$newid}{'fields'}{'user'}) {
1960:): if ($env{'form.ltitools_add_userincdom'}) {
1961:): $ltitools{$newid}{'incdom'} = 1;
1962:): }
1963:): }
1964:): }
1965:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
1966:): foreach my $item (@courseconfig) {
1967:): $ltitools{$newid}{'crsconf'}{$item} = 1;
1968:): }
1969:): if ($env{'form.ltitools_add_custom'}) {
1970:): my $name = $env{'form.ltitools_add_custom_name'};
1971:): my $value = $env{'form.ltitools_add_custom_value'};
1972:): $value =~ s/(`)/'/g;
1973:): $name =~ s/(`)/'/g;
1974:): $ltitools{$newid}{'custom'}{$name} = $value;
1975:): }
1976:): unless ($switchserver) {
1977:): my $keyitem = 'form.ltitools_add_key';
1978:): $env{$keyitem} =~ s/(`)/'/g;
1979:): if ($env{$keyitem} ne '') {
1980:): $ltitools{$newid}{'key'} = $env{$keyitem};
1981:): }
1982:): my $secretitem = 'form.ltitools_secret_add';
1983:): $env{$secretitem} =~ s/(`)/'/g;
1984:): if ($env{$secretitem} ne '') {
1985:): if ($privnum && $cipher) {
1986:): $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1987:): $ltitools{$newid}{'cipher'} = $privnum;
1988:): } else {
1989:): $ltitools{$newid}{'secret'} = $env{$secretitem};
1990:): }
1991:): }
1992:): }
1993:): } else {
1994:): $errors .= '<li><span class="LC_error">'.
1995:): &mt('Failed to acquire unique ID for new external tool').
1996:): '</span></li>';
1997:): }
1998:): }
1999:): if (ref($values) eq 'HASH') {
2000:): my %deletions;
2001:): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2002:): if (@todelete) {
2003:): map { $deletions{$_} = 1; } @todelete;
2004:): }
2005:): my %customadds;
2006:): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2007:): if (@newcustom) {
2008:): map { $customadds{$_} = 1; } @newcustom;
2009:): }
2010:): my %imgdeletions;
2011:): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2012:): if (@todeleteimages) {
2013:): map { $imgdeletions{$_} = 1; } @todeleteimages;
2014:): }
2015:): my $maxnum = $env{'form.ltitools_maxnum'};
2016:): for (my $i=0; $i<=$maxnum; $i++) {
2017:): my $itemid = $env{'form.ltitools_id_'.$i};
2018:): $itemid =~ s/\D+//g;
2019:): if (ref($values->{$itemid}) eq 'HASH') {
2020:): if ($deletions{$itemid}) {
2021:): if ($values->{$itemid}{'image'}) {
2022:): #FIXME need to obsolete item in RES space
2023:): }
2024:): $haschanges{$itemid} = $values->{$itemid}{'title'};
2025:): next;
2026:): } else {
2027:): my $newpos = $env{'form.ltitools_'.$itemid};
2028:): $newpos =~ s/\D+//g;
2029:): foreach my $item ('title','url','lifetime') {
2030:): $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2031:): if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2032:): $haschanges{$itemid} = 1;
2033:): }
2034:): }
2035:): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2036:): $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2037:): }
2038:): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2039:): $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2040:): }
2041:): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2042:): $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2043:): } else {
2044:): $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2045:): }
2046:): if ($values->{$itemid}{'sigmethod'} eq '') {
2047:): if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2048:): $haschanges{$itemid} = 1;
2049:): }
2050:): } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2051:): $haschanges{$itemid} = 1;
2052:): }
2053:): foreach my $size ('width','height') {
2054:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2055:): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2056:): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2057:): $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2058:): if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2059:): if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2060:): $haschanges{$itemid} = 1;
2061:): }
2062:): } else {
2063:): $haschanges{$itemid} = 1;
2064:): }
2065:): } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2066:): if ($values->{$itemid}{'display'}{$size} ne '') {
2067:): $haschanges{$itemid} = 1;
2068:): }
2069:): }
2070:): }
2071:): foreach my $item ('linktext','explanation') {
2072:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2073:): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2074:): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2075:): $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2076:): if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2077:): if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2078:): $haschanges{$itemid} = 1;
2079:): }
2080:): } else {
2081:): $haschanges{$itemid} = 1;
2082:): }
2083:): } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2084:): if ($values->{$itemid}{'display'}{$item} ne '') {
2085:): $haschanges{$itemid} = 1;
2086:): }
2087:): }
2088:): }
2089:): if ($env{'form.ltitools_target_'.$i} eq 'window') {
2090:): $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2091:): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2092:): $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2093:): } else {
2094:): $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2095:): }
2096:): if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2097:): if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2098:): $haschanges{$itemid} = 1;
2099:): }
2100:): } else {
2101:): $haschanges{$itemid} = 1;
2102:): }
2103:): foreach my $extra ('passback','roster') {
2104:): if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2105:): $ltitools{$itemid}{$extra} = 1;
2106:): if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2107:): my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2108:): $lifetime =~ s/^\s+|\s+$//g;
2109:): if ($lifetime =~ /^\d+\.?\d*$/) {
2110:): $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2111:): }
2112:): }
2113:): }
2114:): if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2115:): $haschanges{$itemid} = 1;
2116:): }
2117:): if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2118:): $haschanges{$itemid} = 1;
2119:): }
2120:): }
2121:): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2122:): foreach my $item ('label','title','target','linktext','explanation','append') {
2123:): if (grep(/^\Q$item\E$/,@courseconfig)) {
2124:): $ltitools{$itemid}{'crsconf'}{$item} = 1;
2125:): if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2126:): if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2127:): $haschanges{$itemid} = 1;
2128:): }
2129:): } else {
2130:): $haschanges{$itemid} = 1;
2131:): }
2132:): }
2133:): }
2134:): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2135:): foreach my $field (@fields) {
2136:): if ($possfield{$field}) {
2137:): if ($field eq 'roles') {
2138:): foreach my $role (@courseroles) {
2139:): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2140:): if (($choice ne '') && ($posslti{$choice})) {
2141:): $ltitools{$itemid}{'roles'}{$role} = $choice;
2142:): if ($role eq 'cc') {
2143:): $ltitools{$itemid}{'roles'}{'co'} = $choice;
2144:): }
2145:): }
2146:): if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2147:): if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2148:): $haschanges{$itemid} = 1;
2149:): }
2150:): } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2151:): $haschanges{$itemid} = 1;
2152:): }
2153:): }
2154:): } else {
2155:): $ltitools{$itemid}{'fields'}{$field} = 1;
2156:): if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2157:): if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2158:): $haschanges{$itemid} = 1;
2159:): }
2160:): } else {
2161:): $haschanges{$itemid} = 1;
2162:): }
2163:): }
2164:): }
2165:): }
2166:): if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2167:): if ($ltitools{$itemid}{'fields'}{'user'}) {
2168:): if ($env{'form.ltitools_userincdom_'.$i}) {
2169:): $ltitools{$itemid}{'incdom'} = 1;
2170:): }
2171:): if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2172:): $haschanges{$itemid} = 1;
2173:): }
2174:): }
2175:): }
2176:): $allpos[$newpos] = $itemid;
2177:): }
2178:): if ($imgdeletions{$itemid}) {
2179:): $haschanges{$itemid} = 1;
2180:): if ($context eq 'course') {
2181:): my $currimgurl = $values->{$itemid}{'image'};
2182:): if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2183:): my ($path,$imagefile) = ($1,$2);
2184:): if ($imagefile =~ /^tn\-(.+)$/) {
2185:): my $origimg = $1;
2186:): &Apache::lonnet::removeuploadedurl("$path/$origimg");
2187:): }
2188:): &Apache::lonnet::removeuploadedurl($currimgurl);
2189:): }
2190:): }
2191:): #FIXME need to obsolete item in RES space
2192:): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2193:): my $currimgurl = $values->{$itemid}{'image'};
2194:): my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2195:): $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2196:): if ($imgurl) {
2197:): $ltitools{$itemid}{'image'} = $imgurl;
2198:): $haschanges{$itemid} = 1;
2199:): }
2200:): if ($error) {
2201:): &Apache::lonnet::logthis($error);
2202:): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2203:): }
2204:): } elsif ($values->{$itemid}{'image'}) {
2205:): $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2206:): }
2207:): if ($customadds{$i}) {
2208:): my $name = $env{'form.ltitools_custom_name_'.$i};
2209:): $name =~ s/(`)/'/g;
2210:): $name =~ s/^\s+//;
2211:): $name =~ s/\s+$//;
2212:): my $value = $env{'form.ltitools_custom_value_'.$i};
2213:): $value =~ s/(`)/'/g;
2214:): $value =~ s/^\s+//;
2215:): $value =~ s/\s+$//;
2216:): if ($name ne '') {
2217:): $ltitools{$itemid}{'custom'}{$name} = $value;
2218:): $haschanges{$itemid} = 1;
2219:): }
2220:): }
2221:): my %customdels;
2222:): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2223:): if (@customdeletions) {
2224:): $haschanges{$itemid} = 1;
2225:): }
2226:): map { $customdels{$_} = 1; } @customdeletions;
2227:): if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2228:): foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2229:): unless ($customdels{$key}) {
2230:): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2231:): $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2232:): }
2233:): if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2234:): $haschanges{$itemid} = 1;
2235:): }
2236:): }
2237:): }
2238:): }
2239:): unless ($switchserver) {
2240:): my $keyitem = 'form.ltitools_key_'.$i;
2241:): $env{$keyitem} =~ s/(`)/'/g;
2242:): if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2243:): $haschanges{$itemid} = 1;
2244:): }
2245:): if ($env{$keyitem} ne '') {
2246:): $ltitools{$itemid}{'key'} = $env{$keyitem};
2247:): }
2248:): my $secretitem = 'form.ltitools_secret_'.$i;
2249:): $env{$secretitem} =~ s/(`)/'/g;
2250:): if ($values->{$itemid}{'usable'}) {
2251:): if ($env{'form.ltitools_changesecret_'.$i}) {
2252:): if ($env{$secretitem} ne '') {
2253:): if ($privnum && $cipher) {
2254:): $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2255:): $ltitools{$itemid}{'cipher'} = $privnum;
2256:): } else {
2257:): $ltitools{$itemid}{'secret'} = $env{$secretitem};
2258:): }
2259:): $haschanges{$itemid} = 1;
2260:): }
2261:): } else {
2262:): $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2263:): $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2264:): }
2265:): } elsif ($env{$secretitem} ne '') {
2266:): if ($privnum && $cipher) {
2267:): $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2268:): $ltitools{$itemid}{'cipher'} = $privnum;
2269:): } else {
2270:): $ltitools{$itemid}{'secret'} = $env{$secretitem};
2271:): }
2272:): $haschanges{$itemid} = 1;
2273:): }
2274:): }
2275:): unless ($haschanges{$itemid}) {
2276:): foreach my $key (keys(%{$values->{$itemid}})) {
2277:): if (ref($values->{$itemid}{$key}) eq 'HASH') {
2278:): if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2279:): foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2280:): unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2281:): $haschanges{$itemid} = 1;
2282:): last;
2283:): }
2284:): }
2285:): } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2286:): $haschanges{$itemid} = 1;
2287:): }
2288:): }
2289:): last if ($haschanges{$itemid});
2290:): }
2291:): }
2292:): }
2293:): }
2294:): }
2295:): if (@allpos > 0) {
2296:): my $idx = 0;
2297:): foreach my $itemid (@allpos) {
2298:): if ($itemid ne '') {
2299:): $ltitools{$itemid}{'order'} = $idx;
2300:): if (ref($values) eq 'HASH') {
2301:): if (ref($values->{$itemid}) eq 'HASH') {
2302:): if ($values->{$itemid}{'order'} ne $idx) {
2303:): $haschanges{$itemid} = 1;
2304:): }
2305:): }
2306:): }
2307:): $idx ++;
2308:): }
2309:): }
2310:): }
2311:): if (keys(%haschanges)) {
2312:): foreach my $entry (keys(%haschanges)) {
2313:): $changes->{$entry} = $ltitools{$entry};
2314:): }
2315:): if (ref($lastactref) eq 'HASH') {
2316:): $lastactref->{'courseltitools'} = 1;
2317:): }
2318:): }
2319:): return $errors;
2320:): }
2321:):
2322:): sub process_ltitools_image {
2323:): my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2324:): my $filename = $env{'form.'.$caller.'.filename'};
2325:): my ($error,$url);
2326:): my ($width,$height) = (21,21);
2327:): if ($configuserok eq 'ok') {
2328:): if ($switch) {
2329:): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2330:): $switch);
2331:): } elsif ($author_ok eq 'ok') {
2332:): my ($result,$imageurl,$madethumb);
2333:): if ($context eq 'domain') {
2334:): ($result,$imageurl,$madethumb) =
2335:): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2336:): "ltitools/$itemid/icon",$width,$height);
2337:): } else {
2338:): ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2339:): }
2340:): if ($result eq 'ok') {
2341:): if ($madethumb) {
2342:): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2343:): my $imagethumb = "$path/tn-".$imagefile;
2344:): $url = $imagethumb;
2345:): } else {
2346:): $url = $imageurl;
2347:): }
2348:): } else {
2349:): if ($context eq 'domain') {
2350:): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2351:): } else {
2352:): $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2353:): }
2354:): }
2355:): } else {
2356:): $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);
2357:): }
2358:): } else {
2359:): $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);
2360:): }
2361:): return ($url,$error);
2362:): }
2363:):
2364:): sub processlogo {
2365:): my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2366:): my ($result,$imageurl,$madethumb);
2367:): if ($env{"form.$caller.filename"} ne '') {
2368:): unless ($caller eq 'ltitools_add_image') {
2369:): if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2370:): my ($path,$imagefile) = ($1,$2);
2371:): if ($imagefile =~ /^tn\-(.+)$/) {
2372:): my $origimg = $1;
2373:): &Apache::lonnet::removeuploadedurl("$path/$origimg");
2374:): }
2375:): &Apache::lonnet::removeuploadedurl($currimg);
2376:): }
2377:): }
2378:): $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2379:): '','','',$cnum,$dom,$width,$height);
2380:): if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2381:): my ($path,$imagefile) = ($1,$2);
2382:): $result = 'ok';
2383:): my $thumburl = "$path/tn-".$imagefile;
2384:): my ($rtncode,$info);
2385:): my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2386:): if ($res eq 'ok') {
2387:): $madethumb = 1;
2388:): }
2389:): } elsif ($imageurl eq '/adm/notfound.html') {
2390:): undef($imageurl);
2391:): $result = 'store failed';
2392:): } elsif ($imageurl =~ /^error: (.+)$/) {
2393:): $result = $1;
2394:): }
2395:): }
2396:): return ($result,$imageurl,$madethumb);
2397:): }
2398:):
1.3 raeburn 2399: sub get_sec_str {
2400: my ($entry,$num) = @_;
2401: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2402: my $secstr;
2403: if (grep(/^\s*$/,@secs)) {
2404: $secstr = '';
2405: } elsif (@secs > 0) {
2406: $secstr = join(';',@secs);
2407: }
2408: if ($secstr ne '') {
2409: return '('.$secstr.')';
2410: }
2411: return;
2412: }
2413:
2414: sub check_clone {
2415: my ($clonedom,$disallowed,$clonename) = @_;
2416: return if (ref($disallowed) ne 'HASH');
2417: if ($clonedom !~ /^$match_domain$/) {
2418: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2419: return;
2420: } elsif (!&Apache::lonnet::domain($clonedom)) {
2421: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2422: return;
2423: }
2424: if ($clonename ne '') {
2425: if ($clonename !~ /^$match_username$/) {
2426: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2427: return;
2428: } else {
2429: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2430: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2431: return;
2432: }
2433: }
2434: }
2435: return 'ok';
2436: }
2437:
2438: sub store_changes {
1.9 raeburn 2439: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2440: my ($chome,$output);
1.49.2.28.2.1 (raeburn 2441:): my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2442: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.49.2.28.2.5 (raeburn 2443:: if (ref($values->{'linkprot'}) eq 'HASH') {
2444:: %oldlinkprot = %{$values->{'linkprot'}};
1.49.2.28.2.1 (raeburn 2445:: }
1.49.2.28.2.5 (raeburn 2446:: delete($values->{'linkprot'});
1.49.2.28.2.1 (raeburn 2447:): if (ref($values->{'ltitools'}) eq 'HASH') {
2448:): %oldltitools = %{$values->{'ltitools'}};
2449:): }
1.3 raeburn 2450: %storehash = %{$values};
2451: } else {
1.9 raeburn 2452: if ($crstype eq 'Community') {
2453: $output = &mt('No changes made to community settings.');
2454: } else {
2455: $output = &mt('No changes made to course settings.');
2456: }
2457: return $output;
1.3 raeburn 2458: }
1.49.2.28.2.1 (raeburn 2459:: my ($numchanges,$skipstore);
2460:: if (ref($changes) eq 'HASH') {
2461:: $numchanges = scalar(keys(%{$changes}));
1.49.2.28.2.5 (raeburn 2462:: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.49.2.28.2.1 (raeburn 2463:: $skipstore = 1;
2464:): } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2465:): $skipstore = 1;
2466:: } elsif (!$numchanges) {
2467:: if ($crstype eq 'Community') {
2468:: $output = &mt('No changes made to community settings.');
2469:: } else {
2470:: $output = &mt('No changes made to course settings.');
2471:: }
2472:: return $output;
2473:: }
2474:: }
1.3 raeburn 2475: my %yesno = (
2476: hidefromcat => '1',
2477: problem_stream_switch => '1',
2478: suppress_tries => '1',
2479: disableexampointprint => '1',
2480: hideemptyrows => '1',
2481: suppress_embed_prompt => '1',
2482: );
2483: foreach my $item (@{$prefs_order}) {
2484: if (grep(/^\Q$item\E$/,@{$actions})) {
2485: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2486: if (ref($changes->{$item}) eq 'HASH') {
1.49.2.28.2.3 (raeburn 2487:: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2488: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2489: if ($item eq 'other') {
2490: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2491: $storehash{$key} = $changes->{$item}{$key};
2492: if ($changes->{$item}{$key} eq '') {
2493: push(@delkeys,$key);
1.22 wenzelju 2494: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2495: } else {
1.22 wenzelju 2496: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2497: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2498: }
2499: }
1.49.2.28.2.5 (raeburn 2500:: } elsif ($item eq 'linkprot') {
2501:: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.49.2.28.2.1 (raeburn 2502:): } elsif ($item eq 'ltitools') {
2503:): $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2504: } else {
2505: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2506: my @settings = @{$prefs->{$item}->{'ordered'}};
2507: if ($item eq 'feedback') {
2508: push(@settings,(map { $_.'.text'; } @settings));
2509: }
2510: foreach my $key (@settings) {
2511: if ($key eq 'rolenames') {
2512: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2513: my $msg;
1.9 raeburn 2514: my @roles;
2515: if ($crstype eq 'Community') {
2516: @roles = ('co');
2517: } else {
2518: @roles = ('cc');
2519: }
2520: push(@roles,('in','ta','ep','ad','st'));
2521: foreach my $role (@roles) {
1.3 raeburn 2522: next if (!exists($changes->{$item}{$key.'_'.$role}));
2523: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2524: my $newname = $changes->{$item}{$key.'_'.$role};
2525: $storehash{$role.'.plaintext'} = $newname;
2526: if ($newname eq '') {
2527: $newname = $stdname;
2528: }
2529: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2530: "'<b>".$newname."</b>'").'</li>';
2531: }
2532: if ($msg ne '') {
1.22 wenzelju 2533: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2534: }
1.49.2.28.2.1 (raeburn 2535:): } elsif ($key eq 'timezone') {
2536:): next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2537:): my ($displayname,$text);
2538:): $text = $prefs->{$item}->{'itemtext'}{$key};
2539:): my $displayval;
2540:): if (exists($changes->{$item}{$key})) {
2541:): $displayname = &mt($text);
2542:): $storehash{$key} = $changes->{$item}{$key};
2543:): if ($changes->{$item}{$key} ne '') {
2544:): $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2545:): } else {
2546:): push(@delkeys,$key);
2547:): if (exists($values->{'tzover'})) {
2548:): push(@delkeys,'tzover');
2549:): }
2550:): $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2551:): '<i>'.$displayname.'</i>')).'</li>';
2552:): }
2553:): }
2554:): unless (grep(/^\Q$key\E$/,@delkeys)) {
2555:): if (exists($changes->{$item}{'tzover'})) {
2556:): $storehash{'tzover'} = $changes->{$item}{'tzover'};
2557:): my $tzovertext;
2558:): if ($changes->{$item}{'tzover'} ne '') {
2559:): $tzovertext = &mt('Course Time Zone overrides individual user preference');
2560:): } else {
2561:): push(@delkeys,'tzover');
2562:): $tzovertext = &mt('Course Time Zone does not override individual user preference');
2563:): }
2564:): if ($displayval eq '') {
2565:): $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2566:): } else {
2567:): $displayval .= '<br />'.(' 'x5).$tzovertext;
2568:): }
2569:): }
2570:): if ($displayval ne '') {
2571:): $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2572:): '<i>'.$displayname.'</i>',$displayval)).'</li>';
2573:): }
2574:): }
1.3 raeburn 2575: } else {
2576: next if (!exists($changes->{$item}{$key}));
2577: my ($displayname,$text);
2578: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2579: my $displayval;
1.49.2.28.2.1 (raeburn 2580:): unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2581: $displayval = $changes->{$item}{$key};
2582: }
1.3 raeburn 2583: if ($item eq 'feedback') {
2584: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2585: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2586: $displayname = &mt('Custom text for '.$text.' questions');
2587: } else {
2588: $displayname = &mt('Recipients of '.$text.' questions');
2589: }
2590: } elsif ($item eq 'discussion') {
2591: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2592: $displayname = &mt("$text (role-based)");
2593: if ($displayval ne '') {
2594: my @roles = split(',',$displayval);
2595: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2596: $displayval = join(', ',@roles);
2597: }
2598: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2599: $displayname = &mt("$text (specific user(s))");
2600: } else {
2601: if ($key eq 'allow_discussion_post_editing') {
2602: if ($displayval ne '') {
2603: my @roles = split(',',$displayval);
2604: my @longroles;
2605: foreach my $role (@roles) {
2606: my ($trole,$sec) = split(':',$role);
2607: my $rolename =
2608: &Apache::lonnet::plaintext($trole);
2609: if ($sec ne '') {
2610: $rolename .= ':'.$sec;
2611: }
2612: push(@longroles,$rolename);
2613: }
2614: $displayval = join(', ',@longroles);
2615: }
1.49.2.3 raeburn 2616: } elsif ($key eq 'discussion_post_fonts') {
2617: my ($classorder,$classtitles)=&discussion_vote_classes();
2618: my ($styleorder,$styleitems)=&discussion_vote_styles();
2619: my $count = 1;
2620: my $total = scalar(keys(%{$changes->{$item}}));
2621: foreach my $class (@{$classorder}) {
2622: $count ++;
2623: next unless ($changes->{$item}{$key.'_'.$class});
2624: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2625: my $showval = '';
2626: for (my $i=0; $i<@{$styleorder}; $i++) {
2627: if ($vals[$i] ne '') {
2628: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2629: }
2630: }
2631: if ($vals[3] ne '') {
2632: $showval .= $vals[3];
2633: }
2634: if ($showval ne '') {
2635: $displayval .= $classtitles->{$class}.':{ '.
2636: $showval.'}';
2637: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2638: } else {
2639: $displayval .= $classtitles->{$class}.': '.&mt('None');
2640: push(@delkeys,$key.'_'.$class);
2641: }
2642: unless ($count == $total) {
2643: $displayval .= (' 'x2);
2644: }
2645: }
1.3 raeburn 2646: }
2647: $displayname = &mt($text);
2648: }
2649: } elsif ($item eq 'spreadsheet') {
2650: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2651: my $sheettype = $1;
2652: if ($sheettype eq 'studentcalc') {
2653: &Apache::lonnet::expirespread('','','studentcalc');
2654: } else {
2655: &Apache::lonnet::expirespread('','','assesscalc');
2656: &Apache::lonnet::expirespread('','','studentcalc');
2657: }
2658: }
2659: $displayname = &mt($text);
1.49.2.28.2.1 (raeburn 2660:: } elsif ($item eq 'menuitems') {
2661:: unless ($changes->{$item}{$key} eq '') {
2662:: if ($key eq 'menudefault') {
2663:: $displayname = &mt('Default collection of menu items');
2664:: $displayval = &mt('Collection: [_1]',
2665:: $changes->{$item}{$key});
2666:: } elsif ($key eq 'menucollections') {
2667:: $displayval = &menucollections_display($changes->{$item}{$key});
2668:: }
2669:: }
1.3 raeburn 2670: } else {
2671: $displayname = &mt($text);
2672: }
2673: if (defined($yesno{$key})) {
1.14 raeburn 2674: $displayval = &mt('No');
1.3 raeburn 2675: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2676: $displayval = &mt('Yes');
1.3 raeburn 2677: }
2678: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2679: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2680: } elsif ($key eq 'categories') {
2681: $displayval = $env{'form.categories_display'};
1.49.2.28 raeburn 2682: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2683: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2684: if ($changes->{$item}{$key} eq '1') {
2685: $displayval = &mt('Yes');
2686: } elsif ($changes->{$item}{$key} eq '0') {
2687: $displayval = &mt('No');
2688: }
1.49.2.28.2.1 (raeburn 2689:): } elsif ($key eq 'extresource') {
2690:): if ($changes->{$item}{$key} eq 'iframe') {
2691:): $displayval = &mt('In iframe');
2692:): } else {
2693:): my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2694:): if ($selected eq 'tab') {
2695:): if ($reuse) {
2696:): $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2697:): "'<b>","</b>'",'<br />');
2698:): } else {
2699:): $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2700:): "'<b>","</b>'",'<br />');
2701:): }
2702:): } elsif ($selected eq 'window') {
2703:): if ($reuse) {
2704:): $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2705:): "'<b>","</b>'",'<br />');
2706:): } else {
2707:): $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2708:): "'<b>","</b>'",'<br />');
2709:): }
2710:): if (($width ne '') || ($height ne '')) {
2711:): if ($width ne '') {
2712:): $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2713:): }
2714:): if ($height ne '') {
2715:): $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2716:): }
2717:): }
2718:): }
2719:): }
1.14 raeburn 2720: }
1.25 raeburn 2721: if ($key eq 'co-owners') {
2722: if (ref($changes->{$item}{$key}) eq 'HASH') {
2723: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2724: foreach my $type ('co-owners','pendingco-owners') {
2725: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2726: if ($type eq 'pendingco-owners') {
2727: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2728: $displayname = &mt('Invited as co-owners, pending acceptance');
2729: }
2730: }
2731: if ($changes->{$item}{$key}{$type} eq '') {
2732: push(@delkeys,'internal.'.$type);
2733: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2734: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2735: '<i>'.$displayname.'</i>')).'</li>';
2736: }
2737: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2738: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2739: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2740: '<i>'.$displayname.'</i>',
2741: "'<b>$displayval</b>'")).'</li>';
2742: }
2743: }
2744: }
2745: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.49.2.26 raeburn 2746: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2747: $displayval = &mt('on');
1.49.2.26 raeburn 2748: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2749: $displayval = '';
2750: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.49.2.26 raeburn 2751: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2752: $displayval = &mt('off');
2753: }
2754: if ($displayval) {
2755: $displayname = &mt('Your co-ownership status');
2756: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2757: '<i>'.$displayname.'</i>',
2758: "'<b>$displayval</b>'")).'</li>';
2759: }
2760: }
2761: }
2762: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2763: push(@delkeys,$key);
1.49.2.28.2.1 (raeburn 2764:: if ($item eq 'menuitems') {
2765:: if ($key eq 'menudefault') {
2766:: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2767:: } elsif ($key eq 'menucollections') {
2768:: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2769:: }
2770:: } else {
2771:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2772:: '<i>'.$displayname.'</i>')).'</li>';
2773:: }
2774:: } elsif ($key eq 'menucollections') {
2775:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2776:: $displayval.'</li>';
1.3 raeburn 2777: } else {
1.49.2.28.2.1 (raeburn 2778:): unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2779:): $displayval = "'<b>$displayval</b>'";
2780:): }
1.22 wenzelju 2781: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.49.2.28.2.1 (raeburn 2782:): '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2783: if ($key eq 'url') {
2784: my $bkuptime=time;
2785: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2786: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2787: }
2788: $output .= '</li>';
2789: }
1.25 raeburn 2790: if ($key eq 'co-owners') {
2791: if (ref($changes->{$item}{$key}) eq 'HASH') {
2792: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2793: foreach my $type ('co-owners','pendingco-owners') {
2794: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2795: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2796: }
2797: }
2798: }
2799: } else {
1.49.2.3 raeburn 2800: unless ($key eq 'discussion_post_fonts') {
2801: $storehash{$key} = $changes->{$item}{$key};
2802: }
1.25 raeburn 2803: }
1.3 raeburn 2804: }
1.23 raeburn 2805: if ($key eq 'cloners') {
2806: # Get existing cloners
2807: my %clonenames =
2808: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2809: if ($clonenames{'cloners'} =~ /,/) {
2810: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2811: } else {
2812: $oldcloner[0] = $clonenames{'cloners'};
2813: }
2814: }
1.3 raeburn 2815: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2816: ($key eq 'hidefromcat') || ($key eq 'categories') ||
2817: ($key eq 'co-owners')) {
1.3 raeburn 2818: push(@need_env_update,$key);
2819: }
2820: }
2821: }
2822: }
2823: $output .= '</ul>';
2824: } else {
1.9 raeburn 2825: if ($crstype eq 'Community') {
1.46 raeburn 2826: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2827: } else {
1.46 raeburn 2828: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2829: }
1.3 raeburn 2830: }
2831: }
2832: }
2833: }
1.49.2.28.2.1 (raeburn 2834:: if ($skipstore) {
2835:: return $output;
2836:: }
1.3 raeburn 2837: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2838: if (ref($changes) eq 'HASH') {
2839: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2840: if (exists($changes->{'courseinfo'}{'cloners'})) {
2841: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2842: \@oldcloner);
2843: }
2844: }
2845: }
1.3 raeburn 2846: if (@delkeys) {
2847: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2848: $output .= '<br /><span class="LC_error">';
2849: if ($crstype eq 'Community') {
2850: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2851: } else {
2852: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2853: }
2854: $output .= '</span>';
1.14 raeburn 2855: } else {
2856: foreach my $key (@delkeys) {
2857: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
2858: }
1.3 raeburn 2859: }
2860: }
2861: if (@need_env_update) {
2862: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2863: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
2864: }
2865: &Apache::lonnet::coursedescription($env{'request.course.id'},
2866: {'freshen_cache' => 1});
2867: } else {
1.9 raeburn 2868: $output = '<span class="LC_error">';
2869: if ($crstype eq 'Community') {
2870: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
2871: } else {
2872: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
2873: }
2874: $output .= '</span>';
1.3 raeburn 2875: }
2876: return $output;
2877: }
2878:
1.49.2.28.2.5 (raeburn 2879:: sub store_linkprot {
2880:: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
2881:: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
2882:: if ($context eq 'domain') {
2883:: $ltiauth = 1;
2884:: $home = &Apache::lonnet::domain($cdom,'primary');
2885:: } else {
2886:: $home = &Apache::lonnet::homeserver($cnum,$cdom);
2887:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
2888:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
2889:: } else {
2890:: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
2891:: $ltiauth = $domdefs{'crsltiauth'};
2892:: }
2893:: }
2894:: if (ref($changes) eq 'HASH') {
2895:: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
2896:: if (ref($changes->{$id}) eq 'HASH') {
2897:: if (exists($changes->{$id}->{'key'})) {
2898:: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
2899:: delete($changes->{$id}->{'key'});
2900:: }
2901:: if (exists($changes->{$id}->{'secret'})) {
2902:: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
2903:: delete($changes->{$id}->{'secret'});
2904:: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
2905:: if (exists($oldlinkprot->{$id}{'usable'})) {
2906:: $changes->{$id}->{'usable'} = 1;
2907:: }
1.49.2.28.2.8 (raeburn 2908:: if (exists($oldlinkprot->{$id}{'cipher'})) {
2909:: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
2910:: }
1.49.2.28.2.5 (raeburn 2911:: }
2912:: }
2913:: }
2914:: }
2915:: my @ids=&Apache::lonnet::current_machine_ids();
2916:: if (keys(%ltienc) > 0) {
2917:: if ($context eq 'domain') {
2918:: foreach my $id (keys(%ltienc)) {
2919:: if (exists($ltienc{$id}{'secret'})) {
2920:: $changes->{$id}->{'usable'} = 1;
2921:: }
2922:: }
2923:: } else {
2924:: unless (($home eq 'no_host') || ($home eq '')) {
2925:: my $allowed;
2926:: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2927:: if ($allowed) {
2928:: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
2929:: foreach my $id (keys(%ltienc)) {
2930:: if (exists($ltienc{$id}{'secret'})) {
2931:: $changes->{$id}->{'usable'} = 1;
2932:: }
2933:: }
2934:: } else {
2935:: $lti_save_error = 1;
2936:: }
2937:: }
2938:: }
2939:: }
2940:: }
2941:: unless ($lti_save_error) {
2942:: if ($context eq 'course') {
2943:: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
2944:: my $hashid=$cdom.'_'.$cnum;
2945:: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
2946:: unless (($home eq 'no_host') || ($home eq '')) {
2947:: if (grep(/^\Q$home\E$/,@ids)) {
2948:: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
2949:: }
2950:: }
2951:: } else {
2952:: $lti_save_error = 1;
2953:: }
2954:: }
2955:: unless ($lti_save_error) {
2956:: foreach my $id (sort { $a <=> $b } %{$changes}) {
2957:: if (ref($changes->{$id}) eq 'HASH') {
2958:: my %values = %{$changes->{$id}};
2959:: my %desc = &linkprot_names();
2960:: my $display;
1.49.2.28.2.1 (raeburn 2961:): foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.49.2.28.2.5 (raeburn 2962:: if (($title eq 'key') || ($title eq 'secret')) {
2963:: if (ref($ltienc{$id}) eq 'HASH') {
2964:: if (exists($ltienc{$id}{$title})) {
2965:: if ($title eq 'secret') {
2966:: my $length = length($ltienc{$id}{$title});
2967:: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
2968:: } else {
2969:: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
2970:: }
2971:: }
2972:: }
2973:: } elsif ($title eq 'version') {
2974:: if ($values{$title} eq 'LTI-1p0') {
2975:: $display .= $desc{$title}.': 1.1, ';
2976:: }
1.49.2.28.2.1 (raeburn 2977:): } elsif ($title eq 'returnurl') {
2978:): if ($values{$title}) {
2979:): $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
2980:): }
2981:): } elsif ($title eq 'passbackformat') {
2982:): if ($values{$title} eq '1.0') {
2983:): $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
2984:): } elsif ($values{$title} eq '1.1') {
2985:): $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
2986:): }
1.49.2.28.2.5 (raeburn 2987:: } else {
2988:: $display .= $desc{$title}.': '.$values{$title}.', ';
2989:: }
2990:: }
2991:: if ($ltiauth) {
2992:: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
2993:: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
2994:: $display .= &mt('Source of username: Email address [_1]',
2995:: '(lis_person_contact_email_primary)').', ';
2996:: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
2997:: $display .= &mt('Source of username: User ID [_1]',
2998:: '(lis_person_sourcedid)').', ';
2999:: } else {
3000:: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3001:: }
3002:: if ($values{'notstudent'} eq 'auth') {
3003:: $display .= &mt('Display LON-CAPA login page if no match').', ';
3004:: } elsif ($values{'notstudent'} eq 'reject') {
3005:: $display .= &mt('Discontinue launch if no match').', ';
3006:: }
3007:: }
3008:: }
3009:: $display =~ s/, $//;
3010:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3011:: "'$display'")).'</li>';
3012:: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3013:: my $oldname = $oldlinkprot->{$id}{'name'};
3014:: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3015:: }
3016:: }
3017:: } else {
3018:: $lti_save_error = 1;
3019:: }
3020:: }
3021:: unless ($lti_save_error) {
3022:: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3023:: unless (ref($changes->{$id}) eq 'HASH') {
3024:: push(@deletions,$id);
3025:: }
3026:: }
3027:: if (@deletions) {
3028:: if ($context eq 'course') {
3029:: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3030:: }
3031:: }
3032:: }
3033:: if ($lti_save_error) {
3034:: $output .= '<li>'.
3035:: '<span class="LC_error">'.
3036:: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3037:: '</span>'.
3038:: '</li>';
3039:: }
3040:: return $output;
3041:: }
3042::
1.49.2.28.2.1 (raeburn 3043:): sub store_ltitools {
3044:): my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3045:): my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3046:): my %lt = <itools_names();
3047:): my @courseroles = ('cc','in','ta','ep','st');
3048:): my @allfields = ('fullname','firstname','lastname','email','user','roles');
3049:): if ($context eq 'domain') {
3050:): $home = &Apache::lonnet::domain($cdom,'primary');
3051:): } else {
3052:): $home = &Apache::lonnet::homeserver($cnum,$cdom);
3053:): }
3054:): if (ref($changes) eq 'HASH') {
3055:): foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3056:): if (ref($changes->{$id}) eq 'HASH') {
3057:): if (exists($changes->{$id}->{'key'})) {
3058:): $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3059:): delete($changes->{$id}->{'key'});
3060:): }
3061:): if (exists($changes->{$id}->{'secret'})) {
3062:): $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3063:): delete($changes->{$id}->{'secret'});
3064:): } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3065:): if (exists($oldltitools->{$id}{'usable'})) {
3066:): $changes->{$id}->{'usable'} = 1;
3067:): }
3068:): if (exists($oldltitools->{$id}{'cipher'})) {
3069:): $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3070:): }
3071:): }
3072:): }
3073:): }
3074:): }
3075:): my @ids=&Apache::lonnet::current_machine_ids();
3076:): if (keys(%toolsenc) > 0) {
3077:): unless (($home eq 'no_host') || ($home eq '')) {
3078:): my $allowed;
3079:): foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3080:): if ($allowed) {
3081:): if (($context eq 'domain') ||
3082:): (($context eq 'course') &&
3083:): (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3084:): foreach my $id (keys(%toolsenc)) {
3085:): if (exists($toolsenc{$id}{'secret'})) {
3086:): $changes->{$id}->{'usable'} = 1;
3087:): }
3088:): }
3089:): } else {
3090:): $ltitools_save_error = 1;
3091:): }
3092:): }
3093:): }
3094:): }
3095:): unless ($ltitools_save_error) {
3096:): if ($context eq 'course') {
3097:): if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3098:): my $hashid=$cdom.'_'.$cnum;
3099:): &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3100:): unless (($home eq 'no_host') || ($home eq '')) {
3101:): if (grep(/^\Q$home\E$/,@ids)) {
3102:): &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
3103:): }
3104:): }
3105:): } else {
3106:): $ltitools_save_error = 1;
3107:): }
3108:): }
3109:): unless ($ltitools_save_error) {
3110:): my %bynum;
3111:): foreach my $itemid (sort(keys(%{$changes}))) {
3112:): my $position = $changes->{$itemid}{'order'};
3113:): $bynum{$position} = $itemid;
3114:): }
3115:): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3116:): my $itemid = $bynum{$pos};
3117:): if (ref($changes->{$itemid}) ne 'HASH') {
3118:): $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3119:): } else {
3120:): $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3121:): if ($changes->{$itemid}{'image'}) {
3122:): $output .= ' '.
3123:): '<img src="'.$changes->{$itemid}{'image'}.'"'.
3124:): ' alt="'.&mt('Tool Provider icon').'" />';
3125:): }
3126:): $output .= '</li><ul>';
3127:): my $position = $pos + 1;
3128:): $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3129:): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3130:): if ($changes->{$itemid}{$item} ne '') {
3131:): $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3132:): }
3133:): }
3134:): if (ref($toolsenc{$itemid}) eq 'HASH') {
3135:): foreach my $item ('key','secret') {
3136:): if (exists($toolsenc{$itemid}{$item})) {
3137:): if ($item eq 'secret') {
3138:): $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3139:): } else {
3140:): $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3141:): }
3142:): }
3143:): }
3144:): }
3145:): $output .= '<li>'.&mt('Configurable in course:');
3146:): my @possconfig = ('label','title','target','linktext','explanation','append');
3147:): my $numconfig = 0;
3148:): if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3149:): foreach my $item (@possconfig) {
3150:): if ($changes->{$itemid}{'crsconf'}{$item}) {
3151:): $numconfig ++;
3152:): $output .= ' "'.$lt{'crs'.$item}.'"';
3153:): }
3154:): }
3155:): }
3156:): if (!$numconfig) {
3157:): $output .= ' '.&mt('None');
3158:): }
3159:): $output .= '</li>';
3160:): foreach my $item ('passback','roster') {
3161:): $output .= '<li>'.$lt{$item}.' ';
3162:): if ($changes->{$itemid}{$item}) {
3163:): $output .= &mt('Yes');
3164:): if ($changes->{$itemid}{$item.'valid'}) {
3165:): if ($item eq 'passback') {
3166:): $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3167:): $changes->{$itemid}{$item.'valid'});
3168:): } else {
3169:): $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3170:): $changes->{$itemid}{$item.'valid'});
3171:): }
3172:): }
3173:): } else {
3174:): $output .= &mt('No');
3175:): }
3176:): $output .= '</li>';
3177:): }
3178:): if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3179:): my $displaylist;
3180:): if ($changes->{$itemid}{'display'}{'target'}) {
3181:): $displaylist = &mt('Display target').': '.
3182:): $changes->{$itemid}{'display'}{'target'}.',';
3183:): }
3184:): foreach my $size ('width','height') {
3185:): if ($changes->{$itemid}{'display'}{$size}) {
3186:): $displaylist .= (' 'x2).$lt{$size}.': '.
3187:): $changes->{$itemid}{'display'}{$size}.',';
3188:): }
3189:): }
3190:): if ($displaylist) {
3191:): $displaylist =~ s/,$//;
3192:): $output .= '<li>'.$displaylist.'</li>';
3193:): }
3194:): foreach my $item ('linktext','explanation') {
3195:): if ($changes->{$itemid}{'display'}{$item}) {
3196:): $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3197:): }
3198:): }
3199:): }
3200:): if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3201:): my $fieldlist;
3202:): foreach my $field (@allfields) {
3203:): if ($changes->{$itemid}{'fields'}{$field}) {
3204:): $fieldlist .= (' 'x2).$lt{$field}.',';
3205:): }
3206:): }
3207:): if ($fieldlist) {
3208:): $fieldlist =~ s/,$//;
3209:): if ($changes->{$itemid}{'fields'}{'user'}) {
3210:): if ($changes->{$itemid}{'incdom'}) {
3211:): $fieldlist .= ' ('.&mt('username:domain').')';
3212:): } else {
3213:): $fieldlist .= ' ('.&mt('username').')';
3214:): }
3215:): }
3216:): $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3217:): }
3218:): }
3219:): if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3220:): my $rolemaps;
3221:): foreach my $role (@courseroles) {
3222:): if ($changes->{$itemid}{'roles'}{$role}) {
3223:): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3224:): $changes->{$itemid}{'roles'}{$role}.',';
3225:): }
3226:): }
3227:): if ($rolemaps) {
3228:): $rolemaps =~ s/,$//;
3229:): $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3230:): }
3231:): }
3232:): if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3233:): my $customlist;
3234:): if (keys(%{$changes->{$itemid}{'custom'}})) {
3235:): foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3236:): $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3237:): }
3238:): }
3239:): if ($customlist) {
3240:): $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3241:): }
3242:): }
3243:): $output .= '</ul></li>';
3244:): }
3245:): }
3246:): }
3247:): }
3248:): return $output;
3249:): }
3250:):
1.3 raeburn 3251: sub update_env {
3252: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3253: my $count = 0;
3254: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3255: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3256: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3257: foreach my $key (@{$need_env_update}) {
3258: if ($key eq 'description' && defined($storehash->{$key})) {
3259: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3260: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3261: $count ++;
3262: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3263: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3264: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3265: $count ++;
1.25 raeburn 3266: } elsif ($key eq 'co-owners') {
3267: if ($storehash->{'internal.co-owners'} ne '') {
3268: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3269: }
3270: if ($storehash->{'internal.pendingco-owners'} ne '') {
3271: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3272: }
3273: my @coowners = split(',',$storehash->{'internal.'.$key});
3274: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3275: $count ++;
1.3 raeburn 3276: }
3277: }
3278: if ($count) {
3279: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3280: }
3281: }
3282: }
3283: return;
3284: }
3285:
3286: sub display_disallowed {
1.9 raeburn 3287: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3288: my $output;
3289: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3290: if (keys(%{$disallowed})) {
3291: if ($item eq 'cloners') {
3292: my @fails;
3293: my %lt = &Apache::lonlocal::texthash (
3294: format => 'Invalid format',
3295: domain => 'Domain does not exist',
3296: newuser => 'LON-CAPA user(s) do(es) not exist.',
3297: );
3298: foreach my $error ('format','domain','newuser') {
3299: if (defined($disallowed->{$error})) {
3300: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3301: $lt{$error};
3302: if ($error eq 'newuser') {
1.9 raeburn 3303: $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 3304: }
3305: push(@fails,$msg);
3306: }
3307: }
3308: if (@fails) {
3309: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3310: '</span>'.join('; ',@fails).'.<br />';
3311: }
3312: } elsif ($item eq 'rolenames') {
3313: my %lt = &Apache::lonlocal::texthash (
3314: replacements => 'Name already used to replace a different standard role name',
3315: regulars => 'Name already used as a standard role name',
3316: customrole => 'Name already used as the name of a custom role',
3317: );
3318: my @fails;
3319: foreach my $error ('replacements','regulars','customrole') {
3320: if (ref($disallowed->{$error}) eq 'ARRAY') {
3321: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3322: '</b>, '.&mt('reason').' - '.$lt{'error'});
3323: }
3324: }
3325: if (@fails) {
3326: $output .= '<span class="LC_warning">'.
3327: &mt('Unable to include amongst replacements for role names: ').
3328: '</span>'.join('; ',@fails).'.<br />';
3329: }
3330:
3331: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3332: $output .= '<span class="LC_warning">';
3333: if ($item eq 'feedback') {
1.9 raeburn 3334: if ($crstype eq 'Community') {
3335: $output .= &mt('Unable to include as a recipient of community feedback for:');
3336: } else {
3337: $output .= &mt('Unable to include as a recipient of course feedback for:');
3338: }
1.3 raeburn 3339: } elsif ($item eq 'discussion') {
3340: $output .= &mt('Unable to include in user-based access control for:');
3341: } elsif ($item eq 'localization') {
1.9 raeburn 3342: if ($crstype eq 'Community') {
3343: $output .= &mt('Unable to include in community localization:');
3344: } else {
3345: $output .= &mt('Unable to include in course localization:');
3346: }
1.3 raeburn 3347: }
3348: $output .= '</span><ul>';
3349: foreach my $key (sort(keys(%{$disallowed}))) {
3350: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3351: $output .= '<li><i>'.$itemtext.'</i> - ';
3352: if ($item eq 'localization') {
3353: $output .= &mt('reason - unsupported language: [_1]',
3354: '<b>'.$disallowed->{$key}.'</b>');
3355: } else {
3356: $output .= &mt('reason - invalid user: [_1]',
3357: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3358: }
3359: }
3360: $output .= '</ul><br />';
3361: }
3362: }
1.1 raeburn 3363: }
1.3 raeburn 3364: return $output;
1.1 raeburn 3365: }
3366:
3367: sub get_course {
3368: my ($courseid) = @_;
3369: if (!defined($courseid)) {
3370: $courseid = $env{'request.course.id'};
3371: }
3372: my $cdom=$env{'course.'.$courseid.'.domain'};
3373: my $cnum=$env{'course.'.$courseid.'.num'};
1.49.2.14 raeburn 3374: my $chome=$env{'course.'.$courseid.'.home'};
3375: return ($cnum,$cdom,$chome);
1.1 raeburn 3376: }
3377:
3378: sub get_jscript {
1.49.2.28.2.1 (raeburn 3379:: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3380: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.49.2.28.2.1 (raeburn 3381:): my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3382: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3383: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3384: my $cloners_js = &cloners_javascript($phase);
1.49.2.28.2.1 (raeburn 3385:): my $currltitools;
3386:): if (ref($settings) eq 'HASH') {
3387:): $currltitools = $settings->{'ltitools'};
3388:): }
3389:): my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.49.2.18 raeburn 3390: my @code_order;
3391: if ($crstype ne 'Community') {
3392: if (ref($settings) eq 'HASH') {
3393: my %codedefaults;
3394: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3395: \@code_order);
3396: if (@code_order > 0) {
3397: if ($phase eq 'display') {
3398: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3399: if (grep(/^courseinfo$/,@actions)) {
3400: if ($settings->{'cloners'} ne '') {
3401: unless ($settings->{'cloners'} eq '*') {
3402: my @cloners = split(/,/,$settings->{'cloners'});
3403: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3404: my %local_to_standard;
3405: for (my $i=0; $i<@code_order; $i++) {
3406: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3407: }
3408: foreach my $cloner (@cloners) {
3409: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
3410: ($cloner !~ /^$match_username\:$match_domain$/)) {
3411: foreach my $item (split(/\&/,$cloner)) {
3412: my ($key,$val) = split(/\=/,$item);
3413: $val = &unescape($val);
3414: foreach my $code (@code_order) {
3415: if ($key eq $local_to_standard{$code}) {
3416: $env{'form.'.$key} = $val;
3417: }
3418: }
3419: }
3420: }
3421: }
3422: }
3423: }
3424: }
3425: }
3426: my @codetitles;
3427: (undef,$instcode_js) =
3428: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3429: \@codetitles);
3430: $instcode_js .= <<ENDSCRIPT;
3431: function toggleCloners(callerradio) {
3432: if (document.getElementById('LC_cloners_instcode')) {
3433: if (callerradio.value == 1) {
3434: document.getElementById('LC_cloners_instcode').style.display = "block";
3435: } else {
3436: uncheckOfficialLists();
3437: document.getElementById('LC_cloners_instcode').style.display = "none";
3438: }
3439: }
3440: }
3441:
3442: if (!document.getElementsByClassName) {
3443: function getElementsByClassName(node, classname) {
3444: var a = [];
3445: var re = new RegExp('(^| )'+classname+'( |$)');
3446: var els = node.getElementsByTagName("*");
3447: for(var i=0,j=els.length; i<j; i++)
3448: if(re.test(els[i].className))a.push(els[i]);
3449: return a;
3450: }
3451: }
3452:
3453: function uncheckOfficialLists() {
3454: var codepicks;
3455: if (document.getElementsByClassName) {
3456: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3457: } else {
3458: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3459: }
3460: if (codepicks.length) {
3461: for (var i=0; i<codepicks.length; i++) {
3462: codepicks[i].selectedIndex = 0;
3463: }
3464: }
3465: }
3466:
3467: ENDSCRIPT
3468: }
3469: }
3470: }
1.1 raeburn 3471: if ($can_categorize) {
3472: $categorize_js = <<ENDSCRIPT;
3473: function catsbrowser() {
3474: var catswin = null;
3475: var url = '/adm/courseprefs?phase=categorizecourse';
3476: if (!catswin || catswin.closed) {
3477: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3478: } else {
3479: catswin.focus();
3480: }
3481: }
3482: ENDSCRIPT
3483: }
1.36 raeburn 3484: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3485: if ($loncaparev) {
3486: $loncaparev_js = <<ENDSCRIPT;
3487: function loncaparevinfo() {
3488: var lcrevwin = null;
3489: var url = '/adm/courseprefs?phase=releaseinfo';
3490: if (!lcrevwin || lcrevwin.closed) {
3491: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3492: } else {
3493: lcrevwin.focus();
3494: }
3495: }
3496: ENDSCRIPT
3497: }
1.49.2.10 raeburn 3498: my $cnum = $env{'course.'.$cid.'.num'};
3499: my $syllabus_js = <<ENDSCRIPT;
3500: function syllabusinfo() {
3501: var syllwin = null;
3502: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3503: if (!syllwin || syllwin.closed) {
3504: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3505: } else {
3506: syllwin.focus();
3507: }
3508: }
3509: ENDSCRIPT
1.49.2.28.2.1 (raeburn 3510:: my $menuitems_js;
3511:: unless ($noedit) {
3512:: my $collections;
3513:: my $next = 1;
3514:: if (ref($settings) eq 'HASH') {
3515:: if ($settings->{'menucollections'} ne '') {
3516:: my @current;
3517:: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3518:: my ($num) = split(/\%/,$item);
3519:: if ($num =~ /^\d+$/) {
3520:: push(@current,$num);
3521:: }
3522:: }
3523:: $collections = join("','",sort { $a <=> $b } @current);
3524:: if ($collections) {
3525:: $collections = "'$collections'";
3526:: }
3527:: $next += $current[-1];
3528:: }
3529:: }
3530:: my $deftext = &mt('Standard (all menus shown)');
3531:: $menuitems_js = <<ENDSCRIPT;
3532:: function toggleAddmenucoll() {
3533:: if (document.getElementById('menucollections_add')) {
3534:: var state = 'none';
3535:: var add = document.getElementById('menucollections_add').checked;
3536:: if (add) {
3537:: state = 'inline-block';
3538:: }
3539:: var fieldsets = new Array('shown','text','links','list','inline');
3540:: for (var i=0; i<fieldsets.length; i++) {
3541:: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3542:: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3543:: }
3544:: }
3545:: var box = document.getElementsByClassName('LC_menucoll_add');
3546:: if (box.length) {
3547:: for (var i=0; i<box.length; i++) {
3548:: if (add) {
3549:: box[i].checked = true;
3550:: } else {
3551:: box[i].checked = false;
3552:: }
3553:: }
3554:: }
3555:: if (document.getElementById('menudefault')) {
3556:: var menudef = document.getElementById('menudefault');
3557:: var currsel = menudef.selectedIndex;
3558:: var colls = new Array($collections);
3559:: menudef.options.length = 0;
3560:: if (!add) {
3561:: if (currsel == 1 + colls.length) {
3562:: currsel = 0;
3563:: }
3564:: }
3565:: if (currsel == 0) {
3566:: menudef.options[0] = new Option('$deftext','',true,true);
3567:: } else {
3568:: menudef.options[0] = new Option('$deftext','',false,false);
3569:: }
3570:: if (colls.length) {
3571:: for (var i=0; i<colls.length; i++) {
3572:: var idx = i+1;
3573:: if (currsel == colls[i]) {
3574:: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3575:: } else {
3576:: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3577:: }
3578:: }
3579:: }
3580:: if (add) {
3581:: var addidx = 1 + colls.length;
3582:: if (currsel == addidx) {
3583:: menudef.options[addidx] = new Option('$next','$next',true,true);
3584:: } else {
3585:: menudef.options[addidx] = new Option('$next','$next',false,false);
3586:: }
3587:: }
3588:: }
3589:: }
3590:: }
3591:: ENDSCRIPT
3592:: }
3593:): $extresource_js = <<"ENDSCRIPT";
3594:): function toggleExtRes() {
3595:): if (document.getElementById('LC_extresource')) {
3596:): var extressel = document.getElementById('LC_extresource').value;
3597:): if (document.getElementById('LC_extresreusediv')) {
3598:): var extresreuse = document.getElementById('LC_extresreusediv');
3599:): if (document.getElementById('LC_extressize')) {
3600:): var extressize = document.getElementById('LC_extressize');
3601:): var setvis;
3602:): if ((extressel == 'tab') || (extressel == 'window')) {
3603:): extresreuse.style.display = 'inline-block';
3604:): setvis = 1;
3605:): if (extressel == 'window') {
3606:): extressize.style.display = 'inline-block';
3607:): } else {
3608:): extressize.style.display = 'none';
3609:): }
3610:): }
3611:): if (!setvis) {
3612:): extresreuse.style.display = 'none';
3613:): extressize.style.display = 'none';
3614:): }
3615:): }
3616:): }
3617:): }
3618:): }
3619:): ENDSCRIPT
3620:): $localization_js = <<"ENDSCRIPT";
3621:): function toggleTimeZone() {
3622:): if (document.getElementById('LC_set_timezone')) {
3623:): var timezonesel = document.getElementById('LC_set_timezone').value;
3624:): if (document.getElementById('LC_tzoverdiv')) {
3625:): var tzoverdiv = document.getElementById('LC_tzoverdiv');
3626:): if (timezonesel == '') {
3627:): tzoverdiv.style.display = 'none';
3628:): } else {
3629:): tzoverdiv.style.display = 'block';
3630:): }
3631:): }
3632:): }
3633:): }
3634:): ENDSCRIPT
1.1 raeburn 3635: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.49.2.7 raeburn 3636: '// <![CDATA['."\n".
1.36 raeburn 3637: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.49.2.28.2.1 (raeburn 3638:): $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
3639:): $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.49.2.28.2.5 (raeburn 3640:: &linkprot_javascript()."\n".'//]]>'."\n".
1.49.2.28.2.1 (raeburn 3641:): '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3642: return $jscript;
3643: }
3644:
1.3 raeburn 3645: sub cloners_javascript {
3646: my ($formname) = @_;
3647: return <<"ENDSCRIPT";
3648:
3649: function update_cloners(caller,num) {
3650: var delidx = getIndexByName('cloners_delete');
3651: var actidx = getIndexByName('cloners_activate');
3652: if (caller == 'cloners_all') {
3653: var selall;
3654: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3655: if (document.$formname.cloners_all[i].checked) {
3656: selall = document.$formname.cloners_all[i].value;
3657: }
3658: }
3659: if (selall == 1) {
3660: if (delidx != -1) {
3661: if (document.$formname.cloners_delete.length) {
3662: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3663: document.$formname.cloners_delete[j].checked = true;
3664: }
3665: } else {
3666: document.$formname.elements[delidx].checked = true;
3667: }
3668: }
3669: if (actidx != -1) {
3670: if (document.$formname.cloners_activate.length) {
3671: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3672: if (document.$formname.cloners_activate[i].value == '0') {
3673: document.$formname.cloners_activate[i].checked = false;
3674: }
1.49.2.18 raeburn 3675: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3676: document.$formname.cloners_activate[i].checked = true;
3677: }
3678: }
3679: }
3680: }
3681: document.$formname.cloners_newdom.selectedIndex = 0;
3682: }
3683: }
3684: if (caller == 'cloners_activate') {
3685: if (document.$formname.cloners_activate.length) {
3686: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3687: if (document.$formname.cloners_activate[j].value == num) {
3688: if (document.$formname.cloners_activate[j].checked) {
3689: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3690: if (document.$formname.cloners_all[i].value == '1') {
3691: document.$formname.cloners_all[i].checked = false;
3692: }
3693: if (document.$formname.cloners_all[i].value == '0') {
3694: document.$formname.cloners_all[i].checked = true;
3695: }
3696: }
3697: }
3698: }
3699: }
3700: } else {
3701: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3702: if (document.$formname.cloners_all[i].value == '1') {
3703: document.$formname.cloners_all[i].checked = false;
3704: }
3705: if (document.$formname.cloners_all[i].value == '0') {
3706: document.$formname.cloners_all[i].checked = true;
3707: }
3708: }
3709: }
3710: }
3711: return;
3712: }
3713:
3714: function getIndexByName(item) {
3715: for (var i=0;i<document.$formname.elements.length;i++) {
3716: if (document.$formname.elements[i].name == item) {
3717: return i;
3718: }
3719: }
3720: return -1;
3721: }
3722:
3723: ENDSCRIPT
3724: }
3725:
1.49.2.28.2.5 (raeburn 3726:: sub linkprot_javascript {
3727:: return <<"ENDSCRIPT";
1.49.2.28.2.1 (raeburn 3728:): function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.49.2.28.2.5 (raeburn 3729:: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3730:: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3731:: var itemname = form.elements['linkprot_'+item+'_'+num];
3732:: if (itemname) {
3733:: if (itemname.length > 0) {
3734:: var setvis;
3735:: for (var i=0; i<itemname.length; i++) {
3736:: if (itemname[i].checked == true) {
3737:: if (itemname[i].value == valon) {
3738:: extraid.style.display = styleon;
3739:: setvis = 1;
3740:: }
3741:: break;
3742:: }
3743:: }
3744:: if (!setvis) {
3745:: extraid.style.display = 'none';
3746:: }
3747:: }
3748:: }
3749:: }
3750:: return;
3751:: }
1.49.2.28.2.7 (raeburn 3752::
1.49.2.28.2.5 (raeburn 3753:: ENDSCRIPT
3754::
3755:: }
3756::
1.1 raeburn 3757: sub print_courseinfo {
1.49.2.21 raeburn 3758: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3759: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3760: return;
3761: }
1.49.2.22 raeburn 3762: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3763: if ($noedit) {
3764: $disabled = ' disabled="disabled"';
3765: }
1.1 raeburn 3766: my %domconf =
1.49.2.18 raeburn 3767: &Apache::lonnet::get_dom('configuration',
3768: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3769: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3770: $cathash = $domconf{'coursecategories'}{'cats'};
3771: if (ref($cathash) eq 'HASH') {
3772: $categoriesform =
3773: &Apache::loncommon::assign_categories_table($cathash,
1.49.2.22 raeburn 3774: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3775: }
3776: }
1.25 raeburn 3777: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3778: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3779: }
1.49.2.18 raeburn 3780: my ($currcanclone,@code_order,$cloner_instcode);
3781: my %codedefaults;
3782: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3783: \@code_order);
3784: if ($settings->{'cloners'}) {
3785: unless ($settings->{'cloners'} eq '*') {
3786: my @currclone = split(/,/,$settings->{'cloners'});
3787: foreach my $item (@currclone) {
3788: unless ($item eq '*') {
3789: if (($item !~ /\:/) && ($item =~ /=/)) {
3790: $cloner_instcode = 1;
3791: }
3792: }
3793: }
3794: }
3795: }
3796: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3797: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3798: if (ref($canclone) eq 'HASH') {
3799: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3800: if ($settings->{'internal.coursecode'}) {
3801: my @posscodes;
3802: if (@code_order > 0) {
3803: $currcanclone = 'instcode';
3804: foreach my $item (@{$canclone->{'instcode'}}) {
3805: if (grep(/^\Q$item\E$/,@code_order)) {
3806: push(@posscodes,$item);
3807: }
3808: }
3809: my $codestr = join(' + ',@posscodes);
3810: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3811: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3812: }
3813: }
3814: }
3815: } elsif ($canclone eq 'domain') {
3816: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
3817: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
3818: $currcanclone = 'domain';
3819: }
3820: if ($clonedefaults) {
3821: if ($settings->{'cloners'} ne '') {
3822: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
3823: } else {
3824: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
3825: }
3826: $clonedefaults = '<br /><br />'.$clonedefaults;
3827: }
3828: }
1.1 raeburn 3829: if (!defined($categoriesform)) {
1.15 raeburn 3830: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 3831: }
1.12 raeburn 3832: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.49.2.10 raeburn 3833: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 3834:
1.9 raeburn 3835: my $replace;
3836: if ($crstype eq 'Community') {
3837: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3838: } else {
3839: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3840: }
1.49.2.23 raeburn 3841: my ($editmap,$editsyllabus);
3842: unless ($noedit) {
3843: $editmap = (' 'x2).
3844: '<a href="javascript:openbrowser'.
3845: "('display','url','sequence')\">".
3846: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
3847: &mt('Modification may make assessment data inaccessible!').
3848: '</span>';
3849: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
3850: '</a>');
3851: }
1.1 raeburn 3852: my %items = (
1.3 raeburn 3853: 'url' => {
1.49.2.23 raeburn 3854: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 3855: input => 'textbox',
1.49.2.6 raeburn 3856: size => '55',
1.19 faziophi 3857: advanced => 1
1.1 raeburn 3858: },
3859: 'description' => {
1.3 raeburn 3860: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 3861: input => 'textbox',
1.49.2.6 raeburn 3862: size => '55',
1.1 raeburn 3863: },
1.24 raeburn 3864: 'owner' => {
3865: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
3866: },
1.25 raeburn 3867: 'co-owners' => {
3868: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
3869: },
1.49.2.11 raeburn 3870: 'clonedfrom' => {
3871: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
3872: },
1.1 raeburn 3873: 'courseid' => {
1.3 raeburn 3874: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
3875: &mt('internal, optional').')',
1.1 raeburn 3876: input => 'textbox',
3877: size => '25',
3878: },
1.49.2.12 raeburn 3879: 'uniquecode' => {
3880: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
3881: },
1.1 raeburn 3882: 'cloners' => {
1.3 raeburn 3883: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.49.2.18 raeburn 3884: &mt('Owner and Coordinators included automatically').
3885: $clonedefaults,
1.1 raeburn 3886: input => 'textbox',
1.41 www 3887: size => '40'
1.1 raeburn 3888: },
3889: 'rolenames' => {
1.3 raeburn 3890: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 3891: '('.$replace.')',
1.1 raeburn 3892: input => 'textbox',
3893: size => '20',
1.19 faziophi 3894: advanced => 1
1.1 raeburn 3895: },
1.49.2.24 raeburn 3896: 'syllabus' => {
3897: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.49.2.10 raeburn 3898: &mt('(Syllabus type in use)').(' ' x2).
1.49.2.23 raeburn 3899: $editsyllabus,
1.1 raeburn 3900: },
3901: 'hidefromcat' => {
1.3 raeburn 3902: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 3903: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
3904: input => 'radio',
3905: },
3906: 'categories' => {
1.3 raeburn 3907: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 3908: &mt('Display Categories').'</a>',
3909: input => 'textbox',
3910: size => '25',
3911: },
1.35 raeburn 3912: 'loncaparev' => {
3913: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
3914: },
1.49.2.6 raeburn 3915: 'defaultcredits' => {
3916: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
3917: },
1.1 raeburn 3918: );
3919: my $datatable;
3920: my $count = 0;
3921: foreach my $item (@{$ordered}) {
1.49.2.7 raeburn 3922: my $colspan;
1.1 raeburn 3923: if ($item eq 'hidefromcat') {
3924: next if (!$can_toggle_cat);
3925: } elsif ($item eq 'categories') {
3926: next if (!$can_categorize);
1.49.2.12 raeburn 3927: } elsif ($item eq 'uniquecode') {
3928: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 3929: }
1.49.2.7 raeburn 3930: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
3931: $colspan = 2;
3932: }
1.1 raeburn 3933: $count ++;
1.19 faziophi 3934: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.49.2.7 raeburn 3935: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 3936: } else {
1.49.2.7 raeburn 3937: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 3938: }
1.1 raeburn 3939: if ($items{$item}{input} eq 'radio') {
1.49.2.21 raeburn 3940: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 3941: } elsif ($item eq 'cloners') {
3942: my $includeempty = 1;
3943: my $num = 0;
1.49.2.7 raeburn 3944: $datatable .= '</td><td align="right">'.
3945: &Apache::loncommon::start_data_table().
1.1 raeburn 3946: &Apache::loncommon::start_data_table_row().
3947: '<td><span class="LC_nobreak"><label>'.
3948: &mt('Any user in any domain:').
3949: ' <input type="radio" name="cloners_all" value="1" ';
3950: if ($settings->{$item} eq '*') {
3951: $datatable .= ' checked="checked" ';
3952: }
3953: $datatable .= 'onchange="javascript:update_cloners('.
1.49.2.21 raeburn 3954: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.49.2.18 raeburn 3955: (' 'x2).'<label>'.
3956: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 3957: if ($settings->{$item} ne '*') {
3958: $datatable .= ' checked="checked" ';
3959: }
3960: $datatable .= ' onchange="javascript:update_cloners('.
1.49.2.21 raeburn 3961: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 3962: &Apache::loncommon::end_data_table_row().
3963: &Apache::loncommon::end_data_table().
1.49.2.7 raeburn 3964: '<table><tr><td align="left"><b>'.&mt('Or').
3965: '</b></td></tr></table>'.
1.1 raeburn 3966: &Apache::loncommon::start_data_table();
3967: my @cloners;
3968: if ($settings->{$item} eq '') {
1.49.2.21 raeburn 3969: unless ($noedit) {
3970: my $default;
3971: if ($currcanclone eq 'domain') {
3972: $default = '0';
3973: }
3974: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.49.2.28.2.1 (raeburn 3975:): }
1.1 raeburn 3976: } elsif ($settings->{$item} ne '*') {
3977: my @entries = split(/,/,$settings->{$item});
3978: if (@entries > 0) {
3979: foreach my $entry (@entries) {
3980: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 3981: if ($udom =~ /^$match_domain$/) {
3982: unless (&Apache::lonnet::domain($udom)) {
3983: next;
3984: }
3985: } else {
3986: next;
3987: }
1.1 raeburn 3988: if ($uname eq '*') {
3989: $datatable .=
3990: &Apache::loncommon::start_data_table_row().
1.3 raeburn 3991: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 3992: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 3993: '</b><input type="hidden" name="cloners_dom_'.$num.
3994: '" value="'.$udom.'" /></span><br />'.
3995: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.49.2.21 raeburn 3996: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 3997: &mt('Delete').'</label></span></td>'.
3998: &Apache::loncommon::end_data_table_row();
3999: $num ++;
1.23 raeburn 4000: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4001: unless (grep(/^\Q$entry\E$/,@cloners)) {
4002: push(@cloners,$entry);
4003: }
1.1 raeburn 4004: }
4005: }
4006: }
4007: }
4008: my $add_domtitle = &mt('Any user in additional domain:');
4009: if ($settings->{$item} eq '*') {
4010: $add_domtitle = &mt('Any user in specific domain:');
4011: } elsif ($settings->{$item} eq '') {
4012: $add_domtitle = &mt('Any user in other domain:');
4013: }
4014: my $cloners_str = join(',',@cloners);
4015: $datatable .= &Apache::loncommon::start_data_table_row().
4016: '<td align="left"><span class="LC_nobreak">'.
4017: $add_domtitle.'</span><br />'.
4018: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.49.2.21 raeburn 4019: $includeempty,undef,undef,
4020: undef,undef,$noedit).
1.1 raeburn 4021: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4022: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4023: &Apache::loncommon::end_data_table().
1.49.2.7 raeburn 4024: '<table><tr><td align="left"><b>'.&mt('And').
4025: '</b></td></tr></table>'.
1.1 raeburn 4026: &Apache::loncommon::start_data_table().
4027: &Apache::loncommon::start_data_table_row().
4028: '<td align="left">'.
4029: &mt('Specific users').' (<tt>'.
4030: &mt('user:domain,user:domain').'</tt>)<br />'.
4031: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.49.2.21 raeburn 4032: $items{$item}{'size'},$disabled).
1.1 raeburn 4033: '</td>'.&Apache::loncommon::end_data_table_row().
4034: &Apache::loncommon::end_data_table();
1.49.2.18 raeburn 4035: if (@code_order > 0) {
4036: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4037: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4038: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4039: \%cat_items,\@codetitles,
4040: \%cat_titles,\%cat_order);
4041: my $showncodes = 'off';
4042: my $checkedoff = ' checked="checked"';
4043: my $checkedon = '';
4044: if ($cloner_instcode) {
4045: $checkedon = $checkedoff;
4046: $checkedoff = '';
4047: $showncodes = 'on';
4048: }
4049: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4050: '</b></td></tr></table>'.
4051: &Apache::loncommon::start_data_table().
4052: &Apache::loncommon::start_data_table_row().
4053: '<td align="left"><span class="LC_nobreak">'.
4054: &mt('Cloning by official course(s) based on course category').(' 'x2).
4055: '<label>'.
1.49.2.21 raeburn 4056: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.49.2.18 raeburn 4057: (' ').
4058: '<label>'.
1.49.2.21 raeburn 4059: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.49.2.18 raeburn 4060: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4061: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.49.2.21 raeburn 4062: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.49.2.18 raeburn 4063: '</td>'.&Apache::loncommon::end_data_table_row().
4064: &Apache::loncommon::end_data_table();
4065: }
1.1 raeburn 4066: } elsif ($item eq 'rolenames') {
1.49.2.7 raeburn 4067: $datatable .= '</td><td align="right">'.
4068: &Apache::loncommon::start_data_table();
1.9 raeburn 4069: my @roles;
4070: if ($crstype eq 'Community') {
4071: @roles = ('co');
4072: } else {
4073: @roles = ('cc');
4074: }
4075: push (@roles,('in','ta','ep','ad','st'));
4076: foreach my $role (@roles) {
1.1 raeburn 4077: $datatable .= &Apache::loncommon::start_data_table_row().
4078: '<td align="left"><span class="LC_nobreak">'.
4079: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4080: '</span></td><td align="left">'.
4081: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4082: $settings->{$role.'.plaintext'},
1.49.2.21 raeburn 4083: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4084: &Apache::loncommon::end_data_table_row();
4085: }
4086: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4087: } elsif ($item eq 'categories') {
1.49.2.21 raeburn 4088: my $launcher;
4089: if ($noedit) {
4090: $launcher = $disabled;
4091: } else {
4092: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4093: }
1.3 raeburn 4094: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4095: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4096: $items{$item}{size},$launcher);
1.24 raeburn 4097: } elsif ($item eq 'owner') {
4098: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4099: if ($owner =~ /:/) {
4100: my ($ownername,$ownerdom) = split(':',$owner);
4101: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4102: } elsif ($owner ne '') {
4103: $owner = &Apache::loncommon::plainname($owner,$cdom);
4104: } else {
4105: $owner = &mt('None specified');
4106: }
4107: $datatable .= $owner;
1.49.2.11 raeburn 4108: } elsif ($item eq 'clonedfrom') {
4109: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4110: my $clonedfrom = &mt('None');
4111: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.49.2.13 raeburn 4112: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.49.2.11 raeburn 4113: if ($clonesrcinfo{'description'}) {
4114: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
4115: }
4116: }
4117: $datatable .= $clonedfrom;
1.49.2.12 raeburn 4118: } elsif ($item eq 'uniquecode') {
4119: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
4120: if ($code) {
4121: $datatable .= $code;
4122: }
1.25 raeburn 4123: } elsif ($item eq 'co-owners') {
4124: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4125: my @currcoown;
4126: if ($coowners) {
4127: @currcoown = split(',',$coowners);
4128: }
4129: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4130: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4131: $datatable .= &show_autocoowners(@currcoown);
4132: } else {
1.49.2.21 raeburn 4133: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4134: }
4135: } else {
4136: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4137: $datatable .= &show_autocoowners(@currcoown);
4138: } else {
1.49.2.21 raeburn 4139: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4140: }
4141: }
1.49.2.24 raeburn 4142: } elsif ($item eq 'syllabus') {
1.49.2.10 raeburn 4143: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4144: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4145: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4146: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4147: if ($minimal =~/\w/) {
4148: if ($external =~ m{\Q$minimal\E$}) {
4149: undef($external);
4150: }
4151: } elsif ($uploaded =~/\w/) {
4152: if ($external =~ m{\Q$uploaded\E$}) {
4153: undef($external);
4154: }
4155: }
4156: } elsif ($external!~/\w/) {
4157: undef($external);
4158: }
4159: if ($external) {
4160: $datatable .= &mt('External URL');
4161: } elsif ($minimal) {
4162: $datatable .= &mt('Minimal template');
4163: } elsif ($uploaded) {
4164: $datatable .= &mt('Uploaded file');
4165: } else {
4166: $datatable .= &mt('Standard template');
4167: }
4168: $datatable .= (' ' x 2).
4169: &mt('[_1]View[_2]',
4170: '<a href="javascript:syllabusinfo();">',
4171: '</a>');
1.35 raeburn 4172: } elsif ($item eq 'loncaparev') {
4173: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4174: my $showreqd;
4175: if ($loncaparev) {
1.36 raeburn 4176: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4177: &mt('Details').'</a>';
1.35 raeburn 4178: } else {
4179: $showreqd = &mt('No specific version required');
4180: }
4181: $datatable .= $showreqd;
1.1 raeburn 4182: } else {
1.49.2.21 raeburn 4183: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4184: }
4185: $datatable .= &item_table_row_end();
4186: }
4187: $$rowtotal += scalar(@{$ordered});
4188: return $datatable;
4189: }
4190:
4191: sub new_cloners_dom_row {
1.49.2.18 raeburn 4192: my ($newdom,$num,$default) = @_;
4193: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4194: if ($newdom ne '') {
1.49.2.18 raeburn 4195: if ($num eq $default) {
4196: $checkedon = 'checked="checked" ';
4197: } else {
4198: $checkedoff = 'checked="checked" ';
4199: }
1.1 raeburn 4200: $output .= &Apache::loncommon::start_data_table_row().
4201: '<td valign="top"><span class="LC_nobreak">'.
4202: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4203: (' 'x2).'<label><input type="radio" '.
1.49.2.18 raeburn 4204: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4205: 'onchange="javascript:update_cloners('.
1.1 raeburn 4206: "'cloners_activate','$num'".');" />'.
4207: &mt('Yes').'</label>'.(' 'x2).
4208: '<label><input type="radio" '.
1.49.2.18 raeburn 4209: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4210: 'onchange="javascript:update_cloners('.
1.1 raeburn 4211: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4212: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4213: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4214: &Apache::loncommon::end_data_table_row();
4215: }
4216: return $output;
4217: }
4218:
4219: sub can_modify_catsettings {
1.12 raeburn 4220: my ($dom,$crstype) = @_;
1.1 raeburn 4221: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4222: my ($can_toggle_cat,$can_categorize);
4223: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4224: if ($crstype eq 'Community') {
4225: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4226: $can_toggle_cat = 1;
4227: }
4228: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4229: $can_categorize = 1;
4230: }
4231: } else {
4232: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4233: $can_toggle_cat = 1;
4234: }
4235: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4236: $can_categorize = 1;
4237: }
1.1 raeburn 4238: }
4239: }
4240: return ($can_toggle_cat,$can_categorize);
4241: }
4242:
4243: sub assign_course_categories {
1.9 raeburn 4244: my ($r,$crstype) = @_;
1.1 raeburn 4245: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4246: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4247: my $hascats = 0;
4248: my $cathash;
4249: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4250: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4251: $cathash = $domconf{'coursecategories'}{'cats'};
4252: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4253: foreach my $cat (keys(%{$cathash})) {
4254: next if ($cat eq 'instcode::0');
4255: unless ($crstype eq 'Community') {
4256: next if ($cat eq 'communities::0');
4257: }
4258: $hascats ++;
4259: }
1.1 raeburn 4260: }
4261: }
4262: my $catwin_js;
4263: if ($hascats) {
1.9 raeburn 4264: my $alert;
4265: if ($crstype eq 'Community') {
4266: $alert = &mt("Use 'Save' in the main window to save community categories");
4267: } else {
4268: $alert = &mt("Use 'Save' in the main window to save course categories");
4269: }
1.49.2.19 raeburn 4270: &js_escape(\$alert);
1.1 raeburn 4271: $catwin_js = <<ENDSCRIPT;
4272: <script type="text/javascript">
4273:
4274: function updateCategories() {
4275: var newcategories = '';
4276: var unescapedcats = '';
4277: if (document.chgcats.usecategory.length) {
4278: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4279: if (document.chgcats.usecategory[i].checked == true) {
4280: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4281: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4282: }
4283: }
4284: if (newcategories.length > 0) {
4285: newcategories = newcategories.slice(0,-1);
4286: }
4287: if (unescapedcats.length > 0) {
4288: unescapedcats = unescapedcats.slice(0,-3);
4289: }
4290: } else {
4291: if (document.chgcats.usecategory.checked == true) {
4292: newcategories = document.chgcats.usecategory.value;
4293: unescapedcats = document.chgcats.catname.value;
4294: }
4295: }
4296: opener.document.display.categories.value = newcategories;
4297: opener.document.display.categories_display.value = unescapedcats;
4298: alert("$alert");
4299: self.close();
4300: return;
4301: }
4302:
4303: </script>
4304: ENDSCRIPT
4305: } else {
4306: my $onload;
4307: }
1.9 raeburn 4308: my ($crscat,$catcrs,$assign);
4309: if ($crstype eq 'Community') {
4310: $crscat = 'Community Categories';
4311: $catcrs = &mt('Categorize Community');
4312: $assign = &mt('Assign one or more categories to this community.')
4313: } else {
4314: $crscat = 'Course Categories';
4315: $catcrs = &mt('Categorize Course');
4316: $assign = &mt('Assign one or more categories to this course.')
4317: }
1.1 raeburn 4318: my $start_page =
1.9 raeburn 4319: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4320: {'only_body' => 1,});
4321: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4322: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4323: if ($hascats) {
4324: my %currsettings =
4325: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4326: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4327: $currsettings{'categories'},$crstype);
4328: if ($cattable eq '') {
4329: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4330: } else {
4331: $categoriesform .= $assign.'<br /><br />'.
4332: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4333: $cattable."\n".
4334: '<br /><input type="button" name="changes" value="'.
4335: &mt('Copy to main window').'" '.
4336: 'onclick="javascript:updateCategories()" /></form><br />';
4337: }
1.1 raeburn 4338: } else {
1.12 raeburn 4339: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4340: }
4341: $r->print($start_page.$categoriesform.$end_page);
4342: return;
4343: }
4344:
1.36 raeburn 4345: sub display_loncaparev_constraints {
4346: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.49.2.14 raeburn 4347: my ($reqdmajor,$reqdminor);
1.36 raeburn 4348: my $cid = $env{'request.course.id'};
4349: my $cdom = $env{'course.'.$cid.'.domain'};
4350: my $cnum = $env{'course.'.$cid.'.num'};
4351: my $output;
1.39 raeburn 4352: my %lt = &Apache::lonlocal::texthash (
4353: 'all' => 'all',
4354: 'section/group' => 'section/group',
4355: 'user' => 'user',
4356: );
1.49.2.14 raeburn 4357: &Apache::lonrelrequtils::init_global_hashes();
4358: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4359: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4360: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.49.2.14 raeburn 4361: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4362: }
4363: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.49.2.14 raeburn 4364: %byresponsetype,%bysubmission,%fromblocks);
1.39 raeburn 4365: @scopeorder = ('all','section/group','user');
1.49.2.15 raeburn 4366: my $now = time;
1.36 raeburn 4367: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4368: if (ref($resourcedata) eq 'HASH') {
4369: foreach my $key (keys(%{$resourcedata})) {
1.49.2.14 raeburn 4370: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4371: if ($key =~ /(\Q$item\E)$/) {
1.49.2.14 raeburn 4372: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
1.36 raeburn 4373: my $value = $resourcedata->{$key};
1.49.2.9 raeburn 4374: if ($item eq 'examcode') {
4375: if (&Apache::lonnet::validCODE($value)) {
4376: $value = 'valid';
4377: } else {
4378: $value = '';
4379: }
1.49.2.15 raeburn 4380: } elsif ($item eq 'printstartdate') {
4381: if ($value =~ /^\d+$/) {
4382: if ($value > $now) {
4383: $value = 'future';
4384: }
4385: }
4386: } elsif ($item eq 'printenddate') {
4387: if ($value =~ /^\d+$/) {
4388: if ($value < $now) {
4389: $value = 'past';
4390: }
4391: }
4392:
1.49.2.9 raeburn 4393: }
1.36 raeburn 4394: my ($middle,$scope,$which,$level,$map,$resource);
1.49.2.14 raeburn 4395: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
1.36 raeburn 4396: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4397: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4398: my $valname = &get_param_description($stdtype,$value);
4399: my $rev = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value};
4400: my $start = $cid.'.';
4401: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4402: $middle = $1;
4403: $which = $2;
4404: $scope = 'user';
4405: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4406: $middle = $1;
4407: $which = $2;
4408: $scope = 'section/group';
4409: } else {
1.39 raeburn 4410: $scope = 'all';
1.36 raeburn 4411: }
4412: my $what="$stdname=$valname";
4413: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4414: $level = 'general';
1.39 raeburn 4415: if ($scope eq 'all') {
1.36 raeburn 4416: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4417: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4418: push(@{$fromparam{$rev}{$scope}},$what);
4419: }
4420: } else {
4421: push(@{$fromparam{$rev}{$scope}},$what);
4422: }
4423: } else {
4424: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4425: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4426: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4427: }
4428: } else {
4429: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4430: }
4431: }
4432: $rowspan{$rev} ++;
4433: } elsif ($key =~ /^\Q$start$middle\E(.+)___\(all\).\w+\.\Q$item\E$/) {
4434: $level = 'folder';
4435: $map = $1;
1.39 raeburn 4436: if ($scope eq 'all') {
1.36 raeburn 4437: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4438: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4439: push(@{$bymap{$map}{$rev}{$scope}},$what);
4440: }
4441: } else {
4442: push(@{$bymap{$map}{$rev}{$scope}},$what);
4443: }
4444: } else {
4445: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4446: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4447: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4448: }
4449: } else {
4450: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4451: }
4452: }
4453: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4454: $level = 'resource';
4455: $resource = $1;
1.39 raeburn 4456: if ($scope eq 'all') {
1.36 raeburn 4457: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4458: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4459: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4460: }
4461: } else {
4462: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4463: }
4464: } else {
4465: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4466: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4467: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4468: }
4469: } else {
4470: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4471: }
4472: }
4473: }
4474: }
4475: }
4476: }
4477: }
4478: }
4479: if (keys(%fromparam)) {
4480: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4481: &Apache::loncommon::start_data_table().
4482: &Apache::loncommon::start_data_table_header_row().
4483: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4484: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4485: &Apache::loncommon::end_data_table_header_row();
4486: foreach my $rev (keys(%fromparam)) {
1.49.2.14 raeburn 4487: my ($major,$minor) = split(/\./,$rev);
4488: ($reqdmajor,$reqdminor) =
4489: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4490: $output .= &Apache::loncommon::start_data_table_row().
4491: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4492: my $newrow;
4493: foreach my $scope (@scopeorder) {
4494: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4495: if ($newrow) {
4496: $output .= &Apache::loncommon::continue_data_table_row();
4497: }
1.39 raeburn 4498: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4499: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4500: $output .= '<td>'.$which.'</td><td>'.
4501: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4502: }
4503: $output .= &Apache::loncommon::end_data_table_row();
4504: $newrow = 1;
4505: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4506: if ($newrow) {
4507: $output .= &Apache::loncommon::continue_data_table_row();
4508: }
1.39 raeburn 4509: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4510: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4511: &Apache::loncommon::end_data_table_row();
4512: $newrow = 1;
4513: }
4514: }
4515: }
4516: $output .= &Apache::loncommon::end_data_table().'<br />';
4517: }
4518: }
4519:
1.49.2.14 raeburn 4520: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4521: my $now = time;
4522: if (keys(%comm_blocks) > 0) {
4523: foreach my $block (keys(%comm_blocks)) {
4524: if ($block =~ /^firstaccess____(.+)$/) {
4525: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
4526: if (ref($comm_blocks{$block}) eq 'HASH') {
4527: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4528: ' '.&mt('set by [_1]',
4529: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4530: }
4531: next;
4532: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4533: my ($start,$end) = ($1,$2);
4534: next if ($end < $now);
4535: }
4536: if (ref($comm_blocks{$block}) eq 'HASH') {
4537: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4538: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4539: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
4540: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
4541: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4542: ' '.
4543: &mt('set by [_1]',
4544: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4545: }
4546: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
4547: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
4548: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4549: ' '.
4550: &mt('set by [_1]',
4551: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4552:
4553: }
4554: }
4555: }
4556: }
4557: if (keys(%fromblocks)) {
4558: my %lt = (
4559: docs => 'Content blocking',
4560: printout => 'Printout generation',
4561: timer => 'Timed quiz trigger',
4562: );
4563: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4564: &Apache::loncommon::start_data_table().
4565: &Apache::loncommon::start_data_table_header_row().
4566: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4567: '<th>'.&mt('Event(s)').'</th>'.
4568: &Apache::loncommon::end_data_table_header_row();
4569: foreach my $type ('docs','printout','timer') {
4570: if (ref($fromblocks{$type}) eq 'HASH') {
4571: foreach my $rev (keys(%{$fromblocks{$type}})) {
4572: my ($major,$minor) = split(/\./,$rev);
4573: ($reqdmajor,$reqdminor) =
4574: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4575: $output .= &Apache::loncommon::start_data_table_row().
4576: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4577: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4578: $output .= $event.'<br />';
4579: }
4580: $output =~ s{\Q<br />\E$}{};
4581: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4582: }
4583: }
4584: }
4585: $output .= &Apache::loncommon::end_data_table().'<br />';
4586: }
4587: }
4588:
1.36 raeburn 4589: if (defined($navmap)) {
4590: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
4591: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'};
4592: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
4593: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry'};
4594: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4595: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4596: my $valanon=&get_param_description($stdtype,'anonsurvey');
4597: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.49.2.14 raeburn 4598: my %checkedrev;
1.36 raeburn 4599: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
4600: my @parts = @{$res->parts()};
4601: my $symb = $res->symb();
4602: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
4603: foreach my $part (@parts) {
4604: if (exists($anonsubms{$symb."\0".$part})) {
4605: my $rev = $rev_anonsurv;
4606: my $what="$stdname=$valanon";
4607: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4608: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4609: push(@{$bysubmission{$symb}{$rev}},$what);
4610: }
4611: } else {
4612: push(@{$bysubmission{$symb}{$rev}},$what);
4613: }
4614: $allmaps{$enclosing_map} = 1;
1.49.2.14 raeburn 4615: unless ($checkedrev{'anonsurvey'}) {
4616: my ($major,$minor) = split(/\./,$rev);
4617: ($reqdmajor,$reqdminor) =
4618: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4619: $reqdmajor,$reqdminor);
4620: $checkedrev{'anonsurvey'} = 1;
4621: }
1.36 raeburn 4622: }
4623: if (exists($randtrysubms{$symb."\0".$part})) {
4624: my $rev = $rev_randtry;
4625: my $what="$stdname=$valrandtry";
4626: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4627: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4628: push(@{$bysubmission{$symb}{$rev}},$what);
4629: }
4630: } else {
4631: push(@{$bysubmission{$symb}{$rev}},$what);
4632: }
4633: $allmaps{$enclosing_map} = 1;
1.49.2.14 raeburn 4634: unless ($checkedrev{'randomizetry'}) {
4635: my ($major,$minor) = split(/\./,$rev);
4636: ($reqdmajor,$reqdminor) =
4637: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4638: $reqdmajor,$reqdminor);
4639: $checkedrev{'randomizetry'} = 1;
4640: }
1.36 raeburn 4641: }
4642: }
4643: my %responses = $res->responseTypes();
4644: foreach my $key (keys(%responses)) {
1.49.2.14 raeburn 4645: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4646: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4647: unless ($checkedrev{$key}) {
4648: my ($major,$minor) = split(/\./,$rev);
4649: ($reqdmajor,$reqdminor) =
4650: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4651: $reqdmajor,$reqdminor);
4652: $checkedrev{$key} = 1;
4653: }
4654: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4655: $allmaps{$enclosing_map} = 1;
4656: }
4657: }
4658: }
4659: if (keys(%byresource) > 0) {
4660: foreach my $symb (keys(%byresource)) {
4661: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4662: $allmaps{$map} = 1;
4663: }
4664: }
4665: if (keys(%bymap) > 0) {
4666: foreach my $map (keys(%bymap)) {
4667: $allmaps{$map} = 1;
4668: }
4669: }
4670: foreach my $map (keys(%allmaps)) {
4671: my $mapres = $navmap->getResourceByUrl($map);
4672: if (ref($mapres)) {
1.49.2.16 raeburn 4673: my $mapsymb = $mapres->symb();
4674: $toshow{$mapsymb} = 1;
1.36 raeburn 4675: my $pcslist = $mapres->map_hierarchy();
4676: if ($pcslist ne '') {
4677: foreach my $pc (split(/,/,$pcslist)) {
4678: my $res = $navmap->getByMapPc($pc);
4679: if (ref($res)) {
4680: my $symb = $res->symb();
4681: unless ($symb eq '______') {
4682: $toshow{$symb} = 1;
4683: }
4684: }
4685: }
4686: }
4687: }
4688: }
4689: }
4690: my $mapres_header = '<h4>'.
4691: &mt('Requirements for specific folders or resources').
4692: '</h4>';
4693: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4694: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4695: $output .= $mapres_header;
4696: }
4697: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4698: my $title = 'Version Constraints';
4699: my $start_page =
4700: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4701: $r->print($start_page.$top_header);
4702: if ($output) {
4703: $r->print($output);
4704: if (defined($navmap)) {
4705: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.39 raeburn 4706: \%byresponsetype,\@scopeorder,\%lt);
1.36 raeburn 4707: }
4708: $r->print('<br /><br />');
4709: } else {
4710: $r->print('<p class="LC_info">'.
4711: &mt('No version requirements from resource content or settings.').
4712: '</p>');
4713: }
4714: $r->print(&Apache::loncommon::end_page());
1.49.2.14 raeburn 4715: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4716: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4717: return 1;
4718: }
1.36 raeburn 4719: return;
4720: }
4721:
4722: sub show_contents_view {
1.39 raeburn 4723: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
4724: $scopeorder,$lt) = @_;
1.36 raeburn 4725: if ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4726: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0)) {
4727: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4728: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4729: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4730: my $topmap = $env{'course.'.$cid.'.url'};
4731: $r->print(&Apache::loncommon::start_data_table().
4732: &Apache::loncommon::start_data_table_header_row().
4733: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4734: '<th>'.&mt('Attribute/Setting').'</th>'.
4735: &Apache::loncommon::end_data_table_header_row().
4736: &Apache::loncommon::start_data_table_row().
1.49.2.8 raeburn 4737: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.39 raeburn 4738: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
1.36 raeburn 4739: $r->print(&Apache::loncommon::end_data_table_row());
4740: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4741: my $curRes;
4742: my $depth = 0;
4743: my %parent = ();
4744: my $startcount = 5;
4745: my $lastcontainer = $startcount;
4746: while ($curRes = $it->next()) {
4747: if ($curRes == $it->BEGIN_MAP()) {
4748: $depth++;
4749: $parent{$depth}= $lastcontainer;
4750: }
4751: if ($curRes == $it->END_MAP()) {
4752: $depth--;
4753: $lastcontainer = $parent{$depth};
4754: }
4755: my $indent;
4756: for (my $i=0; $i<$depth; $i++) {
4757: $indent.= $whitespace;
4758: }
4759: if (ref($curRes)) {
4760: my $symb = $curRes->symb();
4761: my $ressymb = $symb;
4762: my $srcf = $curRes->src();
4763: my $title = &Apache::lonnet::gettitle($srcf);
4764: if (($curRes->is_sequence()) || ($curRes->is_page())) {
4765: next unless($toshow->{$symb});
4766: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
4767: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4768: if ($curRes->is_page()) {
4769: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
4770: }
4771: my $rowspan = 1;
4772: if (ref($bymap->{$url}) eq 'HASH') {
4773: $rowspan = scalar(keys(%{$bymap->{$url}}));
4774: }
4775: $r->print(&Apache::loncommon::start_data_table_row().
4776: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 4777: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 4778: $r->print(&Apache::loncommon::end_data_table_row());
4779: } else {
4780: my $rowspan;
4781: if (ref($byresource->{$symb}) eq 'HASH') {
4782: $rowspan += scalar(keys(%{$byresource->{$symb}}));
4783: }
4784: if (ref($bysubmission->{$symb}) eq 'HASH') {
4785: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
4786: }
4787: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4788: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
4789: }
4790: next if (!$rowspan);
4791: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
4792: &mt('Problem').'" />';
4793: $r->print(&Apache::loncommon::start_data_table_row().
4794: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
4795: my $newrow;
4796: if (ref($byresource->{$symb}) eq 'HASH') {
4797: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
4798: if ($newrow) {
4799: $r->print(&Apache::loncommon::continue_data_table_row());
4800: }
4801: $r->print('<td valign="middle">'.$rev.'</td><td>');
4802: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
4803: $r->print('<table border="0">');
4804: foreach my $scope (@{$scopeorder}) {
4805: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4806: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4807: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
4808: $r->print('<td>'.$which.'</td><td>'.
4809: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
4810: '</td>');
4811: }
4812: $r->print('</tr>');
4813: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4814: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 4815: '<td> </td><td>'.
4816: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
4817: }
4818: }
4819: $r->print('</table>');
4820: }
4821: $r->print('</td>');
4822: $r->print(&Apache::loncommon::end_data_table_row());
4823: $newrow = 1;
4824: }
4825: }
4826: if (ref($bysubmission->{$symb}) eq 'HASH') {
4827: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
4828: if ($newrow) {
4829: $r->print(&Apache::loncommon::continue_data_table_row());
4830: }
4831: $r->print('<td>'.$rev.'</td><td>');
4832: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
4833: $r->print(&mt('Submissions to: ').' '.
4834: join(', ',@{$bysubmission->{$symb}{$rev}}));
4835: }
4836: $r->print('</td>');
4837: $r->print(&Apache::loncommon::end_data_table_row());
4838: $newrow = 1;
4839: }
4840: }
4841: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4842: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
4843: if ($newrow) {
4844: $r->print(&Apache::loncommon::continue_data_table_row());
4845: }
4846: $r->print('<td>'.$rev.'</td><td>');
4847: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
4848: $r->print(&mt('Response Type(s): ').' '.
4849: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
4850: }
4851: $r->print('</td>');
4852: }
4853: $r->print(&Apache::loncommon::end_data_table_row());
4854: }
4855: }
4856: }
4857: }
4858: $r->print(&Apache::loncommon::end_data_table());
4859: }
1.49.2.14 raeburn 4860: return;
1.36 raeburn 4861: }
4862:
4863: sub releases_by_map {
1.39 raeburn 4864: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 4865: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.49.2.19 raeburn 4866: my $newrow = 0;
1.36 raeburn 4867: if (ref($bymap->{$url}) eq 'HASH') {
4868: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.49.2.19 raeburn 4869: if ($newrow) {
4870: $r->print(&Apache::loncommon::end_data_table_row().
4871: &Apache::loncommon::continue_data_table_row());
4872: }
1.36 raeburn 4873: $r->print('<td valign="middle">'.$rev.'</td><td>');
4874: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
4875: $r->print('<table border="0">');
4876: foreach my $scope (@{$scopeorder}) {
4877: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4878: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4879: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
4880: $r->print('<td>'.$which.'</td><td>'.
4881: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
4882: '</td>');
4883: }
4884: $r->print('</tr>');
4885: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4886: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 4887: '</td><td> </td><td>'.
4888: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
4889: }
4890: }
4891: $r->print('</table>');
4892: }
4893: $r->print('</td>');
1.49.2.19 raeburn 4894: $newrow = 1;
1.36 raeburn 4895: }
4896: } else {
4897: $r->print('<td colspan="2"> </td>');
4898: }
4899: return;
4900: }
4901:
4902: sub get_param_description {
4903: my ($stdtype,$value) = @_;
4904: my $name = $value;
4905: my $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
4906: unless (ref($paramstrings) eq 'ARRAY') {
4907: return $name;
4908: }
4909: foreach my $possibilities (@{$paramstrings}) {
4910: next unless (ref($possibilities) eq 'ARRAY');
4911: my ($thing, $description) = @{ $possibilities };
4912: if ($thing eq $value) {
4913: $name = $description;
4914: last;
4915: }
4916: }
4917: return $name;
4918: }
4919:
1.49.2.14 raeburn 4920: sub update_releasereq {
4921: my $readmap = 1;
4922: my $getrelreq = 1;
4923: if (ref($modified_courses) eq 'ARRAY') {
4924: foreach my $item (@{$modified_courses}) {
4925: if (ref($item) eq 'ARRAY') {
4926: my ($cdom,$cnum,$chome,$crstype) = @{$item};
4927: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
4928: $chome,$crstype,$cdom.'_'.$cnum,
4929: $readmap,$getrelreq);
4930: }
4931: }
4932: $modified_courses = [];
4933: }
4934: undef($registered_cleanup);
4935: return;
4936: }
4937:
1.25 raeburn 4938: sub show_autocoowners {
4939: my (@currcoown) = @_;
1.49.2.7 raeburn 4940: 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 4941: if (@currcoown > 0) {
4942: $output .= '<br />'.&mt('Current co-owners are:').' '.
4943: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
4944: } else {
4945: $output .= '<br />'.&mt('Currently no co-owners.');
4946: }
4947: return $output;
4948: }
4949:
4950: sub coowner_invitations {
1.49.2.21 raeburn 4951: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
4952: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 4953: my $pendingcoowners =
4954: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
4955: if ($pendingcoowners) {
4956: @pendingcoown = split(',',$pendingcoowners);
4957: }
1.49.2.21 raeburn 4958: if (ref($currcoownref) eq 'ARRAY') {
1.49.2.28.2.2 (raeburn 4959:: @currcoown = @{$currcoownref};
1.49.2.21 raeburn 4960: }
4961: my $disabled;
4962: if ($noedit) {
4963: $disabled = ' disabled="disabled"';
4964: }
1.25 raeburn 4965: my $ccrole = 'cc';
4966: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
4967: foreach my $key (sort(keys(%ccroles))) {
4968: my ($ccname,$ccdom,$role) = split(':',$key);
4969: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
4970: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
4971: push(@othercoords,$ccname.':'.$ccdom);
4972: }
4973: }
4974: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
4975: if ($coowner_rows) {
4976: $output .= &Apache::loncommon::start_data_table();
4977: if (@currcoown) {
4978: $output .= &Apache::loncommon::start_data_table_row().
4979: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
4980: foreach my $person (@currcoown) {
4981: my ($co_uname,$co_dom) = split(':',$person);
1.49.2.21 raeburn 4982: $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 4983: }
4984: $output .= '</td>'.
4985: &Apache::loncommon::end_data_table_row();
4986: }
4987: if ($pendingcoowners) {
4988: $output .= &Apache::loncommon::start_data_table_row().
4989: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
4990: foreach my $person (@pendingcoown) {
4991: my ($co_uname,$co_dom) = split(':',$person);
1.49.2.21 raeburn 4992: $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 4993: }
4994: $output .= '</td>'.
4995: &Apache::loncommon::end_data_table_row();
4996: }
4997: if (@othercoords) {
4998: $output .= &Apache::loncommon::start_data_table_row().
4999: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5000: foreach my $person (@othercoords) {
5001: my ($co_uname,$co_dom) = split(':',$person);
1.49.2.21 raeburn 5002: $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 5003: }
5004: $output .= '</td>'.
5005: &Apache::loncommon::end_data_table_row();
5006: }
5007: $output .= &Apache::loncommon::end_data_table();
5008: } else {
5009: $output = &mt('There are no coordinators to select as co-owners');
5010: }
5011: return $output;
5012: }
5013:
5014: sub manage_coownership {
1.49.2.21 raeburn 5015: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5016: my (@pendingcoown,@currcoown);
1.25 raeburn 5017: my $pendingcoowners =
5018: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5019: if ($pendingcoowners) {
5020: @pendingcoown = split(',',$pendingcoowners);
5021: }
1.49.2.21 raeburn 5022: if (ref($currcoownref) eq 'ARRAY') {
1.49.2.28.2.2 (raeburn 5023:: @currcoown = @{$currcoownref};
1.49.2.21 raeburn 5024: }
5025: my $disabled;
5026: if ($noedit) {
5027: $disabled = ' disabled="disabled"';
5028: }
1.25 raeburn 5029: my ($is_coowner,$is_pending,$output);
5030: my $uname = $env{'user.name'};
5031: my $udom = $env{'user.domain'};
5032: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5033: $is_coowner = 1;
5034: }
5035: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5036: $is_pending = 1;
5037: }
5038: if (@currcoown && ($is_coowner || $is_pending)) {
5039: $output = &Apache::loncommon::start_data_table();
5040: }
5041: if (@currcoown) {
5042: if ($is_coowner || $is_pending) {
5043: $output .= &Apache::loncommon::start_data_table().
5044: &Apache::loncommon::start_data_table_row().'<td>';
5045: }
5046: $output .= &mt('Current co-owners are:').' '.
5047: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5048: if ($is_coowner || $is_pending) {
5049: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5050: }
5051: }
5052: if ($is_coowner || $is_pending) {
5053: if (@currcoown) {
5054: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5055: }
5056: $output .= '<span class="LC_nobreak">';
5057: if ($is_coowner) {
1.49.2.26 raeburn 5058: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5059: } else {
1.49.2.26 raeburn 5060: $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).
5061: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5062: }
5063: $output .= '</span>';
5064: if (@currcoown) {
5065: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5066: }
5067: }
5068: if (@currcoown && ($is_coowner || $is_pending)) {
5069: $output .= &Apache::loncommon::end_data_table();
5070: }
5071: return $output;
5072: }
5073:
1.1 raeburn 5074: sub print_localization {
1.49.2.21 raeburn 5075: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5076: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5077: return;
5078: }
5079: my %items = (
5080: languages => {
1.17 faziophi 5081: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5082: &mt("(overrides individual user preference)"),
1.1 raeburn 5083: input => 'selectbox',
5084: },
5085: timezone => {
1.17 faziophi 5086: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5087: input => 'selectbox',
5088: },
5089: datelocale => {
1.17 faziophi 5090: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5091: input => 'selectbox',
5092: },
5093: );
1.49.2.21 raeburn 5094: my ($datatable,$disabled);
1.1 raeburn 5095: my $count = 0;
1.49.2.21 raeburn 5096: if ($noedit) {
5097: $disabled = ' disabled="disabled"';
5098: }
1.1 raeburn 5099: foreach my $item (@{$ordered}) {
5100: $count ++;
1.49.2.7 raeburn 5101: my $colspan;
5102: unless ($item eq 'languages') {
5103: $colspan = 2;
5104: }
5105: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5106: if ($item eq 'timezone') {
5107: my $includeempty = 1;
5108: my $timezone = &Apache::lonlocal::gettimezone();
1.49.2.28.2.1 (raeburn 5109:): my $onchange;
5110:): unless ($noedit) {
5111:): $onchange = ' onchange="javascript:toggleTimeZone();"';
5112:): }
5113:): my $id = ' id="LC_set_timezone"';
1.1 raeburn 5114: $datatable .=
1.49.2.28.2.1 (raeburn 5115:): &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5116:): $includeempty,$id,$disabled);
5117:): my $tzsty = 'none';
5118:): if ($timezone ne '') {
5119:): $tzsty = 'block';
5120:): }
5121:): $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5122:): '<span class="LC_nobreak">'.
5123:): &mt('Override individual user preference?').
5124:): &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5125:): '</span></div>';
1.1 raeburn 5126: } elsif ($item eq 'datelocale') {
5127: my $includeempty = 1;
5128: my $locale_obj = &Apache::lonlocal::getdatelocale();
5129: my $currdatelocale;
5130: if (ref($locale_obj)) {
5131: $currdatelocale = $locale_obj->id();
5132: }
5133: $datatable .=
5134: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.49.2.21 raeburn 5135: undef,$includeempty,$disabled);
1.1 raeburn 5136: } else {
5137: if ($settings->{$item} eq '') {
1.49.2.21 raeburn 5138: unless ($noedit) {
5139: $datatable .= '</td><td align="right">'.
5140: &Apache::loncommon::select_language('languages_0','',1);
5141: }
1.1 raeburn 5142: } else {
5143: my $num = 0;
1.3 raeburn 5144: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.49.2.7 raeburn 5145: $datatable .= '</td><td align="right"><br />'.
5146: &Apache::loncommon::start_data_table();
1.1 raeburn 5147: if (@languages > 0) {
1.3 raeburn 5148: my %langchoices = &get_lang_choices();
1.1 raeburn 5149: foreach my $lang (@languages) {
5150: my $showlang = $lang;
1.3 raeburn 5151: if (exists($langchoices{$lang})) {
5152: $showlang = $langchoices{$lang};
1.1 raeburn 5153: }
5154: $datatable .=
5155: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5156: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5157: &mt('Language:').'<b> '.$showlang.
5158: '</b><input type="hidden" name="languages_'.$num.
5159: '" value="'.$lang.'" /></span><br />'.
5160: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.49.2.21 raeburn 5161: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5162: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5163: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5164: $num ++;
5165: }
5166: }
1.49.2.21 raeburn 5167: unless ($noedit) {
1.49.2.28.2.1 (raeburn 5168:): $datatable .=
1.49.2.21 raeburn 5169: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5170: '<td align="left"><span class="LC_nobreak">'.
5171: &mt('Additional language:'). '</span><br />'.
5172: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5173: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.49.2.21 raeburn 5174: '</td>'.&Apache::loncommon::end_data_table_row();
5175: }
5176: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5177: }
5178: }
5179: $datatable .= &item_table_row_end();
5180: }
5181: $$rowtotal += scalar(@{$ordered});
5182: return $datatable;
5183: }
5184:
1.3 raeburn 5185: sub get_lang_choices {
5186: my %langchoices;
5187: foreach my $id (&Apache::loncommon::languageids()) {
5188: my $code = &Apache::loncommon::supportedlanguagecode($id);
5189: if ($code) {
5190: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5191: }
5192: }
5193: return %langchoices;
5194: }
5195:
1.1 raeburn 5196: sub print_feedback {
1.49.2.21 raeburn 5197: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5198: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5199: return;
5200: }
5201: my %items = (
1.3 raeburn 5202: 'question.email' => {
5203: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5204: input => 'textbox',
5205: size => '50',
5206: },
5207:
1.3 raeburn 5208: 'comment.email' => {
5209: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5210: input => 'textbox',
5211: size => '50',
5212: },
5213:
1.3 raeburn 5214: 'policy.email' => {
5215: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5216: input => 'textbox',
5217: size => '50',
5218: },
5219: );
5220: my $datatable;
5221: my $count = 0;
5222: my ($cnum) = &get_course();
5223: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5224: my @sections = sort( { $a <=> $b } keys(%sections));
5225: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5226: currone => 'Current recipient:',
5227: currmult => 'Current recipients:',
5228: add => 'Additional recipient:',
5229: del => 'Delete?',
5230: sec => 'Sections:',
1.1 raeburn 5231: );
1.49.2.21 raeburn 5232: my $disabled;
5233: if ($noedit) {
5234: $disabled = ' disabled="disabled"';
5235: }
1.1 raeburn 5236: foreach my $item (@{$ordered}) {
5237: $count ++;
1.20 faziophi 5238: if ($position eq 'top') {
5239: $datatable .= &item_table_row_start($items{$item}{text},$count);
5240: } else {
1.49.2.7 raeburn 5241: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5242: }
1.1 raeburn 5243: if ($position eq 'top') {
5244: my $includeempty = 0;
1.49.2.7 raeburn 5245: $datatable .= '</td><td align="right">'.
5246: &user_table($cdom,$item,\@sections,
1.49.2.21 raeburn 5247: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5248: } else {
1.3 raeburn 5249: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.49.2.21 raeburn 5250: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5251: }
5252: $datatable .= &item_table_row_end();
5253: }
5254: $$rowtotal += scalar(@{$ordered});
5255: return $datatable;
5256: }
5257:
5258: sub user_table {
1.49.2.21 raeburn 5259: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5260: my $output;
5261: if ($currvalue eq '') {
1.49.2.21 raeburn 5262: unless ($noedit) {
5263: $output .= &select_recipient($item,'0',$cdom,$sections);
1.49.2.28.2.1 (raeburn 5264:): }
1.1 raeburn 5265: } else {
5266: my $num = 0;
5267: my @curr = split(/,/,$currvalue);
1.49.2.7 raeburn 5268: $output .= '<table class="LC_data_table">';
1.1 raeburn 5269: my ($currusers);
1.49.2.21 raeburn 5270: my $disabled;
5271: if ($noedit) {
5272: $disabled = ' disabled="disabled"';
5273: }
1.1 raeburn 5274: foreach my $val (@curr) {
5275: next if ($val eq '');
5276: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5277: my @selsec;
5278: if ($seclist) {
5279: $seclist =~ s/(^\(|\)$)//g;
5280: @selsec = split(/\s*;\s*/,$seclist);
5281: }
5282: $currusers .= '<tr>'.
5283: '<td valign="top"><span class="LC_nobreak">'.
5284: '<label><input type="checkbox" '.
1.49.2.21 raeburn 5285: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5286: $lt->{'del'}.'</label>'.
5287: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5288: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5289: &Apache::loncommon::aboutmewrapper(
5290: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5291: $uname,$udom,'aboutuser');
5292: if (ref($sections) eq 'ARRAY') {
5293: if (@{$sections}) {
5294: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5295: &select_sections($item,$num,$sections,
1.49.2.21 raeburn 5296: \@selsec,$noedit);
1.1 raeburn 5297: }
5298: }
5299: $currusers .= '</span></td></tr>';
5300: $num ++;
5301: }
5302: if ($num) {
1.10 raeburn 5303: $output .= '<tr>'.
1.1 raeburn 5304: '<td align="left"><i>';
1.20 faziophi 5305: if ($num == 1) {
1.1 raeburn 5306: $output .= $lt->{'currone'};
5307: } else {
1.21 raeburn 5308: $output .= $lt->{'currmult'};
1.1 raeburn 5309: }
5310: $output .= '</i><br />'.
5311: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5312: '</tr>';
1.1 raeburn 5313: }
1.49.2.21 raeburn 5314: unless ($noedit) {
5315: $output .=
5316: '<tr>'.
1.1 raeburn 5317: '<td align="left"><span class="LC_nobreak"><i>'.
5318: $lt->{'add'}.'</i></span><br />'.
5319: &select_recipient($item,$num,$cdom,$sections).
5320: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.49.2.21 raeburn 5321: '</td></tr>';
5322: }
5323: $output .= '</table>';
1.1 raeburn 5324: }
5325: return $output;
5326: }
5327:
5328: sub select_recipient {
5329: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5330: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5331: my $selectlink =
5332: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.49.2.25 raeburn 5333: $item.'_udom_'.$num,'only');
1.1 raeburn 5334: my $output =
1.10 raeburn 5335: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5336: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5337: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5338: if (ref($sections) eq 'ARRAY') {
5339: if (@{$sections}) {
5340: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5341: &select_sections($item,$num,$sections,$selected).'</td>';
5342: }
5343: }
5344: $output .= '<td valign="top">'.
5345: $selectlink.'</td></tr></table>';
5346: return $output;
5347: }
5348:
5349: sub select_sections {
1.49.2.21 raeburn 5350: my ($item,$num,$sections,$selected,$noedit) = @_;
5351: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5352: if (ref($selected) eq 'ARRAY') {
5353: @currsecs = @{$selected};
5354: }
5355: if (!@currsecs) {
5356: $allsec = ' selected="selected"';
5357: }
1.49.2.21 raeburn 5358: if ($noedit) {
5359: $disabled = ' disabled="disabled"';
5360: }
1.1 raeburn 5361: if (ref($sections) eq 'ARRAY') {
5362: if (@{$sections}) {
5363: my $mult;
5364: if (@{$sections} > 1) {
5365: $mult = ' multiple="multiple"';
5366: if (@{$sections} > 3) {
5367: $mult .= ' size="4"';
5368: }
5369: }
1.49.2.21 raeburn 5370: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
1.1 raeburn 5371: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
5372: foreach my $sec (@{$sections}) {
5373: my $is_sel;
5374: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
5375: $is_sel = 'selected="selected"';
5376: }
5377: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5378: }
5379: $output .= '</select>';
5380: }
5381: }
5382: return $output;
5383: }
5384:
5385: sub print_discussion {
1.49.2.21 raeburn 5386: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5387: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5388: return;
5389: }
5390: my %items = (
5391: 'plc.roles.denied' => {
1.10 raeburn 5392: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5393: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5394: &mt('(role-based)'),
1.1 raeburn 5395: input => 'checkbox',
5396: },
5397:
5398: 'plc.users.denied' => {
1.3 raeburn 5399: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5400: &mt('(specific user(s))'),
1.1 raeburn 5401: input => 'checkbox',
5402: },
5403:
5404: 'pch.roles.denied' => {
1.10 raeburn 5405: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5406: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5407: &mt('(role-based)'),
1.1 raeburn 5408: input => 'checkbox',
5409: },
5410:
5411: 'pch.users.denied' => {
1.3 raeburn 5412: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5413: &mt('(specific user(s))'),
1.1 raeburn 5414: input => 'checkbox',
5415: },
5416: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5417: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5418: input => 'radio',
5419: },
5420:
5421: 'allow_discussion_post_editing' => {
1.3 raeburn 5422: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5423: input => 'checkbox',
5424: },
1.49.2.3 raeburn 5425: 'discussion_post_fonts' => {
5426: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5427: input => 'textbox',
5428: size => '20',
5429: },
1.1 raeburn 5430: );
5431: my $datatable;
5432: my $count;
5433: my ($cnum) = &get_course();
5434: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5435: my @sections = sort( { $a <=> $b } keys(%sections));
5436: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5437: currone => 'Disallowed:',
5438: currmult => 'Disallowed:',
5439: add => 'Disallow more:',
5440: del => 'Delete?',
5441: sec => 'Sections:',
1.1 raeburn 5442: );
5443: foreach my $item (@{$ordered}) {
5444: $count ++;
1.49.2.7 raeburn 5445: my $colspan;
5446: if ($item eq 'allow_limited_html_in_feedback') {
5447: $colspan = 2;
5448: }
5449: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5450: if ($item eq 'plc.roles.denied') {
1.49.2.7 raeburn 5451: $datatable .= '</td><td align="right">'.
1.49.2.21 raeburn 5452: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5453: '</table>';
5454: } elsif ($item eq 'plc.users.denied') {
1.49.2.7 raeburn 5455: $datatable .= '</td><td align="right">'.
5456: &user_table($cdom,$item,undef,
1.49.2.21 raeburn 5457: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5458: } elsif ($item eq 'pch.roles.denied') {
1.49.2.7 raeburn 5459: $datatable .= '</td><td align="right">'.
1.49.2.21 raeburn 5460: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5461: '</table>';
5462: } elsif ($item eq 'pch.users.denied') {
1.49.2.7 raeburn 5463: $datatable .= '</td><td align="right">'.
5464: &user_table($cdom,$item,undef,
1.49.2.21 raeburn 5465: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5466: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.49.2.21 raeburn 5467: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5468: } elsif ($item eq 'allow_discussion_post_editing') {
1.49.2.7 raeburn 5469: $datatable .= '</td><td align="right"><br />'.
5470: &Apache::loncommon::start_data_table().
1.1 raeburn 5471: &Apache::loncommon::start_data_table_row().
5472: '<th align="left">'.&mt('Role').'</th><th>'.
5473: &mt('Sections').'</th>'.
5474: &Apache::loncommon::end_data_table_row().
1.49.2.21 raeburn 5475: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.49.2.7 raeburn 5476: &Apache::loncommon::end_data_table().'<br />';
1.49.2.3 raeburn 5477: } elsif ($item eq 'discussion_post_fonts') {
1.49.2.7 raeburn 5478: $datatable .= '</td><td align="right"><br />'.
5479: &Apache::loncommon::start_data_table().
1.49.2.3 raeburn 5480: &Apache::loncommon::start_data_table_row().
5481: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5482: '<th align="center">'.&mt('font-size').'</th>'.
5483: '<th align="center">'.&mt('font-weight').'</th>'.
5484: '<th align="center">'.&mt('font-style').'</th>'.
5485: '<th align="center">'.&mt('Other css').'</th>'.
5486: &Apache::loncommon::end_data_table_row().
1.49.2.21 raeburn 5487: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.49.2.7 raeburn 5488: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5489: }
5490: $datatable .= &item_table_row_end();
5491: }
5492: $$rowtotal += scalar(@{$ordered});
5493: return $datatable;
5494: }
5495:
5496: sub role_checkboxes {
1.49.2.21 raeburn 5497: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5498: my @roles = ('st','ad','ta','ep','in');
5499: if ($crstype eq 'Community') {
5500: push(@roles,'co');
5501: } else {
5502: push(@roles,'cc');
5503: }
1.1 raeburn 5504: my $output;
5505: my (@current,@curr_roles,%currsec,@sections);
5506: if ($showsections) {
5507: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5508: @sections = sort( { $a <=> $b } keys(%sections));
5509: }
5510: if (ref($settings) eq 'HASH') {
5511: if ($settings->{$item}) {
5512: @current = split(',',$settings->{$item});
5513: if ($showsections) {
5514: foreach my $role (@current) {
5515: if ($role =~ /:/) {
5516: my ($trole,$sec) = split(':',$role);
5517: push(@curr_roles,$trole);
5518: if (ref($currsec{$trole}) eq 'ARRAY') {
5519: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5520: push(@{$currsec{$trole}},$sec);
5521: }
1.3 raeburn 5522: } else {
5523: $currsec{$trole} = [$sec];
1.1 raeburn 5524: }
5525: } else {
5526: push(@curr_roles,$role);
5527: }
5528: }
5529: @current = @curr_roles;
5530: }
5531: }
5532: }
5533: my $numinrow = 3;
5534: my $count = 0;
1.49.2.21 raeburn 5535: my $disabled;
5536: if ($noedit) {
5537: $disabled = ' disabled="disabled"';
5538: }
1.1 raeburn 5539: foreach my $role (@roles) {
5540: my $checked = '';
5541: if (grep(/^\Q$role\E$/,@current)) {
5542: $checked = ' checked="checked" ';
5543: }
1.9 raeburn 5544: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5545: if ($showsections) {
5546: $output .= &Apache::loncommon::start_data_table_row();
5547: } else {
5548: my $rem = $count%($numinrow);
5549: if ($rem == 0) {
5550: if ($count > 0) {
5551: $output .= '</tr>';
5552: }
5553: $output .= '<tr>';
5554: }
5555: }
1.30 raeburn 5556: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.49.2.21 raeburn 5557: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5558: $plrole.'</label></span></td>';
5559: if ($showsections) {
5560: $output .= '<td align="left">'.
1.49.2.21 raeburn 5561: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5562: '</td></tr>';
5563: }
5564: $count ++;
5565: }
5566: my %adv_roles =
5567: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5568: my $total = @roles;
5569: foreach my $role (sort(keys(%adv_roles))) {
5570: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5571: my $rolename = $3;
5572: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5573: my $checked = '';
5574: if (grep(/^\Q$value\E$/,@current)) {
5575: $checked = ' checked="checked" ';
5576: }
5577: if ($showsections) {
5578: $output .= &Apache::loncommon::start_data_table_row();
5579: } else {
5580: my $rem = $count%($numinrow);
5581: if ($rem == 0) {
5582: if ($count > 0) {
5583: $output .= '</tr>';
5584: }
5585: $output .= '<tr>';
5586: }
5587: }
1.30 raeburn 5588: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.49.2.21 raeburn 5589: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5590: '</label></span></td>';
5591: if ($showsections) {
5592: $output .= '<td>'.
1.49.2.21 raeburn 5593: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5594: '</td>'.&Apache::loncommon::end_data_table_row();
5595: }
5596: $total ++;
5597: $count ++;
5598: }
5599: }
5600: if (!$showsections) {
5601: my $rem = $total%($numinrow);
5602: my $colsleft = $numinrow - $rem;
5603: if ($colsleft > 1 ) {
5604: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5605: ' </td>';
5606: } elsif ($colsleft == 1) {
5607: $output .= '<td class="LC_left_item"> </td>';
5608: }
5609: $output .= '</tr>';
5610: }
5611: return $output;
5612: }
5613:
1.49.2.3 raeburn 5614: sub set_discussion_fonts {
1.49.2.21 raeburn 5615: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.49.2.3 raeburn 5616: my ($classorder,$classtitles) = &discussion_vote_classes();
5617: my ($styleorder,$styleitems) = &discussion_vote_styles();
5618: my $output;
5619: if (ref($classorder) eq 'ARRAY') {
1.49.2.21 raeburn 5620: my $disabled;
5621: if ($noedit) {
5622: $disabled = ' disabled="disabled"';
5623: }
1.49.2.3 raeburn 5624: foreach my $cat (@{$classorder}) {
5625: my %curr = ();
5626: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5627: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5628: $output .= &Apache::loncommon::start_data_table_row().
5629: '<td>'.$classtitles->{$cat}.'</td>';
5630: if (ref($styleorder) eq 'ARRAY') {
5631: foreach my $item (@{$styleorder}) {
5632: $output .= '<td><span class="LC_nobreak">';
5633: my $selitem = $item;
5634: if ($item eq 'size') {
5635: my ($currsize,$currunit);
5636: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5637: ($currsize,$currunit) = ($1,$2);
5638: $curr{'size'} = $currunit;
5639: }
1.49.2.21 raeburn 5640: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.49.2.3 raeburn 5641: ' ';
5642: $selitem = 'unit';
5643: }
5644: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.49.2.21 raeburn 5645: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.49.2.3 raeburn 5646: foreach my $val (@{$styleitems->{$item}}) {
5647: my $sel;
5648: if ($val eq $curr{$item}) {
5649: $sel = ' selected="selected"';
5650: }
5651: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
5652: }
5653: }
5654: }
5655: }
1.49.2.21 raeburn 5656: $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 5657: }
5658: $output .= &Apache::loncommon::end_data_table_row();
5659: }
5660: return $output;
5661: }
5662:
5663: sub discussion_vote_classes {
5664: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
5665: my %classtitles = &Apache::lonlocal::texthash(
5666: 'twoplus' => 'Two sigma above mean',
5667: 'oneplus' => 'One sigma above mean',
5668: 'zero' => 'Within one sigma of mean',
5669: 'oneminus' => 'One sigma below mean',
5670: 'twominus' => 'Two sigma below mean',
5671: );
5672: return ($classorder,\%classtitles);
5673: }
5674:
5675: sub discussion_vote_styles {
5676: my $styleorder = ['size','weight','style'];
5677: my $styleitems = {
5678: size => ['','px','%','xx-small','x-small','small','medium','large',
5679: 'x-large','xx-large','smaller','larger'],
5680: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
5681: '500','600','700','800','900'],
5682: style => ['','normal','italic','oblique'],
5683: };
5684: return ($styleorder,$styleitems);
5685: }
5686:
1.1 raeburn 5687: sub print_classlists {
1.49.2.21 raeburn 5688: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5689: my @ordered;
5690: if ($position eq 'top') {
5691: @ordered = ('default_enrollment_start_date',
5692: 'default_enrollment_end_date');
1.49.2.6 raeburn 5693: if ($crstype eq 'Course') {
5694: push(@ordered,'defaultcredits');
5695: }
1.1 raeburn 5696: } elsif ($position eq 'middle') {
1.49.2.7 raeburn 5697: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 5698: } else {
5699: @ordered = ('student_classlist_view',
1.26 raeburn 5700: 'student_classlist_opt_in',
5701: 'student_classlist_portfiles');
1.1 raeburn 5702: }
1.9 raeburn 5703: my %lt;
5704:
5705: if ($crstype eq 'Community') {
5706: %lt = &Apache::lonlocal::texthash (
5707: disabled => 'No viewable membership list',
5708: section => "Membership of viewer's section",
5709: all => 'List of all members',
5710: );
5711: } else {
5712: %lt = &Apache::lonlocal::texthash (
5713: disabled => 'No viewable classlist',
5714: section => "Classlist of viewer's section",
5715: all => 'Classlist of all students',
5716: );
5717: }
5718:
1.1 raeburn 5719: my %items = (
5720: 'default_enrollment_start_date' => {
1.3 raeburn 5721: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 5722: input => 'dates',
5723: },
5724: 'default_enrollment_end_date' => {
1.3 raeburn 5725: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 5726: input => 'dates',
5727: },
1.49.2.7 raeburn 5728: 'defaultcredits' => {
5729: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
5730: },
1.1 raeburn 5731:
5732: 'nothideprivileged' => {
1.3 raeburn 5733: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 5734: input => 'checkbox',
5735: },
5736:
1.49.2.7 raeburn 5737: 'checkforpriv' => {
5738: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
5739: input => 'selectbox',
5740: },
5741:
1.1 raeburn 5742: 'student_classlist_view' => {
1.3 raeburn 5743: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 5744: input => 'selectbox',
1.9 raeburn 5745: options => \%lt,
1.1 raeburn 5746: order => ['disabled','all','section'],
5747: },
1.26 raeburn 5748: 'student_classlist_opt_in' => {
5749: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 5750: input => 'radio',
5751: },
5752:
5753: 'student_classlist_portfiles' => {
1.3 raeburn 5754: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 5755: input => 'radio',
5756: },
5757: );
5758: unless (($settings->{'student_classlist_view'} eq 'all') ||
5759: ($settings->{'student_classlist_view'} eq 'section')) {
5760: $settings->{'student_classlist_view'} = 'disabled';
5761: }
1.49.2.21 raeburn 5762: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 5763: }
5764:
5765: sub print_appearance {
1.49.2.21 raeburn 5766: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5767: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5768: return;
5769: }
1.9 raeburn 5770: my $mathdef;
5771: if ($crstype eq 'Community') {
5772: $mathdef = &mt("None specified - use member's choice");
5773: } else {
5774: $mathdef = &mt("None specified - use student's choice");
5775: }
1.1 raeburn 5776: my %items = (
5777: 'default_xml_style' => {
1.3 raeburn 5778: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 5779: '<a href="javascript:openbrowser'.
5780: "('display','default_xml_style'".
5781: ",'sty')".'">'.&mt('Select Style File').'</a>',
5782: input => 'textbox',
5783: size => 35,
5784: },
5785:
5786: 'pageseparators' => {
1.3 raeburn 5787: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 5788: input => 'radio',
5789: },
5790: 'disable_receipt_display' => {
1.3 raeburn 5791: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 5792: input => 'radio',
5793: },
5794: 'texengine' => {
1.3 raeburn 5795: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 5796: input => 'selectbox',
5797: options => {
1.49.2.11 raeburn 5798: MathJax => 'MathJax',
1.1 raeburn 5799: mimetex => &mt('Convert to Images'),
5800: tth => &mt('TeX to HTML'),
5801: },
1.49.2.20 raeburn 5802: order => ['MathJax','mimetex','tth'],
1.9 raeburn 5803: nullval => $mathdef,
1.1 raeburn 5804: },
5805: 'tthoptions' => {
1.3 raeburn 5806: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 5807: input => 'textbox',
5808: size => 40,
5809: },
1.49.2.17 raeburn 5810: 'uselcmath' => {
5811: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
5812: input => 'radio',
5813: },
5814: 'usejsme' => {
5815: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
5816: input => 'radio',
5817: },
1.49.2.28 raeburn 5818: 'inline_chem' => {
5819: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
5820: input => 'radio',
5821: },
1.49.2.28.2.1 (raeburn 5822:): 'extresource' => {
5823:): text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
5824:): input => 'selectbox',
5825:): options => {
5826:): iframe => 'In iframe',
5827:): tab => 'In new tab',
5828:): window => 'In pop-up window',
5829:): },
5830:): order => ['iframe','tab','window'],
5831:): },
1.1 raeburn 5832: );
1.49.2.21 raeburn 5833: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 5834: }
5835:
5836: sub print_grading {
1.49.2.21 raeburn 5837: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5838: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5839: return;
5840: }
5841: my %items = (
5842: 'grading' => {
1.3 raeburn 5843: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 5844: &Apache::loncommon::help_open_topic('GradingOptions'),
5845: input => 'selectbox',
5846: options => {
5847: standard => &mt('Standard: shows points'),
1.11 www 5848: external => &mt('External: shows number of completed parts and totals'),
5849: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 5850: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
5851: },
1.49.2.2 raeburn 5852: order => ['standard','external','externalnototals','spreadsheet'],
1.1 raeburn 5853: },
5854: 'rndseed' => {
1.3 raeburn 5855: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 5856: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 5857: &mt('Modifying this will make problems have different numbers and answers!').
5858: '</span>',
5859: input => 'selectbox',
5860: options => {
5861: '32bit' => '32bit',
5862: '64bit' => '64bit',
5863: '64bit2' => '64bit2',
5864: '64bit3' => '64bit3',
5865: '64bit4' => '64bit4',
5866: '64bit5' => '64bit5',
5867: },
5868: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 5869: advanced => 1
1.1 raeburn 5870: },
5871: 'receiptalg' => {
1.3 raeburn 5872: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 5873: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 5874: input => 'selectbox',
5875: options => {
5876: receipt => 'receipt',
5877: receipt2 => 'receipt2',
5878: receipt3 => 'receipt3',
5879: },
5880: order => ['receipt','receipt2','receipt3'],
1.41 www 5881: advanced => 1
1.1 raeburn 5882: },
5883: 'disablesigfigs' => {
1.3 raeburn 5884: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 5885: input => 'radio',
5886: },
5887: );
1.49.2.21 raeburn 5888: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
1.1 raeburn 5889: }
5890:
5891: sub print_printouts {
1.49.2.21 raeburn 5892: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5893: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5894: return;
5895: }
5896: my %items = (
5897: problem_stream_switch => {
1.3 raeburn 5898: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 5899: input => 'radio',
5900: },
5901: suppress_tries => {
1.3 raeburn 5902: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 5903: input => 'radio',
5904: },
5905: default_paper_size => {
1.3 raeburn 5906: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 5907: input => 'selectbox',
5908: options => {
5909: Letter => &mt('Letter').' [8 1/2x11 in]',
5910: Legal => &mt('Legal').' [8 1/2x14 in]',
5911: Tabloid => &mt('Tabloid').' [11x17 in]',
5912: Executive => &mt('Executive').' [7 1/2x10 in]',
5913: A2 => &mt('A2').' [420x594 mm]',
5914: A3 => &mt('A3').' [297x420 mm]',
5915: A4 => &mt('A4').' [210x297 mm]',
5916: A5 => &mt('A5').' [148x210 mm]',
5917: A6 => &mt('A6').' [105x148 mm]',
5918: },
5919: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.49.2.5 raeburn 5920: nullval => &mt('None specified'),
1.1 raeburn 5921: },
5922: print_header_format => {
1.3 raeburn 5923: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 5924: input => 'checkbox',
5925: },
5926: disableexampointprint => {
1.3 raeburn 5927: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 5928: input => 'radio',
5929: },
1.14 raeburn 5930: canuse_pdfforms => {
5931: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
5932: input => 'selectbox',
5933: options => {
5934: 1 => &mt('Yes'),
5935: 0 => &mt('No'),
5936: },
5937: order => ['1','0'],
1.49.2.5 raeburn 5938: nullval => &mt('None specified - use domain default'),
1.14 raeburn 5939: }
1.1 raeburn 5940: );
1.49.2.21 raeburn 5941: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 5942: }
5943:
5944: sub print_spreadsheet {
1.49.2.21 raeburn 5945: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5946: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5947: return;
5948: }
5949: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
5950: my %items = (
5951: spreadsheet_default_classcalc => {
1.3 raeburn 5952: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 5953: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
5954: "('display','spreadsheet_default_classcalc'".
5955: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
5956: input => 'textbox',
5957: },
5958: spreadsheet_default_studentcalc => {
1.3 raeburn 5959: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 5960: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
5961: "('display','spreadsheet_default_calc'".
5962: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
5963: input => 'textbox',
5964: },
5965: spreadsheet_default_assesscalc => {
1.3 raeburn 5966: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 5967: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
5968: "('display','spreadsheet_default_assesscalc'".
5969: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
5970: input => 'textbox',
5971: },
5972: hideemptyrows => {
1.3 raeburn 5973: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 5974: input => 'radio',
5975: },
5976: );
1.49.2.21 raeburn 5977: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 5978: }
1.1 raeburn 5979:
5980: sub print_bridgetasks {
1.49.2.21 raeburn 5981: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5982: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5983: return;
5984: }
1.9 raeburn 5985: my ($stumsg,$msgnote);
5986: if ($crstype eq 'Community') {
5987: $stumsg = &mt('Send message to member');
5988: $msgnote = &mt('Message to member and add to user notes');
5989: } else {
5990: $stumsg = &mt('Send message to student');
5991: $msgnote = &mt('Message to student and add to user notes');
5992: }
1.1 raeburn 5993: my %items = (
5994: task_messages => {
1.3 raeburn 5995: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 5996: input => 'selectbox',
5997: options => {
1.9 raeburn 5998: only_student => $stumsg,
5999: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6000: },
6001: order => ['only_student','student_and_user_notes_screen'],
6002: nullval => &mt('No message or record in user notes'),
6003: },
6004: task_grading => {
1.3 raeburn 6005: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6006: input => 'selectbox',
6007: options => {
6008: any => &mt('Grade BTs in any section'),
6009: section => &mt('Grade BTs only in own section')
6010: },
6011: order => ['any','section'],
6012: },
6013: suppress_embed_prompt => {
1.3 raeburn 6014: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6015: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6016: input => 'radio',
6017: },
6018: );
1.49.2.21 raeburn 6019: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6020: }
6021:
1.49.2.28.2.1 (raeburn 6022:): sub print_ltitools {
6023:): my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6024:): my ($datatable,$disabled,$css_class,$dest);
6025:): if ($noedit) {
6026:): $disabled = ' disabled="disabled"';
6027:): }
6028:): my $itemcount = 1;
6029:): unless ($context eq 'domain') {
6030:): my %tooltypes = &Apache::loncommon::usable_exttools();
6031:): unless ($tooltypes{'crs'}) {
6032:): my $showtype = 'course';
6033:): if ($crstype eq 'Community') {
6034:): $showtype = lc($crstype);
6035:): }
6036:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6037:): $datatable = '<tr '.$css_class.'><td colspan="2">'.
6038:): &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6039:): if ($tooltypes{'dom'}) {
6040:): $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6041:): '<i>'.$cdom.'</i>').
6042:): '<br /><br />'.
6043:): &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.");
6044:): } else {
6045:): $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6046:): '<br /><br />'.
6047:): &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6048:): '<i>'.$cdom.'</i>');
6049:):
6050:): }
6051:): $datatable .= '</tr>';
6052:): $itemcount ++;
6053:): return $datatable;
6054:): }
6055:): }
6056:): my %lt = <itools_names();
6057:): my $maxnum = 0;
6058:): my %ordered;
6059:): if (ref($settings) eq 'HASH') {
6060:): foreach my $item (keys(%{$settings})) {
6061:): if (ref($settings->{$item}) eq 'HASH') {
6062:): my $num = $settings->{$item}{'order'};
6063:): $ordered{$num} = $item;
6064:): }
6065:): }
6066:): }
6067:):
6068:): if ($context eq 'domain') {
6069:): $dest = '/adm/domainprefs';
6070:): } else {
6071:): $dest = '/adm/courseprefs';
6072:): }
6073:): my ($switchserver,$switchmessage);
6074:): $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6075:): if ($switchserver) {
6076:): if ($context eq 'domain') {
6077:): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6078:): } elsif ($crstype eq 'Community') {
6079:): $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6080:): } else {
6081:): $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6082:): }
6083:): }
6084:): my $maxnum = scalar(keys(%ordered));
6085:): my @courseroles = ('cc','in','ta','ep','st');
6086:): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6087:): my @fields = ('fullname','firstname','lastname','email','roles','user');
6088:): if (keys(%ordered)) {
6089:): my @items = sort { $a <=> $b } keys(%ordered);
6090:): for (my $i=0; $i<@items; $i++) {
6091:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6092:): my $item = $ordered{$items[$i]};
6093:): my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6094:): if (ref($settings->{$item}) eq 'HASH') {
6095:): $title = $settings->{$item}->{'title'};
6096:): $url = $settings->{$item}->{'url'};
6097:): $key = $settings->{$item}->{'key'};
6098:): $usable = $settings->{$item}->{'usable'};
6099:): $lifetime = $settings->{$item}->{'lifetime'};
6100:): my $image = $settings->{$item}->{'image'};
6101:): if ($image ne '') {
6102:): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6103:): }
6104:): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6105:): $sigsel{'HMAC-256'} = ' selected="selected"';
6106:): } else {
6107:): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6108:): }
6109:): }
6110:): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6111:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6112:): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6113:): for (my $k=0; $k<=$maxnum; $k++) {
6114:): my $vpos = $k+1;
6115:): my $selstr;
6116:): if ($k == $i) {
6117:): $selstr = ' selected="selected" ';
6118:): }
6119:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6120:): }
6121:): $datatable .= '</select>'.(' 'x2).
6122:): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6123:): &mt('Delete?').'</label></span></td>'.
6124:): '<td colspan="2">'.
6125:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6126:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6127:): (' 'x2).
6128:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6129:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6130:): (' 'x2).
6131:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6132:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6133:): (' 'x2).
6134:): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6135:): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6136:): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6137:): '<br /><br />'.
6138:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
6139:): ' value="'.$url.'" /></span>'.
6140:): (' 'x2).
6141:): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6142:): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6143:): if ($key ne '') {
6144:): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6145:): if ($noedit) {
6146:): $datatable .= ': ['.&mt('not shown').']';
6147:): } elsif ($switchserver) {
6148:): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6149:): } else {
6150:): $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6151:): }
6152:): $datatable .= '</span> '.(' 'x2);
6153:): } elsif (!$switchserver) {
6154:): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6155:): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6156:): '</span> '.(' 'x2);
6157:): }
6158:): if ($switchserver) {
6159:): if ($usable ne '') {
6160:): $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6161:): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6162:): '<span class="LC_nobreak">'.&mt('Change secret?').
6163:): '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6164:): (' 'x2).
6165:): '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6166:): '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6167:): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6168:): '</div>';
6169:): } elsif ($key eq '') {
6170:): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6171:): } else {
6172:): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6173:): }
6174:): $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6175:): } else {
6176:): if ($usable ne '') {
6177:): $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6178:): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6179:): '<span class="LC_nobreak">'.&mt('Change?').
6180:): '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6181:): (' 'x2).
6182:): '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6183:): '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6184:): '<span class="LC_nobreak">'.&mt('New Secret').':'.
6185:): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6186:): '<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>'.
6187:): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6188:): } else {
6189:): $datatable .=
6190:): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6191:): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6192:): '<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>'.
6193:): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6194:): }
6195:): }
6196:): $datatable .= '</fieldset>'.
6197:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6198:): '<span class="LC_nobreak">'.&mt('Display target:');
6199:): my %currdisp;
6200:): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6201:): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6202:): $currdisp{'window'} = ' checked="checked"';
6203:): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6204:): $currdisp{'tab'} = ' checked="checked"';
6205:): } else {
6206:): $currdisp{'iframe'} = ' checked="checked"';
6207:): }
6208:): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6209:): $currdisp{'width'} = $1;
6210:): }
6211:): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6212:): $currdisp{'height'} = $1;
6213:): }
6214:): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6215:): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6216:): } else {
6217:): $currdisp{'iframe'} = ' checked="checked"';
6218:): }
6219:): foreach my $disp ('iframe','tab','window') {
6220:): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6221:): $lt{$disp}.'</label>'.(' 'x2);
6222:): }
6223:): $datatable .= (' 'x4);
6224:): foreach my $dimen ('width','height') {
6225:): $datatable .= '<label>'.$lt{$dimen}.' '.
6226:): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6227:): (' 'x2);
6228:): }
6229:): $datatable .= '</span><br />'.
6230:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6231:): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6232:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6233:): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6234:): '</textarea></div><div style=""></div><br />';
6235:): my %units = (
6236:): 'passback' => 'days',
6237:): 'roster' => 'seconds',
6238:): );
6239:): foreach my $extra ('passback','roster') {
6240:): my $validsty = 'none';
6241:): my $currvalid;
6242:): my $checkedon = '';
6243:): my $checkedoff = ' checked="checked"';
6244:): if ($settings->{$item}->{$extra}) {
6245:): $checkedon = $checkedoff;
6246:): $checkedoff = '';
6247:): $validsty = 'inline-block';
6248:): if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6249:): $currvalid = $settings->{$item}->{$extra.'valid'};
6250:): }
6251:): }
6252:): my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6253:): $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6254:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6255:): &mt('No').'</label>'.(' 'x2).
6256:): '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6257:): &mt('Yes').'</label></span></div>'.
6258:): '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6259:): '<span class="LC_nobreak">'.
6260:): &mt("until at least [_1] $units{$extra} after launch",
6261:): '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6262:): '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6263:): }
6264:): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6265:): if ($imgsrc) {
6266:): $datatable .= $imgsrc.
6267:): '<label><input type="checkbox" name="ltitools_image_del"'.
6268:): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6269:): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6270:): } else {
6271:): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6272:): }
6273:): if ($switchserver) {
6274:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6275:): } else {
6276:): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6277:): }
6278:): $datatable .= '</span></fieldset>';
6279:): my (%checkedfields,%rolemaps,$userincdom);
6280:): if (ref($settings->{$item}) eq 'HASH') {
6281:): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6282:): %checkedfields = %{$settings->{$item}->{'fields'}};
6283:): }
6284:): $userincdom = $settings->{$item}->{'incdom'};
6285:): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6286:): %rolemaps = %{$settings->{$item}->{'roles'}};
6287:): $checkedfields{'roles'} = 1;
6288:): }
6289:): }
6290:): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6291:): '<span class="LC_nobreak">';
6292:): my $userfieldstyle = 'display:none;';
6293:): my $seluserdom = '';
6294:): my $unseluserdom = ' selected="selected"';
6295:): foreach my $field (@fields) {
6296:): my ($checked,$onclick,$id,$spacer);
6297:): if ($checkedfields{$field}) {
6298:): $checked = ' checked="checked"';
6299:): }
6300:): if ($field eq 'user') {
6301:): $id = ' id="ltitools_user_field_'.$i.'"';
6302:): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6303:): if ($checked) {
6304:): $userfieldstyle = 'display:inline-block';
6305:): if ($userincdom) {
6306:): $seluserdom = $unseluserdom;
6307:): $unseluserdom = '';
6308:): }
6309:): }
6310:): } else {
6311:): $spacer = (' ' x2);
6312:): }
6313:): $datatable .= '<label>'.
6314:): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6315:): $lt{$field}.'</label>'.$spacer;
6316:): }
6317:): $datatable .= '</span>';
6318:): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6319:): '<span class="LC_nobreak"> : '.
6320:): '<select name="ltitools_userincdom_'.$i.'">'.
6321:): '<option value="">'.&mt('Select').'</option>'.
6322:): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6323:): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6324:): '</select></span></div>';
6325:): $datatable .= '</fieldset>'.
6326:): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6327:): foreach my $role (@courseroles) {
6328:): my ($selected,$selectnone);
6329:): if (!$rolemaps{$role}) {
6330:): $selectnone = ' selected="selected"';
6331:): }
6332:): $datatable .= '<td style="text-align: center">'.
6333:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
6334:): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6335:): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6336:): foreach my $ltirole (@ltiroles) {
6337:): unless ($selectnone) {
6338:): if ($rolemaps{$role} eq $ltirole) {
6339:): $selected = ' selected="selected"';
6340:): } else {
6341:): $selected = '';
6342:): }
6343:): }
6344:): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6345:): }
6346:): $datatable .= '</select></td>';
6347:): }
6348:): $datatable .= '</tr></table></fieldset>';
6349:): my %courseconfig;
6350:): if (ref($settings->{$item}) eq 'HASH') {
6351:): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6352:): %courseconfig = %{$settings->{$item}->{'crsconf'}};
6353:): }
6354:): }
6355:): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6356:): foreach my $item ('label','title','target','linktext','explanation','append') {
6357:): my $checked;
6358:): if ($courseconfig{$item}) {
6359:): $checked = ' checked="checked"';
6360:): }
6361:): $datatable .= '<label>'.
6362:): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6363:): $lt{'crs'.$item}.'</label> '."\n";
6364:): }
6365:): $datatable .= '</span></fieldset>'.
6366:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6367:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6368:): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6369:): my %custom = %{$settings->{$item}->{'custom'}};
6370:): if (keys(%custom) > 0) {
6371:): foreach my $key (sort(keys(%custom))) {
6372:): $datatable .= '<tr><td><span class="LC_nobreak">'.
6373:): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6374:): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6375:): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6376:): ' value="'.$custom{$key}.'" /></td></tr>';
6377:): }
6378:): }
6379:): }
6380:): $datatable .= '<tr><td><span class="LC_nobreak">'.
6381:): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6382:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6383:): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6384:): $datatable .= '</table></fieldset></td></tr>'."\n";
6385:): $itemcount ++;
6386:): }
6387:): }
6388:): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6389:): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6390:): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6391:): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6392:): '<select name="ltitools_add_pos"'.$chgstr.'>';
6393:): for (my $k=0; $k<$maxnum+1; $k++) {
6394:): my $vpos = $k+1;
6395:): my $selstr;
6396:): if ($k == $maxnum) {
6397:): $selstr = ' selected="selected" ';
6398:): }
6399:): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6400:): }
6401:): $datatable .= '</select> '."\n".
6402:): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6403:): '<td colspan="2">'.
6404:): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6405:): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6406:): (' 'x2).
6407:): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6408:): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6409:): (' 'x2).
6410:): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6411:): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6412:): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6413:): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6414:): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6415:): '<br />'.
6416:): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
6417:): (' 'x2).
6418:): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6419:): if ($switchserver) {
6420:): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6421:): } else {
6422:): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6423:): (' 'x2).
6424:): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6425:): '<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";
6426:): }
6427:): $datatable .= '<br /><br />'.
6428:): '</fieldset>'.
6429:): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6430:): '<span class="LC_nobreak">'.&mt('Display target:');
6431:): my %defaultdisp;
6432:): $defaultdisp{'iframe'} = ' checked="checked"';
6433:): foreach my $disp ('iframe','tab','window') {
6434:): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6435:): $lt{$disp}.'</label>'.(' 'x2);
6436:): }
6437:): $datatable .= (' 'x4);
6438:): foreach my $dimen ('width','height') {
6439:): $datatable .= '<label>'.$lt{$dimen}.' '.
6440:): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6441:): (' 'x2);
6442:): }
6443:): $datatable .= '</span><br />'.
6444:): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6445:): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6446:): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6447:): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6448:): '</div><div style=""></div><br />';
6449:): my %units = (
6450:): 'passback' => 'days',
6451:): 'roster' => 'seconds',
6452:): );
6453:): my %defaulttimes = (
6454:): 'passback' => '7',
6455:): 'roster' => '300',
6456:): );
6457:): foreach my $extra ('passback','roster') {
6458:): my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6459:): $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6460:): '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6461:): &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6462:): '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6463:): &mt('Yes').'</label></span></div>'.
6464:): '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6465:): '<span class="LC_nobreak">'.
6466:): &mt("until at least [_1] $units{$extra} after launch",
6467:): '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6468:): '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6469:): }
6470:): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6471:): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6472:): if ($switchserver) {
6473:): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6474:): } else {
6475:): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6476:): }
6477:): $datatable .= '</span></fieldset>'.
6478:): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6479:): '<span class="LC_nobreak">';
6480:): foreach my $field (@fields) {
6481:): my ($id,$onclick,$spacer);
6482:): if ($field eq 'user') {
6483:): $id = ' id="ltitools_user_field_add"';
6484:): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6485:): } else {
6486:): $spacer = (' ' x2);
6487:): }
6488:): $datatable .= '<label>'.
6489:): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6490:): $lt{$field}.'</label>'.$spacer;
6491:): }
6492:): $datatable .= '</span>'.
6493:): '<div style="display:none;" id="ltitools_user_div_add">'.
6494:): '<span class="LC_nobreak"> : '.
6495:): '<select name="ltitools_add_userincdom">'.
6496:): '<option value="" selected="selected">'.&mt('Select').'</option>'.
6497:): '<option value="0">'.&mt('username').'</option>'.
6498:): '<option value="1">'.&mt('username:domain').'</option>'.
6499:): '</select></span></div></fieldset>';
6500:): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6501:): foreach my $role (@courseroles) {
6502:): my ($checked,$checkednone);
6503:): $datatable .= '<td style="text-align: center">'.
6504:): &Apache::lonnet::plaintext($role,'Course').'<br />'.
6505:): '<select name="ltitools_add_roles_'.$role.'">'.
6506:): '<option value="" selected="selected">'.&mt('Select').'</option>';
6507:): foreach my $ltirole (@ltiroles) {
6508:): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6509:): }
6510:): $datatable .= '</select></td>';
6511:): }
6512:): $datatable .= '</tr></table></fieldset>'.
6513:): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6514:): foreach my $item ('label','title','target','linktext','explanation','append') {
6515:): $datatable .= '<label>'.
6516:): '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6517:): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6518:): }
6519:): $datatable .= '</span></fieldset>'.
6520:): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6521:): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6522:): '<tr><td><span class="LC_nobreak">'.
6523:): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6524:): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6525:): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6526:): '</table></fieldset>'."\n".
6527:): '</td>'."\n".
6528:): '</tr>'."\n";
6529:): $itemcount ++;
6530:): return $datatable;
6531:): }
6532:):
6533:): sub ltitools_names {
6534:): my %lt = &Apache::lonlocal::texthash(
6535:): 'title' => 'Title',
6536:): 'version' => 'Version',
6537:): 'msgtype' => 'Message Type',
6538:): 'sigmethod' => 'Signature Method',
6539:): 'url' => 'URL',
6540:): 'key' => 'Key',
6541:): 'lifetime' => 'Nonce lifetime (s)',
6542:): 'secret' => 'Secret',
6543:): 'icon' => 'Icon',
6544:): 'user' => 'User',
6545:): 'fullname' => 'Full Name',
6546:): 'firstname' => 'First Name',
6547:): 'lastname' => 'Last Name',
6548:): 'email' => 'E-mail',
6549:): 'roles' => 'Role',
6550:): 'window' => 'Window',
6551:): 'tab' => 'Tab',
6552:): 'iframe' => 'iFrame',
6553:): 'height' => 'Height',
6554:): 'width' => 'Width',
6555:): 'linktext' => 'Default Link Text',
6556:): 'explanation' => 'Default Explanation',
6557:): 'passback' => 'Tool can return grades:',
6558:): 'roster' => 'Tool can retrieve roster:',
6559:): 'crstarget' => 'Display target',
6560:): 'crslabel' => 'Course label',
6561:): 'crstitle' => 'Course title',
6562:): 'crslinktext' => 'Link Text',
6563:): 'crsexplanation' => 'Explanation',
6564:): 'crsappend' => 'Provider URL',
6565:): );
6566:): return %lt;
6567:): }
6568:):
6569:: sub ltimenu_titles {
6570:: return &Apache::lonlocal::texthash(
6571:: fullname => 'Full name',
6572:: coursetitle => 'Course title',
6573:: role => 'Role',
6574:: logout => 'Logout',
6575:: grades => 'Grades',
6576:: );
6577:: }
6578::
6579:: sub print_menuitems {
6580:: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6581:: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
6582:: return;
6583:: }
6584:: if ($position eq 'top') {
6585:: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
6586:: if ($settings->{'menucollections'} ne '') {
6587:: foreach my $item (split(/;/,$settings->{'menucollections'})) {
6588:: my ($num,$value) = split(/\%/,$item);
6589:: if ($num =~ /^\d+$/) {
6590:: $defaultmenu_options{$num} = $num;
6591:: }
6592:: }
6593:: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
6594:: $addcollection = $defaultmenu_order[-1] + 1;
6595:: } else {
6596:: $addcollection = 1;
6597:: }
6598:: $defaultmenu_options{$addcollection} = $addcollection;
6599:: my %items = (
6600:: 'menudefault' => {
6601:: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
6602:: &mt("(can be overriden in deep-link context)"),
6603:: input => 'selectbox',
6604:: options => \%defaultmenu_options,
6605:: order => \@defaultmenu_order,
6606:: nullval => &mt('Standard (all menus shown)'),
6607:: },
6608:: );
6609:: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
6610:: } else {
6611:: my %menu;
6612:: my $count = 0;
6613:: my $next = 1;
6614:: my ($datatable,$disabled);
6615:: if ($noedit) {
6616:: $disabled = ' disabled="disabled"';
6617:: }
6618::
6619:: my ($ordered,$cats) = &menuitems_categories();
6620:: my @order = @{$ordered};
6621:: my %categories = %{$cats};
6622:: my %menutitles = &menuitems_titles();
6623:: my %menufields = &menuitems_fields();
6624::
6625:: if ($settings->{'menucollections'} ne '') {
6626:: foreach my $item (split(/;/,$settings->{'menucollections'})) {
6627:: my ($num,$value) = split(/\%/,$item);
6628:: if ($num =~ /^\d+$/) {
6629:: my @entries = split(/\&/,$value);
6630:: foreach my $entry (@entries) {
6631:: my ($name,$fields) = split(/=/,$entry);
6632:: $menu{$num}{$name} = $fields;
6633:: }
6634:: }
6635:: }
6636:: if (keys(%menu)) {
6637:: my @current = sort { $a <=> $b } keys(%menu);
6638:: $next += $current[-1];
6639:: foreach my $num (@current) {
6640:: my %checked;
6641:: my $on = ' checked="checked"';
6642:: foreach my $key (keys(%{$menu{$num}})) {
6643:: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
6644:: if ($menu{$num}{$key} eq 'y') {
6645:: $checked{$key} = $on;
6646:: }
6647:: } else {
6648:: foreach my $field (split(/,/,$menu{$num}{$key})) {
6649:: if (exists($menufields{$field})) {
6650:: $checked{$field} = $on;
6651:: }
6652:: }
6653:: }
6654:: }
6655:: if (ref($menu{$num}) eq 'HASH') {
6656:: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
6657:: foreach my $category (@order) {
6658:: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
6659:: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
6660:: if ($category eq 'text') {
6661:: $datatable .= '<i>'.&mt('Header').'</i><br />';
6662:: }
6663:: foreach my $field (@{$categories{$category}}) {
6664:: if ($field eq 'disc') {
6665:: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
6666:: }
6667:: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
6668:: $menufields{$field}.'</label><br />';
6669:: }
6670:: $datatable .= '</fieldset>';
6671:: }
6672:: }
6673:: $datatable .= &item_table_row_end();
6674:: $count ++;
6675:: }
6676:: }
6677:: }
6678:: } elsif ($noedit) {
6679:: my $text = &mt('No menu collections defined for this course.');
6680:: $datatable .= &item_table_row_start($text,$count);
6681:: }
6682:: unless ($noedit) {
6683:: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
6684:: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
6685:: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
6686:: foreach my $category (@order) {
6687:: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
6688:: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
6689:: foreach my $field (@{$categories{$category}}) {
6690:: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
6691:: $menufields{$field}.'</label><br />';
6692:: }
6693:: $datatable .= '</fieldset>';
6694:: }
6695:: }
6696:: $datatable .= &item_table_row_end();
6697:: $count ++;
6698:: }
6699:: return $datatable;
6700:: }
6701:: }
6702::
6703:: sub menuitems_abbreviations {
6704:: my %briefcats = (
6705:: text => 'pt',
6706:: links => 'p',
6707:: list => 'ps',
6708:: inline => 's',
6709:: );
6710:: return %briefcats;
6711:: }
6712::
6713:: sub menuitems_categories {
6714:: my @order = ('shown','text','links','list','inline');
6715:: my %categories = (
6716:: shown => ['top','inline','foot','main'],
6717:: text => ['name','role','crs','disc','fdbk'],
1.49.2.28.2.4 (raeburn 6718:: links => ['pers','logo','comm','roles','help','logout'],
1.49.2.28.2.1 (raeburn 6719:: list => ['about','prefs','port','wish','anno','rss'],
6720:: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
6721:: );
6722:: return (\@order,\%categories);
6723:: }
6724::
6725:: sub menuitems_titles {
6726:: return &Apache::lonlocal::texthash (
6727:: shown => 'Hierarchy',
6728:: text => 'Text',
6729:: links => 'Header links',
6730:: list => 'Drop-down list',
6731:: inline => 'Inline links',
6732:: );
6733:: }
6734::
6735:: sub menuitems_fields {
6736:: return &Apache::lonlocal::texthash (
6737:: top => 'Display header',
6738:: inline => 'Display inline menu',
6739:: foot => 'Display footer',
6740:: main => 'Access to main menu',
6741:: pers => 'Personal',
6742:: logo => 'LON-CAPA',
6743:: comm => 'Messages',
6744:: roles => 'Roles/Courses',
6745:: help => 'Help',
6746:: logout => 'Logout',
6747:: name => 'Fullname',
6748:: crs => 'Course Title',
6749:: role => 'Current Role',
6750:: disc => 'Discussion',
6751:: fdbk => 'Feedback',
6752:: about => 'Information',
6753:: prefs => 'Preferences',
6754:: port => 'Portfolio',
6755:: wish => 'Stored Links',
6756:: anno => 'Calendar',
6757:: rss => 'RSS Feeds',
6758:: cont => 'Contents',
6759:: grades => 'Grades',
6760:: chat => 'Chat',
6761:: people => 'People',
6762:: groups => 'Groups',
6763:: resv => 'Reservations',
6764:: syll => 'Syllabus',
6765:: feeds => 'Feeds',
6766:: );
6767:: }
6768::
6769:: sub menucollections_display {
6770:: my ($collections) = @_;
6771:: my %menu;
6772:: my ($ordered,$cats) = &menuitems_categories();
6773:: my @order = @{$ordered};
6774:: my %categories = %{$cats};
6775:: my %menutitles = &menuitems_titles();
6776:: my %menufields = &menuitems_fields();
6777:: foreach my $item (split(/;/,$collections)) {
6778:: my ($num,$value) = split(/\%/,$item);
6779:: if ($num =~ /^\d+$/) {
6780:: my @entries = split(/\&/,$value);
6781:: foreach my $entry (@entries) {
6782:: my ($name,$fields) = split(/=/,$entry);
6783:: $menu{$num}{$name} = $fields;
6784:: }
6785:: }
6786:: }
6787:: my $output = '';
6788:: if (keys(%menu)) {
6789:: my @current = sort { $a <=> $b } keys(%menu);
6790:: foreach my $num (@current) {
6791:: my %checked;
6792:: foreach my $key (keys(%{$menu{$num}})) {
6793:: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
6794:: if ($menu{$num}{$key} eq 'y') {
6795:: $checked{$key} = 1;
6796:: }
6797:: } else {
6798:: foreach my $field (split(/,/,$menu{$num}{$key})) {
6799:: if (exists($menufields{$field})) {
6800:: $checked{$field} = 1;
6801:: }
6802:: }
6803:: }
6804:: }
6805:: if (ref($menu{$num}) eq 'HASH') {
6806:: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
6807:: foreach my $category (@order) {
6808:: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
6809:: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
6810:: '<legend>'.$menutitles{$category}.'</legend>'."\n";
6811:: if ($category eq 'text') {
6812:: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
6813:: }
6814:: foreach my $field (@{$categories{$category}}) {
6815:: if ($field eq 'disc') {
6816:: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
6817:: }
6818:: if ($checked{$field}) {
6819:: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
6820:: } else {
6821:: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
6822:: }
6823:: $output .= '<br />';
6824:: }
6825:: $output .= '</fieldset>';
6826:: }
6827:: }
6828:: $output .= '</fieldset>';
6829:: }
6830:: }
6831:: }
6832:: return $output;
6833:: }
6834::
6835:: sub print_linkprotection {
1.49.2.28.2.5 (raeburn 6836:: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.49.2.28.2.1 (raeburn 6837::
6838:: my %linkprotection;
6839:: my $count = 0;
6840:: my $next = 1;
1.49.2.28.2.5 (raeburn 6841:: my ($datatable,$disabled,$css_class,$dest);
1.49.2.28.2.1 (raeburn 6842:: if ($noedit) {
6843:: $disabled = ' disabled="disabled"';
6844:: }
1.49.2.28.2.3 (raeburn 6845:: my %desc = &linkprot_names();
6846:: my %lt = &Apache::lonlocal::texthash (
6847:: 'requ' => 'Required settings',
6848:: 'opti' => 'Optional settings',
6849:: );
1.49.2.28.2.1 (raeburn 6850:: my $itemcount = 0;
6851::
1.49.2.28.2.3 (raeburn 6852:: my $ltiauth;
1.49.2.28.2.5 (raeburn 6853:: if ($context eq 'domain') {
6854:: $ltiauth = 1;
1.49.2.28.2.3 (raeburn 6855:: } else {
1.49.2.28.2.5 (raeburn 6856:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
6857:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
6858:: } else {
6859:: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
6860:: $ltiauth = $domdefs{'crsltiauth'};
6861:: }
6862:: }
6863:: if ($context eq 'domain') {
6864:: $dest = '/adm/domainprefs';
6865:: } else {
6866:: $dest = '/adm/courseprefs';
1.49.2.28.2.3 (raeburn 6867:: }
6868::
1.49.2.28.2.5 (raeburn 6869:: my ($switchserver,$switchmessage);
6870:: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6871:: if ($switchserver) {
6872:: if ($context eq 'domain') {
6873:: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6874:: } elsif ($crstype eq 'Community') {
6875:: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6876:: } else {
6877:: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6878:: }
6879:: }
6880::
1.49.2.28.2.6 (raeburn 6881:: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.49.2.28.2.5 (raeburn 6882:: if (keys(%{$settings->{'linkprot'}})) {
6883:: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.49.2.28.2.1 (raeburn 6884:: $next += $current[-1];
6885:: for (my $i=0; $i<@current; $i++) {
6886:: my $num = $current[$i];
6887:: my %values;
1.49.2.28.2.5 (raeburn 6888:: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
6889:: %values = %{$settings->{'linkprot'}->{$num}};
1.49.2.28.2.1 (raeburn 6890:: } else {
6891:: next;
6892:: }
6893:: my $selected;
6894:: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
6895:: $selected = ' selected="selected"';
6896:: }
6897:: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6898:: $datatable .=
6899:: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
6900:: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.49.2.28.2.3 (raeburn 6901:: &mt('Delete?').'</label></span></td><td>';
1.49.2.28.2.1 (raeburn 6902:): my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
6903:): $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
6904:): $passbacksty = 'none';
6905:): $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
6906:): %checkedpassback = (
6907:): 'no' => ' checked="checked"',
6908:): 'yes' => '',
6909:): );
6910:): %checkedpassbackfmt = (
6911:): '1p1' => ' checked="checked"',
6912:): '1p0' => '',
6913:): );
6914:): if ($values{'passback'} ne '') {
6915:): $passbacksty = 'inline-block';
6916:): $checkedpassback{'yes'} = ' checked="checked"';
6917:): $checkedpassback{'no'} = '';
6918:): if ($values{'passbackformat'} eq '1.0') {
6919:): $checkedpassbackfmt{'1p0'} = ' checked="checked"';
6920:): $checkedpassbackfmt{'1p1'} = '';
6921:): }
6922:): }
1.49.2.28.2.3 (raeburn 6923:: if ($ltiauth) {
6924:: $usersty = 'display:none';
1.49.2.28.2.1 (raeburn 6925:): $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.49.2.28.2.3 (raeburn 6926:: %checkedrequser = (
6927:: no => ' checked="checked"',
6928:: yes => '',
6929:: );
6930:: if ($values{'requser'}) {
6931:: $checkedrequser{'yes'} = $checkedrequser{'no'};
6932:: $checkedrequser{'no'} = '';
6933:: }
6934:: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
6935:: if ($values{'requser'}) {
6936:: $usersty = 'display:inline-block';
6937:: }
6938:: }
1.49.2.28.2.1 (raeburn 6939:): $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
6940:): %checkedreturnurl = (
6941:): no => ' checked="checked"',
6942:): yes => '',
6943:): );
6944:): if ($values{'returnurl'} ne '') {
6945:): $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
6946:): $checkedreturnurl{'no'} = '';
6947:): }
6948:): $datatable .=
1.49.2.28.2.3 (raeburn 6949:: '<span class="LC_nobreak">'.$desc{'name'}.
6950:: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.49.2.28.2.1 (raeburn 6951:: (' 'x2).
1.49.2.28.2.3 (raeburn 6952:: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.49.2.28.2.1 (raeburn 6953:: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
6954:: (' 'x2).
1.49.2.28.2.3 (raeburn 6955:: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.49.2.28.2.1 (raeburn 6956:): ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.49.2.28.2.3 (raeburn 6957:: if ($values{'key'} ne '') {
6958:: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
6959:: if ($noedit) {
6960:: $datatable .= ': ['.&mt('not shown').']';
6961:: } elsif ($switchserver) {
6962:: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6963:: } else {
6964:: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
6965:: }
6966:: $datatable .= '</span> '.(' 'x2);
6967:: } elsif (!$switchserver) {
6968:: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
6969:: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
6970:: '</span> '.(' 'x2);
6971:: }
6972:: if ($switchserver) {
6973:: if ($values{'usable'} ne '') {
6974:: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6975:: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6976:: '<span class="LC_nobreak">'.&mt('Change secret?').
1.49.2.28.2.1 (raeburn 6977:): '<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 6978:: (' 'x2).
1.49.2.28.2.1 (raeburn 6979:): '<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 6980:: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.49.2.28.2.5 (raeburn 6981:: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.49.2.28.2.3 (raeburn 6982:: '</div>';
6983:: } elsif ($values{'key'} eq '') {
1.49.2.28.2.5 (raeburn 6984:: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.49.2.28.2.3 (raeburn 6985:: } else {
1.49.2.28.2.5 (raeburn 6986:: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.49.2.28.2.3 (raeburn 6987:: }
1.49.2.28.2.1 (raeburn 6988:): $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.49.2.28.2.3 (raeburn 6989:: } else {
6990:: if ($values{'usable'} ne '') {
6991:: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6992:: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6993:: '<span class="LC_nobreak">'.&mt('Change?').
1.49.2.28.2.1 (raeburn 6994:): '<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 6995:: (' 'x2).
1.49.2.28.2.1 (raeburn 6996:): '<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 6997:: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
6998:: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.49.2.28.2.1 (raeburn 6999:): '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.49.2.28.2.7 (raeburn 7000:: '<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 7001:: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7002:: } else {
7003:: $datatable .=
7004:: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.49.2.28.2.1 (raeburn 7005:): '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.49.2.28.2.7 (raeburn 7006:: '<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 7007:: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7008:: }
7009:: }
1.49.2.28.2.1 (raeburn 7010:): $datatable .= '<br /><br />'.
7011:): '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7012:): '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7013:): $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7014:): '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7015:): $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7016:): '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7017:): '<span class="LC_nobreak">'.&mt('Grade format').
7018:): '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7019:): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7020:): '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7021:): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7022:): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7023:): '<br />'.
7024:): '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7025:): '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7026:): $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7027:): '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7028:): $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7029:): ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7030:): '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7031:): '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7032:): '</span></div> ';
1.49.2.28.2.3 (raeburn 7033:: if ($ltiauth) {
1.49.2.28.2.1 (raeburn 7034:): $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7035:): '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7036:): $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7037:): '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7038:): $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.49.2.28.2.3 (raeburn 7039:: '</fieldset>'.
7040:: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7041:: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7042:: '</fieldset>';
7043:: }
7044:: $datatable .= '</td></tr>';
1.49.2.28.2.1 (raeburn 7045:: $itemcount ++;
7046:: }
7047:: }
7048:: }
7049:: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7050:: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7051:: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.49.2.28.2.3 (raeburn 7052:: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.49.2.28.2.6 (raeburn 7053:: '<td width="100%">';
1.49.2.28.2.1 (raeburn 7054:): my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7055:): $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.49.2.28.2.3 (raeburn 7056:: if ($ltiauth) {
7057:: $usersty = 'display:none';
1.49.2.28.2.1 (raeburn 7058:): $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.49.2.28.2.3 (raeburn 7059:: %checkedrequser = (
7060:: no => ' checked="checked"',
7061:: yes => '',
7062:: );
7063:: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7064:: }
1.49.2.28.2.1 (raeburn 7065:): $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7066:): %checkedpassback = (
7067:): 'no' => ' checked="checked"',
7068:): 'yes' => '',
7069:): );
7070:): %checkedpassbackfmt = (
7071:): '1p1' => ' checked="checked"',
7072:): '1p0' => '',
7073:): );
7074:): $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7075:): %checkedreturnurl = (
7076:): no => ' checked="checked"',
7077:): yes => '',
7078:): );
1.49.2.28.2.3 (raeburn 7079:: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
7080:: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.49.2.28.2.1 (raeburn 7081:: (' 'x2).
1.49.2.28.2.3 (raeburn 7082:: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.49.2.28.2.1 (raeburn 7083:: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7084:: (' 'x2).
7085:): '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7086:): '<br /><br />';
1.49.2.28.2.3 (raeburn 7087:: if ($switchserver) {
1.49.2.28.2.5 (raeburn 7088:: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.49.2.28.2.3 (raeburn 7089:: } else {
7090:: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':<input type="text" size="25" name="linkprot_key_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
7091:: (' 'x2).
1.49.2.28.2.1 (raeburn 7092:): '<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 7093:: '<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 7094:: }
1.49.2.28.2.1 (raeburn 7095:): $datatable .= '<br /><br />'.
7096:): '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7097:): '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7098:): $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7099:): '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7100:): $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7101:): '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none" />'.
7102:): '<span class="LC_nobreak">'.&mt('Grade format').
7103:): '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7104:): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7105:): '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7106:): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7107:): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7108:): '<br />'.
7109:): '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7110:): '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7111:): $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7112:): '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7113:): $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7114:): ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7115:): '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7116:): '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7117:): '</span></div> ';
1.49.2.28.2.3 (raeburn 7118:: if ($ltiauth) {
1.49.2.28.2.1 (raeburn 7119:): $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7120:): '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7121:): $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7122:): '<label><input type="radio" name="linkprot_requser_add" value="1"'.
7123:): $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7124:): '</fieldset>'.
1.49.2.28.2.3 (raeburn 7125:: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7126:: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7127:: '</fieldset>';
7128:: }
7129:: $datatable .= '</td></tr>';
1.49.2.28.2.1 (raeburn 7130:: $$rowtotal ++;
1.49.2.28.2.3 (raeburn 7131:: return $datatable;
1.49.2.28.2.1 (raeburn 7132:: }
7133::
7134:: sub linkprot_names {
1.49.2.28.2.3 (raeburn 7135:: return &Apache::lonlocal::texthash(
1.49.2.28.2.1 (raeburn 7136:: 'version' => 'LTI Version',
7137:: 'key' => 'Key',
7138:: 'lifetime' => 'Nonce lifetime (s)',
1.49.2.28.2.3 (raeburn 7139:: 'name' => 'Launcher Application',
1.49.2.28.2.1 (raeburn 7140:: 'secret' => 'Secret',
7141:): 'passback' => 'Can return grades to Launcher',
7142:): 'returnurl' => 'Launcher return URL',
1.49.2.28.2.3 (raeburn 7143:: 'requser' => 'Use identity',
7144:: 'email' => 'Email address',
7145:: 'sourcedid' => 'User ID',
7146:: 'other' => 'Other',
7147:: 'auth' => 'Display LON-CAPA login page',
7148:: 'reject' => 'Discontinue launch process',
1.49.2.28.2.1 (raeburn 7149:: );
1.49.2.28.2.3 (raeburn 7150:: }
7151::
7152:: sub check_switchserver {
1.49.2.28.2.5 (raeburn 7153:: my ($cdom,$cnum,$context,$dest) = @_;
7154:: my ($allowed,$switchserver,$home);
7155:: if ($context eq 'domain') {
7156:: $home = &Apache::lonnet::domain($cdom,'primary');
7157:: } else {
7158:: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7159:: }
7160:: unless (($home eq 'no_host') || ($home eq '')) {
1.49.2.28.2.3 (raeburn 7161:: my @ids=&Apache::lonnet::current_machine_ids();
7162:: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7163:: if (!$allowed) {
7164:: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7165:: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.49.2.28.2.5 (raeburn 7166:: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.49.2.28.2.3 (raeburn 7167:: }
7168:: }
7169:: return $switchserver;
7170:: }
7171::
7172:: sub linkprot_options {
7173:: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7174:: my %lt;
7175:: if (ref($desc) eq 'HASH') {
7176:: %lt = %{$desc};
7177:: }
7178:: my $userfieldsty = 'none';
7179:: my (%checked,$userfield);
7180:: $checked{'sourcedid'} = ' checked="checked"';
7181:: $checked{'reject'} = ' checked="checked"';
7182:: if (ref($current) eq 'HASH') {
7183:: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7184:: $checked{'sourcedid'} = '';
7185:: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7186:: $checked{'email'} = ' checked="checked"';
7187:: } else {
7188:: $checked{'other'} = ' checked="checked"';
7189:: $userfield = $current->{'mapuser'};
7190:: $userfieldsty = 'inline-block';
7191:: }
7192:: }
7193:: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7194:: $checked{'reject'} = '';
7195:: $checked{'auth'} = ' checked="checked"';
7196:: }
7197:: }
1.49.2.28.2.1 (raeburn 7198:): my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.49.2.28.2.3 (raeburn 7199:: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7200:: &mt('Source of LON-CAPA username in LTI request').': ';
7201:: foreach my $option ('sourcedid','email','other') {
7202:: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7203:: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7204:: ($option eq 'other' ? '' : (' 'x2) );
7205:: }
7206:: $output .= '</span></div>'.
7207:: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7208:: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7209:: 'value="'.$userfield.'"'.$disabled.' /></div>';
7210:: $output .= '<br />'.
7211:: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7212:: &mt('Action when username is not for an enrolled student').': ';
7213:: foreach my $option ('reject','auth') {
7214:: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7215:: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7216:: ($option eq 'auth' ? '' : (' 'x2) );
7217:: }
7218:: $output .= '</span></div>';
7219:: return $output;
1.49.2.28.2.1 (raeburn 7220:: }
7221::
7222:): sub print_extresource_row {
7223:): my ($item,$config,$curr,$noedit) = @_;
7224:): my $onchange;
7225:): unless ($noedit) {
7226:): $onchange = ' onchange="javascript:toggleExtRes();"';
7227:): }
7228:): my $id = 'LC_'.$item;
7229:): my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7230:): my $output = &select_from_options($item,$config->{'order'},
7231:): $config->{'options'},$selected,
7232:): $config->{'nullval'},
7233:): undef,undef,$onchange,$noedit,$id);
7234:): my ($checked,$reusesty,$sizesty);
7235:): if ($reuse) {
7236:): $checked = ' checked="checked"';
7237:): }
7238:): $reusesty = 'none';
7239:): $sizesty = 'none';
7240:): if (($selected eq 'window') || ($selected eq 'tab')) {
7241:): $reusesty = 'inline-block';
7242:): if ($selected eq 'window') {
7243:): $sizesty = 'inline-block';
7244:): }
7245:): }
7246:): $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7247:): '<span class="LC_nobreak">'.
7248:): '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7249:): &mt('Re-use tab/window').'</label>'.
7250:): '</span></div>'.
7251:): '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7252:): '<legend>'.&mt('Window size (optional)').'</legend>'.
7253:): '<span class="LC_nobreak">'.
7254:): &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7255:): (' ' x 3).
7256:): &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7257:): '</span></fieldset>';
7258:): return $output;
7259:): }
7260:):
1.1 raeburn 7261: sub print_other {
1.49.2.21 raeburn 7262: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7263: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7264: return;
7265: }
1.3 raeburn 7266: my @ordered = &get_other_items($cdom,$settings,$allitems);
7267: my %items;
7268: foreach my $parameter (@ordered) {
7269: $items{$parameter} = {
7270: text => '<b>'.$parameter.'</b>',
7271: input => 'textbox',
7272: size => '15',
7273: },
7274: }
7275: push (@ordered,'newp_value');
7276: $items{'newp_value'} = {
7277: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7278: '<input type="textbox" name="newp_name"'.
7279: ' value="" size="30" />',
7280: input => 'textbox',
7281: size => '30',
7282: };
1.49.2.27 raeburn 7283: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7284: }
7285:
7286: sub get_other_items {
7287: my ($cdom,$settings,$allitems) = @_;
7288: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7289: return;
7290: }
1.1 raeburn 7291: my @ordered;
7292: if (ref($settings) eq 'HASH') {
7293: foreach my $parameter (sort(keys(%{$settings}))) {
7294: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7295: next if (($parameter eq 'course.helper.not.run') &&
7296: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7297: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7298: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7299: || ($parameter eq 'type') ||
1.49.2.3 raeburn 7300: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.49.2.11 raeburn 7301: || ($parameter =~ m/^discussion_post_fonts/) ||
7302: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7303: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7304: push(@ordered,$parameter);
7305: }
7306: }
7307: }
1.3 raeburn 7308: return @ordered;
1.1 raeburn 7309: }
7310:
7311: sub item_table_row_start {
1.49.2.28.2.1 (raeburn 7312:: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7313: my $output;
1.49.2.7 raeburn 7314: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7315: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.49.2.28.2.1 (raeburn 7316:: if ($leftclass eq '') {
7317:: $leftclass = 'LC_left_item';
7318:: }
7319:: if ($rightclass eq '') {
7320:: $rightclass = 'LC_right_item';
7321:: }
1.49.2.7 raeburn 7322: $output .= '<tr class="'.$css_class.'">'."\n".
1.49.2.28.2.1 (raeburn 7323:: '<td class="'.$leftclass.'">'.$text.
1.49.2.7 raeburn 7324: '</td>';
1.49.2.28.2.1 (raeburn 7325:: if ($colspan > 1) {
7326:: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.49.2.7 raeburn 7327: } else {
1.49.2.28.2.1 (raeburn 7328:: $output .= '<td class="'.$rightclass.'">';
1.49.2.7 raeburn 7329: }
1.1 raeburn 7330: return $output;
7331: }
7332:
7333: sub item_table_row_end {
7334: return '</td></tr>';
7335: }
7336:
7337: sub yesno_radio {
1.49.2.21 raeburn 7338: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
1.1 raeburn 7339: my $itemon = ' ';
7340: my $itemoff = ' checked="checked" ';
1.49.2.17 raeburn 7341: if (($valueyes eq '') && ($valueno eq '')) {
7342: $valueyes = 'yes';
7343: $valueno = '';
7344: }
1.1 raeburn 7345: if (ref($settings) eq 'HASH') {
1.49.2.17 raeburn 7346: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7347: $itemon = $itemoff;
7348: $itemoff = ' ';
7349: }
1.49.2.17 raeburn 7350: unless (exists($settings->{$item})) {
7351: if ($unsetdefault eq $valueyes) {
7352: $itemon = $itemoff;
7353: $itemoff = ' ';
7354: }
7355: }
1.1 raeburn 7356: }
1.49.2.21 raeburn 7357: my $disabled;
7358: if ($noedit) {
7359: $disabled = ' disabled="disabled"';
7360: }
1.1 raeburn 7361: return '<span class="LC_nobreak"><label>'.
7362: '<input type="radio" name="'.$item.'"'.
1.49.2.21 raeburn 7363: $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
1.1 raeburn 7364: '<label><input type="radio" name="'.$item.'"'.
1.49.2.21 raeburn 7365: $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
1.1 raeburn 7366: }
7367:
7368: sub select_from_options {
1.49.2.28.2.1 (raeburn 7369:: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7370: my $output;
1.49.2.21 raeburn 7371: my $disabled;
7372: if ($noedit) {
7373: $disabled = ' disabled=disabled"';
7374: }
1.1 raeburn 7375: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7376: $output='<select name="'.$item.'" '.$onchange;
7377: if ($multiple) {
7378: $output .= ' multiple="multiple"';
7379: my $num = @{$order};
7380: $num ++ if ($nullval ne '');
7381: if (($maxsize) && ($maxsize < $num)) {
7382: $output .= ' size="'.$maxsize.'"';
7383: }
7384: }
1.49.2.28.2.1 (raeburn 7385:: if ($id ne '') {
7386:: $output .= ' id="'.$id.'"';
7387:: }
1.49.2.21 raeburn 7388: $output .= $disabled.'>'."\n";
1.1 raeburn 7389: if ($nullval ne '') {
7390: $output .= '<option value=""';
7391: if (ref($curr) eq 'ARRAY') {
7392: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7393: $output .= ' selected="selected" ';
7394: }
7395: } else {
7396: if ($curr eq '') {
7397: $output .= ' selected="selected" ';
7398: }
7399: }
7400: $output .= '>'.$nullval.'</option>';
7401: }
7402: foreach my $option (@{$order}) {
7403: $output.= '<option value="'.$option.'"';
7404: if (ref($curr) eq 'ARRAY') {
7405: if (grep(/^\Q$option\E$/,@{$curr})) {
7406: $output .= ' selected="selected" ';
7407: }
7408: } else {
7409: if ($option eq $curr) {
7410: $output.=' selected="selected"';
7411: }
7412: }
7413: $output.=">$options->{$option}</option>\n";
7414: }
7415: $output.="</select>";
7416: }
7417: return $output;
7418: }
7419:
7420: sub make_item_rows {
1.49.2.21 raeburn 7421: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
1.1 raeburn 7422: my $datatable;
7423: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7424: my $count = 0;
7425: foreach my $item (@{$ordered}) {
7426: $count ++;
1.49.2.7 raeburn 7427: my $colspan;
7428: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7429: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7430: $colspan = 2;
7431: }
1.49.2.28.2.1 (raeburn 7432:): my $rowdesc;
7433:): if ($caller eq 'appearance') {
7434:): $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7435:): } else {
7436:): $rowdesc = $items->{$item}{text};
7437:): }
1.41 www 7438: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.49.2.28.2.1 (raeburn 7439:): $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7440: } else {
1.49.2.28.2.1 (raeburn 7441:): $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7442: }
1.49.2.6 raeburn 7443: if ($item eq 'defaultcredits') {
7444: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7445: my $showcredits;
7446: if ($defaultcredits ne '') {
7447: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7448: } else {
7449: $showcredits = &mt('No default set');
7450: }
7451: $datatable .= $showcredits;
7452: } elsif ($item eq 'nothideprivileged') {
1.49.2.21 raeburn 7453: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.49.2.7 raeburn 7454: } elsif ($item eq 'checkforpriv') {
1.49.2.21 raeburn 7455: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7456: } elsif ($item eq 'print_header_format') {
1.49.2.21 raeburn 7457: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.49.2.28.2.1 (raeburn 7458:): } elsif ($item eq 'extresource') {
7459:): $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7460: } elsif ($items->{$item}{input} eq 'dates') {
1.49.2.21 raeburn 7461: my $disabled;
7462: if ($noedit) {
7463: $disabled = ' disabled="disabled"';
7464: }
1.1 raeburn 7465: $datatable .=
7466: &Apache::lonhtmlcommon::date_setter('display',$item,
1.49.2.21 raeburn 7467: $settings->{$item},$disabled);
1.1 raeburn 7468: } elsif ($items->{$item}{input} eq 'radio') {
1.49.2.17 raeburn 7469: my ($unsetdefault,$valueyes,$valueno);
1.49.2.28 raeburn 7470: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.49.2.17 raeburn 7471: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7472: unless ($domdefs{$item} eq '0') {
7473: $unsetdefault = 1;
7474: }
7475: $valueyes = "1";
7476: $valueno = "0";
7477: }
1.49.2.21 raeburn 7478: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7479: } elsif ($items->{$item}{input} eq 'selectbox') {
1.49.2.28.2.1 (raeburn 7480:: my $id;
7481:: if ($caller eq 'menuitems') {
7482:: $id = $item;
7483:: }
1.1 raeburn 7484: my $curr = $settings->{$item};
7485: $datatable .=
7486: &select_from_options($item,$items->{$item}{'order'},
7487: $items->{$item}{'options'},$curr,
1.49.2.21 raeburn 7488: $items->{$item}{'nullval'},
1.49.2.28.2.1 (raeburn 7489:: undef,undef,undef,$noedit,$id);
1.1 raeburn 7490: } elsif ($items->{$item}{input} eq 'textbox') {
1.49.2.21 raeburn 7491: my $disabled;
7492: if ($noedit) {
7493: $disabled = ' disabled=disabled"';
7494: }
1.1 raeburn 7495: $datatable .=
7496: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.49.2.21 raeburn 7497: $items->{$item}{size},
7498: $disabled);
1.1 raeburn 7499: }
7500: $datatable .= &item_table_row_end();
7501: }
7502: if (ref($rowtotal)) {
7503: $$rowtotal += scalar(@{$ordered});
7504: }
7505: }
7506: return $datatable;
7507: }
7508:
7509: sub nothidepriv_row {
1.49.2.21 raeburn 7510: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 7511: my ($cnum) = &get_course();
1.49.2.7 raeburn 7512: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 7513: if (ref($settings) eq 'HASH') {
7514: if ($settings->{$item} ne '') {
7515: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
7516: if ($user !~ /:/) {
7517: $nothide{join(':',split(/[\@]/,$user))}=1;
7518: } else {
7519: $nothide{$user} = 1;
7520: }
7521: }
7522: }
1.49.2.7 raeburn 7523: if ($settings->{'checkforpriv'}) {
7524: @checkdoms = split(/,/,$settings->{'checkforpriv'});
7525: }
1.1 raeburn 7526: }
1.49.2.7 raeburn 7527: push(@checkdoms,$cdom);
7528: my %coursepersonnel =
7529: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 7530: my @privusers;
7531: foreach my $person (keys(%coursepersonnel)) {
1.49.2.7 raeburn 7532: my ($uname,$udom,$role) = split(/:/,$person);
7533: my $user = $uname.':'.$udom;
7534: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 7535: if ($end == -1 || $start == -1) {
7536: next;
7537: }
1.49.2.7 raeburn 7538: foreach my $dom (@checkdoms) {
7539: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
7540: unless (grep(/^\Q$user\E$/,@privusers)) {
7541: push(@privusers,$user);
1.3 raeburn 7542: }
7543: }
7544: }
1.1 raeburn 7545: }
1.49.2.7 raeburn 7546: if (@privusers > 0) {
1.49.2.21 raeburn 7547: my $disabled;
7548: if ($noedit) {
7549: $disabled = ' disabled="disabled"';
7550: }
1.1 raeburn 7551: $datatable .= '<table align="right">';
7552: foreach my $user (sort(@privusers)) {
7553: my $hideon = ' checked="checked" ';
7554: my $hideoff = '';
7555: if ($nothide{$user}) {
7556: $hideoff = $hideon;
7557: $hideon = '';
7558: }
7559: my ($uname,$udom) = split(':',$user);
7560: $datatable .= '<tr><td align="left">'.
7561: &Apache::loncommon::aboutmewrapper(
7562: &Apache::loncommon::plainname($uname,$udom,'firstname'),
7563: $uname,$udom,'aboutuser').
7564: '</td><td align="left">'.
7565: '<span class="LC_nobreak"><label>'.
7566: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.49.2.21 raeburn 7567: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.49.2.17 raeburn 7568: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.49.2.21 raeburn 7569: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 7570: '</tr>';
7571: }
7572: $datatable .= '</table>';
7573: } else {
1.9 raeburn 7574: if ($crstype eq 'Community') {
7575: $datatable .= &mt('No Domain Coordinators have community roles');
7576: } else {
7577: $datatable .= &mt('No Domain Coordinators have course roles');
7578: }
1.1 raeburn 7579: }
7580: return $datatable;
7581: }
7582:
1.49.2.7 raeburn 7583: sub checkforpriv_row {
1.49.2.21 raeburn 7584: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.49.2.7 raeburn 7585: my $datatable;
7586: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7587: if (keys(%domains) == 1) {
7588: $datatable = '</td><td align="right">'.
7589: &mt("Course's domain is only domain");
7590: return $datatable;
7591: }
7592: my @excdoms = ($cdom);
7593: my $num = 0;
7594: if ($settings->{$item} eq '') {
7595: $datatable = '</td><td align="right">'.
7596: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.49.2.21 raeburn 7597: 1,1,undef,undef,\@excdoms,
7598: $noedit);
1.49.2.7 raeburn 7599: } else {
7600: my @privdoms = split(/,/,$settings->{$item});
7601: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
7602: $datatable = '</td><td align="right"><br />'.
7603: &Apache::loncommon::start_data_table();
1.49.2.21 raeburn 7604: my $disabled;
7605: if ($noedit) {
7606: $disabled = ' disabled="disabled"';
7607: }
1.49.2.7 raeburn 7608: if (@privdoms > 0) {
7609: foreach my $currdom (@privdoms) {
7610: next unless ($domains{$currdom});
7611: my $domdesc = &Apache::lonnet::domain($currdom,'description');
7612: if ($domdesc eq '') {
7613: $domdesc = $currdom;
7614: }
7615: $datatable .=
7616: &Apache::loncommon::start_data_table_row().
7617: '<td align="left"><span class="LC_nobreak">'.
7618: &mt('Domain:').'<b> '.$domdesc.
7619: '</b><input type="hidden" name="checkforpriv_'.$num.
7620: '" value="'.$currdom.'" /></span><br />'.
7621: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.49.2.21 raeburn 7622: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
1.49.2.7 raeburn 7623: &mt('Delete').'</label></span></td>'.
7624: &Apache::loncommon::end_data_table_row();
7625: $num ++;
7626: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
7627: push(@excdoms,$currdom);
7628: }
7629: }
7630: }
7631: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
7632: $datatable .=
7633: &Apache::loncommon::start_data_table_row().
7634: '<td align="left"><span class="LC_nobreak">'.
7635: &mt('Additional domain:'). '</span><br />'.
7636: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.49.2.21 raeburn 7637: 1,undef,undef,\@excdoms,$noedit).
1.49.2.7 raeburn 7638: '</td>'.&Apache::loncommon::end_data_table_row();
7639: }
7640: $datatable .= &Apache::loncommon::end_data_table().
7641: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
7642: '<br />';
7643: }
7644: return $datatable;
7645: }
7646:
1.1 raeburn 7647: sub print_hdrfmt_row {
1.49.2.21 raeburn 7648: my ($item,$settings,$noedit) = @_;
1.1 raeburn 7649: my @curr;
7650: my $currnum = 0;
7651: my $maxnum = 2;
7652: my $currstr;
7653: if ($settings->{$item} ne '') {
7654: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
7655: $settings->{$item}.'</tt></span></b><br />';
7656: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 7657: foreach my $val (@current) {
7658: unless ($val eq '') {
7659: push(@curr,$val);
1.1 raeburn 7660: }
7661: }
7662: $currnum = @curr;
7663: $maxnum += $currnum;
7664: }
7665:
7666: my $output = <<ENDJS;
7667:
7668: <script type="text/javascript" language="Javascript">
7669:
7670: function reOrder(chgnum) {
7671: var maxnum = $maxnum;
7672: var oldidx = 'printfmthdr_oldpos_'+chgnum;
7673: var newidx = 'printfmthdr_pos_'+chgnum;
7674: oldidx = getIndexByName(oldidx);
7675: newidx = getIndexByName(newidx);
7676: var oldpos = document.display.elements[oldidx].value;
7677: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7678: document.display.elements[oldidx].value = newpos;
7679: var chgtype = 'up';
7680: if (newpos < oldpos) {
7681: chgtype = 'down';
7682: }
7683: for (var j=0; j<maxnum; j++) {
7684: if (j != chgnum) {
7685: oldidx = 'printfmthdr_oldpos_'+j;
7686: newidx = 'printfmthdr_pos_'+j;
7687: oldidx = getIndexByName(oldidx);
7688: newidx = getIndexByName(newidx);
7689: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7690: var currsel = document.display.elements[newidx].selectedIndex;
7691: if (chgtype == 'up') {
7692: if ((currpos > oldpos) && (currpos <= newpos)) {
7693: document.display.elements[newidx].selectedIndex = currsel-1;
7694: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7695: }
7696: } else {
7697: if ((currpos >= newpos) && (currpos < oldpos)) {
7698: document.display.elements[newidx].selectedIndex = currsel+1;
7699: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
7700: }
7701: }
7702: }
7703: }
7704: return;
7705: }
7706:
7707: function getIndexByName(item) {
7708: for (var i=0;i<document.display.elements.length;i++) {
7709: if (document.display.elements[i].name == item) {
7710: return i;
7711: }
7712: }
7713: return -1;
7714: }
7715:
7716: </script>
7717:
7718: ENDJS
1.49.2.7 raeburn 7719: $output .= '</td><td align="right"><br />'.
7720: $currstr.'<table class="LC_data_table">';
1.49.2.21 raeburn 7721: my $disabled;
7722: if ($noedit) {
7723: $disabled = ' disabled="disabled"';
7724: }
1.1 raeburn 7725: if (@curr > 0) {
7726: for (my $i=0; $i<@curr; $i++) {
7727: my $pos = $i+1;
1.10 raeburn 7728: $output .= '<tr>'.
1.1 raeburn 7729: '<td align="left"><span class="LC_nobreak">'.
1.49.2.21 raeburn 7730: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 7731: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.49.2.21 raeburn 7732: '"'.$disabled.' /></span></td>';
1.1 raeburn 7733: if ($curr[$i] =~ /^%\d*[nca]$/) {
7734: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
7735: $output .= '<td align="left">'.
1.49.2.21 raeburn 7736: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 7737: } else {
7738: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
7739: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.49.2.21 raeburn 7740: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 7741: }
1.10 raeburn 7742: $output .= '</tr>';
1.1 raeburn 7743: }
7744: }
1.49.2.28.2.1 (raeburn 7745:): my $pos = $currnum+1;
1.49.2.21 raeburn 7746: unless ($noedit) {
7747: $output .=
7748: '<tr>'.
1.1 raeburn 7749: '<td align="left"><span class="LC_nobreak">'.
7750: &position_selector($pos,$currnum,$maxnum).
7751: '<b>'.&mt('New').'</b></span></td><td align="left">'.
7752: &substitution_selector($currnum).'</td>'.
1.10 raeburn 7753: '</tr>';
1.49.2.21 raeburn 7754: $pos ++;
7755: $currnum ++;
7756: $output .=
7757: '<tr>'.
1.1 raeburn 7758: '<td align="left"><span class="LC_nobreak">'.
7759: &position_selector($pos,$currnum,$maxnum).
7760: '<b>'.&mt('New').'</b></span></td>'.
7761: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
7762: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 7763: '" value="" size ="25" />'.
7764: '<input type="hidden" name="printfmthdr_maxnum" value="'.
7765: $maxnum.'" /></td>'.
1.49.2.21 raeburn 7766: '</tr>';
7767: }
7768: $output .= '</table><br />';
1.1 raeburn 7769: return $output;
7770: }
7771:
7772: sub position_selector {
1.49.2.21 raeburn 7773: my ($pos,$num,$maxnum,$disabled) = @_;
7774: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 7775: for (my $j=1; $j<=$maxnum; $j++) {
7776: my $sel = '';
7777: if ($pos == $j) {
7778: $sel = ' selected="selected"';
7779: }
7780: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
7781: }
7782: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
7783: '" value="'.$pos.'" />';
7784: return $output;
7785: }
7786:
7787: sub substitution_selector {
1.49.2.21 raeburn 7788: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 7789: my ($stunametxt,$crsidtxt);
7790: if ($crstype eq 'Community') {
7791: $stunametxt = 'member name';
7792: $crsidtxt = 'community ID',
7793: } else {
7794: $stunametxt = 'student name';
7795: $crsidtxt = 'course ID',
7796: }
1.1 raeburn 7797: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 7798: n => $stunametxt,
7799: c => $crsidtxt,
1.1 raeburn 7800: a => 'assignment note',
7801: );
7802: my $output .= &mt('Substitution').'<br />'.
1.49.2.21 raeburn 7803: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 7804: if ($subst eq '') {
7805: $output .= '<option value="" selected="selected"> </option>';
7806: }
7807: foreach my $field ('n','c','a') {
7808: my $sel ='';
7809: if ($subst eq $field) {
7810: $sel = ' selected="selected"';
7811: }
7812: $output .= '<option value="'.$field.'"'.$sel.'>'.
7813: $lt{$field}.'</option>';
7814: }
7815: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
7816: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.49.2.21 raeburn 7817: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 7818: return $output;
7819: }
7820:
1.23 raeburn 7821: sub change_clone {
7822: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
7823: my $clone_crs = $cnum.':'.$cdom;
7824: if ($cnum && $cdom) {
7825: my $clone_crs = $cnum.':'.$cdom;
7826: my @allowclone;
7827: if ($clonelist =~ /,/) {
7828: @allowclone = split(',',$clonelist);
7829: } else {
7830: $allowclone[0] = $clonelist;
7831: }
7832: foreach my $currclone (@allowclone) {
7833: if (!grep(/^$currclone$/,@$oldcloner)) {
7834: if ($currclone ne '*') {
1.49.2.18 raeburn 7835: if ($currclone =~ /:/) {
7836: my ($uname,$udom) = split(/:/,$currclone);
7837: if ($uname && $udom && $uname ne '*') {
7838: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
7839: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
7840: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
7841: if ($currclonecrs{'cloneable'} eq '') {
7842: $currclonecrs{'cloneable'} = $clone_crs;
7843: } else {
7844: $currclonecrs{'cloneable'} .= ','.$clone_crs;
7845: }
7846: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 7847: }
7848: }
7849: }
7850: }
7851: }
7852: }
7853: }
7854: foreach my $oldclone (@$oldcloner) {
7855: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
7856: if ($oldclone ne '*') {
1.49.2.18 raeburn 7857: if ($oldclone =~ /:/) {
7858: my ($uname,$udom) = split(/:/,$oldclone);
7859: if ($uname && $udom && $uname ne '*' ) {
7860: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
7861: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
7862: my %newclonecrs = ();
7863: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
7864: if ($currclonecrs{'cloneable'} =~ /,/) {
7865: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
7866: foreach my $crs (@currclonecrs) {
7867: if ($crs ne $clone_crs) {
7868: $newclonecrs{'cloneable'} .= $crs.',';
7869: }
1.23 raeburn 7870: }
1.49.2.18 raeburn 7871: $newclonecrs{'cloneable'} =~ s/,$//;
7872: } else {
7873: $newclonecrs{'cloneable'} = '';
1.23 raeburn 7874: }
1.49.2.18 raeburn 7875: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 7876: }
7877: }
7878: }
7879: }
7880: }
7881: }
7882: }
7883: }
7884: return;
7885: }
7886:
1.49.2.28.2.8 (raeburn 7887:: sub devalidate_remote_courseprefs {
7888:: my ($cdom,$cnum,$cachekeys) = @_;
7889:: return unless (ref($cachekeys) eq 'HASH');
7890:: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
7891:: my %thismachine;
7892:: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.49.2.28.2.1 (raeburn 7893:): my @posscached = ('courselti','courseltitools');
1.49.2.28.2.8 (raeburn 7894:: if (keys(%servers)) {
7895:: foreach my $server (keys(%servers)) {
7896:: next if ($thismachine{$server});
7897:: my @cached;
7898:: foreach my $name (@posscached) {
7899:: if ($cachekeys->{$name}) {
7900:: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
7901:: }
7902:: }
7903:: if (@cached) {
7904:: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
7905:: }
7906:: }
7907:: }
7908:: return;
7909:: }
7910::
1.1 raeburn 7911: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>