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