Annotation of loncom/interface/courseprefs.pm, revision 1.131
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.131 ! raeburn 4: # $Id: courseprefs.pm,v 1.130 2024/02/24 20:46:24 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.131 ! raeburn 375: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
! 376: unless ($phase eq 'process') {
! 377: if (ref($domdefs{'linkprotsuggested'}) eq 'HASH') {
! 378: $values{'suggested'} = $domdefs{'linkprotsuggested'};
! 379: }
! 380: }
1.99 raeburn 381: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
1.118 raeburn 382: my %ltitools = &Apache::lonnet::dump('ltitools',$cdom,$cnum,undef,undef,undef,1);
383: my %ltitoolsenc = &Apache::lonnet::dump('nohist_toolsenc',$cdom,$cnum,undef,undef,undef,1);
1.102 raeburn 384: foreach my $id (keys(%linkprot)) {
385: if (ref($linkprot{$id}) eq 'HASH') {
1.99 raeburn 386: if (ref($ltienc{$id}) eq 'HASH') {
1.102 raeburn 387: $values{'linkprot'}{$id} = { %{$linkprot{$id}}, %{$ltienc{$id}} };
1.99 raeburn 388: } else {
1.102 raeburn 389: $values{'linkprot'}{$id} = $linkprot{$id};
1.99 raeburn 390: }
391: }
392: unless ($phase eq 'process') {
1.102 raeburn 393: if (ref($values{'linkprot'}{$id}) eq 'HASH') {
394: delete($values{'linkprot'}{$id}{'secret'});
1.99 raeburn 395: }
396: }
397: }
1.102 raeburn 398: if ($linkprot{'lock'}) {
399: delete($linkprot{'lock'});
1.93 raeburn 400: }
1.118 raeburn 401: foreach my $id (keys(%ltitools)) {
402: if (ref($ltitools{$id}) eq 'HASH') {
403: if (ref($ltitoolsenc{$id}) eq 'HASH') {
404: $values{'ltitools'}{$id} = { %{$ltitools{$id}}, %{$ltitoolsenc{$id}} };
405: } else {
406: $values{'ltitools'}{$id} = $ltitools{$id};
407: }
408: }
409: unless ($phase eq 'process') {
410: if (ref($values{'ltitools'}{$id}) eq 'HASH') {
411: delete($values{'ltitools'}{$id}{'secret'});
412: }
413: }
414: }
415: if ($ltitools{'lock'}) {
416: delete($ltitools{'lock'});
417: }
1.1 raeburn 418: my @prefs_order = ('courseinfo','localization','feedback','discussion',
419: 'classlists','appearance','grading','printouts',
1.118 raeburn 420: 'menuitems','ltitools','linkprot','spreadsheet',
421: 'bridgetasks','lti','other');
1.1 raeburn 422: my %prefs = (
423: 'courseinfo' =>
1.9 raeburn 424: { text => $lt{'gens'},
1.44 www 425: help => 'Course_Prefs_General',
1.35 raeburn 426: ordered => ['owner','co-owners','loncaparev','description',
1.64 raeburn 427: 'clonedfrom','courseid','uniquecode','categories',
1.88 raeburn 428: 'hidefromcat','syllabus','cloners','url',
1.64 raeburn 429: 'rolenames'],
1.3 raeburn 430: itemtext => {
1.25 raeburn 431: 'owner' => $lt{'ownr'},
432: 'co-owners' => $lt{'cown'},
433: 'description' => $lt{'desc'},
434: 'courseid' => $lt{'idnu'},
1.64 raeburn 435: 'uniquecode' => $lt{'unco'},
1.25 raeburn 436: 'categories' => $lt{'catg'},
437: 'hidefromcat' => $lt{'excc'},
438: 'cloners' => $lt{'clon'},
1.88 raeburn 439: 'syllabus' => 'Syllabus status',
1.25 raeburn 440: 'url' => 'Top Level Map',
441: 'rolenames' => $lt{'rept'},
1.35 raeburn 442: 'loncaparev' => $lt{'lcrv'},
1.63 raeburn 443: 'clonedfrom' => 'Cloned from',
1.3 raeburn 444: },
1.1 raeburn 445: },
446: 'localization' =>
1.42 www 447: { text => 'Language and time localization',
1.44 www 448: help => 'Course_Prefs_Language',
1.1 raeburn 449: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 450: itemtext => {
1.20 faziophi 451: languages => 'Languages used',
1.9 raeburn 452: timezone => $lt{'time'},
453: datelocale => $lt{'date'},
1.3 raeburn 454: },
1.1 raeburn 455: },
456: 'feedback' =>
1.20 faziophi 457: { text => 'Feedback messages',
1.44 www 458: help => 'Course_Prefs_Feedback',
1.1 raeburn 459: header => [{col1 => 'Questions about:',
1.20 faziophi 460: col2 => 'Recipients'}],
1.3 raeburn 461: ordered => ['question.email','comment.email','policy.email'],
462: itemtext => {
463: 'question.email' => 'Resource Content',
1.9 raeburn 464: 'comment.email' => $lt{'coco'},
465: 'policy.email' => $lt{'copo'},
1.3 raeburn 466: },
1.1 raeburn 467: },
468: 'discussion' =>
469: { text => 'Discussion and Chat',
1.44 www 470: help => 'Course_Prefs_Discussions',
1.31 raeburn 471: ordered => ['pch.roles.denied','pch.users.denied',
1.77 raeburn 472: 'pac.roles.denied','pac.users.denied',
1.31 raeburn 473: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 474: 'allow_limited_html_in_feedback',
1.50 raeburn 475: 'allow_discussion_post_editing',
476: 'discussion_post_fonts'],
1.3 raeburn 477: itemtext => {
1.31 raeburn 478: 'pch.roles.denied' => 'No Resource Discussion',
479: 'pch.users.denied' => 'No Resource Discussion',
480: 'plc.roles.denied' => 'No Chat room use',
481: 'plc.users.denied' => 'No Chat room use',
1.77 raeburn 482: 'pac.roles.denied' => 'No Anonymous Resource Discussion',
483: 'pac.users.denied' => 'No Anonymous Resource Discussion',
1.20 faziophi 484: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
485: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.77 raeburn 486: discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 487: },
1.1 raeburn 488: },
489: 'classlists' =>
1.9 raeburn 490: { text => $lt{'clas'},
1.44 www 491: help => 'Course_Prefs_Classlists',
1.1 raeburn 492: header => [{col1 => 'Type',
1.9 raeburn 493: col2 => $lt{'defd'}},
1.1 raeburn 494: {col1 => 'Setting',
1.9 raeburn 495: col2 => $lt{'priv'}},
1.1 raeburn 496: {col1 => 'Setting',
1.9 raeburn 497: col2 => $lt{'stuv'}}],
1.1 raeburn 498: ordered => ['default_enrollment_start_date',
499: 'default_enrollment_end_date',
1.55 raeburn 500: 'defaultcredits',
1.56 raeburn 501: 'nothideprivileged','checkforpriv',
502: 'student_classlist_view',
1.26 raeburn 503: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 504: itemtext => {
505: default_enrollment_start_date => 'Start date',
506: default_enrollment_end_date => 'End date',
1.57 raeburn 507: nothideprivileged => $lt{'prus'},
1.56 raeburn 508: checkforpriv => $lt{'prdo'},
1.9 raeburn 509: student_classlist_view => $lt{'stuv'},
1.26 raeburn 510: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 511: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.55 raeburn 512: defaultcredits => $lt{'cred'},
1.3 raeburn 513: },
1.1 raeburn 514: },
515: 'appearance' =>
1.20 faziophi 516: { text => 'Display of resources ',
1.44 www 517: help => 'Course_Prefs_Display',
1.1 raeburn 518: ordered => ['default_xml_style','pageseparators',
519: 'disable_receipt_display','texengine',
1.114 raeburn 520: 'tthoptions','uselcmath','usejsme',
521: 'inline_chem','extresource'],
1.3 raeburn 522: itemtext => {
1.17 faziophi 523: default_xml_style => 'Default XML style file',
1.20 faziophi 524: pageseparators => 'Visibly Separate Items on Pages',
525: disable_receipt_display => 'Disable display of problem receipts',
526: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 527: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.69 raeburn 528: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
529: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.95 raeburn 530: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.124 raeburn 531: extresource => 'Display of external resources',
1.3 raeburn 532: },
1.1 raeburn 533: },
534: 'grading' =>
535: { text => 'Grading',
1.44 www 536: help => 'Course_Prefs_Grading',
1.1 raeburn 537: ordered => ['grading','rndseed',
538: 'receiptalg','disablesigfigs'],
1.3 raeburn 539: itemtext => {
1.20 faziophi 540: grading => 'Grading',
541: rndseed => 'Randomization algorithm used',
542: receiptalg => 'Receipt algorithm used',
543: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 544: },
545:
1.1 raeburn 546: },
547: 'printouts' =>
1.20 faziophi 548: { text => 'Printout generation',
1.44 www 549: help => 'Course_Prefs_Printouts',
1.1 raeburn 550: ordered => ['problem_stream_switch','suppress_tries',
551: 'default_paper_size','print_header_format',
1.14 raeburn 552: 'disableexampointprint','canuse_pdfforms'],
1.3 raeburn 553: itemtext => {
554: problem_stream_switch => 'Allow problems to be split over pages',
555: suppress_tries => 'Suppress number of tries in printing',
556: default_paper_size => 'Default paper type',
557: print_header_format => 'Print header format',
1.51 bisitz 558: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 559: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 560: },
1.1 raeburn 561: },
562: 'spreadsheet' =>
563: { text => 'Spreadsheets',
1.44 www 564: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 565: ordered => ['spreadsheet_default_classcalc',
566: 'spreadsheet_default_studentcalc',
567: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 568: itemtext => {
1.9 raeburn 569: spreadsheet_default_classcalc => $lt{'defc'},
570: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 571: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
572: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
573: },
1.1 raeburn 574: },
575: 'bridgetasks' =>
576: { text => 'Bridge tasks',
1.44 www 577: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 578: ordered => ['task_messages','task_grading',
579: 'suppress_embed_prompt'],
1.3 raeburn 580: itemtext => {
1.9 raeburn 581: task_messages => $lt{'seme'},
1.3 raeburn 582: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 583: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 584: },
1.1 raeburn 585: },
1.87 raeburn 586: 'lti' =>
587: {
588: text => 'LTI provider settings',
589: help => 'Course_Prefs_LTIProvider',
590: ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'],
591: itemtext => {
592: 'lti.override' => 'Override domain defaults',
593: 'lti.topmenu' => 'Display LON-CAPA page header',
594: 'lti.inlinemenu' => 'Display LON-CAPA inline menu',
595: 'lti.lcmenu' => 'Menu items',
596: },
597: },
1.91 raeburn 598: 'menuitems' =>
599: {
600: text => 'Menu display',
601: help => 'Course_Prefs_Menus',
602: header => [{col1 => 'Default Menu',
603: col2 => 'Value',},
604: {col1 => 'Menu collections',
605: col2 => 'Settings',
606: }],
607: ordered => ['menudefault','menucollections'],
608: itemtext => {
609: menudefault => 'Choose default collection of menu items for course',
610: menucollections => 'Menu collections',
611: },
612: },
1.102 raeburn 613: 'linkprot' =>
1.93 raeburn 614: {
615: text => 'Link protection',
616: help => 'Course_Prefs_Linkprotection',
617: header => [{col1 => 'Item',
618: col2 => 'Settings',
619: }],
620: },
1.118 raeburn 621: 'ltitools' =>
622: {
623: text => 'External tools',
624: help => 'Course_Prefs_ExternalTools',
625: header => [{col1 => 'Item',
626: col2 => 'Settings',
627: }],
628: },
1.1 raeburn 629: 'other' =>
630: { text => 'Other settings',
1.44 www 631: help => 'Course_Prefs_Other',
1.1 raeburn 632: header => [ {col1 => 'Item',
633: col2 => 'Value',
634: }],
635: },
636: );
1.80 raeburn 637: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 638: my @allitems = &get_allitems(%prefs);
1.108 raeburn 639: my $result = &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
640: \@prefs_order,\%prefs,\%values,
641: $cnum,undef,\@allitems,
642: 'coursepref',$parm_permission);
643: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
644: $r->rflush();
645: &devalidate_remote_courseprefs($cdom,$cnum,$result);
646: }
1.80 raeburn 647: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.91 raeburn 648: my $noedit;
649: if (ref($parm_permission) eq 'HASH') {
650: unless ($parm_permission->{'process'}) {
651: $noedit = 1;
652: }
653: }
654: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 655: my @allitems = &get_allitems(%prefs);
1.1 raeburn 656: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.99 raeburn 657: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.80 raeburn 658: 'coursepref',$parm_permission);
1.1 raeburn 659: } else {
660: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.80 raeburn 661: \@prefs_order,\%prefs,
662: 'coursepref',$parm_permission);
1.1 raeburn 663: }
664: return OK;
665: }
666:
1.80 raeburn 667: sub get_permission {
668: my ($cid) = @_;
669: my %permission;
670: my $allowed = 0;
671: return (\%permission,$allowed) unless ($cid);
672: if (&Apache::lonnet::allowed('opa',$cid)) {
673: %permission= (
674: 'pickactions' => 1,
675: 'categorizecourse' => 1,
676: 'releaseinfo' => 1,
677: 'process' => 1,
678: 'display' => 1,
679: );
680: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
681: %permission = (
682: 'pickactions' => 1,
683: 'releaseinfo' => 1,
684: 'display' => 1,
685: );
686: }
687: foreach my $perm (values(%permission)) {
688: if ($perm) { $allowed=1; last; }
689: }
690: return (\%permission,$allowed);
691: }
692:
1.3 raeburn 693: sub get_allitems {
694: my (%prefs) = @_;
695: my @allitems;
696: foreach my $item (keys(%prefs)) {
697: if (ref($prefs{$item}) eq 'HASH') {
698: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
699: push(@allitems,@{$prefs{$item}{'ordered'}});
700: if ($item eq 'feedback') {
701: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
702: }
1.126 raeburn 703: } elsif (($item eq 'linkprot') || ($item eq 'ltitools')) {
704: push(@allitems,$item);
1.3 raeburn 705: }
706: }
707: }
708: return @allitems;
709: }
710:
1.1 raeburn 711: sub print_config_box {
1.99 raeburn 712: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 713: my $ordered = $item->{'ordered'};
1.3 raeburn 714: my $itemtext = $item->{'itemtext'};
1.80 raeburn 715: my $noedit;
716: if (ref($parm_permission) eq 'HASH') {
717: unless ($parm_permission->{'process'}) {
718: $noedit = 1;
719: }
720: }
1.1 raeburn 721: my $rowtotal = 0;
722: my $output =
1.45 www 723: '<table class="LC_nested_outer">
724: <tr>
725: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 726: &mt($item->{text});
727: if ($item->{'help'}) {
1.53 raeburn 728: $output .= ' '.
1.52 raeburn 729: &Apache::loncommon::help_open_topic($item->{'help'});
730: }
731: $output .= '</span></th>'."\n".
732: '</tr>';
1.91 raeburn 733: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 734: $output .= '
1.45 www 735: <tr>
736: <td>
1.18 faziophi 737: <table class="LC_nested">';
738: if (exists $item->{'header'}->[0]->{'col1'} ||
739: exists $item->{'header'}->[0]->{'col2'}) {
740: $output .= '
741: <tr class="LC_info_row">
1.56 raeburn 742: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
743: if ($action eq 'feedback') {
744: $output .= '
745: <td class="LC_right_item" colspan="2">';
746: } else {
747: $output .= '
748: <td class="LC_right_item">';
749: }
750: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 751: </tr>';
752: }
1.1 raeburn 753: $rowtotal ++;
754: if ($action eq 'feedback') {
1.80 raeburn 755: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 756: } elsif ($action eq 'classlists') {
1.80 raeburn 757: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 758: } elsif ($action eq 'menuitems') {
759: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 760: }
761: $output .= '
762: </table>
1.45 www 763: </td>
764: </tr>
765: <tr>
766: <td>
1.1 raeburn 767: <table class="LC_nested">
768: <tr class="LC_info_row">
769: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 770: if ($action eq 'classlists') {
771: $output .= '
772: <td class="LC_right_item" colspan="2">';
773: } else {
774: $output .= '
775: <td class="LC_right_item">';
776: }
777: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 778: </tr>';
779: if ($action eq 'classlists') {
1.80 raeburn 780: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 781: '
782: </table>
1.45 www 783: </td>
784: </tr>
785: <tr>
786: <td>
1.18 faziophi 787: <table class="LC_nested">';
1.43 www 788: if (exists $item->{'header'}->[2]->{'col1'} ||
789: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 790: $output .= '
791: <tr class="LC_info_row">
1.43 www 792: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
793: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 794: </tr>';
795: }
1.1 raeburn 796: }
797: } else {
798: $output .= '
1.45 www 799: <tr>
800: <td>
1.18 faziophi 801: <table class="LC_nested">';
1.131 ! raeburn 802: if ($action eq 'linkprot') {
! 803: if ((ref($settings) eq 'HASH') && (ref($settings->{'suggested'}) eq 'HASH')) {
! 804: my $hints;
! 805: my $hintcount = 0;
! 806: foreach my $key (sort { $a <=> $b } keys(%{$settings->{'suggested'}})) {
! 807: if ((ref($settings->{'suggested'}->{$key}) eq 'HASH')) {
! 808: if (($settings->{'suggested'}->{$key}-{'name'} ne '') &&
! 809: ($settings->{'suggested'}->{$key}-{'info'} ne '')) {
! 810: my $css_class = $hintcount%2?' class="LC_odd_row"':' class="LC_even_row"';
! 811: $hints .= '<tr '.$css_class.'><td class="LC_left_item">'.
! 812: $settings->{'suggested'}->{$key}->{'name'}.'</td>'.
! 813: '<td class="LC_right_item"><pre>'.
! 814: $settings->{'suggested'}->{$key}->{'info'}.
! 815: '</pre></td></tr>';
! 816: $hintcount ++;
! 817: }
! 818: }
! 819: }
! 820: if ($hintcount) {
! 821: $output .= '<tr class="LC_info_row">'.
! 822: '<td colspan="2" class="LC_left_item">'.&mt('Recommendation(s) for specific launcher application(s)').'</td>'.
! 823: '</tr>'."\n".
! 824: '<tr class="LC_info_row">'.
! 825: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Launcher Application').'</span></td>'.
! 826: '<td class="LC_right_item">'.&mt('Recommendation(s)').'</td></tr>'."\n".
! 827: $hints;
! 828: }
! 829: }
! 830: }
1.18 faziophi 831: if (exists $item->{'header'}->[0]->{'col1'} ||
832: exists $item->{'header'}->[0]->{'col2'}) {
1.131 ! raeburn 833: $output .= '
1.18 faziophi 834: <tr class="LC_info_row">
1.56 raeburn 835: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
836: if (($action eq 'courseinfo') || ($action eq 'localization') ||
837: ($action eq 'print_discussion')) {
838: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
839: } else {
840: $output .= '<td class="LC_right_item" valign="top">';
841: }
842: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 843: </tr>';
844: }
1.1 raeburn 845: }
846: $rowtotal ++;
847: if ($action eq 'courseinfo') {
1.80 raeburn 848: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 849: } elsif ($action eq 'localization') {
1.80 raeburn 850: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 851: } elsif ($action eq 'feedback') {
1.80 raeburn 852: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 853: } elsif ($action eq 'discussion') {
1.80 raeburn 854: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 855: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 856: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 857: } elsif ($action eq 'appearance') {
1.80 raeburn 858: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 859: } elsif ($action eq 'grading') {
1.127 raeburn 860: $output .= &print_grading($cdom,$cnum,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 861: } elsif ($action eq 'printouts') {
1.80 raeburn 862: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 863: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 864: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 865: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 866: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.118 raeburn 867: } elsif ($action eq 'ltitools') {
868: my $currtools = {};
869: if ((ref($settings) eq 'HASH') && (ref($settings->{'ltitools'}))) {
870: $currtools = $settings->{'ltitools'};
871: }
872: $output .= &print_ltitools($cdom,$cnum,$currtools,\$rowtotal,$crstype,$noedit,'course');
1.87 raeburn 873: } elsif ($action eq 'lti') {
874: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 875: } elsif ($action eq 'menuitems') {
876: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 877: } elsif ($action eq 'linkprot') {
878: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 879: } elsif ($action eq 'other') {
1.80 raeburn 880: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 881: }
882: $output .= '
883: </table>
1.45 www 884: </td>
885: </tr>
886: </table><br />';
1.1 raeburn 887: return ($output,$rowtotal);
888: }
889:
890: sub process_changes {
1.108 raeburn 891: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 892: my (%newvalues,$errors);
1.3 raeburn 893: if (ref($item) eq 'HASH') {
894: if (ref($changes) eq 'HASH') {
895: my @ordered;
896: if ($action eq 'other') {
897: @ordered = &get_other_items($cdom,$values,$allitems);
898: if ($env{'form.newp_name'} ne '') {
899: my $newp = $env{'form.newp_name'};
900: if ($env{'form.newp_value'} ne '') {
901: if (ref($allitems) eq 'ARRAY') {
902: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
903: (grep(/^\Q$newp\E$/,@{$allitems}))) {
904: $changes->{$newp} = $env{'form.newp_value'};
905: }
906: }
907: }
908: }
1.118 raeburn 909: } elsif (($action eq 'linkprot') || ($action eq 'ltitools')) {
1.99 raeburn 910: if (ref($values->{$action}) eq 'HASH') {
911: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 912: if ($id =~ /^\d+$/) {
913: push(@ordered,$id);
914: }
915: }
916: }
917: @ordered = sort { $a <=> $b } @ordered;
1.118 raeburn 918: if (($env{'form.'.$action.'_add'}) && ($env{'form.'.$action.'_maxnum'} =~ /^\d+$/)) {
919: push(@ordered,$env{'form.'.$action.'_maxnum'});
1.93 raeburn 920: }
1.3 raeburn 921: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 922: if ($action eq 'courseinfo') {
923: my ($can_toggle_cat,$can_categorize) =
924: &can_modify_catsettings($cdom,$crstype);
925: foreach my $entry (@{$item->{'ordered'}}) {
926: next if (($entry eq 'hidefromcat') &&
927: (!$can_toggle_cat));
928: next if (($entry eq 'categories') &&
929: (!$can_categorize));
930: next if (($entry eq 'loncaparev') ||
1.63 raeburn 931: ($entry eq 'owner') ||
1.88 raeburn 932: ($entry eq 'clonedfrom') ||
933: ($entry eq 'syllabus'));
1.49 raeburn 934: push(@ordered,$entry);
935: }
1.55 raeburn 936: } elsif ($action eq 'classlists') {
937: foreach my $entry (@{$item->{'ordered'}}) {
938: next if ($entry eq 'defaultcredits');
939: push(@ordered,$entry);
940: }
1.49 raeburn 941: } else {
942: @ordered = @{$item->{'ordered'}};
943: }
1.3 raeburn 944: }
945: if (@ordered > 0) {
946: if ($action eq 'feedback') {
947: foreach my $entry (@ordered) {
948: my $userstr = '';
949: my $total = $env{'form.'.$entry.'_total'};
950: if ($total) {
951: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
952: for (my $i=0; $i<$total; $i++) {
953: unless (grep(/^$i$/,@deletes)) {
954: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
955: &get_sec_str($entry,$i).',';
956: }
957: }
958: } else {
959: $total = 0;
960: }
961: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
962: my $uname = $env{'form.'.$entry.'_uname_'.$total};
963: my $udom = $env{'form.'.$entry.'_udom_'.$total};
964: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
965: $userstr =~ s/,$//;
966: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
967: } else {
968: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
969: }
970: } else {
971: $userstr =~ s/,$//;
972: }
973: $newvalues{$entry} = $userstr;
974: if ($newvalues{$entry} ne $values->{$entry}) {
975: $changes->{$entry} = $newvalues{$entry};
976: }
977: my $ext_entry = $entry.'.text';
978: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
979: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
980: $changes->{$ext_entry} = $newvalues{$ext_entry};
981: }
982: }
1.91 raeburn 983: } elsif ($action eq 'menuitems') {
984: my (%current,@colls);
985: my $next = 1;
986: if ($values->{'menucollections'}) {
987: foreach my $item (split(/;/,$values->{'menucollections'})) {
988: my ($num,$value) = split(/\%/,$item);
989: if ($num =~ /^\d+$/) {
990: unless (grep(/^$num$/,@colls)) {
991: push(@colls,$num);
992: }
993: my @entries = split(/\&/,$value);
994: foreach my $entry (@entries) {
995: my ($name,$fields) = split(/=/,$entry);
996: $current{$num}{$name} = $fields;
997: }
998: }
999: }
1000: }
1001: if (@colls) {
1002: @colls = sort { $a <=> $b } @colls;
1003: $next += $colls[-1];
1004: }
1005: if ($env{'form.menucollections_add'} eq $next) {
1006: push(@colls,$next);
1007: }
1008: my $currdef = $values->{'menudefault'};
1009: my $possdef = $env{'form.menudefault'};
1010: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 1011: if ($currdef ne $possdef) {
1.91 raeburn 1012: $changes->{'menudefault'} = $possdef;
1013: }
1.92 raeburn 1014: } elsif ($currdef) {
1.91 raeburn 1015: $changes->{'menudefault'} = '';
1016: }
1017: my $menucoll;
1018: if (@colls) {
1019: my ($ordered,$cats) = &menuitems_categories();
1020: my %shortcats = &menuitems_abbreviations();
1021: foreach my $num (@colls) {
1022: my ($entry,%include);
1023: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
1024: foreach my $item (@{$ordered}) {
1025: if ($item eq 'shown') {
1026: foreach my $type (@{$cats->{$item}}) {
1027: $entry .= $type.'=';
1028: if ($include{$type}) {
1029: $entry .= 'y';
1030: } else {
1031: $entry .= 'n';
1032: }
1033: $entry .= '&';
1034: }
1035: } else {
1036: $entry .= $shortcats{$item}.'=';
1037: foreach my $type (@{$cats->{$item}}) {
1038: if ($include{$type}) {
1039: $entry .= $type.',';
1040: }
1041: }
1042: $entry =~ s/,$//;
1043: $entry .= '&';
1044: }
1045: }
1046: $entry =~ s/\&$//;
1047: if ($menucoll) {
1048: $menucoll .= ';';
1049: }
1050: $menucoll .= $num.'%'.$entry;
1051: }
1052: if ($menucoll ne $values->{'menucollections'}) {
1053: $changes->{'menucollections'} = $menucoll;
1054: }
1055: } elsif ($values->{'menucollections'}) {
1056: $changes->{'menucollections'} = '';
1057: }
1.102 raeburn 1058: } elsif ($action eq 'linkprot') {
1059: if (ref($values) eq 'HASH') {
1.108 raeburn 1060: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 1061: }
1.118 raeburn 1062: } elsif ($action eq 'ltitools') {
1063: if (ref($values) eq 'HASH') {
1064: my $switchserver = &check_switchserver($cdom,$cnum,'course','/adm/courseprefs');
1065: $errors = &process_ltitools('',$cdom,$cnum,$values->{$action},$changes,'course',$lastactref,
1066: 'ok','','ok');
1067: }
1.3 raeburn 1068: } else {
1069: foreach my $entry (@ordered) {
1070: if ($entry eq 'cloners') {
1071: if ($env{'form.cloners_all'}) {
1072: $newvalues{$entry} = '*';
1073: } else {
1074: my @clonedoms;
1075: if (exists($env{'form.cloners_activate'})) {
1076: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1077: if ($actnum ne '-1') {
1.33 raeburn 1078: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1079: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1080: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1081: $newvalues{$entry} = '*:'.$clonedom;
1082: push(@clonedoms,$newvalues{$entry});
1083: }
1084: }
1085: }
1086: } else {
1087: my $num = $env{'form.cloners_total'};
1088: my @deletes =
1089: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1090: for (my $i=0; $i<$num; $i++) {
1091: if (!grep(/^$i$/,@deletes)) {
1092: my $clonedom = $env{'form.cloners_dom_'.$i};
1093: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1094: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1095: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1096: }
1097: }
1098: }
1099: }
1100: if (@clonedoms) {
1101: $newvalues{$entry}=join(',',@clonedoms);
1102: }
1103: }
1104: if ($env{'form.cloners_newdom'} ne '') {
1105: my $clonedom = $env{'form.cloners_newdom'};
1106: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1107: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1108: if (@clonedoms) {
1.3 raeburn 1109: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1110: $newvalues{$entry} .= ','.$newdom;
1111: }
1112: } else {
1113: $newvalues{$entry} = $newdom;
1114: }
1115: }
1116: }
1117: if ($env{'form.'.$entry} ne '') {
1118: my @cloners = split(',',$env{'form.'.$entry});
1119: my @okcloners;
1120: foreach my $cloner (@cloners) {
1.23 raeburn 1121: $cloner =~ s/^\s+//;
1122: $cloner =~ s/\s+$//;
1123: unless ($cloner eq '') {
1124: my ($uname,$udom) = split(':',$cloner);
1125: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1126: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1127: push(@okcloners,$cloner);
1128: }
1.3 raeburn 1129: }
1130: }
1131: }
1132: if (@okcloners) {
1133: my $okclonestr = join(',',@okcloners);
1134: if ($newvalues{$entry} ne '') {
1135: $newvalues{$entry} .= ','.$okclonestr;
1136: } else {
1137: $newvalues{$entry} = $okclonestr;
1138: }
1139: }
1140: }
1.71 raeburn 1141: if (ref($values) eq 'HASH') {
1142: my (@code_order,%codedefaults);
1143: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1144: \@code_order);
1145: my $clonebycode;
1146: if ($env{'form.cloners_instcode'}) {
1147: if (@code_order > 0) {
1148: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1149: my %local_to_standard;
1150: for (my $i=0; $i<@code_order; $i++) {
1151: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1152: }
1153: foreach my $item (@code_order) {
1154: my $key = $local_to_standard{$item};
1155: if ($key ne '') {
1156: if ($env{'form.'.$key}) {
1157: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1158: }
1159: }
1160: }
1161: $clonebycode =~ s/\&$//;
1162: }
1163: }
1164: if ($clonebycode) {
1165: if ($newvalues{$entry}) {
1166: $newvalues{$entry} .= ','.$clonebycode;
1167: } else {
1168: $newvalues{$entry} = $clonebycode;
1169: }
1170: }
1171: }
1.3 raeburn 1172: }
1173: if (ref($disallowed) eq 'HASH') {
1174: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1175: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1176: $disallowed->{'cloners'}{$key} =~ s/,$//;
1177: }
1178: }
1179: }
1.25 raeburn 1180: } elsif ($entry eq 'co-owners') {
1181: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1182: my $coowners = $values->{'internal.co-owners'};
1183: my @currcoown;
1184: if ($coowners) {
1185: @currcoown = split(',',$coowners);
1186: }
1187: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1188: my $autocoowner;
1189: if (($crstype eq 'Course') &&
1190: ($values->{'internal.coursecode'})) {
1191: my %domconf =
1192: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1193: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1194: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1195: }
1196: }
1.96 raeburn 1197: if ($autocoowner) {
1198: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1199: } else {
1.25 raeburn 1200: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1201: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1202: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1203: if (@invitecoowners) {
1204: push(@pendingcoowners,@invitecoowners);
1205: }
1206: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1207: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1208: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1209: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1210: push(@{$changes->{$entry}{'changed'}},'co-owners');
1211: }
1212: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1213: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1214: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1215: }
1216: }
1217: } else {
1218: my (@newpending,@newcoown);
1219: my $uname = $env{'user.name'};
1220: my $udom = $env{'user.domain'};
1221: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1222: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1223: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1224: foreach my $item (@pendingcoown) {
1225: unless ($item eq $uname.':'.$udom) {
1226: push(@newpending,$item);
1227: }
1228: }
1229: @newcoown = @currcoown;
1.90 raeburn 1230: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1231: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1232: push(@newcoown,$uname.':'.$udom);
1233: }
1234: }
1.90 raeburn 1235: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1236: foreach my $item (@currcoown) {
1237: unless ($item eq $uname.':'.$udom) {
1238: push(@newcoown,$item);
1239: }
1240: }
1241: if ($pendingcoowners ne '') {
1242: @newpending = @pendingcoown;
1243: }
1.96 raeburn 1244: } else {
1245: @newcoown = @currcoown;
1.25 raeburn 1246: }
1247: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1248: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1249: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1250: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1251: push(@{$changes->{$entry}{'changed'}},'co-owners');
1252: }
1253: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1254: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1255: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1256: }
1257: }
1.3 raeburn 1258: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1259: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1260: } elsif ($entry eq 'rolenames') {
1261: my %adv_roles =
1262: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1263: my @stds;
1264: if ($crstype eq 'Community') {
1265: @stds = ('co');
1266: } else {
1267: @stds = ('cc');
1268: }
1269: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1270: my (@replacements,@regulars);
1271: foreach my $role (@stds) {
1272: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1273: push(@replacements,$role);
1.3 raeburn 1274: } else {
1275: push(@regulars,$role);
1276: }
1.9 raeburn 1277: }
1.3 raeburn 1278: foreach my $stdrole (@stds) {
1279: my $ext_entry = $entry.'_'.$stdrole;
1280: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1281: $env{'request.course.id'},1);
1282: if ($env{'form.'.$ext_entry} eq $stdname) {
1283: $newvalues{$ext_entry} = '';
1284: } else {
1285: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1286: }
1287: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1288: my $dupname = 0;
1289: if ($newvalues{$ext_entry} ne '') {
1290: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1291: $dupname = 1;
1292: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1293: }
1294: if (!$dupname) {
1295: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1296: $dupname = 1;
1297: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1298: }
1299: }
1300: if (!$dupname) {
1301: foreach my $role (keys(%adv_roles)) {
1302: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1303: $dupname = 1;
1304: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1305: last;
1306: }
1307: }
1308: }
1309: }
1310: if (!$dupname) {
1311: $changes->{$ext_entry} = $newvalues{$ext_entry};
1312: }
1313: }
1314: }
1.77 raeburn 1315: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1316: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1317: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1318: @denied = sort(@denied);
1319: my $deniedstr = '';
1320: if (@denied > 0) {
1321: $deniedstr = join(',',@denied);
1322: }
1323: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1324: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1325: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1326: my $total = $env{'form.'.$entry.'_total'};
1327: my $userstr = '';
1328: my @denied;
1329: if ($total > 0) {
1330: my @deletes =
1331: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1332: for (my $i=0; $i<$total; $i++) {
1333: unless (grep(/^$i$/,@deletes)) {
1334: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1335: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1336: }
1337: }
1338: } else {
1339: $total = 0;
1340: }
1341: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1342: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1343: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1344: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1345: $userstr =~ s/,$//;
1346: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1347: } else {
1348: my $newuser .= $uname.':'.$udom;
1349: if (grep(/^\Q$newuser\E$/,@denied)) {
1350: $userstr =~ s/,$//;
1351: } else {
1352: $userstr .= $newuser;
1353: }
1354: }
1355: } else {
1356: $userstr =~ s/,$//;
1357: }
1358: $newvalues{$entry} = $userstr;
1359: } elsif ($entry eq 'allow_discussion_post_editing') {
1360: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1361: @canedit = sort(@canedit);
1362: foreach my $role (@canedit) {
1363: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1364: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1365: $newvalues{$entry} .= $role.',';
1366: } else {
1367: foreach my $sec (@secs) {
1368: $newvalues{$entry} .= $role.':'.$sec.',';
1369: }
1370: }
1371: }
1372: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1373: } elsif ($entry eq 'discussion_post_fonts') {
1374: my ($classorder,$classtitles) = &discussion_vote_classes();
1375: my $fontchange = 0;
1376: foreach my $class (@{$classorder}) {
1.124 raeburn 1377: my $ext_entry = $entry.'_'.$class;
1.50 raeburn 1378: my $size = $env{'form.'.$ext_entry.'_size'};
1379: my $unit = $env{'form.'.$ext_entry.'_unit'};
1380: my $weight = $env{'form.'.$ext_entry.'_weight'};
1381: my $style = $env{'form.'.$ext_entry.'_style'};
1382: my $other = $env{'form.'.$ext_entry.'_other'};
1383: $size =~ s/,//g;
1.124 raeburn 1384: $unit =~ s/,//g;
1.50 raeburn 1385: $weight =~ s/,//g;
1386: $style =~ s/,//g;
1387: $other =~ s/[^\w;:\s\-\%.]//g;
1388: $other =~ s/(^\s+|\s+$)//g;
1389: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1390: my $current = $values->{$ext_entry};
1391: if ($values->{$ext_entry} eq '') {
1.124 raeburn 1392: $current = ',,,';
1.50 raeburn 1393: }
1394: if ($newvalues{$ext_entry} ne $current) {
1395: $changes->{$ext_entry} = $newvalues{$ext_entry};
1396: $fontchange ++;
1397: }
1398: }
1399: if ($fontchange) {
1400: $changes->{$entry} = 1;
1.124 raeburn 1401: }
1.3 raeburn 1402: } elsif ($entry eq 'nothideprivileged') {
1403: my @curr_nothide;
1404: my @new_nothide;
1405: if ($values->{$entry} ne '') {
1406: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1407: my $nothide;
1408: if ($user !~ /:/) {
1409: $nothide = join(':',split(/[\@]/,$user));
1410: } else {
1411: $nothide = $user;
1412: }
1413: if ((defined($nothide)) &&
1414: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1415: push(@curr_nothide,$nothide);
1416: }
1417: }
1418: }
1419: foreach my $key (keys(%env)) {
1420: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1421: if ($env{$key}) {
1.3 raeburn 1422: my $nothide = $1;
1423: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1424: push(@new_nothide,$nothide);
1425: }
1426: }
1427: }
1428: }
1429: @new_nothide = sort(@new_nothide);
1430: my @differences =
1431: &Apache::loncommon::compare_arrays(\@curr_nothide,
1432: \@new_nothide);
1433: if (@differences > 0) {
1434: if (@new_nothide > 0) {
1435: $newvalues{$entry} = join(',',@new_nothide);
1436: } else {
1437: $newvalues{$entry} = '';
1438: }
1439: } else {
1440: $newvalues{$entry} = $values->{$entry};
1441: }
1442: } elsif ($entry eq 'print_header_format') {
1443: my $maxnum = $env{'form.printfmthdr_maxnum'};
1444: my @newhdr;
1445: if ($maxnum > 2) {
1446: for (my $i=0; $i<$maxnum-2; $i++) {
1447: if ($env{'form.printfmthdr_del_'.$i}) {
1448: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1449: } else {
1450: my $hdr;
1451: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1452: $hdr = '%';
1453: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1454: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1455: }
1456: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1457: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1458: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1459: }
1460: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1461: }
1462: }
1463: }
1464: my $newsub = $maxnum-2;
1465: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1466: my $hdr = '%';
1467: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1468: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1469: }
1470: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1471: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1472: }
1473: my $newtext = $maxnum-1;
1474: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1475: $newvalues{$entry} = join('',@newhdr);
1.124 raeburn 1476: } elsif (($entry eq 'languages') ||
1.56 raeburn 1477: ($entry eq 'checkforpriv')) {
1478: my $settings;
1.3 raeburn 1479: my $total = $env{'form.'.$entry.'_total'};
1480: if ($total) {
1481: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1482: for (my $i=0; $i<$total; $i++) {
1483: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1484: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1485: }
1486: }
1487: } else {
1488: $total = 0;
1489: }
1490: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1491: my $new = $env{'form.'.$entry.'_'.$total};
1.124 raeburn 1492: if ($entry eq 'languages') {
1.56 raeburn 1493: my %langchoices = &get_lang_choices();
1494: if ($langchoices{$new}) {
1495: $settings .= $new;
1496: } else {
1497: $settings =~ s/,$//;
1498: $disallowed->{'localization'}{$entry} = $new;
1499: }
1.3 raeburn 1500: } else {
1.56 raeburn 1501: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1502: if ($domains{$new}) {
1503: $settings .= $new;
1504: } else {
1505: $settings =~ s/,$//;
1506: $disallowed->{'classlists'}{$entry} = $new;
1507: }
1.3 raeburn 1508: }
1509: } else {
1.56 raeburn 1510: $settings =~ s/,$//;
1.3 raeburn 1511: }
1.56 raeburn 1512: $newvalues{$entry} = $settings;
1.87 raeburn 1513: } elsif ($action eq 'lti') {
1514: if ($entry eq 'lti.override') {
1515: $newvalues{$entry} = $env{'form.'.$entry};
1516: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1517: if ($env{'form.lti.override'}) {
1518: $newvalues{$entry} = $env{'form.'.$entry};
1519: } else {
1520: $newvalues{$entry} = '';
1521: }
1522: } elsif ($entry eq 'lti.lcmenu') {
1523: if (($env{'form.lti.override'}) &&
1524: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1525: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1526: my @newlcmenu;
1527: if (@lcmenu) {
1528: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1529: foreach my $item (@menuitems) {
1530: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1531: if (grep(/^\Q$item\E$/,@lcmenu)) {
1532: push(@newlcmenu,$item);
1533: }
1534: }
1535: }
1536: if (@newlcmenu) {
1537: $newvalues{$entry} = join(',',@newlcmenu);
1538: } else {
1539: $newvalues{$entry} = 'none';
1540: }
1541: } else {
1542: $newvalues{$entry} = '';
1543: }
1544: }
1.114 raeburn 1545: } elsif ($entry eq 'extresource') {
1546: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1547: $newvalues{$entry} = $env{'form.'.$entry};
1548: if ($env{'form.'.$entry} ne 'iframe') {
1549: if ($env{'form.extwintabreuse'}) {
1550: $newvalues{$entry} .= ':1';
1551: } else {
1552: $newvalues{$entry} .= ':0';
1553: }
1554: if ($env{'form.'.$entry} eq 'window') {
1555: foreach my $dim ('width','height') {
1556: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1557: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1558: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1559: } else {
1560: $newvalues{$entry} .= ':';
1561: }
1562: }
1563: }
1564: }
1565: }
1566: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1567: if ($newvalues{$entry} ne $values->{$entry}) {
1568: $changes->{$entry} = $newvalues{$entry};
1569: }
1570: }
1.115 raeburn 1571: } elsif ($entry eq 'timezone') {
1572: if ($env{'form.'.$entry}) {
1573: $newvalues{$entry} = $env{'form.'.$entry};
1574: if ($newvalues{$entry} ne $values->{$entry}) {
1575: $changes->{$entry} = $newvalues{$entry};
1576: }
1577: if ($env{'form.tzover'}) {
1578: $newvalues{'tzover'} = $env{'form.tzover'};
1579: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
1580: $changes->{'tzover'} = $newvalues{'tzover'};
1581: }
1582: } elsif ($values->{'tzover'}) {
1583: $changes->{'tzover'} = '';
1584: }
1585: } elsif ($values->{$entry}) {
1586: $changes->{$entry} = '';
1587: }
1.127 raeburn 1588: } elsif ($entry eq 'grading') {
1589: if ($env{'form.'.$entry} eq 'standard') {
1590: if ($env{'form.hidetotals'}) {
1591: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
1592: if (keys(%sections)) {
1593: my @secs = &Apache::loncommon::get_env_multiple('form.hidetotals_sections');
1594: if (grep(/^all$/,@secs)) {
1595: $newvalues{'hidetotals'} = 'all';
1596: } elsif (@secs) {
1597: $newvalues{'hidetotals'} = '';
1598: foreach my $sec (sort {$a <=> $b} @secs) {
1599: if (exists($sections{$sec})) {
1600: $newvalues{'hidetotals'} .= $sec.','
1601: }
1602: }
1603: $newvalues{'hidetotals'} =~ s/,$//;
1604: }
1605: } else {
1606: $newvalues{'hidetotals'} = 'all';
1607: }
1608: }
1609: }
1610: if ($newvalues{'hidetotals'} ne $values->{'hidetotals'}) {
1611: $changes->{'hidetotals'} = $newvalues{'hidetotals'};
1612: $changes->{'grading'} = $env{'form.'.$entry};
1613: }
1614: $newvalues{$entry} = $env{'form.'.$entry};
1.3 raeburn 1615: } else {
1616: $newvalues{$entry} = $env{'form.'.$entry};
1617: }
1.124 raeburn 1618: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
1.115 raeburn 1619: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1620: if ($newvalues{$entry} ne $values->{$entry}) {
1621: $changes->{$entry} = $newvalues{$entry};
1622: }
1.3 raeburn 1623: }
1624: }
1625: }
1626: }
1627: }
1628: }
1.93 raeburn 1629: return $errors;
1630: }
1631:
1.102 raeburn 1632: sub process_linkprot {
1.108 raeburn 1633: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.118 raeburn 1634: my ($dest,$ltiauth,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1635: if (ref($values) eq 'HASH') {
1636: foreach my $id (keys(%{$values})) {
1637: if ($id =~ /^\d+$/) {
1638: unless (ref($values->{$id}) eq 'HASH') {
1639: $linkprot{$id} = '';
1640: }
1641: }
1642: }
1643: }
1.118 raeburn 1644: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'lti',$context);
1.102 raeburn 1645: if ($context eq 'domain') {
1646: $dest = '/adm/domainprefs';
1647: $ltiauth = 1;
1648: } else {
1649: $dest = '/adm/courseprefs';
1650: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1651: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1652: } else {
1653: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1654: $ltiauth = $domdefs{'crsltiauth'};
1655: }
1656: }
1657: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1658: my (@items,%deletions,%itemids,%haschanges);
1659: if ($env{'form.linkprot_add'}) {
1660: my $name = $env{'form.linkprot_name_add'};
1661: $name =~ s/(`)/'/g;
1662: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1663: if ($newid) {
1664: $itemids{'add'} = $newid;
1665: push(@items,'add');
1666: $haschanges{$newid} = 1;
1667: } else {
1668: $errors .= '<span class="LC_error">'.
1669: &mt('Failed to acquire unique ID for link protection').
1670: '</span>';
1671: }
1672: }
1673: if (ref($values) eq 'HASH') {
1674: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1675: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1676: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1677: my $itemid = $env{'form.linkprot_id_'.$i};
1678: $itemid =~ s/\D+//g;
1679: if ($itemid) {
1680: if (ref($values->{$itemid}) eq 'HASH') {
1681: push(@items,$i);
1682: $itemids{$i} = $itemid;
1683: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1684: $deletions{$itemid} = $values->{$itemid}->{'name'};
1685: }
1686: }
1687: }
1688: }
1689: }
1690: foreach my $idx (@items) {
1691: my $itemid = $itemids{$idx};
1692: next unless ($itemid);
1693: if (exists($deletions{$itemid})) {
1694: $linkprot{$itemid} = $deletions{$itemid};
1695: $haschanges{$itemid} = 1;
1696: next;
1697: }
1698: my %current;
1699: if (ref($values) eq 'HASH') {
1700: if (ref($values->{$itemid}) eq 'HASH') {
1701: foreach my $key (keys(%{$values->{$itemid}})) {
1702: $current{$key} = $values->{$itemid}->{$key};
1703: }
1704: }
1705: }
1706: foreach my $inner ('name','lifetime','version') {
1707: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1708: $env{$formitem} =~ s/(`)/'/g;
1709: if ($inner eq 'lifetime') {
1710: $env{$formitem} =~ s/[^\d.]//g;
1711: }
1712: unless ($idx eq 'add') {
1713: if ($current{$inner} ne $env{$formitem}) {
1714: $haschanges{$itemid} = 1;
1715: }
1716: }
1717: if ($env{$formitem} ne '') {
1718: $linkprot{$itemid}{$inner} = $env{$formitem};
1719: }
1720: }
1.112 raeburn 1721: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1722: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1723: if ($env{$urlitem} == 1) {
1724: $env{$urlparamname} =~ s/(`)/'/g;
1725: } elsif (exists($env{$urlparamname})) {
1726: $env{$urlparamname} = '';
1727: }
1.122 raeburn 1728: my $passback = 'form.linkprot_passback_'.$idx;
1729: my $passbackparamname = 'form.linkprot_passbackformat_'.$idx;
1730: if ($env{$passback} == 1) {
1731: unless ($env{$passbackparamname} =~ /^1\.(0|1)$/) {
1732: $env{$passbackparamname} = '';
1733: }
1734: } elsif (exists($env{$passbackparamname})) {
1735: $env{$passbackparamname} = '';
1736: }
1.112 raeburn 1737: unless ($idx eq 'add') {
1738: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1739: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1740: $haschanges{$itemid} = 1;
1741: }
1.122 raeburn 1742: if ((!$current{'passback'} && ($env{$passbackparamname} ne '')) ||
1743: ($current{'passback'} && ($env{$passbackparamname} eq ''))) {
1744: $haschanges{$itemid} = 1;
1745: }
1.112 raeburn 1746: }
1.123 raeburn 1747: if ($env{$urlparamname} ne '') {
1748: $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1749: }
1.122 raeburn 1750: if ($env{$passbackparamname} ne '') {
1751: $linkprot{$itemid}{'passback'} = 1;
1752: $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname};
1.112 raeburn 1753: }
1.102 raeburn 1754: if ($ltiauth) {
1755: my $reqitem = 'form.linkprot_requser_'.$idx;
1756: $env{$reqitem} =~ s/(`)/'/g;
1757: unless ($idx eq 'add') {
1.104 raeburn 1758: if ((!$current{'requser'} && $env{$reqitem}) ||
1759: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1760: $haschanges{$itemid} = 1;
1761: }
1762: }
1763: if ($env{$reqitem} == 1) {
1764: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1765: foreach my $inner ('mapuser','notstudent') {
1766: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1767: $env{$formitem} =~ s/(`)/'/g;
1768: if ($inner eq 'mapuser') {
1769: if ($env{$formitem} eq 'other') {
1770: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1771: $mapuser =~ s/(`)/'/g;
1772: $mapuser =~ s/^\s+|\s+$//g;
1773: if ($mapuser ne '') {
1774: $linkprot{$itemid}{$inner} = $mapuser;
1775: } else {
1776: delete($linkprot{$itemid}{'requser'});
1777: last;
1778: }
1779: } elsif ($env{$formitem} eq 'sourcedid') {
1780: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1781: } elsif ($env{$formitem} eq 'email') {
1782: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1783: }
1784: } else {
1785: $linkprot{$itemid}{$inner} = $env{$formitem};
1786: }
1787: unless ($idx eq 'add') {
1788: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1789: $haschanges{$itemid} = 1;
1790: }
1791: }
1792: }
1793: }
1794: }
1795: unless ($switchserver) {
1796: my $keyitem = 'form.linkprot_key_'.$idx;
1797: $env{$keyitem} =~ s/(`)/'/g;
1798: unless ($idx eq 'add') {
1799: if ($current{'key'} ne $env{$keyitem}) {
1800: $haschanges{$itemid} = 1;
1801: }
1802: }
1803: if ($env{$keyitem} ne '') {
1804: $linkprot{$itemid}{'key'} = $env{$keyitem};
1805: }
1806: my $secretitem = 'form.linkprot_secret_'.$idx;
1807: $env{$secretitem} =~ s/(`)/'/g;
1808: if ($current{'usable'}) {
1809: if ($env{'form.linkprot_changesecret_'.$idx}) {
1810: if ($env{$secretitem} ne '') {
1.103 raeburn 1811: if ($privnum && $cipher) {
1812: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1813: $linkprot{$itemid}{'cipher'} = $privnum;
1814: } else {
1815: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1816: }
1.102 raeburn 1817: $haschanges{$itemid} = 1;
1818: }
1819: } else {
1820: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1821: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1822: }
1823: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1824: if ($privnum && $cipher) {
1825: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1826: $linkprot{$itemid}{'cipher'} = $privnum;
1827: } else {
1828: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1829: }
1.102 raeburn 1830: $haschanges{$itemid} = 1;
1831: }
1832: }
1833: }
1834: if (keys(%haschanges)) {
1835: foreach my $entry (keys(%haschanges)) {
1836: $changes->{$entry} = $linkprot{$entry};
1837: }
1.108 raeburn 1838: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1839: $lastactref->{'courselti'} = 1;
1.108 raeburn 1840: }
1.102 raeburn 1841: }
1842: return $errors;
1843: }
1844:
1845: sub get_linkprot_id {
1846: my ($cdom,$cnum,$name,$context) = @_;
1847: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1848: my $lockhash = {
1849: lock => $env{'user.name'}.
1850: ':'.$env{'user.domain'},
1851: };
1852: my $tries = 0;
1.102 raeburn 1853: my $gotlock;
1854: if ($context eq 'domain') {
1855: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1856: } else {
1857: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1858: }
1.93 raeburn 1859: my ($id,$error);
1860: while (($gotlock ne 'ok') && ($tries<10)) {
1861: $tries ++;
1862: sleep (0.1);
1.102 raeburn 1863: if ($context eq 'domain') {
1.124 raeburn 1864: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1.102 raeburn 1865: } else {
1866: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1867: }
1.93 raeburn 1868: }
1869: if ($gotlock eq 'ok') {
1.102 raeburn 1870: my %currids;
1871: if ($context eq 'domain') {
1872: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1873: } else {
1874: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1875: }
1.93 raeburn 1876: if ($currids{'lock'}) {
1877: delete($currids{'lock'});
1878: if (keys(%currids)) {
1879: my @curr = sort { $a <=> $b } keys(%currids);
1880: if ($curr[-1] =~ /^\d+$/) {
1881: $id = 1 + $curr[-1];
1882: } else {
1883: $id = 1;
1884: }
1885: } else {
1886: $id = 1;
1887: }
1888: if ($id) {
1.102 raeburn 1889: if ($context eq 'domain') {
1890: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1891: $error = 'nostore';
1892: }
1893: } else {
1894: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1895: $error = 'nostore';
1896: }
1.93 raeburn 1897: }
1898: } else {
1899: $error = 'nonumber';
1900: }
1901: }
1.124 raeburn 1902: my $dellockoutcome;
1.102 raeburn 1903: if ($context eq 'domain') {
1904: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1905: } else {
1906: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1907: }
1.93 raeburn 1908: } else {
1909: $error = 'nolock';
1910: }
1911: return ($id,$error);
1.3 raeburn 1912: }
1913:
1.118 raeburn 1914: sub get_credentials {
1915: my ($cdom,$cnum,$type,$context) = @_;
1916: my ($cipher,$privnum,$home);
1917: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1918: my @ids=&Apache::lonnet::current_machine_ids();
1919: if ($context eq 'domain') {
1920: $home = &Apache::lonnet::domain($cdom,'primary');
1921: } else {
1922: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1923: }
1924: my ($hostskey,$domkey,$crskey);
1925: if ($type eq 'ltitools') {
1926: $hostskey = 'toolprivhosts';
1927: $domkey = 'toolenc_dom';
1928: $crskey = 'toolenc_crs';
1929: } else {
1930: $hostskey = 'ltiprivhosts';
1931: $domkey = 'linkprotenc_dom';
1932: $crskey = 'linkprotenc_crs';
1933: }
1934: if ((($context eq 'domain') && ($domdefs{$domkey})) ||
1935: (($context eq 'course') && ($domdefs{$crskey}))) {
1936: unless (($home eq 'no_host') || ($home eq '')) {
1937: if (grep(/^\Q$home\E$/,@ids)) {
1938: if (ref($domdefs{$hostskey}) eq 'ARRAY') {
1939: if (grep(/^\Q$home\E$/,@{$domdefs{$hostskey}})) {
1940: my %privhash = &Apache::lonnet::restore_dom($type,'private',$cdom,$home,1);
1941: my $privkey = $privhash{'key'};
1942: $privnum = $privhash{'version'};
1943: if (($privnum) && ($privkey ne '')) {
1944: $cipher = Crypt::CBC->new({'key' => $privkey,
1945: 'cipher' => 'DES'});
1946: }
1947: }
1948: }
1949: }
1950: }
1951: }
1952: return ($cipher,$privnum);
1953: }
1954:
1955: sub process_ltitools {
1956: my ($r,$cdom,$cnum,$values,$changes,$context,$lastactref,$configuserok,$lonhost,
1957: $author_ok,$confname) = @_;
1958: my (%currconfig,$newid,@allpos,%changes,%ltitools,$errors);
1959:
1960: my (%posslti,%possfield);
1961: my @courseroles = ('cc','in','ta','ep','st');
1962: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1963: map { $posslti{$_} = 1; } @ltiroles;
1964: my @allfields = ('fullname','firstname','lastname','email','user','roles');
1965: map { $possfield{$_} = 1; } @allfields;
1966:
1.120 raeburn 1967: my ($dest,$privnum,$cipher);
1.118 raeburn 1968:
1969: ($cipher,$privnum) = &get_credentials($cdom,$cnum,'ltitools',$context);
1970: if ($context eq 'domain') {
1971: $dest = '/adm/domainprefs';
1972: } else {
1973: $dest = '/adm/courseprefs';
1974: }
1975: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1976:
1977: my (@allpos,@items,%deletions,%itemids,%haschanges);
1978: if ($env{'form.ltitools_add'}) {
1979: my $title = $env{'form.ltitools_add_title'};
1980: $title =~ s/(`)/'/g;
1.125 raeburn 1981: my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title);
1.118 raeburn 1982: if ($newid) {
1983: my $position = $env{'form.ltitools_add_pos'};
1984: $position =~ s/\D+//g;
1985: if ($position ne '') {
1986: $allpos[$position] = $newid;
1987: }
1988: $haschanges{$newid} = 1;
1989: foreach my $item ('title','url','lifetime') {
1990: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1991: if ($item eq 'lifetime') {
1992: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
1993: }
1994: if ($env{'form.ltitools_add_'.$item}) {
1995: $ltitools{$newid}{$item} = $env{'form.ltitools_add_'.$item};
1996: }
1997: }
1998: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
1999: $ltitools{$newid}{'version'} = $env{'form.ltitools_add_version'};
2000: }
2001: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
2002: $ltitools{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
2003: }
2004: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
2005: $ltitools{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
2006: } else {
2007: $ltitools{$newid}{'sigmethod'} = 'HMAC-SHA1';
2008: }
2009: foreach my $item ('width','height','linktext','explanation') {
2010: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
2011: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
2012: if (($item eq 'width') || ($item eq 'height')) {
2013: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
2014: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
2015: }
2016: } else {
2017: if ($env{'form.ltitools_add_'.$item} ne '') {
2018: $ltitools{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
2019: }
2020: }
2021: }
2022: if ($env{'form.ltitools_add_target'} eq 'window') {
2023: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
2024: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
2025: $ltitools{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
2026: } else {
2027: $ltitools{$newid}{'display'}{'target'} = 'iframe';
2028: }
2029: foreach my $item ('passback','roster') {
2030: if ($env{'form.ltitools_'.$item.'_add'}) {
2031: $ltitools{$newid}{$item} = 1;
2032: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
2033: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
2034: $lifetime =~ s/^\s+|\s+$//g;
2035: if ($lifetime =~ /^\d+\.?\d*$/) {
2036: $ltitools{$newid}{$item.'valid'} = $lifetime;
2037: }
2038: }
2039: }
2040: }
2041: if ($env{'form.ltitools_add_image.filename'} ne '') {
2042: my ($imageurl,$error) =
2043: &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_add_image',
2044: $newid,$configuserok,$lonhost,$author_ok);
2045: if ($imageurl) {
2046: $ltitools{$newid}{'image'} = $imageurl;
2047: }
2048: if ($error) {
2049: &Apache::lonnet::logthis($error);
2050: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2051: }
2052: }
2053: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
2054: foreach my $field (@fields) {
2055: if ($possfield{$field}) {
2056: if ($field eq 'roles') {
2057: foreach my $role (@courseroles) {
2058: my $choice = $env{'form.ltitools_add_roles_'.$role};
2059: if (($choice ne '') && ($posslti{$choice})) {
2060: $ltitools{$newid}{'roles'}{$role} = $choice;
2061: if ($role eq 'cc') {
2062: $ltitools{$newid}{'roles'}{'co'} = $choice;
2063: }
2064: }
2065: }
2066: } else {
2067: $ltitools{$newid}{'fields'}{$field} = 1;
2068: }
2069: }
2070: }
2071: if (ref($ltitools{$newid}{'fields'}) eq 'HASH') {
2072: if ($ltitools{$newid}{'fields'}{'user'}) {
2073: if ($env{'form.ltitools_add_userincdom'}) {
2074: $ltitools{$newid}{'incdom'} = 1;
2075: }
2076: }
2077: }
2078: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_add_courseconfig');
2079: foreach my $item (@courseconfig) {
2080: $ltitools{$newid}{'crsconf'}{$item} = 1;
2081: }
2082: if ($env{'form.ltitools_add_custom'}) {
2083: my $name = $env{'form.ltitools_add_custom_name'};
2084: my $value = $env{'form.ltitools_add_custom_value'};
2085: $value =~ s/(`)/'/g;
2086: $name =~ s/(`)/'/g;
2087: $ltitools{$newid}{'custom'}{$name} = $value;
2088: }
2089: unless ($switchserver) {
2090: my $keyitem = 'form.ltitools_add_key';
2091: $env{$keyitem} =~ s/(`)/'/g;
2092: if ($env{$keyitem} ne '') {
2093: $ltitools{$newid}{'key'} = $env{$keyitem};
2094: }
1.119 raeburn 2095: my $secretitem = 'form.ltitools_secret_add';
1.118 raeburn 2096: $env{$secretitem} =~ s/(`)/'/g;
2097: if ($env{$secretitem} ne '') {
2098: if ($privnum && $cipher) {
2099: $ltitools{$newid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2100: $ltitools{$newid}{'cipher'} = $privnum;
2101: } else {
2102: $ltitools{$newid}{'secret'} = $env{$secretitem};
2103: }
2104: }
2105: }
2106: } else {
2107: $errors .= '<li><span class="LC_error">'.
2108: &mt('Failed to acquire unique ID for new external tool').
2109: '</span></li>';
2110: }
2111: }
2112: if (ref($values) eq 'HASH') {
2113: my %deletions;
2114: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
2115: if (@todelete) {
2116: map { $deletions{$_} = 1; } @todelete;
2117: }
2118: my %customadds;
2119: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
2120: if (@newcustom) {
2121: map { $customadds{$_} = 1; } @newcustom;
2122: }
2123: my %imgdeletions;
2124: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
2125: if (@todeleteimages) {
2126: map { $imgdeletions{$_} = 1; } @todeleteimages;
2127: }
2128: my $maxnum = $env{'form.ltitools_maxnum'};
2129: for (my $i=0; $i<=$maxnum; $i++) {
2130: my $itemid = $env{'form.ltitools_id_'.$i};
2131: $itemid =~ s/\D+//g;
2132: if (ref($values->{$itemid}) eq 'HASH') {
2133: if ($deletions{$itemid}) {
2134: if ($values->{$itemid}{'image'}) {
2135: #FIXME need to obsolete item in RES space
2136: }
2137: $haschanges{$itemid} = $values->{$itemid}{'title'};
2138: next;
2139: } else {
2140: my $newpos = $env{'form.ltitools_'.$itemid};
2141: $newpos =~ s/\D+//g;
2142: foreach my $item ('title','url','lifetime') {
2143: $ltitools{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2144: if ($values->{$itemid}{$item} ne $ltitools{$itemid}{$item}) {
2145: $haschanges{$itemid} = 1;
2146: }
2147: }
2148: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
2149: $ltitools{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
2150: }
2151: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
2152: $ltitools{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
2153: }
2154: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
2155: $ltitools{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
2156: } else {
2157: $ltitools{$itemid}{'sigmethod'} = 'HMAC-SHA1';
2158: }
2159: if ($values->{$itemid}{'sigmethod'} eq '') {
2160: if ($ltitools{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
2161: $haschanges{$itemid} = 1;
2162: }
2163: } elsif ($values->{$itemid}{'sigmethod'} ne $ltitools{$itemid}{'sigmethod'}) {
2164: $haschanges{$itemid} = 1;
2165: }
2166: foreach my $size ('width','height') {
2167: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
2168: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
2169: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
2170: $ltitools{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
2171: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2172: if ($values->{$itemid}{'display'}{$size} ne $ltitools{$itemid}{'display'}{$size}) {
2173: $haschanges{$itemid} = 1;
2174: }
2175: } else {
2176: $haschanges{$itemid} = 1;
2177: }
2178: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2179: if ($values->{$itemid}{'display'}{$size} ne '') {
2180: $haschanges{$itemid} = 1;
2181: }
2182: }
2183: }
2184: foreach my $item ('linktext','explanation') {
2185: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
2186: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
2187: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
2188: $ltitools{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
2189: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2190: if ($values->{$itemid}{'display'}{$item} ne $ltitools{$itemid}{'display'}{$item}) {
2191: $haschanges{$itemid} = 1;
2192: }
2193: } else {
2194: $haschanges{$itemid} = 1;
2195: }
2196: } elsif (ref($values->{$itemid}{'display'}) eq 'HASH') {
2197: if ($values->{$itemid}{'display'}{$item} ne '') {
2198: $haschanges{$itemid} = 1;
2199: }
2200: }
2201: }
2202: if ($env{'form.ltitools_target_'.$i} eq 'window') {
2203: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2204: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
2205: $ltitools{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
2206: } else {
2207: $ltitools{$itemid}{'display'}{'target'} = 'iframe';
2208: }
2209: if (ref($values->{$itemid}{'display'}) eq 'HASH') {
2210: if ($values->{$itemid}{'display'}{'target'} ne $ltitools{$itemid}{'display'}{'target'}) {
2211: $haschanges{$itemid} = 1;
2212: }
2213: } else {
2214: $haschanges{$itemid} = 1;
2215: }
2216: foreach my $extra ('passback','roster') {
2217: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
2218: $ltitools{$itemid}{$extra} = 1;
2219: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
2220: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
2221: $lifetime =~ s/^\s+|\s+$//g;
2222: if ($lifetime =~ /^\d+\.?\d*$/) {
2223: $ltitools{$itemid}{$extra.'valid'} = $lifetime;
2224: }
2225: }
2226: }
2227: if ($values->{$itemid}{$extra} ne $ltitools{$itemid}{$extra}) {
2228: $haschanges{$itemid} = 1;
2229: }
2230: if ($values->{$itemid}{$extra.'valid'} ne $ltitools{$itemid}{$extra.'valid'}) {
2231: $haschanges{$itemid} = 1;
2232: }
2233: }
2234: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
2235: foreach my $item ('label','title','target','linktext','explanation','append') {
2236: if (grep(/^\Q$item\E$/,@courseconfig)) {
2237: $ltitools{$itemid}{'crsconf'}{$item} = 1;
2238: if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') {
2239: if ($values->{$itemid}{'crsconf'}{$item} ne $ltitools{$itemid}{'crsconf'}{$item}) {
2240: $haschanges{$itemid} = 1;
2241: }
2242: } else {
2243: $haschanges{$itemid} = 1;
2244: }
2245: }
2246: }
2247: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
2248: foreach my $field (@fields) {
2249: if ($possfield{$field}) {
2250: if ($field eq 'roles') {
2251: foreach my $role (@courseroles) {
2252: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
2253: if (($choice ne '') && ($posslti{$choice})) {
2254: $ltitools{$itemid}{'roles'}{$role} = $choice;
2255: if ($role eq 'cc') {
2256: $ltitools{$itemid}{'roles'}{'co'} = $choice;
2257: }
2258: }
2259: if (ref($values->{$itemid}{'roles'}) eq 'HASH') {
2260: if ($values->{$itemid}{'roles'}{$role} ne $ltitools{$itemid}{'roles'}{$role}) {
2261: $haschanges{$itemid} = 1;
2262: }
2263: } elsif ($ltitools{$itemid}{'roles'}{$role}) {
2264: $haschanges{$itemid} = 1;
2265: }
2266: }
2267: } else {
2268: $ltitools{$itemid}{'fields'}{$field} = 1;
2269: if (ref($values->{$itemid}{'fields'}) eq 'HASH') {
2270: if ($values->{$itemid}{'fields'}{$field} ne $ltitools{$itemid}{'fields'}{$field}) {
2271: $haschanges{$itemid} = 1;
2272: }
2273: } else {
2274: $haschanges{$itemid} = 1;
2275: }
2276: }
2277: }
2278: }
2279: if (ref($ltitools{$itemid}{'fields'}) eq 'HASH') {
2280: if ($ltitools{$itemid}{'fields'}{'user'}) {
2281: if ($env{'form.ltitools_userincdom_'.$i}) {
2282: $ltitools{$itemid}{'incdom'} = 1;
2283: }
2284: if ($values->{$itemid}{'incdom'} ne $ltitools{$itemid}{'incdom'}) {
2285: $haschanges{$itemid} = 1;
2286: }
2287: }
2288: }
2289: $allpos[$newpos] = $itemid;
2290: }
2291: if ($imgdeletions{$itemid}) {
2292: $haschanges{$itemid} = 1;
2293: if ($context eq 'course') {
2294: my $currimgurl = $values->{$itemid}{'image'};
2295: if ($currimgurl =~ m{^(\Q/uploaded/$cdom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2296: my ($path,$imagefile) = ($1,$2);
2297: if ($imagefile =~ /^tn\-(.+)$/) {
2298: my $origimg = $1;
2299: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2300: }
2301: &Apache::lonnet::removeuploadedurl($currimgurl);
2302: }
2303: }
2304: #FIXME need to obsolete item in RES space
2305: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
2306: my $currimgurl = $values->{$itemid}{'image'};
2307: my ($imgurl,$error) = &process_ltitools_image($r,$context,$cdom,$cnum,$confname,'ltitools_image_'.$i,
2308: $itemid,$configuserok,$lonhost,$author_ok,$currimgurl);
2309: if ($imgurl) {
2310: $ltitools{$itemid}{'image'} = $imgurl;
2311: $haschanges{$itemid} = 1;
2312: }
2313: if ($error) {
2314: &Apache::lonnet::logthis($error);
2315: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
2316: }
2317: } elsif ($values->{$itemid}{'image'}) {
2318: $ltitools{$itemid}{'image'} = $values->{$itemid}{'image'};
2319: }
2320: if ($customadds{$i}) {
2321: my $name = $env{'form.ltitools_custom_name_'.$i};
2322: $name =~ s/(`)/'/g;
2323: $name =~ s/^\s+//;
2324: $name =~ s/\s+$//;
2325: my $value = $env{'form.ltitools_custom_value_'.$i};
2326: $value =~ s/(`)/'/g;
2327: $value =~ s/^\s+//;
2328: $value =~ s/\s+$//;
2329: if ($name ne '') {
2330: $ltitools{$itemid}{'custom'}{$name} = $value;
2331: $haschanges{$itemid} = 1;
2332: }
2333: }
2334: my %customdels;
2335: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
2336: if (@customdeletions) {
2337: $haschanges{$itemid} = 1;
2338: }
2339: map { $customdels{$_} = 1; } @customdeletions;
2340: if (ref($values->{$itemid}{'custom'}) eq 'HASH') {
2341: foreach my $key (keys(%{$values->{$itemid}{'custom'}})) {
2342: unless ($customdels{$key}) {
2343: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
2344: $ltitools{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
2345: }
2346: if ($values->{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
2347: $haschanges{$itemid} = 1;
2348: }
2349: }
2350: }
2351: }
2352: unless ($switchserver) {
2353: my $keyitem = 'form.ltitools_key_'.$i;
2354: $env{$keyitem} =~ s/(`)/'/g;
2355: if ($values->{$itemid}{'key'} ne $env{$keyitem}) {
2356: $haschanges{$itemid} = 1;
2357: }
2358: if ($env{$keyitem} ne '') {
2359: $ltitools{$itemid}{'key'} = $env{$keyitem};
2360: }
2361: my $secretitem = 'form.ltitools_secret_'.$i;
2362: $env{$secretitem} =~ s/(`)/'/g;
2363: if ($values->{$itemid}{'usable'}) {
2364: if ($env{'form.ltitools_changesecret_'.$i}) {
2365: if ($env{$secretitem} ne '') {
2366: if ($privnum && $cipher) {
2367: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2368: $ltitools{$itemid}{'cipher'} = $privnum;
2369: } else {
2370: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2371: }
2372: $haschanges{$itemid} = 1;
2373: }
2374: } else {
2375: $ltitools{$itemid}{'secret'} = $values->{$itemid}{'secret'};
2376: $ltitools{$itemid}{'cipher'} = $values->{$itemid}{'cipher'};
2377: }
2378: } elsif ($env{$secretitem} ne '') {
2379: if ($privnum && $cipher) {
2380: $ltitools{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
2381: $ltitools{$itemid}{'cipher'} = $privnum;
2382: } else {
2383: $ltitools{$itemid}{'secret'} = $env{$secretitem};
2384: }
2385: $haschanges{$itemid} = 1;
2386: }
2387: }
2388: unless ($haschanges{$itemid}) {
2389: foreach my $key (keys(%{$values->{$itemid}})) {
2390: if (ref($values->{$itemid}{$key}) eq 'HASH') {
2391: if (ref($ltitools{$itemid}{$key}) eq 'HASH') {
2392: foreach my $innerkey (keys(%{$values->{$itemid}{$key}})) {
2393: unless (exists($ltitools{$itemid}{$key}{$innerkey})) {
2394: $haschanges{$itemid} = 1;
2395: last;
2396: }
2397: }
2398: } elsif (keys(%{$values->{$itemid}{$key}}) > 0) {
2399: $haschanges{$itemid} = 1;
2400: }
2401: }
2402: last if ($haschanges{$itemid});
2403: }
2404: }
2405: }
2406: }
2407: }
2408: if (@allpos > 0) {
2409: my $idx = 0;
2410: foreach my $itemid (@allpos) {
2411: if ($itemid ne '') {
2412: $ltitools{$itemid}{'order'} = $idx;
2413: if (ref($values) eq 'HASH') {
2414: if (ref($values->{$itemid}) eq 'HASH') {
2415: if ($values->{$itemid}{'order'} ne $idx) {
2416: $haschanges{$itemid} = 1;
2417: }
2418: }
2419: }
2420: $idx ++;
2421: }
2422: }
2423: }
2424: if (keys(%haschanges)) {
2425: foreach my $entry (keys(%haschanges)) {
2426: $changes->{$entry} = $ltitools{$entry};
2427: }
2428: if (ref($lastactref) eq 'HASH') {
2429: $lastactref->{'courseltitools'} = 1;
2430: }
2431: }
2432: return $errors;
2433: }
2434:
2435: sub process_ltitools_image {
2436: my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_;
2437: my $filename = $env{'form.'.$caller.'.filename'};
2438: my ($error,$url);
2439: my ($width,$height) = (21,21);
2440: if ($configuserok eq 'ok') {
2441: if ($switch) {
2442: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
2443: $switch);
2444: } elsif ($author_ok eq 'ok') {
2445: my ($result,$imageurl,$madethumb);
2446: if ($context eq 'domain') {
2447: ($result,$imageurl,$madethumb) =
2448: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
2449: "ltitools/$itemid/icon",$width,$height);
2450: } else {
2451: ($result,$imageurl,$madethumb) = &processlogo($dom,$cnum,$caller,$currimg,$itemid,$width,$height);
2452: }
2453: if ($result eq 'ok') {
2454: if ($madethumb) {
2455: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
2456: my $imagethumb = "$path/tn-".$imagefile;
2457: $url = $imagethumb;
2458: } else {
2459: $url = $imageurl;
2460: }
2461: } else {
2462: if ($context eq 'domain') {
2463: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
2464: } else {
2465: $error = &mt("Upload of [_1] failed because an error occurred. Error was: [_2].",$filename,$result);
2466: }
2467: }
2468: } else {
2469: $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);
2470: }
2471: } else {
2472: $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);
2473: }
2474: return ($url,$error);
2475: }
2476:
2477: sub processlogo {
2478: my ($dom,$cnum,$caller,$currimg,$itemid,$width,$height) = @_;
2479: my ($result,$imageurl,$madethumb);
2480: if ($env{"form.$caller.filename"} ne '') {
2481: unless ($caller eq 'ltitools_add_image') {
2482: if ($currimg =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2483: my ($path,$imagefile) = ($1,$2);
2484: if ($imagefile =~ /^tn\-(.+)$/) {
2485: my $origimg = $1;
2486: &Apache::lonnet::removeuploadedurl("$path/$origimg");
2487: }
2488: &Apache::lonnet::removeuploadedurl($currimg);
2489: }
2490: }
2491: $imageurl = &Apache::lonnet::userfileupload($caller,'toollogo',"toollogo/$itemid",
2492: '','','',$cnum,$dom,$width,$height);
2493: if ($imageurl =~ m{^(\Q/uploaded/$dom/$cnum/toollogo/$itemid\E)/([^/]+)$}) {
2494: my ($path,$imagefile) = ($1,$2);
2495: $result = 'ok';
2496: my $thumburl = "$path/tn-".$imagefile;
2497: my ($rtncode,$info);
2498: my $res = &Apache::lonnet::getuploaded('HEAD',$thumburl,$dom,$cnum,\$info,\$rtncode);
2499: if ($res eq 'ok') {
2500: $madethumb = 1;
2501: }
2502: } elsif ($imageurl eq '/adm/notfound.html') {
2503: undef($imageurl);
2504: $result = 'store failed';
2505: } elsif ($imageurl =~ /^error: (.+)$/) {
2506: $result = $1;
2507: }
2508: }
2509: return ($result,$imageurl,$madethumb);
2510: }
2511:
1.3 raeburn 2512: sub get_sec_str {
2513: my ($entry,$num) = @_;
2514: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
2515: my $secstr;
2516: if (grep(/^\s*$/,@secs)) {
2517: $secstr = '';
2518: } elsif (@secs > 0) {
2519: $secstr = join(';',@secs);
2520: }
2521: if ($secstr ne '') {
2522: return '('.$secstr.')';
2523: }
2524: return;
2525: }
2526:
2527: sub check_clone {
2528: my ($clonedom,$disallowed,$clonename) = @_;
2529: return if (ref($disallowed) ne 'HASH');
2530: if ($clonedom !~ /^$match_domain$/) {
2531: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
2532: return;
2533: } elsif (!&Apache::lonnet::domain($clonedom)) {
2534: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
2535: return;
2536: }
2537: if ($clonename ne '') {
2538: if ($clonename !~ /^$match_username$/) {
2539: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
2540: return;
2541: } else {
2542: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
2543: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
2544: return;
2545: }
2546: }
2547: }
2548: return 'ok';
2549: }
2550:
2551: sub store_changes {
1.9 raeburn 2552: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 2553: my ($chome,$output);
1.118 raeburn 2554: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot,%oldltitools);
1.3 raeburn 2555: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 2556: if (ref($values->{'linkprot'}) eq 'HASH') {
2557: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 2558: }
1.102 raeburn 2559: delete($values->{'linkprot'});
1.118 raeburn 2560: if (ref($values->{'ltitools'}) eq 'HASH') {
2561: %oldltitools = %{$values->{'ltitools'}};
2562: }
1.3 raeburn 2563: %storehash = %{$values};
2564: } else {
1.9 raeburn 2565: if ($crstype eq 'Community') {
2566: $output = &mt('No changes made to community settings.');
2567: } else {
2568: $output = &mt('No changes made to course settings.');
2569: }
2570: return $output;
1.3 raeburn 2571: }
1.93 raeburn 2572: my ($numchanges,$skipstore);
2573: if (ref($changes) eq 'HASH') {
2574: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 2575: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 2576: $skipstore = 1;
1.118 raeburn 2577: } elsif (($numchanges == 1) && (exists($changes->{'ltitools'}))) {
2578: $skipstore = 1;
1.93 raeburn 2579: } elsif (!$numchanges) {
2580: if ($crstype eq 'Community') {
2581: $output = &mt('No changes made to community settings.');
2582: } else {
2583: $output = &mt('No changes made to course settings.');
2584: }
2585: return $output;
2586: }
2587: }
1.3 raeburn 2588: my %yesno = (
2589: hidefromcat => '1',
2590: problem_stream_switch => '1',
2591: suppress_tries => '1',
2592: disableexampointprint => '1',
2593: hideemptyrows => '1',
2594: suppress_embed_prompt => '1',
2595: );
2596: foreach my $item (@{$prefs_order}) {
2597: if (grep(/^\Q$item\E$/,@{$actions})) {
2598: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
2599: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 2600: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 2601: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 2602: if ($item eq 'other') {
2603: foreach my $key (sort(keys(%{$changes->{$item}}))) {
2604: $storehash{$key} = $changes->{$item}{$key};
2605: if ($changes->{$item}{$key} eq '') {
2606: push(@delkeys,$key);
1.22 wenzelju 2607: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 2608: } else {
1.22 wenzelju 2609: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
2610: "'$storehash{$key}'")).'</li>';
1.3 raeburn 2611: }
2612: }
1.102 raeburn 2613: } elsif ($item eq 'linkprot') {
2614: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.118 raeburn 2615: } elsif ($item eq 'ltitools') {
2616: $output .= &store_ltitools($cdom,$cnum,'course',$changes->{$item},\%oldltitools);
1.3 raeburn 2617: } else {
2618: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
2619: my @settings = @{$prefs->{$item}->{'ordered'}};
2620: if ($item eq 'feedback') {
2621: push(@settings,(map { $_.'.text'; } @settings));
2622: }
2623: foreach my $key (@settings) {
2624: if ($key eq 'rolenames') {
2625: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
2626: my $msg;
1.9 raeburn 2627: my @roles;
2628: if ($crstype eq 'Community') {
2629: @roles = ('co');
2630: } else {
2631: @roles = ('cc');
2632: }
2633: push(@roles,('in','ta','ep','ad','st'));
2634: foreach my $role (@roles) {
1.3 raeburn 2635: next if (!exists($changes->{$item}{$key.'_'.$role}));
2636: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
2637: my $newname = $changes->{$item}{$key.'_'.$role};
2638: $storehash{$role.'.plaintext'} = $newname;
2639: if ($newname eq '') {
2640: $newname = $stdname;
2641: }
2642: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
2643: "'<b>".$newname."</b>'").'</li>';
2644: }
2645: if ($msg ne '') {
1.22 wenzelju 2646: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 2647: }
1.115 raeburn 2648: } elsif ($key eq 'timezone') {
2649: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
2650: my ($displayname,$text);
2651: $text = $prefs->{$item}->{'itemtext'}{$key};
2652: my $displayval;
2653: if (exists($changes->{$item}{$key})) {
2654: $displayname = &mt($text);
2655: $storehash{$key} = $changes->{$item}{$key};
2656: if ($changes->{$item}{$key} ne '') {
2657: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
2658: } else {
2659: push(@delkeys,$key);
2660: if (exists($values->{'tzover'})) {
2661: push(@delkeys,'tzover');
2662: }
2663: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2664: '<i>'.$displayname.'</i>')).'</li>';
2665: }
2666: }
2667: unless (grep(/^\Q$key\E$/,@delkeys)) {
2668: if (exists($changes->{$item}{'tzover'})) {
2669: $storehash{'tzover'} = $changes->{$item}{'tzover'};
2670: my $tzovertext;
2671: if ($changes->{$item}{'tzover'} ne '') {
2672: $tzovertext = &mt('Course Time Zone overrides individual user preference');
2673: } else {
2674: push(@delkeys,'tzover');
2675: $tzovertext = &mt('Course Time Zone does not override individual user preference');
2676: }
2677: if ($displayval eq '') {
2678: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
2679: } else {
2680: $displayval .= '<br />'.(' 'x5).$tzovertext;
2681: }
2682: }
2683: if ($displayval ne '') {
2684: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2685: '<i>'.$displayname.'</i>',$displayval)).'</li>';
2686: }
2687: }
1.3 raeburn 2688: } else {
2689: next if (!exists($changes->{$item}{$key}));
2690: my ($displayname,$text);
2691: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 2692: my $displayval;
1.114 raeburn 2693: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 2694: $displayval = $changes->{$item}{$key};
2695: }
1.127 raeburn 2696: if (($item eq 'grading') && ($key eq 'grading')) {
2697: if ($displayval eq 'standard') {
2698: my $hidetotals;
2699: if (exists($changes->{$item}{'hidetotals'})) {
2700: if ($changes->{$item}{'hidetotals'} eq '') {
2701: if (exists($values->{'hidetotals'})) {
2702: push(@delkeys,'hidetotals');
2703: }
2704: } else {
2705: $hidetotals = $changes->{$item}{'hidetotals'};
2706: }
2707: } elsif (exists($values->{'hidetotals'})) {
2708: $hidetotals = $values->{'hidetotals'};
2709: }
2710: if ($hidetotals eq '') {
2711: $displayval = &mt('standard with "hide course totals" set to "No"');
2712: if (exists($values->{'hidetotals'})) {
2713: push(@delkeys,'hidetotals');
2714: }
2715: } elsif ($hidetotals =~ /^([\w,]+)$/) {
2716: my $secstr = $1;
2717: my @secs = split(/,/,$secstr);
2718: if (grep(/^all$/,@secs)) {
2719: $displayval = &mt('standard with "hide course totals" set to "Yes" for all users');
2720: $hidetotals = 'all';
2721: } else {
2722: $displayval = &mt('standard with "hide course totals" set to "Yes" for users in section(s): [_1]',join(', ',@secs));
2723: }
2724: $storehash{'hidetotals'} = $hidetotals;
2725: }
2726: } elsif (exists($values->{'hidetotals'})) {
2727: push(@delkeys,'hidetotals');
2728: }
2729: }
1.3 raeburn 2730: if ($item eq 'feedback') {
2731: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
2732: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
2733: $displayname = &mt('Custom text for '.$text.' questions');
2734: } else {
2735: $displayname = &mt('Recipients of '.$text.' questions');
2736: }
2737: } elsif ($item eq 'discussion') {
2738: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2739: $displayname = &mt("$text (role-based)");
2740: if ($displayval ne '') {
2741: my @roles = split(',',$displayval);
2742: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2743: $displayval = join(', ',@roles);
2744: }
2745: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2746: $displayname = &mt("$text (specific user(s))");
2747: } else {
2748: if ($key eq 'allow_discussion_post_editing') {
2749: if ($displayval ne '') {
2750: my @roles = split(',',$displayval);
2751: my @longroles;
2752: foreach my $role (@roles) {
2753: my ($trole,$sec) = split(':',$role);
2754: my $rolename =
2755: &Apache::lonnet::plaintext($trole);
2756: if ($sec ne '') {
2757: $rolename .= ':'.$sec;
2758: }
2759: push(@longroles,$rolename);
2760: }
2761: $displayval = join(', ',@longroles);
2762: }
1.50 raeburn 2763: } elsif ($key eq 'discussion_post_fonts') {
2764: my ($classorder,$classtitles)=&discussion_vote_classes();
2765: my ($styleorder,$styleitems)=&discussion_vote_styles();
2766: my $count = 1;
2767: my $total = scalar(keys(%{$changes->{$item}}));
2768: foreach my $class (@{$classorder}) {
2769: $count ++;
2770: next unless ($changes->{$item}{$key.'_'.$class});
2771: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2772: my $showval = '';
2773: for (my $i=0; $i<@{$styleorder}; $i++) {
2774: if ($vals[$i] ne '') {
2775: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2776: }
2777: }
2778: if ($vals[3] ne '') {
2779: $showval .= $vals[3];
2780: }
2781: if ($showval ne '') {
2782: $displayval .= $classtitles->{$class}.':{ '.
2783: $showval.'}';
2784: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2785: } else {
2786: $displayval .= $classtitles->{$class}.': '.&mt('None');
2787: push(@delkeys,$key.'_'.$class);
2788: }
2789: unless ($count == $total) {
2790: $displayval .= (' 'x2);
2791: }
2792: }
1.3 raeburn 2793: }
2794: $displayname = &mt($text);
2795: }
2796: } elsif ($item eq 'spreadsheet') {
2797: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2798: my $sheettype = $1;
2799: if ($sheettype eq 'studentcalc') {
2800: &Apache::lonnet::expirespread('','','studentcalc');
2801: } else {
2802: &Apache::lonnet::expirespread('','','assesscalc');
2803: &Apache::lonnet::expirespread('','','studentcalc');
2804: }
2805: }
2806: $displayname = &mt($text);
1.87 raeburn 2807: } elsif ($item eq 'lti') {
2808: if ($key eq 'lti.lcmenu') {
2809: if ($changes->{$item}{$key} eq 'none') {
2810: $displayval = &mt('None of the configurable menu items displayed');
2811: } else {
2812: my %ltititles = <imenu_titles();
2813: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2814: }
2815: } else {
2816: if ($changes->{$item}{$key} eq '1') {
2817: $displayval = &mt('Yes');
2818: } elsif ($changes->{$item}{$key} eq '') {
2819: $displayval = &mt('No');
2820: }
2821: }
2822: $displayname = &mt($text);
1.91 raeburn 2823: } elsif ($item eq 'menuitems') {
2824: unless ($changes->{$item}{$key} eq '') {
2825: if ($key eq 'menudefault') {
2826: $displayname = &mt('Default collection of menu items');
2827: $displayval = &mt('Collection: [_1]',
2828: $changes->{$item}{$key});
2829: } elsif ($key eq 'menucollections') {
2830: $displayval = &menucollections_display($changes->{$item}{$key});
2831: }
2832: }
1.3 raeburn 2833: } else {
2834: $displayname = &mt($text);
2835: }
2836: if (defined($yesno{$key})) {
1.14 raeburn 2837: $displayval = &mt('No');
1.3 raeburn 2838: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2839: $displayval = &mt('Yes');
1.3 raeburn 2840: }
2841: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2842: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2843: } elsif ($key eq 'categories') {
2844: $displayval = $env{'form.categories_display'};
1.95 raeburn 2845: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2846: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2847: if ($changes->{$item}{$key} eq '1') {
2848: $displayval = &mt('Yes');
2849: } elsif ($changes->{$item}{$key} eq '0') {
2850: $displayval = &mt('No');
2851: }
1.114 raeburn 2852: } elsif ($key eq 'extresource') {
2853: if ($changes->{$item}{$key} eq 'iframe') {
2854: $displayval = &mt('In iframe');
2855: } else {
2856: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2857: if ($selected eq 'tab') {
2858: if ($reuse) {
2859: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2860: "'<b>","</b>'",'<br />');
2861: } else {
2862: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2863: "'<b>","</b>'",'<br />');
2864: }
2865: } elsif ($selected eq 'window') {
2866: if ($reuse) {
2867: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2868: "'<b>","</b>'",'<br />');
2869: } else {
2870: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2871: "'<b>","</b>'",'<br />');
2872: }
2873: if (($width ne '') || ($height ne '')) {
2874: if ($width ne '') {
2875: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2876: }
2877: if ($height ne '') {
2878: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2879: }
2880: }
2881: }
2882: }
1.14 raeburn 2883: }
1.25 raeburn 2884: if ($key eq 'co-owners') {
2885: if (ref($changes->{$item}{$key}) eq 'HASH') {
2886: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2887: foreach my $type ('co-owners','pendingco-owners') {
2888: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2889: if ($type eq 'pendingco-owners') {
2890: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2891: $displayname = &mt('Invited as co-owners, pending acceptance');
2892: }
2893: }
2894: if ($changes->{$item}{$key}{$type} eq '') {
2895: push(@delkeys,'internal.'.$type);
2896: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2897: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2898: '<i>'.$displayname.'</i>')).'</li>';
2899: }
2900: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2901: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2902: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2903: '<i>'.$displayname.'</i>',
2904: "'<b>$displayval</b>'")).'</li>';
2905: }
2906: }
2907: }
2908: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2909: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2910: $displayval = &mt('on');
1.90 raeburn 2911: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2912: $displayval = '';
2913: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2914: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2915: $displayval = &mt('off');
2916: }
2917: if ($displayval) {
2918: $displayname = &mt('Your co-ownership status');
2919: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2920: '<i>'.$displayname.'</i>',
2921: "'<b>$displayval</b>'")).'</li>';
2922: }
2923: }
2924: }
2925: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2926: push(@delkeys,$key);
1.87 raeburn 2927: if ($item eq 'lti') {
2928: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2929: if (($key eq 'lti.lcmenu') &&
2930: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2931: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2932: } else {
2933: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2934: '<i>'.$displayname.'</i>',
2935: "'<b>$displayval</b>'")).'</li>';
2936: }
2937: } elsif (!exists($changes->{$item}{'lti.override'})) {
2938: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2939: }
1.91 raeburn 2940: } elsif ($item eq 'menuitems') {
2941: if ($key eq 'menudefault') {
2942: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2943: } elsif ($key eq 'menucollections') {
2944: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2945: }
1.87 raeburn 2946: } else {
2947: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2948: '<i>'.$displayname.'</i>')).'</li>';
2949: }
1.91 raeburn 2950: } elsif ($key eq 'menucollections') {
2951: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2952: $displayval.'</li>';
1.3 raeburn 2953: } else {
1.114 raeburn 2954: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2955: $displayval = "'<b>$displayval</b>'";
2956: }
1.22 wenzelju 2957: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2958: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2959: if ($key eq 'url') {
2960: my $bkuptime=time;
2961: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2962: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2963: }
2964: $output .= '</li>';
2965: }
1.25 raeburn 2966: if ($key eq 'co-owners') {
2967: if (ref($changes->{$item}{$key}) eq 'HASH') {
2968: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2969: foreach my $type ('co-owners','pendingco-owners') {
2970: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2971: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2972: }
2973: }
2974: }
2975: } else {
1.50 raeburn 2976: unless ($key eq 'discussion_post_fonts') {
2977: $storehash{$key} = $changes->{$item}{$key};
2978: }
1.25 raeburn 2979: }
1.3 raeburn 2980: }
1.23 raeburn 2981: if ($key eq 'cloners') {
2982: # Get existing cloners
2983: my %clonenames =
2984: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2985: if ($clonenames{'cloners'} =~ /,/) {
2986: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2987: } else {
2988: $oldcloner[0] = $clonenames{'cloners'};
2989: }
2990: }
1.3 raeburn 2991: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2992: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2993: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2994: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2995: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2996: push(@need_env_update,$key);
2997: }
2998: }
2999: }
3000: }
3001: $output .= '</ul>';
3002: } else {
1.9 raeburn 3003: if ($crstype eq 'Community') {
1.46 raeburn 3004: $output .= &mt('No changes made to community settings.');
1.9 raeburn 3005: } else {
1.46 raeburn 3006: $output .= &mt('No changes made to course settings.');
1.9 raeburn 3007: }
1.3 raeburn 3008: }
3009: }
3010: }
3011: }
1.93 raeburn 3012: if ($skipstore) {
3013: return $output;
3014: }
1.3 raeburn 3015: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 3016: if (ref($changes) eq 'HASH') {
3017: if (ref($changes->{'courseinfo'}) eq 'HASH') {
3018: if (exists($changes->{'courseinfo'}{'cloners'})) {
3019: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
3020: \@oldcloner);
3021: }
3022: }
3023: }
1.3 raeburn 3024: if (@delkeys) {
3025: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 3026: $output .= '<br /><span class="LC_error">';
3027: if ($crstype eq 'Community') {
3028: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
3029: } else {
3030: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
3031: }
3032: $output .= '</span>';
1.14 raeburn 3033: } else {
3034: foreach my $key (@delkeys) {
3035: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
3036: }
1.3 raeburn 3037: }
3038: }
3039: if (@need_env_update) {
3040: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
3041: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
3042: }
3043: &Apache::lonnet::coursedescription($env{'request.course.id'},
3044: {'freshen_cache' => 1});
3045: } else {
1.9 raeburn 3046: $output = '<span class="LC_error">';
3047: if ($crstype eq 'Community') {
3048: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
3049: } else {
3050: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
3051: }
3052: $output .= '</span>';
1.3 raeburn 3053: }
3054: return $output;
3055: }
3056:
1.102 raeburn 3057: sub store_linkprot {
3058: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 3059: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 3060: if ($context eq 'domain') {
3061: $ltiauth = 1;
1.103 raeburn 3062: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 3063: } else {
1.103 raeburn 3064: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 3065: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
3066: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
3067: } else {
3068: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
3069: $ltiauth = $domdefs{'crsltiauth'};
3070: }
3071: }
3072: if (ref($changes) eq 'HASH') {
3073: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3074: if (ref($changes->{$id}) eq 'HASH') {
3075: if (exists($changes->{$id}->{'key'})) {
3076: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
3077: delete($changes->{$id}->{'key'});
3078: }
3079: if (exists($changes->{$id}->{'secret'})) {
3080: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
3081: delete($changes->{$id}->{'secret'});
3082: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3083: if (exists($oldlinkprot->{$id}{'usable'})) {
3084: $changes->{$id}->{'usable'} = 1;
3085: }
1.109 raeburn 3086: if (exists($oldlinkprot->{$id}{'cipher'})) {
3087: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
3088: }
1.102 raeburn 3089: }
3090: }
3091: }
3092: }
3093: my @ids=&Apache::lonnet::current_machine_ids();
3094: if (keys(%ltienc) > 0) {
3095: if ($context eq 'domain') {
3096: foreach my $id (keys(%ltienc)) {
3097: if (exists($ltienc{$id}{'secret'})) {
3098: $changes->{$id}->{'usable'} = 1;
3099: }
3100: }
3101: } else {
1.103 raeburn 3102: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 3103: my $allowed;
3104: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3105: if ($allowed) {
3106: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
3107: foreach my $id (keys(%ltienc)) {
3108: if (exists($ltienc{$id}{'secret'})) {
3109: $changes->{$id}->{'usable'} = 1;
3110: }
3111: }
3112: } else {
3113: $lti_save_error = 1;
3114: }
3115: }
3116: }
3117: }
3118: }
3119: unless ($lti_save_error) {
3120: if ($context eq 'course') {
3121: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
3122: my $hashid=$cdom.'_'.$cnum;
3123: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 3124: unless (($home eq 'no_host') || ($home eq '')) {
3125: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 3126: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
3127: }
3128: }
3129: } else {
3130: $lti_save_error = 1;
3131: }
3132: }
3133: unless ($lti_save_error) {
3134: foreach my $id (sort { $a <=> $b } %{$changes}) {
3135: if (ref($changes->{$id}) eq 'HASH') {
3136: my %values = %{$changes->{$id}};
3137: my %desc = &linkprot_names();
3138: my $display;
1.122 raeburn 3139: foreach my $title ('name','lifetime','version','key','secret','returnurl','passbackformat') {
1.102 raeburn 3140: if (($title eq 'key') || ($title eq 'secret')) {
3141: if (ref($ltienc{$id}) eq 'HASH') {
3142: if (exists($ltienc{$id}{$title})) {
3143: if ($title eq 'secret') {
3144: my $length = length($ltienc{$id}{$title});
1.103 raeburn 3145: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 3146: } else {
3147: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
3148: }
3149: }
3150: }
3151: } elsif ($title eq 'version') {
3152: if ($values{$title} eq 'LTI-1p0') {
3153: $display .= $desc{$title}.': 1.1, ';
3154: }
1.112 raeburn 3155: } elsif ($title eq 'returnurl') {
3156: if ($values{$title}) {
1.124 raeburn 3157: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
1.112 raeburn 3158: }
1.122 raeburn 3159: } elsif ($title eq 'passbackformat') {
3160: if ($values{$title} eq '1.0') {
3161: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.0 format').', ';
3162: } elsif ($values{$title} eq '1.1') {
3163: $display .= &mt('Can return grades to Launcher with Outcomes Service 1.1 format').', ';
3164: }
1.102 raeburn 3165: } else {
3166: $display .= $desc{$title}.': '.$values{$title}.', ';
3167: }
3168: }
3169: if ($ltiauth) {
3170: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
3171: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
3172: $display .= &mt('Source of username: Email address [_1]',
3173: '(lis_person_contact_email_primary)').', ';
3174: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
3175: $display .= &mt('Source of username: User ID [_1]',
3176: '(lis_person_sourcedid)').', ';
3177: } else {
3178: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
3179: }
3180: if ($values{'notstudent'} eq 'auth') {
3181: $display .= &mt('Display LON-CAPA login page if no match').', ';
3182: } elsif ($values{'notstudent'} eq 'reject') {
3183: $display .= &mt('Discontinue launch if no match').', ';
3184: }
3185: }
3186: }
3187: $display =~ s/, $//;
3188: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
3189: "'$display'")).'</li>';
3190: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
3191: my $oldname = $oldlinkprot->{$id}{'name'};
3192: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
3193: }
3194: }
3195: } else {
3196: $lti_save_error = 1;
3197: }
3198: }
3199: unless ($lti_save_error) {
3200: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3201: unless (ref($changes->{$id}) eq 'HASH') {
3202: push(@deletions,$id);
3203: }
3204: }
3205: if (@deletions) {
3206: if ($context eq 'course') {
3207: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
3208: }
3209: }
3210: }
3211: if ($lti_save_error) {
3212: $output .= '<li>'.
3213: '<span class="LC_error">'.
3214: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
3215: '</span>'.
3216: '</li>';
3217: }
3218: return $output;
3219: }
3220:
1.118 raeburn 3221: sub store_ltitools {
3222: my ($cdom,$cnum,$context,$changes,$oldltitools) = @_;
3223: my ($home,$ltitools_save_error,$output,$error,%toolsenc,@deletions);
3224: my %lt = <itools_names();
3225: my @courseroles = ('cc','in','ta','ep','st');
3226: my @allfields = ('fullname','firstname','lastname','email','user','roles');
3227: if ($context eq 'domain') {
3228: $home = &Apache::lonnet::domain($cdom,'primary');
3229: } else {
3230: $home = &Apache::lonnet::homeserver($cnum,$cdom);
3231: }
3232: if (ref($changes) eq 'HASH') {
3233: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
3234: if (ref($changes->{$id}) eq 'HASH') {
3235: if (exists($changes->{$id}->{'key'})) {
3236: $toolsenc{$id}{'key'} = $changes->{$id}->{'key'};
3237: delete($changes->{$id}->{'key'});
3238: }
3239: if (exists($changes->{$id}->{'secret'})) {
3240: $toolsenc{$id}{'secret'} = $changes->{$id}->{'secret'};
3241: delete($changes->{$id}->{'secret'});
3242: } elsif (ref($oldltitools->{$id}) eq 'HASH') {
3243: if (exists($oldltitools->{$id}{'usable'})) {
3244: $changes->{$id}->{'usable'} = 1;
3245: }
3246: if (exists($oldltitools->{$id}{'cipher'})) {
3247: $changes->{$id}->{'cipher'} = $oldltitools->{$id}{'cipher'};
3248: }
3249: }
3250: }
3251: }
3252: }
3253: my @ids=&Apache::lonnet::current_machine_ids();
3254: if (keys(%toolsenc) > 0) {
3255: unless (($home eq 'no_host') || ($home eq '')) {
3256: my $allowed;
3257: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3258: if ($allowed) {
3259: if (($context eq 'domain') ||
3260: (($context eq 'course') &&
3261: (&Apache::lonnet::put('nohist_toolsenc',\%toolsenc,$cdom,$cnum,1) eq 'ok'))) {
3262: foreach my $id (keys(%toolsenc)) {
3263: if (exists($toolsenc{$id}{'secret'})) {
3264: $changes->{$id}->{'usable'} = 1;
3265: }
3266: }
3267: } else {
3268: $ltitools_save_error = 1;
3269: }
3270: }
3271: }
3272: }
3273: unless ($ltitools_save_error) {
3274: if ($context eq 'course') {
3275: if (&Apache::lonnet::put('ltitools',$changes,$cdom,$cnum,1) eq 'ok') {
3276: my $hashid=$cdom.'_'.$cnum;
3277: &Apache::lonnet::devalidate_cache_new('courseltitools',$hashid);
3278: unless (($home eq 'no_host') || ($home eq '')) {
3279: if (grep(/^\Q$home\E$/,@ids)) {
1.120 raeburn 3280: &Apache::lonnet::devalidate_cache_new('crsltitoolsenc',$hashid);
1.118 raeburn 3281: }
3282: }
3283: } else {
3284: $ltitools_save_error = 1;
3285: }
3286: }
3287: unless ($ltitools_save_error) {
3288: my %bynum;
3289: foreach my $itemid (sort(keys(%{$changes}))) {
3290: my $position = $changes->{$itemid}{'order'};
3291: $bynum{$position} = $itemid;
3292: }
3293: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
3294: my $itemid = $bynum{$pos};
3295: if (ref($changes->{$itemid}) ne 'HASH') {
3296: $output .= '<li>'.&mt('Deleted: [_1]',$changes->{$itemid}).'</li>';
3297: } else {
3298: $output .= '<li><b>'.$changes->{$itemid}{'title'}.'</b>';
3299: if ($changes->{$itemid}{'image'}) {
3300: $output .= ' '.
3301: '<img src="'.$changes->{$itemid}{'image'}.'"'.
3302: ' alt="'.&mt('Tool Provider icon').'" />';
3303: }
3304: $output .= '</li><ul>';
3305: my $position = $pos + 1;
3306: $output .= '<li>'.&mt('Order: [_1]',$position).'</li>';
3307: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
3308: if ($changes->{$itemid}{$item} ne '') {
3309: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{$item}.'</li>';
3310: }
3311: }
3312: if (ref($toolsenc{$itemid}) eq 'HASH') {
3313: foreach my $item ('key','secret') {
3314: if (exists($toolsenc{$itemid}{$item})) {
3315: if ($item eq 'secret') {
3316: $output .= '<li>'.$lt{$item}.': ['.&mt('not shown').']</li>';
3317: } else {
3318: $output .= '<li>'.$lt{$item}.': '.$toolsenc{$itemid}{$item}.'</li>';
3319: }
3320: }
3321: }
3322: }
1.129 raeburn 3323: $output .= '<li>';
3324: if ($context eq 'domain') {
3325: $output .= &mt('Configurable in course');
3326: } else {
3327: $output .= &mt('Configurable for each instance of tool in course');
3328: }
3329: $output .= ':';
1.118 raeburn 3330: my @possconfig = ('label','title','target','linktext','explanation','append');
3331: my $numconfig = 0;
3332: if (ref($changes->{$itemid}{'crsconf'}) eq 'HASH') {
3333: foreach my $item (@possconfig) {
3334: if ($changes->{$itemid}{'crsconf'}{$item}) {
3335: $numconfig ++;
3336: $output .= ' "'.$lt{'crs'.$item}.'"';
3337: }
3338: }
3339: }
3340: if (!$numconfig) {
3341: $output .= ' '.&mt('None');
3342: }
3343: $output .= '</li>';
3344: foreach my $item ('passback','roster') {
3345: $output .= '<li>'.$lt{$item}.' ';
3346: if ($changes->{$itemid}{$item}) {
3347: $output .= &mt('Yes');
3348: if ($changes->{$itemid}{$item.'valid'}) {
3349: if ($item eq 'passback') {
3350: $output .= ' '.&mt('valid for at least [quant,_1,day] after launch',
3351: $changes->{$itemid}{$item.'valid'});
3352: } else {
3353: $output .= ' '.&mt('valid for at least [quant,_1,second] after launch',
3354: $changes->{$itemid}{$item.'valid'});
3355: }
3356: }
3357: } else {
3358: $output .= &mt('No');
3359: }
3360: $output .= '</li>';
3361: }
3362: if (ref($changes->{$itemid}{'display'}) eq 'HASH') {
3363: my $displaylist;
3364: if ($changes->{$itemid}{'display'}{'target'}) {
3365: $displaylist = &mt('Display target').': '.
3366: $changes->{$itemid}{'display'}{'target'}.',';
3367: }
3368: foreach my $size ('width','height') {
3369: if ($changes->{$itemid}{'display'}{$size}) {
3370: $displaylist .= (' 'x2).$lt{$size}.': '.
3371: $changes->{$itemid}{'display'}{$size}.',';
3372: }
3373: }
3374: if ($displaylist) {
3375: $displaylist =~ s/,$//;
3376: $output .= '<li>'.$displaylist.'</li>';
3377: }
3378: foreach my $item ('linktext','explanation') {
3379: if ($changes->{$itemid}{'display'}{$item}) {
3380: $output .= '<li>'.$lt{$item}.': '.$changes->{$itemid}{'display'}{$item}.'</li>';
3381: }
3382: }
3383: }
3384: if (ref($changes->{$itemid}{'fields'}) eq 'HASH') {
3385: my $fieldlist;
3386: foreach my $field (@allfields) {
3387: if ($changes->{$itemid}{'fields'}{$field}) {
3388: $fieldlist .= (' 'x2).$lt{$field}.',';
3389: }
3390: }
3391: if ($fieldlist) {
3392: $fieldlist =~ s/,$//;
3393: if ($changes->{$itemid}{'fields'}{'user'}) {
3394: if ($changes->{$itemid}{'incdom'}) {
3395: $fieldlist .= ' ('.&mt('username:domain').')';
3396: } else {
3397: $fieldlist .= ' ('.&mt('username').')';
3398: }
3399: }
3400: $output .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
3401: }
3402: }
3403: if (ref($changes->{$itemid}{'roles'}) eq 'HASH') {
3404: my $rolemaps;
3405: foreach my $role (@courseroles) {
3406: if ($changes->{$itemid}{'roles'}{$role}) {
3407: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
3408: $changes->{$itemid}{'roles'}{$role}.',';
3409: }
3410: }
3411: if ($rolemaps) {
3412: $rolemaps =~ s/,$//;
3413: $output .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
3414: }
3415: }
3416: if (ref($changes->{$itemid}{'custom'}) eq 'HASH') {
3417: my $customlist;
3418: if (keys(%{$changes->{$itemid}{'custom'}})) {
3419: foreach my $key (sort(keys(%{$changes->{$itemid}{'custom'}}))) {
3420: $customlist .= $key.':'.$changes->{$itemid}{'custom'}{$key}.(' 'x2);
3421: }
3422: }
3423: if ($customlist) {
3424: $output .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
3425: }
3426: }
3427: $output .= '</ul></li>';
3428: }
3429: }
3430: }
3431: }
3432: return $output;
3433: }
3434:
1.3 raeburn 3435: sub update_env {
3436: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
3437: my $count = 0;
3438: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
3439: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
3440: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
3441: foreach my $key (@{$need_env_update}) {
3442: if ($key eq 'description' && defined($storehash->{$key})) {
3443: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
3444: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
3445: $count ++;
3446: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
3447: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
3448: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
3449: $count ++;
1.25 raeburn 3450: } elsif ($key eq 'co-owners') {
3451: if ($storehash->{'internal.co-owners'} ne '') {
3452: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
3453: }
3454: if ($storehash->{'internal.pendingco-owners'} ne '') {
3455: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
3456: }
3457: my @coowners = split(',',$storehash->{'internal.'.$key});
3458: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
3459: $count ++;
1.87 raeburn 3460: } elsif ($key =~ /^lti\./) {
3461: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 3462: }
3463: }
3464: if ($count) {
3465: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
3466: }
3467: }
3468: }
3469: return;
3470: }
3471:
3472: sub display_disallowed {
1.9 raeburn 3473: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 3474: my $output;
3475: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
3476: if (keys(%{$disallowed})) {
3477: if ($item eq 'cloners') {
3478: my @fails;
3479: my %lt = &Apache::lonlocal::texthash (
3480: format => 'Invalid format',
3481: domain => 'Domain does not exist',
3482: newuser => 'LON-CAPA user(s) do(es) not exist.',
3483: );
3484: foreach my $error ('format','domain','newuser') {
3485: if (defined($disallowed->{$error})) {
3486: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
3487: $lt{$error};
3488: if ($error eq 'newuser') {
1.9 raeburn 3489: $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 3490: }
3491: push(@fails,$msg);
3492: }
3493: }
3494: if (@fails) {
3495: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
3496: '</span>'.join('; ',@fails).'.<br />';
3497: }
3498: } elsif ($item eq 'rolenames') {
3499: my %lt = &Apache::lonlocal::texthash (
3500: replacements => 'Name already used to replace a different standard role name',
3501: regulars => 'Name already used as a standard role name',
3502: customrole => 'Name already used as the name of a custom role',
3503: );
3504: my @fails;
3505: foreach my $error ('replacements','regulars','customrole') {
3506: if (ref($disallowed->{$error}) eq 'ARRAY') {
3507: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
3508: '</b>, '.&mt('reason').' - '.$lt{'error'});
3509: }
3510: }
3511: if (@fails) {
3512: $output .= '<span class="LC_warning">'.
3513: &mt('Unable to include amongst replacements for role names: ').
3514: '</span>'.join('; ',@fails).'.<br />';
3515: }
3516:
3517: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
3518: $output .= '<span class="LC_warning">';
3519: if ($item eq 'feedback') {
1.9 raeburn 3520: if ($crstype eq 'Community') {
3521: $output .= &mt('Unable to include as a recipient of community feedback for:');
3522: } else {
3523: $output .= &mt('Unable to include as a recipient of course feedback for:');
3524: }
1.3 raeburn 3525: } elsif ($item eq 'discussion') {
3526: $output .= &mt('Unable to include in user-based access control for:');
3527: } elsif ($item eq 'localization') {
1.9 raeburn 3528: if ($crstype eq 'Community') {
3529: $output .= &mt('Unable to include in community localization:');
3530: } else {
3531: $output .= &mt('Unable to include in course localization:');
3532: }
1.3 raeburn 3533: }
3534: $output .= '</span><ul>';
3535: foreach my $key (sort(keys(%{$disallowed}))) {
3536: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
3537: $output .= '<li><i>'.$itemtext.'</i> - ';
3538: if ($item eq 'localization') {
3539: $output .= &mt('reason - unsupported language: [_1]',
3540: '<b>'.$disallowed->{$key}.'</b>');
3541: } else {
3542: $output .= &mt('reason - invalid user: [_1]',
3543: '<b>'.$disallowed->{$key}.'</b>').'</li>';
3544: }
3545: }
3546: $output .= '</ul><br />';
3547: }
3548: }
1.1 raeburn 3549: }
1.3 raeburn 3550: return $output;
1.1 raeburn 3551: }
3552:
3553: sub get_course {
3554: my ($courseid) = @_;
3555: if (!defined($courseid)) {
3556: $courseid = $env{'request.course.id'};
3557: }
3558: my $cdom=$env{'course.'.$courseid.'.domain'};
3559: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 3560: my $chome=$env{'course.'.$courseid.'.home'};
3561: return ($cnum,$cdom,$chome);
1.1 raeburn 3562: }
3563:
3564: sub get_jscript {
1.91 raeburn 3565: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 3566: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 raeburn 3567: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 3568: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
3569: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 3570: my $cloners_js = &cloners_javascript($phase);
1.118 raeburn 3571: my $currltitools;
3572: if (ref($settings) eq 'HASH') {
3573: $currltitools = $settings->{'ltitools'};
3574: }
3575: my $ltitools_js = &Apache::lonconfigsettings::ltitools_javascript($currltitools);
1.71 raeburn 3576: my @code_order;
3577: if ($crstype ne 'Community') {
3578: if (ref($settings) eq 'HASH') {
3579: my %codedefaults;
3580: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3581: \@code_order);
3582: if (@code_order > 0) {
3583: if ($phase eq 'display') {
3584: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
3585: if (grep(/^courseinfo$/,@actions)) {
3586: if ($settings->{'cloners'} ne '') {
3587: unless ($settings->{'cloners'} eq '*') {
3588: my @cloners = split(/,/,$settings->{'cloners'});
3589: my @standardnames = &Apache::loncommon::get_standard_codeitems();
3590: my %local_to_standard;
3591: for (my $i=0; $i<@code_order; $i++) {
3592: $local_to_standard{$code_order[$i]} = $standardnames[$i];
3593: }
3594: foreach my $cloner (@cloners) {
1.124 raeburn 3595: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
1.71 raeburn 3596: ($cloner !~ /^$match_username\:$match_domain$/)) {
3597: foreach my $item (split(/\&/,$cloner)) {
3598: my ($key,$val) = split(/\=/,$item);
3599: $val = &unescape($val);
3600: foreach my $code (@code_order) {
3601: if ($key eq $local_to_standard{$code}) {
3602: $env{'form.'.$key} = $val;
3603: }
3604: }
3605: }
3606: }
3607: }
3608: }
3609: }
3610: }
3611: }
3612: my @codetitles;
3613: (undef,$instcode_js) =
3614: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
3615: \@codetitles);
3616: $instcode_js .= <<ENDSCRIPT;
3617: function toggleCloners(callerradio) {
3618: if (document.getElementById('LC_cloners_instcode')) {
3619: if (callerradio.value == 1) {
3620: document.getElementById('LC_cloners_instcode').style.display = "block";
3621: } else {
3622: uncheckOfficialLists();
3623: document.getElementById('LC_cloners_instcode').style.display = "none";
3624: }
3625: }
3626: }
3627:
3628: if (!document.getElementsByClassName) {
3629: function getElementsByClassName(node, classname) {
3630: var a = [];
3631: var re = new RegExp('(^| )'+classname+'( |$)');
3632: var els = node.getElementsByTagName("*");
3633: for(var i=0,j=els.length; i<j; i++)
3634: if(re.test(els[i].className))a.push(els[i]);
3635: return a;
3636: }
3637: }
3638:
3639: function uncheckOfficialLists() {
3640: var codepicks;
3641: if (document.getElementsByClassName) {
3642: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
3643: } else {
3644: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
3645: }
3646: if (codepicks.length) {
3647: for (var i=0; i<codepicks.length; i++) {
3648: codepicks[i].selectedIndex = 0;
3649: }
3650: }
3651: }
3652:
3653: ENDSCRIPT
3654: }
3655: }
3656: }
1.1 raeburn 3657: if ($can_categorize) {
3658: $categorize_js = <<ENDSCRIPT;
3659: function catsbrowser() {
3660: var catswin = null;
3661: var url = '/adm/courseprefs?phase=categorizecourse';
3662: if (!catswin || catswin.closed) {
3663: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3664: } else {
3665: catswin.focus();
3666: }
3667: }
3668: ENDSCRIPT
3669: }
1.36 raeburn 3670: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
3671: if ($loncaparev) {
3672: $loncaparev_js = <<ENDSCRIPT;
3673: function loncaparevinfo() {
3674: var lcrevwin = null;
3675: var url = '/adm/courseprefs?phase=releaseinfo';
3676: if (!lcrevwin || lcrevwin.closed) {
3677: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3678: } else {
3679: lcrevwin.focus();
3680: }
3681: }
3682: ENDSCRIPT
3683: }
1.60 raeburn 3684: my $cnum = $env{'course.'.$cid.'.num'};
3685: my $syllabus_js = <<ENDSCRIPT;
3686: function syllabusinfo() {
3687: var syllwin = null;
3688: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
3689: if (!syllwin || syllwin.closed) {
3690: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
3691: } else {
3692: syllwin.focus();
3693: }
3694: }
3695: ENDSCRIPT
1.127 raeburn 3696: my ($menuitems_js,$grading_js);
1.91 raeburn 3697: unless ($noedit) {
3698: my $collections;
3699: my $next = 1;
3700: if (ref($settings) eq 'HASH') {
3701: if ($settings->{'menucollections'} ne '') {
3702: my @current;
3703: foreach my $item (split(/;/,$settings->{'menucollections'})) {
3704: my ($num) = split(/\%/,$item);
3705: if ($num =~ /^\d+$/) {
3706: push(@current,$num);
3707: }
3708: }
3709: $collections = join("','",sort { $a <=> $b } @current);
3710: if ($collections) {
3711: $collections = "'$collections'";
3712: }
3713: $next += $current[-1];
3714: }
3715: }
3716: my $deftext = &mt('Standard (all menus shown)');
3717: $menuitems_js = <<ENDSCRIPT;
3718: function toggleAddmenucoll() {
3719: if (document.getElementById('menucollections_add')) {
3720: var state = 'none';
3721: var add = document.getElementById('menucollections_add').checked;
3722: if (add) {
3723: state = 'inline-block';
3724: }
3725: var fieldsets = new Array('shown','text','links','list','inline');
3726: for (var i=0; i<fieldsets.length; i++) {
3727: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
3728: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
3729: }
3730: }
3731: var box = document.getElementsByClassName('LC_menucoll_add');
3732: if (box.length) {
3733: for (var i=0; i<box.length; i++) {
3734: if (add) {
3735: box[i].checked = true;
3736: } else {
3737: box[i].checked = false;
3738: }
3739: }
3740: }
3741: if (document.getElementById('menudefault')) {
3742: var menudef = document.getElementById('menudefault');
3743: var currsel = menudef.selectedIndex;
3744: var colls = new Array($collections);
3745: menudef.options.length = 0;
3746: if (!add) {
3747: if (currsel == 1 + colls.length) {
3748: currsel = 0;
3749: }
3750: }
3751: if (currsel == 0) {
3752: menudef.options[0] = new Option('$deftext','',true,true);
3753: } else {
3754: menudef.options[0] = new Option('$deftext','',false,false);
3755: }
3756: if (colls.length) {
3757: for (var i=0; i<colls.length; i++) {
3758: var idx = i+1;
3759: if (currsel == colls[i]) {
3760: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
3761: } else {
3762: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
3763: }
3764: }
3765: }
3766: if (add) {
3767: var addidx = 1 + colls.length;
3768: if (currsel == addidx) {
3769: menudef.options[addidx] = new Option('$next','$next',true,true);
3770: } else {
3771: menudef.options[addidx] = new Option('$next','$next',false,false);
3772: }
3773: }
3774: }
3775: }
3776: }
3777: ENDSCRIPT
1.127 raeburn 3778: $grading_js = <<"ENDSCRIPT";
3779: function toggleGrading(form) {
3780: if (document.getElementById('hidetotalsdiv')) {
3781: var totalsdivid = document.getElementById('hidetotalsdiv');
3782: var selname = form.elements['grading'];
3783: if (selname) {
3784: var current = selname.options[selname.selectedIndex].value
3785: if (current == 'standard') {
3786: totalsdivid.style.display = 'inline-block';
3787: } else {
3788: totalsdivid.style.display = 'none';
3789: }
3790: }
3791: }
3792: return;
3793: }
3794:
3795: function toggleHiddenTotalsSec(form) {
3796: if (document.getElementById('sectotalsdiv')) {
3797: var sectotalsdivid = document.getElementById('sectotalsdiv');
3798: var radioname = form.elements['hidetotals'];
3799: if (radioname) {
3800: if (radioname.length > 0) {
3801: var setvis;
3802: for (var i=0; i<radioname.length; i++) {
3803: if (radioname[i].checked == true) {
3804: if (radioname[i].value == 1) {
3805: sectotalsdivid.style.display = 'inline-block';
3806: setvis = 1;
3807: }
3808: break;
3809: }
3810: }
3811: if (!setvis) {
3812: sectotalsdivid.style.display = 'none';
3813: }
3814: }
3815: }
3816: }
3817: return;
3818: }
3819: ENDSCRIPT
1.91 raeburn 3820: }
1.114 raeburn 3821: $extresource_js = <<"ENDSCRIPT";
3822: function toggleExtRes() {
3823: if (document.getElementById('LC_extresource')) {
3824: var extressel = document.getElementById('LC_extresource').value;
3825: if (document.getElementById('LC_extresreusediv')) {
3826: var extresreuse = document.getElementById('LC_extresreusediv');
3827: if (document.getElementById('LC_extressize')) {
3828: var extressize = document.getElementById('LC_extressize');
3829: var setvis;
3830: if ((extressel == 'tab') || (extressel == 'window')) {
3831: extresreuse.style.display = 'inline-block';
3832: setvis = 1;
3833: if (extressel == 'window') {
3834: extressize.style.display = 'inline-block';
3835: } else {
3836: extressize.style.display = 'none';
3837: }
3838: }
3839: if (!setvis) {
3840: extresreuse.style.display = 'none';
3841: extressize.style.display = 'none';
3842: }
3843: }
3844: }
3845: }
3846: }
3847: ENDSCRIPT
1.115 raeburn 3848: $localization_js = <<"ENDSCRIPT";
3849: function toggleTimeZone() {
3850: if (document.getElementById('LC_set_timezone')) {
3851: var timezonesel = document.getElementById('LC_set_timezone').value;
3852: if (document.getElementById('LC_tzoverdiv')) {
3853: var tzoverdiv = document.getElementById('LC_tzoverdiv');
3854: if (timezonesel == '') {
3855: tzoverdiv.style.display = 'none';
3856: } else {
3857: tzoverdiv.style.display = 'block';
3858: }
3859: }
3860: }
3861: }
3862: ENDSCRIPT
1.1 raeburn 3863: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.124 raeburn 3864: '// <![CDATA['."\n".
1.36 raeburn 3865: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 raeburn 3866: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 3867: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.127 raeburn 3868: $grading_js."\n".&linkprot_javascript()."\n".'//]]>'."\n".
1.118 raeburn 3869: '</script>'."\n".$stubrowse_js."\n".$ltitools_js."\n";
1.1 raeburn 3870: return $jscript;
3871: }
3872:
1.3 raeburn 3873: sub cloners_javascript {
3874: my ($formname) = @_;
3875: return <<"ENDSCRIPT";
3876:
3877: function update_cloners(caller,num) {
3878: var delidx = getIndexByName('cloners_delete');
3879: var actidx = getIndexByName('cloners_activate');
3880: if (caller == 'cloners_all') {
3881: var selall;
3882: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3883: if (document.$formname.cloners_all[i].checked) {
3884: selall = document.$formname.cloners_all[i].value;
3885: }
3886: }
3887: if (selall == 1) {
3888: if (delidx != -1) {
3889: if (document.$formname.cloners_delete.length) {
3890: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
3891: document.$formname.cloners_delete[j].checked = true;
3892: }
3893: } else {
3894: document.$formname.elements[delidx].checked = true;
3895: }
3896: }
3897: if (actidx != -1) {
3898: if (document.$formname.cloners_activate.length) {
3899: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
3900: if (document.$formname.cloners_activate[i].value == '0') {
3901: document.$formname.cloners_activate[i].checked = false;
3902: }
1.71 raeburn 3903: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 3904: document.$formname.cloners_activate[i].checked = true;
3905: }
3906: }
3907: }
3908: }
3909: document.$formname.cloners_newdom.selectedIndex = 0;
3910: }
3911: }
3912: if (caller == 'cloners_activate') {
3913: if (document.$formname.cloners_activate.length) {
3914: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
3915: if (document.$formname.cloners_activate[j].value == num) {
3916: if (document.$formname.cloners_activate[j].checked) {
3917: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3918: if (document.$formname.cloners_all[i].value == '1') {
3919: document.$formname.cloners_all[i].checked = false;
3920: }
3921: if (document.$formname.cloners_all[i].value == '0') {
3922: document.$formname.cloners_all[i].checked = true;
3923: }
3924: }
3925: }
3926: }
3927: }
3928: } else {
3929: for (var i=0; i<document.$formname.cloners_all.length; i++) {
3930: if (document.$formname.cloners_all[i].value == '1') {
3931: document.$formname.cloners_all[i].checked = false;
3932: }
3933: if (document.$formname.cloners_all[i].value == '0') {
3934: document.$formname.cloners_all[i].checked = true;
3935: }
3936: }
3937: }
3938: }
3939: return;
3940: }
3941:
3942: function getIndexByName(item) {
3943: for (var i=0;i<document.$formname.elements.length;i++) {
3944: if (document.$formname.elements[i].name == item) {
3945: return i;
3946: }
3947: }
3948: return -1;
3949: }
3950:
3951: ENDSCRIPT
3952: }
3953:
1.102 raeburn 3954: sub linkprot_javascript {
3955: return <<"ENDSCRIPT";
1.112 raeburn 3956: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 3957: if (document.getElementById('linkprot_'+extra+'_'+num)) {
3958: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
3959: var itemname = form.elements['linkprot_'+item+'_'+num];
3960: if (itemname) {
3961: if (itemname.length > 0) {
3962: var setvis;
3963: for (var i=0; i<itemname.length; i++) {
3964: if (itemname[i].checked == true) {
3965: if (itemname[i].value == valon) {
3966: extraid.style.display = styleon;
3967: setvis = 1;
3968: }
3969: break;
3970: }
3971: }
3972: if (!setvis) {
3973: extraid.style.display = 'none';
3974: }
3975: }
3976: }
3977: }
3978: return;
3979: }
1.106 raeburn 3980:
1.102 raeburn 3981: ENDSCRIPT
3982:
3983: }
3984:
1.1 raeburn 3985: sub print_courseinfo {
1.80 raeburn 3986: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3987: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3988: return;
3989: }
1.83 raeburn 3990: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3991: if ($noedit) {
3992: $disabled = ' disabled="disabled"';
3993: }
1.1 raeburn 3994: my %domconf =
1.71 raeburn 3995: &Apache::lonnet::get_dom('configuration',
3996: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3997: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3998: $cathash = $domconf{'coursecategories'}{'cats'};
3999: if (ref($cathash) eq 'HASH') {
4000: $categoriesform =
4001: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 4002: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 4003: }
4004: }
1.25 raeburn 4005: if (ref($domconf{'autoenroll'}) eq 'HASH') {
4006: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
4007: }
1.71 raeburn 4008: my ($currcanclone,@code_order,$cloner_instcode);
4009: my %codedefaults;
4010: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
4011: \@code_order);
4012: if ($settings->{'cloners'}) {
4013: unless ($settings->{'cloners'} eq '*') {
4014: my @currclone = split(/,/,$settings->{'cloners'});
4015: foreach my $item (@currclone) {
4016: unless ($item eq '*') {
4017: if (($item !~ /\:/) && ($item =~ /=/)) {
4018: $cloner_instcode = 1;
4019: }
4020: }
4021: }
4022: }
4023: }
4024: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
4025: my $canclone = $domconf{'coursedefaults'}{'canclone'};
4026: if (ref($canclone) eq 'HASH') {
4027: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
4028: if ($settings->{'internal.coursecode'}) {
4029: my @posscodes;
4030: if (@code_order > 0) {
4031: $currcanclone = 'instcode';
4032: foreach my $item (@{$canclone->{'instcode'}}) {
4033: if (grep(/^\Q$item\E$/,@code_order)) {
4034: push(@posscodes,$item);
4035: }
4036: }
4037: my $codestr = join(' + ',@posscodes);
4038: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
4039: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
4040: }
4041: }
4042: }
4043: } elsif ($canclone eq 'domain') {
4044: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
4045: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
4046: $currcanclone = 'domain';
4047: }
4048: if ($clonedefaults) {
4049: if ($settings->{'cloners'} ne '') {
4050: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
4051: } else {
4052: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
4053: }
4054: $clonedefaults = '<br /><br />'.$clonedefaults;
4055: }
4056: }
1.1 raeburn 4057: if (!defined($categoriesform)) {
1.15 raeburn 4058: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 4059: }
1.12 raeburn 4060: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 4061: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 4062:
1.9 raeburn 4063: my $replace;
4064: if ($crstype eq 'Community') {
4065: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
4066: } else {
4067: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
4068: }
1.84 raeburn 4069: my ($editmap,$editsyllabus);
4070: unless ($noedit) {
4071: $editmap = (' 'x2).
4072: '<a href="javascript:openbrowser'.
4073: "('display','url','sequence')\">".
4074: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
4075: &mt('Modification may make assessment data inaccessible!').
4076: '</span>';
4077: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
1.124 raeburn 4078: '</a>');
1.84 raeburn 4079: }
1.1 raeburn 4080: my %items = (
1.3 raeburn 4081: 'url' => {
1.84 raeburn 4082: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 4083: input => 'textbox',
1.55 raeburn 4084: size => '55',
1.19 faziophi 4085: advanced => 1
1.1 raeburn 4086: },
4087: 'description' => {
1.3 raeburn 4088: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 4089: input => 'textbox',
1.55 raeburn 4090: size => '55',
1.1 raeburn 4091: },
1.24 raeburn 4092: 'owner' => {
4093: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
4094: },
1.25 raeburn 4095: 'co-owners' => {
4096: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
4097: },
1.63 raeburn 4098: 'clonedfrom' => {
4099: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
4100: },
1.1 raeburn 4101: 'courseid' => {
1.3 raeburn 4102: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
4103: &mt('internal, optional').')',
1.1 raeburn 4104: input => 'textbox',
4105: size => '25',
4106: },
1.64 raeburn 4107: 'uniquecode' => {
4108: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
4109: },
1.1 raeburn 4110: 'cloners' => {
1.3 raeburn 4111: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 4112: &mt('Owner and Coordinators included automatically').
4113: $clonedefaults,
1.1 raeburn 4114: input => 'textbox',
1.41 www 4115: size => '40'
1.1 raeburn 4116: },
4117: 'rolenames' => {
1.3 raeburn 4118: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 4119: '('.$replace.')',
1.1 raeburn 4120: input => 'textbox',
4121: size => '20',
1.19 faziophi 4122: advanced => 1
1.1 raeburn 4123: },
1.88 raeburn 4124: 'syllabus' => {
4125: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 4126: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 4127: $editsyllabus,
1.1 raeburn 4128: },
4129: 'hidefromcat' => {
1.3 raeburn 4130: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 4131: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
4132: input => 'radio',
4133: },
4134: 'categories' => {
1.3 raeburn 4135: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 4136: &mt('Display Categories').'</a>',
4137: input => 'textbox',
4138: size => '25',
4139: },
1.35 raeburn 4140: 'loncaparev' => {
4141: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
4142: },
1.55 raeburn 4143: 'defaultcredits' => {
4144: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
4145: },
1.1 raeburn 4146: );
4147: my $datatable;
4148: my $count = 0;
4149: foreach my $item (@{$ordered}) {
1.56 raeburn 4150: my $colspan;
1.1 raeburn 4151: if ($item eq 'hidefromcat') {
4152: next if (!$can_toggle_cat);
4153: } elsif ($item eq 'categories') {
4154: next if (!$can_categorize);
1.64 raeburn 4155: } elsif ($item eq 'uniquecode') {
4156: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 4157: }
1.56 raeburn 4158: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
1.124 raeburn 4159: $colspan = 2;
1.56 raeburn 4160: }
1.1 raeburn 4161: $count ++;
1.19 faziophi 4162: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 4163: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 4164: } else {
1.56 raeburn 4165: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 4166: }
1.1 raeburn 4167: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 4168: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4169: } elsif ($item eq 'cloners') {
4170: my $includeempty = 1;
4171: my $num = 0;
1.56 raeburn 4172: $datatable .= '</td><td align="right">'.
4173: &Apache::loncommon::start_data_table().
1.1 raeburn 4174: &Apache::loncommon::start_data_table_row().
4175: '<td><span class="LC_nobreak"><label>'.
4176: &mt('Any user in any domain:').
4177: ' <input type="radio" name="cloners_all" value="1" ';
4178: if ($settings->{$item} eq '*') {
4179: $datatable .= ' checked="checked" ';
4180: }
4181: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 4182: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4183: (' 'x2).'<label>'.
4184: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 4185: if ($settings->{$item} ne '*') {
4186: $datatable .= ' checked="checked" ';
4187: }
4188: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 4189: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 4190: &Apache::loncommon::end_data_table_row().
4191: &Apache::loncommon::end_data_table().
1.56 raeburn 4192: '<table><tr><td align="left"><b>'.&mt('Or').
4193: '</b></td></tr></table>'.
1.1 raeburn 4194: &Apache::loncommon::start_data_table();
4195: my @cloners;
4196: if ($settings->{$item} eq '') {
1.80 raeburn 4197: unless ($noedit) {
4198: my $default;
4199: if ($currcanclone eq 'domain') {
4200: $default = '0';
4201: }
4202: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 4203: }
1.1 raeburn 4204: } elsif ($settings->{$item} ne '*') {
4205: my @entries = split(/,/,$settings->{$item});
4206: if (@entries > 0) {
4207: foreach my $entry (@entries) {
4208: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 4209: if ($udom =~ /^$match_domain$/) {
4210: unless (&Apache::lonnet::domain($udom)) {
4211: next;
4212: }
4213: } else {
4214: next;
4215: }
1.1 raeburn 4216: if ($uname eq '*') {
4217: $datatable .=
4218: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4219: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 4220: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 4221: '</b><input type="hidden" name="cloners_dom_'.$num.
4222: '" value="'.$udom.'" /></span><br />'.
4223: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4224: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 4225: &mt('Delete').'</label></span></td>'.
4226: &Apache::loncommon::end_data_table_row();
4227: $num ++;
1.23 raeburn 4228: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
4229: unless (grep(/^\Q$entry\E$/,@cloners)) {
4230: push(@cloners,$entry);
4231: }
1.1 raeburn 4232: }
4233: }
4234: }
4235: }
4236: my $add_domtitle = &mt('Any user in additional domain:');
4237: if ($settings->{$item} eq '*') {
4238: $add_domtitle = &mt('Any user in specific domain:');
4239: } elsif ($settings->{$item} eq '') {
4240: $add_domtitle = &mt('Any user in other domain:');
4241: }
4242: my $cloners_str = join(',',@cloners);
4243: $datatable .= &Apache::loncommon::start_data_table_row().
4244: '<td align="left"><span class="LC_nobreak">'.
4245: $add_domtitle.'</span><br />'.
4246: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 4247: $includeempty,undef,undef,
4248: undef,undef,$noedit).
1.1 raeburn 4249: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
4250: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 4251: &Apache::loncommon::end_data_table().
1.56 raeburn 4252: '<table><tr><td align="left"><b>'.&mt('And').
4253: '</b></td></tr></table>'.
1.1 raeburn 4254: &Apache::loncommon::start_data_table().
4255: &Apache::loncommon::start_data_table_row().
4256: '<td align="left">'.
4257: &mt('Specific users').' (<tt>'.
4258: &mt('user:domain,user:domain').'</tt>)<br />'.
4259: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 4260: $items{$item}{'size'},$disabled).
1.1 raeburn 4261: '</td>'.&Apache::loncommon::end_data_table_row().
4262: &Apache::loncommon::end_data_table();
1.71 raeburn 4263: if (@code_order > 0) {
4264: my (%cat_items,@codetitles,%cat_titles,%cat_order);
4265: my ($jscript,$totcodes,$numtitles,$lasttitle) =
4266: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
4267: \%cat_items,\@codetitles,
4268: \%cat_titles,\%cat_order);
4269: my $showncodes = 'off';
4270: my $checkedoff = ' checked="checked"';
4271: my $checkedon = '';
4272: if ($cloner_instcode) {
4273: $checkedon = $checkedoff;
4274: $checkedoff = '';
4275: $showncodes = 'on';
4276: }
4277: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
4278: '</b></td></tr></table>'.
4279: &Apache::loncommon::start_data_table().
4280: &Apache::loncommon::start_data_table_row().
4281: '<td align="left"><span class="LC_nobreak">'.
4282: &mt('Cloning by official course(s) based on course category').(' 'x2).
4283: '<label>'.
1.80 raeburn 4284: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 4285: (' ').
4286: '<label>'.
1.80 raeburn 4287: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 4288: &Apache::courseclassifier::build_instcode_selectors($numtitles,
4289: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 4290: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 4291: '</td>'.&Apache::loncommon::end_data_table_row().
4292: &Apache::loncommon::end_data_table();
4293: }
1.1 raeburn 4294: } elsif ($item eq 'rolenames') {
1.56 raeburn 4295: $datatable .= '</td><td align="right">'.
4296: &Apache::loncommon::start_data_table();
1.9 raeburn 4297: my @roles;
4298: if ($crstype eq 'Community') {
4299: @roles = ('co');
4300: } else {
4301: @roles = ('cc');
4302: }
4303: push (@roles,('in','ta','ep','ad','st'));
4304: foreach my $role (@roles) {
1.1 raeburn 4305: $datatable .= &Apache::loncommon::start_data_table_row().
4306: '<td align="left"><span class="LC_nobreak">'.
4307: &Apache::lonnet::plaintext($role,$crstype,undef,1).
4308: '</span></td><td align="left">'.
4309: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
4310: $settings->{$role.'.plaintext'},
1.80 raeburn 4311: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 4312: &Apache::loncommon::end_data_table_row();
4313: }
4314: $datatable .= &Apache::loncommon::end_data_table().'</td>';
4315: } elsif ($item eq 'categories') {
1.80 raeburn 4316: my $launcher;
4317: if ($noedit) {
4318: $launcher = $disabled;
4319: } else {
4320: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
4321: }
1.3 raeburn 4322: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
4323: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
4324: $items{$item}{size},$launcher);
1.24 raeburn 4325: } elsif ($item eq 'owner') {
4326: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
4327: if ($owner =~ /:/) {
4328: my ($ownername,$ownerdom) = split(':',$owner);
4329: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
4330: } elsif ($owner ne '') {
4331: $owner = &Apache::loncommon::plainname($owner,$cdom);
4332: } else {
4333: $owner = &mt('None specified');
4334: }
4335: $datatable .= $owner;
1.63 raeburn 4336: } elsif ($item eq 'clonedfrom') {
4337: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
4338: my $clonedfrom = &mt('None');
4339: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 4340: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 4341: if ($clonesrcinfo{'description'}) {
1.124 raeburn 4342: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
1.63 raeburn 4343: }
4344: }
4345: $datatable .= $clonedfrom;
1.64 raeburn 4346: } elsif ($item eq 'uniquecode') {
1.124 raeburn 4347: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
1.64 raeburn 4348: if ($code) {
4349: $datatable .= $code;
4350: }
1.25 raeburn 4351: } elsif ($item eq 'co-owners') {
4352: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
4353: my @currcoown;
4354: if ($coowners) {
4355: @currcoown = split(',',$coowners);
4356: }
4357: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
4358: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4359: $datatable .= &show_autocoowners(@currcoown);
4360: } else {
1.80 raeburn 4361: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4362: }
4363: } else {
4364: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
4365: $datatable .= &show_autocoowners(@currcoown);
4366: } else {
1.80 raeburn 4367: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 4368: }
4369: }
1.88 raeburn 4370: } elsif ($item eq 'syllabus') {
1.60 raeburn 4371: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
4372: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
4373: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
4374: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
4375: if ($minimal =~/\w/) {
4376: if ($external =~ m{\Q$minimal\E$}) {
4377: undef($external);
4378: }
4379: } elsif ($uploaded =~/\w/) {
4380: if ($external =~ m{\Q$uploaded\E$}) {
4381: undef($external);
4382: }
4383: }
4384: } elsif ($external!~/\w/) {
4385: undef($external);
4386: }
4387: if ($external) {
4388: $datatable .= &mt('External URL');
4389: } elsif ($minimal) {
4390: $datatable .= &mt('Minimal template');
4391: } elsif ($uploaded) {
4392: $datatable .= &mt('Uploaded file');
4393: } else {
1.124 raeburn 4394: $datatable .= &mt('Standard template');
1.60 raeburn 4395: }
4396: $datatable .= (' ' x 2).
4397: &mt('[_1]View[_2]',
4398: '<a href="javascript:syllabusinfo();">',
1.124 raeburn 4399: '</a>');
1.35 raeburn 4400: } elsif ($item eq 'loncaparev') {
4401: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
4402: my $showreqd;
4403: if ($loncaparev) {
1.36 raeburn 4404: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 4405: &mt('Details').'</a>';
1.35 raeburn 4406: } else {
4407: $showreqd = &mt('No specific version required');
4408: }
4409: $datatable .= $showreqd;
1.1 raeburn 4410: } else {
1.80 raeburn 4411: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 4412: }
4413: $datatable .= &item_table_row_end();
4414: }
4415: $$rowtotal += scalar(@{$ordered});
4416: return $datatable;
4417: }
4418:
4419: sub new_cloners_dom_row {
1.71 raeburn 4420: my ($newdom,$num,$default) = @_;
4421: my ($output,$checkedon,$checkedoff);
1.1 raeburn 4422: if ($newdom ne '') {
1.71 raeburn 4423: if ($num eq $default) {
1.124 raeburn 4424: $checkedon = 'checked="checked" ';
1.71 raeburn 4425: } else {
4426: $checkedoff = 'checked="checked" ';
4427: }
1.1 raeburn 4428: $output .= &Apache::loncommon::start_data_table_row().
4429: '<td valign="top"><span class="LC_nobreak">'.
4430: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
4431: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 4432: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 4433: 'onchange="javascript:update_cloners('.
1.1 raeburn 4434: "'cloners_activate','$num'".');" />'.
4435: &mt('Yes').'</label>'.(' 'x2).
4436: '<label><input type="radio" '.
1.71 raeburn 4437: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 4438: 'onchange="javascript:update_cloners('.
1.1 raeburn 4439: "'cloners_activate','$num'".');" />'.
1.3 raeburn 4440: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
4441: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 4442: &Apache::loncommon::end_data_table_row();
4443: }
4444: return $output;
4445: }
4446:
4447: sub can_modify_catsettings {
1.12 raeburn 4448: my ($dom,$crstype) = @_;
1.1 raeburn 4449: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
4450: my ($can_toggle_cat,$can_categorize);
4451: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 4452: if ($crstype eq 'Community') {
4453: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
4454: $can_toggle_cat = 1;
4455: }
4456: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
4457: $can_categorize = 1;
4458: }
4459: } else {
4460: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
4461: $can_toggle_cat = 1;
4462: }
4463: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
4464: $can_categorize = 1;
4465: }
1.1 raeburn 4466: }
4467: }
4468: return ($can_toggle_cat,$can_categorize);
4469: }
4470:
4471: sub assign_course_categories {
1.9 raeburn 4472: my ($r,$crstype) = @_;
1.1 raeburn 4473: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4474: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4475: my $hascats = 0;
4476: my $cathash;
4477: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
4478: if (ref($domconf{'coursecategories'}) eq 'HASH') {
4479: $cathash = $domconf{'coursecategories'}{'cats'};
4480: if (ref($cathash) eq 'HASH') {
1.12 raeburn 4481: foreach my $cat (keys(%{$cathash})) {
4482: next if ($cat eq 'instcode::0');
4483: unless ($crstype eq 'Community') {
4484: next if ($cat eq 'communities::0');
4485: }
4486: $hascats ++;
4487: }
1.1 raeburn 4488: }
4489: }
4490: my $catwin_js;
4491: if ($hascats) {
1.9 raeburn 4492: my $alert;
4493: if ($crstype eq 'Community') {
4494: $alert = &mt("Use 'Save' in the main window to save community categories");
4495: } else {
4496: $alert = &mt("Use 'Save' in the main window to save course categories");
4497: }
1.72 damieng 4498: &js_escape(\$alert);
1.1 raeburn 4499: $catwin_js = <<ENDSCRIPT;
4500: <script type="text/javascript">
4501:
4502: function updateCategories() {
4503: var newcategories = '';
4504: var unescapedcats = '';
4505: if (document.chgcats.usecategory.length) {
4506: for (var i=0; i<document.chgcats.usecategory.length; i++) {
4507: if (document.chgcats.usecategory[i].checked == true) {
4508: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
4509: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
4510: }
4511: }
4512: if (newcategories.length > 0) {
4513: newcategories = newcategories.slice(0,-1);
4514: }
4515: if (unescapedcats.length > 0) {
4516: unescapedcats = unescapedcats.slice(0,-3);
4517: }
4518: } else {
4519: if (document.chgcats.usecategory.checked == true) {
4520: newcategories = document.chgcats.usecategory.value;
4521: unescapedcats = document.chgcats.catname.value;
4522: }
4523: }
4524: opener.document.display.categories.value = newcategories;
4525: opener.document.display.categories_display.value = unescapedcats;
4526: alert("$alert");
4527: self.close();
4528: return;
4529: }
4530:
4531: </script>
4532: ENDSCRIPT
4533: } else {
4534: my $onload;
4535: }
1.9 raeburn 4536: my ($crscat,$catcrs,$assign);
4537: if ($crstype eq 'Community') {
4538: $crscat = 'Community Categories';
4539: $catcrs = &mt('Categorize Community');
4540: $assign = &mt('Assign one or more categories to this community.')
4541: } else {
4542: $crscat = 'Course Categories';
4543: $catcrs = &mt('Categorize Course');
4544: $assign = &mt('Assign one or more categories to this course.')
4545: }
1.1 raeburn 4546: my $start_page =
1.9 raeburn 4547: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 4548: {'only_body' => 1,});
4549: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 4550: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 4551: if ($hascats) {
4552: my %currsettings =
4553: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 4554: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
4555: $currsettings{'categories'},$crstype);
4556: if ($cattable eq '') {
4557: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
4558: } else {
4559: $categoriesform .= $assign.'<br /><br />'.
4560: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
4561: $cattable."\n".
4562: '<br /><input type="button" name="changes" value="'.
4563: &mt('Copy to main window').'" '.
4564: 'onclick="javascript:updateCategories()" /></form><br />';
4565: }
1.1 raeburn 4566: } else {
1.12 raeburn 4567: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 4568: }
4569: $r->print($start_page.$categoriesform.$end_page);
4570: return;
4571: }
4572:
1.36 raeburn 4573: sub display_loncaparev_constraints {
4574: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.124 raeburn 4575: my ($reqdmajor,$reqdminor);
1.36 raeburn 4576: my $cid = $env{'request.course.id'};
4577: my $cdom = $env{'course.'.$cid.'.domain'};
4578: my $cnum = $env{'course.'.$cid.'.num'};
4579: my $output;
1.39 raeburn 4580: my %lt = &Apache::lonlocal::texthash (
4581: 'all' => 'all',
4582: 'section/group' => 'section/group',
4583: 'user' => 'user',
4584: );
1.66 raeburn 4585: &Apache::lonrelrequtils::init_global_hashes();
4586: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
4587: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 4588: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 4589: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 4590: }
4591: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 4592: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 4593: @scopeorder = ('all','section/group','user');
1.67 raeburn 4594: my $now = time;
1.36 raeburn 4595: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
4596: if (ref($resourcedata) eq 'HASH') {
4597: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 4598: my %found;
1.66 raeburn 4599: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 4600: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 4601: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
4602: my $value = $resourcedata->{$key};
4603: if ($item eq 'examcode') {
4604: if (&Apache::lonnet::validCODE($value)) {
4605: $value = 'valid';
4606: } else {
4607: $value = '';
4608: }
4609: } elsif ($item eq 'printstartdate') {
1.67 raeburn 4610: if ($value =~ /^\d+$/) {
1.70 raeburn 4611: if ($value > $now) {
4612: $value = 'future';
4613: }
4614: }
4615: } elsif ($item eq 'printenddate') {
4616: if ($value =~ /^\d+$/) {
4617: if ($value < $now) {
4618: $value = 'past';
4619: }
4620: }
4621: }
4622: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
4623: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
4624: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 4625: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 4626: }
4627: }
4628: }
4629: }
1.79 raeburn 4630: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
4631: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 4632: my $value = $resourcedata->{$key};
1.79 raeburn 4633: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 4634: if ($value =~ /$valuematch/) {
4635: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 4636: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 4637: $found{$item}{'rev'} =
1.76 raeburn 4638: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 4639: last;
4640: }
4641: }
4642: }
4643: }
1.76 raeburn 4644: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
4645: my $regexp;
4646: if ($item eq 'maplevelrecurse') {
4647: $regexp = '\.(?:sequence|page)___\(rec\)\.';
4648: }
4649: if ($regexp ne '') {
4650: if ($key =~ /$regexp.*\.(\w+)$/) {
4651: my $name = $1;
4652: my $value = $resourcedata->{$key};
4653: if ($name eq 'type') {
4654: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
4655: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
4656: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
4657: }
4658: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
4659: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
4660: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
4661: $found{$name}{'rev'} =
4662: $Apache::lonnet::needsrelease{'parameter::::'.$item};
4663: }
4664: }
4665: }
1.70 raeburn 4666: foreach my $item (keys(%found)) {
4667: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
4668: my $rev = $found{$item}{'rev'};
4669: my $valname = $found{$item}{'valname'};
1.76 raeburn 4670: my $extra = $found{$item}{'extra'};
1.70 raeburn 4671: my ($middle,$scope,$which,$level,$map,$resource);
4672: my $start = $cid.'.';
4673: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
4674: $middle = $1;
4675: $which = $2;
4676: $scope = 'user';
4677: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
4678: $middle = $1;
4679: $which = $2;
4680: $scope = 'section/group';
4681: } else {
4682: $scope = 'all';
4683: }
4684: my $what="$stdname=$valname";
1.76 raeburn 4685: if ($extra) {
4686: $what .= "<br/>$extra<br />";
4687: }
1.70 raeburn 4688: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
4689: $level = 'general';
4690: if ($scope eq 'all') {
4691: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4692: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
4693: push(@{$fromparam{$rev}{$scope}},$what);
4694: }
4695: } else {
4696: push(@{$fromparam{$rev}{$scope}},$what);
4697: }
4698: } else {
4699: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
4700: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
4701: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4702: }
4703: } else {
4704: push(@{$fromparam{$rev}{$scope}{$which}},$what);
4705: }
4706: }
4707: $rowspan{$rev} ++;
1.76 raeburn 4708: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 4709: $level = 'folder';
4710: $map = $1;
4711: if ($scope eq 'all') {
4712: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
4713: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
4714: push(@{$bymap{$map}{$rev}{$scope}},$what);
4715: }
4716: } else {
4717: push(@{$bymap{$map}{$rev}{$scope}},$what);
4718: }
4719: } else {
4720: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
4721: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
4722: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4723: }
4724: } else {
4725: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
4726: }
4727: }
4728: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
4729: $level = 'resource';
4730: $resource = $1;
4731: if ($scope eq 'all') {
4732: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
4733: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
4734: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4735: }
4736: } else {
4737: push(@{$byresource{$resource}{$rev}{$scope}},$what);
4738: }
4739: } else {
4740: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
4741: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
4742: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
4743: }
4744: } else {
4745: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 4746: }
4747: }
4748: }
4749: }
4750: }
4751: if (keys(%fromparam)) {
4752: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
4753: &Apache::loncommon::start_data_table().
4754: &Apache::loncommon::start_data_table_header_row().
4755: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
4756: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
4757: &Apache::loncommon::end_data_table_header_row();
4758: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 4759: my ($major,$minor) = split(/\./,$rev);
4760: ($reqdmajor,$reqdminor) =
4761: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 4762: $output .= &Apache::loncommon::start_data_table_row().
4763: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
4764: my $newrow;
4765: foreach my $scope (@scopeorder) {
4766: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
4767: if ($newrow) {
4768: $output .= &Apache::loncommon::continue_data_table_row();
4769: }
1.39 raeburn 4770: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 4771: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
4772: $output .= '<td>'.$which.'</td><td>'.
4773: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
4774: }
4775: $output .= &Apache::loncommon::end_data_table_row();
4776: $newrow = 1;
4777: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
4778: if ($newrow) {
4779: $output .= &Apache::loncommon::continue_data_table_row();
4780: }
1.39 raeburn 4781: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 4782: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
4783: &Apache::loncommon::end_data_table_row();
4784: $newrow = 1;
4785: }
4786: }
4787: }
4788: $output .= &Apache::loncommon::end_data_table().'<br />';
4789: }
4790: }
4791:
1.66 raeburn 4792: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4793: my $now = time;
4794: if (keys(%comm_blocks) > 0) {
4795: foreach my $block (keys(%comm_blocks)) {
4796: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 4797: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 4798: if (ref($comm_blocks{$block}) eq 'HASH') {
4799: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4800: ' '.&mt('set by [_1]',
4801: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4802: }
4803: next;
4804: } elsif ($block =~ /^(\d+)____(\d+)$/) {
4805: my ($start,$end) = ($1,$2);
4806: next if ($end < $now);
4807: }
4808: if (ref($comm_blocks{$block}) eq 'HASH') {
4809: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
4810: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
4811: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 4812: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 4813: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4814: ' '.
4815: &mt('set by [_1]',
4816: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4817: }
4818: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 4819: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 4820: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
4821: ' '.
4822: &mt('set by [_1]',
4823: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
4824:
4825: }
4826: }
4827: }
4828: }
4829: if (keys(%fromblocks)) {
4830: my %lt = (
4831: docs => 'Content blocking',
4832: printout => 'Printout generation',
4833: timer => 'Timed quiz trigger',
4834: );
4835: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
4836: &Apache::loncommon::start_data_table().
4837: &Apache::loncommon::start_data_table_header_row().
4838: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
4839: '<th>'.&mt('Event(s)').'</th>'.
4840: &Apache::loncommon::end_data_table_header_row();
4841: foreach my $type ('docs','printout','timer') {
4842: if (ref($fromblocks{$type}) eq 'HASH') {
4843: foreach my $rev (keys(%{$fromblocks{$type}})) {
4844: my ($major,$minor) = split(/\./,$rev);
1.124 raeburn 4845: ($reqdmajor,$reqdminor) =
1.66 raeburn 4846: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
4847: $output .= &Apache::loncommon::start_data_table_row().
4848: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
4849: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
4850: $output .= $event.'<br />';
4851: }
4852: $output =~ s{\Q<br />\E$}{};
4853: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4854: }
4855: }
4856: }
4857: $output .= &Apache::loncommon::end_data_table().'<br />';
4858: }
4859: }
4860:
1.36 raeburn 4861: if (defined($navmap)) {
4862: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 4863: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 4864: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 4865: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 4866: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 4867: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
4868: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
4869: my $valanon=&get_param_description($stdtype,'anonsurvey');
4870: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 4871: my %checkedrev;
1.85 raeburn 4872: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 4873: my @parts = @{$res->parts()};
4874: my $symb = $res->symb();
4875: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 4876: if ($res->is_tool()) {
4877: my $rev = $rev_exttool;
4878: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
4879: $allmaps{$enclosing_map} = 1;
4880: next;
4881: }
1.36 raeburn 4882: foreach my $part (@parts) {
4883: if (exists($anonsubms{$symb."\0".$part})) {
4884: my $rev = $rev_anonsurv;
4885: my $what="$stdname=$valanon";
4886: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4887: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4888: push(@{$bysubmission{$symb}{$rev}},$what);
4889: }
4890: } else {
4891: push(@{$bysubmission{$symb}{$rev}},$what);
4892: }
4893: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4894: unless ($checkedrev{'anonsurvey'}) {
4895: my ($major,$minor) = split(/\./,$rev);
4896: ($reqdmajor,$reqdminor) =
4897: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4898: $reqdmajor,$reqdminor);
4899: $checkedrev{'anonsurvey'} = 1;
4900: }
1.36 raeburn 4901: }
4902: if (exists($randtrysubms{$symb."\0".$part})) {
4903: my $rev = $rev_randtry;
4904: my $what="$stdname=$valrandtry";
4905: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
4906: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
4907: push(@{$bysubmission{$symb}{$rev}},$what);
4908: }
4909: } else {
4910: push(@{$bysubmission{$symb}{$rev}},$what);
4911: }
4912: $allmaps{$enclosing_map} = 1;
1.66 raeburn 4913: unless ($checkedrev{'randomizetry'}) {
4914: my ($major,$minor) = split(/\./,$rev);
4915: ($reqdmajor,$reqdminor) =
4916: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4917: $reqdmajor,$reqdminor);
4918: $checkedrev{'randomizetry'} = 1;
4919: }
1.36 raeburn 4920: }
4921: }
4922: my %responses = $res->responseTypes();
4923: foreach my $key (keys(%responses)) {
1.66 raeburn 4924: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
4925: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
4926: unless ($checkedrev{$key}) {
4927: my ($major,$minor) = split(/\./,$rev);
4928: ($reqdmajor,$reqdminor) =
4929: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
4930: $reqdmajor,$reqdminor);
4931: $checkedrev{$key} = 1;
1.124 raeburn 4932: }
1.66 raeburn 4933: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 4934: $allmaps{$enclosing_map} = 1;
4935: }
4936: }
4937: }
4938: if (keys(%byresource) > 0) {
4939: foreach my $symb (keys(%byresource)) {
4940: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
4941: $allmaps{$map} = 1;
4942: }
4943: }
4944: if (keys(%bymap) > 0) {
4945: foreach my $map (keys(%bymap)) {
4946: $allmaps{$map} = 1;
4947: }
4948: }
4949: foreach my $map (keys(%allmaps)) {
4950: my $mapres = $navmap->getResourceByUrl($map);
4951: if (ref($mapres)) {
1.68 raeburn 4952: my $mapsymb = $mapres->symb();
4953: $toshow{$mapsymb} = 1;
1.36 raeburn 4954: my $pcslist = $mapres->map_hierarchy();
4955: if ($pcslist ne '') {
4956: foreach my $pc (split(/,/,$pcslist)) {
4957: my $res = $navmap->getByMapPc($pc);
4958: if (ref($res)) {
4959: my $symb = $res->symb();
4960: unless ($symb eq '______') {
4961: $toshow{$symb} = 1;
4962: }
4963: }
4964: }
4965: }
4966: }
4967: }
4968: }
1.117 raeburn 4969: my $supptools = &Apache::lonnet::count_supptools($cnum,$cdom,1,1);
1.36 raeburn 4970: my $mapres_header = '<h4>'.
4971: &mt('Requirements for specific folders or resources').
4972: '</h4>';
4973: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4974: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4975: $output .= $mapres_header;
4976: }
4977: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4978: my $title = 'Version Constraints';
4979: my $start_page =
4980: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4981: $r->print($start_page.$top_header);
4982: if ($output) {
4983: $r->print($output);
1.86 raeburn 4984: if (defined($navmap) || $supptools) {
1.36 raeburn 4985: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4986: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4987: }
4988: $r->print('<br /><br />');
4989: } else {
4990: $r->print('<p class="LC_info">'.
4991: &mt('No version requirements from resource content or settings.').
4992: '</p>');
4993: }
4994: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4995: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4996: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4997: return 1;
4998: }
1.36 raeburn 4999: return;
5000: }
5001:
5002: sub show_contents_view {
1.39 raeburn 5003: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 5004: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
5005: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
5006: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
5007: my $showmaincontent;
5008: if ((ref($navmap)) &&
5009: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
5010: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
5011: (keys(%{$bycrsrestype}) > 0))) {
5012: $showmaincontent = 1;
5013: }
5014: if ($showmaincontent || $supptools) {
5015: $r->print(&Apache::loncommon::start_data_table());
5016: }
5017: if ($showmaincontent) {
5018: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 5019: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 5020: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 5021: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5022: '<th>'.&mt('Attribute/Setting').'</th>'.
5023: &Apache::loncommon::end_data_table_header_row().
5024: &Apache::loncommon::start_data_table_row().
1.58 raeburn 5025: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 5026: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
5027: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5028: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
5029: my $curRes;
5030: my $depth = 0;
5031: my %parent = ();
5032: my $startcount = 5;
5033: my $lastcontainer = $startcount;
5034: while ($curRes = $it->next()) {
5035: if ($curRes == $it->BEGIN_MAP()) {
5036: $depth++;
5037: $parent{$depth}= $lastcontainer;
5038: }
5039: if ($curRes == $it->END_MAP()) {
5040: $depth--;
5041: $lastcontainer = $parent{$depth};
5042: }
5043: my $indent;
5044: for (my $i=0; $i<$depth; $i++) {
5045: $indent.= $whitespace;
5046: }
5047: if (ref($curRes)) {
5048: my $symb = $curRes->symb();
5049: my $ressymb = $symb;
5050: my $srcf = $curRes->src();
5051: my $title = &Apache::lonnet::gettitle($srcf);
5052: if (($curRes->is_sequence()) || ($curRes->is_page())) {
5053: next unless($toshow->{$symb});
5054: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
5055: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5056: if ($curRes->is_page()) {
5057: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
5058: }
5059: my $rowspan = 1;
5060: if (ref($bymap->{$url}) eq 'HASH') {
5061: $rowspan = scalar(keys(%{$bymap->{$url}}));
5062: }
5063: $r->print(&Apache::loncommon::start_data_table_row().
5064: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 5065: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 5066: $r->print(&Apache::loncommon::end_data_table_row());
5067: } else {
5068: my $rowspan;
5069: if (ref($byresource->{$symb}) eq 'HASH') {
5070: $rowspan += scalar(keys(%{$byresource->{$symb}}));
5071: }
5072: if (ref($bysubmission->{$symb}) eq 'HASH') {
5073: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
5074: }
5075: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5076: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
5077: }
1.85 raeburn 5078: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5079: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
5080: }
1.36 raeburn 5081: next if (!$rowspan);
5082: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
5083: &mt('Problem').'" />';
5084: $r->print(&Apache::loncommon::start_data_table_row().
5085: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
5086: my $newrow;
5087: if (ref($byresource->{$symb}) eq 'HASH') {
5088: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
5089: if ($newrow) {
5090: $r->print(&Apache::loncommon::continue_data_table_row());
5091: }
5092: $r->print('<td valign="middle">'.$rev.'</td><td>');
5093: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
5094: $r->print('<table border="0">');
5095: foreach my $scope (@{$scopeorder}) {
5096: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5097: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5098: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
5099: $r->print('<td>'.$which.'</td><td>'.
5100: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
5101: '</td>');
5102: }
5103: $r->print('</tr>');
5104: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5105: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 5106: '<td> </td><td>'.
5107: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
5108: }
5109: }
5110: $r->print('</table>');
5111: }
5112: $r->print('</td>');
5113: $r->print(&Apache::loncommon::end_data_table_row());
5114: $newrow = 1;
5115: }
5116: }
5117: if (ref($bysubmission->{$symb}) eq 'HASH') {
5118: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
5119: if ($newrow) {
5120: $r->print(&Apache::loncommon::continue_data_table_row());
5121: }
5122: $r->print('<td>'.$rev.'</td><td>');
5123: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
5124: $r->print(&mt('Submissions to: ').' '.
5125: join(', ',@{$bysubmission->{$symb}{$rev}}));
5126: }
5127: $r->print('</td>');
5128: $r->print(&Apache::loncommon::end_data_table_row());
5129: $newrow = 1;
5130: }
5131: }
5132: if (ref($byresponsetype->{$symb}) eq 'HASH') {
5133: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
5134: if ($newrow) {
5135: $r->print(&Apache::loncommon::continue_data_table_row());
5136: }
5137: $r->print('<td>'.$rev.'</td><td>');
5138: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
5139: $r->print(&mt('Response Type(s): ').' '.
5140: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
5141: }
5142: $r->print('</td>');
5143: }
5144: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 5145: $newrow = 1;
5146: }
5147: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
5148: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
5149: if ($newrow) {
5150: $r->print(&Apache::loncommon::continue_data_table_row());
5151: }
5152: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
5153: }
1.86 raeburn 5154: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 5155: }
5156: }
5157: }
5158: }
1.86 raeburn 5159: }
5160: if ($supptools) {
5161: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
5162: $r->print(&Apache::loncommon::start_data_table_header_row().
5163: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
5164: '<th>'.&mt('Resource Type').'</th>'.
5165: &Apache::loncommon::end_data_table_header_row().
5166: &Apache::loncommon::start_data_table_row().
5167: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
5168: '<td valign="middle">'.
5169: $Apache::lonrelrequtils::exttool{'major'}.'.'.
5170: $Apache::lonrelrequtils::exttool{'minor'}.
5171: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
5172: $supptools).'</td>'.
5173: &Apache::loncommon::end_data_table_row());
5174: }
5175: if ($showmaincontent || $supptools) {
1.36 raeburn 5176: $r->print(&Apache::loncommon::end_data_table());
5177: }
1.66 raeburn 5178: return;
1.36 raeburn 5179: }
5180:
5181: sub releases_by_map {
1.39 raeburn 5182: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 5183: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.124 raeburn 5184: my $newrow = 0;
1.36 raeburn 5185: if (ref($bymap->{$url}) eq 'HASH') {
5186: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 5187: if ($newrow) {
5188: $r->print(&Apache::loncommon::end_data_table_row().
5189: &Apache::loncommon::continue_data_table_row());
5190: }
1.36 raeburn 5191: $r->print('<td valign="middle">'.$rev.'</td><td>');
5192: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
5193: $r->print('<table border="0">');
5194: foreach my $scope (@{$scopeorder}) {
5195: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 5196: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 5197: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
5198: $r->print('<td>'.$which.'</td><td>'.
5199: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
5200: '</td>');
5201: }
5202: $r->print('</tr>');
5203: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 5204: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 5205: '</td><td> </td><td>'.
5206: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
5207: }
5208: }
5209: $r->print('</table>');
5210: }
5211: $r->print('</td>');
1.73 raeburn 5212: $newrow = 1;
1.36 raeburn 5213: }
5214: } else {
5215: $r->print('<td colspan="2"> </td>');
5216: }
5217: return;
5218: }
5219:
5220: sub get_param_description {
1.70 raeburn 5221: my ($stdtype,$value,$regexp) = @_;
5222: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 5223: if ($stdtype =~ /^string/) {
5224: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
5225: } elsif ($stdtype eq 'date_interval') {
5226: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
5227: }
1.70 raeburn 5228: if ($regexp) {
1.74 raeburn 5229: if ($stdtype =~ /^string/) {
5230: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
5231: } elsif ($stdtype eq 'date_interval') {
5232: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
5233: }
1.70 raeburn 5234: if (ref($parammatches) eq 'ARRAY') {
5235: @possibles = @{$parammatches};
5236: } else {
5237: undef($regexp);
5238: $name = $value;
5239: }
5240: }
5241: unless ($regexp) {
5242: $name = $value;
5243: if (ref($paramstrings) eq 'ARRAY') {
5244: @possibles = @{$paramstrings};
5245: } else {
1.76 raeburn 5246: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
5247: if ($name == 0) {
5248: $name = &mt('Never');
5249: } elsif (($name ne '') && ($name !~ /\D/)) {
5250: $name = &Apache::lonlocal::locallocaltime($name);
5251: }
5252: }
1.70 raeburn 5253: return $name;
5254: }
1.36 raeburn 5255: }
1.70 raeburn 5256: foreach my $possibilities (@possibles) {
1.36 raeburn 5257: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 5258: my $gotregexmatch = '';
5259: if ($regexp) {
5260: last if ($gotregexmatch);
5261: my ($item,$pattern) = @{ $possibilities };
5262: if ($value =~ /$pattern/) {
5263: if (ref($paramstrings) eq 'ARRAY') {
5264: foreach my $possibles (@{$paramstrings}) {
5265: next unless (ref($possibles) eq 'ARRAY');
5266: my ($thing,$description) = @{$possibles};
5267: if ($thing eq $item) {
5268: $name = $description;
5269: $gotregexmatch = 1;
5270: last;
5271: }
5272: }
5273: last if ($gotregexmatch);
5274: }
5275: }
5276: } else {
5277: my ($thing,$description) = @{ $possibilities };
5278: if ($thing eq $value) {
5279: $name = $description;
5280: last;
5281: }
1.36 raeburn 5282: }
5283: }
5284: return $name;
5285: }
5286:
1.66 raeburn 5287: sub update_releasereq {
5288: my $readmap = 1;
5289: my $getrelreq = 1;
5290: if (ref($modified_courses) eq 'ARRAY') {
5291: foreach my $item (@{$modified_courses}) {
5292: if (ref($item) eq 'ARRAY') {
5293: my ($cdom,$cnum,$chome,$crstype) = @{$item};
5294: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
5295: $chome,$crstype,$cdom.'_'.$cnum,
5296: $readmap,$getrelreq);
5297: }
5298: }
5299: $modified_courses = [];
5300: }
5301: undef($registered_cleanup);
5302: return;
5303: }
5304:
1.25 raeburn 5305: sub show_autocoowners {
5306: my (@currcoown) = @_;
1.56 raeburn 5307: 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 5308: if (@currcoown > 0) {
5309: $output .= '<br />'.&mt('Current co-owners are:').' '.
5310: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5311: } else {
5312: $output .= '<br />'.&mt('Currently no co-owners.');
5313: }
5314: return $output;
5315: }
5316:
5317: sub coowner_invitations {
1.80 raeburn 5318: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5319: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5320: my $pendingcoowners =
5321: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5322: if ($pendingcoowners) {
5323: @pendingcoown = split(',',$pendingcoowners);
5324: }
1.80 raeburn 5325: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5326: @currcoown = @{$currcoownref};
1.80 raeburn 5327: }
5328: my $disabled;
5329: if ($noedit) {
5330: $disabled = ' disabled="disabled"';
5331: }
1.25 raeburn 5332: my $ccrole = 'cc';
5333: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5334: foreach my $key (sort(keys(%ccroles))) {
5335: my ($ccname,$ccdom,$role) = split(':',$key);
5336: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5337: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5338: push(@othercoords,$ccname.':'.$ccdom);
5339: }
5340: }
5341: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5342: if ($coowner_rows) {
5343: $output .= &Apache::loncommon::start_data_table();
5344: if (@currcoown) {
5345: $output .= &Apache::loncommon::start_data_table_row().
5346: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5347: foreach my $person (@currcoown) {
5348: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5349: $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 5350: }
5351: $output .= '</td>'.
5352: &Apache::loncommon::end_data_table_row();
5353: }
5354: if ($pendingcoowners) {
5355: $output .= &Apache::loncommon::start_data_table_row().
5356: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5357: foreach my $person (@pendingcoown) {
5358: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5359: $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 5360: }
5361: $output .= '</td>'.
5362: &Apache::loncommon::end_data_table_row();
5363: }
5364: if (@othercoords) {
5365: $output .= &Apache::loncommon::start_data_table_row().
5366: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5367: foreach my $person (@othercoords) {
5368: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5369: $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 5370: }
5371: $output .= '</td>'.
5372: &Apache::loncommon::end_data_table_row();
5373: }
5374: $output .= &Apache::loncommon::end_data_table();
5375: } else {
5376: $output = &mt('There are no coordinators to select as co-owners');
5377: }
5378: return $output;
5379: }
5380:
5381: sub manage_coownership {
1.80 raeburn 5382: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5383: my (@pendingcoown,@currcoown);
1.25 raeburn 5384: my $pendingcoowners =
5385: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5386: if ($pendingcoowners) {
5387: @pendingcoown = split(',',$pendingcoowners);
5388: }
1.80 raeburn 5389: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5390: @currcoown = @{$currcoownref};
1.80 raeburn 5391: }
5392: my $disabled;
5393: if ($noedit) {
5394: $disabled = ' disabled="disabled"';
5395: }
1.25 raeburn 5396: my ($is_coowner,$is_pending,$output);
5397: my $uname = $env{'user.name'};
5398: my $udom = $env{'user.domain'};
5399: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5400: $is_coowner = 1;
5401: }
5402: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5403: $is_pending = 1;
5404: }
5405: if (@currcoown && ($is_coowner || $is_pending)) {
5406: $output = &Apache::loncommon::start_data_table();
5407: }
5408: if (@currcoown) {
5409: if ($is_coowner || $is_pending) {
5410: $output .= &Apache::loncommon::start_data_table().
5411: &Apache::loncommon::start_data_table_row().'<td>';
5412: }
5413: $output .= &mt('Current co-owners are:').' '.
5414: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5415: if ($is_coowner || $is_pending) {
5416: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5417: }
5418: }
5419: if ($is_coowner || $is_pending) {
5420: if (@currcoown) {
5421: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5422: }
5423: $output .= '<span class="LC_nobreak">';
5424: if ($is_coowner) {
1.90 raeburn 5425: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5426: } else {
1.90 raeburn 5427: $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).
5428: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5429: }
5430: $output .= '</span>';
5431: if (@currcoown) {
5432: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5433: }
5434: }
5435: if (@currcoown && ($is_coowner || $is_pending)) {
5436: $output .= &Apache::loncommon::end_data_table();
5437: }
5438: return $output;
5439: }
5440:
1.1 raeburn 5441: sub print_localization {
1.80 raeburn 5442: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5443: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5444: return;
5445: }
5446: my %items = (
5447: languages => {
1.17 faziophi 5448: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5449: &mt("(overrides individual user preference)"),
1.1 raeburn 5450: input => 'selectbox',
5451: },
5452: timezone => {
1.17 faziophi 5453: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5454: input => 'selectbox',
5455: },
5456: datelocale => {
1.17 faziophi 5457: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5458: input => 'selectbox',
5459: },
5460: );
1.80 raeburn 5461: my ($datatable,$disabled);
1.1 raeburn 5462: my $count = 0;
1.80 raeburn 5463: if ($noedit) {
5464: $disabled = ' disabled="disabled"';
5465: }
1.1 raeburn 5466: foreach my $item (@{$ordered}) {
5467: $count ++;
1.56 raeburn 5468: my $colspan;
5469: unless ($item eq 'languages') {
1.80 raeburn 5470: $colspan = 2;
1.56 raeburn 5471: }
5472: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5473: if ($item eq 'timezone') {
5474: my $includeempty = 1;
5475: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5476: my $onchange;
5477: unless ($noedit) {
5478: $onchange = ' onchange="javascript:toggleTimeZone();"';
5479: }
5480: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5481: $datatable .=
1.115 raeburn 5482: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5483: $includeempty,$id,$disabled);
5484: my $tzsty = 'none';
5485: if ($timezone ne '') {
5486: $tzsty = 'block';
5487: }
5488: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5489: '<span class="LC_nobreak">'.
5490: &mt('Override individual user preference?').
5491: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5492: '</span></div>';
1.1 raeburn 5493: } elsif ($item eq 'datelocale') {
5494: my $includeempty = 1;
5495: my $locale_obj = &Apache::lonlocal::getdatelocale();
5496: my $currdatelocale;
5497: if (ref($locale_obj)) {
5498: $currdatelocale = $locale_obj->id();
5499: }
5500: $datatable .=
5501: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5502: undef,$includeempty,$disabled);
1.1 raeburn 5503: } else {
5504: if ($settings->{$item} eq '') {
1.124 raeburn 5505: unless ($noedit) {
1.80 raeburn 5506: $datatable .= '</td><td align="right">'.
5507: &Apache::loncommon::select_language('languages_0','',1);
5508: }
1.1 raeburn 5509: } else {
5510: my $num = 0;
1.3 raeburn 5511: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5512: $datatable .= '</td><td align="right"><br />'.
5513: &Apache::loncommon::start_data_table();
1.1 raeburn 5514: if (@languages > 0) {
1.3 raeburn 5515: my %langchoices = &get_lang_choices();
1.1 raeburn 5516: foreach my $lang (@languages) {
5517: my $showlang = $lang;
1.3 raeburn 5518: if (exists($langchoices{$lang})) {
5519: $showlang = $langchoices{$lang};
1.1 raeburn 5520: }
5521: $datatable .=
5522: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5523: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5524: &mt('Language:').'<b> '.$showlang.
5525: '</b><input type="hidden" name="languages_'.$num.
5526: '" value="'.$lang.'" /></span><br />'.
5527: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5528: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5529: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5530: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5531: $num ++;
5532: }
5533: }
1.80 raeburn 5534: unless ($noedit) {
5535: $datatable .=
5536: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5537: '<td align="left"><span class="LC_nobreak">'.
5538: &mt('Additional language:'). '</span><br />'.
5539: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5540: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5541: '</td>'.&Apache::loncommon::end_data_table_row();
1.124 raeburn 5542: }
5543: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5544: }
5545: }
5546: $datatable .= &item_table_row_end();
5547: }
5548: $$rowtotal += scalar(@{$ordered});
5549: return $datatable;
5550: }
5551:
1.3 raeburn 5552: sub get_lang_choices {
5553: my %langchoices;
5554: foreach my $id (&Apache::loncommon::languageids()) {
5555: my $code = &Apache::loncommon::supportedlanguagecode($id);
5556: if ($code) {
5557: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5558: }
5559: }
5560: return %langchoices;
5561: }
5562:
1.1 raeburn 5563: sub print_feedback {
1.80 raeburn 5564: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5565: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5566: return;
5567: }
5568: my %items = (
1.3 raeburn 5569: 'question.email' => {
5570: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5571: input => 'textbox',
5572: size => '50',
5573: },
5574:
1.3 raeburn 5575: 'comment.email' => {
5576: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5577: input => 'textbox',
5578: size => '50',
5579: },
5580:
1.3 raeburn 5581: 'policy.email' => {
5582: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5583: input => 'textbox',
5584: size => '50',
5585: },
5586: );
5587: my $datatable;
5588: my $count = 0;
5589: my ($cnum) = &get_course();
5590: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5591: my @sections = sort( { $a <=> $b } keys(%sections));
5592: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5593: currone => 'Current recipient:',
5594: currmult => 'Current recipients:',
5595: add => 'Additional recipient:',
5596: del => 'Delete?',
5597: sec => 'Sections:',
1.1 raeburn 5598: );
1.80 raeburn 5599: my $disabled;
5600: if ($noedit) {
5601: $disabled = ' disabled="disabled"';
5602: }
1.1 raeburn 5603: foreach my $item (@{$ordered}) {
5604: $count ++;
1.20 faziophi 5605: if ($position eq 'top') {
5606: $datatable .= &item_table_row_start($items{$item}{text},$count);
5607: } else {
1.56 raeburn 5608: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5609: }
1.1 raeburn 5610: if ($position eq 'top') {
5611: my $includeempty = 0;
1.94 raeburn 5612: $datatable .= '</td><td align="right">'.
5613: &user_table($cdom,$item,\@sections,
1.80 raeburn 5614: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5615: } else {
1.3 raeburn 5616: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5617: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5618: }
5619: $datatable .= &item_table_row_end();
5620: }
5621: $$rowtotal += scalar(@{$ordered});
5622: return $datatable;
5623: }
5624:
5625: sub user_table {
1.80 raeburn 5626: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5627: my $output;
5628: if ($currvalue eq '') {
1.80 raeburn 5629: unless ($noedit) {
5630: $output .= &select_recipient($item,'0',$cdom,$sections);
5631: }
1.1 raeburn 5632: } else {
5633: my $num = 0;
5634: my @curr = split(/,/,$currvalue);
1.56 raeburn 5635: $output .= '<table class="LC_data_table">';
1.1 raeburn 5636: my ($currusers);
1.80 raeburn 5637: my $disabled;
5638: if ($noedit) {
5639: $disabled = ' disabled="disabled"';
5640: }
1.1 raeburn 5641: foreach my $val (@curr) {
5642: next if ($val eq '');
5643: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5644: my @selsec;
5645: if ($seclist) {
5646: $seclist =~ s/(^\(|\)$)//g;
5647: @selsec = split(/\s*;\s*/,$seclist);
5648: }
5649: $currusers .= '<tr>'.
5650: '<td valign="top"><span class="LC_nobreak">'.
5651: '<label><input type="checkbox" '.
1.80 raeburn 5652: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5653: $lt->{'del'}.'</label>'.
5654: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5655: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5656: &Apache::loncommon::aboutmewrapper(
5657: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5658: $uname,$udom,'aboutuser');
5659: if (ref($sections) eq 'ARRAY') {
5660: if (@{$sections}) {
5661: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5662: &select_sections($item,$num,$sections,
1.80 raeburn 5663: \@selsec,$noedit);
1.1 raeburn 5664: }
5665: }
5666: $currusers .= '</span></td></tr>';
5667: $num ++;
5668: }
5669: if ($num) {
1.10 raeburn 5670: $output .= '<tr>'.
1.1 raeburn 5671: '<td align="left"><i>';
1.20 faziophi 5672: if ($num == 1) {
1.1 raeburn 5673: $output .= $lt->{'currone'};
5674: } else {
1.21 raeburn 5675: $output .= $lt->{'currmult'};
1.1 raeburn 5676: }
5677: $output .= '</i><br />'.
5678: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5679: '</tr>';
1.1 raeburn 5680: }
1.80 raeburn 5681: unless ($noedit) {
5682: $output .=
5683: '<tr>'.
1.1 raeburn 5684: '<td align="left"><span class="LC_nobreak"><i>'.
5685: $lt->{'add'}.'</i></span><br />'.
5686: &select_recipient($item,$num,$cdom,$sections).
5687: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5688: '</td></tr>';
5689: }
5690: $output .= '</table>';
1.1 raeburn 5691: }
5692: return $output;
5693: }
5694:
5695: sub select_recipient {
5696: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5697: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5698: my $selectlink =
5699: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5700: $item.'_udom_'.$num,'only');
1.1 raeburn 5701: my $output =
1.10 raeburn 5702: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5703: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5704: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5705: if (ref($sections) eq 'ARRAY') {
5706: if (@{$sections}) {
5707: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5708: &select_sections($item,$num,$sections,$selected).'</td>';
5709: }
5710: }
5711: $output .= '<td valign="top">'.
5712: $selectlink.'</td></tr></table>';
5713: return $output;
5714: }
5715:
5716: sub select_sections {
1.127 raeburn 5717: my ($item,$num,$sections,$selected,$noedit,$allval) = @_;
1.80 raeburn 5718: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5719: if (ref($selected) eq 'ARRAY') {
5720: @currsecs = @{$selected};
5721: }
5722: if (!@currsecs) {
5723: $allsec = ' selected="selected"';
5724: }
1.80 raeburn 5725: if ($noedit) {
5726: $disabled = ' disabled="disabled"';
5727: }
1.1 raeburn 5728: if (ref($sections) eq 'ARRAY') {
5729: if (@{$sections}) {
5730: my $mult;
5731: if (@{$sections} > 1) {
5732: $mult = ' multiple="multiple"';
1.127 raeburn 5733: my $size;
1.1 raeburn 5734: if (@{$sections} > 3) {
1.127 raeburn 5735: $size = 4;
5736: } else {
5737: $size = 1 + scalar(@{$sections});
1.1 raeburn 5738: }
1.127 raeburn 5739: $mult .= ' size="'.$size.'"';
5740: }
5741: my $name = $item.'_sections';
5742: unless ($item eq 'hidetotals') {
5743: $name .= '_'.$num;
1.1 raeburn 5744: }
1.127 raeburn 5745: $output = '<select name="'.$name.'"'.$mult.$disabled.'>'.
5746: ' <option value="'.$allval.'"'.$allsec.'>'.&mt('All').'</option>';
1.1 raeburn 5747: foreach my $sec (@{$sections}) {
5748: my $is_sel;
5749: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
1.127 raeburn 5750: $is_sel = ' selected="selected"';
1.1 raeburn 5751: }
5752: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5753: }
5754: $output .= '</select>';
5755: }
5756: }
5757: return $output;
5758: }
5759:
5760: sub print_discussion {
1.80 raeburn 5761: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5762: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5763: return;
5764: }
5765: my %items = (
5766: 'plc.roles.denied' => {
1.10 raeburn 5767: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5768: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5769: &mt('(role-based)'),
1.1 raeburn 5770: input => 'checkbox',
5771: },
5772:
5773: 'plc.users.denied' => {
1.3 raeburn 5774: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5775: &mt('(specific user(s))'),
1.1 raeburn 5776: input => 'checkbox',
5777: },
5778:
5779: 'pch.roles.denied' => {
1.10 raeburn 5780: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5781: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5782: &mt('(role-based)'),
1.1 raeburn 5783: input => 'checkbox',
5784: },
5785:
5786: 'pch.users.denied' => {
1.3 raeburn 5787: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5788: &mt('(specific user(s))'),
1.1 raeburn 5789: input => 'checkbox',
5790: },
1.77 raeburn 5791:
5792: 'pac.roles.denied' => {
5793: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5794: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5795: &mt('(role-based)'),
5796: input => 'checkbox',
5797: },
5798:
5799: 'pac.users.denied' => {
5800: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5801: &mt('(specific user(s))'),
5802: input => 'checkbox',
5803: },
5804:
1.1 raeburn 5805: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5806: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5807: input => 'radio',
5808: },
5809:
5810: 'allow_discussion_post_editing' => {
1.3 raeburn 5811: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5812: input => 'checkbox',
5813: },
1.50 raeburn 5814: 'discussion_post_fonts' => {
5815: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5816: input => 'textbox',
5817: size => '20',
5818: },
1.1 raeburn 5819: );
5820: my $datatable;
5821: my $count;
5822: my ($cnum) = &get_course();
5823: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5824: my @sections = sort( { $a <=> $b } keys(%sections));
5825: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5826: currone => 'Disallowed:',
5827: currmult => 'Disallowed:',
5828: add => 'Disallow more:',
5829: del => 'Delete?',
5830: sec => 'Sections:',
1.1 raeburn 5831: );
5832: foreach my $item (@{$ordered}) {
5833: $count ++;
1.56 raeburn 5834: my $colspan;
5835: if ($item eq 'allow_limited_html_in_feedback') {
5836: $colspan = 2;
1.124 raeburn 5837: }
1.56 raeburn 5838: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5839: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5840: $datatable .= '</td><td align="right">'.
1.80 raeburn 5841: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5842: '</table>';
5843: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5844: $datatable .= '</td><td align="right">'.
5845: &user_table($cdom,$item,undef,
1.80 raeburn 5846: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5847: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5848: $datatable .= '</td><td align="right">'.
1.80 raeburn 5849: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5850: '</table>';
5851: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5852: $datatable .= '</td><td align="right">'.
5853: &user_table($cdom,$item,undef,
1.80 raeburn 5854: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5855: } elsif ($item eq 'pac.roles.denied') {
5856: $datatable .= '</td><td align="right">'.
1.80 raeburn 5857: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5858: '</table>';
5859: } elsif ($item eq 'pac.users.denied') {
5860: $datatable .= '</td><td align="right">'.
5861: &user_table($cdom,$item,undef,
1.80 raeburn 5862: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5863: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5864: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5865: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5866: $datatable .= '</td><td align="right"><br />'.
5867: &Apache::loncommon::start_data_table().
1.1 raeburn 5868: &Apache::loncommon::start_data_table_row().
5869: '<th align="left">'.&mt('Role').'</th><th>'.
5870: &mt('Sections').'</th>'.
5871: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5872: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5873: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5874: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5875: $datatable .= '</td><td align="right"><br />'.
5876: &Apache::loncommon::start_data_table().
1.50 raeburn 5877: &Apache::loncommon::start_data_table_row().
5878: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5879: '<th align="center">'.&mt('font-size').'</th>'.
5880: '<th align="center">'.&mt('font-weight').'</th>'.
5881: '<th align="center">'.&mt('font-style').'</th>'.
1.124 raeburn 5882: '<th align="center">'.&mt('Other css').'</th>'.
1.50 raeburn 5883: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5884: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5885: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5886: }
5887: $datatable .= &item_table_row_end();
5888: }
5889: $$rowtotal += scalar(@{$ordered});
5890: return $datatable;
5891: }
5892:
5893: sub role_checkboxes {
1.80 raeburn 5894: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5895: my @roles = ('st','ad','ta','ep','in');
5896: if ($crstype eq 'Community') {
5897: push(@roles,'co');
5898: } else {
5899: push(@roles,'cc');
5900: }
1.1 raeburn 5901: my $output;
5902: my (@current,@curr_roles,%currsec,@sections);
5903: if ($showsections) {
5904: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5905: @sections = sort( { $a <=> $b } keys(%sections));
5906: }
5907: if (ref($settings) eq 'HASH') {
5908: if ($settings->{$item}) {
5909: @current = split(',',$settings->{$item});
5910: if ($showsections) {
5911: foreach my $role (@current) {
5912: if ($role =~ /:/) {
5913: my ($trole,$sec) = split(':',$role);
5914: push(@curr_roles,$trole);
5915: if (ref($currsec{$trole}) eq 'ARRAY') {
5916: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5917: push(@{$currsec{$trole}},$sec);
5918: }
1.3 raeburn 5919: } else {
5920: $currsec{$trole} = [$sec];
1.1 raeburn 5921: }
5922: } else {
5923: push(@curr_roles,$role);
5924: }
5925: }
5926: @current = @curr_roles;
5927: }
5928: }
5929: }
5930: my $numinrow = 3;
5931: my $count = 0;
1.80 raeburn 5932: my $disabled;
5933: if ($noedit) {
1.124 raeburn 5934: $disabled = ' disabled="disabled"';
1.80 raeburn 5935: }
1.1 raeburn 5936: foreach my $role (@roles) {
5937: my $checked = '';
5938: if (grep(/^\Q$role\E$/,@current)) {
5939: $checked = ' checked="checked" ';
5940: }
1.9 raeburn 5941: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5942: if ($showsections) {
5943: $output .= &Apache::loncommon::start_data_table_row();
5944: } else {
5945: my $rem = $count%($numinrow);
5946: if ($rem == 0) {
5947: if ($count > 0) {
5948: $output .= '</tr>';
5949: }
5950: $output .= '<tr>';
5951: }
5952: }
1.30 raeburn 5953: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5954: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5955: $plrole.'</label></span></td>';
5956: if ($showsections) {
5957: $output .= '<td align="left">'.
1.80 raeburn 5958: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5959: '</td></tr>';
5960: }
5961: $count ++;
5962: }
5963: my %adv_roles =
5964: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5965: my $total = @roles;
5966: foreach my $role (sort(keys(%adv_roles))) {
5967: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5968: my $rolename = $3;
5969: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5970: my $checked = '';
5971: if (grep(/^\Q$value\E$/,@current)) {
5972: $checked = ' checked="checked" ';
5973: }
5974: if ($showsections) {
5975: $output .= &Apache::loncommon::start_data_table_row();
5976: } else {
5977: my $rem = $count%($numinrow);
5978: if ($rem == 0) {
5979: if ($count > 0) {
5980: $output .= '</tr>';
5981: }
5982: $output .= '<tr>';
5983: }
5984: }
1.30 raeburn 5985: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5986: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5987: '</label></span></td>';
5988: if ($showsections) {
5989: $output .= '<td>'.
1.80 raeburn 5990: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5991: '</td>'.&Apache::loncommon::end_data_table_row();
5992: }
5993: $total ++;
5994: $count ++;
5995: }
5996: }
5997: if (!$showsections) {
5998: my $rem = $total%($numinrow);
5999: my $colsleft = $numinrow - $rem;
6000: if ($colsleft > 1 ) {
6001: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6002: ' </td>';
6003: } elsif ($colsleft == 1) {
6004: $output .= '<td class="LC_left_item"> </td>';
6005: }
6006: $output .= '</tr>';
6007: }
6008: return $output;
6009: }
6010:
1.50 raeburn 6011: sub set_discussion_fonts {
1.80 raeburn 6012: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 6013: my ($classorder,$classtitles) = &discussion_vote_classes();
6014: my ($styleorder,$styleitems) = &discussion_vote_styles();
6015: my $output;
6016: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 6017: my $disabled;
6018: if ($noedit) {
6019: $disabled = ' disabled="disabled"';
6020: }
1.50 raeburn 6021: foreach my $cat (@{$classorder}) {
6022: my %curr = ();
6023: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
6024: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
6025: $output .= &Apache::loncommon::start_data_table_row().
6026: '<td>'.$classtitles->{$cat}.'</td>';
6027: if (ref($styleorder) eq 'ARRAY') {
6028: foreach my $item (@{$styleorder}) {
6029: $output .= '<td><span class="LC_nobreak">';
6030: my $selitem = $item;
6031: if ($item eq 'size') {
6032: my ($currsize,$currunit);
6033: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
6034: ($currsize,$currunit) = ($1,$2);
6035: $curr{'size'} = $currunit;
6036: }
1.81 raeburn 6037: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 6038: ' ';
6039: $selitem = 'unit';
6040: }
6041: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 6042: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 6043: foreach my $val (@{$styleitems->{$item}}) {
6044: my $sel;
6045: if ($val eq $curr{$item}) {
6046: $sel = ' selected="selected"';
6047: }
6048: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
6049: }
6050: }
6051: }
6052: }
1.80 raeburn 6053: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 6054: }
6055: $output .= &Apache::loncommon::end_data_table_row();
6056: }
6057: return $output;
6058: }
6059:
6060: sub discussion_vote_classes {
6061: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
1.124 raeburn 6062: my %classtitles = &Apache::lonlocal::texthash(
1.50 raeburn 6063: 'twoplus' => 'Two sigma above mean',
6064: 'oneplus' => 'One sigma above mean',
6065: 'zero' => 'Within one sigma of mean',
6066: 'oneminus' => 'One sigma below mean',
6067: 'twominus' => 'Two sigma below mean',
6068: );
6069: return ($classorder,\%classtitles);
6070: }
6071:
6072: sub discussion_vote_styles {
6073: my $styleorder = ['size','weight','style'];
6074: my $styleitems = {
6075: size => ['','px','%','xx-small','x-small','small','medium','large',
6076: 'x-large','xx-large','smaller','larger'],
6077: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
6078: '500','600','700','800','900'],
6079: style => ['','normal','italic','oblique'],
6080: };
6081: return ($styleorder,$styleitems);
6082: }
6083:
1.1 raeburn 6084: sub print_classlists {
1.80 raeburn 6085: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 6086: my @ordered;
6087: if ($position eq 'top') {
6088: @ordered = ('default_enrollment_start_date',
6089: 'default_enrollment_end_date');
1.55 raeburn 6090: if ($crstype eq 'Course') {
6091: push(@ordered,'defaultcredits');
6092: }
1.1 raeburn 6093: } elsif ($position eq 'middle') {
1.56 raeburn 6094: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 6095: } else {
6096: @ordered = ('student_classlist_view',
1.26 raeburn 6097: 'student_classlist_opt_in',
6098: 'student_classlist_portfiles');
1.1 raeburn 6099: }
1.9 raeburn 6100: my %lt;
6101:
6102: if ($crstype eq 'Community') {
6103: %lt = &Apache::lonlocal::texthash (
6104: disabled => 'No viewable membership list',
6105: section => "Membership of viewer's section",
6106: all => 'List of all members',
6107: );
6108: } else {
6109: %lt = &Apache::lonlocal::texthash (
6110: disabled => 'No viewable classlist',
6111: section => "Classlist of viewer's section",
6112: all => 'Classlist of all students',
6113: );
6114: }
6115:
1.1 raeburn 6116: my %items = (
6117: 'default_enrollment_start_date' => {
1.3 raeburn 6118: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 6119: input => 'dates',
6120: },
6121: 'default_enrollment_end_date' => {
1.3 raeburn 6122: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 6123: input => 'dates',
6124: },
1.55 raeburn 6125: 'defaultcredits' => {
6126: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
6127: },
1.124 raeburn 6128:
1.1 raeburn 6129: 'nothideprivileged' => {
1.3 raeburn 6130: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 6131: input => 'checkbox',
6132: },
6133:
1.56 raeburn 6134: 'checkforpriv' => {
6135: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
6136: input => 'selectbox',
6137: },
6138:
1.1 raeburn 6139: 'student_classlist_view' => {
1.3 raeburn 6140: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 6141: input => 'selectbox',
1.9 raeburn 6142: options => \%lt,
1.1 raeburn 6143: order => ['disabled','all','section'],
6144: },
1.26 raeburn 6145: 'student_classlist_opt_in' => {
6146: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 6147: input => 'radio',
6148: },
6149:
6150: 'student_classlist_portfiles' => {
1.3 raeburn 6151: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 6152: input => 'radio',
6153: },
6154: );
6155: unless (($settings->{'student_classlist_view'} eq 'all') ||
6156: ($settings->{'student_classlist_view'} eq 'section')) {
6157: $settings->{'student_classlist_view'} = 'disabled';
6158: }
1.80 raeburn 6159: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6160: }
6161:
6162: sub print_appearance {
1.80 raeburn 6163: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6164: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6165: return;
6166: }
1.9 raeburn 6167: my $mathdef;
6168: if ($crstype eq 'Community') {
6169: $mathdef = &mt("None specified - use member's choice");
6170: } else {
6171: $mathdef = &mt("None specified - use student's choice");
6172: }
1.1 raeburn 6173: my %items = (
6174: 'default_xml_style' => {
1.3 raeburn 6175: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6176: '<a href="javascript:openbrowser'.
6177: "('display','default_xml_style'".
6178: ",'sty')".'">'.&mt('Select Style File').'</a>',
6179: input => 'textbox',
6180: size => 35,
6181: },
6182:
6183: 'pageseparators' => {
1.3 raeburn 6184: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6185: input => 'radio',
6186: },
6187: 'disable_receipt_display' => {
1.3 raeburn 6188: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6189: input => 'radio',
6190: },
6191: 'texengine' => {
1.3 raeburn 6192: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6193: input => 'selectbox',
6194: options => {
1.61 raeburn 6195: MathJax => 'MathJax',
1.1 raeburn 6196: mimetex => &mt('Convert to Images'),
6197: tth => &mt('TeX to HTML'),
6198: },
1.75 raeburn 6199: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6200: nullval => $mathdef,
1.1 raeburn 6201: },
6202: 'tthoptions' => {
1.3 raeburn 6203: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6204: input => 'textbox',
6205: size => 40,
6206: },
1.69 raeburn 6207: 'uselcmath' => {
6208: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6209: input => 'radio',
6210: },
6211: 'usejsme' => {
6212: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6213: input => 'radio',
6214: },
1.95 raeburn 6215: 'inline_chem' => {
6216: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6217: input => 'radio',
6218: },
1.114 raeburn 6219: 'extresource' => {
6220: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6221: input => 'selectbox',
6222: options => {
6223: iframe => 'In iframe',
6224: tab => 'In new tab',
6225: window => 'In pop-up window',
6226: },
6227: order => ['iframe','tab','window'],
6228: },
1.1 raeburn 6229: );
1.80 raeburn 6230: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6231: }
6232:
6233: sub print_grading {
1.127 raeburn 6234: my ($cdom,$cnum,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6235: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6236: return;
6237: }
6238: my %items = (
6239: 'grading' => {
1.3 raeburn 6240: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6241: &Apache::loncommon::help_open_topic('GradingOptions'),
6242: input => 'selectbox',
6243: options => {
6244: standard => &mt('Standard: shows points'),
1.34 www 6245: categories => &mt('Categories: shows points according to categories'),
1.11 www 6246: external => &mt('External: shows number of completed parts and totals'),
6247: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6248: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6249: },
1.34 www 6250: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6251: },
6252: 'rndseed' => {
1.3 raeburn 6253: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.127 raeburn 6254: '<br /><span class="LC_warning LC_nobreak">'.
1.1 raeburn 6255: &mt('Modifying this will make problems have different numbers and answers!').
6256: '</span>',
6257: input => 'selectbox',
6258: options => {
6259: '32bit' => '32bit',
6260: '64bit' => '64bit',
6261: '64bit2' => '64bit2',
6262: '64bit3' => '64bit3',
6263: '64bit4' => '64bit4',
6264: '64bit5' => '64bit5',
6265: },
6266: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6267: advanced => 1
1.1 raeburn 6268: },
6269: 'receiptalg' => {
1.3 raeburn 6270: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6271: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6272: input => 'selectbox',
6273: options => {
6274: receipt => 'receipt',
6275: receipt2 => 'receipt2',
6276: receipt3 => 'receipt3',
6277: },
6278: order => ['receipt','receipt2','receipt3'],
1.41 www 6279: advanced => 1
1.1 raeburn 6280: },
6281: 'disablesigfigs' => {
1.3 raeburn 6282: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6283: input => 'radio',
6284: },
6285: );
1.127 raeburn 6286: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit,$cnum);
1.1 raeburn 6287: }
6288:
6289: sub print_printouts {
1.80 raeburn 6290: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6291: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6292: return;
6293: }
6294: my %items = (
6295: problem_stream_switch => {
1.3 raeburn 6296: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6297: input => 'radio',
6298: },
6299: suppress_tries => {
1.3 raeburn 6300: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6301: input => 'radio',
6302: },
6303: default_paper_size => {
1.3 raeburn 6304: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6305: input => 'selectbox',
6306: options => {
6307: Letter => &mt('Letter').' [8 1/2x11 in]',
6308: Legal => &mt('Legal').' [8 1/2x14 in]',
6309: Tabloid => &mt('Tabloid').' [11x17 in]',
6310: Executive => &mt('Executive').' [7 1/2x10 in]',
6311: A2 => &mt('A2').' [420x594 mm]',
6312: A3 => &mt('A3').' [297x420 mm]',
6313: A4 => &mt('A4').' [210x297 mm]',
6314: A5 => &mt('A5').' [148x210 mm]',
6315: A6 => &mt('A6').' [105x148 mm]',
6316: },
6317: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6318: nullval => &mt('None specified'),
1.1 raeburn 6319: },
6320: print_header_format => {
1.3 raeburn 6321: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6322: input => 'checkbox',
6323: },
6324: disableexampointprint => {
1.3 raeburn 6325: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6326: input => 'radio',
6327: },
1.14 raeburn 6328: canuse_pdfforms => {
6329: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6330: input => 'selectbox',
6331: options => {
6332: 1 => &mt('Yes'),
6333: 0 => &mt('No'),
6334: },
6335: order => ['1','0'],
1.54 bisitz 6336: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6337: }
1.1 raeburn 6338: );
1.80 raeburn 6339: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6340: }
6341:
6342: sub print_spreadsheet {
1.80 raeburn 6343: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6344: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6345: return;
6346: }
6347: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6348: my %items = (
6349: spreadsheet_default_classcalc => {
1.3 raeburn 6350: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6351: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6352: "('display','spreadsheet_default_classcalc'".
6353: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6354: input => 'textbox',
6355: },
6356: spreadsheet_default_studentcalc => {
1.3 raeburn 6357: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6358: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6359: "('display','spreadsheet_default_calc'".
6360: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6361: input => 'textbox',
6362: },
6363: spreadsheet_default_assesscalc => {
1.3 raeburn 6364: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6365: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6366: "('display','spreadsheet_default_assesscalc'".
6367: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6368: input => 'textbox',
6369: },
6370: hideemptyrows => {
1.3 raeburn 6371: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6372: input => 'radio',
6373: },
6374: );
1.80 raeburn 6375: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6376: }
1.1 raeburn 6377:
6378: sub print_bridgetasks {
1.80 raeburn 6379: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6380: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6381: return;
6382: }
1.9 raeburn 6383: my ($stumsg,$msgnote);
6384: if ($crstype eq 'Community') {
6385: $stumsg = &mt('Send message to member');
6386: $msgnote = &mt('Message to member and add to user notes');
6387: } else {
6388: $stumsg = &mt('Send message to student');
6389: $msgnote = &mt('Message to student and add to user notes');
6390: }
1.1 raeburn 6391: my %items = (
6392: task_messages => {
1.3 raeburn 6393: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6394: input => 'selectbox',
6395: options => {
1.9 raeburn 6396: only_student => $stumsg,
6397: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6398: },
6399: order => ['only_student','student_and_user_notes_screen'],
6400: nullval => &mt('No message or record in user notes'),
6401: },
6402: task_grading => {
1.3 raeburn 6403: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6404: input => 'selectbox',
6405: options => {
6406: any => &mt('Grade BTs in any section'),
6407: section => &mt('Grade BTs only in own section')
6408: },
6409: order => ['any','section'],
6410: },
6411: suppress_embed_prompt => {
1.3 raeburn 6412: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6413: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6414: input => 'radio',
6415: },
6416: );
1.80 raeburn 6417: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6418: }
6419:
1.118 raeburn 6420: sub print_ltitools {
6421: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6422: my ($datatable,$disabled,$css_class,$dest);
1.121 raeburn 6423: if ($noedit) {
6424: $disabled = ' disabled="disabled"';
6425: }
1.120 raeburn 6426: my $itemcount = 1;
6427: unless ($context eq 'domain') {
6428: my %tooltypes = &Apache::loncommon::usable_exttools();
6429: unless ($tooltypes{'crs'}) {
6430: my $showtype = 'course';
6431: if ($crstype eq 'Community') {
6432: $showtype = lc($crstype);
6433: }
6434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6435: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6436: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6437: if ($tooltypes{'dom'}) {
6438: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6439: '<i>'.$cdom.'</i>').
6440: '<br /><br />'.
6441: &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.");
6442: } else {
6443: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6444: '<br /><br />'.
6445: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6446: '<i>'.$cdom.'</i>');
6447:
6448: }
6449: $datatable .= '</tr>';
6450: $itemcount ++;
6451: return $datatable;
6452: }
6453: }
1.118 raeburn 6454: my %lt = <itools_names();
6455: my $maxnum = 0;
6456: my %ordered;
6457: if (ref($settings) eq 'HASH') {
6458: foreach my $item (keys(%{$settings})) {
6459: if (ref($settings->{$item}) eq 'HASH') {
6460: my $num = $settings->{$item}{'order'};
6461: $ordered{$num} = $item;
6462: }
6463: }
6464: }
6465:
6466: if ($context eq 'domain') {
6467: $dest = '/adm/domainprefs';
6468: } else {
6469: $dest = '/adm/courseprefs';
6470: }
6471: my ($switchserver,$switchmessage);
6472: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6473: if ($switchserver) {
6474: if ($context eq 'domain') {
6475: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6476: } elsif ($crstype eq 'Community') {
6477: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6478: } else {
6479: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6480: }
6481: }
6482: my $maxnum = scalar(keys(%ordered));
6483: my @courseroles = ('cc','in','ta','ep','st');
6484: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6485: my @fields = ('fullname','firstname','lastname','email','roles','user');
6486: if (keys(%ordered)) {
6487: my @items = sort { $a <=> $b } keys(%ordered);
6488: for (my $i=0; $i<@items; $i++) {
6489: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6490: my $item = $ordered{$items[$i]};
6491: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6492: if (ref($settings->{$item}) eq 'HASH') {
6493: $title = $settings->{$item}->{'title'};
6494: $url = $settings->{$item}->{'url'};
6495: $key = $settings->{$item}->{'key'};
6496: $usable = $settings->{$item}->{'usable'};
6497: $lifetime = $settings->{$item}->{'lifetime'};
6498: my $image = $settings->{$item}->{'image'};
6499: if ($image ne '') {
6500: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6501: }
6502: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6503: $sigsel{'HMAC-256'} = ' selected="selected"';
6504: } else {
6505: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6506: }
6507: }
6508: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6509: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6510: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6511: for (my $k=0; $k<=$maxnum; $k++) {
6512: my $vpos = $k+1;
6513: my $selstr;
6514: if ($k == $i) {
6515: $selstr = ' selected="selected" ';
6516: }
6517: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6518: }
6519: $datatable .= '</select>'.(' 'x2).
6520: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6521: &mt('Delete?').'</label></span></td>'.
6522: '<td colspan="2">'.
6523: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6524: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6525: (' 'x2).
6526: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6527: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6528: (' 'x2).
6529: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6530: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6531: (' 'x2).
6532: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6533: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6534: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6535: '<br /><br />'.
1.120 raeburn 6536: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6537: ' value="'.$url.'" /></span>'.
6538: (' 'x2).
6539: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6540: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6541: if ($key ne '') {
6542: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6543: if ($noedit) {
6544: $datatable .= ': ['.&mt('not shown').']';
6545: } elsif ($switchserver) {
6546: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6547: } else {
6548: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6549: }
6550: $datatable .= '</span> '.(' 'x2);
6551: } elsif (!$switchserver) {
6552: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6553: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6554: '</span> '.(' 'x2);
6555: }
6556: if ($switchserver) {
6557: if ($usable ne '') {
6558: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6559: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6560: '<span class="LC_nobreak">'.&mt('Change secret?').
6561: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6562: (' 'x2).
6563: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6564: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6565: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6566: '</div>';
6567: } elsif ($key eq '') {
6568: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6569: } else {
6570: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6571: }
6572: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6573: } else {
6574: if ($usable ne '') {
6575: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6576: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6577: '<span class="LC_nobreak">'.&mt('Change?').
6578: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6579: (' 'x2).
6580: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6581: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6582: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6583: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6584: '<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>'.
6585: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6586: } else {
6587: $datatable .=
6588: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6589: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6590: '<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>'.
6591: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6592: }
6593: }
6594: $datatable .= '</fieldset>'.
6595: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6596: '<span class="LC_nobreak">'.&mt('Display target:');
6597: my %currdisp;
6598: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6599: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6600: $currdisp{'window'} = ' checked="checked"';
6601: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6602: $currdisp{'tab'} = ' checked="checked"';
6603: } else {
6604: $currdisp{'iframe'} = ' checked="checked"';
6605: }
6606: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6607: $currdisp{'width'} = $1;
6608: }
6609: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6610: $currdisp{'height'} = $1;
6611: }
6612: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6613: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6614: } else {
6615: $currdisp{'iframe'} = ' checked="checked"';
6616: }
6617: foreach my $disp ('iframe','tab','window') {
6618: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6619: $lt{$disp}.'</label>'.(' 'x2);
6620: }
6621: $datatable .= (' 'x4);
6622: foreach my $dimen ('width','height') {
6623: $datatable .= '<label>'.$lt{$dimen}.' '.
6624: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6625: (' 'x2);
6626: }
6627: $datatable .= '</span><br />'.
6628: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6629: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6630: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6631: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6632: '</textarea></div><div style=""></div><br />';
6633: my %units = (
6634: 'passback' => 'days',
6635: 'roster' => 'seconds',
6636: );
6637: foreach my $extra ('passback','roster') {
6638: my $validsty = 'none';
6639: my $currvalid;
6640: my $checkedon = '';
6641: my $checkedoff = ' checked="checked"';
6642: if ($settings->{$item}->{$extra}) {
6643: $checkedon = $checkedoff;
6644: $checkedoff = '';
6645: $validsty = 'inline-block';
6646: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6647: $currvalid = $settings->{$item}->{$extra.'valid'};
6648: }
6649: }
6650: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6651: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6652: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6653: &mt('No').'</label>'.(' 'x2).
6654: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6655: &mt('Yes').'</label></span></div>'.
6656: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6657: '<span class="LC_nobreak">'.
6658: &mt("until at least [_1] $units{$extra} after launch",
6659: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6660: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6661: }
6662: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6663: if ($imgsrc) {
6664: $datatable .= $imgsrc.
6665: '<label><input type="checkbox" name="ltitools_image_del"'.
6666: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6667: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6668: } else {
6669: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6670: }
6671: if ($switchserver) {
6672: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6673: } else {
6674: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6675: }
6676: $datatable .= '</span></fieldset>';
6677: my (%checkedfields,%rolemaps,$userincdom);
6678: if (ref($settings->{$item}) eq 'HASH') {
6679: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6680: %checkedfields = %{$settings->{$item}->{'fields'}};
6681: }
6682: $userincdom = $settings->{$item}->{'incdom'};
6683: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6684: %rolemaps = %{$settings->{$item}->{'roles'}};
6685: $checkedfields{'roles'} = 1;
6686: }
6687: }
6688: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6689: '<span class="LC_nobreak">';
6690: my $userfieldstyle = 'display:none;';
6691: my $seluserdom = '';
6692: my $unseluserdom = ' selected="selected"';
6693: foreach my $field (@fields) {
6694: my ($checked,$onclick,$id,$spacer);
6695: if ($checkedfields{$field}) {
6696: $checked = ' checked="checked"';
6697: }
6698: if ($field eq 'user') {
6699: $id = ' id="ltitools_user_field_'.$i.'"';
6700: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6701: if ($checked) {
6702: $userfieldstyle = 'display:inline-block';
6703: if ($userincdom) {
6704: $seluserdom = $unseluserdom;
6705: $unseluserdom = '';
6706: }
6707: }
6708: } else {
6709: $spacer = (' ' x2);
6710: }
6711: $datatable .= '<label>'.
6712: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6713: $lt{$field}.'</label>'.$spacer;
6714: }
6715: $datatable .= '</span>';
6716: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6717: '<span class="LC_nobreak"> : '.
6718: '<select name="ltitools_userincdom_'.$i.'">'.
6719: '<option value="">'.&mt('Select').'</option>'.
6720: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6721: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6722: '</select></span></div>';
6723: $datatable .= '</fieldset>'.
6724: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6725: foreach my $role (@courseroles) {
6726: my ($selected,$selectnone);
6727: if (!$rolemaps{$role}) {
6728: $selectnone = ' selected="selected"';
6729: }
6730: $datatable .= '<td style="text-align: center">'.
6731: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6732: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6733: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6734: foreach my $ltirole (@ltiroles) {
6735: unless ($selectnone) {
6736: if ($rolemaps{$role} eq $ltirole) {
6737: $selected = ' selected="selected"';
6738: } else {
6739: $selected = '';
6740: }
6741: }
6742: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6743: }
6744: $datatable .= '</select></td>';
6745: }
6746: $datatable .= '</tr></table></fieldset>';
6747: my %courseconfig;
6748: if (ref($settings->{$item}) eq 'HASH') {
6749: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6750: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6751: }
6752: }
1.129 raeburn 6753: $datatable .= '<fieldset><legend>';
6754: if ($context eq 'domain') {
6755: $datatable .= &mt('Configurable in course');
6756: } else {
6757: $datatable .= &mt('Configurable for each instance of tool in course');
6758: }
6759: $datatable .= '</legend><span class="LC_nobreak">';
1.118 raeburn 6760: foreach my $item ('label','title','target','linktext','explanation','append') {
6761: my $checked;
6762: if ($courseconfig{$item}) {
6763: $checked = ' checked="checked"';
6764: }
6765: $datatable .= '<label>'.
6766: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6767: $lt{'crs'.$item}.'</label> '."\n";
6768: }
6769: $datatable .= '</span></fieldset>'.
6770: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6771: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6772: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6773: my %custom = %{$settings->{$item}->{'custom'}};
6774: if (keys(%custom) > 0) {
6775: foreach my $key (sort(keys(%custom))) {
6776: $datatable .= '<tr><td><span class="LC_nobreak">'.
6777: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6778: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6779: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6780: ' value="'.$custom{$key}.'" /></td></tr>';
6781: }
6782: }
6783: }
6784: $datatable .= '<tr><td><span class="LC_nobreak">'.
6785: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6786: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6787: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6788: $datatable .= '</table></fieldset></td></tr>'."\n";
6789: $itemcount ++;
6790: }
6791: }
6792: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6793: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6794: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6795: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6796: '<select name="ltitools_add_pos"'.$chgstr.'>';
6797: for (my $k=0; $k<$maxnum+1; $k++) {
6798: my $vpos = $k+1;
6799: my $selstr;
6800: if ($k == $maxnum) {
6801: $selstr = ' selected="selected" ';
6802: }
6803: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6804: }
6805: $datatable .= '</select> '."\n".
6806: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6807: '<td colspan="2">'.
6808: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6809: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6810: (' 'x2).
6811: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6812: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6813: (' 'x2).
6814: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6815: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6816: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6817: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6818: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6819: '<br />'.
1.120 raeburn 6820: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6821: (' 'x2).
6822: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6823: if ($switchserver) {
6824: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6825: } else {
6826: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6827: (' 'x2).
1.119 raeburn 6828: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6829: '<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 6830: }
6831: $datatable .= '<br /><br />'.
6832: '</fieldset>'.
6833: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6834: '<span class="LC_nobreak">'.&mt('Display target:');
6835: my %defaultdisp;
6836: $defaultdisp{'iframe'} = ' checked="checked"';
6837: foreach my $disp ('iframe','tab','window') {
6838: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6839: $lt{$disp}.'</label>'.(' 'x2);
6840: }
6841: $datatable .= (' 'x4);
6842: foreach my $dimen ('width','height') {
6843: $datatable .= '<label>'.$lt{$dimen}.' '.
6844: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6845: (' 'x2);
6846: }
6847: $datatable .= '</span><br />'.
6848: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6849: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6850: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6851: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6852: '</div><div style=""></div><br />';
6853: my %units = (
6854: 'passback' => 'days',
6855: 'roster' => 'seconds',
6856: );
6857: my %defaulttimes = (
6858: 'passback' => '7',
6859: 'roster' => '300',
6860: );
6861: foreach my $extra ('passback','roster') {
6862: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6863: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6864: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6865: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6866: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6867: &mt('Yes').'</label></span></div>'.
6868: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6869: '<span class="LC_nobreak">'.
6870: &mt("until at least [_1] $units{$extra} after launch",
6871: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6872: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6873: }
6874: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6875: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6876: if ($switchserver) {
6877: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6878: } else {
6879: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6880: }
6881: $datatable .= '</span></fieldset>'.
6882: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6883: '<span class="LC_nobreak">';
6884: foreach my $field (@fields) {
6885: my ($id,$onclick,$spacer);
6886: if ($field eq 'user') {
6887: $id = ' id="ltitools_user_field_add"';
6888: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6889: } else {
6890: $spacer = (' ' x2);
6891: }
6892: $datatable .= '<label>'.
6893: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6894: $lt{$field}.'</label>'.$spacer;
6895: }
6896: $datatable .= '</span>'.
6897: '<div style="display:none;" id="ltitools_user_div_add">'.
6898: '<span class="LC_nobreak"> : '.
6899: '<select name="ltitools_add_userincdom">'.
6900: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6901: '<option value="0">'.&mt('username').'</option>'.
6902: '<option value="1">'.&mt('username:domain').'</option>'.
6903: '</select></span></div></fieldset>';
6904: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6905: foreach my $role (@courseroles) {
6906: my ($checked,$checkednone);
6907: $datatable .= '<td style="text-align: center">'.
6908: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6909: '<select name="ltitools_add_roles_'.$role.'">'.
6910: '<option value="" selected="selected">'.&mt('Select').'</option>';
6911: foreach my $ltirole (@ltiroles) {
6912: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6913: }
6914: $datatable .= '</select></td>';
6915: }
6916: $datatable .= '</tr></table></fieldset>'.
1.129 raeburn 6917: '<fieldset><legend>';
6918: if ($context eq 'domain') {
6919: $datatable .= &mt('Configurable in course');
6920: } else {
6921: $datatable .= &mt('Configurable for each instance of tool in course');
6922: }
6923: $datatable .= '</legend><span class="LC_nobreak">';
1.118 raeburn 6924: foreach my $item ('label','title','target','linktext','explanation','append') {
6925: $datatable .= '<label>'.
6926: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6927: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6928: }
6929: $datatable .= '</span></fieldset>'.
6930: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6931: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6932: '<tr><td><span class="LC_nobreak">'.
6933: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6934: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6935: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6936: '</table></fieldset>'."\n".
6937: '</td>'."\n".
6938: '</tr>'."\n";
6939: $itemcount ++;
6940: return $datatable;
6941: }
6942:
6943: sub ltitools_names {
6944: my %lt = &Apache::lonlocal::texthash(
6945: 'title' => 'Title',
6946: 'version' => 'Version',
6947: 'msgtype' => 'Message Type',
6948: 'sigmethod' => 'Signature Method',
6949: 'url' => 'URL',
6950: 'key' => 'Key',
6951: 'lifetime' => 'Nonce lifetime (s)',
6952: 'secret' => 'Secret',
6953: 'icon' => 'Icon',
6954: 'user' => 'User',
6955: 'fullname' => 'Full Name',
6956: 'firstname' => 'First Name',
6957: 'lastname' => 'Last Name',
6958: 'email' => 'E-mail',
6959: 'roles' => 'Role',
6960: 'window' => 'Window',
6961: 'tab' => 'Tab',
6962: 'iframe' => 'iFrame',
6963: 'height' => 'Height',
6964: 'width' => 'Width',
6965: 'linktext' => 'Default Link Text',
6966: 'explanation' => 'Default Explanation',
6967: 'passback' => 'Tool can return grades:',
6968: 'roster' => 'Tool can retrieve roster:',
6969: 'crstarget' => 'Display target',
6970: 'crslabel' => 'Course label',
6971: 'crstitle' => 'Course title',
6972: 'crslinktext' => 'Link Text',
6973: 'crsexplanation' => 'Explanation',
6974: 'crsappend' => 'Provider URL',
6975: );
6976: return %lt;
6977: }
6978:
1.87 raeburn 6979: sub print_lti {
6980: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6981: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6982: return;
6983: }
6984: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6985: my %menutitles = <imenu_titles();
6986: my ($domdefs,$displaydefs);
6987: if ($env{'request.lti.login'}) {
6988: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6989: my @domdefsmenu;
6990: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6991: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6992: $domdefs = &mt('Header shown').', ';
6993: }
6994: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6995: $domdefs .= &mt('Inline menu shown');
6996: }
6997: $domdefs =~ s/,\s$//;
6998: if (!$domdefs) {
6999: $domdefs = &mt('No header or inline menu shown');
7000: }
7001: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
7002: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
7003: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
7004: }
7005: }
7006: $displaydefs = &mt('Domain defaults');
7007: if (@domdefsmenu) {
7008: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
7009: if (@diffs) {
7010: my $missing;
7011: foreach my $item (@menuitems) {
7012: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
7013: $missing .= ' '.$menutitles{$item}.',';
7014: }
7015: }
7016: $missing =~ s/,$//;
7017: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
7018: } else {
7019: $displaydefs .= ': '.&mt('All shown');
7020: }
7021: } else {
7022: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
7023: }
7024: } else {
7025: $displaydefs = &mt('Domain defaults only available in LTI context');
7026: }
7027: my %items = (
7028: 'lti.override' => {
7029: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
7030: input => 'radio',
7031: },
7032: 'lti.topmenu' => {
7033: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
7034: input => 'radio',
7035: },
7036: 'lti.inlinemenu' => {
7037: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
7038: input => 'radio',
7039: },
7040: 'lti.lcmenu' => {
7041: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
7042: input => 'custom',
7043: },
7044: );
7045: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
7046: }
7047:
7048: sub lcmenu_checkboxes {
7049: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
7050: my @menuitems = ('fullname','coursetitle','role','logout','grades');
7051: my %menutitles = <imenu_titles();
7052: my (@current,@domdefs);
7053: if ($env{'request.lti.login'}) {
7054: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
7055: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
7056: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
7057: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
7058: }
7059: }
7060: }
7061: if (ref($settings) eq 'HASH') {
7062: if ($settings->{'lti.lcmenu'}) {
7063: unless ($settings->{'lti.lcmenu'} eq 'none') {
7064: @current = split(',',$settings->{'lti.lcmenu'});
7065: }
7066: } else {
7067: @current = @domdefs;
7068: }
7069: } else {
7070: @current = @domdefs;
7071: }
7072: my $numinrow = 3;
7073: my $count = 0;
7074: my $disabled;
7075: if ($noedit) {
7076: $disabled = ' disabled="disabled"';
7077: }
7078: my $output = '<table>';
7079: foreach my $item (@menuitems) {
7080: my $checked = '';
7081: if (grep(/^\Q$item\E$/,@current)) {
7082: $checked = ' checked="checked" ';
7083: }
7084: my $rem = $count%($numinrow);
7085: if ($rem == 0) {
7086: if ($count > 0) {
7087: $output .= '</tr>';
7088: }
7089: $output .= '<tr>';
7090: }
7091: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
7092: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
7093: $menutitles{$item}.'</label></span></td>';
7094: $count ++;
7095: }
7096: my $rem = $count%($numinrow);
7097: my $colsleft = $numinrow - $rem;
7098: if ($colsleft > 1 ) {
7099: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7100: ' </td>';
7101: } elsif ($colsleft == 1) {
7102: $output .= '<td class="LC_left_item"> </td>';
7103: }
7104: $output .= '</tr></table>';
7105: }
7106:
7107: sub ltimenu_titles {
7108: return &Apache::lonlocal::texthash(
7109: fullname => 'Full name',
7110: coursetitle => 'Course title',
7111: role => 'Role',
7112: logout => 'Logout',
7113: grades => 'Grades',
7114: );
7115: }
7116:
1.91 raeburn 7117: sub print_menuitems {
7118: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
7119: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
7120: return;
7121: }
7122: if ($position eq 'top') {
7123: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
7124: if ($settings->{'menucollections'} ne '') {
7125: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7126: my ($num,$value) = split(/\%/,$item);
7127: if ($num =~ /^\d+$/) {
7128: $defaultmenu_options{$num} = $num;
7129: }
7130: }
7131: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
7132: $addcollection = $defaultmenu_order[-1] + 1;
7133: } else {
7134: $addcollection = 1;
7135: }
7136: $defaultmenu_options{$addcollection} = $addcollection;
7137: my %items = (
7138: 'menudefault' => {
7139: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
7140: &mt("(can be overriden in deep-link context)"),
7141: input => 'selectbox',
7142: options => \%defaultmenu_options,
7143: order => \@defaultmenu_order,
7144: nullval => &mt('Standard (all menus shown)'),
7145: },
7146: );
7147: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
7148: } else {
7149: my %menu;
7150: my $count = 0;
7151: my $next = 1;
7152: my ($datatable,$disabled);
7153: if ($noedit) {
7154: $disabled = ' disabled="disabled"';
7155: }
7156:
7157: my ($ordered,$cats) = &menuitems_categories();
7158: my @order = @{$ordered};
7159: my %categories = %{$cats};
7160: my %menutitles = &menuitems_titles();
7161: my %menufields = &menuitems_fields();
7162:
7163: if ($settings->{'menucollections'} ne '') {
7164: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7165: my ($num,$value) = split(/\%/,$item);
7166: if ($num =~ /^\d+$/) {
7167: my @entries = split(/\&/,$value);
7168: foreach my $entry (@entries) {
7169: my ($name,$fields) = split(/=/,$entry);
7170: $menu{$num}{$name} = $fields;
7171: }
7172: }
7173: }
7174: if (keys(%menu)) {
7175: my @current = sort { $a <=> $b } keys(%menu);
7176: $next += $current[-1];
7177: foreach my $num (@current) {
7178: my %checked;
7179: my $on = ' checked="checked"';
7180: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7181: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7182: if ($menu{$num}{$key} eq 'y') {
7183: $checked{$key} = $on;
7184: }
7185: } else {
7186: foreach my $field (split(/,/,$menu{$num}{$key})) {
7187: if (exists($menufields{$field})) {
7188: $checked{$field} = $on;
7189: }
7190: }
7191: }
7192: }
7193: if (ref($menu{$num}) eq 'HASH') {
7194: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7195: foreach my $category (@order) {
7196: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7197: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7198: if ($category eq 'text') {
7199: $datatable .= '<i>'.&mt('Header').'</i><br />';
7200: }
1.91 raeburn 7201: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7202: if ($field eq 'disc') {
7203: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7204: }
1.91 raeburn 7205: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7206: $menufields{$field}.'</label><br />';
7207: }
7208: $datatable .= '</fieldset>';
7209: }
7210: }
7211: $datatable .= &item_table_row_end();
7212: $count ++;
7213: }
7214: }
7215: }
7216: } elsif ($noedit) {
7217: my $text = &mt('No menu collections defined for this course.');
7218: $datatable .= &item_table_row_start($text,$count);
7219: }
7220: unless ($noedit) {
7221: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7222: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7223: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7224: foreach my $category (@order) {
7225: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7226: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7227: foreach my $field (@{$categories{$category}}) {
7228: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7229: $menufields{$field}.'</label><br />';
7230: }
7231: $datatable .= '</fieldset>';
7232: }
7233: }
7234: $datatable .= &item_table_row_end();
7235: $count ++;
7236: }
7237: return $datatable;
7238: }
7239: }
7240:
7241: sub menuitems_abbreviations {
7242: my %briefcats = (
7243: text => 'pt',
7244: links => 'p',
7245: list => 'ps',
7246: inline => 's',
7247: );
7248: return %briefcats;
7249: }
7250:
7251: sub menuitems_categories {
7252: my @order = ('shown','text','links','list','inline');
7253: my %categories = (
1.94 raeburn 7254: shown => ['top','inline','foot','main'],
7255: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7256: links => ['pers','logo','menu','comm','roles','help','logout'],
1.128 raeburn 7257: list => ['about','prefs','port','wish','anno','rss','srch','brse'],
1.91 raeburn 7258: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7259: );
7260: return (\@order,\%categories);
7261: }
7262:
7263: sub menuitems_titles {
7264: return &Apache::lonlocal::texthash (
7265: shown => 'Hierarchy',
1.94 raeburn 7266: text => 'Text',
1.91 raeburn 7267: links => 'Header links',
7268: list => 'Drop-down list',
7269: inline => 'Inline links',
7270: );
7271: }
7272:
7273: sub menuitems_fields {
7274: return &Apache::lonlocal::texthash (
7275: top => 'Display header',
7276: inline => 'Display inline menu',
1.94 raeburn 7277: foot => 'Display footer',
1.91 raeburn 7278: main => 'Access to main menu',
1.92 raeburn 7279: pers => 'Personal',
7280: logo => 'LON-CAPA',
1.91 raeburn 7281: menu => 'Home',
7282: comm => 'Messages',
7283: roles => 'Roles/Courses',
7284: help => 'Help',
7285: logout => 'Logout',
7286: name => 'Fullname',
7287: crs => 'Course Title',
7288: role => 'Current Role',
1.94 raeburn 7289: disc => 'Discussion',
7290: fdbk => 'Feedback',
1.91 raeburn 7291: about => 'Information',
7292: prefs => 'Preferences',
7293: port => 'Portfolio',
7294: wish => 'Stored Links',
7295: anno => 'Calendar',
7296: rss => 'RSS Feeds',
1.128 raeburn 7297: srch => 'Search Library',
7298: brse => 'Browse Library',
1.91 raeburn 7299: cont => 'Contents',
7300: grades => 'Grades',
7301: chat => 'Chat',
7302: people => 'People',
7303: groups => 'Groups',
7304: resv => 'Reservations',
7305: syll => 'Syllabus',
7306: feeds => 'Feeds',
7307: );
7308: }
7309:
7310: sub menucollections_display {
7311: my ($collections) = @_;
7312: my %menu;
7313: my ($ordered,$cats) = &menuitems_categories();
7314: my @order = @{$ordered};
7315: my %categories = %{$cats};
7316: my %menutitles = &menuitems_titles();
7317: my %menufields = &menuitems_fields();
7318: foreach my $item (split(/;/,$collections)) {
7319: my ($num,$value) = split(/\%/,$item);
7320: if ($num =~ /^\d+$/) {
7321: my @entries = split(/\&/,$value);
7322: foreach my $entry (@entries) {
7323: my ($name,$fields) = split(/=/,$entry);
7324: $menu{$num}{$name} = $fields;
7325: }
7326: }
7327: }
7328: my $output = '';
7329: if (keys(%menu)) {
7330: my @current = sort { $a <=> $b } keys(%menu);
7331: foreach my $num (@current) {
7332: my %checked;
7333: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7334: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7335: if ($menu{$num}{$key} eq 'y') {
7336: $checked{$key} = 1;
7337: }
7338: } else {
7339: foreach my $field (split(/,/,$menu{$num}{$key})) {
7340: if (exists($menufields{$field})) {
7341: $checked{$field} = 1;
7342: }
7343: }
7344: }
7345: }
7346: if (ref($menu{$num}) eq 'HASH') {
7347: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7348: foreach my $category (@order) {
7349: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7350: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7351: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7352: if ($category eq 'text') {
7353: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
1.124 raeburn 7354: }
1.91 raeburn 7355: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7356: if ($field eq 'disc') {
7357: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7358: }
1.91 raeburn 7359: if ($checked{$field}) {
7360: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7361: } else {
7362: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7363: }
7364: $output .= '<br />';
7365: }
7366: $output .= '</fieldset>';
7367: }
7368: }
7369: $output .= '</fieldset>';
7370: }
7371: }
7372: }
7373: return $output;
7374: }
7375:
1.93 raeburn 7376: sub print_linkprotection {
1.102 raeburn 7377: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7378:
7379: my %linkprotection;
7380: my $count = 0;
7381: my $next = 1;
1.102 raeburn 7382: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7383: if ($noedit) {
7384: $disabled = ' disabled="disabled"';
7385: }
1.100 raeburn 7386: my %desc = &linkprot_names();
7387: my %lt = &Apache::lonlocal::texthash (
7388: 'requ' => 'Required settings',
7389: 'opti' => 'Optional settings',
7390: );
1.93 raeburn 7391: my $itemcount = 0;
7392:
1.100 raeburn 7393: my $ltiauth;
1.102 raeburn 7394: if ($context eq 'domain') {
7395: $ltiauth = 1;
7396: } else {
7397: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7398: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7399: } else {
7400: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7401: $ltiauth = $domdefs{'crsltiauth'};
7402: }
7403: }
7404: if ($context eq 'domain') {
7405: $dest = '/adm/domainprefs';
1.100 raeburn 7406: } else {
1.102 raeburn 7407: $dest = '/adm/courseprefs';
7408: }
1.124 raeburn 7409:
1.102 raeburn 7410: my ($switchserver,$switchmessage);
7411: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7412: if ($switchserver) {
7413: if ($context eq 'domain') {
1.124 raeburn 7414: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.102 raeburn 7415: } elsif ($crstype eq 'Community') {
7416: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7417: } else {
7418: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7419: }
1.100 raeburn 7420: }
1.99 raeburn 7421:
1.105 raeburn 7422: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7423: if (keys(%{$settings->{'linkprot'}})) {
7424: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7425: $next += $current[-1];
7426: for (my $i=0; $i<@current; $i++) {
7427: my $num = $current[$i];
7428: my %values;
1.102 raeburn 7429: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7430: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7431: } else {
7432: next;
7433: }
7434: my $selected;
7435: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7436: $selected = ' selected="selected"';
7437: }
7438: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7439: $datatable .=
7440: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7441: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7442: &mt('Delete?').'</label></span></td><td>';
1.122 raeburn 7443: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7444: $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
7445: $passbacksty = 'none';
7446: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
7447: %checkedpassback = (
7448: 'no' => ' checked="checked"',
7449: 'yes' => '',
1.124 raeburn 7450: );
1.122 raeburn 7451: %checkedpassbackfmt = (
7452: '1p1' => ' checked="checked"',
7453: '1p0' => '',
7454: );
7455: if ($values{'passback'} ne '') {
7456: $passbacksty = 'inline-block';
7457: $checkedpassback{'yes'} = ' checked="checked"';
7458: $checkedpassback{'no'} = '';
7459: if ($values{'passbackformat'} eq '1.0') {
7460: $checkedpassbackfmt{'1p0'} = ' checked="checked"';
7461: $checkedpassbackfmt{'1p1'} = '';
7462: }
7463: }
1.100 raeburn 7464: if ($ltiauth) {
7465: $usersty = 'display:none';
1.112 raeburn 7466: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7467: %checkedrequser = (
7468: no => ' checked="checked"',
7469: yes => '',
7470: );
7471: if ($values{'requser'}) {
7472: $checkedrequser{'yes'} = $checkedrequser{'no'};
7473: $checkedrequser{'no'} = '';
7474: }
7475: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
1.124 raeburn 7476: if ($values{'requser'}) {
1.100 raeburn 7477: $usersty = 'display:inline-block';
7478: }
7479: }
1.112 raeburn 7480: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7481: %checkedreturnurl = (
7482: no => ' checked="checked"',
7483: yes => '',
7484: );
7485: if ($values{'returnurl'} ne '') {
7486: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7487: $checkedreturnurl{'no'} = '';
7488: }
1.100 raeburn 7489: $datatable .=
7490: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7491: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7492: (' 'x2).
1.100 raeburn 7493: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7494: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7495: (' 'x2).
1.100 raeburn 7496: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7497: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7498: if ($values{'key'} ne '') {
1.100 raeburn 7499: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7500: if ($noedit) {
7501: $datatable .= ': ['.&mt('not shown').']';
7502: } elsif ($switchserver) {
7503: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7504: } else {
7505: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7506: }
7507: $datatable .= '</span> '.(' 'x2);
7508: } elsif (!$switchserver) {
1.100 raeburn 7509: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7510: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7511: '</span> '.(' 'x2);
7512: }
7513: if ($switchserver) {
7514: if ($values{'usable'} ne '') {
7515: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7516: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7517: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7518: '<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 7519: (' 'x2).
1.118 raeburn 7520: '<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 7521: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7522: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7523: '</div>';
7524: } elsif ($values{'key'} eq '') {
1.102 raeburn 7525: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7526: } else {
1.102 raeburn 7527: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7528: }
1.111 raeburn 7529: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7530: } else {
7531: if ($values{'usable'} ne '') {
7532: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7533: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7534: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7535: '<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 7536: (' 'x2).
1.118 raeburn 7537: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7538: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7539: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7540: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7541: '<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 7542: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7543: } else {
7544: $datatable .=
1.100 raeburn 7545: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7546: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7547: '<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 7548: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7549: }
7550: }
1.112 raeburn 7551: $datatable .= '<br /><br />'.
1.122 raeburn 7552: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7553: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7554: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7555: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7556: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7557: '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7558: '<span class="LC_nobreak">'.&mt('Grade format').
7559: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7560: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7561: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7562: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7563: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7564: '<br />'.
1.112 raeburn 7565: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7566: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7567: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7568: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7569: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.130 raeburn 7570: ' <div id="linkprot_divurlparam_'.$i.'" style="display:none">'.
1.112 raeburn 7571: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7572: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7573: '</span></div> ';
1.100 raeburn 7574: if ($ltiauth) {
1.112 raeburn 7575: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7576: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7577: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7578: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7579: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7580: '</fieldset>'.
7581: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7582: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7583: '</fieldset>';
7584: }
1.99 raeburn 7585: $datatable .= '</td></tr>';
1.93 raeburn 7586: $itemcount ++;
7587: }
7588: }
7589: }
7590: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7591: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7592: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7593: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7594: '<td width="100%">';
1.122 raeburn 7595: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7596: $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.100 raeburn 7597: if ($ltiauth) {
7598: $usersty = 'display:none';
1.112 raeburn 7599: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7600: %checkedrequser = (
7601: no => ' checked="checked"',
7602: yes => '',
7603: );
7604: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7605: }
1.122 raeburn 7606: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7607: %checkedpassback = (
7608: 'no' => ' checked="checked"',
7609: 'yes' => '',
7610: );
7611: %checkedpassbackfmt = (
7612: '1p1' => ' checked="checked"',
7613: '1p0' => '',
7614: );
1.112 raeburn 7615: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7616: %checkedreturnurl = (
7617: no => ' checked="checked"',
7618: yes => '',
7619: );
1.100 raeburn 7620: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7621: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7622: (' 'x2).
1.100 raeburn 7623: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7624: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7625: (' 'x2).
1.112 raeburn 7626: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7627: '<br /><br />';
1.99 raeburn 7628: if ($switchserver) {
1.102 raeburn 7629: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7630: } else {
1.100 raeburn 7631: $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 7632: (' 'x2).
1.116 raeburn 7633: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7634: '<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 7635: }
1.112 raeburn 7636: $datatable .= '<br /><br />'.
1.122 raeburn 7637: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7638: '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7639: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7640: '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7641: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.130 raeburn 7642: '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none">'.
1.122 raeburn 7643: '<span class="LC_nobreak">'.&mt('Grade format').
7644: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7645: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7646: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7647: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7648: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7649: '<br />'.
1.112 raeburn 7650: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7651: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7652: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7653: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7654: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.130 raeburn 7655: ' <div id="linkprot_divurlparam_add" style="display:none">'.
1.112 raeburn 7656: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7657: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7658: '</span></div> ';
7659: if ($ltiauth) {
7660: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7661: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7662: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7663: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7664: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7665: '</fieldset>'.
1.100 raeburn 7666: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7667: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7668: '</fieldset>';
7669: }
1.99 raeburn 7670: $datatable .= '</td></tr>';
1.93 raeburn 7671: $$rowtotal ++;
1.101 raeburn 7672: return $datatable;
1.93 raeburn 7673: }
7674:
7675: sub linkprot_names {
1.100 raeburn 7676: return &Apache::lonlocal::texthash(
1.93 raeburn 7677: 'version' => 'LTI Version',
7678: 'key' => 'Key',
7679: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7680: 'name' => 'Launcher Application',
1.93 raeburn 7681: 'secret' => 'Secret',
1.122 raeburn 7682: 'passback' => 'Can return grades to Launcher',
1.112 raeburn 7683: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7684: 'requser' => 'Use identity',
7685: 'email' => 'Email address',
7686: 'sourcedid' => 'User ID',
7687: 'other' => 'Other',
7688: 'auth' => 'Display LON-CAPA login page',
7689: 'reject' => 'Discontinue launch process',
1.93 raeburn 7690: );
7691: }
7692:
1.99 raeburn 7693: sub check_switchserver {
1.102 raeburn 7694: my ($cdom,$cnum,$context,$dest) = @_;
7695: my ($allowed,$switchserver,$home);
7696: if ($context eq 'domain') {
7697: $home = &Apache::lonnet::domain($cdom,'primary');
7698: } else {
7699: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7700: }
7701: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7702: my @ids=&Apache::lonnet::current_machine_ids();
7703: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7704: if (!$allowed) {
7705: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7706: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7707: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7708: }
7709: }
7710: return $switchserver;
7711: }
7712:
1.100 raeburn 7713: sub linkprot_options {
7714: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7715: my %lt;
7716: if (ref($desc) eq 'HASH') {
7717: %lt = %{$desc};
7718: }
7719: my $userfieldsty = 'none';
7720: my (%checked,$userfield);
7721: $checked{'sourcedid'} = ' checked="checked"';
7722: $checked{'reject'} = ' checked="checked"';
7723: if (ref($current) eq 'HASH') {
7724: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7725: $checked{'sourcedid'} = '';
7726: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7727: $checked{'email'} = ' checked="checked"';
7728: } else {
7729: $checked{'other'} = ' checked="checked"';
7730: $userfield = $current->{'mapuser'};
7731: $userfieldsty = 'inline-block';
7732: }
7733: }
7734: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7735: $checked{'reject'} = '';
7736: $checked{'auth'} = ' checked="checked"';
7737: }
7738: }
1.112 raeburn 7739: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7740: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7741: &mt('Source of LON-CAPA username in LTI request').': ';
7742: foreach my $option ('sourcedid','email','other') {
7743: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7744: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7745: ($option eq 'other' ? '' : (' 'x2) );
7746: }
7747: $output .= '</span></div>'.
7748: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7749: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7750: 'value="'.$userfield.'"'.$disabled.' /></div>';
7751: $output .= '<br />'.
7752: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7753: &mt('Action when username is not for an enrolled student').': ';
7754: foreach my $option ('reject','auth') {
7755: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7756: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7757: ($option eq 'auth' ? '' : (' 'x2) );
7758: }
7759: $output .= '</span></div>';
7760: return $output;
7761: }
7762:
1.114 raeburn 7763: sub print_extresource_row {
7764: my ($item,$config,$curr,$noedit) = @_;
7765: my $onchange;
7766: unless ($noedit) {
7767: $onchange = ' onchange="javascript:toggleExtRes();"';
7768: }
7769: my $id = 'LC_'.$item;
7770: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7771: my $output = &select_from_options($item,$config->{'order'},
7772: $config->{'options'},$selected,
7773: $config->{'nullval'},
7774: undef,undef,$onchange,$noedit,$id);
1.124 raeburn 7775: my ($checked,$reusesty,$sizesty);
1.114 raeburn 7776: if ($reuse) {
7777: $checked = ' checked="checked"';
7778: }
7779: $reusesty = 'none';
7780: $sizesty = 'none';
7781: if (($selected eq 'window') || ($selected eq 'tab')) {
7782: $reusesty = 'inline-block';
7783: if ($selected eq 'window') {
7784: $sizesty = 'inline-block';
7785: }
7786: }
7787: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7788: '<span class="LC_nobreak">'.
7789: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7790: &mt('Re-use tab/window').'</label>'.
7791: '</span></div>'.
7792: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7793: '<legend>'.&mt('Window size (optional)').'</legend>'.
7794: '<span class="LC_nobreak">'.
7795: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7796: (' ' x 3).
7797: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7798: '</span></fieldset>';
7799: return $output;
7800: }
7801:
1.1 raeburn 7802: sub print_other {
1.80 raeburn 7803: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7804: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7805: return;
7806: }
1.3 raeburn 7807: my @ordered = &get_other_items($cdom,$settings,$allitems);
7808: my %items;
7809: foreach my $parameter (@ordered) {
7810: $items{$parameter} = {
7811: text => '<b>'.$parameter.'</b>',
7812: input => 'textbox',
7813: size => '15',
7814: },
7815: }
7816: push (@ordered,'newp_value');
7817: $items{'newp_value'} = {
7818: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7819: '<input type="textbox" name="newp_name"'.
7820: ' value="" size="30" />',
7821: input => 'textbox',
7822: size => '30',
7823: };
1.93 raeburn 7824: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7825: }
7826:
7827: sub get_other_items {
7828: my ($cdom,$settings,$allitems) = @_;
7829: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7830: return;
7831: }
1.1 raeburn 7832: my @ordered;
7833: if (ref($settings) eq 'HASH') {
7834: foreach my $parameter (sort(keys(%{$settings}))) {
7835: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7836: next if (($parameter eq 'course.helper.not.run') &&
7837: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7838: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7839: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7840: || ($parameter eq 'type') ||
1.50 raeburn 7841: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7842: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7843: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7844: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7845: push(@ordered,$parameter);
7846: }
7847: }
7848: }
1.3 raeburn 7849: return @ordered;
1.1 raeburn 7850: }
7851:
7852: sub item_table_row_start {
1.91 raeburn 7853: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7854: my $output;
1.56 raeburn 7855: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7856: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7857: if ($leftclass eq '') {
7858: $leftclass = 'LC_left_item';
7859: }
7860: if ($rightclass eq '') {
7861: $rightclass = 'LC_right_item';
7862: }
1.56 raeburn 7863: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7864: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7865: '</td>';
1.91 raeburn 7866: if ($colspan > 1) {
7867: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7868: } else {
1.91 raeburn 7869: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7870: }
1.1 raeburn 7871: return $output;
7872: }
7873:
7874: sub item_table_row_end {
7875: return '</td></tr>';
7876: }
7877:
7878: sub yesno_radio {
1.127 raeburn 7879: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit,$onclick,$reverse) = @_;
1.1 raeburn 7880: my $itemon = ' ';
7881: my $itemoff = ' checked="checked" ';
1.69 raeburn 7882: if (($valueyes eq '') && ($valueno eq '')) {
7883: $valueyes = 'yes';
7884: $valueno = '';
7885: }
1.1 raeburn 7886: if (ref($settings) eq 'HASH') {
1.69 raeburn 7887: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7888: $itemon = $itemoff;
7889: $itemoff = ' ';
7890: }
1.69 raeburn 7891: unless (exists($settings->{$item})) {
7892: if ($unsetdefault eq $valueyes) {
7893: $itemon = $itemoff;
7894: $itemoff = ' ';
7895: }
7896: }
1.1 raeburn 7897: }
1.80 raeburn 7898: my $disabled;
7899: if ($noedit) {
7900: $disabled = ' disabled="disabled"';
1.127 raeburn 7901: } elsif ($onclick) {
7902: $onclick = ' onclick="'.$onclick.'"';
7903: }
7904: if ($reverse) {
7905: return '<span class="LC_nobreak"><label>'.
7906: '<input type="radio" name="'.$item.'"'.
7907: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label> '.
7908: '<label><input type="radio" name="'.$item.'"'.
7909: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label></span>';
7910: } else {
7911: return '<span class="LC_nobreak"><label>'.
7912: '<input type="radio" name="'.$item.'"'.
7913: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label> '.
7914: '<label><input type="radio" name="'.$item.'"'.
7915: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label></span>';
1.80 raeburn 7916: }
1.1 raeburn 7917: }
7918:
7919: sub select_from_options {
1.91 raeburn 7920: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7921: my $output;
1.80 raeburn 7922: my $disabled;
7923: if ($noedit) {
7924: $disabled = ' disabled=disabled"';
7925: }
1.1 raeburn 7926: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7927: $output='<select name="'.$item.'" '.$onchange;
7928: if ($multiple) {
7929: $output .= ' multiple="multiple"';
7930: my $num = @{$order};
7931: $num ++ if ($nullval ne '');
7932: if (($maxsize) && ($maxsize < $num)) {
7933: $output .= ' size="'.$maxsize.'"';
7934: }
7935: }
1.91 raeburn 7936: if ($id ne '') {
7937: $output .= ' id="'.$id.'"';
7938: }
1.80 raeburn 7939: $output .= $disabled.'>'."\n";
1.1 raeburn 7940: if ($nullval ne '') {
7941: $output .= '<option value=""';
7942: if (ref($curr) eq 'ARRAY') {
7943: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7944: $output .= ' selected="selected" ';
7945: }
7946: } else {
7947: if ($curr eq '') {
7948: $output .= ' selected="selected" ';
7949: }
7950: }
7951: $output .= '>'.$nullval.'</option>';
7952: }
7953: foreach my $option (@{$order}) {
7954: $output.= '<option value="'.$option.'"';
7955: if (ref($curr) eq 'ARRAY') {
7956: if (grep(/^\Q$option\E$/,@{$curr})) {
7957: $output .= ' selected="selected" ';
7958: }
7959: } else {
7960: if ($option eq $curr) {
7961: $output.=' selected="selected"';
7962: }
7963: }
7964: $output.=">$options->{$option}</option>\n";
7965: }
7966: $output.="</select>";
7967: }
7968: return $output;
7969: }
7970:
7971: sub make_item_rows {
1.127 raeburn 7972: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit,$cnum) = @_;
1.1 raeburn 7973: my $datatable;
7974: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7975: my $count = 0;
7976: foreach my $item (@{$ordered}) {
7977: $count ++;
1.56 raeburn 7978: my $colspan;
7979: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7980: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7981: $colspan = 2;
7982: }
1.114 raeburn 7983: my $rowdesc;
7984: if ($caller eq 'appearance') {
7985: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7986: } else {
7987: $rowdesc = $items->{$item}{text};
7988: }
1.41 www 7989: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7990: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7991: } else {
1.114 raeburn 7992: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7993: }
1.55 raeburn 7994: if ($item eq 'defaultcredits') {
7995: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7996: my $showcredits;
7997: if ($defaultcredits ne '') {
7998: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7999: } else {
8000: $showcredits = &mt('No default set');
8001: }
8002: $datatable .= $showcredits;
8003: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 8004: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 8005: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 8006: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 8007: } elsif ($item eq 'print_header_format') {
1.80 raeburn 8008: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 8009: } elsif ($item eq 'lti.lcmenu') {
8010: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 8011: } elsif ($item eq 'extresource') {
8012: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 8013: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 8014: my $disabled;
8015: if ($noedit) {
8016: $disabled = ' disabled="disabled"';
8017: }
1.1 raeburn 8018: $datatable .=
8019: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 8020: $settings->{$item},$disabled);
1.1 raeburn 8021: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 8022: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 8023: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 8024: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
8025: unless ($domdefs{$item} eq '0') {
8026: $unsetdefault = 1;
8027: }
8028: $valueyes = "1";
8029: $valueno = "0";
1.87 raeburn 8030: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
8031: $valueyes = '1';
1.69 raeburn 8032: }
1.80 raeburn 8033: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 8034: } elsif ($items->{$item}{input} eq 'selectbox') {
1.127 raeburn 8035: my ($id,$onchange);
1.91 raeburn 8036: if ($caller eq 'menuitems') {
8037: $id = $item;
1.127 raeburn 8038: } elsif ($caller eq 'grading') {
8039: if ($item eq 'grading') {
8040: $onchange = ' onchange="javascript:toggleGrading(this.form);"';
8041: $id = $item;
8042: }
1.91 raeburn 8043: }
1.1 raeburn 8044: my $curr = $settings->{$item};
8045: $datatable .=
8046: &select_from_options($item,$items->{$item}{'order'},
8047: $items->{$item}{'options'},$curr,
1.80 raeburn 8048: $items->{$item}{'nullval'},
1.127 raeburn 8049: undef,undef,$onchange,$noedit,$id);
8050: if ($item eq 'grading') {
8051: my ($unsetdefault,$valueyes,$valueno,$sectionbox);
8052: my $gradingsty = 'none';
8053: my $gradingsecsty = 'none';
8054: $unsetdefault = 0;
8055: my (@selsec,@sections,%current);
8056: if ($curr eq 'standard') {
8057: $gradingsty = 'inline-block';
8058: if (ref($settings) eq 'HASH') {
8059: $current{'hidetotals'} = $settings->{'hidetotals'};
8060: if ($settings->{'hidetotals'} =~ /^([\w,]+)$/) {
8061: my $secstr = $1;
8062: unless ($secstr eq 'all') {
8063: @selsec = split(/,/,$secstr);
8064: }
8065: $current{'hidetotals'} = 1;
8066: }
8067: }
8068: }
8069: $valueyes = "1";
8070: $valueno = "0";
8071: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
8072: if (keys(%sections)) {
8073: @sections = sort( { $a <=> $b } keys(%sections));
8074: }
8075: my $onclick = 'javascript:toggleHiddenTotalsSec(this.form);';
8076: my $sectionbox = '<div id="sectotalsdiv" style="display:'.$gradingsecsty.'; float:right">';
8077: my $reverse = 1;
8078: if (@sections) {
8079: $sectionbox .= ' ... '.&mt('hidden in sections').': '.
8080: '<div style="position: relative; top: 0%;">'.
8081: &select_sections('hidetotals','',\@sections,\@selsec,$noedit,'all').
8082: '</div>';
8083: }
8084: $sectionbox .= '</div>';
8085: $datatable .= '<fieldset id="hidetotalsdiv" style="display:'.$gradingsty.';">'.
8086: '<legend style="font-weight: normal;">'.
8087: &mt('Hide Course Points Totals').'</legend>'.
8088: '<div style="position: relative; top: 0%; float:left">'.
8089: &yesno_radio('hidetotals',\%current,$unsetdefault,$valueyes,$valueno,$noedit,
8090: $onclick,$reverse).'</div>'.
8091: $sectionbox.
8092: '</fieldset><div style="padding:0;clear:both;margin:0;border:0"></div>';
8093: }
1.1 raeburn 8094: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 8095: my $disabled;
8096: if ($noedit) {
8097: $disabled = ' disabled=disabled"';
8098: }
1.1 raeburn 8099: $datatable .=
8100: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 8101: $items->{$item}{size},
8102: $disabled);
1.1 raeburn 8103: }
8104: $datatable .= &item_table_row_end();
8105: }
8106: if (ref($rowtotal)) {
8107: $$rowtotal += scalar(@{$ordered});
8108: }
8109: }
8110: return $datatable;
8111: }
8112:
8113: sub nothidepriv_row {
1.80 raeburn 8114: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 8115: my ($cnum) = &get_course();
1.56 raeburn 8116: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 8117: if (ref($settings) eq 'HASH') {
8118: if ($settings->{$item} ne '') {
8119: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
8120: if ($user !~ /:/) {
8121: $nothide{join(':',split(/[\@]/,$user))}=1;
8122: } else {
8123: $nothide{$user} = 1;
8124: }
8125: }
8126: }
1.56 raeburn 8127: if ($settings->{'checkforpriv'}) {
1.124 raeburn 8128: @checkdoms = split(/,/,$settings->{'checkforpriv'});
1.56 raeburn 8129: }
1.1 raeburn 8130: }
1.56 raeburn 8131: push(@checkdoms,$cdom);
8132: my %coursepersonnel =
8133: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 8134: my @privusers;
8135: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 8136: my ($uname,$udom,$role) = split(/:/,$person);
8137: my $user = $uname.':'.$udom;
8138: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 8139: if ($end == -1 || $start == -1) {
8140: next;
8141: }
1.124 raeburn 8142: foreach my $dom (@checkdoms) {
1.56 raeburn 8143: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
8144: unless (grep(/^\Q$user\E$/,@privusers)) {
8145: push(@privusers,$user);
1.3 raeburn 8146: }
8147: }
8148: }
1.1 raeburn 8149: }
1.56 raeburn 8150: if (@privusers > 0) {
1.80 raeburn 8151: my $disabled;
8152: if ($noedit) {
8153: $disabled = ' disabled="disabled"';
8154: }
1.1 raeburn 8155: $datatable .= '<table align="right">';
8156: foreach my $user (sort(@privusers)) {
8157: my $hideon = ' checked="checked" ';
8158: my $hideoff = '';
8159: if ($nothide{$user}) {
8160: $hideoff = $hideon;
8161: $hideon = '';
8162: }
8163: my ($uname,$udom) = split(':',$user);
8164: $datatable .= '<tr><td align="left">'.
8165: &Apache::loncommon::aboutmewrapper(
8166: &Apache::loncommon::plainname($uname,$udom,'firstname'),
8167: $uname,$udom,'aboutuser').
8168: '</td><td align="left">'.
8169: '<span class="LC_nobreak"><label>'.
8170: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8171: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 8172: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8173: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 8174: '</tr>';
8175: }
8176: $datatable .= '</table>';
8177: } else {
1.9 raeburn 8178: if ($crstype eq 'Community') {
8179: $datatable .= &mt('No Domain Coordinators have community roles');
8180: } else {
8181: $datatable .= &mt('No Domain Coordinators have course roles');
8182: }
1.1 raeburn 8183: }
8184: return $datatable;
8185: }
8186:
1.56 raeburn 8187: sub checkforpriv_row {
1.80 raeburn 8188: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 8189: my $datatable;
8190: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8191: if (keys(%domains) == 1) {
8192: $datatable = '</td><td align="right">'.
8193: &mt("Course's domain is only domain");
8194: return $datatable;
8195: }
8196: my @excdoms = ($cdom);
8197: my $num = 0;
8198: if ($settings->{$item} eq '') {
8199: $datatable = '</td><td align="right">'.
8200: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 8201: 1,1,undef,undef,\@excdoms,
8202: $noedit);
1.56 raeburn 8203: } else {
8204: my @privdoms = split(/,/,$settings->{$item});
8205: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8206: $datatable = '</td><td align="right"><br />'.
8207: &Apache::loncommon::start_data_table();
1.80 raeburn 8208: my $disabled;
8209: if ($noedit) {
8210: $disabled = ' disabled="disabled"';
8211: }
1.56 raeburn 8212: if (@privdoms > 0) {
8213: foreach my $currdom (@privdoms) {
8214: next unless ($domains{$currdom});
8215: my $domdesc = &Apache::lonnet::domain($currdom,'description');
8216: if ($domdesc eq '') {
8217: $domdesc = $currdom;
1.124 raeburn 8218: }
1.56 raeburn 8219: $datatable .=
8220: &Apache::loncommon::start_data_table_row().
8221: '<td align="left"><span class="LC_nobreak">'.
8222: &mt('Domain:').'<b> '.$domdesc.
8223: '</b><input type="hidden" name="checkforpriv_'.$num.
8224: '" value="'.$currdom.'" /></span><br />'.
8225: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 8226: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
8227: &mt('Delete').'</label></span></td>'.
1.56 raeburn 8228: &Apache::loncommon::end_data_table_row();
8229: $num ++;
1.124 raeburn 8230: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
1.56 raeburn 8231: push(@excdoms,$currdom);
8232: }
8233: }
8234: }
8235: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
1.124 raeburn 8236: $datatable .=
1.56 raeburn 8237: &Apache::loncommon::start_data_table_row().
8238: '<td align="left"><span class="LC_nobreak">'.
8239: &mt('Additional domain:'). '</span><br />'.
8240: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8241: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8242: '</td>'.&Apache::loncommon::end_data_table_row();
8243: }
8244: $datatable .= &Apache::loncommon::end_data_table().
8245: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8246: '<br />';
8247: }
8248: return $datatable;
8249: }
8250:
1.1 raeburn 8251: sub print_hdrfmt_row {
1.80 raeburn 8252: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8253: my @curr;
8254: my $currnum = 0;
8255: my $maxnum = 2;
8256: my $currstr;
8257: if ($settings->{$item} ne '') {
8258: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8259: $settings->{$item}.'</tt></span></b><br />';
8260: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8261: foreach my $val (@current) {
8262: unless ($val eq '') {
8263: push(@curr,$val);
1.1 raeburn 8264: }
8265: }
8266: $currnum = @curr;
8267: $maxnum += $currnum;
8268: }
8269:
8270: my $output = <<ENDJS;
8271:
8272: <script type="text/javascript" language="Javascript">
8273:
8274: function reOrder(chgnum) {
8275: var maxnum = $maxnum;
8276: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8277: var newidx = 'printfmthdr_pos_'+chgnum;
8278: oldidx = getIndexByName(oldidx);
8279: newidx = getIndexByName(newidx);
8280: var oldpos = document.display.elements[oldidx].value;
8281: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8282: document.display.elements[oldidx].value = newpos;
8283: var chgtype = 'up';
8284: if (newpos < oldpos) {
8285: chgtype = 'down';
8286: }
8287: for (var j=0; j<maxnum; j++) {
8288: if (j != chgnum) {
8289: oldidx = 'printfmthdr_oldpos_'+j;
8290: newidx = 'printfmthdr_pos_'+j;
8291: oldidx = getIndexByName(oldidx);
8292: newidx = getIndexByName(newidx);
8293: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8294: var currsel = document.display.elements[newidx].selectedIndex;
8295: if (chgtype == 'up') {
8296: if ((currpos > oldpos) && (currpos <= newpos)) {
8297: document.display.elements[newidx].selectedIndex = currsel-1;
8298: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8299: }
8300: } else {
8301: if ((currpos >= newpos) && (currpos < oldpos)) {
8302: document.display.elements[newidx].selectedIndex = currsel+1;
8303: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8304: }
8305: }
8306: }
8307: }
8308: return;
8309: }
8310:
8311: function getIndexByName(item) {
8312: for (var i=0;i<document.display.elements.length;i++) {
8313: if (document.display.elements[i].name == item) {
8314: return i;
8315: }
8316: }
8317: return -1;
8318: }
8319:
8320: </script>
8321:
8322: ENDJS
1.56 raeburn 8323: $output .= '</td><td align="right"><br />'.
8324: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8325: my $disabled;
8326: if ($noedit) {
8327: $disabled = ' disabled="disabled"';
8328: }
1.1 raeburn 8329: if (@curr > 0) {
8330: for (my $i=0; $i<@curr; $i++) {
8331: my $pos = $i+1;
1.10 raeburn 8332: $output .= '<tr>'.
1.1 raeburn 8333: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8334: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8335: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8336: '"'.$disabled.' /></span></td>';
1.1 raeburn 8337: if ($curr[$i] =~ /^%\d*[nca]$/) {
8338: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8339: $output .= '<td align="left">'.
1.80 raeburn 8340: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8341: } else {
8342: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8343: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8344: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8345: }
1.10 raeburn 8346: $output .= '</tr>';
1.1 raeburn 8347: }
8348: }
1.80 raeburn 8349: my $pos = $currnum+1;
1.124 raeburn 8350: unless ($noedit) {
1.80 raeburn 8351: $output .=
8352: '<tr>'.
1.1 raeburn 8353: '<td align="left"><span class="LC_nobreak">'.
8354: &position_selector($pos,$currnum,$maxnum).
8355: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8356: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8357: '</tr>';
1.80 raeburn 8358: $pos ++;
1.82 raeburn 8359: $currnum ++;
8360: $output .=
1.80 raeburn 8361: '<tr>'.
1.1 raeburn 8362: '<td align="left"><span class="LC_nobreak">'.
8363: &position_selector($pos,$currnum,$maxnum).
8364: '<b>'.&mt('New').'</b></span></td>'.
8365: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8366: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8367: '" value="" size ="25" />'.
8368: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8369: $maxnum.'" /></td>'.
1.80 raeburn 8370: '</tr>';
8371: }
8372: $output .= '</table><br />';
1.1 raeburn 8373: return $output;
8374: }
8375:
8376: sub position_selector {
1.80 raeburn 8377: my ($pos,$num,$maxnum,$disabled) = @_;
8378: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8379: for (my $j=1; $j<=$maxnum; $j++) {
8380: my $sel = '';
8381: if ($pos == $j) {
8382: $sel = ' selected="selected"';
8383: }
8384: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8385: }
8386: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8387: '" value="'.$pos.'" />';
8388: return $output;
8389: }
8390:
8391: sub substitution_selector {
1.80 raeburn 8392: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8393: my ($stunametxt,$crsidtxt);
8394: if ($crstype eq 'Community') {
8395: $stunametxt = 'member name';
8396: $crsidtxt = 'community ID',
8397: } else {
8398: $stunametxt = 'student name';
8399: $crsidtxt = 'course ID',
8400: }
1.1 raeburn 8401: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8402: n => $stunametxt,
8403: c => $crsidtxt,
1.1 raeburn 8404: a => 'assignment note',
8405: );
8406: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8407: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8408: if ($subst eq '') {
8409: $output .= '<option value="" selected="selected"> </option>';
8410: }
8411: foreach my $field ('n','c','a') {
8412: my $sel ='';
8413: if ($subst eq $field) {
8414: $sel = ' selected="selected"';
8415: }
8416: $output .= '<option value="'.$field.'"'.$sel.'>'.
8417: $lt{$field}.'</option>';
8418: }
8419: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8420: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8421: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8422: return $output;
8423: }
8424:
1.23 raeburn 8425: sub change_clone {
8426: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8427: my $clone_crs = $cnum.':'.$cdom;
8428: if ($cnum && $cdom) {
8429: my $clone_crs = $cnum.':'.$cdom;
8430: my @allowclone;
8431: if ($clonelist =~ /,/) {
8432: @allowclone = split(',',$clonelist);
8433: } else {
8434: $allowclone[0] = $clonelist;
8435: }
8436: foreach my $currclone (@allowclone) {
8437: if (!grep(/^$currclone$/,@$oldcloner)) {
8438: if ($currclone ne '*') {
1.71 raeburn 8439: if ($currclone =~ /:/) {
8440: my ($uname,$udom) = split(/:/,$currclone);
8441: if ($uname && $udom && $uname ne '*') {
8442: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8443: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8444: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8445: if ($currclonecrs{'cloneable'} eq '') {
8446: $currclonecrs{'cloneable'} = $clone_crs;
8447: } else {
8448: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8449: }
8450: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8451: }
8452: }
8453: }
8454: }
8455: }
8456: }
8457: }
8458: foreach my $oldclone (@$oldcloner) {
8459: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8460: if ($oldclone ne '*') {
1.71 raeburn 8461: if ($oldclone =~ /:/) {
8462: my ($uname,$udom) = split(/:/,$oldclone);
8463: if ($uname && $udom && $uname ne '*' ) {
8464: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8465: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8466: my %newclonecrs = ();
8467: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8468: if ($currclonecrs{'cloneable'} =~ /,/) {
8469: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8470: foreach my $crs (@currclonecrs) {
8471: if ($crs ne $clone_crs) {
8472: $newclonecrs{'cloneable'} .= $crs.',';
8473: }
1.23 raeburn 8474: }
1.71 raeburn 8475: $newclonecrs{'cloneable'} =~ s/,$//;
8476: } else {
8477: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8478: }
1.71 raeburn 8479: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8480: }
8481: }
8482: }
8483: }
8484: }
8485: }
8486: }
8487: }
8488: return;
8489: }
8490:
1.108 raeburn 8491: sub devalidate_remote_courseprefs {
8492: my ($cdom,$cnum,$cachekeys) = @_;
8493: return unless (ref($cachekeys) eq 'HASH');
8494: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8495: my %thismachine;
8496: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8497: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8498: if (keys(%servers)) {
8499: foreach my $server (keys(%servers)) {
8500: next if ($thismachine{$server});
8501: my @cached;
8502: foreach my $name (@posscached) {
8503: if ($cachekeys->{$name}) {
8504: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8505: }
8506: }
8507: if (@cached) {
8508: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8509: }
8510: }
8511: }
8512: return;
8513: }
8514:
1.1 raeburn 8515: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>