Annotation of loncom/interface/courseprefs.pm, revision 1.127
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.127 ! raeburn 4: # $Id: courseprefs.pm,v 1.126 2023/09/02 12:51:32 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.23 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: courseprefs- Handler to set/modify course configuration
36:
37: =head1 SYNOPSIS
38:
39: courseprefs provides an interface for setting general course configuration
40:
41: =head1 DESCRIPTION
42:
43: This module is used for configuration of a course
44:
45: =head1 INTERNAL SUBROUTINES
46:
47: =over
48:
49: =item get_allitems()
50:
51: =item print_config_box()
52:
53: =item process_changes()
54:
1.102 raeburn 55: =item process_linkprot()
56:
1.23 raeburn 57: =item get_sec_str()
58:
59: =item check_clone()
60:
61: =item store_changes()
62:
1.102 raeburn 63: =item store_linkprot()
64:
1.23 raeburn 65: =item update_env()
66:
67: =item display_disallowed()
68:
69: =item get_course()
70:
71: =item get_jscript()
72:
73: =item cloners_javascript()
74:
75: =item print_courseinfo()
76:
77: =item new_cloners_dom_row()
78:
79: =item can_modify_catsettings()
80:
81: =item assign_course_categories()
82:
83: =item print_localization()
84:
85: =item get_lang_choices()
86:
87: =item print_feedback()
88:
89: =item user_table()
90:
91: =item select_recipient()
92:
93: =item select_sections()
94:
95: =item print_discussion()
96:
97: =item role_checkboxes()
98:
99: =item print_classlists()
100:
101: =item print_appearance()
102:
103: =item print_grading()
104:
105: =item print_printouts()
106:
107: =item print_spreadsheet()
108:
109: =item print_bridgetasks()
110:
111: =item print_other()
112:
113: =item get_other_items()
114:
115: =item item_table_row_start()
116:
117: =item item_table_row_end()
118:
1.115 raeburn 119: =item yesno_radio()
1.23 raeburn 120:
121: =item select_from_options()
122:
123: =item make_item_rows()
124:
125: Creates table used to display and set course configuration items.
126:
127: Inputs: $cdom,$items,$ordered,$settings,$rowtotal,$crstype
128: where $cdom is course's domain, $items is HASH ref for current config
129: item, $ordered is ARRAY ref of items to include in row in
130: display order, $settings is HASH ref of current values forrow,
131: $rowtotal is SCALAR ref used to accumulate row count, $crstype is
132: course type.
133:
134: Returns: $datatable
135: HTML mark-up of data table which accumulates individual rows.
136:
137: =item nothidepriv_row()
138:
139: Creates row containing form elements used to display and set
140: whether Domain coordinators who are currently included in
141: advanced course user .db file for a course are to be hidden (e.g.,
142: in syllabus, or from course user lists).
143:
1.80 raeburn 144: Inputs: $cdom,$item,$settings,$crstype,$noedit
1.23 raeburn 145: where $cdom is course domain, item is nothideprivileged, $settings is
146: HASH ref of the current values for nothideprivileged, $crstype is
147: course type (Course or Community).
148:
149: Return: $datatable
150: HTML mark-up for Privileged users (Domain Coordinators) in staff listing.
151:
152: =item print_hdrfmt_row()
153:
154: Creates row containing form elements used to display and set
155: substitution items and text to be used in the header included
156: on printouts.
157:
158: Inputs: $item,$settings
159: where $item is print_header_format, and $settings is a HASH ref
160: of the current values stored for print_header_format.
161:
162: Returns: $output
163: HTML mark-up containing Javascript functions: reOrder() and getIndexByName()
164: used to dynamically update position selectboxes, and HTML table elements
165: for the "Print header format" row.
166:
167: =item position_selector()
168:
169: Creates a select box which can be used to reorder substitutions
170: and text included in a printout header.
171:
172: Inputs: $pos,$num,$maxnum
173: where $pos is current position, $num is the unique identifier,
174: and $maxnum is the total number of items (both substitutions
175: and text in the printout header.
176:
177: Returns: $output
178: HTML mark-up for the selectbox and a hidden form element containing
179: the current position.
180:
181: =item substitution_selector()
182:
183: Creates a combination of select box for choosing an item
184: (student name, course ID or assignment note) to substitute,
185: and a corresponding size limit in the header used for printouts.
186:
187: Inputs: $num,$subst,$limit,$crstype
188: where $num is the unique identifier, $subst is the current
189: substitution (n,c or a, for name, course or note respectively,
190: $limit is the current size limit (integer), and $crstype is
191: course type - course or community.
192:
193: Returns: $output
194: HTML mark-up for selectbox and textbox (separate table cells).
195:
196: =item change_clone()
197:
198: Modifies the list of courses a user can clone (stored
199: in the user's environment.db file), called when a
200: change is made to the list of users allowed to clone
201: a course.
202:
203: Inputs: $action,$cloner
204: where $action is add or drop, and $cloner is identity of
205: user for whom cloning ability is to be changed in course.
206:
207: Returns: nothing
208:
209: =back
210:
211: =cut
212:
213:
1.1 raeburn 214: package Apache::courseprefs;
215:
216: use strict;
217: use Apache::Constants qw(:common :http);
218: use Apache::lonnet;
219: use Apache::loncommon();
220: use Apache::lonhtmlcommon();
221: use Apache::lonconfigsettings;
1.66 raeburn 222: use Apache::lonrelrequtils;
1.36 raeburn 223: use Apache::lonparmset;
1.71 raeburn 224: use Apache::courseclassifier;
1.1 raeburn 225: use Apache::lonlocal;
226: use LONCAPA qw(:DEFAULT :match);
1.103 raeburn 227: use Crypt::CBC;
1.118 raeburn 228: use Time::HiRes qw( sleep );
1.1 raeburn 229:
1.66 raeburn 230: my $registered_cleanup;
231: my $modified_courses;
232:
1.1 raeburn 233: sub handler {
234: my $r=shift;
235: if ($r->header_only) {
236: &Apache::loncommon::content_type($r,'text/html');
237: $r->send_http_header;
238: return OK;
239: }
240: my $context = 'course';
241: my $cid = $env{'request.course.id'};
1.66 raeburn 242: my ($cnum,$cdom,$chome) = &get_course($cid);
1.1 raeburn 243: my $crstype = &Apache::loncommon::course_type();
1.80 raeburn 244: my ($parm_permission,$allowed) = &get_permission($cid);
1.1 raeburn 245: my $navmap = Apache::lonnavmaps::navmap->new();
1.80 raeburn 246: if ($allowed && $navmap) {
1.1 raeburn 247: &Apache::loncommon::content_type($r,'text/html');
248: $r->send_http_header;
249: } else {
250: if ($navmap) {
1.9 raeburn 251: if ($crstype eq 'Community') {
252: $env{'user.error.msg'}=
253: "/adm/courseprefs:opa:0:0:Cannot modify community settings";
254: } else {
255: $env{'user.error.msg'}=
256: "/adm/courseprefs:opa:0:0:Cannot modify course settings";
257: }
1.1 raeburn 258: } else {
1.9 raeburn 259: if ($crstype eq 'Community') {
260: $env{'user.error.msg'}=
261: "/adm/courseprefs::0:1:Course environment gone, reinitialize the community";
262: } else {
263: $env{'user.error.msg'}=
264: "/adm/courseprefs::0:1:Course environment gone, reinitialize the course";
265:
266: }
1.1 raeburn 267: }
268: return HTTP_NOT_ACCEPTABLE;
269: }
270:
1.66 raeburn 271: $registered_cleanup=0;
272: @{$modified_courses}=();
273:
1.4 raeburn 274: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
275: ['phase','actions','origin']);
1.1 raeburn 276: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.4 raeburn 277: if ($env{'form.origin'} eq 'params') {
278: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
279: text=>"Parameter Manager"});
280: }
1.9 raeburn 281: my ($brtext,$brtitle,$crsinfotext,$crsinfodesc,$crscateg,$crshide);
282: my %lt;
283: if ($crstype eq 'Community') {
284: %lt = (
1.40 www 285: conf => 'Community Settings',
286: edit => 'Edit Community Settings',
1.9 raeburn 287: gens => 'General community settings',
288: idnu => 'Community ID or number',
1.64 raeburn 289: unco => 'Unique code',
1.9 raeburn 290: desc => 'Community Description',
1.24 raeburn 291: ownr => 'Community Owner',
1.25 raeburn 292: cown => 'Community Co-owners',
1.9 raeburn 293: catg => 'Categorize community',
294: excc => 'Exclude from community catalog',
295: clon => 'Users allowed to clone community',
296: rept => 'Replacement titles for standard community roles',
1.115 raeburn 297: time => 'Time Zone where the community is located',
1.9 raeburn 298: date => 'Locale used for community calendar',
299: coco => 'Community Content',
300: copo => 'Community Policy',
1.13 bisitz 301: priv => 'Domain Coordinators in community',
1.9 raeburn 302: defd => 'Default dates for member access',
303: stuv => 'Member-viewable membership list options',
304: stul => 'Member agreement needed to be listed',
1.42 www 305: clas => 'Membership and facilitator listing',
1.57 raeburn 306: prus => 'Privileged users (Domain Coordinators) in facilitator listing',
1.9 raeburn 307: defc => 'Default Community Spreadsheet',
308: defs => 'Default User Spreadsheet',
309: seme => 'Send message to member when clicking Done on Tasks'
310: );
311: } else {
312: %lt = (
1.40 www 313: conf => 'Course Settings',
314: edit => 'Edit Course Settings',
1.20 faziophi 315: gens => 'General course settings',
316: idnu => 'Course ID or number',
1.64 raeburn 317: unco => 'Unique code',
1.20 faziophi 318: desc => 'Course Description',
1.124 raeburn 319: cred => 'Student credits',
1.24 raeburn 320: ownr => 'Course Owner',
1.25 raeburn 321: cown => 'Course Co-owners',
1.9 raeburn 322: catg => 'Categorize course',
323: excc => 'Exclude from course catalog',
324: clon => 'Users allowed to clone course',
325: rept => 'Replacement titles for standard course roles',
1.115 raeburn 326: time => 'Time Zone in which the course takes place',
1.20 faziophi 327: date => 'Locale used for course calendar',
1.9 raeburn 328: coco => 'Course Content',
329: copo => 'Course Policy',
1.13 bisitz 330: priv => 'Domain Coordinators in course',
1.9 raeburn 331: defd => 'Default dates for student access',
332: stuv => 'Student-viewable classlist options',
333: stul => 'Student agreement needed to be listed',
1.42 www 334: clas => 'Classlists and staff listing',
1.57 raeburn 335: prus => 'Privileged users (Domain Coordinators) in staff listing',
1.56 raeburn 336: prdo => "Domains to check for privileged users (besides course's domain)",
1.9 raeburn 337: defc => 'Default Course Spreadsheet',
338: defs => 'Default Student Spreadsheet',
339: seme => 'Send message to student when clicking Done on Tasks',
340: );
341: }
1.35 raeburn 342: $lt{'lcrv'} = 'Required LON-CAPA version';
1.1 raeburn 343: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/courseprefs',
1.9 raeburn 344: text=>$lt{'conf'}});
1.1 raeburn 345: my $breadcrumbs =
1.9 raeburn 346: &Apache::lonhtmlcommon::breadcrumbs($lt{'edit'});
1.1 raeburn 347:
348: my $phase = 'pickactions';
349: if ( exists($env{'form.phase'}) ) {
350: $phase = $env{'form.phase'};
351: }
352:
1.80 raeburn 353: if (($phase eq 'categorizecourse') && ($parm_permission->{'categorizecourse'})) {
1.9 raeburn 354: &assign_course_categories($r,$crstype);
1.1 raeburn 355: return OK;
356: }
357:
1.80 raeburn 358: if (($phase eq 'releaseinfo') && ($parm_permission->{'releaseinfo'})) {
1.36 raeburn 359: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
360: if ($loncaparev) {
1.66 raeburn 361: if (&display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype)) {
362: push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
363: unless ($registered_cleanup) {
364: my $handlers = $r->get_handlers('PerlCleanupHandler');
365: $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
366: $registered_cleanup=1;
367: }
368: }
1.36 raeburn 369: return OK;
370: }
371: }
372:
1.1 raeburn 373: my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.102 raeburn 374: my %linkprot=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1.99 raeburn 375: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
1.118 raeburn 376: my %ltitools = &Apache::lonnet::dump('ltitools',$cdom,$cnum,undef,undef,undef,1);
377: my %ltitoolsenc = &Apache::lonnet::dump('nohist_toolsenc',$cdom,$cnum,undef,undef,undef,1);
1.102 raeburn 378: foreach my $id (keys(%linkprot)) {
379: if (ref($linkprot{$id}) eq 'HASH') {
1.99 raeburn 380: if (ref($ltienc{$id}) eq 'HASH') {
1.102 raeburn 381: $values{'linkprot'}{$id} = { %{$linkprot{$id}}, %{$ltienc{$id}} };
1.99 raeburn 382: } else {
1.102 raeburn 383: $values{'linkprot'}{$id} = $linkprot{$id};
1.99 raeburn 384: }
385: }
386: unless ($phase eq 'process') {
1.102 raeburn 387: if (ref($values{'linkprot'}{$id}) eq 'HASH') {
388: delete($values{'linkprot'}{$id}{'secret'});
1.99 raeburn 389: }
390: }
391: }
1.102 raeburn 392: if ($linkprot{'lock'}) {
393: delete($linkprot{'lock'});
1.93 raeburn 394: }
1.118 raeburn 395: foreach my $id (keys(%ltitools)) {
396: if (ref($ltitools{$id}) eq 'HASH') {
397: if (ref($ltitoolsenc{$id}) eq 'HASH') {
398: $values{'ltitools'}{$id} = { %{$ltitools{$id}}, %{$ltitoolsenc{$id}} };
399: } else {
400: $values{'ltitools'}{$id} = $ltitools{$id};
401: }
402: }
403: unless ($phase eq 'process') {
404: if (ref($values{'ltitools'}{$id}) eq 'HASH') {
405: delete($values{'ltitools'}{$id}{'secret'});
406: }
407: }
408: }
409: if ($ltitools{'lock'}) {
410: delete($ltitools{'lock'});
411: }
1.1 raeburn 412: my @prefs_order = ('courseinfo','localization','feedback','discussion',
413: 'classlists','appearance','grading','printouts',
1.118 raeburn 414: 'menuitems','ltitools','linkprot','spreadsheet',
415: 'bridgetasks','lti','other');
1.1 raeburn 416: my %prefs = (
417: 'courseinfo' =>
1.9 raeburn 418: { text => $lt{'gens'},
1.44 www 419: help => 'Course_Prefs_General',
1.35 raeburn 420: ordered => ['owner','co-owners','loncaparev','description',
1.64 raeburn 421: 'clonedfrom','courseid','uniquecode','categories',
1.88 raeburn 422: 'hidefromcat','syllabus','cloners','url',
1.64 raeburn 423: 'rolenames'],
1.3 raeburn 424: itemtext => {
1.25 raeburn 425: 'owner' => $lt{'ownr'},
426: 'co-owners' => $lt{'cown'},
427: 'description' => $lt{'desc'},
428: 'courseid' => $lt{'idnu'},
1.64 raeburn 429: 'uniquecode' => $lt{'unco'},
1.25 raeburn 430: 'categories' => $lt{'catg'},
431: 'hidefromcat' => $lt{'excc'},
432: 'cloners' => $lt{'clon'},
1.88 raeburn 433: 'syllabus' => 'Syllabus status',
1.25 raeburn 434: 'url' => 'Top Level Map',
435: 'rolenames' => $lt{'rept'},
1.35 raeburn 436: 'loncaparev' => $lt{'lcrv'},
1.63 raeburn 437: 'clonedfrom' => 'Cloned from',
1.3 raeburn 438: },
1.1 raeburn 439: },
440: 'localization' =>
1.42 www 441: { text => 'Language and time localization',
1.44 www 442: help => 'Course_Prefs_Language',
1.1 raeburn 443: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 444: itemtext => {
1.20 faziophi 445: languages => 'Languages used',
1.9 raeburn 446: timezone => $lt{'time'},
447: datelocale => $lt{'date'},
1.3 raeburn 448: },
1.1 raeburn 449: },
450: 'feedback' =>
1.20 faziophi 451: { text => 'Feedback messages',
1.44 www 452: help => 'Course_Prefs_Feedback',
1.1 raeburn 453: header => [{col1 => 'Questions about:',
1.20 faziophi 454: col2 => 'Recipients'}],
1.3 raeburn 455: ordered => ['question.email','comment.email','policy.email'],
456: itemtext => {
457: 'question.email' => 'Resource Content',
1.9 raeburn 458: 'comment.email' => $lt{'coco'},
459: 'policy.email' => $lt{'copo'},
1.3 raeburn 460: },
1.1 raeburn 461: },
462: 'discussion' =>
463: { text => 'Discussion and Chat',
1.44 www 464: help => 'Course_Prefs_Discussions',
1.31 raeburn 465: ordered => ['pch.roles.denied','pch.users.denied',
1.77 raeburn 466: 'pac.roles.denied','pac.users.denied',
1.31 raeburn 467: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 468: 'allow_limited_html_in_feedback',
1.50 raeburn 469: 'allow_discussion_post_editing',
470: 'discussion_post_fonts'],
1.3 raeburn 471: itemtext => {
1.31 raeburn 472: 'pch.roles.denied' => 'No Resource Discussion',
473: 'pch.users.denied' => 'No Resource Discussion',
474: 'plc.roles.denied' => 'No Chat room use',
475: 'plc.users.denied' => 'No Chat room use',
1.77 raeburn 476: 'pac.roles.denied' => 'No Anonymous Resource Discussion',
477: 'pac.users.denied' => 'No Anonymous Resource Discussion',
1.20 faziophi 478: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
479: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.77 raeburn 480: discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 481: },
1.1 raeburn 482: },
483: 'classlists' =>
1.9 raeburn 484: { text => $lt{'clas'},
1.44 www 485: help => 'Course_Prefs_Classlists',
1.1 raeburn 486: header => [{col1 => 'Type',
1.9 raeburn 487: col2 => $lt{'defd'}},
1.1 raeburn 488: {col1 => 'Setting',
1.9 raeburn 489: col2 => $lt{'priv'}},
1.1 raeburn 490: {col1 => 'Setting',
1.9 raeburn 491: col2 => $lt{'stuv'}}],
1.1 raeburn 492: ordered => ['default_enrollment_start_date',
493: 'default_enrollment_end_date',
1.55 raeburn 494: 'defaultcredits',
1.56 raeburn 495: 'nothideprivileged','checkforpriv',
496: 'student_classlist_view',
1.26 raeburn 497: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 498: itemtext => {
499: default_enrollment_start_date => 'Start date',
500: default_enrollment_end_date => 'End date',
1.57 raeburn 501: nothideprivileged => $lt{'prus'},
1.56 raeburn 502: checkforpriv => $lt{'prdo'},
1.9 raeburn 503: student_classlist_view => $lt{'stuv'},
1.26 raeburn 504: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 505: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.55 raeburn 506: defaultcredits => $lt{'cred'},
1.3 raeburn 507: },
1.1 raeburn 508: },
509: 'appearance' =>
1.20 faziophi 510: { text => 'Display of resources ',
1.44 www 511: help => 'Course_Prefs_Display',
1.1 raeburn 512: ordered => ['default_xml_style','pageseparators',
513: 'disable_receipt_display','texengine',
1.114 raeburn 514: 'tthoptions','uselcmath','usejsme',
515: 'inline_chem','extresource'],
1.3 raeburn 516: itemtext => {
1.17 faziophi 517: default_xml_style => 'Default XML style file',
1.20 faziophi 518: pageseparators => 'Visibly Separate Items on Pages',
519: disable_receipt_display => 'Disable display of problem receipts',
520: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 521: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.69 raeburn 522: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
523: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.95 raeburn 524: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.124 raeburn 525: extresource => 'Display of external resources',
1.3 raeburn 526: },
1.1 raeburn 527: },
528: 'grading' =>
529: { text => 'Grading',
1.44 www 530: help => 'Course_Prefs_Grading',
1.1 raeburn 531: ordered => ['grading','rndseed',
532: 'receiptalg','disablesigfigs'],
1.3 raeburn 533: itemtext => {
1.20 faziophi 534: grading => 'Grading',
535: rndseed => 'Randomization algorithm used',
536: receiptalg => 'Receipt algorithm used',
537: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 538: },
539:
1.1 raeburn 540: },
541: 'printouts' =>
1.20 faziophi 542: { text => 'Printout generation',
1.44 www 543: help => 'Course_Prefs_Printouts',
1.1 raeburn 544: ordered => ['problem_stream_switch','suppress_tries',
545: 'default_paper_size','print_header_format',
1.14 raeburn 546: 'disableexampointprint','canuse_pdfforms'],
1.3 raeburn 547: itemtext => {
548: problem_stream_switch => 'Allow problems to be split over pages',
549: suppress_tries => 'Suppress number of tries in printing',
550: default_paper_size => 'Default paper type',
551: print_header_format => 'Print header format',
1.51 bisitz 552: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 553: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 554: },
1.1 raeburn 555: },
556: 'spreadsheet' =>
557: { text => 'Spreadsheets',
1.44 www 558: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 559: ordered => ['spreadsheet_default_classcalc',
560: 'spreadsheet_default_studentcalc',
561: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 562: itemtext => {
1.9 raeburn 563: spreadsheet_default_classcalc => $lt{'defc'},
564: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 565: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
566: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
567: },
1.1 raeburn 568: },
569: 'bridgetasks' =>
570: { text => 'Bridge tasks',
1.44 www 571: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 572: ordered => ['task_messages','task_grading',
573: 'suppress_embed_prompt'],
1.3 raeburn 574: itemtext => {
1.9 raeburn 575: task_messages => $lt{'seme'},
1.3 raeburn 576: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 577: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 578: },
1.1 raeburn 579: },
1.87 raeburn 580: 'lti' =>
581: {
582: text => 'LTI provider settings',
583: help => 'Course_Prefs_LTIProvider',
584: ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'],
585: itemtext => {
586: 'lti.override' => 'Override domain defaults',
587: 'lti.topmenu' => 'Display LON-CAPA page header',
588: 'lti.inlinemenu' => 'Display LON-CAPA inline menu',
589: 'lti.lcmenu' => 'Menu items',
590: },
591: },
1.91 raeburn 592: 'menuitems' =>
593: {
594: text => 'Menu display',
595: help => 'Course_Prefs_Menus',
596: header => [{col1 => 'Default Menu',
597: col2 => 'Value',},
598: {col1 => 'Menu collections',
599: col2 => 'Settings',
600: }],
601: ordered => ['menudefault','menucollections'],
602: itemtext => {
603: menudefault => 'Choose default collection of menu items for course',
604: menucollections => 'Menu collections',
605: },
606: },
1.102 raeburn 607: 'linkprot' =>
1.93 raeburn 608: {
609: text => 'Link protection',
610: help => 'Course_Prefs_Linkprotection',
611: header => [{col1 => 'Item',
612: col2 => 'Settings',
613: }],
614: },
1.118 raeburn 615: 'ltitools' =>
616: {
617: text => 'External tools',
618: help => 'Course_Prefs_ExternalTools',
619: header => [{col1 => 'Item',
620: col2 => 'Settings',
621: }],
622: },
1.1 raeburn 623: 'other' =>
624: { text => 'Other settings',
1.44 www 625: help => 'Course_Prefs_Other',
1.1 raeburn 626: header => [ {col1 => 'Item',
627: col2 => 'Value',
628: }],
629: },
630: );
1.80 raeburn 631: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 632: my @allitems = &get_allitems(%prefs);
1.108 raeburn 633: my $result = &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
634: \@prefs_order,\%prefs,\%values,
635: $cnum,undef,\@allitems,
636: 'coursepref',$parm_permission);
637: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
638: $r->rflush();
639: &devalidate_remote_courseprefs($cdom,$cnum,$result);
640: }
1.80 raeburn 641: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.91 raeburn 642: my $noedit;
643: if (ref($parm_permission) eq 'HASH') {
644: unless ($parm_permission->{'process'}) {
645: $noedit = 1;
646: }
647: }
648: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 649: my @allitems = &get_allitems(%prefs);
1.1 raeburn 650: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.99 raeburn 651: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.80 raeburn 652: 'coursepref',$parm_permission);
1.1 raeburn 653: } else {
654: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.80 raeburn 655: \@prefs_order,\%prefs,
656: 'coursepref',$parm_permission);
1.1 raeburn 657: }
658: return OK;
659: }
660:
1.80 raeburn 661: sub get_permission {
662: my ($cid) = @_;
663: my %permission;
664: my $allowed = 0;
665: return (\%permission,$allowed) unless ($cid);
666: if (&Apache::lonnet::allowed('opa',$cid)) {
667: %permission= (
668: 'pickactions' => 1,
669: 'categorizecourse' => 1,
670: 'releaseinfo' => 1,
671: 'process' => 1,
672: 'display' => 1,
673: );
674: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
675: %permission = (
676: 'pickactions' => 1,
677: 'releaseinfo' => 1,
678: 'display' => 1,
679: );
680: }
681: foreach my $perm (values(%permission)) {
682: if ($perm) { $allowed=1; last; }
683: }
684: return (\%permission,$allowed);
685: }
686:
1.3 raeburn 687: sub get_allitems {
688: my (%prefs) = @_;
689: my @allitems;
690: foreach my $item (keys(%prefs)) {
691: if (ref($prefs{$item}) eq 'HASH') {
692: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
693: push(@allitems,@{$prefs{$item}{'ordered'}});
694: if ($item eq 'feedback') {
695: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
696: }
1.126 raeburn 697: } elsif (($item eq 'linkprot') || ($item eq 'ltitools')) {
698: push(@allitems,$item);
1.3 raeburn 699: }
700: }
701: }
702: return @allitems;
703: }
704:
1.1 raeburn 705: sub print_config_box {
1.99 raeburn 706: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 707: my $ordered = $item->{'ordered'};
1.3 raeburn 708: my $itemtext = $item->{'itemtext'};
1.80 raeburn 709: my $noedit;
710: if (ref($parm_permission) eq 'HASH') {
711: unless ($parm_permission->{'process'}) {
712: $noedit = 1;
713: }
714: }
1.1 raeburn 715: my $rowtotal = 0;
716: my $output =
1.45 www 717: '<table class="LC_nested_outer">
718: <tr>
719: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 720: &mt($item->{text});
721: if ($item->{'help'}) {
1.53 raeburn 722: $output .= ' '.
1.52 raeburn 723: &Apache::loncommon::help_open_topic($item->{'help'});
724: }
725: $output .= '</span></th>'."\n".
726: '</tr>';
1.91 raeburn 727: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 728: $output .= '
1.45 www 729: <tr>
730: <td>
1.18 faziophi 731: <table class="LC_nested">';
732: if (exists $item->{'header'}->[0]->{'col1'} ||
733: exists $item->{'header'}->[0]->{'col2'}) {
734: $output .= '
735: <tr class="LC_info_row">
1.56 raeburn 736: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
737: if ($action eq 'feedback') {
738: $output .= '
739: <td class="LC_right_item" colspan="2">';
740: } else {
741: $output .= '
742: <td class="LC_right_item">';
743: }
744: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 745: </tr>';
746: }
1.1 raeburn 747: $rowtotal ++;
748: if ($action eq 'feedback') {
1.80 raeburn 749: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 750: } elsif ($action eq 'classlists') {
1.80 raeburn 751: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 752: } elsif ($action eq 'menuitems') {
753: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 754: }
755: $output .= '
756: </table>
1.45 www 757: </td>
758: </tr>
759: <tr>
760: <td>
1.1 raeburn 761: <table class="LC_nested">
762: <tr class="LC_info_row">
763: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 764: if ($action eq 'classlists') {
765: $output .= '
766: <td class="LC_right_item" colspan="2">';
767: } else {
768: $output .= '
769: <td class="LC_right_item">';
770: }
771: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 772: </tr>';
773: if ($action eq 'classlists') {
1.80 raeburn 774: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 775: '
776: </table>
1.45 www 777: </td>
778: </tr>
779: <tr>
780: <td>
1.18 faziophi 781: <table class="LC_nested">';
1.43 www 782: if (exists $item->{'header'}->[2]->{'col1'} ||
783: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 784: $output .= '
785: <tr class="LC_info_row">
1.43 www 786: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
787: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 788: </tr>';
789: }
1.1 raeburn 790: }
791: } else {
792: $output .= '
1.45 www 793: <tr>
794: <td>
1.18 faziophi 795: <table class="LC_nested">';
796: if (exists $item->{'header'}->[0]->{'col1'} ||
797: exists $item->{'header'}->[0]->{'col2'}) {
798: $output .= '
799: <tr class="LC_info_row">
1.56 raeburn 800: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
801: if (($action eq 'courseinfo') || ($action eq 'localization') ||
802: ($action eq 'print_discussion')) {
803: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
804: } else {
805: $output .= '<td class="LC_right_item" valign="top">';
806: }
807: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 808: </tr>';
809: }
1.1 raeburn 810: }
811: $rowtotal ++;
812: if ($action eq 'courseinfo') {
1.80 raeburn 813: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 814: } elsif ($action eq 'localization') {
1.80 raeburn 815: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 816: } elsif ($action eq 'feedback') {
1.80 raeburn 817: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 818: } elsif ($action eq 'discussion') {
1.80 raeburn 819: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 820: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 821: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 822: } elsif ($action eq 'appearance') {
1.80 raeburn 823: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 824: } elsif ($action eq 'grading') {
1.127 ! raeburn 825: $output .= &print_grading($cdom,$cnum,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 826: } elsif ($action eq 'printouts') {
1.80 raeburn 827: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 828: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 829: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 830: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 831: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.118 raeburn 832: } elsif ($action eq 'ltitools') {
833: my $currtools = {};
834: if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
835: $currtools = $settings->{'ltitools'};
836: }
837: $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
1.87 raeburn 838: } elsif ($action eq 'lti') {
839: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 840: } elsif ($action eq 'menuitems') {
841: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 842: } elsif ($action eq 'linkprot') {
843: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 844: } elsif ($action eq 'other') {
1.80 raeburn 845: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 846: }
847: $output .= '
848: </table>
1.45 www 849: </td>
850: </tr>
851: </table><br />';
1.1 raeburn 852: return ($output,$rowtotal);
853: }
854:
855: sub process_changes {
1.108 raeburn 856: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 857: my (%newvalues,$errors);
1.3 raeburn 858: if (ref($item) eq 'HASH') {
859: if (ref($changes) eq 'HASH') {
860: my @ordered;
861: if ($action eq 'other') {
862: @ordered = &get_other_items($cdom,$values,$allitems);
863: if ($env{'form.newp_name'} ne '') {
864: my $newp = $env{'form.newp_name'};
865: if ($env{'form.newp_value'} ne '') {
866: if (ref($allitems) eq 'ARRAY') {
867: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
868: (grep(/^\Q$newp\E$/,@{$allitems}))) {
869: $changes->{$newp} = $env{'form.newp_value'};
870: }
871: }
872: }
873: }
1.118 raeburn 874: } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.99 raeburn 875: if (ref($values->{$action}) eq 'HASH') {
876: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 877: if ($id =~ /^\d+$/) {
878: push(@ordered,$id);
879: }
880: }
881: }
882: @ordered = sort { $a <=> $b } @ordered;
1.118 raeburn 883: if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
884: push(@ordered,$env{'form.'.$action.'_maxnum'});
1.93 raeburn 885: }
1.3 raeburn 886: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 887: if ($action eq 'courseinfo') {
888: my ($can_toggle_cat,$can_categorize) =
889: &can_modify_catsettings($cdom,$crstype);
890: foreach my $entry (@{$item->{'ordered'}}) {
891: next if (($entry eq 'hidefromcat') &&
892: (!$can_toggle_cat));
893: next if (($entry eq 'categories') &&
894: (!$can_categorize));
895: next if (($entry eq 'loncaparev') ||
1.63 raeburn 896: ($entry eq 'owner') ||
1.88 raeburn 897: ($entry eq 'clonedfrom') ||
898: ($entry eq 'syllabus'));
1.49 raeburn 899: push(@ordered,$entry);
900: }
1.55 raeburn 901: } elsif ($action eq 'classlists') {
902: foreach my $entry (@{$item->{'ordered'}}) {
903: next if ($entry eq 'defaultcredits');
904: push(@ordered,$entry);
905: }
1.49 raeburn 906: } else {
907: @ordered = @{$item->{'ordered'}};
908: }
1.3 raeburn 909: }
910: if (@ordered > 0) {
911: if ($action eq 'feedback') {
912: foreach my $entry (@ordered) {
913: my $userstr = '';
914: my $total = $env{'form.'.$entry.'_total'};
915: if ($total) {
916: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
917: for (my $i=0; $i<$total; $i++) {
918: unless (grep(/^$i$/,@deletes)) {
919: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
920: &get_sec_str($entry,$i).',';
921: }
922: }
923: } else {
924: $total = 0;
925: }
926: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
927: my $uname = $env{'form.'.$entry.'_uname_'.$total};
928: my $udom = $env{'form.'.$entry.'_udom_'.$total};
929: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
930: $userstr =~ s/,$//;
931: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
932: } else {
933: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
934: }
935: } else {
936: $userstr =~ s/,$//;
937: }
938: $newvalues{$entry} = $userstr;
939: if ($newvalues{$entry} ne $values->{$entry}) {
940: $changes->{$entry} = $newvalues{$entry};
941: }
942: my $ext_entry = $entry.'.text';
943: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
944: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
945: $changes->{$ext_entry} = $newvalues{$ext_entry};
946: }
947: }
1.91 raeburn 948: } elsif ($action eq 'menuitems') {
949: my (%current,@colls);
950: my $next = 1;
951: if ($values->{'menucollections'}) {
952: foreach my $item (split(/;/,$values->{'menucollections'})) {
953: my ($num,$value) = split(/\%/,$item);
954: if ($num =~ /^\d+$/) {
955: unless (grep(/^$num$/,@colls)) {
956: push(@colls,$num);
957: }
958: my @entries = split(/\&/,$value);
959: foreach my $entry (@entries) {
960: my ($name,$fields) = split(/=/,$entry);
961: $current{$num}{$name} = $fields;
962: }
963: }
964: }
965: }
966: if (@colls) {
967: @colls = sort { $a <=> $b } @colls;
968: $next += $colls[-1];
969: }
970: if ($env{'form.menucollections_add'} eq $next) {
971: push(@colls,$next);
972: }
973: my $currdef = $values->{'menudefault'};
974: my $possdef = $env{'form.menudefault'};
975: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 976: if ($currdef ne $possdef) {
1.91 raeburn 977: $changes->{'menudefault'} = $possdef;
978: }
1.92 raeburn 979: } elsif ($currdef) {
1.91 raeburn 980: $changes->{'menudefault'} = '';
981: }
982: my $menucoll;
983: if (@colls) {
984: my ($ordered,$cats) = &menuitems_categories();
985: my %shortcats = &menuitems_abbreviations();
986: foreach my $num (@colls) {
987: my ($entry,%include);
988: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
989: foreach my $item (@{$ordered}) {
990: if ($item eq 'shown') {
991: foreach my $type (@{$cats->{$item}}) {
992: $entry .= $type.'=';
993: if ($include{$type}) {
994: $entry .= 'y';
995: } else {
996: $entry .= 'n';
997: }
998: $entry .= '&';
999: }
1000: } else {
1001: $entry .= $shortcats{$item}.'=';
1002: foreach my $type (@{$cats->{$item}}) {
1003: if ($include{$type}) {
1004: $entry .= $type.',';
1005: }
1006: }
1007: $entry =~ s/,$//;
1008: $entry .= '&';
1009: }
1010: }
1011: $entry =~ s/\&$//;
1012: if ($menucoll) {
1013: $menucoll .= ';';
1014: }
1015: $menucoll .= $num.'%'.$entry;
1016: }
1017: if ($menucoll ne $values->{'menucollections'}) {
1018: $changes->{'menucollections'} = $menucoll;
1019: }
1020: } elsif ($values->{'menucollections'}) {
1021: $changes->{'menucollections'} = '';
1022: }
1.102 raeburn 1023: } elsif ($action eq 'linkprot') {
1024: if (ref($values) eq 'HASH') {
1.108 raeburn 1025: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 1026: }
1.118 raeburn 1027: } elsif ($action eq 'ltitools') {
1028: if (ref($values) eq 'HASH') {
1029: my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1030: $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1031: 'ok','','ok');
1032: }
1.3 raeburn 1033: } else {
1034: foreach my $entry (@ordered) {
1035: if ($entry eq 'cloners') {
1036: if ($env{'form.cloners_all'}) {
1037: $newvalues{$entry} = '*';
1038: } else {
1039: my @clonedoms;
1040: if (exists($env{'form.cloners_activate'})) {
1041: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1042: if ($actnum ne '-1') {
1.33 raeburn 1043: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1044: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1045: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1046: $newvalues{$entry} = '*:'.$clonedom;
1047: push(@clonedoms,$newvalues{$entry});
1048: }
1049: }
1050: }
1051: } else {
1052: my $num = $env{'form.cloners_total'};
1053: my @deletes =
1054: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1055: for (my $i=0; $i<$num; $i++) {
1056: if (!grep(/^$i$/,@deletes)) {
1057: my $clonedom = $env{'form.cloners_dom_'.$i};
1058: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1059: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1060: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1061: }
1062: }
1063: }
1064: }
1065: if (@clonedoms) {
1066: $newvalues{$entry}=join(',',@clonedoms);
1067: }
1068: }
1069: if ($env{'form.cloners_newdom'} ne '') {
1070: my $clonedom = $env{'form.cloners_newdom'};
1071: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1072: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1073: if (@clonedoms) {
1.3 raeburn 1074: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1075: $newvalues{$entry} .= ','.$newdom;
1076: }
1077: } else {
1078: $newvalues{$entry} = $newdom;
1079: }
1080: }
1081: }
1082: if ($env{'form.'.$entry} ne '') {
1083: my @cloners = split(',',$env{'form.'.$entry});
1084: my @okcloners;
1085: foreach my $cloner (@cloners) {
1.23 raeburn 1086: $cloner =~ s/^\s+//;
1087: $cloner =~ s/\s+$//;
1088: unless ($cloner eq '') {
1089: my ($uname,$udom) = split(':',$cloner);
1090: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1091: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1092: push(@okcloners,$cloner);
1093: }
1.3 raeburn 1094: }
1095: }
1096: }
1097: if (@okcloners) {
1098: my $okclonestr = join(',',@okcloners);
1099: if ($newvalues{$entry} ne '') {
1100: $newvalues{$entry} .= ','.$okclonestr;
1101: } else {
1102: $newvalues{$entry} = $okclonestr;
1103: }
1104: }
1105: }
1.71 raeburn 1106: if (ref($values) eq 'HASH') {
1107: my (@code_order,%codedefaults);
1108: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1109: \@code_order);
1110: my $clonebycode;
1111: if ($env{'form.cloners_instcode'}) {
1112: if (@code_order > 0) {
1113: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1114: my %local_to_standard;
1115: for (my $i=0; $i<@code_order; $i++) {
1116: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1117: }
1118: foreach my $item (@code_order) {
1119: my $key = $local_to_standard{$item};
1120: if ($key ne '') {
1121: if ($env{'form.'.$key}) {
1122: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1123: }
1124: }
1125: }
1126: $clonebycode =~ s/\&$//;
1127: }
1128: }
1129: if ($clonebycode) {
1130: if ($newvalues{$entry}) {
1131: $newvalues{$entry} .= ','.$clonebycode;
1132: } else {
1133: $newvalues{$entry} = $clonebycode;
1134: }
1135: }
1136: }
1.3 raeburn 1137: }
1138: if (ref($disallowed) eq 'HASH') {
1139: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1140: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1141: $disallowed->{'cloners'}{$key} =~ s/,$//;
1142: }
1143: }
1144: }
1.25 raeburn 1145: } elsif ($entry eq 'co-owners') {
1146: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1147: my $coowners = $values->{'internal.co-owners'};
1148: my @currcoown;
1149: if ($coowners) {
1150: @currcoown = split(',',$coowners);
1151: }
1152: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1153: my $autocoowner;
1154: if (($crstype eq 'Course') &&
1155: ($values->{'internal.coursecode'})) {
1156: my %domconf =
1157: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1158: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1159: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1160: }
1161: }
1.96 raeburn 1162: if ($autocoowner) {
1163: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1164: } else {
1.25 raeburn 1165: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1166: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1167: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1168: if (@invitecoowners) {
1169: push(@pendingcoowners,@invitecoowners);
1170: }
1171: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1172: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1173: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1174: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1175: push(@{$changes->{$entry}{'changed'}},'co-owners');
1176: }
1177: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1178: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1179: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1180: }
1181: }
1182: } else {
1183: my (@newpending,@newcoown);
1184: my $uname = $env{'user.name'};
1185: my $udom = $env{'user.domain'};
1186: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1187: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1188: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1189: foreach my $item (@pendingcoown) {
1190: unless ($item eq $uname.':'.$udom) {
1191: push(@newpending,$item);
1192: }
1193: }
1194: @newcoown = @currcoown;
1.90 raeburn 1195: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1196: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1197: push(@newcoown,$uname.':'.$udom);
1198: }
1199: }
1.90 raeburn 1200: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1201: foreach my $item (@currcoown) {
1202: unless ($item eq $uname.':'.$udom) {
1203: push(@newcoown,$item);
1204: }
1205: }
1206: if ($pendingcoowners ne '') {
1207: @newpending = @pendingcoown;
1208: }
1.96 raeburn 1209: } else {
1210: @newcoown = @currcoown;
1.25 raeburn 1211: }
1212: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1213: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1214: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1215: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1216: push(@{$changes->{$entry}{'changed'}},'co-owners');
1217: }
1218: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1219: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1220: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1221: }
1222: }
1.3 raeburn 1223: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1224: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1225: } elsif ($entry eq 'rolenames') {
1226: my %adv_roles =
1227: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1228: my @stds;
1229: if ($crstype eq 'Community') {
1230: @stds = ('co');
1231: } else {
1232: @stds = ('cc');
1233: }
1234: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1235: my (@replacements,@regulars);
1236: foreach my $role (@stds) {
1237: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1238: push(@replacements,$role);
1.3 raeburn 1239: } else {
1240: push(@regulars,$role);
1241: }
1.9 raeburn 1242: }
1.3 raeburn 1243: foreach my $stdrole (@stds) {
1244: my $ext_entry = $entry.'_'.$stdrole;
1245: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1246: $env{'request.course.id'},1);
1247: if ($env{'form.'.$ext_entry} eq $stdname) {
1248: $newvalues{$ext_entry} = '';
1249: } else {
1250: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1251: }
1252: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1253: my $dupname = 0;
1254: if ($newvalues{$ext_entry} ne '') {
1255: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1256: $dupname = 1;
1257: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1258: }
1259: if (!$dupname) {
1260: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1261: $dupname = 1;
1262: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1263: }
1264: }
1265: if (!$dupname) {
1266: foreach my $role (keys(%adv_roles)) {
1267: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1268: $dupname = 1;
1269: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1270: last;
1271: }
1272: }
1273: }
1274: }
1275: if (!$dupname) {
1276: $changes->{$ext_entry} = $newvalues{$ext_entry};
1277: }
1278: }
1279: }
1.77 raeburn 1280: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1281: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1282: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1283: @denied = sort(@denied);
1284: my $deniedstr = '';
1285: if (@denied > 0) {
1286: $deniedstr = join(',',@denied);
1287: }
1288: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1289: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1290: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1291: my $total = $env{'form.'.$entry.'_total'};
1292: my $userstr = '';
1293: my @denied;
1294: if ($total > 0) {
1295: my @deletes =
1296: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1297: for (my $i=0; $i<$total; $i++) {
1298: unless (grep(/^$i$/,@deletes)) {
1299: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1300: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1301: }
1302: }
1303: } else {
1304: $total = 0;
1305: }
1306: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1307: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1308: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1309: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1310: $userstr =~ s/,$//;
1311: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1312: } else {
1313: my $newuser .= $uname.':'.$udom;
1314: if (grep(/^\Q$newuser\E$/,@denied)) {
1315: $userstr =~ s/,$//;
1316: } else {
1317: $userstr .= $newuser;
1318: }
1319: }
1320: } else {
1321: $userstr =~ s/,$//;
1322: }
1323: $newvalues{$entry} = $userstr;
1324: } elsif ($entry eq 'allow_discussion_post_editing') {
1325: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1326: @canedit = sort(@canedit);
1327: foreach my $role (@canedit) {
1328: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1329: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1330: $newvalues{$entry} .= $role.',';
1331: } else {
1332: foreach my $sec (@secs) {
1333: $newvalues{$entry} .= $role.':'.$sec.',';
1334: }
1335: }
1336: }
1337: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1338: } elsif ($entry eq 'discussion_post_fonts') {
1339: my ($classorder,$classtitles) = &discussion_vote_classes();
1340: my $fontchange = 0;
1341: foreach my $class (@{$classorder}) {
1.124 raeburn 1342: my $ext_entry = $entry.'_'.$class;
1.50 raeburn 1343: my $size = $env{'form.'.$ext_entry.'_size'};
1344: my $unit = $env{'form.'.$ext_entry.'_unit'};
1345: my $weight = $env{'form.'.$ext_entry.'_weight'};
1346: my $style = $env{'form.'.$ext_entry.'_style'};
1347: my $other = $env{'form.'.$ext_entry.'_other'};
1348: $size =~ s/,//g;
1.124 raeburn 1349: $unit =~ s/,//g;
1.50 raeburn 1350: $weight =~ s/,//g;
1351: $style =~ s/,//g;
1352: $other =~ s/[^\w;:\s\-\%.]//g;
1353: $other =~ s/(^\s+|\s+$)//g;
1354: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1355: my $current = $values->{$ext_entry};
1356: if ($values->{$ext_entry} eq '') {
1.124 raeburn 1357: $current = ',,,';
1.50 raeburn 1358: }
1359: if ($newvalues{$ext_entry} ne $current) {
1360: $changes->{$ext_entry} = $newvalues{$ext_entry};
1361: $fontchange ++;
1362: }
1363: }
1364: if ($fontchange) {
1365: $changes->{$entry} = 1;
1.124 raeburn 1366: }
1.3 raeburn 1367: } elsif ($entry eq 'nothideprivileged') {
1368: my @curr_nothide;
1369: my @new_nothide;
1370: if ($values->{$entry} ne '') {
1371: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1372: my $nothide;
1373: if ($user !~ /:/) {
1374: $nothide = join(':',split(/[\@]/,$user));
1375: } else {
1376: $nothide = $user;
1377: }
1378: if ((defined($nothide)) &&
1379: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1380: push(@curr_nothide,$nothide);
1381: }
1382: }
1383: }
1384: foreach my $key (keys(%env)) {
1385: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1386: if ($env{$key}) {
1.3 raeburn 1387: my $nothide = $1;
1388: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1389: push(@new_nothide,$nothide);
1390: }
1391: }
1392: }
1393: }
1394: @new_nothide = sort(@new_nothide);
1395: my @differences =
1396: &Apache::loncommon::compare_arrays(\@curr_nothide,
1397: \@new_nothide);
1398: if (@differences > 0) {
1399: if (@new_nothide > 0) {
1400: $newvalues{$entry} = join(',',@new_nothide);
1401: } else {
1402: $newvalues{$entry} = '';
1403: }
1404: } else {
1405: $newvalues{$entry} = $values->{$entry};
1406: }
1407: } elsif ($entry eq 'print_header_format') {
1408: my $maxnum = $env{'form.printfmthdr_maxnum'};
1409: my @newhdr;
1410: if ($maxnum > 2) {
1411: for (my $i=0; $i<$maxnum-2; $i++) {
1412: if ($env{'form.printfmthdr_del_'.$i}) {
1413: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1414: } else {
1415: my $hdr;
1416: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1417: $hdr = '%';
1418: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1419: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1420: }
1421: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1422: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1423: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1424: }
1425: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1426: }
1427: }
1428: }
1429: my $newsub = $maxnum-2;
1430: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1431: my $hdr = '%';
1432: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1433: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1434: }
1435: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1436: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1437: }
1438: my $newtext = $maxnum-1;
1439: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1440: $newvalues{$entry} = join('',@newhdr);
1.124 raeburn 1441: } elsif (($entry eq 'languages') ||
1.56 raeburn 1442: ($entry eq 'checkforpriv')) {
1443: my $settings;
1.3 raeburn 1444: my $total = $env{'form.'.$entry.'_total'};
1445: if ($total) {
1446: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1447: for (my $i=0; $i<$total; $i++) {
1448: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1449: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1450: }
1451: }
1452: } else {
1453: $total = 0;
1454: }
1455: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1456: my $new = $env{'form.'.$entry.'_'.$total};
1.124 raeburn 1457: if ($entry eq 'languages') {
1.56 raeburn 1458: my %langchoices = &get_lang_choices();
1459: if ($langchoices{$new}) {
1460: $settings .= $new;
1461: } else {
1462: $settings =~ s/,$//;
1463: $disallowed->{'localization'}{$entry} = $new;
1464: }
1.3 raeburn 1465: } else {
1.56 raeburn 1466: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1467: if ($domains{$new}) {
1468: $settings .= $new;
1469: } else {
1470: $settings =~ s/,$//;
1471: $disallowed->{'classlists'}{$entry} = $new;
1472: }
1.3 raeburn 1473: }
1474: } else {
1.56 raeburn 1475: $settings =~ s/,$//;
1.3 raeburn 1476: }
1.56 raeburn 1477: $newvalues{$entry} = $settings;
1.87 raeburn 1478: } elsif ($action eq 'lti') {
1479: if ($entry eq 'lti.override') {
1480: $newvalues{$entry} = $env{'form.'.$entry};
1481: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1482: if ($env{'form.lti.override'}) {
1483: $newvalues{$entry} = $env{'form.'.$entry};
1484: } else {
1485: $newvalues{$entry} = '';
1486: }
1487: } elsif ($entry eq 'lti.lcmenu') {
1488: if (($env{'form.lti.override'}) &&
1489: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1490: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1491: my @newlcmenu;
1492: if (@lcmenu) {
1493: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1494: foreach my $item (@menuitems) {
1495: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1496: if (grep(/^\Q$item\E$/,@lcmenu)) {
1497: push(@newlcmenu,$item);
1498: }
1499: }
1500: }
1501: if (@newlcmenu) {
1502: $newvalues{$entry} = join(',',@newlcmenu);
1503: } else {
1504: $newvalues{$entry} = 'none';
1505: }
1506: } else {
1507: $newvalues{$entry} = '';
1508: }
1509: }
1.114 raeburn 1510: } elsif ($entry eq 'extresource') {
1511: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1512: $newvalues{$entry} = $env{'form.'.$entry};
1513: if ($env{'form.'.$entry} ne 'iframe') {
1514: if ($env{'form.extwintabreuse'}) {
1515: $newvalues{$entry} .= ':1';
1516: } else {
1517: $newvalues{$entry} .= ':0';
1518: }
1519: if ($env{'form.'.$entry} eq 'window') {
1520: foreach my $dim ('width','height') {
1521: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1522: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1523: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1524: } else {
1525: $newvalues{$entry} .= ':';
1526: }
1527: }
1528: }
1529: }
1530: }
1531: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1532: if ($newvalues{$entry} ne $values->{$entry}) {
1533: $changes->{$entry} = $newvalues{$entry};
1534: }
1535: }
1.115 raeburn 1536: } elsif ($entry eq 'timezone') {
1537: if ($env{'form.'.$entry}) {
1538: $newvalues{$entry} = $env{'form.'.$entry};
1539: if ($newvalues{$entry} ne $values->{$entry}) {
1540: $changes->{$entry} = $newvalues{$entry};
1541: }
1542: if ($env{'form.tzover'}) {
1543: $newvalues{'tzover'} = $env{'form.tzover'};
1544: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1545: $changes->{'tzover'} = $newvalues{'tzover'};
1546: }
1547: } elsif ($values->{'tzover'}) {
1548: $changes->{'tzover'} = '';
1549: }
1550: } elsif ($values->{$entry}) {
1551: $changes->{$entry} = '';
1552: }
1.127 ! raeburn 1553: } elsif ($entry eq 'grading') {
! 1554: if ($env{'form.'.$entry} eq 'standard') {
! 1555: if ($env{'form.hidetotals'}) {
! 1556: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
! 1557: if (keys(%sections)) {
! 1558: my @secs = &Apache::loncommon::get_env_multiple('form.hidetotals_sections');
! 1559: if (grep(/^all$/,@secs)) {
! 1560: $newvalues{'hidetotals'} = 'all';
! 1561: } elsif (@secs) {
! 1562: $newvalues{'hidetotals'} = '';
! 1563: foreach my $sec (sort {$a <=> $b} @secs) {
! 1564: if (exists($sections{$sec})) {
! 1565: $newvalues{'hidetotals'} .= $sec.','
! 1566: }
! 1567: }
! 1568: $newvalues{'hidetotals'} =~ s/,$//;
! 1569: }
! 1570: } else {
! 1571: $newvalues{'hidetotals'} = 'all';
! 1572: }
! 1573: }
! 1574: }
! 1575: if ($newvalues{'hidetotals'} ne $values->{'hidetotals'}) {
! 1576: $changes->{'hidetotals'} = $newvalues{'hidetotals'};
! 1577: $changes->{'grading'} = $env{'form.'.$entry};
! 1578: }
! 1579: $newvalues{$entry} = $env{'form.'.$entry};
1.3 raeburn 1580: } else {
1581: $newvalues{$entry} = $env{'form.'.$entry};
1582: }
1.124 raeburn 1583: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1.115 raeburn 1584: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1585: if ($newvalues{$entry} ne $values->{$entry}) {
1586: $changes->{$entry} = $newvalues{$entry};
1587: }
1.3 raeburn 1588: }
1589: }
1590: }
1591: }
1592: }
1593: }
1.93 raeburn 1594: return $errors;
1595: }
1596:
1.102 raeburn 1597: sub process_linkprot {
1.108 raeburn 1598: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.118 raeburn 1599: my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1600: if (ref($values) eq 'HASH') {
1601: foreach my $id (keys(%{$values})) {
1602: if ($id =~ /^\d+$/) {
1603: unless (ref($values->{$id}) eq 'HASH') {
1604: $linkprot{$id} = '';
1605: }
1606: }
1607: }
1608: }
1.118 raeburn 1609: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.102 raeburn 1610: if ($context eq 'domain') {
1611: $dest = '/adm/domainprefs';
1612: $ltiauth = 1;
1613: } else {
1614: $dest = '/adm/courseprefs';
1615: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1616: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1617: } else {
1618: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1619: $ltiauth = $domdefs{'crsltiauth'};
1620: }
1621: }
1622: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1623: my (@items,%deletions,%itemids,%haschanges);
1624: if ($env{'form.linkprot_add'}) {
1625: my $name = $env{'form.linkprot_name_add'};
1626: $name =~ s/(`)/'/g;
1627: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1628: if ($newid) {
1629: $itemids{'add'} = $newid;
1630: push(@items,'add');
1631: $haschanges{$newid} = 1;
1632: } else {
1633: $errors .= '<span class="LC_error">'.
1634: &mt('Failed to acquire unique ID for link protection').
1635: '</span>';
1636: }
1637: }
1638: if (ref($values) eq 'HASH') {
1639: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1640: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1641: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1642: my $itemid = $env{'form.linkprot_id_'.$i};
1643: $itemid =~ s/\D+//g;
1644: if ($itemid) {
1645: if (ref($values->{$itemid}) eq 'HASH') {
1646: push(@items,$i);
1647: $itemids{$i} = $itemid;
1648: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1649: $deletions{$itemid} = $values->{$itemid}->{'name'};
1650: }
1651: }
1652: }
1653: }
1654: }
1655: foreach my $idx (@items) {
1656: my $itemid = $itemids{$idx};
1657: next unless ($itemid);
1658: if (exists($deletions{$itemid})) {
1659: $linkprot{$itemid} = $deletions{$itemid};
1660: $haschanges{$itemid} = 1;
1661: next;
1662: }
1663: my %current;
1664: if (ref($values) eq 'HASH') {
1665: if (ref($values->{$itemid}) eq 'HASH') {
1666: foreach my $key (keys(%{$values->{$itemid}})) {
1667: $current{$key} = $values->{$itemid}->{$key};
1668: }
1669: }
1670: }
1671: foreach my $inner ('name','lifetime','version') {
1672: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1673: $env{$formitem} =~ s/(`)/'/g;
1674: if ($inner eq 'lifetime') {
1675: $env{$formitem} =~ s/[^\d.]//g;
1676: }
1677: unless ($idx eq 'add') {
1678: if ($current{$inner} ne $env{$formitem}) {
1679: $haschanges{$itemid} = 1;
1680: }
1681: }
1682: if ($env{$formitem} ne '') {
1683: $linkprot{$itemid}{$inner} = $env{$formitem};
1684: }
1685: }
1.112 raeburn 1686: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1687: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1688: if ($env{$urlitem} == 1) {
1689: $env{$urlparamname} =~ s/(`)/'/g;
1690: } elsif (exists($env{$urlparamname})) {
1691: $env{$urlparamname} = '';
1692: }
1.122 raeburn 1693: my $passback = 'form.linkprot_passback_'.$idx;
1694: my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
1695: if ($env{$passback} == 1) {
1696: unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
1697: $env{$passbackparamname} = '';
1698: }
1699: } elsif (exists($env{$passbackparamname})) {
1700: $env{$passbackparamname} = '';
1701: }
1.112 raeburn 1702: unless ($idx eq 'add') {
1703: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1704: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1705: $haschanges{$itemid} = 1;
1706: }
1.122 raeburn 1707: if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
1708: ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
1709: $haschanges{$itemid} = 1;
1710: }
1.112 raeburn 1711: }
1.123 raeburn 1712: if ($env{$urlparamname} ne '') {
1713: $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1714: }
1.122 raeburn 1715: if ($env{$passbackparamname} ne '') {
1716: $linkprot{$itemid}{'passback'} = 1;
1717: $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1.112 raeburn 1718: }
1.102 raeburn 1719: if ($ltiauth) {
1720: my $reqitem = 'form.linkprot_requser_'.$idx;
1721: $env{$reqitem} =~ s/(`)/'/g;
1722: unless ($idx eq 'add') {
1.104 raeburn 1723: if ((!$current{'requser'} && $env{$reqitem}) ||
1724: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1725: $haschanges{$itemid} = 1;
1726: }
1727: }
1728: if ($env{$reqitem} == 1) {
1729: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1730: foreach my $inner ('mapuser','notstudent') {
1731: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1732: $env{$formitem} =~ s/(`)/'/g;
1733: if ($inner eq 'mapuser') {
1734: if ($env{$formitem} eq 'other') {
1735: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1736: $mapuser =~ s/(`)/'/g;
1737: $mapuser =~ s/^\s+|\s+$//g;
1738: if ($mapuser ne '') {
1739: $linkprot{$itemid}{$inner} = $mapuser;
1740: } else {
1741: delete($linkprot{$itemid}{'requser'});
1742: last;
1743: }
1744: } elsif ($env{$formitem} eq 'sourcedid') {
1745: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1746: } elsif ($env{$formitem} eq 'email') {
1747: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1748: }
1749: } else {
1750: $linkprot{$itemid}{$inner} = $env{$formitem};
1751: }
1752: unless ($idx eq 'add') {
1753: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1754: $haschanges{$itemid} = 1;
1755: }
1756: }
1757: }
1758: }
1759: }
1760: unless ($switchserver) {
1761: my $keyitem = 'form.linkprot_key_'.$idx;
1762: $env{$keyitem} =~ s/(`)/'/g;
1763: unless ($idx eq 'add') {
1764: if ($current{'key'} ne $env{$keyitem}) {
1765: $haschanges{$itemid} = 1;
1766: }
1767: }
1768: if ($env{$keyitem} ne '') {
1769: $linkprot{$itemid}{'key'} = $env{$keyitem};
1770: }
1771: my $secretitem = 'form.linkprot_secret_'.$idx;
1772: $env{$secretitem} =~ s/(`)/'/g;
1773: if ($current{'usable'}) {
1774: if ($env{'form.linkprot_changesecret_'.$idx}) {
1775: if ($env{$secretitem} ne '') {
1.103 raeburn 1776: if ($privnum && $cipher) {
1777: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1778: $linkprot{$itemid}{'cipher'} = $privnum;
1779: } else {
1780: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1781: }
1.102 raeburn 1782: $haschanges{$itemid} = 1;
1783: }
1784: } else {
1785: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1786: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1787: }
1788: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1789: if ($privnum && $cipher) {
1790: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1791: $linkprot{$itemid}{'cipher'} = $privnum;
1792: } else {
1793: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1794: }
1.102 raeburn 1795: $haschanges{$itemid} = 1;
1796: }
1797: }
1798: }
1799: if (keys(%haschanges)) {
1800: foreach my $entry (keys(%haschanges)) {
1801: $changes->{$entry} = $linkprot{$entry};
1802: }
1.108 raeburn 1803: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1804: $lastactref->{'courselti'} = 1;
1.108 raeburn 1805: }
1.102 raeburn 1806: }
1807: return $errors;
1808: }
1809:
1810: sub get_linkprot_id {
1811: my ($cdom,$cnum,$name,$context) = @_;
1812: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1813: my $lockhash = {
1814: lock => $env{'user.name'}.
1815: ':'.$env{'user.domain'},
1816: };
1817: my $tries = 0;
1.102 raeburn 1818: my $gotlock;
1819: if ($context eq 'domain') {
1820: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1821: } else {
1822: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1823: }
1.93 raeburn 1824: my ($id,$error);
1825: while (($gotlock ne 'ok') && ($tries<10)) {
1826: $tries ++;
1827: sleep (0.1);
1.102 raeburn 1828: if ($context eq 'domain') {
1.124 raeburn 1829: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1.102 raeburn 1830: } else {
1831: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1832: }
1.93 raeburn 1833: }
1834: if ($gotlock eq 'ok') {
1.102 raeburn 1835: my %currids;
1836: if ($context eq 'domain') {
1837: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1838: } else {
1839: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1840: }
1.93 raeburn 1841: if ($currids{'lock'}) {
1842: delete($currids{'lock'});
1843: if (keys(%currids)) {
1844: my @curr = sort { $a <=> $b } keys(%currids);
1845: if ($curr[-1] =~ /^\d+$/) {
1846: $id = 1 + $curr[-1];
1847: } else {
1848: $id = 1;
1849: }
1850: } else {
1851: $id = 1;
1852: }
1853: if ($id) {
1.102 raeburn 1854: if ($context eq 'domain') {
1855: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1856: $error = 'nostore';
1857: }
1858: } else {
1859: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1860: $error = 'nostore';
1861: }
1.93 raeburn 1862: }
1863: } else {
1864: $error = 'nonumber';
1865: }
1866: }
1.124 raeburn 1867: my $dellockoutcome;
1.102 raeburn 1868: if ($context eq 'domain') {
1869: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1870: } else {
1871: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1872: }
1.93 raeburn 1873: } else {
1874: $error = 'nolock';
1875: }
1876: return ($id,$error);
1.3 raeburn 1877: }
1878:
1.118 raeburn 1879: sub get_credentials {
1880: my ($cdom,$cnum,$type,$context) = @_;
1881: my ($cipher,$privnum,$home);
1882: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1883: my @ids=&Apache::lonnet::current_machine_ids();
1884: if ($context eq 'domain') {
1885: $home = &Apache::lonnet::domain($cdom,'primary');
1886: } else {
1887: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1888: }
1889: my ($hostskey,$domkey,$crskey);
1890: if ($type eq 'ltitools') {
1891: $hostskey = 'toolprivhosts';
1892: $domkey = 'toolenc_dom';
1893: $crskey = 'toolenc_crs';
1894: } else {
1895: $hostskey = 'ltiprivhosts';
1896: $domkey = 'linkprotenc_dom';
1897: $crskey = 'linkprotenc_crs';
1898: }
1899: if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1900: (($context eq 'course') && ($domdefs{$crskey}))) {
1901: unless (($home eq 'no_host') || ($home eq '')) {
1902: if (grep(/^\Q$home\E$/,@ids)) {
1903: if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1904: if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1905: my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1906: my $privkey = $privhash{'key'};
1907: $privnum = $privhash{'version'};
1908: if (($privnum) && ($privkey ne '')) {
1909: $cipher = Crypt::CBC->new({'key' => $privkey,
1910: 'cipher' => 'DES'});
1911: }
1912: }
1913: }
1914: }
1915: }
1916: }
1917: return ($cipher,$privnum);
1918: }
1919:
1920: sub process_ltitools {
1921: my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1922: $author_ok,$confname) = @_;
1923: my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1924:
1925: my (%posslti,%possfield);
1926: my @courseroles = ('cc','in','ta','ep','st');
1927: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1928: map { $posslti{$_} = 1; } @ltiroles;
1929: my @allfields = ('fullname','firstname','lastname','email','user','roles');
1930: map { $possfield{$_} = 1; } @allfields;
1931:
1.120 raeburn 1932: my ($dest,$privnum,$cipher);
1.118 raeburn 1933:
1934: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1935: if ($context eq 'domain') {
1936: $dest = '/adm/domainprefs';
1937: } else {
1938: $dest = '/adm/courseprefs';
1939: }
1940: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1941:
1942: my (@allpos,@items,%deletions,%itemids,%haschanges);
1943: if ($env{'form.ltitools_add'}) {
1944: my $title = $env{'form.ltitools_add_title'};
1945: $title =~ s/(`)/'/g;
1.125 raeburn 1946: my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
1.118 raeburn 1947: if ($newid) {
1948: my $position = $env{'form.ltitools_add_pos'};
1949: $position =~ s/\D+//g;
1950: if ($position ne '') {
1951: $allpos[$position] = $newid;
1952: }
1953: $haschanges{$newid} = 1;
1954: foreach my $item ('title','url','lifetime') {
1955: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1956: if ($item eq 'lifetime') {
1957: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1958: }
1959: if ($env{'form.ltitools_add_'.$item}) {
1960: $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1961: }
1962: }
1963: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1964: $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
1965: }
1966: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
1967: $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
1968: }
1969: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
1970: $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
1971: } else {
1972: $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
1973: }
1974: foreach my $item ('width','height','linktext','explanation') {
1975: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
1976: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1977: if (($item eq 'width') || ($item eq 'height')) {
1978: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
1979: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1980: }
1981: } else {
1982: if ($env{'form.ltitools_add_'.$item} ne '') {
1983: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
1984: }
1985: }
1986: }
1987: if ($env{'form.ltitools_add_target'} eq 'window') {
1988: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1989: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
1990: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1991: } else {
1992: $ltitools{$newid}{'display'}{'target'} = 'iframe';
1993: }
1994: foreach my $item ('passback','roster') {
1995: if ($env{'form.ltitools_'.$item.'_add'}) {
1996: $ltitools{$newid}{$item} = 1;
1997: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
1998: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
1999: $lifetime =~ s/^\s+|\s+$//g;
2000: if ($lifetime =~ /^\d+\.?\d*$/) {
2001: $ltitools{$newid}{$item.'valid'} = $lifetime;
2002: }
2003: }
2004: }
2005: }
2006: if ($env{'form.ltitools_add_image.filename'} ne '') {
2007: my ($imageurl,$error) =
2008: &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
2009: $newid,$configuserok,$lonhost,$author_ok);
2010: if ($imageurl) {
2011: $ltitools{$newid}{'image'} = $imageurl;
2012: }
2013: if ($error) {
2014: &Apache::lonnet::logthis($error);
2015: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2016: }
2017: }
2018: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
2019: foreach my $field (@fields) {
2020: if ($possfield{$field}) {
2021: if ($field eq 'roles') {
2022: foreach my $role (@courseroles) {
2023: my $choice = $env{'form.ltitools_add_roles_'.$role};
2024: if (($choice ne '') && ($posslti{$choice})) {
2025: $ltitools{$newid}{'roles'}{$role} = $choice;
2026: if ($role eq 'cc') {
2027: $ltitools{$newid}{'roles'}{'co'} = $choice;
2028: }
2029: }
2030: }
2031: } else {
2032: $ltitools{$newid}{'fields'}{$field} = 1;
2033: }
2034: }
2035: }
2036: if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
2037: if ($ltitools{$newid}{'fields'}{'user'}) {
2038: if ($env{'form.ltitools_add_userincdom'}) {
2039: $ltitools{$newid}{'incdom'} = 1;
2040: }
2041: }
2042: }
2043: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
2044: foreach my $item (@courseconfig) {
2045: $ltitools{$newid}{'crsconf'}{$item} = 1;
2046: }
2047: if ($env{'form.ltitools_add_custom'}) {
2048: my $name = $env{'form.ltitools_add_custom_name'};
2049: my $value = $env{'form.ltitools_add_custom_value'};
2050: $value =~ s/(`)/'/g;
2051: $name =~ s/(`)/'/g;
2052: $ltitools{$newid}{'custom'}{$name} = $value;
2053: }
2054: unless ($switchserver) {
2055: my $keyitem = 'form.ltitools_add_key';
2056: $env{$keyitem} =~ s/(`)/'/g;
2057: if ($env{$keyitem} ne '') {
2058: $ltitools{$newid}{'key'} = $env{$keyitem};
2059: }
1.119 raeburn 2060: my $secretitem = 'form.ltitools_secret_add';
1.118 raeburn 2061: $env{$secretitem} =~ s/(`)/'/g;
2062: if ($env{$secretitem} ne '') {
2063: if ($privnum && $cipher) {
2064: $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2065: $ltitools{$newid}{'cipher'} = $privnum;
2066: } else {
2067: $ltitools{$newid}{'secret'} = $env{$secretitem};
2068: }
2069: }
2070: }
2071: } else {
2072: $errors .= '<li><span class="LC_error">'.
2073: &mt('Failed to acquire unique ID for new external tool').
2074: '</span></li>';
2075: }
2076: }
2077: if (ref($values) eq 'HASH') {
2078: my %deletions;
2079: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2080: if (@todelete) {
2081: map { $deletions{$_} = 1; } @todelete;
2082: }
2083: my %customadds;
2084: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2085: if (@newcustom) {
2086: map { $customadds{$_} = 1; } @newcustom;
2087: }
2088: my %imgdeletions;
2089: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2090: if (@todeleteimages) {
2091: map { $imgdeletions{$_} = 1; } @todeleteimages;
2092: }
2093: my $maxnum = $env{'form.ltitools_maxnum'};
2094: for (my $i=0; $i<=$maxnum; $i++) {
2095: my $itemid = $env{'form.ltitools_id_'.$i};
2096: $itemid =~ s/\D+//g;
2097: if (ref($values->{$itemid}) eq 'HASH') {
2098: if ($deletions{$itemid}) {
2099: if ($values->{$itemid}{'image'}) {
2100: #FIXME need to obsolete item in RES space
2101: }
2102: $haschanges{$itemid} = $values->{$itemid}{'title'};
2103: next;
2104: } else {
2105: my $newpos = $env{'form.ltitools_'.$itemid};
2106: $newpos =~ s/\D+//g;
2107: foreach my $item ('title','url','lifetime') {
2108: $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2109: if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2110: $haschanges{$itemid} = 1;
2111: }
2112: }
2113: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2114: $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2115: }
2116: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2117: $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2118: }
2119: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2120: $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2121: } else {
2122: $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2123: }
2124: if ($values->{$itemid}{'sigmethod'} eq '') {
2125: if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2126: $haschanges{$itemid} = 1;
2127: }
2128: } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2129: $haschanges{$itemid} = 1;
2130: }
2131: foreach my $size ('width','height') {
2132: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2133: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2134: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2135: $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2136: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2137: if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2138: $haschanges{$itemid} = 1;
2139: }
2140: } else {
2141: $haschanges{$itemid} = 1;
2142: }
2143: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2144: if ($values->{$itemid}{'display'}{$size} ne '') {
2145: $haschanges{$itemid} = 1;
2146: }
2147: }
2148: }
2149: foreach my $item ('linktext','explanation') {
2150: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2151: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2152: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2153: $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2154: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2155: if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2156: $haschanges{$itemid} = 1;
2157: }
2158: } else {
2159: $haschanges{$itemid} = 1;
2160: }
2161: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2162: if ($values->{$itemid}{'display'}{$item} ne '') {
2163: $haschanges{$itemid} = 1;
2164: }
2165: }
2166: }
2167: if ($env{'form.ltitools_target_'.$i} eq 'window') {
2168: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2169: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2170: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2171: } else {
2172: $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2173: }
2174: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2175: if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2176: $haschanges{$itemid} = 1;
2177: }
2178: } else {
2179: $haschanges{$itemid} = 1;
2180: }
2181: foreach my $extra ('passback','roster') {
2182: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2183: $ltitools{$itemid}{$extra} = 1;
2184: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2185: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2186: $lifetime =~ s/^\s+|\s+$//g;
2187: if ($lifetime =~ /^\d+\.?\d*$/) {
2188: $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2189: }
2190: }
2191: }
2192: if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2193: $haschanges{$itemid} = 1;
2194: }
2195: if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2196: $haschanges{$itemid} = 1;
2197: }
2198: }
2199: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2200: foreach my $item ('label','title','target','linktext','explanation','append') {
2201: if (grep(/^\Q$item\E$/,@courseconfig)) {
2202: $ltitools{$itemid}{'crsconf'}{$item} = 1;
2203: if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2204: if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2205: $haschanges{$itemid} = 1;
2206: }
2207: } else {
2208: $haschanges{$itemid} = 1;
2209: }
2210: }
2211: }
2212: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2213: foreach my $field (@fields) {
2214: if ($possfield{$field}) {
2215: if ($field eq 'roles') {
2216: foreach my $role (@courseroles) {
2217: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2218: if (($choice ne '') && ($posslti{$choice})) {
2219: $ltitools{$itemid}{'roles'}{$role} = $choice;
2220: if ($role eq 'cc') {
2221: $ltitools{$itemid}{'roles'}{'co'} = $choice;
2222: }
2223: }
2224: if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2225: if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2226: $haschanges{$itemid} = 1;
2227: }
2228: } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2229: $haschanges{$itemid} = 1;
2230: }
2231: }
2232: } else {
2233: $ltitools{$itemid}{'fields'}{$field} = 1;
2234: if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2235: if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2236: $haschanges{$itemid} = 1;
2237: }
2238: } else {
2239: $haschanges{$itemid} = 1;
2240: }
2241: }
2242: }
2243: }
2244: if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2245: if ($ltitools{$itemid}{'fields'}{'user'}) {
2246: if ($env{'form.ltitools_userincdom_'.$i}) {
2247: $ltitools{$itemid}{'incdom'} = 1;
2248: }
2249: if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2250: $haschanges{$itemid} = 1;
2251: }
2252: }
2253: }
2254: $allpos[$newpos] = $itemid;
2255: }
2256: if ($imgdeletions{$itemid}) {
2257: $haschanges{$itemid} = 1;
2258: if ($context eq 'course') {
2259: my $currimgurl = $values->{$itemid}{'image'};
2260: if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2261: my ($path,$imagefile) = ($1,$2);
2262: if ($imagefile =~ /^tn\-(.+)$/) {
2263: my $origimg = $1;
2264: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2265: }
2266: &Apache::lonnet::removeuploadedurl($currimgurl);
2267: }
2268: }
2269: #FIXME need to obsolete item in RES space
2270: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2271: my $currimgurl = $values->{$itemid}{'image'};
2272: my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2273: $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2274: if ($imgurl) {
2275: $ltitools{$itemid}{'image'} = $imgurl;
2276: $haschanges{$itemid} = 1;
2277: }
2278: if ($error) {
2279: &Apache::lonnet::logthis($error);
2280: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2281: }
2282: } elsif ($values->{$itemid}{'image'}) {
2283: $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2284: }
2285: if ($customadds{$i}) {
2286: my $name = $env{'form.ltitools_custom_name_'.$i};
2287: $name =~ s/(`)/'/g;
2288: $name =~ s/^\s+//;
2289: $name =~ s/\s+$//;
2290: my $value = $env{'form.ltitools_custom_value_'.$i};
2291: $value =~ s/(`)/'/g;
2292: $value =~ s/^\s+//;
2293: $value =~ s/\s+$//;
2294: if ($name ne '') {
2295: $ltitools{$itemid}{'custom'}{$name} = $value;
2296: $haschanges{$itemid} = 1;
2297: }
2298: }
2299: my %customdels;
2300: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2301: if (@customdeletions) {
2302: $haschanges{$itemid} = 1;
2303: }
2304: map { $customdels{$_} = 1; } @customdeletions;
2305: if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2306: foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2307: unless ($customdels{$key}) {
2308: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2309: $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2310: }
2311: if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2312: $haschanges{$itemid} = 1;
2313: }
2314: }
2315: }
2316: }
2317: unless ($switchserver) {
2318: my $keyitem = 'form.ltitools_key_'.$i;
2319: $env{$keyitem} =~ s/(`)/'/g;
2320: if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2321: $haschanges{$itemid} = 1;
2322: }
2323: if ($env{$keyitem} ne '') {
2324: $ltitools{$itemid}{'key'} = $env{$keyitem};
2325: }
2326: my $secretitem = 'form.ltitools_secret_'.$i;
2327: $env{$secretitem} =~ s/(`)/'/g;
2328: if ($values->{$itemid}{'usable'}) {
2329: if ($env{'form.ltitools_changesecret_'.$i}) {
2330: if ($env{$secretitem} ne '') {
2331: if ($privnum && $cipher) {
2332: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2333: $ltitools{$itemid}{'cipher'} = $privnum;
2334: } else {
2335: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2336: }
2337: $haschanges{$itemid} = 1;
2338: }
2339: } else {
2340: $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2341: $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2342: }
2343: } elsif ($env{$secretitem} ne '') {
2344: if ($privnum && $cipher) {
2345: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2346: $ltitools{$itemid}{'cipher'} = $privnum;
2347: } else {
2348: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2349: }
2350: $haschanges{$itemid} = 1;
2351: }
2352: }
2353: unless ($haschanges{$itemid}) {
2354: foreach my $key (keys(%{$values->{$itemid}})) {
2355: if (ref($values->{$itemid}{$key}) eq 'HASH') {
2356: if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2357: foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2358: unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2359: $haschanges{$itemid} = 1;
2360: last;
2361: }
2362: }
2363: } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2364: $haschanges{$itemid} = 1;
2365: }
2366: }
2367: last if ($haschanges{$itemid});
2368: }
2369: }
2370: }
2371: }
2372: }
2373: if (@allpos > 0) {
2374: my $idx = 0;
2375: foreach my $itemid (@allpos) {
2376: if ($itemid ne '') {
2377: $ltitools{$itemid}{'order'} = $idx;
2378: if (ref($values) eq 'HASH') {
2379: if (ref($values->{$itemid}) eq 'HASH') {
2380: if ($values->{$itemid}{'order'} ne $idx) {
2381: $haschanges{$itemid} = 1;
2382: }
2383: }
2384: }
2385: $idx ++;
2386: }
2387: }
2388: }
2389: if (keys(%haschanges)) {
2390: foreach my $entry (keys(%haschanges)) {
2391: $changes->{$entry} = $ltitools{$entry};
2392: }
2393: if (ref($lastactref) eq 'HASH') {
2394: $lastactref->{'courseltitools'} = 1;
2395: }
2396: }
2397: return $errors;
2398: }
2399:
2400: sub process_ltitools_image {
2401: my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2402: my $filename = $env{'form.'.$caller.'.filename'};
2403: my ($error,$url);
2404: my ($width,$height) = (21,21);
2405: if ($configuserok eq 'ok') {
2406: if ($switch) {
2407: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2408: $switch);
2409: } elsif ($author_ok eq 'ok') {
2410: my ($result,$imageurl,$madethumb);
2411: if ($context eq 'domain') {
2412: ($result,$imageurl,$madethumb) =
2413: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2414: "ltitools/$itemid/icon",$width,$height);
2415: } else {
2416: ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2417: }
2418: if ($result eq 'ok') {
2419: if ($madethumb) {
2420: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2421: my $imagethumb = "$path/tn-".$imagefile;
2422: $url = $imagethumb;
2423: } else {
2424: $url = $imageurl;
2425: }
2426: } else {
2427: if ($context eq 'domain') {
2428: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2429: } else {
2430: $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2431: }
2432: }
2433: } else {
2434: $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$author_ok);
2435: }
2436: } else {
2437: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$configuserok);
2438: }
2439: return ($url,$error);
2440: }
2441:
2442: sub processlogo {
2443: my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2444: my ($result,$imageurl,$madethumb);
2445: if ($env{"form.$caller.filename"} ne '') {
2446: unless ($caller eq 'ltitools_add_image') {
2447: if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2448: my ($path,$imagefile) = ($1,$2);
2449: if ($imagefile =~ /^tn\-(.+)$/) {
2450: my $origimg = $1;
2451: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2452: }
2453: &Apache::lonnet::removeuploadedurl($currimg);
2454: }
2455: }
2456: $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2457: '','','',$cnum,$dom,$width,$height);
2458: if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2459: my ($path,$imagefile) = ($1,$2);
2460: $result = 'ok';
2461: my $thumburl = "$path/tn-".$imagefile;
2462: my ($rtncode,$info);
2463: my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2464: if ($res eq 'ok') {
2465: $madethumb = 1;
2466: }
2467: } elsif ($imageurl eq '/adm/notfound.html') {
2468: undef($imageurl);
2469: $result = 'store failed';
2470: } elsif ($imageurl =~ /^error: (.+)$/) {
2471: $result = $1;
2472: }
2473: }
2474: return ($result,$imageurl,$madethumb);
2475: }
2476:
1.3 raeburn 2477: sub get_sec_str {
2478: my ($entry,$num) = @_;
2479: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2480: my $secstr;
2481: if (grep(/^\s*$/,@secs)) {
2482: $secstr = '';
2483: } elsif (@secs > 0) {
2484: $secstr = join(';',@secs);
2485: }
2486: if ($secstr ne '') {
2487: return '('.$secstr.')';
2488: }
2489: return;
2490: }
2491:
2492: sub check_clone {
2493: my ($clonedom,$disallowed,$clonename) = @_;
2494: return if (ref($disallowed) ne 'HASH');
2495: if ($clonedom !~ /^$match_domain$/) {
2496: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2497: return;
2498: } elsif (!&Apache::lonnet::domain($clonedom)) {
2499: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2500: return;
2501: }
2502: if ($clonename ne '') {
2503: if ($clonename !~ /^$match_username$/) {
2504: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2505: return;
2506: } else {
2507: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2508: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2509: return;
2510: }
2511: }
2512: }
2513: return 'ok';
2514: }
2515:
2516: sub store_changes {
1.9 raeburn 2517: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2518: my ($chome,$output);
1.118 raeburn 2519: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2520: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 2521: if (ref($values->{'linkprot'}) eq 'HASH') {
2522: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 2523: }
1.102 raeburn 2524: delete($values->{'linkprot'});
1.118 raeburn 2525: if (ref($values->{'ltitools'}) eq 'HASH') {
2526: %oldltitools = %{$values->{'ltitools'}};
2527: }
1.3 raeburn 2528: %storehash = %{$values};
2529: } else {
1.9 raeburn 2530: if ($crstype eq 'Community') {
2531: $output = &mt('No changes made to community settings.');
2532: } else {
2533: $output = &mt('No changes made to course settings.');
2534: }
2535: return $output;
1.3 raeburn 2536: }
1.93 raeburn 2537: my ($numchanges,$skipstore);
2538: if (ref($changes) eq 'HASH') {
2539: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 2540: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 2541: $skipstore = 1;
1.118 raeburn 2542: } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2543: $skipstore = 1;
1.93 raeburn 2544: } elsif (!$numchanges) {
2545: if ($crstype eq 'Community') {
2546: $output = &mt('No changes made to community settings.');
2547: } else {
2548: $output = &mt('No changes made to course settings.');
2549: }
2550: return $output;
2551: }
2552: }
1.3 raeburn 2553: my %yesno = (
2554: hidefromcat => '1',
2555: problem_stream_switch => '1',
2556: suppress_tries => '1',
2557: disableexampointprint => '1',
2558: hideemptyrows => '1',
2559: suppress_embed_prompt => '1',
2560: );
2561: foreach my $item (@{$prefs_order}) {
2562: if (grep(/^\Q$item\E$/,@{$actions})) {
2563: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2564: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 2565: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2566: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2567: if ($item eq 'other') {
2568: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2569: $storehash{$key} = $changes->{$item}{$key};
2570: if ($changes->{$item}{$key} eq '') {
2571: push(@delkeys,$key);
1.22 wenzelju 2572: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2573: } else {
1.22 wenzelju 2574: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2575: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2576: }
2577: }
1.102 raeburn 2578: } elsif ($item eq 'linkprot') {
2579: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.118 raeburn 2580: } elsif ($item eq 'ltitools') {
2581: $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2582: } else {
2583: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2584: my @settings = @{$prefs->{$item}->{'ordered'}};
2585: if ($item eq 'feedback') {
2586: push(@settings,(map { $_.'.text'; } @settings));
2587: }
2588: foreach my $key (@settings) {
2589: if ($key eq 'rolenames') {
2590: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2591: my $msg;
1.9 raeburn 2592: my @roles;
2593: if ($crstype eq 'Community') {
2594: @roles = ('co');
2595: } else {
2596: @roles = ('cc');
2597: }
2598: push(@roles,('in','ta','ep','ad','st'));
2599: foreach my $role (@roles) {
1.3 raeburn 2600: next if (!exists($changes->{$item}{$key.'_'.$role}));
2601: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2602: my $newname = $changes->{$item}{$key.'_'.$role};
2603: $storehash{$role.'.plaintext'} = $newname;
2604: if ($newname eq '') {
2605: $newname = $stdname;
2606: }
2607: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2608: "'<b>".$newname."</b>'").'</li>';
2609: }
2610: if ($msg ne '') {
1.22 wenzelju 2611: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2612: }
1.115 raeburn 2613: } elsif ($key eq 'timezone') {
2614: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2615: my ($displayname,$text);
2616: $text = $prefs->{$item}->{'itemtext'}{$key};
2617: my $displayval;
2618: if (exists($changes->{$item}{$key})) {
2619: $displayname = &mt($text);
2620: $storehash{$key} = $changes->{$item}{$key};
2621: if ($changes->{$item}{$key} ne '') {
2622: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2623: } else {
2624: push(@delkeys,$key);
2625: if (exists($values->{'tzover'})) {
2626: push(@delkeys,'tzover');
2627: }
2628: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2629: '<i>'.$displayname.'</i>')).'</li>';
2630: }
2631: }
2632: unless (grep(/^\Q$key\E$/,@delkeys)) {
2633: if (exists($changes->{$item}{'tzover'})) {
2634: $storehash{'tzover'} = $changes->{$item}{'tzover'};
2635: my $tzovertext;
2636: if ($changes->{$item}{'tzover'} ne '') {
2637: $tzovertext = &mt('Course Time Zone overrides individual user preference');
2638: } else {
2639: push(@delkeys,'tzover');
2640: $tzovertext = &mt('Course Time Zone does not override individual user preference');
2641: }
2642: if ($displayval eq '') {
2643: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2644: } else {
2645: $displayval .= '<br />'.(' 'x5).$tzovertext;
2646: }
2647: }
2648: if ($displayval ne '') {
2649: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2650: '<i>'.$displayname.'</i>',$displayval)).'</li>';
2651: }
2652: }
1.3 raeburn 2653: } else {
2654: next if (!exists($changes->{$item}{$key}));
2655: my ($displayname,$text);
2656: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2657: my $displayval;
1.114 raeburn 2658: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2659: $displayval = $changes->{$item}{$key};
2660: }
1.127 ! raeburn 2661: if (($item eq 'grading') && ($key eq 'grading')) {
! 2662: if ($displayval eq 'standard') {
! 2663: my $hidetotals;
! 2664: if (exists($changes->{$item}{'hidetotals'})) {
! 2665: if ($changes->{$item}{'hidetotals'} eq '') {
! 2666: if (exists($values->{'hidetotals'})) {
! 2667: push(@delkeys,'hidetotals');
! 2668: }
! 2669: } else {
! 2670: $hidetotals = $changes->{$item}{'hidetotals'};
! 2671: }
! 2672: } elsif (exists($values->{'hidetotals'})) {
! 2673: $hidetotals = $values->{'hidetotals'};
! 2674: }
! 2675: if ($hidetotals eq '') {
! 2676: $displayval = &mt('standard with "hide course totals" set to "No"');
! 2677: if (exists($values->{'hidetotals'})) {
! 2678: push(@delkeys,'hidetotals');
! 2679: }
! 2680: } elsif ($hidetotals =~ /^([\w,]+)$/) {
! 2681: my $secstr = $1;
! 2682: my @secs = split(/,/,$secstr);
! 2683: if (grep(/^all$/,@secs)) {
! 2684: $displayval = &mt('standard with "hide course totals" set to "Yes" for all users');
! 2685: $hidetotals = 'all';
! 2686: } else {
! 2687: $displayval = &mt('standard with "hide course totals" set to "Yes" for users in section(s): [_1]',join(', ',@secs));
! 2688: }
! 2689: $storehash{'hidetotals'} = $hidetotals;
! 2690: }
! 2691: } elsif (exists($values->{'hidetotals'})) {
! 2692: push(@delkeys,'hidetotals');
! 2693: }
! 2694: }
1.3 raeburn 2695: if ($item eq 'feedback') {
2696: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2697: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2698: $displayname = &mt('Custom text for '.$text.' questions');
2699: } else {
2700: $displayname = &mt('Recipients of '.$text.' questions');
2701: }
2702: } elsif ($item eq 'discussion') {
2703: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2704: $displayname = &mt("$text (role-based)");
2705: if ($displayval ne '') {
2706: my @roles = split(',',$displayval);
2707: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2708: $displayval = join(', ',@roles);
2709: }
2710: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2711: $displayname = &mt("$text (specific user(s))");
2712: } else {
2713: if ($key eq 'allow_discussion_post_editing') {
2714: if ($displayval ne '') {
2715: my @roles = split(',',$displayval);
2716: my @longroles;
2717: foreach my $role (@roles) {
2718: my ($trole,$sec) = split(':',$role);
2719: my $rolename =
2720: &Apache::lonnet::plaintext($trole);
2721: if ($sec ne '') {
2722: $rolename .= ':'.$sec;
2723: }
2724: push(@longroles,$rolename);
2725: }
2726: $displayval = join(', ',@longroles);
2727: }
1.50 raeburn 2728: } elsif ($key eq 'discussion_post_fonts') {
2729: my ($classorder,$classtitles)=&discussion_vote_classes();
2730: my ($styleorder,$styleitems)=&discussion_vote_styles();
2731: my $count = 1;
2732: my $total = scalar(keys(%{$changes->{$item}}));
2733: foreach my $class (@{$classorder}) {
2734: $count ++;
2735: next unless ($changes->{$item}{$key.'_'.$class});
2736: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2737: my $showval = '';
2738: for (my $i=0; $i<@{$styleorder}; $i++) {
2739: if ($vals[$i] ne '') {
2740: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2741: }
2742: }
2743: if ($vals[3] ne '') {
2744: $showval .= $vals[3];
2745: }
2746: if ($showval ne '') {
2747: $displayval .= $classtitles->{$class}.':{ '.
2748: $showval.'}';
2749: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2750: } else {
2751: $displayval .= $classtitles->{$class}.': '.&mt('None');
2752: push(@delkeys,$key.'_'.$class);
2753: }
2754: unless ($count == $total) {
2755: $displayval .= (' 'x2);
2756: }
2757: }
1.3 raeburn 2758: }
2759: $displayname = &mt($text);
2760: }
2761: } elsif ($item eq 'spreadsheet') {
2762: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2763: my $sheettype = $1;
2764: if ($sheettype eq 'studentcalc') {
2765: &Apache::lonnet::expirespread('','','studentcalc');
2766: } else {
2767: &Apache::lonnet::expirespread('','','assesscalc');
2768: &Apache::lonnet::expirespread('','','studentcalc');
2769: }
2770: }
2771: $displayname = &mt($text);
1.87 raeburn 2772: } elsif ($item eq 'lti') {
2773: if ($key eq 'lti.lcmenu') {
2774: if ($changes->{$item}{$key} eq 'none') {
2775: $displayval = &mt('None of the configurable menu items displayed');
2776: } else {
2777: my %ltititles = <imenu_titles();
2778: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2779: }
2780: } else {
2781: if ($changes->{$item}{$key} eq '1') {
2782: $displayval = &mt('Yes');
2783: } elsif ($changes->{$item}{$key} eq '') {
2784: $displayval = &mt('No');
2785: }
2786: }
2787: $displayname = &mt($text);
1.91 raeburn 2788: } elsif ($item eq 'menuitems') {
2789: unless ($changes->{$item}{$key} eq '') {
2790: if ($key eq 'menudefault') {
2791: $displayname = &mt('Default collection of menu items');
2792: $displayval = &mt('Collection: [_1]',
2793: $changes->{$item}{$key});
2794: } elsif ($key eq 'menucollections') {
2795: $displayval = &menucollections_display($changes->{$item}{$key});
2796: }
2797: }
1.3 raeburn 2798: } else {
2799: $displayname = &mt($text);
2800: }
2801: if (defined($yesno{$key})) {
1.14 raeburn 2802: $displayval = &mt('No');
1.3 raeburn 2803: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2804: $displayval = &mt('Yes');
1.3 raeburn 2805: }
2806: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2807: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2808: } elsif ($key eq 'categories') {
2809: $displayval = $env{'form.categories_display'};
1.95 raeburn 2810: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2811: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2812: if ($changes->{$item}{$key} eq '1') {
2813: $displayval = &mt('Yes');
2814: } elsif ($changes->{$item}{$key} eq '0') {
2815: $displayval = &mt('No');
2816: }
1.114 raeburn 2817: } elsif ($key eq 'extresource') {
2818: if ($changes->{$item}{$key} eq 'iframe') {
2819: $displayval = &mt('In iframe');
2820: } else {
2821: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2822: if ($selected eq 'tab') {
2823: if ($reuse) {
2824: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2825: "'<b>","</b>'",'<br />');
2826: } else {
2827: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2828: "'<b>","</b>'",'<br />');
2829: }
2830: } elsif ($selected eq 'window') {
2831: if ($reuse) {
2832: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2833: "'<b>","</b>'",'<br />');
2834: } else {
2835: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2836: "'<b>","</b>'",'<br />');
2837: }
2838: if (($width ne '') || ($height ne '')) {
2839: if ($width ne '') {
2840: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2841: }
2842: if ($height ne '') {
2843: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2844: }
2845: }
2846: }
2847: }
1.14 raeburn 2848: }
1.25 raeburn 2849: if ($key eq 'co-owners') {
2850: if (ref($changes->{$item}{$key}) eq 'HASH') {
2851: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2852: foreach my $type ('co-owners','pendingco-owners') {
2853: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2854: if ($type eq 'pendingco-owners') {
2855: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2856: $displayname = &mt('Invited as co-owners, pending acceptance');
2857: }
2858: }
2859: if ($changes->{$item}{$key}{$type} eq '') {
2860: push(@delkeys,'internal.'.$type);
2861: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2862: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2863: '<i>'.$displayname.'</i>')).'</li>';
2864: }
2865: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2866: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2867: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2868: '<i>'.$displayname.'</i>',
2869: "'<b>$displayval</b>'")).'</li>';
2870: }
2871: }
2872: }
2873: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2874: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2875: $displayval = &mt('on');
1.90 raeburn 2876: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2877: $displayval = '';
2878: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2879: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2880: $displayval = &mt('off');
2881: }
2882: if ($displayval) {
2883: $displayname = &mt('Your co-ownership status');
2884: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2885: '<i>'.$displayname.'</i>',
2886: "'<b>$displayval</b>'")).'</li>';
2887: }
2888: }
2889: }
2890: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2891: push(@delkeys,$key);
1.87 raeburn 2892: if ($item eq 'lti') {
2893: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2894: if (($key eq 'lti.lcmenu') &&
2895: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2896: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2897: } else {
2898: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2899: '<i>'.$displayname.'</i>',
2900: "'<b>$displayval</b>'")).'</li>';
2901: }
2902: } elsif (!exists($changes->{$item}{'lti.override'})) {
2903: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2904: }
1.91 raeburn 2905: } elsif ($item eq 'menuitems') {
2906: if ($key eq 'menudefault') {
2907: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2908: } elsif ($key eq 'menucollections') {
2909: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2910: }
1.87 raeburn 2911: } else {
2912: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2913: '<i>'.$displayname.'</i>')).'</li>';
2914: }
1.91 raeburn 2915: } elsif ($key eq 'menucollections') {
2916: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2917: $displayval.'</li>';
1.3 raeburn 2918: } else {
1.114 raeburn 2919: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2920: $displayval = "'<b>$displayval</b>'";
2921: }
1.22 wenzelju 2922: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2923: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2924: if ($key eq 'url') {
2925: my $bkuptime=time;
2926: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2927: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2928: }
2929: $output .= '</li>';
2930: }
1.25 raeburn 2931: if ($key eq 'co-owners') {
2932: if (ref($changes->{$item}{$key}) eq 'HASH') {
2933: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2934: foreach my $type ('co-owners','pendingco-owners') {
2935: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2936: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2937: }
2938: }
2939: }
2940: } else {
1.50 raeburn 2941: unless ($key eq 'discussion_post_fonts') {
2942: $storehash{$key} = $changes->{$item}{$key};
2943: }
1.25 raeburn 2944: }
1.3 raeburn 2945: }
1.23 raeburn 2946: if ($key eq 'cloners') {
2947: # Get existing cloners
2948: my %clonenames =
2949: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2950: if ($clonenames{'cloners'} =~ /,/) {
2951: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2952: } else {
2953: $oldcloner[0] = $clonenames{'cloners'};
2954: }
2955: }
1.3 raeburn 2956: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2957: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2958: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2959: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2960: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2961: push(@need_env_update,$key);
2962: }
2963: }
2964: }
2965: }
2966: $output .= '</ul>';
2967: } else {
1.9 raeburn 2968: if ($crstype eq 'Community') {
1.46 raeburn 2969: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2970: } else {
1.46 raeburn 2971: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2972: }
1.3 raeburn 2973: }
2974: }
2975: }
2976: }
1.93 raeburn 2977: if ($skipstore) {
2978: return $output;
2979: }
1.3 raeburn 2980: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2981: if (ref($changes) eq 'HASH') {
2982: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2983: if (exists($changes->{'courseinfo'}{'cloners'})) {
2984: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2985: \@oldcloner);
2986: }
2987: }
2988: }
1.3 raeburn 2989: if (@delkeys) {
2990: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2991: $output .= '<br /><span class="LC_error">';
2992: if ($crstype eq 'Community') {
2993: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2994: } else {
2995: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2996: }
2997: $output .= '</span>';
1.14 raeburn 2998: } else {
2999: foreach my $key (@delkeys) {
3000: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
3001: }
1.3 raeburn 3002: }
3003: }
3004: if (@need_env_update) {
3005: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
3006: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
3007: }
3008: &Apache::lonnet::coursedescription($env{'request.course.id'},
3009: {'freshen_cache' => 1});
3010: } else {
1.9 raeburn 3011: $output = '<span class="LC_error">';
3012: if ($crstype eq 'Community') {
3013: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
3014: } else {
3015: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
3016: }
3017: $output .= '</span>';
1.3 raeburn 3018: }
3019: return $output;
3020: }
3021:
1.102 raeburn 3022: sub store_linkprot {
3023: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 3024: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 3025: if ($context eq 'domain') {
3026: $ltiauth = 1;
1.103 raeburn 3027: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 3028: } else {
1.103 raeburn 3029: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 3030: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
3031: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
3032: } else {
3033: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
3034: $ltiauth = $domdefs{'crsltiauth'};
3035: }
3036: }
3037: if (ref($changes) eq 'HASH') {
3038: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3039: if (ref($changes->{$id}) eq 'HASH') {
3040: if (exists($changes->{$id}->{'key'})) {
3041: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
3042: delete($changes->{$id}->{'key'});
3043: }
3044: if (exists($changes->{$id}->{'secret'})) {
3045: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
3046: delete($changes->{$id}->{'secret'});
3047: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3048: if (exists($oldlinkprot->{$id}{'usable'})) {
3049: $changes->{$id}->{'usable'} = 1;
3050: }
1.109 raeburn 3051: if (exists($oldlinkprot->{$id}{'cipher'})) {
3052: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
3053: }
1.102 raeburn 3054: }
3055: }
3056: }
3057: }
3058: my @ids=&Apache::lonnet::current_machine_ids();
3059: if (keys(%ltienc) > 0) {
3060: if ($context eq 'domain') {
3061: foreach my $id (keys(%ltienc)) {
3062: if (exists($ltienc{$id}{'secret'})) {
3063: $changes->{$id}->{'usable'} = 1;
3064: }
3065: }
3066: } else {
1.103 raeburn 3067: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 3068: my $allowed;
3069: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3070: if ($allowed) {
3071: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
3072: foreach my $id (keys(%ltienc)) {
3073: if (exists($ltienc{$id}{'secret'})) {
3074: $changes->{$id}->{'usable'} = 1;
3075: }
3076: }
3077: } else {
3078: $lti_save_error = 1;
3079: }
3080: }
3081: }
3082: }
3083: }
3084: unless ($lti_save_error) {
3085: if ($context eq 'course') {
3086: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3087: my $hashid=$cdom.'_'.$cnum;
3088: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 3089: unless (($home eq 'no_host') || ($home eq '')) {
3090: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 3091: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3092: }
3093: }
3094: } else {
3095: $lti_save_error = 1;
3096: }
3097: }
3098: unless ($lti_save_error) {
3099: foreach my $id (sort { $a <=> $b } %{$changes}) {
3100: if (ref($changes->{$id}) eq 'HASH') {
3101: my %values = %{$changes->{$id}};
3102: my %desc = &linkprot_names();
3103: my $display;
1.122 raeburn 3104: foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.102 raeburn 3105: if (($title eq 'key') || ($title eq 'secret')) {
3106: if (ref($ltienc{$id}) eq 'HASH') {
3107: if (exists($ltienc{$id}{$title})) {
3108: if ($title eq 'secret') {
3109: my $length = length($ltienc{$id}{$title});
1.103 raeburn 3110: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 3111: } else {
3112: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3113: }
3114: }
3115: }
3116: } elsif ($title eq 'version') {
3117: if ($values{$title} eq 'LTI-1p0') {
3118: $display .= $desc{$title}.': 1.1, ';
3119: }
1.112 raeburn 3120: } elsif ($title eq 'returnurl') {
3121: if ($values{$title}) {
1.124 raeburn 3122: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
1.112 raeburn 3123: }
1.122 raeburn 3124: } elsif ($title eq 'passbackformat') {
3125: if ($values{$title} eq '1.0') {
3126: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
3127: } elsif ($values{$title} eq '1.1') {
3128: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
3129: }
1.102 raeburn 3130: } else {
3131: $display .= $desc{$title}.': '.$values{$title}.', ';
3132: }
3133: }
3134: if ($ltiauth) {
3135: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3136: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3137: $display .= &mt('Source of username: Email address [_1]',
3138: '(lis_person_contact_email_primary)').', ';
3139: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3140: $display .= &mt('Source of username: User ID [_1]',
3141: '(lis_person_sourcedid)').', ';
3142: } else {
3143: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3144: }
3145: if ($values{'notstudent'} eq 'auth') {
3146: $display .= &mt('Display LON-CAPA login page if no match').', ';
3147: } elsif ($values{'notstudent'} eq 'reject') {
3148: $display .= &mt('Discontinue launch if no match').', ';
3149: }
3150: }
3151: }
3152: $display =~ s/, $//;
3153: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3154: "'$display'")).'</li>';
3155: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3156: my $oldname = $oldlinkprot->{$id}{'name'};
3157: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3158: }
3159: }
3160: } else {
3161: $lti_save_error = 1;
3162: }
3163: }
3164: unless ($lti_save_error) {
3165: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3166: unless (ref($changes->{$id}) eq 'HASH') {
3167: push(@deletions,$id);
3168: }
3169: }
3170: if (@deletions) {
3171: if ($context eq 'course') {
3172: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3173: }
3174: }
3175: }
3176: if ($lti_save_error) {
3177: $output .= '<li>'.
3178: '<span class="LC_error">'.
3179: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3180: '</span>'.
3181: '</li>';
3182: }
3183: return $output;
3184: }
3185:
1.118 raeburn 3186: sub store_ltitools {
3187: my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3188: my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3189: my %lt = <itools_names();
3190: my @courseroles = ('cc','in','ta','ep','st');
3191: my @allfields = ('fullname','firstname','lastname','email','user','roles');
3192: if ($context eq 'domain') {
3193: $home = &Apache::lonnet::domain($cdom,'primary');
3194: } else {
3195: $home = &Apache::lonnet::homeserver($cnum,$cdom);
3196: }
3197: if (ref($changes) eq 'HASH') {
3198: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3199: if (ref($changes->{$id}) eq 'HASH') {
3200: if (exists($changes->{$id}->{'key'})) {
3201: $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3202: delete($changes->{$id}->{'key'});
3203: }
3204: if (exists($changes->{$id}->{'secret'})) {
3205: $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3206: delete($changes->{$id}->{'secret'});
3207: } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3208: if (exists($oldltitools->{$id}{'usable'})) {
3209: $changes->{$id}->{'usable'} = 1;
3210: }
3211: if (exists($oldltitools->{$id}{'cipher'})) {
3212: $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3213: }
3214: }
3215: }
3216: }
3217: }
3218: my @ids=&Apache::lonnet::current_machine_ids();
3219: if (keys(%toolsenc) > 0) {
3220: unless (($home eq 'no_host') || ($home eq '')) {
3221: my $allowed;
3222: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3223: if ($allowed) {
3224: if (($context eq 'domain') ||
3225: (($context eq 'course') &&
3226: (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3227: foreach my $id (keys(%toolsenc)) {
3228: if (exists($toolsenc{$id}{'secret'})) {
3229: $changes->{$id}->{'usable'} = 1;
3230: }
3231: }
3232: } else {
3233: $ltitools_save_error = 1;
3234: }
3235: }
3236: }
3237: }
3238: unless ($ltitools_save_error) {
3239: if ($context eq 'course') {
3240: if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3241: my $hashid=$cdom.'_'.$cnum;
3242: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3243: unless (($home eq 'no_host') || ($home eq '')) {
3244: if (grep(/^\Q$home\E$/,@ids)) {
1.120 raeburn 3245: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
1.118 raeburn 3246: }
3247: }
3248: } else {
3249: $ltitools_save_error = 1;
3250: }
3251: }
3252: unless ($ltitools_save_error) {
3253: my %bynum;
3254: foreach my $itemid (sort(keys(%{$changes}))) {
3255: my $position = $changes->{$itemid}{'order'};
3256: $bynum{$position} = $itemid;
3257: }
3258: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3259: my $itemid = $bynum{$pos};
3260: if (ref($changes->{$itemid}) ne 'HASH') {
3261: $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3262: } else {
3263: $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3264: if ($changes->{$itemid}{'image'}) {
3265: $output .= ' '.
3266: '<img src="'.$changes->{$itemid}{'image'}.'"'.
3267: ' alt="'.&mt('Tool Provider icon').'" />';
3268: }
3269: $output .= '</li><ul>';
3270: my $position = $pos + 1;
3271: $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3272: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3273: if ($changes->{$itemid}{$item} ne '') {
3274: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3275: }
3276: }
3277: if (ref($toolsenc{$itemid}) eq 'HASH') {
3278: foreach my $item ('key','secret') {
3279: if (exists($toolsenc{$itemid}{$item})) {
3280: if ($item eq 'secret') {
3281: $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3282: } else {
3283: $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3284: }
3285: }
3286: }
3287: }
3288: $output .= '<li>'.&mt('Configurable in course:');
3289: my @possconfig = ('label','title','target','linktext','explanation','append');
3290: my $numconfig = 0;
3291: if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3292: foreach my $item (@possconfig) {
3293: if ($changes->{$itemid}{'crsconf'}{$item}) {
3294: $numconfig ++;
3295: $output .= ' "'.$lt{'crs'.$item}.'"';
3296: }
3297: }
3298: }
3299: if (!$numconfig) {
3300: $output .= ' '.&mt('None');
3301: }
3302: $output .= '</li>';
3303: foreach my $item ('passback','roster') {
3304: $output .= '<li>'.$lt{$item}.' ';
3305: if ($changes->{$itemid}{$item}) {
3306: $output .= &mt('Yes');
3307: if ($changes->{$itemid}{$item.'valid'}) {
3308: if ($item eq 'passback') {
3309: $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3310: $changes->{$itemid}{$item.'valid'});
3311: } else {
3312: $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3313: $changes->{$itemid}{$item.'valid'});
3314: }
3315: }
3316: } else {
3317: $output .= &mt('No');
3318: }
3319: $output .= '</li>';
3320: }
3321: if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3322: my $displaylist;
3323: if ($changes->{$itemid}{'display'}{'target'}) {
3324: $displaylist = &mt('Display target').': '.
3325: $changes->{$itemid}{'display'}{'target'}.',';
3326: }
3327: foreach my $size ('width','height') {
3328: if ($changes->{$itemid}{'display'}{$size}) {
3329: $displaylist .= (' 'x2).$lt{$size}.': '.
3330: $changes->{$itemid}{'display'}{$size}.',';
3331: }
3332: }
3333: if ($displaylist) {
3334: $displaylist =~ s/,$//;
3335: $output .= '<li>'.$displaylist.'</li>';
3336: }
3337: foreach my $item ('linktext','explanation') {
3338: if ($changes->{$itemid}{'display'}{$item}) {
3339: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3340: }
3341: }
3342: }
3343: if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3344: my $fieldlist;
3345: foreach my $field (@allfields) {
3346: if ($changes->{$itemid}{'fields'}{$field}) {
3347: $fieldlist .= (' 'x2).$lt{$field}.',';
3348: }
3349: }
3350: if ($fieldlist) {
3351: $fieldlist =~ s/,$//;
3352: if ($changes->{$itemid}{'fields'}{'user'}) {
3353: if ($changes->{$itemid}{'incdom'}) {
3354: $fieldlist .= ' ('.&mt('username:domain').')';
3355: } else {
3356: $fieldlist .= ' ('.&mt('username').')';
3357: }
3358: }
3359: $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3360: }
3361: }
3362: if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3363: my $rolemaps;
3364: foreach my $role (@courseroles) {
3365: if ($changes->{$itemid}{'roles'}{$role}) {
3366: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3367: $changes->{$itemid}{'roles'}{$role}.',';
3368: }
3369: }
3370: if ($rolemaps) {
3371: $rolemaps =~ s/,$//;
3372: $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3373: }
3374: }
3375: if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3376: my $customlist;
3377: if (keys(%{$changes->{$itemid}{'custom'}})) {
3378: foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3379: $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3380: }
3381: }
3382: if ($customlist) {
3383: $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3384: }
3385: }
3386: $output .= '</ul></li>';
3387: }
3388: }
3389: }
3390: }
3391: return $output;
3392: }
3393:
1.3 raeburn 3394: sub update_env {
3395: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3396: my $count = 0;
3397: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3398: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3399: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3400: foreach my $key (@{$need_env_update}) {
3401: if ($key eq 'description' && defined($storehash->{$key})) {
3402: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3403: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3404: $count ++;
3405: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3406: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3407: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3408: $count ++;
1.25 raeburn 3409: } elsif ($key eq 'co-owners') {
3410: if ($storehash->{'internal.co-owners'} ne '') {
3411: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3412: }
3413: if ($storehash->{'internal.pendingco-owners'} ne '') {
3414: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3415: }
3416: my @coowners = split(',',$storehash->{'internal.'.$key});
3417: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3418: $count ++;
1.87 raeburn 3419: } elsif ($key =~ /^lti\./) {
3420: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 3421: }
3422: }
3423: if ($count) {
3424: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3425: }
3426: }
3427: }
3428: return;
3429: }
3430:
3431: sub display_disallowed {
1.9 raeburn 3432: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3433: my $output;
3434: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3435: if (keys(%{$disallowed})) {
3436: if ($item eq 'cloners') {
3437: my @fails;
3438: my %lt = &Apache::lonlocal::texthash (
3439: format => 'Invalid format',
3440: domain => 'Domain does not exist',
3441: newuser => 'LON-CAPA user(s) do(es) not exist.',
3442: );
3443: foreach my $error ('format','domain','newuser') {
3444: if (defined($disallowed->{$error})) {
3445: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3446: $lt{$error};
3447: if ($error eq 'newuser') {
1.9 raeburn 3448: $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 3449: }
3450: push(@fails,$msg);
3451: }
3452: }
3453: if (@fails) {
3454: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3455: '</span>'.join('; ',@fails).'.<br />';
3456: }
3457: } elsif ($item eq 'rolenames') {
3458: my %lt = &Apache::lonlocal::texthash (
3459: replacements => 'Name already used to replace a different standard role name',
3460: regulars => 'Name already used as a standard role name',
3461: customrole => 'Name already used as the name of a custom role',
3462: );
3463: my @fails;
3464: foreach my $error ('replacements','regulars','customrole') {
3465: if (ref($disallowed->{$error}) eq 'ARRAY') {
3466: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3467: '</b>, '.&mt('reason').' - '.$lt{'error'});
3468: }
3469: }
3470: if (@fails) {
3471: $output .= '<span class="LC_warning">'.
3472: &mt('Unable to include amongst replacements for role names: ').
3473: '</span>'.join('; ',@fails).'.<br />';
3474: }
3475:
3476: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3477: $output .= '<span class="LC_warning">';
3478: if ($item eq 'feedback') {
1.9 raeburn 3479: if ($crstype eq 'Community') {
3480: $output .= &mt('Unable to include as a recipient of community feedback for:');
3481: } else {
3482: $output .= &mt('Unable to include as a recipient of course feedback for:');
3483: }
1.3 raeburn 3484: } elsif ($item eq 'discussion') {
3485: $output .= &mt('Unable to include in user-based access control for:');
3486: } elsif ($item eq 'localization') {
1.9 raeburn 3487: if ($crstype eq 'Community') {
3488: $output .= &mt('Unable to include in community localization:');
3489: } else {
3490: $output .= &mt('Unable to include in course localization:');
3491: }
1.3 raeburn 3492: }
3493: $output .= '</span><ul>';
3494: foreach my $key (sort(keys(%{$disallowed}))) {
3495: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3496: $output .= '<li><i>'.$itemtext.'</i> - ';
3497: if ($item eq 'localization') {
3498: $output .= &mt('reason - unsupported language: [_1]',
3499: '<b>'.$disallowed->{$key}.'</b>');
3500: } else {
3501: $output .= &mt('reason - invalid user: [_1]',
3502: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3503: }
3504: }
3505: $output .= '</ul><br />';
3506: }
3507: }
1.1 raeburn 3508: }
1.3 raeburn 3509: return $output;
1.1 raeburn 3510: }
3511:
3512: sub get_course {
3513: my ($courseid) = @_;
3514: if (!defined($courseid)) {
3515: $courseid = $env{'request.course.id'};
3516: }
3517: my $cdom=$env{'course.'.$courseid.'.domain'};
3518: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 3519: my $chome=$env{'course.'.$courseid.'.home'};
3520: return ($cnum,$cdom,$chome);
1.1 raeburn 3521: }
3522:
3523: sub get_jscript {
1.91 raeburn 3524: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3525: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 raeburn 3526: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3527: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3528: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3529: my $cloners_js = &cloners_javascript($phase);
1.118 raeburn 3530: my $currltitools;
3531: if (ref($settings) eq 'HASH') {
3532: $currltitools = $settings->{'ltitools'};
3533: }
3534: my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.71 raeburn 3535: my @code_order;
3536: if ($crstype ne 'Community') {
3537: if (ref($settings) eq 'HASH') {
3538: my %codedefaults;
3539: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3540: \@code_order);
3541: if (@code_order > 0) {
3542: if ($phase eq 'display') {
3543: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3544: if (grep(/^courseinfo$/,@actions)) {
3545: if ($settings->{'cloners'} ne '') {
3546: unless ($settings->{'cloners'} eq '*') {
3547: my @cloners = split(/,/,$settings->{'cloners'});
3548: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3549: my %local_to_standard;
3550: for (my $i=0; $i<@code_order; $i++) {
3551: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3552: }
3553: foreach my $cloner (@cloners) {
1.124 raeburn 3554: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
1.71 raeburn 3555: ($cloner !~ /^$match_username\:$match_domain$/)) {
3556: foreach my $item (split(/\&/,$cloner)) {
3557: my ($key,$val) = split(/\=/,$item);
3558: $val = &unescape($val);
3559: foreach my $code (@code_order) {
3560: if ($key eq $local_to_standard{$code}) {
3561: $env{'form.'.$key} = $val;
3562: }
3563: }
3564: }
3565: }
3566: }
3567: }
3568: }
3569: }
3570: }
3571: my @codetitles;
3572: (undef,$instcode_js) =
3573: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3574: \@codetitles);
3575: $instcode_js .= <<ENDSCRIPT;
3576: function toggleCloners(callerradio) {
3577: if (document.getElementById('LC_cloners_instcode')) {
3578: if (callerradio.value == 1) {
3579: document.getElementById('LC_cloners_instcode').style.display = "block";
3580: } else {
3581: uncheckOfficialLists();
3582: document.getElementById('LC_cloners_instcode').style.display = "none";
3583: }
3584: }
3585: }
3586:
3587: if (!document.getElementsByClassName) {
3588: function getElementsByClassName(node, classname) {
3589: var a = [];
3590: var re = new RegExp('(^| )'+classname+'( |$)');
3591: var els = node.getElementsByTagName("*");
3592: for(var i=0,j=els.length; i<j; i++)
3593: if(re.test(els[i].className))a.push(els[i]);
3594: return a;
3595: }
3596: }
3597:
3598: function uncheckOfficialLists() {
3599: var codepicks;
3600: if (document.getElementsByClassName) {
3601: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3602: } else {
3603: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3604: }
3605: if (codepicks.length) {
3606: for (var i=0; i<codepicks.length; i++) {
3607: codepicks[i].selectedIndex = 0;
3608: }
3609: }
3610: }
3611:
3612: ENDSCRIPT
3613: }
3614: }
3615: }
1.1 raeburn 3616: if ($can_categorize) {
3617: $categorize_js = <<ENDSCRIPT;
3618: function catsbrowser() {
3619: var catswin = null;
3620: var url = '/adm/courseprefs?phase=categorizecourse';
3621: if (!catswin || catswin.closed) {
3622: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3623: } else {
3624: catswin.focus();
3625: }
3626: }
3627: ENDSCRIPT
3628: }
1.36 raeburn 3629: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3630: if ($loncaparev) {
3631: $loncaparev_js = <<ENDSCRIPT;
3632: function loncaparevinfo() {
3633: var lcrevwin = null;
3634: var url = '/adm/courseprefs?phase=releaseinfo';
3635: if (!lcrevwin || lcrevwin.closed) {
3636: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3637: } else {
3638: lcrevwin.focus();
3639: }
3640: }
3641: ENDSCRIPT
3642: }
1.60 raeburn 3643: my $cnum = $env{'course.'.$cid.'.num'};
3644: my $syllabus_js = <<ENDSCRIPT;
3645: function syllabusinfo() {
3646: var syllwin = null;
3647: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3648: if (!syllwin || syllwin.closed) {
3649: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3650: } else {
3651: syllwin.focus();
3652: }
3653: }
3654: ENDSCRIPT
1.127 ! raeburn 3655: my ($menuitems_js,$grading_js);
1.91 raeburn 3656: unless ($noedit) {
3657: my $collections;
3658: my $next = 1;
3659: if (ref($settings) eq 'HASH') {
3660: if ($settings->{'menucollections'} ne '') {
3661: my @current;
3662: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3663: my ($num) = split(/\%/,$item);
3664: if ($num =~ /^\d+$/) {
3665: push(@current,$num);
3666: }
3667: }
3668: $collections = join("','",sort { $a <=> $b } @current);
3669: if ($collections) {
3670: $collections = "'$collections'";
3671: }
3672: $next += $current[-1];
3673: }
3674: }
3675: my $deftext = &mt('Standard (all menus shown)');
3676: $menuitems_js = <<ENDSCRIPT;
3677: function toggleAddmenucoll() {
3678: if (document.getElementById('menucollections_add')) {
3679: var state = 'none';
3680: var add = document.getElementById('menucollections_add').checked;
3681: if (add) {
3682: state = 'inline-block';
3683: }
3684: var fieldsets = new Array('shown','text','links','list','inline');
3685: for (var i=0; i<fieldsets.length; i++) {
3686: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3687: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3688: }
3689: }
3690: var box = document.getElementsByClassName('LC_menucoll_add');
3691: if (box.length) {
3692: for (var i=0; i<box.length; i++) {
3693: if (add) {
3694: box[i].checked = true;
3695: } else {
3696: box[i].checked = false;
3697: }
3698: }
3699: }
3700: if (document.getElementById('menudefault')) {
3701: var menudef = document.getElementById('menudefault');
3702: var currsel = menudef.selectedIndex;
3703: var colls = new Array($collections);
3704: menudef.options.length = 0;
3705: if (!add) {
3706: if (currsel == 1 + colls.length) {
3707: currsel = 0;
3708: }
3709: }
3710: if (currsel == 0) {
3711: menudef.options[0] = new Option('$deftext','',true,true);
3712: } else {
3713: menudef.options[0] = new Option('$deftext','',false,false);
3714: }
3715: if (colls.length) {
3716: for (var i=0; i<colls.length; i++) {
3717: var idx = i+1;
3718: if (currsel == colls[i]) {
3719: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3720: } else {
3721: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3722: }
3723: }
3724: }
3725: if (add) {
3726: var addidx = 1 + colls.length;
3727: if (currsel == addidx) {
3728: menudef.options[addidx] = new Option('$next','$next',true,true);
3729: } else {
3730: menudef.options[addidx] = new Option('$next','$next',false,false);
3731: }
3732: }
3733: }
3734: }
3735: }
3736: ENDSCRIPT
1.127 ! raeburn 3737: $grading_js = <<"ENDSCRIPT";
! 3738: function toggleGrading(form) {
! 3739: if (document.getElementById('hidetotalsdiv')) {
! 3740: var totalsdivid = document.getElementById('hidetotalsdiv');
! 3741: var selname = form.elements['grading'];
! 3742: if (selname) {
! 3743: var current = selname.options[selname.selectedIndex].value
! 3744: if (current == 'standard') {
! 3745: totalsdivid.style.display = 'inline-block';
! 3746: } else {
! 3747: totalsdivid.style.display = 'none';
! 3748: }
! 3749: }
! 3750: }
! 3751: return;
! 3752: }
! 3753:
! 3754: function toggleHiddenTotalsSec(form) {
! 3755: if (document.getElementById('sectotalsdiv')) {
! 3756: var sectotalsdivid = document.getElementById('sectotalsdiv');
! 3757: var radioname = form.elements['hidetotals'];
! 3758: if (radioname) {
! 3759: if (radioname.length > 0) {
! 3760: var setvis;
! 3761: for (var i=0; i<radioname.length; i++) {
! 3762: if (radioname[i].checked == true) {
! 3763: if (radioname[i].value == 1) {
! 3764: sectotalsdivid.style.display = 'inline-block';
! 3765: setvis = 1;
! 3766: }
! 3767: break;
! 3768: }
! 3769: }
! 3770: if (!setvis) {
! 3771: sectotalsdivid.style.display = 'none';
! 3772: }
! 3773: }
! 3774: }
! 3775: }
! 3776: return;
! 3777: }
! 3778: ENDSCRIPT
1.91 raeburn 3779: }
1.114 raeburn 3780: $extresource_js = <<"ENDSCRIPT";
3781: function toggleExtRes() {
3782: if (document.getElementById('LC_extresource')) {
3783: var extressel = document.getElementById('LC_extresource').value;
3784: if (document.getElementById('LC_extresreusediv')) {
3785: var extresreuse = document.getElementById('LC_extresreusediv');
3786: if (document.getElementById('LC_extressize')) {
3787: var extressize = document.getElementById('LC_extressize');
3788: var setvis;
3789: if ((extressel == 'tab') || (extressel == 'window')) {
3790: extresreuse.style.display = 'inline-block';
3791: setvis = 1;
3792: if (extressel == 'window') {
3793: extressize.style.display = 'inline-block';
3794: } else {
3795: extressize.style.display = 'none';
3796: }
3797: }
3798: if (!setvis) {
3799: extresreuse.style.display = 'none';
3800: extressize.style.display = 'none';
3801: }
3802: }
3803: }
3804: }
3805: }
3806: ENDSCRIPT
1.115 raeburn 3807: $localization_js = <<"ENDSCRIPT";
3808: function toggleTimeZone() {
3809: if (document.getElementById('LC_set_timezone')) {
3810: var timezonesel = document.getElementById('LC_set_timezone').value;
3811: if (document.getElementById('LC_tzoverdiv')) {
3812: var tzoverdiv = document.getElementById('LC_tzoverdiv');
3813: if (timezonesel == '') {
3814: tzoverdiv.style.display = 'none';
3815: } else {
3816: tzoverdiv.style.display = 'block';
3817: }
3818: }
3819: }
3820: }
3821: ENDSCRIPT
1.1 raeburn 3822: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.124 raeburn 3823: '// <![CDATA['."\n".
1.36 raeburn 3824: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 raeburn 3825: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 3826: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.127 ! raeburn 3827: $grading_js."\n".&linkprot_javascript()."\n".'//]]>'."\n".
1.118 raeburn 3828: '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3829: return $jscript;
3830: }
3831:
1.3 raeburn 3832: sub cloners_javascript {
3833: my ($formname) = @_;
3834: return <<"ENDSCRIPT";
3835:
3836: function update_cloners(caller,num) {
3837: var delidx = getIndexByName('cloners_delete');
3838: var actidx = getIndexByName('cloners_activate');
3839: if (caller == 'cloners_all') {
3840: var selall;
3841: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3842: if (document.$formname.cloners_all[i].checked) {
3843: selall = document.$formname.cloners_all[i].value;
3844: }
3845: }
3846: if (selall == 1) {
3847: if (delidx != -1) {
3848: if (document.$formname.cloners_delete.length) {
3849: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3850: document.$formname.cloners_delete[j].checked = true;
3851: }
3852: } else {
3853: document.$formname.elements[delidx].checked = true;
3854: }
3855: }
3856: if (actidx != -1) {
3857: if (document.$formname.cloners_activate.length) {
3858: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3859: if (document.$formname.cloners_activate[i].value == '0') {
3860: document.$formname.cloners_activate[i].checked = false;
3861: }
1.71 raeburn 3862: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3863: document.$formname.cloners_activate[i].checked = true;
3864: }
3865: }
3866: }
3867: }
3868: document.$formname.cloners_newdom.selectedIndex = 0;
3869: }
3870: }
3871: if (caller == 'cloners_activate') {
3872: if (document.$formname.cloners_activate.length) {
3873: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3874: if (document.$formname.cloners_activate[j].value == num) {
3875: if (document.$formname.cloners_activate[j].checked) {
3876: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3877: if (document.$formname.cloners_all[i].value == '1') {
3878: document.$formname.cloners_all[i].checked = false;
3879: }
3880: if (document.$formname.cloners_all[i].value == '0') {
3881: document.$formname.cloners_all[i].checked = true;
3882: }
3883: }
3884: }
3885: }
3886: }
3887: } else {
3888: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3889: if (document.$formname.cloners_all[i].value == '1') {
3890: document.$formname.cloners_all[i].checked = false;
3891: }
3892: if (document.$formname.cloners_all[i].value == '0') {
3893: document.$formname.cloners_all[i].checked = true;
3894: }
3895: }
3896: }
3897: }
3898: return;
3899: }
3900:
3901: function getIndexByName(item) {
3902: for (var i=0;i<document.$formname.elements.length;i++) {
3903: if (document.$formname.elements[i].name == item) {
3904: return i;
3905: }
3906: }
3907: return -1;
3908: }
3909:
3910: ENDSCRIPT
3911: }
3912:
1.102 raeburn 3913: sub linkprot_javascript {
3914: return <<"ENDSCRIPT";
1.112 raeburn 3915: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 3916: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3917: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3918: var itemname = form.elements['linkprot_'+item+'_'+num];
3919: if (itemname) {
3920: if (itemname.length > 0) {
3921: var setvis;
3922: for (var i=0; i<itemname.length; i++) {
3923: if (itemname[i].checked == true) {
3924: if (itemname[i].value == valon) {
3925: extraid.style.display = styleon;
3926: setvis = 1;
3927: }
3928: break;
3929: }
3930: }
3931: if (!setvis) {
3932: extraid.style.display = 'none';
3933: }
3934: }
3935: }
3936: }
3937: return;
3938: }
1.106 raeburn 3939:
1.102 raeburn 3940: ENDSCRIPT
3941:
3942: }
3943:
1.1 raeburn 3944: sub print_courseinfo {
1.80 raeburn 3945: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3946: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3947: return;
3948: }
1.83 raeburn 3949: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3950: if ($noedit) {
3951: $disabled = ' disabled="disabled"';
3952: }
1.1 raeburn 3953: my %domconf =
1.71 raeburn 3954: &Apache::lonnet::get_dom('configuration',
3955: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3956: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3957: $cathash = $domconf{'coursecategories'}{'cats'};
3958: if (ref($cathash) eq 'HASH') {
3959: $categoriesform =
3960: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 3961: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3962: }
3963: }
1.25 raeburn 3964: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3965: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3966: }
1.71 raeburn 3967: my ($currcanclone,@code_order,$cloner_instcode);
3968: my %codedefaults;
3969: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3970: \@code_order);
3971: if ($settings->{'cloners'}) {
3972: unless ($settings->{'cloners'} eq '*') {
3973: my @currclone = split(/,/,$settings->{'cloners'});
3974: foreach my $item (@currclone) {
3975: unless ($item eq '*') {
3976: if (($item !~ /\:/) && ($item =~ /=/)) {
3977: $cloner_instcode = 1;
3978: }
3979: }
3980: }
3981: }
3982: }
3983: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3984: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3985: if (ref($canclone) eq 'HASH') {
3986: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3987: if ($settings->{'internal.coursecode'}) {
3988: my @posscodes;
3989: if (@code_order > 0) {
3990: $currcanclone = 'instcode';
3991: foreach my $item (@{$canclone->{'instcode'}}) {
3992: if (grep(/^\Q$item\E$/,@code_order)) {
3993: push(@posscodes,$item);
3994: }
3995: }
3996: my $codestr = join(' + ',@posscodes);
3997: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3998: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3999: }
4000: }
4001: }
4002: } elsif ($canclone eq 'domain') {
4003: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
4004: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
4005: $currcanclone = 'domain';
4006: }
4007: if ($clonedefaults) {
4008: if ($settings->{'cloners'} ne '') {
4009: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
4010: } else {
4011: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
4012: }
4013: $clonedefaults = '<br /><br />'.$clonedefaults;
4014: }
4015: }
1.1 raeburn 4016: if (!defined($categoriesform)) {
1.15 raeburn 4017: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 4018: }
1.12 raeburn 4019: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 4020: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 4021:
1.9 raeburn 4022: my $replace;
4023: if ($crstype eq 'Community') {
4024: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
4025: } else {
4026: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
4027: }
1.84 raeburn 4028: my ($editmap,$editsyllabus);
4029: unless ($noedit) {
4030: $editmap = (' 'x2).
4031: '<a href="javascript:openbrowser'.
4032: "('display','url','sequence')\">".
4033: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
4034: &mt('Modification may make assessment data inaccessible!').
4035: '</span>';
4036: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
1.124 raeburn 4037: '</a>');
1.84 raeburn 4038: }
1.1 raeburn 4039: my %items = (
1.3 raeburn 4040: 'url' => {
1.84 raeburn 4041: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 4042: input => 'textbox',
1.55 raeburn 4043: size => '55',
1.19 faziophi 4044: advanced => 1
1.1 raeburn 4045: },
4046: 'description' => {
1.3 raeburn 4047: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 4048: input => 'textbox',
1.55 raeburn 4049: size => '55',
1.1 raeburn 4050: },
1.24 raeburn 4051: 'owner' => {
4052: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
4053: },
1.25 raeburn 4054: 'co-owners' => {
4055: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
4056: },
1.63 raeburn 4057: 'clonedfrom' => {
4058: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
4059: },
1.1 raeburn 4060: 'courseid' => {
1.3 raeburn 4061: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
4062: &mt('internal, optional').')',
1.1 raeburn 4063: input => 'textbox',
4064: size => '25',
4065: },
1.64 raeburn 4066: 'uniquecode' => {
4067: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
4068: },
1.1 raeburn 4069: 'cloners' => {
1.3 raeburn 4070: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 4071: &mt('Owner and Coordinators included automatically').
4072: $clonedefaults,
1.1 raeburn 4073: input => 'textbox',
1.41 www 4074: size => '40'
1.1 raeburn 4075: },
4076: 'rolenames' => {
1.3 raeburn 4077: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 4078: '('.$replace.')',
1.1 raeburn 4079: input => 'textbox',
4080: size => '20',
1.19 faziophi 4081: advanced => 1
1.1 raeburn 4082: },
1.88 raeburn 4083: 'syllabus' => {
4084: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 4085: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 4086: $editsyllabus,
1.1 raeburn 4087: },
4088: 'hidefromcat' => {
1.3 raeburn 4089: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 4090: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
4091: input => 'radio',
4092: },
4093: 'categories' => {
1.3 raeburn 4094: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 4095: &mt('Display Categories').'</a>',
4096: input => 'textbox',
4097: size => '25',
4098: },
1.35 raeburn 4099: 'loncaparev' => {
4100: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
4101: },
1.55 raeburn 4102: 'defaultcredits' => {
4103: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4104: },
1.1 raeburn 4105: );
4106: my $datatable;
4107: my $count = 0;
4108: foreach my $item (@{$ordered}) {
1.56 raeburn 4109: my $colspan;
1.1 raeburn 4110: if ($item eq 'hidefromcat') {
4111: next if (!$can_toggle_cat);
4112: } elsif ($item eq 'categories') {
4113: next if (!$can_categorize);
1.64 raeburn 4114: } elsif ($item eq 'uniquecode') {
4115: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4116: }
1.56 raeburn 4117: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
1.124 raeburn 4118: $colspan = 2;
1.56 raeburn 4119: }
1.1 raeburn 4120: $count ++;
1.19 faziophi 4121: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 4122: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4123: } else {
1.56 raeburn 4124: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4125: }
1.1 raeburn 4126: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 4127: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4128: } elsif ($item eq 'cloners') {
4129: my $includeempty = 1;
4130: my $num = 0;
1.56 raeburn 4131: $datatable .= '</td><td align="right">'.
4132: &Apache::loncommon::start_data_table().
1.1 raeburn 4133: &Apache::loncommon::start_data_table_row().
4134: '<td><span class="LC_nobreak"><label>'.
4135: &mt('Any user in any domain:').
4136: ' <input type="radio" name="cloners_all" value="1" ';
4137: if ($settings->{$item} eq '*') {
4138: $datatable .= ' checked="checked" ';
4139: }
4140: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 4141: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4142: (' 'x2).'<label>'.
4143: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4144: if ($settings->{$item} ne '*') {
4145: $datatable .= ' checked="checked" ';
4146: }
4147: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 4148: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4149: &Apache::loncommon::end_data_table_row().
4150: &Apache::loncommon::end_data_table().
1.56 raeburn 4151: '<table><tr><td align="left"><b>'.&mt('Or').
4152: '</b></td></tr></table>'.
1.1 raeburn 4153: &Apache::loncommon::start_data_table();
4154: my @cloners;
4155: if ($settings->{$item} eq '') {
1.80 raeburn 4156: unless ($noedit) {
4157: my $default;
4158: if ($currcanclone eq 'domain') {
4159: $default = '0';
4160: }
4161: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 4162: }
1.1 raeburn 4163: } elsif ($settings->{$item} ne '*') {
4164: my @entries = split(/,/,$settings->{$item});
4165: if (@entries > 0) {
4166: foreach my $entry (@entries) {
4167: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4168: if ($udom =~ /^$match_domain$/) {
4169: unless (&Apache::lonnet::domain($udom)) {
4170: next;
4171: }
4172: } else {
4173: next;
4174: }
1.1 raeburn 4175: if ($uname eq '*') {
4176: $datatable .=
4177: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4178: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4179: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4180: '</b><input type="hidden" name="cloners_dom_'.$num.
4181: '" value="'.$udom.'" /></span><br />'.
4182: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4183: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4184: &mt('Delete').'</label></span></td>'.
4185: &Apache::loncommon::end_data_table_row();
4186: $num ++;
1.23 raeburn 4187: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4188: unless (grep(/^\Q$entry\E$/,@cloners)) {
4189: push(@cloners,$entry);
4190: }
1.1 raeburn 4191: }
4192: }
4193: }
4194: }
4195: my $add_domtitle = &mt('Any user in additional domain:');
4196: if ($settings->{$item} eq '*') {
4197: $add_domtitle = &mt('Any user in specific domain:');
4198: } elsif ($settings->{$item} eq '') {
4199: $add_domtitle = &mt('Any user in other domain:');
4200: }
4201: my $cloners_str = join(',',@cloners);
4202: $datatable .= &Apache::loncommon::start_data_table_row().
4203: '<td align="left"><span class="LC_nobreak">'.
4204: $add_domtitle.'</span><br />'.
4205: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 4206: $includeempty,undef,undef,
4207: undef,undef,$noedit).
1.1 raeburn 4208: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4209: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4210: &Apache::loncommon::end_data_table().
1.56 raeburn 4211: '<table><tr><td align="left"><b>'.&mt('And').
4212: '</b></td></tr></table>'.
1.1 raeburn 4213: &Apache::loncommon::start_data_table().
4214: &Apache::loncommon::start_data_table_row().
4215: '<td align="left">'.
4216: &mt('Specific users').' (<tt>'.
4217: &mt('user:domain,user:domain').'</tt>)<br />'.
4218: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 4219: $items{$item}{'size'},$disabled).
1.1 raeburn 4220: '</td>'.&Apache::loncommon::end_data_table_row().
4221: &Apache::loncommon::end_data_table();
1.71 raeburn 4222: if (@code_order > 0) {
4223: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4224: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4225: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4226: \%cat_items,\@codetitles,
4227: \%cat_titles,\%cat_order);
4228: my $showncodes = 'off';
4229: my $checkedoff = ' checked="checked"';
4230: my $checkedon = '';
4231: if ($cloner_instcode) {
4232: $checkedon = $checkedoff;
4233: $checkedoff = '';
4234: $showncodes = 'on';
4235: }
4236: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4237: '</b></td></tr></table>'.
4238: &Apache::loncommon::start_data_table().
4239: &Apache::loncommon::start_data_table_row().
4240: '<td align="left"><span class="LC_nobreak">'.
4241: &mt('Cloning by official course(s) based on course category').(' 'x2).
4242: '<label>'.
1.80 raeburn 4243: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4244: (' ').
4245: '<label>'.
1.80 raeburn 4246: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 4247: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4248: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 4249: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 4250: '</td>'.&Apache::loncommon::end_data_table_row().
4251: &Apache::loncommon::end_data_table();
4252: }
1.1 raeburn 4253: } elsif ($item eq 'rolenames') {
1.56 raeburn 4254: $datatable .= '</td><td align="right">'.
4255: &Apache::loncommon::start_data_table();
1.9 raeburn 4256: my @roles;
4257: if ($crstype eq 'Community') {
4258: @roles = ('co');
4259: } else {
4260: @roles = ('cc');
4261: }
4262: push (@roles,('in','ta','ep','ad','st'));
4263: foreach my $role (@roles) {
1.1 raeburn 4264: $datatable .= &Apache::loncommon::start_data_table_row().
4265: '<td align="left"><span class="LC_nobreak">'.
4266: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4267: '</span></td><td align="left">'.
4268: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4269: $settings->{$role.'.plaintext'},
1.80 raeburn 4270: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4271: &Apache::loncommon::end_data_table_row();
4272: }
4273: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4274: } elsif ($item eq 'categories') {
1.80 raeburn 4275: my $launcher;
4276: if ($noedit) {
4277: $launcher = $disabled;
4278: } else {
4279: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4280: }
1.3 raeburn 4281: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4282: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4283: $items{$item}{size},$launcher);
1.24 raeburn 4284: } elsif ($item eq 'owner') {
4285: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4286: if ($owner =~ /:/) {
4287: my ($ownername,$ownerdom) = split(':',$owner);
4288: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4289: } elsif ($owner ne '') {
4290: $owner = &Apache::loncommon::plainname($owner,$cdom);
4291: } else {
4292: $owner = &mt('None specified');
4293: }
4294: $datatable .= $owner;
1.63 raeburn 4295: } elsif ($item eq 'clonedfrom') {
4296: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4297: my $clonedfrom = &mt('None');
4298: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 4299: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 4300: if ($clonesrcinfo{'description'}) {
1.124 raeburn 4301: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
1.63 raeburn 4302: }
4303: }
4304: $datatable .= $clonedfrom;
1.64 raeburn 4305: } elsif ($item eq 'uniquecode') {
1.124 raeburn 4306: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
1.64 raeburn 4307: if ($code) {
4308: $datatable .= $code;
4309: }
1.25 raeburn 4310: } elsif ($item eq 'co-owners') {
4311: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4312: my @currcoown;
4313: if ($coowners) {
4314: @currcoown = split(',',$coowners);
4315: }
4316: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4317: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4318: $datatable .= &show_autocoowners(@currcoown);
4319: } else {
1.80 raeburn 4320: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4321: }
4322: } else {
4323: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4324: $datatable .= &show_autocoowners(@currcoown);
4325: } else {
1.80 raeburn 4326: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4327: }
4328: }
1.88 raeburn 4329: } elsif ($item eq 'syllabus') {
1.60 raeburn 4330: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4331: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4332: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4333: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4334: if ($minimal =~/\w/) {
4335: if ($external =~ m{\Q$minimal\E$}) {
4336: undef($external);
4337: }
4338: } elsif ($uploaded =~/\w/) {
4339: if ($external =~ m{\Q$uploaded\E$}) {
4340: undef($external);
4341: }
4342: }
4343: } elsif ($external!~/\w/) {
4344: undef($external);
4345: }
4346: if ($external) {
4347: $datatable .= &mt('External URL');
4348: } elsif ($minimal) {
4349: $datatable .= &mt('Minimal template');
4350: } elsif ($uploaded) {
4351: $datatable .= &mt('Uploaded file');
4352: } else {
1.124 raeburn 4353: $datatable .= &mt('Standard template');
1.60 raeburn 4354: }
4355: $datatable .= (' ' x 2).
4356: &mt('[_1]View[_2]',
4357: '<a href="javascript:syllabusinfo();">',
1.124 raeburn 4358: '</a>');
1.35 raeburn 4359: } elsif ($item eq 'loncaparev') {
4360: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4361: my $showreqd;
4362: if ($loncaparev) {
1.36 raeburn 4363: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4364: &mt('Details').'</a>';
1.35 raeburn 4365: } else {
4366: $showreqd = &mt('No specific version required');
4367: }
4368: $datatable .= $showreqd;
1.1 raeburn 4369: } else {
1.80 raeburn 4370: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4371: }
4372: $datatable .= &item_table_row_end();
4373: }
4374: $$rowtotal += scalar(@{$ordered});
4375: return $datatable;
4376: }
4377:
4378: sub new_cloners_dom_row {
1.71 raeburn 4379: my ($newdom,$num,$default) = @_;
4380: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4381: if ($newdom ne '') {
1.71 raeburn 4382: if ($num eq $default) {
1.124 raeburn 4383: $checkedon = 'checked="checked" ';
1.71 raeburn 4384: } else {
4385: $checkedoff = 'checked="checked" ';
4386: }
1.1 raeburn 4387: $output .= &Apache::loncommon::start_data_table_row().
4388: '<td valign="top"><span class="LC_nobreak">'.
4389: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4390: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 4391: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4392: 'onchange="javascript:update_cloners('.
1.1 raeburn 4393: "'cloners_activate','$num'".');" />'.
4394: &mt('Yes').'</label>'.(' 'x2).
4395: '<label><input type="radio" '.
1.71 raeburn 4396: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4397: 'onchange="javascript:update_cloners('.
1.1 raeburn 4398: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4399: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4400: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4401: &Apache::loncommon::end_data_table_row();
4402: }
4403: return $output;
4404: }
4405:
4406: sub can_modify_catsettings {
1.12 raeburn 4407: my ($dom,$crstype) = @_;
1.1 raeburn 4408: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4409: my ($can_toggle_cat,$can_categorize);
4410: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4411: if ($crstype eq 'Community') {
4412: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4413: $can_toggle_cat = 1;
4414: }
4415: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4416: $can_categorize = 1;
4417: }
4418: } else {
4419: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4420: $can_toggle_cat = 1;
4421: }
4422: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4423: $can_categorize = 1;
4424: }
1.1 raeburn 4425: }
4426: }
4427: return ($can_toggle_cat,$can_categorize);
4428: }
4429:
4430: sub assign_course_categories {
1.9 raeburn 4431: my ($r,$crstype) = @_;
1.1 raeburn 4432: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4433: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4434: my $hascats = 0;
4435: my $cathash;
4436: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4437: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4438: $cathash = $domconf{'coursecategories'}{'cats'};
4439: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4440: foreach my $cat (keys(%{$cathash})) {
4441: next if ($cat eq 'instcode::0');
4442: unless ($crstype eq 'Community') {
4443: next if ($cat eq 'communities::0');
4444: }
4445: $hascats ++;
4446: }
1.1 raeburn 4447: }
4448: }
4449: my $catwin_js;
4450: if ($hascats) {
1.9 raeburn 4451: my $alert;
4452: if ($crstype eq 'Community') {
4453: $alert = &mt("Use 'Save' in the main window to save community categories");
4454: } else {
4455: $alert = &mt("Use 'Save' in the main window to save course categories");
4456: }
1.72 damieng 4457: &js_escape(\$alert);
1.1 raeburn 4458: $catwin_js = <<ENDSCRIPT;
4459: <script type="text/javascript">
4460:
4461: function updateCategories() {
4462: var newcategories = '';
4463: var unescapedcats = '';
4464: if (document.chgcats.usecategory.length) {
4465: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4466: if (document.chgcats.usecategory[i].checked == true) {
4467: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4468: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4469: }
4470: }
4471: if (newcategories.length > 0) {
4472: newcategories = newcategories.slice(0,-1);
4473: }
4474: if (unescapedcats.length > 0) {
4475: unescapedcats = unescapedcats.slice(0,-3);
4476: }
4477: } else {
4478: if (document.chgcats.usecategory.checked == true) {
4479: newcategories = document.chgcats.usecategory.value;
4480: unescapedcats = document.chgcats.catname.value;
4481: }
4482: }
4483: opener.document.display.categories.value = newcategories;
4484: opener.document.display.categories_display.value = unescapedcats;
4485: alert("$alert");
4486: self.close();
4487: return;
4488: }
4489:
4490: </script>
4491: ENDSCRIPT
4492: } else {
4493: my $onload;
4494: }
1.9 raeburn 4495: my ($crscat,$catcrs,$assign);
4496: if ($crstype eq 'Community') {
4497: $crscat = 'Community Categories';
4498: $catcrs = &mt('Categorize Community');
4499: $assign = &mt('Assign one or more categories to this community.')
4500: } else {
4501: $crscat = 'Course Categories';
4502: $catcrs = &mt('Categorize Course');
4503: $assign = &mt('Assign one or more categories to this course.')
4504: }
1.1 raeburn 4505: my $start_page =
1.9 raeburn 4506: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4507: {'only_body' => 1,});
4508: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4509: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4510: if ($hascats) {
4511: my %currsettings =
4512: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4513: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4514: $currsettings{'categories'},$crstype);
4515: if ($cattable eq '') {
4516: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4517: } else {
4518: $categoriesform .= $assign.'<br /><br />'.
4519: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4520: $cattable."\n".
4521: '<br /><input type="button" name="changes" value="'.
4522: &mt('Copy to main window').'" '.
4523: 'onclick="javascript:updateCategories()" /></form><br />';
4524: }
1.1 raeburn 4525: } else {
1.12 raeburn 4526: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4527: }
4528: $r->print($start_page.$categoriesform.$end_page);
4529: return;
4530: }
4531:
1.36 raeburn 4532: sub display_loncaparev_constraints {
4533: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.124 raeburn 4534: my ($reqdmajor,$reqdminor);
1.36 raeburn 4535: my $cid = $env{'request.course.id'};
4536: my $cdom = $env{'course.'.$cid.'.domain'};
4537: my $cnum = $env{'course.'.$cid.'.num'};
4538: my $output;
1.39 raeburn 4539: my %lt = &Apache::lonlocal::texthash (
4540: 'all' => 'all',
4541: 'section/group' => 'section/group',
4542: 'user' => 'user',
4543: );
1.66 raeburn 4544: &Apache::lonrelrequtils::init_global_hashes();
4545: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4546: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4547: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 4548: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4549: }
4550: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 4551: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 4552: @scopeorder = ('all','section/group','user');
1.67 raeburn 4553: my $now = time;
1.36 raeburn 4554: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4555: if (ref($resourcedata) eq 'HASH') {
4556: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 4557: my %found;
1.66 raeburn 4558: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4559: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 4560: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
4561: my $value = $resourcedata->{$key};
4562: if ($item eq 'examcode') {
4563: if (&Apache::lonnet::validCODE($value)) {
4564: $value = 'valid';
4565: } else {
4566: $value = '';
4567: }
4568: } elsif ($item eq 'printstartdate') {
1.67 raeburn 4569: if ($value =~ /^\d+$/) {
1.70 raeburn 4570: if ($value > $now) {
4571: $value = 'future';
4572: }
4573: }
4574: } elsif ($item eq 'printenddate') {
4575: if ($value =~ /^\d+$/) {
4576: if ($value < $now) {
4577: $value = 'past';
4578: }
4579: }
4580: }
4581: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
4582: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4583: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 4584: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 4585: }
4586: }
4587: }
4588: }
1.79 raeburn 4589: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
4590: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 4591: my $value = $resourcedata->{$key};
1.79 raeburn 4592: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 4593: if ($value =~ /$valuematch/) {
4594: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 4595: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 4596: $found{$item}{'rev'} =
1.76 raeburn 4597: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 4598: last;
4599: }
4600: }
4601: }
4602: }
1.76 raeburn 4603: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
4604: my $regexp;
4605: if ($item eq 'maplevelrecurse') {
4606: $regexp = '\.(?:sequence|page)___\(rec\)\.';
4607: }
4608: if ($regexp ne '') {
4609: if ($key =~ /$regexp.*\.(\w+)$/) {
4610: my $name = $1;
4611: my $value = $resourcedata->{$key};
4612: if ($name eq 'type') {
4613: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
4614: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
4615: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
4616: }
4617: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
4618: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
4619: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
4620: $found{$name}{'rev'} =
4621: $Apache::lonnet::needsrelease{'parameter::::'.$item};
4622: }
4623: }
4624: }
1.70 raeburn 4625: foreach my $item (keys(%found)) {
4626: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4627: my $rev = $found{$item}{'rev'};
4628: my $valname = $found{$item}{'valname'};
1.76 raeburn 4629: my $extra = $found{$item}{'extra'};
1.70 raeburn 4630: my ($middle,$scope,$which,$level,$map,$resource);
4631: my $start = $cid.'.';
4632: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4633: $middle = $1;
4634: $which = $2;
4635: $scope = 'user';
4636: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4637: $middle = $1;
4638: $which = $2;
4639: $scope = 'section/group';
4640: } else {
4641: $scope = 'all';
4642: }
4643: my $what="$stdname=$valname";
1.76 raeburn 4644: if ($extra) {
4645: $what .= "<br/>$extra<br />";
4646: }
1.70 raeburn 4647: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4648: $level = 'general';
4649: if ($scope eq 'all') {
4650: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4651: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4652: push(@{$fromparam{$rev}{$scope}},$what);
4653: }
4654: } else {
4655: push(@{$fromparam{$rev}{$scope}},$what);
4656: }
4657: } else {
4658: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4659: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4660: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4661: }
4662: } else {
4663: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4664: }
4665: }
4666: $rowspan{$rev} ++;
1.76 raeburn 4667: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 4668: $level = 'folder';
4669: $map = $1;
4670: if ($scope eq 'all') {
4671: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4672: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4673: push(@{$bymap{$map}{$rev}{$scope}},$what);
4674: }
4675: } else {
4676: push(@{$bymap{$map}{$rev}{$scope}},$what);
4677: }
4678: } else {
4679: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4680: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4681: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4682: }
4683: } else {
4684: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4685: }
4686: }
4687: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4688: $level = 'resource';
4689: $resource = $1;
4690: if ($scope eq 'all') {
4691: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4692: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4693: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4694: }
4695: } else {
4696: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4697: }
4698: } else {
4699: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4700: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4701: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4702: }
4703: } else {
4704: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 4705: }
4706: }
4707: }
4708: }
4709: }
4710: if (keys(%fromparam)) {
4711: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4712: &Apache::loncommon::start_data_table().
4713: &Apache::loncommon::start_data_table_header_row().
4714: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4715: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4716: &Apache::loncommon::end_data_table_header_row();
4717: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 4718: my ($major,$minor) = split(/\./,$rev);
4719: ($reqdmajor,$reqdminor) =
4720: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4721: $output .= &Apache::loncommon::start_data_table_row().
4722: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4723: my $newrow;
4724: foreach my $scope (@scopeorder) {
4725: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4726: if ($newrow) {
4727: $output .= &Apache::loncommon::continue_data_table_row();
4728: }
1.39 raeburn 4729: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4730: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4731: $output .= '<td>'.$which.'</td><td>'.
4732: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4733: }
4734: $output .= &Apache::loncommon::end_data_table_row();
4735: $newrow = 1;
4736: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4737: if ($newrow) {
4738: $output .= &Apache::loncommon::continue_data_table_row();
4739: }
1.39 raeburn 4740: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4741: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4742: &Apache::loncommon::end_data_table_row();
4743: $newrow = 1;
4744: }
4745: }
4746: }
4747: $output .= &Apache::loncommon::end_data_table().'<br />';
4748: }
4749: }
4750:
1.66 raeburn 4751: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4752: my $now = time;
4753: if (keys(%comm_blocks) > 0) {
4754: foreach my $block (keys(%comm_blocks)) {
4755: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 4756: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 4757: if (ref($comm_blocks{$block}) eq 'HASH') {
4758: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4759: ' '.&mt('set by [_1]',
4760: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4761: }
4762: next;
4763: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4764: my ($start,$end) = ($1,$2);
4765: next if ($end < $now);
4766: }
4767: if (ref($comm_blocks{$block}) eq 'HASH') {
4768: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4769: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4770: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 4771: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 4772: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4773: ' '.
4774: &mt('set by [_1]',
4775: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4776: }
4777: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 4778: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 4779: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4780: ' '.
4781: &mt('set by [_1]',
4782: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4783:
4784: }
4785: }
4786: }
4787: }
4788: if (keys(%fromblocks)) {
4789: my %lt = (
4790: docs => 'Content blocking',
4791: printout => 'Printout generation',
4792: timer => 'Timed quiz trigger',
4793: );
4794: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4795: &Apache::loncommon::start_data_table().
4796: &Apache::loncommon::start_data_table_header_row().
4797: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4798: '<th>'.&mt('Event(s)').'</th>'.
4799: &Apache::loncommon::end_data_table_header_row();
4800: foreach my $type ('docs','printout','timer') {
4801: if (ref($fromblocks{$type}) eq 'HASH') {
4802: foreach my $rev (keys(%{$fromblocks{$type}})) {
4803: my ($major,$minor) = split(/\./,$rev);
1.124 raeburn 4804: ($reqdmajor,$reqdminor) =
1.66 raeburn 4805: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4806: $output .= &Apache::loncommon::start_data_table_row().
4807: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4808: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4809: $output .= $event.'<br />';
4810: }
4811: $output =~ s{\Q<br />\E$}{};
4812: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4813: }
4814: }
4815: }
4816: $output .= &Apache::loncommon::end_data_table().'<br />';
4817: }
4818: }
4819:
1.36 raeburn 4820: if (defined($navmap)) {
4821: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 4822: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 4823: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 4824: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 4825: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 4826: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4827: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4828: my $valanon=&get_param_description($stdtype,'anonsurvey');
4829: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 4830: my %checkedrev;
1.85 raeburn 4831: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 4832: my @parts = @{$res->parts()};
4833: my $symb = $res->symb();
4834: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 4835: if ($res->is_tool()) {
4836: my $rev = $rev_exttool;
4837: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
4838: $allmaps{$enclosing_map} = 1;
4839: next;
4840: }
1.36 raeburn 4841: foreach my $part (@parts) {
4842: if (exists($anonsubms{$symb."\0".$part})) {
4843: my $rev = $rev_anonsurv;
4844: my $what="$stdname=$valanon";
4845: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4846: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4847: push(@{$bysubmission{$symb}{$rev}},$what);
4848: }
4849: } else {
4850: push(@{$bysubmission{$symb}{$rev}},$what);
4851: }
4852: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4853: unless ($checkedrev{'anonsurvey'}) {
4854: my ($major,$minor) = split(/\./,$rev);
4855: ($reqdmajor,$reqdminor) =
4856: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4857: $reqdmajor,$reqdminor);
4858: $checkedrev{'anonsurvey'} = 1;
4859: }
1.36 raeburn 4860: }
4861: if (exists($randtrysubms{$symb."\0".$part})) {
4862: my $rev = $rev_randtry;
4863: my $what="$stdname=$valrandtry";
4864: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4865: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4866: push(@{$bysubmission{$symb}{$rev}},$what);
4867: }
4868: } else {
4869: push(@{$bysubmission{$symb}{$rev}},$what);
4870: }
4871: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4872: unless ($checkedrev{'randomizetry'}) {
4873: my ($major,$minor) = split(/\./,$rev);
4874: ($reqdmajor,$reqdminor) =
4875: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4876: $reqdmajor,$reqdminor);
4877: $checkedrev{'randomizetry'} = 1;
4878: }
1.36 raeburn 4879: }
4880: }
4881: my %responses = $res->responseTypes();
4882: foreach my $key (keys(%responses)) {
1.66 raeburn 4883: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4884: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4885: unless ($checkedrev{$key}) {
4886: my ($major,$minor) = split(/\./,$rev);
4887: ($reqdmajor,$reqdminor) =
4888: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4889: $reqdmajor,$reqdminor);
4890: $checkedrev{$key} = 1;
1.124 raeburn 4891: }
1.66 raeburn 4892: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4893: $allmaps{$enclosing_map} = 1;
4894: }
4895: }
4896: }
4897: if (keys(%byresource) > 0) {
4898: foreach my $symb (keys(%byresource)) {
4899: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4900: $allmaps{$map} = 1;
4901: }
4902: }
4903: if (keys(%bymap) > 0) {
4904: foreach my $map (keys(%bymap)) {
4905: $allmaps{$map} = 1;
4906: }
4907: }
4908: foreach my $map (keys(%allmaps)) {
4909: my $mapres = $navmap->getResourceByUrl($map);
4910: if (ref($mapres)) {
1.68 raeburn 4911: my $mapsymb = $mapres->symb();
4912: $toshow{$mapsymb} = 1;
1.36 raeburn 4913: my $pcslist = $mapres->map_hierarchy();
4914: if ($pcslist ne '') {
4915: foreach my $pc (split(/,/,$pcslist)) {
4916: my $res = $navmap->getByMapPc($pc);
4917: if (ref($res)) {
4918: my $symb = $res->symb();
4919: unless ($symb eq '______') {
4920: $toshow{$symb} = 1;
4921: }
4922: }
4923: }
4924: }
4925: }
4926: }
4927: }
1.117 raeburn 4928: my $supptools = &Apache::lonnet::count_supptools($cnum,$cdom,1,1);
1.36 raeburn 4929: my $mapres_header = '<h4>'.
4930: &mt('Requirements for specific folders or resources').
4931: '</h4>';
4932: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4933: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4934: $output .= $mapres_header;
4935: }
4936: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4937: my $title = 'Version Constraints';
4938: my $start_page =
4939: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4940: $r->print($start_page.$top_header);
4941: if ($output) {
4942: $r->print($output);
1.86 raeburn 4943: if (defined($navmap) || $supptools) {
1.36 raeburn 4944: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4945: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4946: }
4947: $r->print('<br /><br />');
4948: } else {
4949: $r->print('<p class="LC_info">'.
4950: &mt('No version requirements from resource content or settings.').
4951: '</p>');
4952: }
4953: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4954: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4955: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4956: return 1;
4957: }
1.36 raeburn 4958: return;
4959: }
4960:
4961: sub show_contents_view {
1.39 raeburn 4962: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 4963: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
4964: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4965: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4966: my $showmaincontent;
4967: if ((ref($navmap)) &&
4968: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4969: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
4970: (keys(%{$bycrsrestype}) > 0))) {
4971: $showmaincontent = 1;
4972: }
4973: if ($showmaincontent || $supptools) {
4974: $r->print(&Apache::loncommon::start_data_table());
4975: }
4976: if ($showmaincontent) {
4977: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 4978: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 4979: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 4980: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4981: '<th>'.&mt('Attribute/Setting').'</th>'.
4982: &Apache::loncommon::end_data_table_header_row().
4983: &Apache::loncommon::start_data_table_row().
1.58 raeburn 4984: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 4985: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
4986: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4987: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4988: my $curRes;
4989: my $depth = 0;
4990: my %parent = ();
4991: my $startcount = 5;
4992: my $lastcontainer = $startcount;
4993: while ($curRes = $it->next()) {
4994: if ($curRes == $it->BEGIN_MAP()) {
4995: $depth++;
4996: $parent{$depth}= $lastcontainer;
4997: }
4998: if ($curRes == $it->END_MAP()) {
4999: $depth--;
5000: $lastcontainer = $parent{$depth};
5001: }
5002: my $indent;
5003: for (my $i=0; $i<$depth; $i++) {
5004: $indent.= $whitespace;
5005: }
5006: if (ref($curRes)) {
5007: my $symb = $curRes->symb();
5008: my $ressymb = $symb;
5009: my $srcf = $curRes->src();
5010: my $title = &Apache::lonnet::gettitle($srcf);
5011: if (($curRes->is_sequence()) || ($curRes->is_page())) {
5012: next unless($toshow->{$symb});
5013: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
5014: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5015: if ($curRes->is_page()) {
5016: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
5017: }
5018: my $rowspan = 1;
5019: if (ref($bymap->{$url}) eq 'HASH') {
5020: $rowspan = scalar(keys(%{$bymap->{$url}}));
5021: }
5022: $r->print(&Apache::loncommon::start_data_table_row().
5023: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 5024: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 5025: $r->print(&Apache::loncommon::end_data_table_row());
5026: } else {
5027: my $rowspan;
5028: if (ref($byresource->{$symb}) eq 'HASH') {
5029: $rowspan += scalar(keys(%{$byresource->{$symb}}));
5030: }
5031: if (ref($bysubmission->{$symb}) eq 'HASH') {
5032: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
5033: }
5034: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5035: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
5036: }
1.85 raeburn 5037: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5038: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
5039: }
1.36 raeburn 5040: next if (!$rowspan);
5041: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
5042: &mt('Problem').'" />';
5043: $r->print(&Apache::loncommon::start_data_table_row().
5044: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
5045: my $newrow;
5046: if (ref($byresource->{$symb}) eq 'HASH') {
5047: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
5048: if ($newrow) {
5049: $r->print(&Apache::loncommon::continue_data_table_row());
5050: }
5051: $r->print('<td valign="middle">'.$rev.'</td><td>');
5052: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
5053: $r->print('<table border="0">');
5054: foreach my $scope (@{$scopeorder}) {
5055: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5056: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5057: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
5058: $r->print('<td>'.$which.'</td><td>'.
5059: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
5060: '</td>');
5061: }
5062: $r->print('</tr>');
5063: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5064: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 5065: '<td> </td><td>'.
5066: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
5067: }
5068: }
5069: $r->print('</table>');
5070: }
5071: $r->print('</td>');
5072: $r->print(&Apache::loncommon::end_data_table_row());
5073: $newrow = 1;
5074: }
5075: }
5076: if (ref($bysubmission->{$symb}) eq 'HASH') {
5077: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
5078: if ($newrow) {
5079: $r->print(&Apache::loncommon::continue_data_table_row());
5080: }
5081: $r->print('<td>'.$rev.'</td><td>');
5082: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
5083: $r->print(&mt('Submissions to: ').' '.
5084: join(', ',@{$bysubmission->{$symb}{$rev}}));
5085: }
5086: $r->print('</td>');
5087: $r->print(&Apache::loncommon::end_data_table_row());
5088: $newrow = 1;
5089: }
5090: }
5091: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5092: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
5093: if ($newrow) {
5094: $r->print(&Apache::loncommon::continue_data_table_row());
5095: }
5096: $r->print('<td>'.$rev.'</td><td>');
5097: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
5098: $r->print(&mt('Response Type(s): ').' '.
5099: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
5100: }
5101: $r->print('</td>');
5102: }
5103: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 5104: $newrow = 1;
5105: }
5106: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5107: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
5108: if ($newrow) {
5109: $r->print(&Apache::loncommon::continue_data_table_row());
5110: }
5111: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
5112: }
1.86 raeburn 5113: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5114: }
5115: }
5116: }
5117: }
1.86 raeburn 5118: }
5119: if ($supptools) {
5120: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5121: $r->print(&Apache::loncommon::start_data_table_header_row().
5122: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5123: '<th>'.&mt('Resource Type').'</th>'.
5124: &Apache::loncommon::end_data_table_header_row().
5125: &Apache::loncommon::start_data_table_row().
5126: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
5127: '<td valign="middle">'.
5128: $Apache::lonrelrequtils::exttool{'major'}.'.'.
5129: $Apache::lonrelrequtils::exttool{'minor'}.
5130: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
5131: $supptools).'</td>'.
5132: &Apache::loncommon::end_data_table_row());
5133: }
5134: if ($showmaincontent || $supptools) {
1.36 raeburn 5135: $r->print(&Apache::loncommon::end_data_table());
5136: }
1.66 raeburn 5137: return;
1.36 raeburn 5138: }
5139:
5140: sub releases_by_map {
1.39 raeburn 5141: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 5142: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.124 raeburn 5143: my $newrow = 0;
1.36 raeburn 5144: if (ref($bymap->{$url}) eq 'HASH') {
5145: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 5146: if ($newrow) {
5147: $r->print(&Apache::loncommon::end_data_table_row().
5148: &Apache::loncommon::continue_data_table_row());
5149: }
1.36 raeburn 5150: $r->print('<td valign="middle">'.$rev.'</td><td>');
5151: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
5152: $r->print('<table border="0">');
5153: foreach my $scope (@{$scopeorder}) {
5154: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5155: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5156: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
5157: $r->print('<td>'.$which.'</td><td>'.
5158: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
5159: '</td>');
5160: }
5161: $r->print('</tr>');
5162: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5163: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 5164: '</td><td> </td><td>'.
5165: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
5166: }
5167: }
5168: $r->print('</table>');
5169: }
5170: $r->print('</td>');
1.73 raeburn 5171: $newrow = 1;
1.36 raeburn 5172: }
5173: } else {
5174: $r->print('<td colspan="2"> </td>');
5175: }
5176: return;
5177: }
5178:
5179: sub get_param_description {
1.70 raeburn 5180: my ($stdtype,$value,$regexp) = @_;
5181: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 5182: if ($stdtype =~ /^string/) {
5183: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5184: } elsif ($stdtype eq 'date_interval') {
5185: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
5186: }
1.70 raeburn 5187: if ($regexp) {
1.74 raeburn 5188: if ($stdtype =~ /^string/) {
5189: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
5190: } elsif ($stdtype eq 'date_interval') {
5191: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
5192: }
1.70 raeburn 5193: if (ref($parammatches) eq 'ARRAY') {
5194: @possibles = @{$parammatches};
5195: } else {
5196: undef($regexp);
5197: $name = $value;
5198: }
5199: }
5200: unless ($regexp) {
5201: $name = $value;
5202: if (ref($paramstrings) eq 'ARRAY') {
5203: @possibles = @{$paramstrings};
5204: } else {
1.76 raeburn 5205: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
5206: if ($name == 0) {
5207: $name = &mt('Never');
5208: } elsif (($name ne '') && ($name !~ /\D/)) {
5209: $name = &Apache::lonlocal::locallocaltime($name);
5210: }
5211: }
1.70 raeburn 5212: return $name;
5213: }
1.36 raeburn 5214: }
1.70 raeburn 5215: foreach my $possibilities (@possibles) {
1.36 raeburn 5216: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 5217: my $gotregexmatch = '';
5218: if ($regexp) {
5219: last if ($gotregexmatch);
5220: my ($item,$pattern) = @{ $possibilities };
5221: if ($value =~ /$pattern/) {
5222: if (ref($paramstrings) eq 'ARRAY') {
5223: foreach my $possibles (@{$paramstrings}) {
5224: next unless (ref($possibles) eq 'ARRAY');
5225: my ($thing,$description) = @{$possibles};
5226: if ($thing eq $item) {
5227: $name = $description;
5228: $gotregexmatch = 1;
5229: last;
5230: }
5231: }
5232: last if ($gotregexmatch);
5233: }
5234: }
5235: } else {
5236: my ($thing,$description) = @{ $possibilities };
5237: if ($thing eq $value) {
5238: $name = $description;
5239: last;
5240: }
1.36 raeburn 5241: }
5242: }
5243: return $name;
5244: }
5245:
1.66 raeburn 5246: sub update_releasereq {
5247: my $readmap = 1;
5248: my $getrelreq = 1;
5249: if (ref($modified_courses) eq 'ARRAY') {
5250: foreach my $item (@{$modified_courses}) {
5251: if (ref($item) eq 'ARRAY') {
5252: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5253: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5254: $chome,$crstype,$cdom.'_'.$cnum,
5255: $readmap,$getrelreq);
5256: }
5257: }
5258: $modified_courses = [];
5259: }
5260: undef($registered_cleanup);
5261: return;
5262: }
5263:
1.25 raeburn 5264: sub show_autocoowners {
5265: my (@currcoown) = @_;
1.56 raeburn 5266: 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 5267: if (@currcoown > 0) {
5268: $output .= '<br />'.&mt('Current co-owners are:').' '.
5269: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5270: } else {
5271: $output .= '<br />'.&mt('Currently no co-owners.');
5272: }
5273: return $output;
5274: }
5275:
5276: sub coowner_invitations {
1.80 raeburn 5277: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5278: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5279: my $pendingcoowners =
5280: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5281: if ($pendingcoowners) {
5282: @pendingcoown = split(',',$pendingcoowners);
5283: }
1.80 raeburn 5284: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5285: @currcoown = @{$currcoownref};
1.80 raeburn 5286: }
5287: my $disabled;
5288: if ($noedit) {
5289: $disabled = ' disabled="disabled"';
5290: }
1.25 raeburn 5291: my $ccrole = 'cc';
5292: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5293: foreach my $key (sort(keys(%ccroles))) {
5294: my ($ccname,$ccdom,$role) = split(':',$key);
5295: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5296: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5297: push(@othercoords,$ccname.':'.$ccdom);
5298: }
5299: }
5300: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5301: if ($coowner_rows) {
5302: $output .= &Apache::loncommon::start_data_table();
5303: if (@currcoown) {
5304: $output .= &Apache::loncommon::start_data_table_row().
5305: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5306: foreach my $person (@currcoown) {
5307: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5308: $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 5309: }
5310: $output .= '</td>'.
5311: &Apache::loncommon::end_data_table_row();
5312: }
5313: if ($pendingcoowners) {
5314: $output .= &Apache::loncommon::start_data_table_row().
5315: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5316: foreach my $person (@pendingcoown) {
5317: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5318: $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 5319: }
5320: $output .= '</td>'.
5321: &Apache::loncommon::end_data_table_row();
5322: }
5323: if (@othercoords) {
5324: $output .= &Apache::loncommon::start_data_table_row().
5325: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5326: foreach my $person (@othercoords) {
5327: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5328: $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 5329: }
5330: $output .= '</td>'.
5331: &Apache::loncommon::end_data_table_row();
5332: }
5333: $output .= &Apache::loncommon::end_data_table();
5334: } else {
5335: $output = &mt('There are no coordinators to select as co-owners');
5336: }
5337: return $output;
5338: }
5339:
5340: sub manage_coownership {
1.80 raeburn 5341: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5342: my (@pendingcoown,@currcoown);
1.25 raeburn 5343: my $pendingcoowners =
5344: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5345: if ($pendingcoowners) {
5346: @pendingcoown = split(',',$pendingcoowners);
5347: }
1.80 raeburn 5348: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5349: @currcoown = @{$currcoownref};
1.80 raeburn 5350: }
5351: my $disabled;
5352: if ($noedit) {
5353: $disabled = ' disabled="disabled"';
5354: }
1.25 raeburn 5355: my ($is_coowner,$is_pending,$output);
5356: my $uname = $env{'user.name'};
5357: my $udom = $env{'user.domain'};
5358: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5359: $is_coowner = 1;
5360: }
5361: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5362: $is_pending = 1;
5363: }
5364: if (@currcoown && ($is_coowner || $is_pending)) {
5365: $output = &Apache::loncommon::start_data_table();
5366: }
5367: if (@currcoown) {
5368: if ($is_coowner || $is_pending) {
5369: $output .= &Apache::loncommon::start_data_table().
5370: &Apache::loncommon::start_data_table_row().'<td>';
5371: }
5372: $output .= &mt('Current co-owners are:').' '.
5373: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5374: if ($is_coowner || $is_pending) {
5375: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5376: }
5377: }
5378: if ($is_coowner || $is_pending) {
5379: if (@currcoown) {
5380: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5381: }
5382: $output .= '<span class="LC_nobreak">';
5383: if ($is_coowner) {
1.90 raeburn 5384: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5385: } else {
1.90 raeburn 5386: $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).
5387: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5388: }
5389: $output .= '</span>';
5390: if (@currcoown) {
5391: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5392: }
5393: }
5394: if (@currcoown && ($is_coowner || $is_pending)) {
5395: $output .= &Apache::loncommon::end_data_table();
5396: }
5397: return $output;
5398: }
5399:
1.1 raeburn 5400: sub print_localization {
1.80 raeburn 5401: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5402: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5403: return;
5404: }
5405: my %items = (
5406: languages => {
1.17 faziophi 5407: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5408: &mt("(overrides individual user preference)"),
1.1 raeburn 5409: input => 'selectbox',
5410: },
5411: timezone => {
1.17 faziophi 5412: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5413: input => 'selectbox',
5414: },
5415: datelocale => {
1.17 faziophi 5416: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5417: input => 'selectbox',
5418: },
5419: );
1.80 raeburn 5420: my ($datatable,$disabled);
1.1 raeburn 5421: my $count = 0;
1.80 raeburn 5422: if ($noedit) {
5423: $disabled = ' disabled="disabled"';
5424: }
1.1 raeburn 5425: foreach my $item (@{$ordered}) {
5426: $count ++;
1.56 raeburn 5427: my $colspan;
5428: unless ($item eq 'languages') {
1.80 raeburn 5429: $colspan = 2;
1.56 raeburn 5430: }
5431: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5432: if ($item eq 'timezone') {
5433: my $includeempty = 1;
5434: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5435: my $onchange;
5436: unless ($noedit) {
5437: $onchange = ' onchange="javascript:toggleTimeZone();"';
5438: }
5439: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5440: $datatable .=
1.115 raeburn 5441: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5442: $includeempty,$id,$disabled);
5443: my $tzsty = 'none';
5444: if ($timezone ne '') {
5445: $tzsty = 'block';
5446: }
5447: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5448: '<span class="LC_nobreak">'.
5449: &mt('Override individual user preference?').
5450: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5451: '</span></div>';
1.1 raeburn 5452: } elsif ($item eq 'datelocale') {
5453: my $includeempty = 1;
5454: my $locale_obj = &Apache::lonlocal::getdatelocale();
5455: my $currdatelocale;
5456: if (ref($locale_obj)) {
5457: $currdatelocale = $locale_obj->id();
5458: }
5459: $datatable .=
5460: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5461: undef,$includeempty,$disabled);
1.1 raeburn 5462: } else {
5463: if ($settings->{$item} eq '') {
1.124 raeburn 5464: unless ($noedit) {
1.80 raeburn 5465: $datatable .= '</td><td align="right">'.
5466: &Apache::loncommon::select_language('languages_0','',1);
5467: }
1.1 raeburn 5468: } else {
5469: my $num = 0;
1.3 raeburn 5470: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5471: $datatable .= '</td><td align="right"><br />'.
5472: &Apache::loncommon::start_data_table();
1.1 raeburn 5473: if (@languages > 0) {
1.3 raeburn 5474: my %langchoices = &get_lang_choices();
1.1 raeburn 5475: foreach my $lang (@languages) {
5476: my $showlang = $lang;
1.3 raeburn 5477: if (exists($langchoices{$lang})) {
5478: $showlang = $langchoices{$lang};
1.1 raeburn 5479: }
5480: $datatable .=
5481: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5482: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5483: &mt('Language:').'<b> '.$showlang.
5484: '</b><input type="hidden" name="languages_'.$num.
5485: '" value="'.$lang.'" /></span><br />'.
5486: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5487: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5488: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5489: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5490: $num ++;
5491: }
5492: }
1.80 raeburn 5493: unless ($noedit) {
5494: $datatable .=
5495: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5496: '<td align="left"><span class="LC_nobreak">'.
5497: &mt('Additional language:'). '</span><br />'.
5498: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5499: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5500: '</td>'.&Apache::loncommon::end_data_table_row();
1.124 raeburn 5501: }
5502: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5503: }
5504: }
5505: $datatable .= &item_table_row_end();
5506: }
5507: $$rowtotal += scalar(@{$ordered});
5508: return $datatable;
5509: }
5510:
1.3 raeburn 5511: sub get_lang_choices {
5512: my %langchoices;
5513: foreach my $id (&Apache::loncommon::languageids()) {
5514: my $code = &Apache::loncommon::supportedlanguagecode($id);
5515: if ($code) {
5516: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5517: }
5518: }
5519: return %langchoices;
5520: }
5521:
1.1 raeburn 5522: sub print_feedback {
1.80 raeburn 5523: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5524: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5525: return;
5526: }
5527: my %items = (
1.3 raeburn 5528: 'question.email' => {
5529: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5530: input => 'textbox',
5531: size => '50',
5532: },
5533:
1.3 raeburn 5534: 'comment.email' => {
5535: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5536: input => 'textbox',
5537: size => '50',
5538: },
5539:
1.3 raeburn 5540: 'policy.email' => {
5541: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5542: input => 'textbox',
5543: size => '50',
5544: },
5545: );
5546: my $datatable;
5547: my $count = 0;
5548: my ($cnum) = &get_course();
5549: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5550: my @sections = sort( { $a <=> $b } keys(%sections));
5551: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5552: currone => 'Current recipient:',
5553: currmult => 'Current recipients:',
5554: add => 'Additional recipient:',
5555: del => 'Delete?',
5556: sec => 'Sections:',
1.1 raeburn 5557: );
1.80 raeburn 5558: my $disabled;
5559: if ($noedit) {
5560: $disabled = ' disabled="disabled"';
5561: }
1.1 raeburn 5562: foreach my $item (@{$ordered}) {
5563: $count ++;
1.20 faziophi 5564: if ($position eq 'top') {
5565: $datatable .= &item_table_row_start($items{$item}{text},$count);
5566: } else {
1.56 raeburn 5567: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5568: }
1.1 raeburn 5569: if ($position eq 'top') {
5570: my $includeempty = 0;
1.94 raeburn 5571: $datatable .= '</td><td align="right">'.
5572: &user_table($cdom,$item,\@sections,
1.80 raeburn 5573: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5574: } else {
1.3 raeburn 5575: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5576: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5577: }
5578: $datatable .= &item_table_row_end();
5579: }
5580: $$rowtotal += scalar(@{$ordered});
5581: return $datatable;
5582: }
5583:
5584: sub user_table {
1.80 raeburn 5585: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5586: my $output;
5587: if ($currvalue eq '') {
1.80 raeburn 5588: unless ($noedit) {
5589: $output .= &select_recipient($item,'0',$cdom,$sections);
5590: }
1.1 raeburn 5591: } else {
5592: my $num = 0;
5593: my @curr = split(/,/,$currvalue);
1.56 raeburn 5594: $output .= '<table class="LC_data_table">';
1.1 raeburn 5595: my ($currusers);
1.80 raeburn 5596: my $disabled;
5597: if ($noedit) {
5598: $disabled = ' disabled="disabled"';
5599: }
1.1 raeburn 5600: foreach my $val (@curr) {
5601: next if ($val eq '');
5602: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5603: my @selsec;
5604: if ($seclist) {
5605: $seclist =~ s/(^\(|\)$)//g;
5606: @selsec = split(/\s*;\s*/,$seclist);
5607: }
5608: $currusers .= '<tr>'.
5609: '<td valign="top"><span class="LC_nobreak">'.
5610: '<label><input type="checkbox" '.
1.80 raeburn 5611: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5612: $lt->{'del'}.'</label>'.
5613: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5614: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5615: &Apache::loncommon::aboutmewrapper(
5616: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5617: $uname,$udom,'aboutuser');
5618: if (ref($sections) eq 'ARRAY') {
5619: if (@{$sections}) {
5620: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5621: &select_sections($item,$num,$sections,
1.80 raeburn 5622: \@selsec,$noedit);
1.1 raeburn 5623: }
5624: }
5625: $currusers .= '</span></td></tr>';
5626: $num ++;
5627: }
5628: if ($num) {
1.10 raeburn 5629: $output .= '<tr>'.
1.1 raeburn 5630: '<td align="left"><i>';
1.20 faziophi 5631: if ($num == 1) {
1.1 raeburn 5632: $output .= $lt->{'currone'};
5633: } else {
1.21 raeburn 5634: $output .= $lt->{'currmult'};
1.1 raeburn 5635: }
5636: $output .= '</i><br />'.
5637: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5638: '</tr>';
1.1 raeburn 5639: }
1.80 raeburn 5640: unless ($noedit) {
5641: $output .=
5642: '<tr>'.
1.1 raeburn 5643: '<td align="left"><span class="LC_nobreak"><i>'.
5644: $lt->{'add'}.'</i></span><br />'.
5645: &select_recipient($item,$num,$cdom,$sections).
5646: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5647: '</td></tr>';
5648: }
5649: $output .= '</table>';
1.1 raeburn 5650: }
5651: return $output;
5652: }
5653:
5654: sub select_recipient {
5655: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5656: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5657: my $selectlink =
5658: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5659: $item.'_udom_'.$num,'only');
1.1 raeburn 5660: my $output =
1.10 raeburn 5661: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5662: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5663: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5664: if (ref($sections) eq 'ARRAY') {
5665: if (@{$sections}) {
5666: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5667: &select_sections($item,$num,$sections,$selected).'</td>';
5668: }
5669: }
5670: $output .= '<td valign="top">'.
5671: $selectlink.'</td></tr></table>';
5672: return $output;
5673: }
5674:
5675: sub select_sections {
1.127 ! raeburn 5676: my ($item,$num,$sections,$selected,$noedit,$allval) = @_;
1.80 raeburn 5677: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5678: if (ref($selected) eq 'ARRAY') {
5679: @currsecs = @{$selected};
5680: }
5681: if (!@currsecs) {
5682: $allsec = ' selected="selected"';
5683: }
1.80 raeburn 5684: if ($noedit) {
5685: $disabled = ' disabled="disabled"';
5686: }
1.1 raeburn 5687: if (ref($sections) eq 'ARRAY') {
5688: if (@{$sections}) {
5689: my $mult;
5690: if (@{$sections} > 1) {
5691: $mult = ' multiple="multiple"';
1.127 ! raeburn 5692: my $size;
1.1 raeburn 5693: if (@{$sections} > 3) {
1.127 ! raeburn 5694: $size = 4;
! 5695: } else {
! 5696: $size = 1 + scalar(@{$sections});
1.1 raeburn 5697: }
1.127 ! raeburn 5698: $mult .= ' size="'.$size.'"';
! 5699: }
! 5700: my $name = $item.'_sections';
! 5701: unless ($item eq 'hidetotals') {
! 5702: $name .= '_'.$num;
1.1 raeburn 5703: }
1.127 ! raeburn 5704: $output = '<select name="'.$name.'"'.$mult.$disabled.'>'.
! 5705: ' <option value="'.$allval.'"'.$allsec.'>'.&mt('All').'</option>';
1.1 raeburn 5706: foreach my $sec (@{$sections}) {
5707: my $is_sel;
5708: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
1.127 ! raeburn 5709: $is_sel = ' selected="selected"';
1.1 raeburn 5710: }
5711: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5712: }
5713: $output .= '</select>';
5714: }
5715: }
5716: return $output;
5717: }
5718:
5719: sub print_discussion {
1.80 raeburn 5720: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5721: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5722: return;
5723: }
5724: my %items = (
5725: 'plc.roles.denied' => {
1.10 raeburn 5726: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5727: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5728: &mt('(role-based)'),
1.1 raeburn 5729: input => 'checkbox',
5730: },
5731:
5732: 'plc.users.denied' => {
1.3 raeburn 5733: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5734: &mt('(specific user(s))'),
1.1 raeburn 5735: input => 'checkbox',
5736: },
5737:
5738: 'pch.roles.denied' => {
1.10 raeburn 5739: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5740: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5741: &mt('(role-based)'),
1.1 raeburn 5742: input => 'checkbox',
5743: },
5744:
5745: 'pch.users.denied' => {
1.3 raeburn 5746: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5747: &mt('(specific user(s))'),
1.1 raeburn 5748: input => 'checkbox',
5749: },
1.77 raeburn 5750:
5751: 'pac.roles.denied' => {
5752: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5753: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5754: &mt('(role-based)'),
5755: input => 'checkbox',
5756: },
5757:
5758: 'pac.users.denied' => {
5759: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5760: &mt('(specific user(s))'),
5761: input => 'checkbox',
5762: },
5763:
1.1 raeburn 5764: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5765: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5766: input => 'radio',
5767: },
5768:
5769: 'allow_discussion_post_editing' => {
1.3 raeburn 5770: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5771: input => 'checkbox',
5772: },
1.50 raeburn 5773: 'discussion_post_fonts' => {
5774: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5775: input => 'textbox',
5776: size => '20',
5777: },
1.1 raeburn 5778: );
5779: my $datatable;
5780: my $count;
5781: my ($cnum) = &get_course();
5782: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5783: my @sections = sort( { $a <=> $b } keys(%sections));
5784: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5785: currone => 'Disallowed:',
5786: currmult => 'Disallowed:',
5787: add => 'Disallow more:',
5788: del => 'Delete?',
5789: sec => 'Sections:',
1.1 raeburn 5790: );
5791: foreach my $item (@{$ordered}) {
5792: $count ++;
1.56 raeburn 5793: my $colspan;
5794: if ($item eq 'allow_limited_html_in_feedback') {
5795: $colspan = 2;
1.124 raeburn 5796: }
1.56 raeburn 5797: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5798: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5799: $datatable .= '</td><td align="right">'.
1.80 raeburn 5800: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5801: '</table>';
5802: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5803: $datatable .= '</td><td align="right">'.
5804: &user_table($cdom,$item,undef,
1.80 raeburn 5805: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5806: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5807: $datatable .= '</td><td align="right">'.
1.80 raeburn 5808: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5809: '</table>';
5810: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5811: $datatable .= '</td><td align="right">'.
5812: &user_table($cdom,$item,undef,
1.80 raeburn 5813: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5814: } elsif ($item eq 'pac.roles.denied') {
5815: $datatable .= '</td><td align="right">'.
1.80 raeburn 5816: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5817: '</table>';
5818: } elsif ($item eq 'pac.users.denied') {
5819: $datatable .= '</td><td align="right">'.
5820: &user_table($cdom,$item,undef,
1.80 raeburn 5821: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5822: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5823: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5824: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5825: $datatable .= '</td><td align="right"><br />'.
5826: &Apache::loncommon::start_data_table().
1.1 raeburn 5827: &Apache::loncommon::start_data_table_row().
5828: '<th align="left">'.&mt('Role').'</th><th>'.
5829: &mt('Sections').'</th>'.
5830: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5831: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5832: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5833: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5834: $datatable .= '</td><td align="right"><br />'.
5835: &Apache::loncommon::start_data_table().
1.50 raeburn 5836: &Apache::loncommon::start_data_table_row().
5837: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5838: '<th align="center">'.&mt('font-size').'</th>'.
5839: '<th align="center">'.&mt('font-weight').'</th>'.
5840: '<th align="center">'.&mt('font-style').'</th>'.
1.124 raeburn 5841: '<th align="center">'.&mt('Other css').'</th>'.
1.50 raeburn 5842: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5843: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5844: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5845: }
5846: $datatable .= &item_table_row_end();
5847: }
5848: $$rowtotal += scalar(@{$ordered});
5849: return $datatable;
5850: }
5851:
5852: sub role_checkboxes {
1.80 raeburn 5853: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5854: my @roles = ('st','ad','ta','ep','in');
5855: if ($crstype eq 'Community') {
5856: push(@roles,'co');
5857: } else {
5858: push(@roles,'cc');
5859: }
1.1 raeburn 5860: my $output;
5861: my (@current,@curr_roles,%currsec,@sections);
5862: if ($showsections) {
5863: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5864: @sections = sort( { $a <=> $b } keys(%sections));
5865: }
5866: if (ref($settings) eq 'HASH') {
5867: if ($settings->{$item}) {
5868: @current = split(',',$settings->{$item});
5869: if ($showsections) {
5870: foreach my $role (@current) {
5871: if ($role =~ /:/) {
5872: my ($trole,$sec) = split(':',$role);
5873: push(@curr_roles,$trole);
5874: if (ref($currsec{$trole}) eq 'ARRAY') {
5875: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5876: push(@{$currsec{$trole}},$sec);
5877: }
1.3 raeburn 5878: } else {
5879: $currsec{$trole} = [$sec];
1.1 raeburn 5880: }
5881: } else {
5882: push(@curr_roles,$role);
5883: }
5884: }
5885: @current = @curr_roles;
5886: }
5887: }
5888: }
5889: my $numinrow = 3;
5890: my $count = 0;
1.80 raeburn 5891: my $disabled;
5892: if ($noedit) {
1.124 raeburn 5893: $disabled = ' disabled="disabled"';
1.80 raeburn 5894: }
1.1 raeburn 5895: foreach my $role (@roles) {
5896: my $checked = '';
5897: if (grep(/^\Q$role\E$/,@current)) {
5898: $checked = ' checked="checked" ';
5899: }
1.9 raeburn 5900: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5901: if ($showsections) {
5902: $output .= &Apache::loncommon::start_data_table_row();
5903: } else {
5904: my $rem = $count%($numinrow);
5905: if ($rem == 0) {
5906: if ($count > 0) {
5907: $output .= '</tr>';
5908: }
5909: $output .= '<tr>';
5910: }
5911: }
1.30 raeburn 5912: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5913: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5914: $plrole.'</label></span></td>';
5915: if ($showsections) {
5916: $output .= '<td align="left">'.
1.80 raeburn 5917: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5918: '</td></tr>';
5919: }
5920: $count ++;
5921: }
5922: my %adv_roles =
5923: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5924: my $total = @roles;
5925: foreach my $role (sort(keys(%adv_roles))) {
5926: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5927: my $rolename = $3;
5928: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5929: my $checked = '';
5930: if (grep(/^\Q$value\E$/,@current)) {
5931: $checked = ' checked="checked" ';
5932: }
5933: if ($showsections) {
5934: $output .= &Apache::loncommon::start_data_table_row();
5935: } else {
5936: my $rem = $count%($numinrow);
5937: if ($rem == 0) {
5938: if ($count > 0) {
5939: $output .= '</tr>';
5940: }
5941: $output .= '<tr>';
5942: }
5943: }
1.30 raeburn 5944: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5945: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5946: '</label></span></td>';
5947: if ($showsections) {
5948: $output .= '<td>'.
1.80 raeburn 5949: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5950: '</td>'.&Apache::loncommon::end_data_table_row();
5951: }
5952: $total ++;
5953: $count ++;
5954: }
5955: }
5956: if (!$showsections) {
5957: my $rem = $total%($numinrow);
5958: my $colsleft = $numinrow - $rem;
5959: if ($colsleft > 1 ) {
5960: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5961: ' </td>';
5962: } elsif ($colsleft == 1) {
5963: $output .= '<td class="LC_left_item"> </td>';
5964: }
5965: $output .= '</tr>';
5966: }
5967: return $output;
5968: }
5969:
1.50 raeburn 5970: sub set_discussion_fonts {
1.80 raeburn 5971: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 5972: my ($classorder,$classtitles) = &discussion_vote_classes();
5973: my ($styleorder,$styleitems) = &discussion_vote_styles();
5974: my $output;
5975: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 5976: my $disabled;
5977: if ($noedit) {
5978: $disabled = ' disabled="disabled"';
5979: }
1.50 raeburn 5980: foreach my $cat (@{$classorder}) {
5981: my %curr = ();
5982: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5983: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5984: $output .= &Apache::loncommon::start_data_table_row().
5985: '<td>'.$classtitles->{$cat}.'</td>';
5986: if (ref($styleorder) eq 'ARRAY') {
5987: foreach my $item (@{$styleorder}) {
5988: $output .= '<td><span class="LC_nobreak">';
5989: my $selitem = $item;
5990: if ($item eq 'size') {
5991: my ($currsize,$currunit);
5992: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5993: ($currsize,$currunit) = ($1,$2);
5994: $curr{'size'} = $currunit;
5995: }
1.81 raeburn 5996: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 5997: ' ';
5998: $selitem = 'unit';
5999: }
6000: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 6001: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 6002: foreach my $val (@{$styleitems->{$item}}) {
6003: my $sel;
6004: if ($val eq $curr{$item}) {
6005: $sel = ' selected="selected"';
6006: }
6007: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
6008: }
6009: }
6010: }
6011: }
1.80 raeburn 6012: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 6013: }
6014: $output .= &Apache::loncommon::end_data_table_row();
6015: }
6016: return $output;
6017: }
6018:
6019: sub discussion_vote_classes {
6020: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
1.124 raeburn 6021: my %classtitles = &Apache::lonlocal::texthash(
1.50 raeburn 6022: 'twoplus' => 'Two sigma above mean',
6023: 'oneplus' => 'One sigma above mean',
6024: 'zero' => 'Within one sigma of mean',
6025: 'oneminus' => 'One sigma below mean',
6026: 'twominus' => 'Two sigma below mean',
6027: );
6028: return ($classorder,\%classtitles);
6029: }
6030:
6031: sub discussion_vote_styles {
6032: my $styleorder = ['size','weight','style'];
6033: my $styleitems = {
6034: size => ['','px','%','xx-small','x-small','small','medium','large',
6035: 'x-large','xx-large','smaller','larger'],
6036: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
6037: '500','600','700','800','900'],
6038: style => ['','normal','italic','oblique'],
6039: };
6040: return ($styleorder,$styleitems);
6041: }
6042:
1.1 raeburn 6043: sub print_classlists {
1.80 raeburn 6044: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 6045: my @ordered;
6046: if ($position eq 'top') {
6047: @ordered = ('default_enrollment_start_date',
6048: 'default_enrollment_end_date');
1.55 raeburn 6049: if ($crstype eq 'Course') {
6050: push(@ordered,'defaultcredits');
6051: }
1.1 raeburn 6052: } elsif ($position eq 'middle') {
1.56 raeburn 6053: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 6054: } else {
6055: @ordered = ('student_classlist_view',
1.26 raeburn 6056: 'student_classlist_opt_in',
6057: 'student_classlist_portfiles');
1.1 raeburn 6058: }
1.9 raeburn 6059: my %lt;
6060:
6061: if ($crstype eq 'Community') {
6062: %lt = &Apache::lonlocal::texthash (
6063: disabled => 'No viewable membership list',
6064: section => "Membership of viewer's section",
6065: all => 'List of all members',
6066: );
6067: } else {
6068: %lt = &Apache::lonlocal::texthash (
6069: disabled => 'No viewable classlist',
6070: section => "Classlist of viewer's section",
6071: all => 'Classlist of all students',
6072: );
6073: }
6074:
1.1 raeburn 6075: my %items = (
6076: 'default_enrollment_start_date' => {
1.3 raeburn 6077: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 6078: input => 'dates',
6079: },
6080: 'default_enrollment_end_date' => {
1.3 raeburn 6081: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 6082: input => 'dates',
6083: },
1.55 raeburn 6084: 'defaultcredits' => {
6085: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
6086: },
1.124 raeburn 6087:
1.1 raeburn 6088: 'nothideprivileged' => {
1.3 raeburn 6089: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 6090: input => 'checkbox',
6091: },
6092:
1.56 raeburn 6093: 'checkforpriv' => {
6094: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
6095: input => 'selectbox',
6096: },
6097:
1.1 raeburn 6098: 'student_classlist_view' => {
1.3 raeburn 6099: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 6100: input => 'selectbox',
1.9 raeburn 6101: options => \%lt,
1.1 raeburn 6102: order => ['disabled','all','section'],
6103: },
1.26 raeburn 6104: 'student_classlist_opt_in' => {
6105: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 6106: input => 'radio',
6107: },
6108:
6109: 'student_classlist_portfiles' => {
1.3 raeburn 6110: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 6111: input => 'radio',
6112: },
6113: );
6114: unless (($settings->{'student_classlist_view'} eq 'all') ||
6115: ($settings->{'student_classlist_view'} eq 'section')) {
6116: $settings->{'student_classlist_view'} = 'disabled';
6117: }
1.80 raeburn 6118: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6119: }
6120:
6121: sub print_appearance {
1.80 raeburn 6122: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6123: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6124: return;
6125: }
1.9 raeburn 6126: my $mathdef;
6127: if ($crstype eq 'Community') {
6128: $mathdef = &mt("None specified - use member's choice");
6129: } else {
6130: $mathdef = &mt("None specified - use student's choice");
6131: }
1.1 raeburn 6132: my %items = (
6133: 'default_xml_style' => {
1.3 raeburn 6134: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6135: '<a href="javascript:openbrowser'.
6136: "('display','default_xml_style'".
6137: ",'sty')".'">'.&mt('Select Style File').'</a>',
6138: input => 'textbox',
6139: size => 35,
6140: },
6141:
6142: 'pageseparators' => {
1.3 raeburn 6143: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6144: input => 'radio',
6145: },
6146: 'disable_receipt_display' => {
1.3 raeburn 6147: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6148: input => 'radio',
6149: },
6150: 'texengine' => {
1.3 raeburn 6151: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6152: input => 'selectbox',
6153: options => {
1.61 raeburn 6154: MathJax => 'MathJax',
1.1 raeburn 6155: mimetex => &mt('Convert to Images'),
6156: tth => &mt('TeX to HTML'),
6157: },
1.75 raeburn 6158: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6159: nullval => $mathdef,
1.1 raeburn 6160: },
6161: 'tthoptions' => {
1.3 raeburn 6162: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6163: input => 'textbox',
6164: size => 40,
6165: },
1.69 raeburn 6166: 'uselcmath' => {
6167: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6168: input => 'radio',
6169: },
6170: 'usejsme' => {
6171: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6172: input => 'radio',
6173: },
1.95 raeburn 6174: 'inline_chem' => {
6175: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6176: input => 'radio',
6177: },
1.114 raeburn 6178: 'extresource' => {
6179: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6180: input => 'selectbox',
6181: options => {
6182: iframe => 'In iframe',
6183: tab => 'In new tab',
6184: window => 'In pop-up window',
6185: },
6186: order => ['iframe','tab','window'],
6187: },
1.1 raeburn 6188: );
1.80 raeburn 6189: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6190: }
6191:
6192: sub print_grading {
1.127 ! raeburn 6193: my ($cdom,$cnum,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6194: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6195: return;
6196: }
6197: my %items = (
6198: 'grading' => {
1.3 raeburn 6199: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6200: &Apache::loncommon::help_open_topic('GradingOptions'),
6201: input => 'selectbox',
6202: options => {
6203: standard => &mt('Standard: shows points'),
1.34 www 6204: categories => &mt('Categories: shows points according to categories'),
1.11 www 6205: external => &mt('External: shows number of completed parts and totals'),
6206: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6207: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6208: },
1.34 www 6209: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6210: },
6211: 'rndseed' => {
1.3 raeburn 6212: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.127 ! raeburn 6213: '<br /><span class="LC_warning LC_nobreak">'.
1.1 raeburn 6214: &mt('Modifying this will make problems have different numbers and answers!').
6215: '</span>',
6216: input => 'selectbox',
6217: options => {
6218: '32bit' => '32bit',
6219: '64bit' => '64bit',
6220: '64bit2' => '64bit2',
6221: '64bit3' => '64bit3',
6222: '64bit4' => '64bit4',
6223: '64bit5' => '64bit5',
6224: },
6225: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6226: advanced => 1
1.1 raeburn 6227: },
6228: 'receiptalg' => {
1.3 raeburn 6229: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6230: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6231: input => 'selectbox',
6232: options => {
6233: receipt => 'receipt',
6234: receipt2 => 'receipt2',
6235: receipt3 => 'receipt3',
6236: },
6237: order => ['receipt','receipt2','receipt3'],
1.41 www 6238: advanced => 1
1.1 raeburn 6239: },
6240: 'disablesigfigs' => {
1.3 raeburn 6241: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6242: input => 'radio',
6243: },
6244: );
1.127 ! raeburn 6245: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit,$cnum);
1.1 raeburn 6246: }
6247:
6248: sub print_printouts {
1.80 raeburn 6249: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6250: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6251: return;
6252: }
6253: my %items = (
6254: problem_stream_switch => {
1.3 raeburn 6255: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6256: input => 'radio',
6257: },
6258: suppress_tries => {
1.3 raeburn 6259: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6260: input => 'radio',
6261: },
6262: default_paper_size => {
1.3 raeburn 6263: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6264: input => 'selectbox',
6265: options => {
6266: Letter => &mt('Letter').' [8 1/2x11 in]',
6267: Legal => &mt('Legal').' [8 1/2x14 in]',
6268: Tabloid => &mt('Tabloid').' [11x17 in]',
6269: Executive => &mt('Executive').' [7 1/2x10 in]',
6270: A2 => &mt('A2').' [420x594 mm]',
6271: A3 => &mt('A3').' [297x420 mm]',
6272: A4 => &mt('A4').' [210x297 mm]',
6273: A5 => &mt('A5').' [148x210 mm]',
6274: A6 => &mt('A6').' [105x148 mm]',
6275: },
6276: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6277: nullval => &mt('None specified'),
1.1 raeburn 6278: },
6279: print_header_format => {
1.3 raeburn 6280: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6281: input => 'checkbox',
6282: },
6283: disableexampointprint => {
1.3 raeburn 6284: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6285: input => 'radio',
6286: },
1.14 raeburn 6287: canuse_pdfforms => {
6288: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6289: input => 'selectbox',
6290: options => {
6291: 1 => &mt('Yes'),
6292: 0 => &mt('No'),
6293: },
6294: order => ['1','0'],
1.54 bisitz 6295: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6296: }
1.1 raeburn 6297: );
1.80 raeburn 6298: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6299: }
6300:
6301: sub print_spreadsheet {
1.80 raeburn 6302: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6303: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6304: return;
6305: }
6306: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6307: my %items = (
6308: spreadsheet_default_classcalc => {
1.3 raeburn 6309: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6310: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6311: "('display','spreadsheet_default_classcalc'".
6312: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6313: input => 'textbox',
6314: },
6315: spreadsheet_default_studentcalc => {
1.3 raeburn 6316: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6317: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6318: "('display','spreadsheet_default_calc'".
6319: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6320: input => 'textbox',
6321: },
6322: spreadsheet_default_assesscalc => {
1.3 raeburn 6323: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6324: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6325: "('display','spreadsheet_default_assesscalc'".
6326: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6327: input => 'textbox',
6328: },
6329: hideemptyrows => {
1.3 raeburn 6330: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6331: input => 'radio',
6332: },
6333: );
1.80 raeburn 6334: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6335: }
1.1 raeburn 6336:
6337: sub print_bridgetasks {
1.80 raeburn 6338: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6339: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6340: return;
6341: }
1.9 raeburn 6342: my ($stumsg,$msgnote);
6343: if ($crstype eq 'Community') {
6344: $stumsg = &mt('Send message to member');
6345: $msgnote = &mt('Message to member and add to user notes');
6346: } else {
6347: $stumsg = &mt('Send message to student');
6348: $msgnote = &mt('Message to student and add to user notes');
6349: }
1.1 raeburn 6350: my %items = (
6351: task_messages => {
1.3 raeburn 6352: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6353: input => 'selectbox',
6354: options => {
1.9 raeburn 6355: only_student => $stumsg,
6356: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6357: },
6358: order => ['only_student','student_and_user_notes_screen'],
6359: nullval => &mt('No message or record in user notes'),
6360: },
6361: task_grading => {
1.3 raeburn 6362: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6363: input => 'selectbox',
6364: options => {
6365: any => &mt('Grade BTs in any section'),
6366: section => &mt('Grade BTs only in own section')
6367: },
6368: order => ['any','section'],
6369: },
6370: suppress_embed_prompt => {
1.3 raeburn 6371: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6372: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6373: input => 'radio',
6374: },
6375: );
1.80 raeburn 6376: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6377: }
6378:
1.118 raeburn 6379: sub print_ltitools {
6380: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6381: my ($datatable,$disabled,$css_class,$dest);
1.121 raeburn 6382: if ($noedit) {
6383: $disabled = ' disabled="disabled"';
6384: }
1.120 raeburn 6385: my $itemcount = 1;
6386: unless ($context eq 'domain') {
6387: my %tooltypes = &Apache::loncommon::usable_exttools();
6388: unless ($tooltypes{'crs'}) {
6389: my $showtype = 'course';
6390: if ($crstype eq 'Community') {
6391: $showtype = lc($crstype);
6392: }
6393: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6394: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6395: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6396: if ($tooltypes{'dom'}) {
6397: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6398: '<i>'.$cdom.'</i>').
6399: '<br /><br />'.
6400: &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.");
6401: } else {
6402: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6403: '<br /><br />'.
6404: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6405: '<i>'.$cdom.'</i>');
6406:
6407: }
6408: $datatable .= '</tr>';
6409: $itemcount ++;
6410: return $datatable;
6411: }
6412: }
1.118 raeburn 6413: my %lt = <itools_names();
6414: my $maxnum = 0;
6415: my %ordered;
6416: if (ref($settings) eq 'HASH') {
6417: foreach my $item (keys(%{$settings})) {
6418: if (ref($settings->{$item}) eq 'HASH') {
6419: my $num = $settings->{$item}{'order'};
6420: $ordered{$num} = $item;
6421: }
6422: }
6423: }
6424:
6425: if ($context eq 'domain') {
6426: $dest = '/adm/domainprefs';
6427: } else {
6428: $dest = '/adm/courseprefs';
6429: }
6430: my ($switchserver,$switchmessage);
6431: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6432: if ($switchserver) {
6433: if ($context eq 'domain') {
6434: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6435: } elsif ($crstype eq 'Community') {
6436: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6437: } else {
6438: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6439: }
6440: }
6441: my $maxnum = scalar(keys(%ordered));
6442: my @courseroles = ('cc','in','ta','ep','st');
6443: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6444: my @fields = ('fullname','firstname','lastname','email','roles','user');
6445: if (keys(%ordered)) {
6446: my @items = sort { $a <=> $b } keys(%ordered);
6447: for (my $i=0; $i<@items; $i++) {
6448: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6449: my $item = $ordered{$items[$i]};
6450: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6451: if (ref($settings->{$item}) eq 'HASH') {
6452: $title = $settings->{$item}->{'title'};
6453: $url = $settings->{$item}->{'url'};
6454: $key = $settings->{$item}->{'key'};
6455: $usable = $settings->{$item}->{'usable'};
6456: $lifetime = $settings->{$item}->{'lifetime'};
6457: my $image = $settings->{$item}->{'image'};
6458: if ($image ne '') {
6459: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6460: }
6461: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6462: $sigsel{'HMAC-256'} = ' selected="selected"';
6463: } else {
6464: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6465: }
6466: }
6467: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6468: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6469: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6470: for (my $k=0; $k<=$maxnum; $k++) {
6471: my $vpos = $k+1;
6472: my $selstr;
6473: if ($k == $i) {
6474: $selstr = ' selected="selected" ';
6475: }
6476: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6477: }
6478: $datatable .= '</select>'.(' 'x2).
6479: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6480: &mt('Delete?').'</label></span></td>'.
6481: '<td colspan="2">'.
6482: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6483: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6484: (' 'x2).
6485: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6486: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6487: (' 'x2).
6488: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6489: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6490: (' 'x2).
6491: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6492: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6493: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6494: '<br /><br />'.
1.120 raeburn 6495: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6496: ' value="'.$url.'" /></span>'.
6497: (' 'x2).
6498: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6499: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6500: if ($key ne '') {
6501: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6502: if ($noedit) {
6503: $datatable .= ': ['.&mt('not shown').']';
6504: } elsif ($switchserver) {
6505: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6506: } else {
6507: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6508: }
6509: $datatable .= '</span> '.(' 'x2);
6510: } elsif (!$switchserver) {
6511: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6512: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6513: '</span> '.(' 'x2);
6514: }
6515: if ($switchserver) {
6516: if ($usable ne '') {
6517: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6518: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6519: '<span class="LC_nobreak">'.&mt('Change secret?').
6520: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6521: (' 'x2).
6522: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6523: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6524: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6525: '</div>';
6526: } elsif ($key eq '') {
6527: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6528: } else {
6529: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6530: }
6531: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6532: } else {
6533: if ($usable ne '') {
6534: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6535: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6536: '<span class="LC_nobreak">'.&mt('Change?').
6537: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6538: (' 'x2).
6539: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6540: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6541: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6542: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6543: '<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>'.
6544: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6545: } else {
6546: $datatable .=
6547: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6548: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6549: '<label><input type="checkbox" name="ltitools_visible_'.$i.'" id="ltitools_visible_'.$i.'" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>'.
6550: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6551: }
6552: }
6553: $datatable .= '</fieldset>'.
6554: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6555: '<span class="LC_nobreak">'.&mt('Display target:');
6556: my %currdisp;
6557: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6558: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6559: $currdisp{'window'} = ' checked="checked"';
6560: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6561: $currdisp{'tab'} = ' checked="checked"';
6562: } else {
6563: $currdisp{'iframe'} = ' checked="checked"';
6564: }
6565: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6566: $currdisp{'width'} = $1;
6567: }
6568: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6569: $currdisp{'height'} = $1;
6570: }
6571: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6572: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6573: } else {
6574: $currdisp{'iframe'} = ' checked="checked"';
6575: }
6576: foreach my $disp ('iframe','tab','window') {
6577: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6578: $lt{$disp}.'</label>'.(' 'x2);
6579: }
6580: $datatable .= (' 'x4);
6581: foreach my $dimen ('width','height') {
6582: $datatable .= '<label>'.$lt{$dimen}.' '.
6583: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6584: (' 'x2);
6585: }
6586: $datatable .= '</span><br />'.
6587: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6588: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6589: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6590: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6591: '</textarea></div><div style=""></div><br />';
6592: my %units = (
6593: 'passback' => 'days',
6594: 'roster' => 'seconds',
6595: );
6596: foreach my $extra ('passback','roster') {
6597: my $validsty = 'none';
6598: my $currvalid;
6599: my $checkedon = '';
6600: my $checkedoff = ' checked="checked"';
6601: if ($settings->{$item}->{$extra}) {
6602: $checkedon = $checkedoff;
6603: $checkedoff = '';
6604: $validsty = 'inline-block';
6605: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6606: $currvalid = $settings->{$item}->{$extra.'valid'};
6607: }
6608: }
6609: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6610: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6611: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6612: &mt('No').'</label>'.(' 'x2).
6613: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6614: &mt('Yes').'</label></span></div>'.
6615: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6616: '<span class="LC_nobreak">'.
6617: &mt("until at least [_1] $units{$extra} after launch",
6618: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6619: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6620: }
6621: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6622: if ($imgsrc) {
6623: $datatable .= $imgsrc.
6624: '<label><input type="checkbox" name="ltitools_image_del"'.
6625: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6626: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6627: } else {
6628: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6629: }
6630: if ($switchserver) {
6631: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6632: } else {
6633: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6634: }
6635: $datatable .= '</span></fieldset>';
6636: my (%checkedfields,%rolemaps,$userincdom);
6637: if (ref($settings->{$item}) eq 'HASH') {
6638: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6639: %checkedfields = %{$settings->{$item}->{'fields'}};
6640: }
6641: $userincdom = $settings->{$item}->{'incdom'};
6642: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6643: %rolemaps = %{$settings->{$item}->{'roles'}};
6644: $checkedfields{'roles'} = 1;
6645: }
6646: }
6647: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6648: '<span class="LC_nobreak">';
6649: my $userfieldstyle = 'display:none;';
6650: my $seluserdom = '';
6651: my $unseluserdom = ' selected="selected"';
6652: foreach my $field (@fields) {
6653: my ($checked,$onclick,$id,$spacer);
6654: if ($checkedfields{$field}) {
6655: $checked = ' checked="checked"';
6656: }
6657: if ($field eq 'user') {
6658: $id = ' id="ltitools_user_field_'.$i.'"';
6659: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6660: if ($checked) {
6661: $userfieldstyle = 'display:inline-block';
6662: if ($userincdom) {
6663: $seluserdom = $unseluserdom;
6664: $unseluserdom = '';
6665: }
6666: }
6667: } else {
6668: $spacer = (' ' x2);
6669: }
6670: $datatable .= '<label>'.
6671: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6672: $lt{$field}.'</label>'.$spacer;
6673: }
6674: $datatable .= '</span>';
6675: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6676: '<span class="LC_nobreak"> : '.
6677: '<select name="ltitools_userincdom_'.$i.'">'.
6678: '<option value="">'.&mt('Select').'</option>'.
6679: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6680: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6681: '</select></span></div>';
6682: $datatable .= '</fieldset>'.
6683: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6684: foreach my $role (@courseroles) {
6685: my ($selected,$selectnone);
6686: if (!$rolemaps{$role}) {
6687: $selectnone = ' selected="selected"';
6688: }
6689: $datatable .= '<td style="text-align: center">'.
6690: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6691: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6692: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6693: foreach my $ltirole (@ltiroles) {
6694: unless ($selectnone) {
6695: if ($rolemaps{$role} eq $ltirole) {
6696: $selected = ' selected="selected"';
6697: } else {
6698: $selected = '';
6699: }
6700: }
6701: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6702: }
6703: $datatable .= '</select></td>';
6704: }
6705: $datatable .= '</tr></table></fieldset>';
6706: my %courseconfig;
6707: if (ref($settings->{$item}) eq 'HASH') {
6708: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6709: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6710: }
6711: }
6712: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6713: foreach my $item ('label','title','target','linktext','explanation','append') {
6714: my $checked;
6715: if ($courseconfig{$item}) {
6716: $checked = ' checked="checked"';
6717: }
6718: $datatable .= '<label>'.
6719: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6720: $lt{'crs'.$item}.'</label> '."\n";
6721: }
6722: $datatable .= '</span></fieldset>'.
6723: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6724: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6725: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6726: my %custom = %{$settings->{$item}->{'custom'}};
6727: if (keys(%custom) > 0) {
6728: foreach my $key (sort(keys(%custom))) {
6729: $datatable .= '<tr><td><span class="LC_nobreak">'.
6730: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6731: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6732: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6733: ' value="'.$custom{$key}.'" /></td></tr>';
6734: }
6735: }
6736: }
6737: $datatable .= '<tr><td><span class="LC_nobreak">'.
6738: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6739: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6740: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6741: $datatable .= '</table></fieldset></td></tr>'."\n";
6742: $itemcount ++;
6743: }
6744: }
6745: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6746: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6747: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6748: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6749: '<select name="ltitools_add_pos"'.$chgstr.'>';
6750: for (my $k=0; $k<$maxnum+1; $k++) {
6751: my $vpos = $k+1;
6752: my $selstr;
6753: if ($k == $maxnum) {
6754: $selstr = ' selected="selected" ';
6755: }
6756: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6757: }
6758: $datatable .= '</select> '."\n".
6759: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6760: '<td colspan="2">'.
6761: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6762: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6763: (' 'x2).
6764: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6765: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6766: (' 'x2).
6767: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6768: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6769: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6770: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6771: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6772: '<br />'.
1.120 raeburn 6773: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6774: (' 'x2).
6775: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6776: if ($switchserver) {
6777: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6778: } else {
6779: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6780: (' 'x2).
1.119 raeburn 6781: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6782: '<label><input type="checkbox" name="ltitools_add_visible" id="ltitools_add_visible" onclick="if (this.checked) { this.form.ltitools_secret_add.type='."'text'".' } else { this.form.ltitools_secret_add.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label></span> '."\n";
1.118 raeburn 6783: }
6784: $datatable .= '<br /><br />'.
6785: '</fieldset>'.
6786: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6787: '<span class="LC_nobreak">'.&mt('Display target:');
6788: my %defaultdisp;
6789: $defaultdisp{'iframe'} = ' checked="checked"';
6790: foreach my $disp ('iframe','tab','window') {
6791: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6792: $lt{$disp}.'</label>'.(' 'x2);
6793: }
6794: $datatable .= (' 'x4);
6795: foreach my $dimen ('width','height') {
6796: $datatable .= '<label>'.$lt{$dimen}.' '.
6797: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6798: (' 'x2);
6799: }
6800: $datatable .= '</span><br />'.
6801: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6802: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6803: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6804: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6805: '</div><div style=""></div><br />';
6806: my %units = (
6807: 'passback' => 'days',
6808: 'roster' => 'seconds',
6809: );
6810: my %defaulttimes = (
6811: 'passback' => '7',
6812: 'roster' => '300',
6813: );
6814: foreach my $extra ('passback','roster') {
6815: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6816: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6817: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6818: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6819: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6820: &mt('Yes').'</label></span></div>'.
6821: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6822: '<span class="LC_nobreak">'.
6823: &mt("until at least [_1] $units{$extra} after launch",
6824: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6825: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6826: }
6827: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6828: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6829: if ($switchserver) {
6830: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6831: } else {
6832: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6833: }
6834: $datatable .= '</span></fieldset>'.
6835: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6836: '<span class="LC_nobreak">';
6837: foreach my $field (@fields) {
6838: my ($id,$onclick,$spacer);
6839: if ($field eq 'user') {
6840: $id = ' id="ltitools_user_field_add"';
6841: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6842: } else {
6843: $spacer = (' ' x2);
6844: }
6845: $datatable .= '<label>'.
6846: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6847: $lt{$field}.'</label>'.$spacer;
6848: }
6849: $datatable .= '</span>'.
6850: '<div style="display:none;" id="ltitools_user_div_add">'.
6851: '<span class="LC_nobreak"> : '.
6852: '<select name="ltitools_add_userincdom">'.
6853: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6854: '<option value="0">'.&mt('username').'</option>'.
6855: '<option value="1">'.&mt('username:domain').'</option>'.
6856: '</select></span></div></fieldset>';
6857: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6858: foreach my $role (@courseroles) {
6859: my ($checked,$checkednone);
6860: $datatable .= '<td style="text-align: center">'.
6861: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6862: '<select name="ltitools_add_roles_'.$role.'">'.
6863: '<option value="" selected="selected">'.&mt('Select').'</option>';
6864: foreach my $ltirole (@ltiroles) {
6865: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6866: }
6867: $datatable .= '</select></td>';
6868: }
6869: $datatable .= '</tr></table></fieldset>'.
6870: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
6871: foreach my $item ('label','title','target','linktext','explanation','append') {
6872: $datatable .= '<label>'.
6873: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6874: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6875: }
6876: $datatable .= '</span></fieldset>'.
6877: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6878: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6879: '<tr><td><span class="LC_nobreak">'.
6880: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6881: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6882: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6883: '</table></fieldset>'."\n".
6884: '</td>'."\n".
6885: '</tr>'."\n";
6886: $itemcount ++;
6887: return $datatable;
6888: }
6889:
6890: sub ltitools_names {
6891: my %lt = &Apache::lonlocal::texthash(
6892: 'title' => 'Title',
6893: 'version' => 'Version',
6894: 'msgtype' => 'Message Type',
6895: 'sigmethod' => 'Signature Method',
6896: 'url' => 'URL',
6897: 'key' => 'Key',
6898: 'lifetime' => 'Nonce lifetime (s)',
6899: 'secret' => 'Secret',
6900: 'icon' => 'Icon',
6901: 'user' => 'User',
6902: 'fullname' => 'Full Name',
6903: 'firstname' => 'First Name',
6904: 'lastname' => 'Last Name',
6905: 'email' => 'E-mail',
6906: 'roles' => 'Role',
6907: 'window' => 'Window',
6908: 'tab' => 'Tab',
6909: 'iframe' => 'iFrame',
6910: 'height' => 'Height',
6911: 'width' => 'Width',
6912: 'linktext' => 'Default Link Text',
6913: 'explanation' => 'Default Explanation',
6914: 'passback' => 'Tool can return grades:',
6915: 'roster' => 'Tool can retrieve roster:',
6916: 'crstarget' => 'Display target',
6917: 'crslabel' => 'Course label',
6918: 'crstitle' => 'Course title',
6919: 'crslinktext' => 'Link Text',
6920: 'crsexplanation' => 'Explanation',
6921: 'crsappend' => 'Provider URL',
6922: );
6923: return %lt;
6924: }
6925:
1.87 raeburn 6926: sub print_lti {
6927: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6928: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6929: return;
6930: }
6931: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6932: my %menutitles = <imenu_titles();
6933: my ($domdefs,$displaydefs);
6934: if ($env{'request.lti.login'}) {
6935: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6936: my @domdefsmenu;
6937: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6938: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6939: $domdefs = &mt('Header shown').', ';
6940: }
6941: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6942: $domdefs .= &mt('Inline menu shown');
6943: }
6944: $domdefs =~ s/,\s$//;
6945: if (!$domdefs) {
6946: $domdefs = &mt('No header or inline menu shown');
6947: }
6948: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
6949: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
6950: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
6951: }
6952: }
6953: $displaydefs = &mt('Domain defaults');
6954: if (@domdefsmenu) {
6955: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
6956: if (@diffs) {
6957: my $missing;
6958: foreach my $item (@menuitems) {
6959: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
6960: $missing .= ' '.$menutitles{$item}.',';
6961: }
6962: }
6963: $missing =~ s/,$//;
6964: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
6965: } else {
6966: $displaydefs .= ': '.&mt('All shown');
6967: }
6968: } else {
6969: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
6970: }
6971: } else {
6972: $displaydefs = &mt('Domain defaults only available in LTI context');
6973: }
6974: my %items = (
6975: 'lti.override' => {
6976: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
6977: input => 'radio',
6978: },
6979: 'lti.topmenu' => {
6980: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
6981: input => 'radio',
6982: },
6983: 'lti.inlinemenu' => {
6984: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
6985: input => 'radio',
6986: },
6987: 'lti.lcmenu' => {
6988: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
6989: input => 'custom',
6990: },
6991: );
6992: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
6993: }
6994:
6995: sub lcmenu_checkboxes {
6996: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
6997: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6998: my %menutitles = <imenu_titles();
6999: my (@current,@domdefs);
7000: if ($env{'request.lti.login'}) {
7001: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
7002: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
7003: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
7004: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
7005: }
7006: }
7007: }
7008: if (ref($settings) eq 'HASH') {
7009: if ($settings->{'lti.lcmenu'}) {
7010: unless ($settings->{'lti.lcmenu'} eq 'none') {
7011: @current = split(',',$settings->{'lti.lcmenu'});
7012: }
7013: } else {
7014: @current = @domdefs;
7015: }
7016: } else {
7017: @current = @domdefs;
7018: }
7019: my $numinrow = 3;
7020: my $count = 0;
7021: my $disabled;
7022: if ($noedit) {
7023: $disabled = ' disabled="disabled"';
7024: }
7025: my $output = '<table>';
7026: foreach my $item (@menuitems) {
7027: my $checked = '';
7028: if (grep(/^\Q$item\E$/,@current)) {
7029: $checked = ' checked="checked" ';
7030: }
7031: my $rem = $count%($numinrow);
7032: if ($rem == 0) {
7033: if ($count > 0) {
7034: $output .= '</tr>';
7035: }
7036: $output .= '<tr>';
7037: }
7038: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
7039: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
7040: $menutitles{$item}.'</label></span></td>';
7041: $count ++;
7042: }
7043: my $rem = $count%($numinrow);
7044: my $colsleft = $numinrow - $rem;
7045: if ($colsleft > 1 ) {
7046: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7047: ' </td>';
7048: } elsif ($colsleft == 1) {
7049: $output .= '<td class="LC_left_item"> </td>';
7050: }
7051: $output .= '</tr></table>';
7052: }
7053:
7054: sub ltimenu_titles {
7055: return &Apache::lonlocal::texthash(
7056: fullname => 'Full name',
7057: coursetitle => 'Course title',
7058: role => 'Role',
7059: logout => 'Logout',
7060: grades => 'Grades',
7061: );
7062: }
7063:
1.91 raeburn 7064: sub print_menuitems {
7065: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
7066: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
7067: return;
7068: }
7069: if ($position eq 'top') {
7070: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
7071: if ($settings->{'menucollections'} ne '') {
7072: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7073: my ($num,$value) = split(/\%/,$item);
7074: if ($num =~ /^\d+$/) {
7075: $defaultmenu_options{$num} = $num;
7076: }
7077: }
7078: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
7079: $addcollection = $defaultmenu_order[-1] + 1;
7080: } else {
7081: $addcollection = 1;
7082: }
7083: $defaultmenu_options{$addcollection} = $addcollection;
7084: my %items = (
7085: 'menudefault' => {
7086: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
7087: &mt("(can be overriden in deep-link context)"),
7088: input => 'selectbox',
7089: options => \%defaultmenu_options,
7090: order => \@defaultmenu_order,
7091: nullval => &mt('Standard (all menus shown)'),
7092: },
7093: );
7094: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
7095: } else {
7096: my %menu;
7097: my $count = 0;
7098: my $next = 1;
7099: my ($datatable,$disabled);
7100: if ($noedit) {
7101: $disabled = ' disabled="disabled"';
7102: }
7103:
7104: my ($ordered,$cats) = &menuitems_categories();
7105: my @order = @{$ordered};
7106: my %categories = %{$cats};
7107: my %menutitles = &menuitems_titles();
7108: my %menufields = &menuitems_fields();
7109:
7110: if ($settings->{'menucollections'} ne '') {
7111: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7112: my ($num,$value) = split(/\%/,$item);
7113: if ($num =~ /^\d+$/) {
7114: my @entries = split(/\&/,$value);
7115: foreach my $entry (@entries) {
7116: my ($name,$fields) = split(/=/,$entry);
7117: $menu{$num}{$name} = $fields;
7118: }
7119: }
7120: }
7121: if (keys(%menu)) {
7122: my @current = sort { $a <=> $b } keys(%menu);
7123: $next += $current[-1];
7124: foreach my $num (@current) {
7125: my %checked;
7126: my $on = ' checked="checked"';
7127: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7128: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7129: if ($menu{$num}{$key} eq 'y') {
7130: $checked{$key} = $on;
7131: }
7132: } else {
7133: foreach my $field (split(/,/,$menu{$num}{$key})) {
7134: if (exists($menufields{$field})) {
7135: $checked{$field} = $on;
7136: }
7137: }
7138: }
7139: }
7140: if (ref($menu{$num}) eq 'HASH') {
7141: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7142: foreach my $category (@order) {
7143: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7144: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7145: if ($category eq 'text') {
7146: $datatable .= '<i>'.&mt('Header').'</i><br />';
7147: }
1.91 raeburn 7148: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7149: if ($field eq 'disc') {
7150: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7151: }
1.91 raeburn 7152: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7153: $menufields{$field}.'</label><br />';
7154: }
7155: $datatable .= '</fieldset>';
7156: }
7157: }
7158: $datatable .= &item_table_row_end();
7159: $count ++;
7160: }
7161: }
7162: }
7163: } elsif ($noedit) {
7164: my $text = &mt('No menu collections defined for this course.');
7165: $datatable .= &item_table_row_start($text,$count);
7166: }
7167: unless ($noedit) {
7168: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7169: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7170: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7171: foreach my $category (@order) {
7172: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7173: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7174: foreach my $field (@{$categories{$category}}) {
7175: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7176: $menufields{$field}.'</label><br />';
7177: }
7178: $datatable .= '</fieldset>';
7179: }
7180: }
7181: $datatable .= &item_table_row_end();
7182: $count ++;
7183: }
7184: return $datatable;
7185: }
7186: }
7187:
7188: sub menuitems_abbreviations {
7189: my %briefcats = (
7190: text => 'pt',
7191: links => 'p',
7192: list => 'ps',
7193: inline => 's',
7194: );
7195: return %briefcats;
7196: }
7197:
7198: sub menuitems_categories {
7199: my @order = ('shown','text','links','list','inline');
7200: my %categories = (
1.94 raeburn 7201: shown => ['top','inline','foot','main'],
7202: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7203: links => ['pers','logo','menu','comm','roles','help','logout'],
1.91 raeburn 7204: list => ['about','prefs','port','wish','anno','rss'],
7205: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7206: );
7207: return (\@order,\%categories);
7208: }
7209:
7210: sub menuitems_titles {
7211: return &Apache::lonlocal::texthash (
7212: shown => 'Hierarchy',
1.94 raeburn 7213: text => 'Text',
1.91 raeburn 7214: links => 'Header links',
7215: list => 'Drop-down list',
7216: inline => 'Inline links',
7217: );
7218: }
7219:
7220: sub menuitems_fields {
7221: return &Apache::lonlocal::texthash (
7222: top => 'Display header',
7223: inline => 'Display inline menu',
1.94 raeburn 7224: foot => 'Display footer',
1.91 raeburn 7225: main => 'Access to main menu',
1.92 raeburn 7226: pers => 'Personal',
7227: logo => 'LON-CAPA',
1.91 raeburn 7228: menu => 'Home',
7229: comm => 'Messages',
7230: roles => 'Roles/Courses',
7231: help => 'Help',
7232: logout => 'Logout',
7233: name => 'Fullname',
7234: crs => 'Course Title',
7235: role => 'Current Role',
1.94 raeburn 7236: disc => 'Discussion',
7237: fdbk => 'Feedback',
1.91 raeburn 7238: about => 'Information',
7239: prefs => 'Preferences',
7240: port => 'Portfolio',
7241: wish => 'Stored Links',
7242: anno => 'Calendar',
7243: rss => 'RSS Feeds',
7244: cont => 'Contents',
7245: grades => 'Grades',
7246: chat => 'Chat',
7247: people => 'People',
7248: groups => 'Groups',
7249: resv => 'Reservations',
7250: syll => 'Syllabus',
7251: feeds => 'Feeds',
7252: );
7253: }
7254:
7255: sub menucollections_display {
7256: my ($collections) = @_;
7257: my %menu;
7258: my ($ordered,$cats) = &menuitems_categories();
7259: my @order = @{$ordered};
7260: my %categories = %{$cats};
7261: my %menutitles = &menuitems_titles();
7262: my %menufields = &menuitems_fields();
7263: foreach my $item (split(/;/,$collections)) {
7264: my ($num,$value) = split(/\%/,$item);
7265: if ($num =~ /^\d+$/) {
7266: my @entries = split(/\&/,$value);
7267: foreach my $entry (@entries) {
7268: my ($name,$fields) = split(/=/,$entry);
7269: $menu{$num}{$name} = $fields;
7270: }
7271: }
7272: }
7273: my $output = '';
7274: if (keys(%menu)) {
7275: my @current = sort { $a <=> $b } keys(%menu);
7276: foreach my $num (@current) {
7277: my %checked;
7278: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7279: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7280: if ($menu{$num}{$key} eq 'y') {
7281: $checked{$key} = 1;
7282: }
7283: } else {
7284: foreach my $field (split(/,/,$menu{$num}{$key})) {
7285: if (exists($menufields{$field})) {
7286: $checked{$field} = 1;
7287: }
7288: }
7289: }
7290: }
7291: if (ref($menu{$num}) eq 'HASH') {
7292: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7293: foreach my $category (@order) {
7294: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7295: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7296: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7297: if ($category eq 'text') {
7298: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
1.124 raeburn 7299: }
1.91 raeburn 7300: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7301: if ($field eq 'disc') {
7302: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7303: }
1.91 raeburn 7304: if ($checked{$field}) {
7305: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7306: } else {
7307: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7308: }
7309: $output .= '<br />';
7310: }
7311: $output .= '</fieldset>';
7312: }
7313: }
7314: $output .= '</fieldset>';
7315: }
7316: }
7317: }
7318: return $output;
7319: }
7320:
1.93 raeburn 7321: sub print_linkprotection {
1.102 raeburn 7322: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7323:
7324: my %linkprotection;
7325: my $count = 0;
7326: my $next = 1;
1.102 raeburn 7327: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7328: if ($noedit) {
7329: $disabled = ' disabled="disabled"';
7330: }
1.100 raeburn 7331: my %desc = &linkprot_names();
7332: my %lt = &Apache::lonlocal::texthash (
7333: 'requ' => 'Required settings',
7334: 'opti' => 'Optional settings',
7335: );
1.93 raeburn 7336: my $itemcount = 0;
7337:
1.100 raeburn 7338: my $ltiauth;
1.102 raeburn 7339: if ($context eq 'domain') {
7340: $ltiauth = 1;
7341: } else {
7342: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7343: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7344: } else {
7345: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7346: $ltiauth = $domdefs{'crsltiauth'};
7347: }
7348: }
7349: if ($context eq 'domain') {
7350: $dest = '/adm/domainprefs';
1.100 raeburn 7351: } else {
1.102 raeburn 7352: $dest = '/adm/courseprefs';
7353: }
1.124 raeburn 7354:
1.102 raeburn 7355: my ($switchserver,$switchmessage);
7356: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7357: if ($switchserver) {
7358: if ($context eq 'domain') {
1.124 raeburn 7359: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.102 raeburn 7360: } elsif ($crstype eq 'Community') {
7361: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7362: } else {
7363: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7364: }
1.100 raeburn 7365: }
1.99 raeburn 7366:
1.105 raeburn 7367: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7368: if (keys(%{$settings->{'linkprot'}})) {
7369: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7370: $next += $current[-1];
7371: for (my $i=0; $i<@current; $i++) {
7372: my $num = $current[$i];
7373: my %values;
1.102 raeburn 7374: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7375: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7376: } else {
7377: next;
7378: }
7379: my $selected;
7380: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7381: $selected = ' selected="selected"';
7382: }
7383: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7384: $datatable .=
7385: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7386: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7387: &mt('Delete?').'</label></span></td><td>';
1.122 raeburn 7388: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7389: $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
7390: $passbacksty = 'none';
7391: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
7392: %checkedpassback = (
7393: 'no' => ' checked="checked"',
7394: 'yes' => '',
1.124 raeburn 7395: );
1.122 raeburn 7396: %checkedpassbackfmt = (
7397: '1p1' => ' checked="checked"',
7398: '1p0' => '',
7399: );
7400: if ($values{'passback'} ne '') {
7401: $passbacksty = 'inline-block';
7402: $checkedpassback{'yes'} = ' checked="checked"';
7403: $checkedpassback{'no'} = '';
7404: if ($values{'passbackformat'} eq '1.0') {
7405: $checkedpassbackfmt{'1p0'} = ' checked="checked"';
7406: $checkedpassbackfmt{'1p1'} = '';
7407: }
7408: }
1.100 raeburn 7409: if ($ltiauth) {
7410: $usersty = 'display:none';
1.112 raeburn 7411: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7412: %checkedrequser = (
7413: no => ' checked="checked"',
7414: yes => '',
7415: );
7416: if ($values{'requser'}) {
7417: $checkedrequser{'yes'} = $checkedrequser{'no'};
7418: $checkedrequser{'no'} = '';
7419: }
7420: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
1.124 raeburn 7421: if ($values{'requser'}) {
1.100 raeburn 7422: $usersty = 'display:inline-block';
7423: }
7424: }
1.112 raeburn 7425: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7426: %checkedreturnurl = (
7427: no => ' checked="checked"',
7428: yes => '',
7429: );
7430: if ($values{'returnurl'} ne '') {
7431: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7432: $checkedreturnurl{'no'} = '';
7433: }
1.100 raeburn 7434: $datatable .=
7435: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7436: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7437: (' 'x2).
1.100 raeburn 7438: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7439: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7440: (' 'x2).
1.100 raeburn 7441: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7442: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7443: if ($values{'key'} ne '') {
1.100 raeburn 7444: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7445: if ($noedit) {
7446: $datatable .= ': ['.&mt('not shown').']';
7447: } elsif ($switchserver) {
7448: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7449: } else {
7450: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7451: }
7452: $datatable .= '</span> '.(' 'x2);
7453: } elsif (!$switchserver) {
1.100 raeburn 7454: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7455: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7456: '</span> '.(' 'x2);
7457: }
7458: if ($switchserver) {
7459: if ($values{'usable'} ne '') {
7460: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7461: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7462: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7463: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
1.99 raeburn 7464: (' 'x2).
1.118 raeburn 7465: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
1.99 raeburn 7466: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7467: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7468: '</div>';
7469: } elsif ($values{'key'} eq '') {
1.102 raeburn 7470: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7471: } else {
1.102 raeburn 7472: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7473: }
1.111 raeburn 7474: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7475: } else {
7476: if ($values{'usable'} ne '') {
7477: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7478: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7479: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7480: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
1.99 raeburn 7481: (' 'x2).
1.118 raeburn 7482: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7483: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7484: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7485: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7486: '<label><input type="checkbox" name="linkprot_visible_'.$i.'" id="linkprot_visible_'.$i.'" onclick="if (this.checked) { this.form.linkprot_secret_'.$i.'.type='."'text'".' } else { this.form.linkprot_secret_'.$i.'.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>'.
1.99 raeburn 7487: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7488: } else {
7489: $datatable .=
1.100 raeburn 7490: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7491: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7492: '<label><input type="checkbox" name="linkprot_visible_'.$i.'" id="linkprot_visible_'.$i.'" onclick="if (this.checked) { this.form.linkprot_secret_'.$i.'.type='."'text'".' } else { this.form.linkprot_secret_'.$i.'.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>'.
1.99 raeburn 7493: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7494: }
7495: }
1.112 raeburn 7496: $datatable .= '<br /><br />'.
1.122 raeburn 7497: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7498: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7499: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7500: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7501: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7502: '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7503: '<span class="LC_nobreak">'.&mt('Grade format').
7504: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7505: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7506: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7507: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7508: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7509: '<br />'.
1.112 raeburn 7510: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7511: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7512: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7513: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7514: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7515: ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
7516: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7517: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7518: '</span></div> ';
1.100 raeburn 7519: if ($ltiauth) {
1.112 raeburn 7520: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7521: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7522: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7523: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7524: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7525: '</fieldset>'.
7526: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7527: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7528: '</fieldset>';
7529: }
1.99 raeburn 7530: $datatable .= '</td></tr>';
1.93 raeburn 7531: $itemcount ++;
7532: }
7533: }
7534: }
7535: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7536: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7537: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7538: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7539: '<td width="100%">';
1.122 raeburn 7540: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7541: $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.100 raeburn 7542: if ($ltiauth) {
7543: $usersty = 'display:none';
1.112 raeburn 7544: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7545: %checkedrequser = (
7546: no => ' checked="checked"',
7547: yes => '',
7548: );
7549: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7550: }
1.122 raeburn 7551: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7552: %checkedpassback = (
7553: 'no' => ' checked="checked"',
7554: 'yes' => '',
7555: );
7556: %checkedpassbackfmt = (
7557: '1p1' => ' checked="checked"',
7558: '1p0' => '',
7559: );
1.112 raeburn 7560: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7561: %checkedreturnurl = (
7562: no => ' checked="checked"',
7563: yes => '',
7564: );
1.100 raeburn 7565: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7566: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7567: (' 'x2).
1.100 raeburn 7568: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7569: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7570: (' 'x2).
1.112 raeburn 7571: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7572: '<br /><br />';
1.99 raeburn 7573: if ($switchserver) {
1.102 raeburn 7574: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7575: } else {
1.100 raeburn 7576: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':<input type="text" size="25" name="linkprot_key_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.99 raeburn 7577: (' 'x2).
1.116 raeburn 7578: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7579: '<label><input type="checkbox" name="linkprot_visible_add" id="linkprot_visible_add" onclick="if (this.checked) { this.form.linkprot_secret_add.type='."'text'".' } else { this.form.linkprot_secret_add.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label></span> '."\n";
1.99 raeburn 7580: }
1.112 raeburn 7581: $datatable .= '<br /><br />'.
1.122 raeburn 7582: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7583: '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7584: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7585: '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7586: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7587: '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none" />'.
7588: '<span class="LC_nobreak">'.&mt('Grade format').
7589: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7590: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7591: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7592: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7593: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7594: '<br />'.
1.112 raeburn 7595: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7596: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7597: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7598: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7599: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7600: ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
7601: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7602: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7603: '</span></div> ';
7604: if ($ltiauth) {
7605: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7606: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7607: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7608: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7609: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7610: '</fieldset>'.
1.100 raeburn 7611: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7612: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7613: '</fieldset>';
7614: }
1.99 raeburn 7615: $datatable .= '</td></tr>';
1.93 raeburn 7616: $$rowtotal ++;
1.101 raeburn 7617: return $datatable;
1.93 raeburn 7618: }
7619:
7620: sub linkprot_names {
1.100 raeburn 7621: return &Apache::lonlocal::texthash(
1.93 raeburn 7622: 'version' => 'LTI Version',
7623: 'key' => 'Key',
7624: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7625: 'name' => 'Launcher Application',
1.93 raeburn 7626: 'secret' => 'Secret',
1.122 raeburn 7627: 'passback' => 'Can return grades to Launcher',
1.112 raeburn 7628: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7629: 'requser' => 'Use identity',
7630: 'email' => 'Email address',
7631: 'sourcedid' => 'User ID',
7632: 'other' => 'Other',
7633: 'auth' => 'Display LON-CAPA login page',
7634: 'reject' => 'Discontinue launch process',
1.93 raeburn 7635: );
7636: }
7637:
1.99 raeburn 7638: sub check_switchserver {
1.102 raeburn 7639: my ($cdom,$cnum,$context,$dest) = @_;
7640: my ($allowed,$switchserver,$home);
7641: if ($context eq 'domain') {
7642: $home = &Apache::lonnet::domain($cdom,'primary');
7643: } else {
7644: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7645: }
7646: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7647: my @ids=&Apache::lonnet::current_machine_ids();
7648: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7649: if (!$allowed) {
7650: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7651: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7652: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7653: }
7654: }
7655: return $switchserver;
7656: }
7657:
1.100 raeburn 7658: sub linkprot_options {
7659: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7660: my %lt;
7661: if (ref($desc) eq 'HASH') {
7662: %lt = %{$desc};
7663: }
7664: my $userfieldsty = 'none';
7665: my (%checked,$userfield);
7666: $checked{'sourcedid'} = ' checked="checked"';
7667: $checked{'reject'} = ' checked="checked"';
7668: if (ref($current) eq 'HASH') {
7669: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7670: $checked{'sourcedid'} = '';
7671: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7672: $checked{'email'} = ' checked="checked"';
7673: } else {
7674: $checked{'other'} = ' checked="checked"';
7675: $userfield = $current->{'mapuser'};
7676: $userfieldsty = 'inline-block';
7677: }
7678: }
7679: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7680: $checked{'reject'} = '';
7681: $checked{'auth'} = ' checked="checked"';
7682: }
7683: }
1.112 raeburn 7684: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7685: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7686: &mt('Source of LON-CAPA username in LTI request').': ';
7687: foreach my $option ('sourcedid','email','other') {
7688: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7689: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7690: ($option eq 'other' ? '' : (' 'x2) );
7691: }
7692: $output .= '</span></div>'.
7693: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7694: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7695: 'value="'.$userfield.'"'.$disabled.' /></div>';
7696: $output .= '<br />'.
7697: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7698: &mt('Action when username is not for an enrolled student').': ';
7699: foreach my $option ('reject','auth') {
7700: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7701: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7702: ($option eq 'auth' ? '' : (' 'x2) );
7703: }
7704: $output .= '</span></div>';
7705: return $output;
7706: }
7707:
1.114 raeburn 7708: sub print_extresource_row {
7709: my ($item,$config,$curr,$noedit) = @_;
7710: my $onchange;
7711: unless ($noedit) {
7712: $onchange = ' onchange="javascript:toggleExtRes();"';
7713: }
7714: my $id = 'LC_'.$item;
7715: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7716: my $output = &select_from_options($item,$config->{'order'},
7717: $config->{'options'},$selected,
7718: $config->{'nullval'},
7719: undef,undef,$onchange,$noedit,$id);
1.124 raeburn 7720: my ($checked,$reusesty,$sizesty);
1.114 raeburn 7721: if ($reuse) {
7722: $checked = ' checked="checked"';
7723: }
7724: $reusesty = 'none';
7725: $sizesty = 'none';
7726: if (($selected eq 'window') || ($selected eq 'tab')) {
7727: $reusesty = 'inline-block';
7728: if ($selected eq 'window') {
7729: $sizesty = 'inline-block';
7730: }
7731: }
7732: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7733: '<span class="LC_nobreak">'.
7734: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7735: &mt('Re-use tab/window').'</label>'.
7736: '</span></div>'.
7737: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7738: '<legend>'.&mt('Window size (optional)').'</legend>'.
7739: '<span class="LC_nobreak">'.
7740: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7741: (' ' x 3).
7742: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7743: '</span></fieldset>';
7744: return $output;
7745: }
7746:
1.1 raeburn 7747: sub print_other {
1.80 raeburn 7748: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7749: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7750: return;
7751: }
1.3 raeburn 7752: my @ordered = &get_other_items($cdom,$settings,$allitems);
7753: my %items;
7754: foreach my $parameter (@ordered) {
7755: $items{$parameter} = {
7756: text => '<b>'.$parameter.'</b>',
7757: input => 'textbox',
7758: size => '15',
7759: },
7760: }
7761: push (@ordered,'newp_value');
7762: $items{'newp_value'} = {
7763: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7764: '<input type="textbox" name="newp_name"'.
7765: ' value="" size="30" />',
7766: input => 'textbox',
7767: size => '30',
7768: };
1.93 raeburn 7769: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7770: }
7771:
7772: sub get_other_items {
7773: my ($cdom,$settings,$allitems) = @_;
7774: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7775: return;
7776: }
1.1 raeburn 7777: my @ordered;
7778: if (ref($settings) eq 'HASH') {
7779: foreach my $parameter (sort(keys(%{$settings}))) {
7780: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7781: next if (($parameter eq 'course.helper.not.run') &&
7782: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7783: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7784: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7785: || ($parameter eq 'type') ||
1.50 raeburn 7786: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7787: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7788: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7789: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7790: push(@ordered,$parameter);
7791: }
7792: }
7793: }
1.3 raeburn 7794: return @ordered;
1.1 raeburn 7795: }
7796:
7797: sub item_table_row_start {
1.91 raeburn 7798: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7799: my $output;
1.56 raeburn 7800: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7801: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7802: if ($leftclass eq '') {
7803: $leftclass = 'LC_left_item';
7804: }
7805: if ($rightclass eq '') {
7806: $rightclass = 'LC_right_item';
7807: }
1.56 raeburn 7808: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7809: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7810: '</td>';
1.91 raeburn 7811: if ($colspan > 1) {
7812: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7813: } else {
1.91 raeburn 7814: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7815: }
1.1 raeburn 7816: return $output;
7817: }
7818:
7819: sub item_table_row_end {
7820: return '</td></tr>';
7821: }
7822:
7823: sub yesno_radio {
1.127 ! raeburn 7824: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit,$onclick,$reverse) = @_;
1.1 raeburn 7825: my $itemon = ' ';
7826: my $itemoff = ' checked="checked" ';
1.69 raeburn 7827: if (($valueyes eq '') && ($valueno eq '')) {
7828: $valueyes = 'yes';
7829: $valueno = '';
7830: }
1.1 raeburn 7831: if (ref($settings) eq 'HASH') {
1.69 raeburn 7832: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7833: $itemon = $itemoff;
7834: $itemoff = ' ';
7835: }
1.69 raeburn 7836: unless (exists($settings->{$item})) {
7837: if ($unsetdefault eq $valueyes) {
7838: $itemon = $itemoff;
7839: $itemoff = ' ';
7840: }
7841: }
1.1 raeburn 7842: }
1.80 raeburn 7843: my $disabled;
7844: if ($noedit) {
7845: $disabled = ' disabled="disabled"';
1.127 ! raeburn 7846: } elsif ($onclick) {
! 7847: $onclick = ' onclick="'.$onclick.'"';
! 7848: }
! 7849: if ($reverse) {
! 7850: return '<span class="LC_nobreak"><label>'.
! 7851: '<input type="radio" name="'.$item.'"'.
! 7852: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label> '.
! 7853: '<label><input type="radio" name="'.$item.'"'.
! 7854: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label></span>';
! 7855: } else {
! 7856: return '<span class="LC_nobreak"><label>'.
! 7857: '<input type="radio" name="'.$item.'"'.
! 7858: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label> '.
! 7859: '<label><input type="radio" name="'.$item.'"'.
! 7860: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label></span>';
1.80 raeburn 7861: }
1.1 raeburn 7862: }
7863:
7864: sub select_from_options {
1.91 raeburn 7865: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7866: my $output;
1.80 raeburn 7867: my $disabled;
7868: if ($noedit) {
7869: $disabled = ' disabled=disabled"';
7870: }
1.1 raeburn 7871: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7872: $output='<select name="'.$item.'" '.$onchange;
7873: if ($multiple) {
7874: $output .= ' multiple="multiple"';
7875: my $num = @{$order};
7876: $num ++ if ($nullval ne '');
7877: if (($maxsize) && ($maxsize < $num)) {
7878: $output .= ' size="'.$maxsize.'"';
7879: }
7880: }
1.91 raeburn 7881: if ($id ne '') {
7882: $output .= ' id="'.$id.'"';
7883: }
1.80 raeburn 7884: $output .= $disabled.'>'."\n";
1.1 raeburn 7885: if ($nullval ne '') {
7886: $output .= '<option value=""';
7887: if (ref($curr) eq 'ARRAY') {
7888: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7889: $output .= ' selected="selected" ';
7890: }
7891: } else {
7892: if ($curr eq '') {
7893: $output .= ' selected="selected" ';
7894: }
7895: }
7896: $output .= '>'.$nullval.'</option>';
7897: }
7898: foreach my $option (@{$order}) {
7899: $output.= '<option value="'.$option.'"';
7900: if (ref($curr) eq 'ARRAY') {
7901: if (grep(/^\Q$option\E$/,@{$curr})) {
7902: $output .= ' selected="selected" ';
7903: }
7904: } else {
7905: if ($option eq $curr) {
7906: $output.=' selected="selected"';
7907: }
7908: }
7909: $output.=">$options->{$option}</option>\n";
7910: }
7911: $output.="</select>";
7912: }
7913: return $output;
7914: }
7915:
7916: sub make_item_rows {
1.127 ! raeburn 7917: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit,$cnum) = @_;
1.1 raeburn 7918: my $datatable;
7919: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7920: my $count = 0;
7921: foreach my $item (@{$ordered}) {
7922: $count ++;
1.56 raeburn 7923: my $colspan;
7924: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7925: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7926: $colspan = 2;
7927: }
1.114 raeburn 7928: my $rowdesc;
7929: if ($caller eq 'appearance') {
7930: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7931: } else {
7932: $rowdesc = $items->{$item}{text};
7933: }
1.41 www 7934: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7935: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7936: } else {
1.114 raeburn 7937: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7938: }
1.55 raeburn 7939: if ($item eq 'defaultcredits') {
7940: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7941: my $showcredits;
7942: if ($defaultcredits ne '') {
7943: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7944: } else {
7945: $showcredits = &mt('No default set');
7946: }
7947: $datatable .= $showcredits;
7948: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 7949: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 7950: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 7951: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 7952: } elsif ($item eq 'print_header_format') {
1.80 raeburn 7953: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 7954: } elsif ($item eq 'lti.lcmenu') {
7955: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 7956: } elsif ($item eq 'extresource') {
7957: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 7958: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 7959: my $disabled;
7960: if ($noedit) {
7961: $disabled = ' disabled="disabled"';
7962: }
1.1 raeburn 7963: $datatable .=
7964: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 7965: $settings->{$item},$disabled);
1.1 raeburn 7966: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 7967: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 7968: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 7969: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7970: unless ($domdefs{$item} eq '0') {
7971: $unsetdefault = 1;
7972: }
7973: $valueyes = "1";
7974: $valueno = "0";
1.87 raeburn 7975: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
7976: $valueyes = '1';
1.69 raeburn 7977: }
1.80 raeburn 7978: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 7979: } elsif ($items->{$item}{input} eq 'selectbox') {
1.127 ! raeburn 7980: my ($id,$onchange);
1.91 raeburn 7981: if ($caller eq 'menuitems') {
7982: $id = $item;
1.127 ! raeburn 7983: } elsif ($caller eq 'grading') {
! 7984: if ($item eq 'grading') {
! 7985: $onchange = ' onchange="javascript:toggleGrading(this.form);"';
! 7986: $id = $item;
! 7987: }
1.91 raeburn 7988: }
1.1 raeburn 7989: my $curr = $settings->{$item};
7990: $datatable .=
7991: &select_from_options($item,$items->{$item}{'order'},
7992: $items->{$item}{'options'},$curr,
1.80 raeburn 7993: $items->{$item}{'nullval'},
1.127 ! raeburn 7994: undef,undef,$onchange,$noedit,$id);
! 7995: if ($item eq 'grading') {
! 7996: my ($unsetdefault,$valueyes,$valueno,$sectionbox);
! 7997: my $gradingsty = 'none';
! 7998: my $gradingsecsty = 'none';
! 7999: $unsetdefault = 0;
! 8000: my (@selsec,@sections,%current);
! 8001: if ($curr eq 'standard') {
! 8002: $gradingsty = 'inline-block';
! 8003: if (ref($settings) eq 'HASH') {
! 8004: $current{'hidetotals'} = $settings->{'hidetotals'};
! 8005: if ($settings->{'hidetotals'} =~ /^([\w,]+)$/) {
! 8006: my $secstr = $1;
! 8007: unless ($secstr eq 'all') {
! 8008: @selsec = split(/,/,$secstr);
! 8009: }
! 8010: $current{'hidetotals'} = 1;
! 8011: }
! 8012: }
! 8013: }
! 8014: $valueyes = "1";
! 8015: $valueno = "0";
! 8016: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
! 8017: if (keys(%sections)) {
! 8018: @sections = sort( { $a <=> $b } keys(%sections));
! 8019: }
! 8020: my $onclick = 'javascript:toggleHiddenTotalsSec(this.form);';
! 8021: my $sectionbox = '<div id="sectotalsdiv" style="display:'.$gradingsecsty.'; float:right">';
! 8022: my $reverse = 1;
! 8023: if (@sections) {
! 8024: $sectionbox .= ' ... '.&mt('hidden in sections').': '.
! 8025: '<div style="position: relative; top: 0%;">'.
! 8026: &select_sections('hidetotals','',\@sections,\@selsec,$noedit,'all').
! 8027: '</div>';
! 8028: }
! 8029: $sectionbox .= '</div>';
! 8030: $datatable .= '<fieldset id="hidetotalsdiv" style="display:'.$gradingsty.';">'.
! 8031: '<legend style="font-weight: normal;">'.
! 8032: &mt('Hide Course Points Totals').'</legend>'.
! 8033: '<div style="position: relative; top: 0%; float:left">'.
! 8034: &yesno_radio('hidetotals',\%current,$unsetdefault,$valueyes,$valueno,$noedit,
! 8035: $onclick,$reverse).'</div>'.
! 8036: $sectionbox.
! 8037: '</fieldset><div style="padding:0;clear:both;margin:0;border:0"></div>';
! 8038: }
1.1 raeburn 8039: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 8040: my $disabled;
8041: if ($noedit) {
8042: $disabled = ' disabled=disabled"';
8043: }
1.1 raeburn 8044: $datatable .=
8045: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 8046: $items->{$item}{size},
8047: $disabled);
1.1 raeburn 8048: }
8049: $datatable .= &item_table_row_end();
8050: }
8051: if (ref($rowtotal)) {
8052: $$rowtotal += scalar(@{$ordered});
8053: }
8054: }
8055: return $datatable;
8056: }
8057:
8058: sub nothidepriv_row {
1.80 raeburn 8059: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 8060: my ($cnum) = &get_course();
1.56 raeburn 8061: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 8062: if (ref($settings) eq 'HASH') {
8063: if ($settings->{$item} ne '') {
8064: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
8065: if ($user !~ /:/) {
8066: $nothide{join(':',split(/[\@]/,$user))}=1;
8067: } else {
8068: $nothide{$user} = 1;
8069: }
8070: }
8071: }
1.56 raeburn 8072: if ($settings->{'checkforpriv'}) {
1.124 raeburn 8073: @checkdoms = split(/,/,$settings->{'checkforpriv'});
1.56 raeburn 8074: }
1.1 raeburn 8075: }
1.56 raeburn 8076: push(@checkdoms,$cdom);
8077: my %coursepersonnel =
8078: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 8079: my @privusers;
8080: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 8081: my ($uname,$udom,$role) = split(/:/,$person);
8082: my $user = $uname.':'.$udom;
8083: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 8084: if ($end == -1 || $start == -1) {
8085: next;
8086: }
1.124 raeburn 8087: foreach my $dom (@checkdoms) {
1.56 raeburn 8088: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
8089: unless (grep(/^\Q$user\E$/,@privusers)) {
8090: push(@privusers,$user);
1.3 raeburn 8091: }
8092: }
8093: }
1.1 raeburn 8094: }
1.56 raeburn 8095: if (@privusers > 0) {
1.80 raeburn 8096: my $disabled;
8097: if ($noedit) {
8098: $disabled = ' disabled="disabled"';
8099: }
1.1 raeburn 8100: $datatable .= '<table align="right">';
8101: foreach my $user (sort(@privusers)) {
8102: my $hideon = ' checked="checked" ';
8103: my $hideoff = '';
8104: if ($nothide{$user}) {
8105: $hideoff = $hideon;
8106: $hideon = '';
8107: }
8108: my ($uname,$udom) = split(':',$user);
8109: $datatable .= '<tr><td align="left">'.
8110: &Apache::loncommon::aboutmewrapper(
8111: &Apache::loncommon::plainname($uname,$udom,'firstname'),
8112: $uname,$udom,'aboutuser').
8113: '</td><td align="left">'.
8114: '<span class="LC_nobreak"><label>'.
8115: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8116: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 8117: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8118: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 8119: '</tr>';
8120: }
8121: $datatable .= '</table>';
8122: } else {
1.9 raeburn 8123: if ($crstype eq 'Community') {
8124: $datatable .= &mt('No Domain Coordinators have community roles');
8125: } else {
8126: $datatable .= &mt('No Domain Coordinators have course roles');
8127: }
1.1 raeburn 8128: }
8129: return $datatable;
8130: }
8131:
1.56 raeburn 8132: sub checkforpriv_row {
1.80 raeburn 8133: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 8134: my $datatable;
8135: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8136: if (keys(%domains) == 1) {
8137: $datatable = '</td><td align="right">'.
8138: &mt("Course's domain is only domain");
8139: return $datatable;
8140: }
8141: my @excdoms = ($cdom);
8142: my $num = 0;
8143: if ($settings->{$item} eq '') {
8144: $datatable = '</td><td align="right">'.
8145: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 8146: 1,1,undef,undef,\@excdoms,
8147: $noedit);
1.56 raeburn 8148: } else {
8149: my @privdoms = split(/,/,$settings->{$item});
8150: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8151: $datatable = '</td><td align="right"><br />'.
8152: &Apache::loncommon::start_data_table();
1.80 raeburn 8153: my $disabled;
8154: if ($noedit) {
8155: $disabled = ' disabled="disabled"';
8156: }
1.56 raeburn 8157: if (@privdoms > 0) {
8158: foreach my $currdom (@privdoms) {
8159: next unless ($domains{$currdom});
8160: my $domdesc = &Apache::lonnet::domain($currdom,'description');
8161: if ($domdesc eq '') {
8162: $domdesc = $currdom;
1.124 raeburn 8163: }
1.56 raeburn 8164: $datatable .=
8165: &Apache::loncommon::start_data_table_row().
8166: '<td align="left"><span class="LC_nobreak">'.
8167: &mt('Domain:').'<b> '.$domdesc.
8168: '</b><input type="hidden" name="checkforpriv_'.$num.
8169: '" value="'.$currdom.'" /></span><br />'.
8170: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 8171: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
8172: &mt('Delete').'</label></span></td>'.
1.56 raeburn 8173: &Apache::loncommon::end_data_table_row();
8174: $num ++;
1.124 raeburn 8175: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
1.56 raeburn 8176: push(@excdoms,$currdom);
8177: }
8178: }
8179: }
8180: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
1.124 raeburn 8181: $datatable .=
1.56 raeburn 8182: &Apache::loncommon::start_data_table_row().
8183: '<td align="left"><span class="LC_nobreak">'.
8184: &mt('Additional domain:'). '</span><br />'.
8185: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8186: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8187: '</td>'.&Apache::loncommon::end_data_table_row();
8188: }
8189: $datatable .= &Apache::loncommon::end_data_table().
8190: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8191: '<br />';
8192: }
8193: return $datatable;
8194: }
8195:
1.1 raeburn 8196: sub print_hdrfmt_row {
1.80 raeburn 8197: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8198: my @curr;
8199: my $currnum = 0;
8200: my $maxnum = 2;
8201: my $currstr;
8202: if ($settings->{$item} ne '') {
8203: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8204: $settings->{$item}.'</tt></span></b><br />';
8205: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8206: foreach my $val (@current) {
8207: unless ($val eq '') {
8208: push(@curr,$val);
1.1 raeburn 8209: }
8210: }
8211: $currnum = @curr;
8212: $maxnum += $currnum;
8213: }
8214:
8215: my $output = <<ENDJS;
8216:
8217: <script type="text/javascript" language="Javascript">
8218:
8219: function reOrder(chgnum) {
8220: var maxnum = $maxnum;
8221: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8222: var newidx = 'printfmthdr_pos_'+chgnum;
8223: oldidx = getIndexByName(oldidx);
8224: newidx = getIndexByName(newidx);
8225: var oldpos = document.display.elements[oldidx].value;
8226: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8227: document.display.elements[oldidx].value = newpos;
8228: var chgtype = 'up';
8229: if (newpos < oldpos) {
8230: chgtype = 'down';
8231: }
8232: for (var j=0; j<maxnum; j++) {
8233: if (j != chgnum) {
8234: oldidx = 'printfmthdr_oldpos_'+j;
8235: newidx = 'printfmthdr_pos_'+j;
8236: oldidx = getIndexByName(oldidx);
8237: newidx = getIndexByName(newidx);
8238: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8239: var currsel = document.display.elements[newidx].selectedIndex;
8240: if (chgtype == 'up') {
8241: if ((currpos > oldpos) && (currpos <= newpos)) {
8242: document.display.elements[newidx].selectedIndex = currsel-1;
8243: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8244: }
8245: } else {
8246: if ((currpos >= newpos) && (currpos < oldpos)) {
8247: document.display.elements[newidx].selectedIndex = currsel+1;
8248: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8249: }
8250: }
8251: }
8252: }
8253: return;
8254: }
8255:
8256: function getIndexByName(item) {
8257: for (var i=0;i<document.display.elements.length;i++) {
8258: if (document.display.elements[i].name == item) {
8259: return i;
8260: }
8261: }
8262: return -1;
8263: }
8264:
8265: </script>
8266:
8267: ENDJS
1.56 raeburn 8268: $output .= '</td><td align="right"><br />'.
8269: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8270: my $disabled;
8271: if ($noedit) {
8272: $disabled = ' disabled="disabled"';
8273: }
1.1 raeburn 8274: if (@curr > 0) {
8275: for (my $i=0; $i<@curr; $i++) {
8276: my $pos = $i+1;
1.10 raeburn 8277: $output .= '<tr>'.
1.1 raeburn 8278: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8279: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8280: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8281: '"'.$disabled.' /></span></td>';
1.1 raeburn 8282: if ($curr[$i] =~ /^%\d*[nca]$/) {
8283: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8284: $output .= '<td align="left">'.
1.80 raeburn 8285: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8286: } else {
8287: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8288: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8289: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8290: }
1.10 raeburn 8291: $output .= '</tr>';
1.1 raeburn 8292: }
8293: }
1.80 raeburn 8294: my $pos = $currnum+1;
1.124 raeburn 8295: unless ($noedit) {
1.80 raeburn 8296: $output .=
8297: '<tr>'.
1.1 raeburn 8298: '<td align="left"><span class="LC_nobreak">'.
8299: &position_selector($pos,$currnum,$maxnum).
8300: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8301: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8302: '</tr>';
1.80 raeburn 8303: $pos ++;
1.82 raeburn 8304: $currnum ++;
8305: $output .=
1.80 raeburn 8306: '<tr>'.
1.1 raeburn 8307: '<td align="left"><span class="LC_nobreak">'.
8308: &position_selector($pos,$currnum,$maxnum).
8309: '<b>'.&mt('New').'</b></span></td>'.
8310: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8311: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8312: '" value="" size ="25" />'.
8313: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8314: $maxnum.'" /></td>'.
1.80 raeburn 8315: '</tr>';
8316: }
8317: $output .= '</table><br />';
1.1 raeburn 8318: return $output;
8319: }
8320:
8321: sub position_selector {
1.80 raeburn 8322: my ($pos,$num,$maxnum,$disabled) = @_;
8323: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8324: for (my $j=1; $j<=$maxnum; $j++) {
8325: my $sel = '';
8326: if ($pos == $j) {
8327: $sel = ' selected="selected"';
8328: }
8329: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8330: }
8331: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8332: '" value="'.$pos.'" />';
8333: return $output;
8334: }
8335:
8336: sub substitution_selector {
1.80 raeburn 8337: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8338: my ($stunametxt,$crsidtxt);
8339: if ($crstype eq 'Community') {
8340: $stunametxt = 'member name';
8341: $crsidtxt = 'community ID',
8342: } else {
8343: $stunametxt = 'student name';
8344: $crsidtxt = 'course ID',
8345: }
1.1 raeburn 8346: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8347: n => $stunametxt,
8348: c => $crsidtxt,
1.1 raeburn 8349: a => 'assignment note',
8350: );
8351: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8352: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8353: if ($subst eq '') {
8354: $output .= '<option value="" selected="selected"> </option>';
8355: }
8356: foreach my $field ('n','c','a') {
8357: my $sel ='';
8358: if ($subst eq $field) {
8359: $sel = ' selected="selected"';
8360: }
8361: $output .= '<option value="'.$field.'"'.$sel.'>'.
8362: $lt{$field}.'</option>';
8363: }
8364: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8365: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8366: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8367: return $output;
8368: }
8369:
1.23 raeburn 8370: sub change_clone {
8371: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8372: my $clone_crs = $cnum.':'.$cdom;
8373: if ($cnum && $cdom) {
8374: my $clone_crs = $cnum.':'.$cdom;
8375: my @allowclone;
8376: if ($clonelist =~ /,/) {
8377: @allowclone = split(',',$clonelist);
8378: } else {
8379: $allowclone[0] = $clonelist;
8380: }
8381: foreach my $currclone (@allowclone) {
8382: if (!grep(/^$currclone$/,@$oldcloner)) {
8383: if ($currclone ne '*') {
1.71 raeburn 8384: if ($currclone =~ /:/) {
8385: my ($uname,$udom) = split(/:/,$currclone);
8386: if ($uname && $udom && $uname ne '*') {
8387: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8388: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8389: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8390: if ($currclonecrs{'cloneable'} eq '') {
8391: $currclonecrs{'cloneable'} = $clone_crs;
8392: } else {
8393: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8394: }
8395: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8396: }
8397: }
8398: }
8399: }
8400: }
8401: }
8402: }
8403: foreach my $oldclone (@$oldcloner) {
8404: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8405: if ($oldclone ne '*') {
1.71 raeburn 8406: if ($oldclone =~ /:/) {
8407: my ($uname,$udom) = split(/:/,$oldclone);
8408: if ($uname && $udom && $uname ne '*' ) {
8409: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8410: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8411: my %newclonecrs = ();
8412: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8413: if ($currclonecrs{'cloneable'} =~ /,/) {
8414: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8415: foreach my $crs (@currclonecrs) {
8416: if ($crs ne $clone_crs) {
8417: $newclonecrs{'cloneable'} .= $crs.',';
8418: }
1.23 raeburn 8419: }
1.71 raeburn 8420: $newclonecrs{'cloneable'} =~ s/,$//;
8421: } else {
8422: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8423: }
1.71 raeburn 8424: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8425: }
8426: }
8427: }
8428: }
8429: }
8430: }
8431: }
8432: }
8433: return;
8434: }
8435:
1.108 raeburn 8436: sub devalidate_remote_courseprefs {
8437: my ($cdom,$cnum,$cachekeys) = @_;
8438: return unless (ref($cachekeys) eq 'HASH');
8439: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8440: my %thismachine;
8441: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8442: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8443: if (keys(%servers)) {
8444: foreach my $server (keys(%servers)) {
8445: next if ($thismachine{$server});
8446: my @cached;
8447: foreach my $name (@posscached) {
8448: if ($cachekeys->{$name}) {
8449: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8450: }
8451: }
8452: if (@cached) {
8453: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8454: }
8455: }
8456: }
8457: return;
8458: }
8459:
1.1 raeburn 8460: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>