Annotation of loncom/interface/courseprefs.pm, revision 1.132
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.132 ! raeburn 4: # $Id: courseprefs.pm,v 1.131 2024/02/24 23:41:44 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: }
1.132 ! raeburn 5301: return OK;
1.66 raeburn 5302: }
5303:
1.25 raeburn 5304: sub show_autocoowners {
5305: my (@currcoown) = @_;
1.56 raeburn 5306: 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 5307: if (@currcoown > 0) {
5308: $output .= '<br />'.&mt('Current co-owners are:').' '.
5309: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5310: } else {
5311: $output .= '<br />'.&mt('Currently no co-owners.');
5312: }
5313: return $output;
5314: }
5315:
5316: sub coowner_invitations {
1.80 raeburn 5317: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5318: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 5319: my $pendingcoowners =
5320: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5321: if ($pendingcoowners) {
5322: @pendingcoown = split(',',$pendingcoowners);
5323: }
1.80 raeburn 5324: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5325: @currcoown = @{$currcoownref};
1.80 raeburn 5326: }
5327: my $disabled;
5328: if ($noedit) {
5329: $disabled = ' disabled="disabled"';
5330: }
1.25 raeburn 5331: my $ccrole = 'cc';
5332: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
5333: foreach my $key (sort(keys(%ccroles))) {
5334: my ($ccname,$ccdom,$role) = split(':',$key);
5335: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
5336: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
5337: push(@othercoords,$ccname.':'.$ccdom);
5338: }
5339: }
5340: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
5341: if ($coowner_rows) {
5342: $output .= &Apache::loncommon::start_data_table();
5343: if (@currcoown) {
5344: $output .= &Apache::loncommon::start_data_table_row().
5345: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
5346: foreach my $person (@currcoown) {
5347: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5348: $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 5349: }
5350: $output .= '</td>'.
5351: &Apache::loncommon::end_data_table_row();
5352: }
5353: if ($pendingcoowners) {
5354: $output .= &Apache::loncommon::start_data_table_row().
5355: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
5356: foreach my $person (@pendingcoown) {
5357: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5358: $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 5359: }
5360: $output .= '</td>'.
5361: &Apache::loncommon::end_data_table_row();
5362: }
5363: if (@othercoords) {
5364: $output .= &Apache::loncommon::start_data_table_row().
5365: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
5366: foreach my $person (@othercoords) {
5367: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 5368: $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 5369: }
5370: $output .= '</td>'.
5371: &Apache::loncommon::end_data_table_row();
5372: }
5373: $output .= &Apache::loncommon::end_data_table();
5374: } else {
5375: $output = &mt('There are no coordinators to select as co-owners');
5376: }
5377: return $output;
5378: }
5379:
5380: sub manage_coownership {
1.80 raeburn 5381: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
5382: my (@pendingcoown,@currcoown);
1.25 raeburn 5383: my $pendingcoowners =
5384: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
5385: if ($pendingcoowners) {
5386: @pendingcoown = split(',',$pendingcoowners);
5387: }
1.80 raeburn 5388: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 5389: @currcoown = @{$currcoownref};
1.80 raeburn 5390: }
5391: my $disabled;
5392: if ($noedit) {
5393: $disabled = ' disabled="disabled"';
5394: }
1.25 raeburn 5395: my ($is_coowner,$is_pending,$output);
5396: my $uname = $env{'user.name'};
5397: my $udom = $env{'user.domain'};
5398: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
5399: $is_coowner = 1;
5400: }
5401: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
5402: $is_pending = 1;
5403: }
5404: if (@currcoown && ($is_coowner || $is_pending)) {
5405: $output = &Apache::loncommon::start_data_table();
5406: }
5407: if (@currcoown) {
5408: if ($is_coowner || $is_pending) {
5409: $output .= &Apache::loncommon::start_data_table().
5410: &Apache::loncommon::start_data_table_row().'<td>';
5411: }
5412: $output .= &mt('Current co-owners are:').' '.
5413: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
5414: if ($is_coowner || $is_pending) {
5415: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5416: }
5417: }
5418: if ($is_coowner || $is_pending) {
5419: if (@currcoown) {
5420: $output .= &Apache::loncommon::start_data_table_row().'<td>';
5421: }
5422: $output .= '<span class="LC_nobreak">';
5423: if ($is_coowner) {
1.90 raeburn 5424: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 5425: } else {
1.90 raeburn 5426: $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).
5427: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 5428: }
5429: $output .= '</span>';
5430: if (@currcoown) {
5431: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
5432: }
5433: }
5434: if (@currcoown && ($is_coowner || $is_pending)) {
5435: $output .= &Apache::loncommon::end_data_table();
5436: }
5437: return $output;
5438: }
5439:
1.1 raeburn 5440: sub print_localization {
1.80 raeburn 5441: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5442: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5443: return;
5444: }
5445: my %items = (
5446: languages => {
1.17 faziophi 5447: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
5448: &mt("(overrides individual user preference)"),
1.1 raeburn 5449: input => 'selectbox',
5450: },
5451: timezone => {
1.17 faziophi 5452: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 5453: input => 'selectbox',
5454: },
5455: datelocale => {
1.17 faziophi 5456: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 5457: input => 'selectbox',
5458: },
5459: );
1.80 raeburn 5460: my ($datatable,$disabled);
1.1 raeburn 5461: my $count = 0;
1.80 raeburn 5462: if ($noedit) {
5463: $disabled = ' disabled="disabled"';
5464: }
1.1 raeburn 5465: foreach my $item (@{$ordered}) {
5466: $count ++;
1.56 raeburn 5467: my $colspan;
5468: unless ($item eq 'languages') {
1.80 raeburn 5469: $colspan = 2;
1.56 raeburn 5470: }
5471: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5472: if ($item eq 'timezone') {
5473: my $includeempty = 1;
5474: my $timezone = &Apache::lonlocal::gettimezone();
1.115 raeburn 5475: my $onchange;
5476: unless ($noedit) {
5477: $onchange = ' onchange="javascript:toggleTimeZone();"';
5478: }
5479: my $id = ' id="LC_set_timezone"';
1.1 raeburn 5480: $datatable .=
1.115 raeburn 5481: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
5482: $includeempty,$id,$disabled);
5483: my $tzsty = 'none';
5484: if ($timezone ne '') {
5485: $tzsty = 'block';
5486: }
5487: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
5488: '<span class="LC_nobreak">'.
5489: &mt('Override individual user preference?').
5490: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
5491: '</span></div>';
1.1 raeburn 5492: } elsif ($item eq 'datelocale') {
5493: my $includeempty = 1;
5494: my $locale_obj = &Apache::lonlocal::getdatelocale();
5495: my $currdatelocale;
5496: if (ref($locale_obj)) {
5497: $currdatelocale = $locale_obj->id();
5498: }
5499: $datatable .=
5500: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 5501: undef,$includeempty,$disabled);
1.1 raeburn 5502: } else {
5503: if ($settings->{$item} eq '') {
1.124 raeburn 5504: unless ($noedit) {
1.80 raeburn 5505: $datatable .= '</td><td align="right">'.
5506: &Apache::loncommon::select_language('languages_0','',1);
5507: }
1.1 raeburn 5508: } else {
5509: my $num = 0;
1.3 raeburn 5510: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 5511: $datatable .= '</td><td align="right"><br />'.
5512: &Apache::loncommon::start_data_table();
1.1 raeburn 5513: if (@languages > 0) {
1.3 raeburn 5514: my %langchoices = &get_lang_choices();
1.1 raeburn 5515: foreach my $lang (@languages) {
5516: my $showlang = $lang;
1.3 raeburn 5517: if (exists($langchoices{$lang})) {
5518: $showlang = $langchoices{$lang};
1.1 raeburn 5519: }
5520: $datatable .=
5521: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5522: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 5523: &mt('Language:').'<b> '.$showlang.
5524: '</b><input type="hidden" name="languages_'.$num.
5525: '" value="'.$lang.'" /></span><br />'.
5526: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 5527: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5528: &mt('Delete').'</label></span></td>'.
1.3 raeburn 5529: &Apache::loncommon::end_data_table_row();
1.1 raeburn 5530: $num ++;
5531: }
5532: }
1.80 raeburn 5533: unless ($noedit) {
5534: $datatable .=
5535: &Apache::loncommon::start_data_table_row().
1.3 raeburn 5536: '<td align="left"><span class="LC_nobreak">'.
5537: &mt('Additional language:'). '</span><br />'.
5538: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 5539: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 5540: '</td>'.&Apache::loncommon::end_data_table_row();
1.124 raeburn 5541: }
5542: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5543: }
5544: }
5545: $datatable .= &item_table_row_end();
5546: }
5547: $$rowtotal += scalar(@{$ordered});
5548: return $datatable;
5549: }
5550:
1.3 raeburn 5551: sub get_lang_choices {
5552: my %langchoices;
5553: foreach my $id (&Apache::loncommon::languageids()) {
5554: my $code = &Apache::loncommon::supportedlanguagecode($id);
5555: if ($code) {
5556: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5557: }
5558: }
5559: return %langchoices;
5560: }
5561:
1.1 raeburn 5562: sub print_feedback {
1.80 raeburn 5563: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5564: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5565: return;
5566: }
5567: my %items = (
1.3 raeburn 5568: 'question.email' => {
5569: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 5570: input => 'textbox',
5571: size => '50',
5572: },
5573:
1.3 raeburn 5574: 'comment.email' => {
5575: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 5576: input => 'textbox',
5577: size => '50',
5578: },
5579:
1.3 raeburn 5580: 'policy.email' => {
5581: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 5582: input => 'textbox',
5583: size => '50',
5584: },
5585: );
5586: my $datatable;
5587: my $count = 0;
5588: my ($cnum) = &get_course();
5589: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5590: my @sections = sort( { $a <=> $b } keys(%sections));
5591: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5592: currone => 'Current recipient:',
5593: currmult => 'Current recipients:',
5594: add => 'Additional recipient:',
5595: del => 'Delete?',
5596: sec => 'Sections:',
1.1 raeburn 5597: );
1.80 raeburn 5598: my $disabled;
5599: if ($noedit) {
5600: $disabled = ' disabled="disabled"';
5601: }
1.1 raeburn 5602: foreach my $item (@{$ordered}) {
5603: $count ++;
1.20 faziophi 5604: if ($position eq 'top') {
5605: $datatable .= &item_table_row_start($items{$item}{text},$count);
5606: } else {
1.56 raeburn 5607: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 5608: }
1.1 raeburn 5609: if ($position eq 'top') {
5610: my $includeempty = 0;
1.94 raeburn 5611: $datatable .= '</td><td align="right">'.
5612: &user_table($cdom,$item,\@sections,
1.80 raeburn 5613: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5614: } else {
1.3 raeburn 5615: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 5616: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 5617: }
5618: $datatable .= &item_table_row_end();
5619: }
5620: $$rowtotal += scalar(@{$ordered});
5621: return $datatable;
5622: }
5623:
5624: sub user_table {
1.80 raeburn 5625: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 5626: my $output;
5627: if ($currvalue eq '') {
1.80 raeburn 5628: unless ($noedit) {
5629: $output .= &select_recipient($item,'0',$cdom,$sections);
5630: }
1.1 raeburn 5631: } else {
5632: my $num = 0;
5633: my @curr = split(/,/,$currvalue);
1.56 raeburn 5634: $output .= '<table class="LC_data_table">';
1.1 raeburn 5635: my ($currusers);
1.80 raeburn 5636: my $disabled;
5637: if ($noedit) {
5638: $disabled = ' disabled="disabled"';
5639: }
1.1 raeburn 5640: foreach my $val (@curr) {
5641: next if ($val eq '');
5642: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
5643: my @selsec;
5644: if ($seclist) {
5645: $seclist =~ s/(^\(|\)$)//g;
5646: @selsec = split(/\s*;\s*/,$seclist);
5647: }
5648: $currusers .= '<tr>'.
5649: '<td valign="top"><span class="LC_nobreak">'.
5650: '<label><input type="checkbox" '.
1.80 raeburn 5651: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 5652: $lt->{'del'}.'</label>'.
5653: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 5654: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 5655: &Apache::loncommon::aboutmewrapper(
5656: &Apache::loncommon::plainname($uname,$udom,'firstname'),
5657: $uname,$udom,'aboutuser');
5658: if (ref($sections) eq 'ARRAY') {
5659: if (@{$sections}) {
5660: $currusers.= (' 'x3).$lt->{'sec'}.' '.
5661: &select_sections($item,$num,$sections,
1.80 raeburn 5662: \@selsec,$noedit);
1.1 raeburn 5663: }
5664: }
5665: $currusers .= '</span></td></tr>';
5666: $num ++;
5667: }
5668: if ($num) {
1.10 raeburn 5669: $output .= '<tr>'.
1.1 raeburn 5670: '<td align="left"><i>';
1.20 faziophi 5671: if ($num == 1) {
1.1 raeburn 5672: $output .= $lt->{'currone'};
5673: } else {
1.21 raeburn 5674: $output .= $lt->{'currmult'};
1.1 raeburn 5675: }
5676: $output .= '</i><br />'.
5677: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 5678: '</tr>';
1.1 raeburn 5679: }
1.80 raeburn 5680: unless ($noedit) {
5681: $output .=
5682: '<tr>'.
1.1 raeburn 5683: '<td align="left"><span class="LC_nobreak"><i>'.
5684: $lt->{'add'}.'</i></span><br />'.
5685: &select_recipient($item,$num,$cdom,$sections).
5686: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 5687: '</td></tr>';
5688: }
5689: $output .= '</table>';
1.1 raeburn 5690: }
5691: return $output;
5692: }
5693:
5694: sub select_recipient {
5695: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
5696: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
5697: my $selectlink =
5698: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 5699: $item.'_udom_'.$num,'only');
1.1 raeburn 5700: my $output =
1.10 raeburn 5701: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 5702: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
5703: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
5704: if (ref($sections) eq 'ARRAY') {
5705: if (@{$sections}) {
5706: $output .= '<td align="center">'.&mt('Sections').'<br />'.
5707: &select_sections($item,$num,$sections,$selected).'</td>';
5708: }
5709: }
5710: $output .= '<td valign="top">'.
5711: $selectlink.'</td></tr></table>';
5712: return $output;
5713: }
5714:
5715: sub select_sections {
1.127 raeburn 5716: my ($item,$num,$sections,$selected,$noedit,$allval) = @_;
1.80 raeburn 5717: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 5718: if (ref($selected) eq 'ARRAY') {
5719: @currsecs = @{$selected};
5720: }
5721: if (!@currsecs) {
5722: $allsec = ' selected="selected"';
5723: }
1.80 raeburn 5724: if ($noedit) {
5725: $disabled = ' disabled="disabled"';
5726: }
1.1 raeburn 5727: if (ref($sections) eq 'ARRAY') {
5728: if (@{$sections}) {
5729: my $mult;
5730: if (@{$sections} > 1) {
5731: $mult = ' multiple="multiple"';
1.127 raeburn 5732: my $size;
1.1 raeburn 5733: if (@{$sections} > 3) {
1.127 raeburn 5734: $size = 4;
5735: } else {
5736: $size = 1 + scalar(@{$sections});
1.1 raeburn 5737: }
1.127 raeburn 5738: $mult .= ' size="'.$size.'"';
5739: }
5740: my $name = $item.'_sections';
5741: unless ($item eq 'hidetotals') {
5742: $name .= '_'.$num;
1.1 raeburn 5743: }
1.127 raeburn 5744: $output = '<select name="'.$name.'"'.$mult.$disabled.'>'.
5745: ' <option value="'.$allval.'"'.$allsec.'>'.&mt('All').'</option>';
1.1 raeburn 5746: foreach my $sec (@{$sections}) {
5747: my $is_sel;
5748: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
1.127 raeburn 5749: $is_sel = ' selected="selected"';
1.1 raeburn 5750: }
5751: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
5752: }
5753: $output .= '</select>';
5754: }
5755: }
5756: return $output;
5757: }
5758:
5759: sub print_discussion {
1.80 raeburn 5760: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 5761: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5762: return;
5763: }
5764: my %items = (
5765: 'plc.roles.denied' => {
1.10 raeburn 5766: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
5767: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 5768: &mt('(role-based)'),
1.1 raeburn 5769: input => 'checkbox',
5770: },
5771:
5772: 'plc.users.denied' => {
1.3 raeburn 5773: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
5774: &mt('(specific user(s))'),
1.1 raeburn 5775: input => 'checkbox',
5776: },
5777:
5778: 'pch.roles.denied' => {
1.10 raeburn 5779: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
5780: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 5781: &mt('(role-based)'),
1.1 raeburn 5782: input => 'checkbox',
5783: },
5784:
5785: 'pch.users.denied' => {
1.3 raeburn 5786: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
5787: &mt('(specific user(s))'),
1.1 raeburn 5788: input => 'checkbox',
5789: },
1.77 raeburn 5790:
5791: 'pac.roles.denied' => {
5792: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
5793: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
5794: &mt('(role-based)'),
5795: input => 'checkbox',
5796: },
5797:
5798: 'pac.users.denied' => {
5799: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
5800: &mt('(specific user(s))'),
5801: input => 'checkbox',
5802: },
5803:
1.1 raeburn 5804: 'allow_limited_html_in_feedback' => {
1.3 raeburn 5805: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 5806: input => 'radio',
5807: },
5808:
5809: 'allow_discussion_post_editing' => {
1.3 raeburn 5810: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 5811: input => 'checkbox',
5812: },
1.50 raeburn 5813: 'discussion_post_fonts' => {
5814: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
5815: input => 'textbox',
5816: size => '20',
5817: },
1.1 raeburn 5818: );
5819: my $datatable;
5820: my $count;
5821: my ($cnum) = &get_course();
5822: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5823: my @sections = sort( { $a <=> $b } keys(%sections));
5824: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 5825: currone => 'Disallowed:',
5826: currmult => 'Disallowed:',
5827: add => 'Disallow more:',
5828: del => 'Delete?',
5829: sec => 'Sections:',
1.1 raeburn 5830: );
5831: foreach my $item (@{$ordered}) {
5832: $count ++;
1.56 raeburn 5833: my $colspan;
5834: if ($item eq 'allow_limited_html_in_feedback') {
5835: $colspan = 2;
1.124 raeburn 5836: }
1.56 raeburn 5837: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 5838: if ($item eq 'plc.roles.denied') {
1.56 raeburn 5839: $datatable .= '</td><td align="right">'.
1.80 raeburn 5840: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5841: '</table>';
5842: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 5843: $datatable .= '</td><td align="right">'.
5844: &user_table($cdom,$item,undef,
1.80 raeburn 5845: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5846: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 5847: $datatable .= '</td><td align="right">'.
1.80 raeburn 5848: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 5849: '</table>';
5850: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 5851: $datatable .= '</td><td align="right">'.
5852: &user_table($cdom,$item,undef,
1.80 raeburn 5853: $settings->{$item},\%lt,$noedit);
1.77 raeburn 5854: } elsif ($item eq 'pac.roles.denied') {
5855: $datatable .= '</td><td align="right">'.
1.80 raeburn 5856: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 5857: '</table>';
5858: } elsif ($item eq 'pac.users.denied') {
5859: $datatable .= '</td><td align="right">'.
5860: &user_table($cdom,$item,undef,
1.80 raeburn 5861: $settings->{$item},\%lt,$noedit);
1.1 raeburn 5862: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 5863: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 5864: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 5865: $datatable .= '</td><td align="right"><br />'.
5866: &Apache::loncommon::start_data_table().
1.1 raeburn 5867: &Apache::loncommon::start_data_table_row().
5868: '<th align="left">'.&mt('Role').'</th><th>'.
5869: &mt('Sections').'</th>'.
5870: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5871: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 5872: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 5873: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 5874: $datatable .= '</td><td align="right"><br />'.
5875: &Apache::loncommon::start_data_table().
1.50 raeburn 5876: &Apache::loncommon::start_data_table_row().
5877: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
5878: '<th align="center">'.&mt('font-size').'</th>'.
5879: '<th align="center">'.&mt('font-weight').'</th>'.
5880: '<th align="center">'.&mt('font-style').'</th>'.
1.124 raeburn 5881: '<th align="center">'.&mt('Other css').'</th>'.
1.50 raeburn 5882: &Apache::loncommon::end_data_table_row().
1.80 raeburn 5883: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 5884: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 5885: }
5886: $datatable .= &item_table_row_end();
5887: }
5888: $$rowtotal += scalar(@{$ordered});
5889: return $datatable;
5890: }
5891:
5892: sub role_checkboxes {
1.80 raeburn 5893: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 5894: my @roles = ('st','ad','ta','ep','in');
5895: if ($crstype eq 'Community') {
5896: push(@roles,'co');
5897: } else {
5898: push(@roles,'cc');
5899: }
1.1 raeburn 5900: my $output;
5901: my (@current,@curr_roles,%currsec,@sections);
5902: if ($showsections) {
5903: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
5904: @sections = sort( { $a <=> $b } keys(%sections));
5905: }
5906: if (ref($settings) eq 'HASH') {
5907: if ($settings->{$item}) {
5908: @current = split(',',$settings->{$item});
5909: if ($showsections) {
5910: foreach my $role (@current) {
5911: if ($role =~ /:/) {
5912: my ($trole,$sec) = split(':',$role);
5913: push(@curr_roles,$trole);
5914: if (ref($currsec{$trole}) eq 'ARRAY') {
5915: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
5916: push(@{$currsec{$trole}},$sec);
5917: }
1.3 raeburn 5918: } else {
5919: $currsec{$trole} = [$sec];
1.1 raeburn 5920: }
5921: } else {
5922: push(@curr_roles,$role);
5923: }
5924: }
5925: @current = @curr_roles;
5926: }
5927: }
5928: }
5929: my $numinrow = 3;
5930: my $count = 0;
1.80 raeburn 5931: my $disabled;
5932: if ($noedit) {
1.124 raeburn 5933: $disabled = ' disabled="disabled"';
1.80 raeburn 5934: }
1.1 raeburn 5935: foreach my $role (@roles) {
5936: my $checked = '';
5937: if (grep(/^\Q$role\E$/,@current)) {
5938: $checked = ' checked="checked" ';
5939: }
1.9 raeburn 5940: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 5941: if ($showsections) {
5942: $output .= &Apache::loncommon::start_data_table_row();
5943: } else {
5944: my $rem = $count%($numinrow);
5945: if ($rem == 0) {
5946: if ($count > 0) {
5947: $output .= '</tr>';
5948: }
5949: $output .= '<tr>';
5950: }
5951: }
1.30 raeburn 5952: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5953: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 5954: $plrole.'</label></span></td>';
5955: if ($showsections) {
5956: $output .= '<td align="left">'.
1.80 raeburn 5957: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5958: '</td></tr>';
5959: }
5960: $count ++;
5961: }
5962: my %adv_roles =
5963: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5964: my $total = @roles;
5965: foreach my $role (sort(keys(%adv_roles))) {
5966: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5967: my $rolename = $3;
5968: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5969: my $checked = '';
5970: if (grep(/^\Q$value\E$/,@current)) {
5971: $checked = ' checked="checked" ';
5972: }
5973: if ($showsections) {
5974: $output .= &Apache::loncommon::start_data_table_row();
5975: } else {
5976: my $rem = $count%($numinrow);
5977: if ($rem == 0) {
5978: if ($count > 0) {
5979: $output .= '</tr>';
5980: }
5981: $output .= '<tr>';
5982: }
5983: }
1.30 raeburn 5984: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5985: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5986: '</label></span></td>';
5987: if ($showsections) {
5988: $output .= '<td>'.
1.80 raeburn 5989: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5990: '</td>'.&Apache::loncommon::end_data_table_row();
5991: }
5992: $total ++;
5993: $count ++;
5994: }
5995: }
5996: if (!$showsections) {
5997: my $rem = $total%($numinrow);
5998: my $colsleft = $numinrow - $rem;
5999: if ($colsleft > 1 ) {
6000: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6001: ' </td>';
6002: } elsif ($colsleft == 1) {
6003: $output .= '<td class="LC_left_item"> </td>';
6004: }
6005: $output .= '</tr>';
6006: }
6007: return $output;
6008: }
6009:
1.50 raeburn 6010: sub set_discussion_fonts {
1.80 raeburn 6011: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 6012: my ($classorder,$classtitles) = &discussion_vote_classes();
6013: my ($styleorder,$styleitems) = &discussion_vote_styles();
6014: my $output;
6015: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 6016: my $disabled;
6017: if ($noedit) {
6018: $disabled = ' disabled="disabled"';
6019: }
1.50 raeburn 6020: foreach my $cat (@{$classorder}) {
6021: my %curr = ();
6022: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
6023: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
6024: $output .= &Apache::loncommon::start_data_table_row().
6025: '<td>'.$classtitles->{$cat}.'</td>';
6026: if (ref($styleorder) eq 'ARRAY') {
6027: foreach my $item (@{$styleorder}) {
6028: $output .= '<td><span class="LC_nobreak">';
6029: my $selitem = $item;
6030: if ($item eq 'size') {
6031: my ($currsize,$currunit);
6032: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
6033: ($currsize,$currunit) = ($1,$2);
6034: $curr{'size'} = $currunit;
6035: }
1.81 raeburn 6036: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 6037: ' ';
6038: $selitem = 'unit';
6039: }
6040: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 6041: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 6042: foreach my $val (@{$styleitems->{$item}}) {
6043: my $sel;
6044: if ($val eq $curr{$item}) {
6045: $sel = ' selected="selected"';
6046: }
6047: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
6048: }
6049: }
6050: }
6051: }
1.80 raeburn 6052: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 6053: }
6054: $output .= &Apache::loncommon::end_data_table_row();
6055: }
6056: return $output;
6057: }
6058:
6059: sub discussion_vote_classes {
6060: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
1.124 raeburn 6061: my %classtitles = &Apache::lonlocal::texthash(
1.50 raeburn 6062: 'twoplus' => 'Two sigma above mean',
6063: 'oneplus' => 'One sigma above mean',
6064: 'zero' => 'Within one sigma of mean',
6065: 'oneminus' => 'One sigma below mean',
6066: 'twominus' => 'Two sigma below mean',
6067: );
6068: return ($classorder,\%classtitles);
6069: }
6070:
6071: sub discussion_vote_styles {
6072: my $styleorder = ['size','weight','style'];
6073: my $styleitems = {
6074: size => ['','px','%','xx-small','x-small','small','medium','large',
6075: 'x-large','xx-large','smaller','larger'],
6076: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
6077: '500','600','700','800','900'],
6078: style => ['','normal','italic','oblique'],
6079: };
6080: return ($styleorder,$styleitems);
6081: }
6082:
1.1 raeburn 6083: sub print_classlists {
1.80 raeburn 6084: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 6085: my @ordered;
6086: if ($position eq 'top') {
6087: @ordered = ('default_enrollment_start_date',
6088: 'default_enrollment_end_date');
1.55 raeburn 6089: if ($crstype eq 'Course') {
6090: push(@ordered,'defaultcredits');
6091: }
1.1 raeburn 6092: } elsif ($position eq 'middle') {
1.56 raeburn 6093: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 6094: } else {
6095: @ordered = ('student_classlist_view',
1.26 raeburn 6096: 'student_classlist_opt_in',
6097: 'student_classlist_portfiles');
1.1 raeburn 6098: }
1.9 raeburn 6099: my %lt;
6100:
6101: if ($crstype eq 'Community') {
6102: %lt = &Apache::lonlocal::texthash (
6103: disabled => 'No viewable membership list',
6104: section => "Membership of viewer's section",
6105: all => 'List of all members',
6106: );
6107: } else {
6108: %lt = &Apache::lonlocal::texthash (
6109: disabled => 'No viewable classlist',
6110: section => "Classlist of viewer's section",
6111: all => 'Classlist of all students',
6112: );
6113: }
6114:
1.1 raeburn 6115: my %items = (
6116: 'default_enrollment_start_date' => {
1.3 raeburn 6117: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 6118: input => 'dates',
6119: },
6120: 'default_enrollment_end_date' => {
1.3 raeburn 6121: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 6122: input => 'dates',
6123: },
1.55 raeburn 6124: 'defaultcredits' => {
6125: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
6126: },
1.124 raeburn 6127:
1.1 raeburn 6128: 'nothideprivileged' => {
1.3 raeburn 6129: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 6130: input => 'checkbox',
6131: },
6132:
1.56 raeburn 6133: 'checkforpriv' => {
6134: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
6135: input => 'selectbox',
6136: },
6137:
1.1 raeburn 6138: 'student_classlist_view' => {
1.3 raeburn 6139: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 6140: input => 'selectbox',
1.9 raeburn 6141: options => \%lt,
1.1 raeburn 6142: order => ['disabled','all','section'],
6143: },
1.26 raeburn 6144: 'student_classlist_opt_in' => {
6145: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 6146: input => 'radio',
6147: },
6148:
6149: 'student_classlist_portfiles' => {
1.3 raeburn 6150: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 6151: input => 'radio',
6152: },
6153: );
6154: unless (($settings->{'student_classlist_view'} eq 'all') ||
6155: ($settings->{'student_classlist_view'} eq 'section')) {
6156: $settings->{'student_classlist_view'} = 'disabled';
6157: }
1.80 raeburn 6158: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 6159: }
6160:
6161: sub print_appearance {
1.80 raeburn 6162: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6163: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6164: return;
6165: }
1.9 raeburn 6166: my $mathdef;
6167: if ($crstype eq 'Community') {
6168: $mathdef = &mt("None specified - use member's choice");
6169: } else {
6170: $mathdef = &mt("None specified - use student's choice");
6171: }
1.1 raeburn 6172: my %items = (
6173: 'default_xml_style' => {
1.3 raeburn 6174: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 6175: '<a href="javascript:openbrowser'.
6176: "('display','default_xml_style'".
6177: ",'sty')".'">'.&mt('Select Style File').'</a>',
6178: input => 'textbox',
6179: size => 35,
6180: },
6181:
6182: 'pageseparators' => {
1.3 raeburn 6183: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 6184: input => 'radio',
6185: },
6186: 'disable_receipt_display' => {
1.3 raeburn 6187: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 6188: input => 'radio',
6189: },
6190: 'texengine' => {
1.3 raeburn 6191: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 6192: input => 'selectbox',
6193: options => {
1.61 raeburn 6194: MathJax => 'MathJax',
1.1 raeburn 6195: mimetex => &mt('Convert to Images'),
6196: tth => &mt('TeX to HTML'),
6197: },
1.75 raeburn 6198: order => ['MathJax','mimetex','tth'],
1.9 raeburn 6199: nullval => $mathdef,
1.1 raeburn 6200: },
6201: 'tthoptions' => {
1.3 raeburn 6202: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 6203: input => 'textbox',
6204: size => 40,
6205: },
1.69 raeburn 6206: 'uselcmath' => {
6207: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
6208: input => 'radio',
6209: },
6210: 'usejsme' => {
6211: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
6212: input => 'radio',
6213: },
1.95 raeburn 6214: 'inline_chem' => {
6215: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
6216: input => 'radio',
6217: },
1.114 raeburn 6218: 'extresource' => {
6219: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
6220: input => 'selectbox',
6221: options => {
6222: iframe => 'In iframe',
6223: tab => 'In new tab',
6224: window => 'In pop-up window',
6225: },
6226: order => ['iframe','tab','window'],
6227: },
1.1 raeburn 6228: );
1.80 raeburn 6229: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 6230: }
6231:
6232: sub print_grading {
1.127 raeburn 6233: my ($cdom,$cnum,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6234: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6235: return;
6236: }
6237: my %items = (
6238: 'grading' => {
1.3 raeburn 6239: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 6240: &Apache::loncommon::help_open_topic('GradingOptions'),
6241: input => 'selectbox',
6242: options => {
6243: standard => &mt('Standard: shows points'),
1.34 www 6244: categories => &mt('Categories: shows points according to categories'),
1.11 www 6245: external => &mt('External: shows number of completed parts and totals'),
6246: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 6247: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
6248: },
1.34 www 6249: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 6250: },
6251: 'rndseed' => {
1.3 raeburn 6252: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.127 raeburn 6253: '<br /><span class="LC_warning LC_nobreak">'.
1.1 raeburn 6254: &mt('Modifying this will make problems have different numbers and answers!').
6255: '</span>',
6256: input => 'selectbox',
6257: options => {
6258: '32bit' => '32bit',
6259: '64bit' => '64bit',
6260: '64bit2' => '64bit2',
6261: '64bit3' => '64bit3',
6262: '64bit4' => '64bit4',
6263: '64bit5' => '64bit5',
6264: },
6265: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 6266: advanced => 1
1.1 raeburn 6267: },
6268: 'receiptalg' => {
1.3 raeburn 6269: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 6270: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 6271: input => 'selectbox',
6272: options => {
6273: receipt => 'receipt',
6274: receipt2 => 'receipt2',
6275: receipt3 => 'receipt3',
6276: },
6277: order => ['receipt','receipt2','receipt3'],
1.41 www 6278: advanced => 1
1.1 raeburn 6279: },
6280: 'disablesigfigs' => {
1.3 raeburn 6281: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 6282: input => 'radio',
6283: },
6284: );
1.127 raeburn 6285: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit,$cnum);
1.1 raeburn 6286: }
6287:
6288: sub print_printouts {
1.80 raeburn 6289: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6290: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6291: return;
6292: }
6293: my %items = (
6294: problem_stream_switch => {
1.3 raeburn 6295: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 6296: input => 'radio',
6297: },
6298: suppress_tries => {
1.3 raeburn 6299: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 6300: input => 'radio',
6301: },
6302: default_paper_size => {
1.3 raeburn 6303: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 6304: input => 'selectbox',
6305: options => {
6306: Letter => &mt('Letter').' [8 1/2x11 in]',
6307: Legal => &mt('Legal').' [8 1/2x14 in]',
6308: Tabloid => &mt('Tabloid').' [11x17 in]',
6309: Executive => &mt('Executive').' [7 1/2x10 in]',
6310: A2 => &mt('A2').' [420x594 mm]',
6311: A3 => &mt('A3').' [297x420 mm]',
6312: A4 => &mt('A4').' [210x297 mm]',
6313: A5 => &mt('A5').' [148x210 mm]',
6314: A6 => &mt('A6').' [105x148 mm]',
6315: },
6316: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 6317: nullval => &mt('None specified'),
1.1 raeburn 6318: },
6319: print_header_format => {
1.3 raeburn 6320: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 6321: input => 'checkbox',
6322: },
6323: disableexampointprint => {
1.3 raeburn 6324: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 6325: input => 'radio',
6326: },
1.14 raeburn 6327: canuse_pdfforms => {
6328: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
6329: input => 'selectbox',
6330: options => {
6331: 1 => &mt('Yes'),
6332: 0 => &mt('No'),
6333: },
6334: order => ['1','0'],
1.54 bisitz 6335: nullval => &mt('None specified - use domain default'),
1.14 raeburn 6336: }
1.1 raeburn 6337: );
1.80 raeburn 6338: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 6339: }
6340:
6341: sub print_spreadsheet {
1.80 raeburn 6342: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6343: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6344: return;
6345: }
6346: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
6347: my %items = (
6348: spreadsheet_default_classcalc => {
1.3 raeburn 6349: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 6350: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6351: "('display','spreadsheet_default_classcalc'".
6352: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6353: input => 'textbox',
6354: },
6355: spreadsheet_default_studentcalc => {
1.3 raeburn 6356: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 6357: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6358: "('display','spreadsheet_default_calc'".
6359: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6360: input => 'textbox',
6361: },
6362: spreadsheet_default_assesscalc => {
1.3 raeburn 6363: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 6364: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
6365: "('display','spreadsheet_default_assesscalc'".
6366: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
6367: input => 'textbox',
6368: },
6369: hideemptyrows => {
1.3 raeburn 6370: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 6371: input => 'radio',
6372: },
6373: );
1.80 raeburn 6374: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 6375: }
1.1 raeburn 6376:
6377: sub print_bridgetasks {
1.80 raeburn 6378: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 6379: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 6380: return;
6381: }
1.9 raeburn 6382: my ($stumsg,$msgnote);
6383: if ($crstype eq 'Community') {
6384: $stumsg = &mt('Send message to member');
6385: $msgnote = &mt('Message to member and add to user notes');
6386: } else {
6387: $stumsg = &mt('Send message to student');
6388: $msgnote = &mt('Message to student and add to user notes');
6389: }
1.1 raeburn 6390: my %items = (
6391: task_messages => {
1.3 raeburn 6392: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 6393: input => 'selectbox',
6394: options => {
1.9 raeburn 6395: only_student => $stumsg,
6396: student_and_user_notes_screen => $msgnote,
1.1 raeburn 6397: },
6398: order => ['only_student','student_and_user_notes_screen'],
6399: nullval => &mt('No message or record in user notes'),
6400: },
6401: task_grading => {
1.3 raeburn 6402: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 6403: input => 'selectbox',
6404: options => {
6405: any => &mt('Grade BTs in any section'),
6406: section => &mt('Grade BTs only in own section')
6407: },
6408: order => ['any','section'],
6409: },
6410: suppress_embed_prompt => {
1.3 raeburn 6411: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
6412: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 6413: input => 'radio',
6414: },
6415: );
1.80 raeburn 6416: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 6417: }
6418:
1.118 raeburn 6419: sub print_ltitools {
6420: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
6421: my ($datatable,$disabled,$css_class,$dest);
1.121 raeburn 6422: if ($noedit) {
6423: $disabled = ' disabled="disabled"';
6424: }
1.120 raeburn 6425: my $itemcount = 1;
6426: unless ($context eq 'domain') {
6427: my %tooltypes = &Apache::loncommon::usable_exttools();
6428: unless ($tooltypes{'crs'}) {
6429: my $showtype = 'course';
6430: if ($crstype eq 'Community') {
6431: $showtype = lc($crstype);
6432: }
6433: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6434: $datatable = '<tr '.$css_class.'><td colspan="2">'.
6435: &mt("Definition of external tools is not enabled for this $showtype.").'<br />';
6436: if ($tooltypes{'dom'}) {
6437: $datatable .= &mt("Contact an administrator for the $showtype domain ([_1]) to request this feature be enabled.",
6438: '<i>'.$cdom.'</i>').
6439: '<br /><br />'.
6440: &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.");
6441: } else {
6442: $datatable .= &mt("Use of external tools defined at a domain level is not enabled, either, for this $showtype.").
6443: '<br /><br />'.
6444: &mt("Contact an administrator for the $showtype domain ([_1]) to request changes.",
6445: '<i>'.$cdom.'</i>');
6446:
6447: }
6448: $datatable .= '</tr>';
6449: $itemcount ++;
6450: return $datatable;
6451: }
6452: }
1.118 raeburn 6453: my %lt = <itools_names();
6454: my $maxnum = 0;
6455: my %ordered;
6456: if (ref($settings) eq 'HASH') {
6457: foreach my $item (keys(%{$settings})) {
6458: if (ref($settings->{$item}) eq 'HASH') {
6459: my $num = $settings->{$item}{'order'};
6460: $ordered{$num} = $item;
6461: }
6462: }
6463: }
6464:
6465: if ($context eq 'domain') {
6466: $dest = '/adm/domainprefs';
6467: } else {
6468: $dest = '/adm/courseprefs';
6469: }
6470: my ($switchserver,$switchmessage);
6471: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
6472: if ($switchserver) {
6473: if ($context eq 'domain') {
6474: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
6475: } elsif ($crstype eq 'Community') {
6476: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
6477: } else {
6478: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
6479: }
6480: }
6481: my $maxnum = scalar(keys(%ordered));
6482: my @courseroles = ('cc','in','ta','ep','st');
6483: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
6484: my @fields = ('fullname','firstname','lastname','email','roles','user');
6485: if (keys(%ordered)) {
6486: my @items = sort { $a <=> $b } keys(%ordered);
6487: for (my $i=0; $i<@items; $i++) {
6488: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6489: my $item = $ordered{$items[$i]};
6490: my ($title,$key,$url,$usable,$lifetime,$imgsrc,%sigsel);
6491: if (ref($settings->{$item}) eq 'HASH') {
6492: $title = $settings->{$item}->{'title'};
6493: $url = $settings->{$item}->{'url'};
6494: $key = $settings->{$item}->{'key'};
6495: $usable = $settings->{$item}->{'usable'};
6496: $lifetime = $settings->{$item}->{'lifetime'};
6497: my $image = $settings->{$item}->{'image'};
6498: if ($image ne '') {
6499: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
6500: }
6501: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
6502: $sigsel{'HMAC-256'} = ' selected="selected"';
6503: } else {
6504: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
6505: }
6506: }
6507: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
6508: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6509: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
6510: for (my $k=0; $k<=$maxnum; $k++) {
6511: my $vpos = $k+1;
6512: my $selstr;
6513: if ($k == $i) {
6514: $selstr = ' selected="selected" ';
6515: }
6516: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6517: }
6518: $datatable .= '</select>'.(' 'x2).
6519: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
6520: &mt('Delete?').'</label></span></td>'.
6521: '<td colspan="2">'.
6522: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6523: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
6524: (' 'x2).
6525: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
6526: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6527: (' 'x2).
6528: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
6529: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6530: (' 'x2).
6531: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
6532: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
6533: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
6534: '<br /><br />'.
1.120 raeburn 6535: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_url_'.$i.'"'.
1.118 raeburn 6536: ' value="'.$url.'" /></span>'.
6537: (' 'x2).
6538: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
6539: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span><br /><br />';
6540: if ($key ne '') {
6541: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6542: if ($noedit) {
6543: $datatable .= ': ['.&mt('not shown').']';
6544: } elsif ($switchserver) {
6545: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6546: } else {
6547: $datatable .= ':<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />';
6548: }
6549: $datatable .= '</span> '.(' 'x2);
6550: } elsif (!$switchserver) {
6551: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6552: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" autocomplete="off"'.$disabled.' />'.
6553: '</span> '.(' 'x2);
6554: }
6555: if ($switchserver) {
6556: if ($usable ne '') {
6557: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6558: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6559: '<span class="LC_nobreak">'.&mt('Change secret?').
6560: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6561: (' 'x2).
6562: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
6563: '</span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6564: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6565: '</div>';
6566: } elsif ($key eq '') {
6567: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6568: } else {
6569: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6570: }
6571: $datatable .= '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" />';
6572: } else {
6573: if ($usable ne '') {
6574: $datatable .= '<div id="ltitools_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6575: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6576: '<span class="LC_nobreak">'.&mt('Change?').
6577: '<label><input type="radio" value="0" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
6578: (' 'x2).
6579: '<label><input type="radio" value="1" name="ltitools_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','ltitools'".');"'.$disabled.' />'.&mt('Yes').
6580: '</label> </span><div id="ltitools_divchgsecret_'.$i.'" style="display:none" />'.
6581: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6582: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6583: '<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>'.
6584: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span></div>';
6585: } else {
6586: $datatable .=
6587: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6588: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
6589: '<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>'.
6590: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>';
6591: }
6592: }
6593: $datatable .= '</fieldset>'.
6594: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6595: '<span class="LC_nobreak">'.&mt('Display target:');
6596: my %currdisp;
6597: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
6598: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
6599: $currdisp{'window'} = ' checked="checked"';
6600: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
6601: $currdisp{'tab'} = ' checked="checked"';
6602: } else {
6603: $currdisp{'iframe'} = ' checked="checked"';
6604: }
6605: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
6606: $currdisp{'width'} = $1;
6607: }
6608: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
6609: $currdisp{'height'} = $1;
6610: }
6611: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
6612: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
6613: } else {
6614: $currdisp{'iframe'} = ' checked="checked"';
6615: }
6616: foreach my $disp ('iframe','tab','window') {
6617: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
6618: $lt{$disp}.'</label>'.(' 'x2);
6619: }
6620: $datatable .= (' 'x4);
6621: foreach my $dimen ('width','height') {
6622: $datatable .= '<label>'.$lt{$dimen}.' '.
6623: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
6624: (' 'x2);
6625: }
6626: $datatable .= '</span><br />'.
6627: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6628: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
6629: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6630: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
6631: '</textarea></div><div style=""></div><br />';
6632: my %units = (
6633: 'passback' => 'days',
6634: 'roster' => 'seconds',
6635: );
6636: foreach my $extra ('passback','roster') {
6637: my $validsty = 'none';
6638: my $currvalid;
6639: my $checkedon = '';
6640: my $checkedoff = ' checked="checked"';
6641: if ($settings->{$item}->{$extra}) {
6642: $checkedon = $checkedoff;
6643: $checkedoff = '';
6644: $validsty = 'inline-block';
6645: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
6646: $currvalid = $settings->{$item}->{$extra.'valid'};
6647: }
6648: }
6649: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
6650: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6651: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
6652: &mt('No').'</label>'.(' 'x2).
6653: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
6654: &mt('Yes').'</label></span></div>'.
6655: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
6656: '<span class="LC_nobreak">'.
6657: &mt("until at least [_1] $units{$extra} after launch",
6658: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
6659: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6660: }
6661: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
6662: if ($imgsrc) {
6663: $datatable .= $imgsrc.
6664: '<label><input type="checkbox" name="ltitools_image_del"'.
6665: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
6666: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
6667: } else {
6668: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6669: }
6670: if ($switchserver) {
6671: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6672: } else {
6673: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
6674: }
6675: $datatable .= '</span></fieldset>';
6676: my (%checkedfields,%rolemaps,$userincdom);
6677: if (ref($settings->{$item}) eq 'HASH') {
6678: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
6679: %checkedfields = %{$settings->{$item}->{'fields'}};
6680: }
6681: $userincdom = $settings->{$item}->{'incdom'};
6682: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
6683: %rolemaps = %{$settings->{$item}->{'roles'}};
6684: $checkedfields{'roles'} = 1;
6685: }
6686: }
6687: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6688: '<span class="LC_nobreak">';
6689: my $userfieldstyle = 'display:none;';
6690: my $seluserdom = '';
6691: my $unseluserdom = ' selected="selected"';
6692: foreach my $field (@fields) {
6693: my ($checked,$onclick,$id,$spacer);
6694: if ($checkedfields{$field}) {
6695: $checked = ' checked="checked"';
6696: }
6697: if ($field eq 'user') {
6698: $id = ' id="ltitools_user_field_'.$i.'"';
6699: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
6700: if ($checked) {
6701: $userfieldstyle = 'display:inline-block';
6702: if ($userincdom) {
6703: $seluserdom = $unseluserdom;
6704: $unseluserdom = '';
6705: }
6706: }
6707: } else {
6708: $spacer = (' ' x2);
6709: }
6710: $datatable .= '<label>'.
6711: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
6712: $lt{$field}.'</label>'.$spacer;
6713: }
6714: $datatable .= '</span>';
6715: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
6716: '<span class="LC_nobreak"> : '.
6717: '<select name="ltitools_userincdom_'.$i.'">'.
6718: '<option value="">'.&mt('Select').'</option>'.
6719: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
6720: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
6721: '</select></span></div>';
6722: $datatable .= '</fieldset>'.
6723: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6724: foreach my $role (@courseroles) {
6725: my ($selected,$selectnone);
6726: if (!$rolemaps{$role}) {
6727: $selectnone = ' selected="selected"';
6728: }
6729: $datatable .= '<td style="text-align: center">'.
6730: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6731: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
6732: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6733: foreach my $ltirole (@ltiroles) {
6734: unless ($selectnone) {
6735: if ($rolemaps{$role} eq $ltirole) {
6736: $selected = ' selected="selected"';
6737: } else {
6738: $selected = '';
6739: }
6740: }
6741: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6742: }
6743: $datatable .= '</select></td>';
6744: }
6745: $datatable .= '</tr></table></fieldset>';
6746: my %courseconfig;
6747: if (ref($settings->{$item}) eq 'HASH') {
6748: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
6749: %courseconfig = %{$settings->{$item}->{'crsconf'}};
6750: }
6751: }
1.129 raeburn 6752: $datatable .= '<fieldset><legend>';
6753: if ($context eq 'domain') {
6754: $datatable .= &mt('Configurable in course');
6755: } else {
6756: $datatable .= &mt('Configurable for each instance of tool in course');
6757: }
6758: $datatable .= '</legend><span class="LC_nobreak">';
1.118 raeburn 6759: foreach my $item ('label','title','target','linktext','explanation','append') {
6760: my $checked;
6761: if ($courseconfig{$item}) {
6762: $checked = ' checked="checked"';
6763: }
6764: $datatable .= '<label>'.
6765: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
6766: $lt{'crs'.$item}.'</label> '."\n";
6767: }
6768: $datatable .= '</span></fieldset>'.
6769: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6770: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
6771: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
6772: my %custom = %{$settings->{$item}->{'custom'}};
6773: if (keys(%custom) > 0) {
6774: foreach my $key (sort(keys(%custom))) {
6775: $datatable .= '<tr><td><span class="LC_nobreak">'.
6776: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
6777: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6778: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
6779: ' value="'.$custom{$key}.'" /></td></tr>';
6780: }
6781: }
6782: }
6783: $datatable .= '<tr><td><span class="LC_nobreak">'.
6784: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
6785: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
6786: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
6787: $datatable .= '</table></fieldset></td></tr>'."\n";
6788: $itemcount ++;
6789: }
6790: }
6791: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6792: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
6793: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6794: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
6795: '<select name="ltitools_add_pos"'.$chgstr.'>';
6796: for (my $k=0; $k<$maxnum+1; $k++) {
6797: my $vpos = $k+1;
6798: my $selstr;
6799: if ($k == $maxnum) {
6800: $selstr = ' selected="selected" ';
6801: }
6802: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6803: }
6804: $datatable .= '</select> '."\n".
6805: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6806: '<td colspan="2">'.
6807: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6808: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
6809: (' 'x2).
6810: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
6811: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6812: (' 'x2).
6813: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
6814: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
6815: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
6816: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
6817: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
6818: '<br />'.
1.120 raeburn 6819: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="60" name="ltitools_add_url" value="" /></span> '."\n".
1.118 raeburn 6820: (' 'x2).
6821: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span><br />';
6822: if ($switchserver) {
6823: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6824: } else {
6825: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
6826: (' 'x2).
1.119 raeburn 6827: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
6828: '<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 6829: }
6830: $datatable .= '<br /><br />'.
6831: '</fieldset>'.
6832: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
6833: '<span class="LC_nobreak">'.&mt('Display target:');
6834: my %defaultdisp;
6835: $defaultdisp{'iframe'} = ' checked="checked"';
6836: foreach my $disp ('iframe','tab','window') {
6837: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
6838: $lt{$disp}.'</label>'.(' 'x2);
6839: }
6840: $datatable .= (' 'x4);
6841: foreach my $dimen ('width','height') {
6842: $datatable .= '<label>'.$lt{$dimen}.' '.
6843: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
6844: (' 'x2);
6845: }
6846: $datatable .= '</span><br />'.
6847: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
6848: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
6849: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
6850: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
6851: '</div><div style=""></div><br />';
6852: my %units = (
6853: 'passback' => 'days',
6854: 'roster' => 'seconds',
6855: );
6856: my %defaulttimes = (
6857: 'passback' => '7',
6858: 'roster' => '300',
6859: );
6860: foreach my $extra ('passback','roster') {
6861: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
6862: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
6863: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
6864: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
6865: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
6866: &mt('Yes').'</label></span></div>'.
6867: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
6868: '<span class="LC_nobreak">'.
6869: &mt("until at least [_1] $units{$extra} after launch",
6870: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
6871: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6872: }
6873: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
6874: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
6875: if ($switchserver) {
6876: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6877: } else {
6878: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
6879: }
6880: $datatable .= '</span></fieldset>'.
6881: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
6882: '<span class="LC_nobreak">';
6883: foreach my $field (@fields) {
6884: my ($id,$onclick,$spacer);
6885: if ($field eq 'user') {
6886: $id = ' id="ltitools_user_field_add"';
6887: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
6888: } else {
6889: $spacer = (' ' x2);
6890: }
6891: $datatable .= '<label>'.
6892: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
6893: $lt{$field}.'</label>'.$spacer;
6894: }
6895: $datatable .= '</span>'.
6896: '<div style="display:none;" id="ltitools_user_div_add">'.
6897: '<span class="LC_nobreak"> : '.
6898: '<select name="ltitools_add_userincdom">'.
6899: '<option value="" selected="selected">'.&mt('Select').'</option>'.
6900: '<option value="0">'.&mt('username').'</option>'.
6901: '<option value="1">'.&mt('username:domain').'</option>'.
6902: '</select></span></div></fieldset>';
6903: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
6904: foreach my $role (@courseroles) {
6905: my ($checked,$checkednone);
6906: $datatable .= '<td style="text-align: center">'.
6907: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6908: '<select name="ltitools_add_roles_'.$role.'">'.
6909: '<option value="" selected="selected">'.&mt('Select').'</option>';
6910: foreach my $ltirole (@ltiroles) {
6911: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
6912: }
6913: $datatable .= '</select></td>';
6914: }
6915: $datatable .= '</tr></table></fieldset>'.
1.129 raeburn 6916: '<fieldset><legend>';
6917: if ($context eq 'domain') {
6918: $datatable .= &mt('Configurable in course');
6919: } else {
6920: $datatable .= &mt('Configurable for each instance of tool in course');
6921: }
6922: $datatable .= '</legend><span class="LC_nobreak">';
1.118 raeburn 6923: foreach my $item ('label','title','target','linktext','explanation','append') {
6924: $datatable .= '<label>'.
6925: '<input type="checkbox" name="ltitools_add_courseconfig" value="'.$item.'" checked="checked" />'.
6926: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
6927: }
6928: $datatable .= '</span></fieldset>'.
6929: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
6930: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6931: '<tr><td><span class="LC_nobreak">'.
6932: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
6933: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
6934: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
6935: '</table></fieldset>'."\n".
6936: '</td>'."\n".
6937: '</tr>'."\n";
6938: $itemcount ++;
6939: return $datatable;
6940: }
6941:
6942: sub ltitools_names {
6943: my %lt = &Apache::lonlocal::texthash(
6944: 'title' => 'Title',
6945: 'version' => 'Version',
6946: 'msgtype' => 'Message Type',
6947: 'sigmethod' => 'Signature Method',
6948: 'url' => 'URL',
6949: 'key' => 'Key',
6950: 'lifetime' => 'Nonce lifetime (s)',
6951: 'secret' => 'Secret',
6952: 'icon' => 'Icon',
6953: 'user' => 'User',
6954: 'fullname' => 'Full Name',
6955: 'firstname' => 'First Name',
6956: 'lastname' => 'Last Name',
6957: 'email' => 'E-mail',
6958: 'roles' => 'Role',
6959: 'window' => 'Window',
6960: 'tab' => 'Tab',
6961: 'iframe' => 'iFrame',
6962: 'height' => 'Height',
6963: 'width' => 'Width',
6964: 'linktext' => 'Default Link Text',
6965: 'explanation' => 'Default Explanation',
6966: 'passback' => 'Tool can return grades:',
6967: 'roster' => 'Tool can retrieve roster:',
6968: 'crstarget' => 'Display target',
6969: 'crslabel' => 'Course label',
6970: 'crstitle' => 'Course title',
6971: 'crslinktext' => 'Link Text',
6972: 'crsexplanation' => 'Explanation',
6973: 'crsappend' => 'Provider URL',
6974: );
6975: return %lt;
6976: }
6977:
1.87 raeburn 6978: sub print_lti {
6979: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
6980: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
6981: return;
6982: }
6983: my @menuitems = ('fullname','coursetitle','role','logout','grades');
6984: my %menutitles = <imenu_titles();
6985: my ($domdefs,$displaydefs);
6986: if ($env{'request.lti.login'}) {
6987: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
6988: my @domdefsmenu;
6989: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
6990: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
6991: $domdefs = &mt('Header shown').', ';
6992: }
6993: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
6994: $domdefs .= &mt('Inline menu shown');
6995: }
6996: $domdefs =~ s/,\s$//;
6997: if (!$domdefs) {
6998: $domdefs = &mt('No header or inline menu shown');
6999: }
7000: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
7001: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
7002: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
7003: }
7004: }
7005: $displaydefs = &mt('Domain defaults');
7006: if (@domdefsmenu) {
7007: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
7008: if (@diffs) {
7009: my $missing;
7010: foreach my $item (@menuitems) {
7011: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
7012: $missing .= ' '.$menutitles{$item}.',';
7013: }
7014: }
7015: $missing =~ s/,$//;
7016: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
7017: } else {
7018: $displaydefs .= ': '.&mt('All shown');
7019: }
7020: } else {
7021: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
7022: }
7023: } else {
7024: $displaydefs = &mt('Domain defaults only available in LTI context');
7025: }
7026: my %items = (
7027: 'lti.override' => {
7028: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
7029: input => 'radio',
7030: },
7031: 'lti.topmenu' => {
7032: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
7033: input => 'radio',
7034: },
7035: 'lti.inlinemenu' => {
7036: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
7037: input => 'radio',
7038: },
7039: 'lti.lcmenu' => {
7040: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
7041: input => 'custom',
7042: },
7043: );
7044: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
7045: }
7046:
7047: sub lcmenu_checkboxes {
7048: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
7049: my @menuitems = ('fullname','coursetitle','role','logout','grades');
7050: my %menutitles = <imenu_titles();
7051: my (@current,@domdefs);
7052: if ($env{'request.lti.login'}) {
7053: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
7054: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
7055: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
7056: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
7057: }
7058: }
7059: }
7060: if (ref($settings) eq 'HASH') {
7061: if ($settings->{'lti.lcmenu'}) {
7062: unless ($settings->{'lti.lcmenu'} eq 'none') {
7063: @current = split(',',$settings->{'lti.lcmenu'});
7064: }
7065: } else {
7066: @current = @domdefs;
7067: }
7068: } else {
7069: @current = @domdefs;
7070: }
7071: my $numinrow = 3;
7072: my $count = 0;
7073: my $disabled;
7074: if ($noedit) {
7075: $disabled = ' disabled="disabled"';
7076: }
7077: my $output = '<table>';
7078: foreach my $item (@menuitems) {
7079: my $checked = '';
7080: if (grep(/^\Q$item\E$/,@current)) {
7081: $checked = ' checked="checked" ';
7082: }
7083: my $rem = $count%($numinrow);
7084: if ($rem == 0) {
7085: if ($count > 0) {
7086: $output .= '</tr>';
7087: }
7088: $output .= '<tr>';
7089: }
7090: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
7091: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
7092: $menutitles{$item}.'</label></span></td>';
7093: $count ++;
7094: }
7095: my $rem = $count%($numinrow);
7096: my $colsleft = $numinrow - $rem;
7097: if ($colsleft > 1 ) {
7098: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7099: ' </td>';
7100: } elsif ($colsleft == 1) {
7101: $output .= '<td class="LC_left_item"> </td>';
7102: }
7103: $output .= '</tr></table>';
7104: }
7105:
7106: sub ltimenu_titles {
7107: return &Apache::lonlocal::texthash(
7108: fullname => 'Full name',
7109: coursetitle => 'Course title',
7110: role => 'Role',
7111: logout => 'Logout',
7112: grades => 'Grades',
7113: );
7114: }
7115:
1.91 raeburn 7116: sub print_menuitems {
7117: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
7118: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
7119: return;
7120: }
7121: if ($position eq 'top') {
7122: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
7123: if ($settings->{'menucollections'} ne '') {
7124: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7125: my ($num,$value) = split(/\%/,$item);
7126: if ($num =~ /^\d+$/) {
7127: $defaultmenu_options{$num} = $num;
7128: }
7129: }
7130: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
7131: $addcollection = $defaultmenu_order[-1] + 1;
7132: } else {
7133: $addcollection = 1;
7134: }
7135: $defaultmenu_options{$addcollection} = $addcollection;
7136: my %items = (
7137: 'menudefault' => {
7138: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
7139: &mt("(can be overriden in deep-link context)"),
7140: input => 'selectbox',
7141: options => \%defaultmenu_options,
7142: order => \@defaultmenu_order,
7143: nullval => &mt('Standard (all menus shown)'),
7144: },
7145: );
7146: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
7147: } else {
7148: my %menu;
7149: my $count = 0;
7150: my $next = 1;
7151: my ($datatable,$disabled);
7152: if ($noedit) {
7153: $disabled = ' disabled="disabled"';
7154: }
7155:
7156: my ($ordered,$cats) = &menuitems_categories();
7157: my @order = @{$ordered};
7158: my %categories = %{$cats};
7159: my %menutitles = &menuitems_titles();
7160: my %menufields = &menuitems_fields();
7161:
7162: if ($settings->{'menucollections'} ne '') {
7163: foreach my $item (split(/;/,$settings->{'menucollections'})) {
7164: my ($num,$value) = split(/\%/,$item);
7165: if ($num =~ /^\d+$/) {
7166: my @entries = split(/\&/,$value);
7167: foreach my $entry (@entries) {
7168: my ($name,$fields) = split(/=/,$entry);
7169: $menu{$num}{$name} = $fields;
7170: }
7171: }
7172: }
7173: if (keys(%menu)) {
7174: my @current = sort { $a <=> $b } keys(%menu);
7175: $next += $current[-1];
7176: foreach my $num (@current) {
7177: my %checked;
7178: my $on = ' checked="checked"';
7179: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7180: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7181: if ($menu{$num}{$key} eq 'y') {
7182: $checked{$key} = $on;
7183: }
7184: } else {
7185: foreach my $field (split(/,/,$menu{$num}{$key})) {
7186: if (exists($menufields{$field})) {
7187: $checked{$field} = $on;
7188: }
7189: }
7190: }
7191: }
7192: if (ref($menu{$num}) eq 'HASH') {
7193: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
7194: foreach my $category (@order) {
7195: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7196: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7197: if ($category eq 'text') {
7198: $datatable .= '<i>'.&mt('Header').'</i><br />';
7199: }
1.91 raeburn 7200: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7201: if ($field eq 'disc') {
7202: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
7203: }
1.91 raeburn 7204: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
7205: $menufields{$field}.'</label><br />';
7206: }
7207: $datatable .= '</fieldset>';
7208: }
7209: }
7210: $datatable .= &item_table_row_end();
7211: $count ++;
7212: }
7213: }
7214: }
7215: } elsif ($noedit) {
7216: my $text = &mt('No menu collections defined for this course.');
7217: $datatable .= &item_table_row_start($text,$count);
7218: }
7219: unless ($noedit) {
7220: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
7221: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
7222: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
7223: foreach my $category (@order) {
7224: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7225: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
7226: foreach my $field (@{$categories{$category}}) {
7227: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
7228: $menufields{$field}.'</label><br />';
7229: }
7230: $datatable .= '</fieldset>';
7231: }
7232: }
7233: $datatable .= &item_table_row_end();
7234: $count ++;
7235: }
7236: return $datatable;
7237: }
7238: }
7239:
7240: sub menuitems_abbreviations {
7241: my %briefcats = (
7242: text => 'pt',
7243: links => 'p',
7244: list => 'ps',
7245: inline => 's',
7246: );
7247: return %briefcats;
7248: }
7249:
7250: sub menuitems_categories {
7251: my @order = ('shown','text','links','list','inline');
7252: my %categories = (
1.94 raeburn 7253: shown => ['top','inline','foot','main'],
7254: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 7255: links => ['pers','logo','menu','comm','roles','help','logout'],
1.128 raeburn 7256: list => ['about','prefs','port','wish','anno','rss','srch','brse'],
1.91 raeburn 7257: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
7258: );
7259: return (\@order,\%categories);
7260: }
7261:
7262: sub menuitems_titles {
7263: return &Apache::lonlocal::texthash (
7264: shown => 'Hierarchy',
1.94 raeburn 7265: text => 'Text',
1.91 raeburn 7266: links => 'Header links',
7267: list => 'Drop-down list',
7268: inline => 'Inline links',
7269: );
7270: }
7271:
7272: sub menuitems_fields {
7273: return &Apache::lonlocal::texthash (
7274: top => 'Display header',
7275: inline => 'Display inline menu',
1.94 raeburn 7276: foot => 'Display footer',
1.91 raeburn 7277: main => 'Access to main menu',
1.92 raeburn 7278: pers => 'Personal',
7279: logo => 'LON-CAPA',
1.91 raeburn 7280: menu => 'Home',
7281: comm => 'Messages',
7282: roles => 'Roles/Courses',
7283: help => 'Help',
7284: logout => 'Logout',
7285: name => 'Fullname',
7286: crs => 'Course Title',
7287: role => 'Current Role',
1.94 raeburn 7288: disc => 'Discussion',
7289: fdbk => 'Feedback',
1.91 raeburn 7290: about => 'Information',
7291: prefs => 'Preferences',
7292: port => 'Portfolio',
7293: wish => 'Stored Links',
7294: anno => 'Calendar',
7295: rss => 'RSS Feeds',
1.128 raeburn 7296: srch => 'Search Library',
7297: brse => 'Browse Library',
1.91 raeburn 7298: cont => 'Contents',
7299: grades => 'Grades',
7300: chat => 'Chat',
7301: people => 'People',
7302: groups => 'Groups',
7303: resv => 'Reservations',
7304: syll => 'Syllabus',
7305: feeds => 'Feeds',
7306: );
7307: }
7308:
7309: sub menucollections_display {
7310: my ($collections) = @_;
7311: my %menu;
7312: my ($ordered,$cats) = &menuitems_categories();
7313: my @order = @{$ordered};
7314: my %categories = %{$cats};
7315: my %menutitles = &menuitems_titles();
7316: my %menufields = &menuitems_fields();
7317: foreach my $item (split(/;/,$collections)) {
7318: my ($num,$value) = split(/\%/,$item);
7319: if ($num =~ /^\d+$/) {
7320: my @entries = split(/\&/,$value);
7321: foreach my $entry (@entries) {
7322: my ($name,$fields) = split(/=/,$entry);
7323: $menu{$num}{$name} = $fields;
7324: }
7325: }
7326: }
7327: my $output = '';
7328: if (keys(%menu)) {
7329: my @current = sort { $a <=> $b } keys(%menu);
7330: foreach my $num (@current) {
7331: my %checked;
7332: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 7333: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 7334: if ($menu{$num}{$key} eq 'y') {
7335: $checked{$key} = 1;
7336: }
7337: } else {
7338: foreach my $field (split(/,/,$menu{$num}{$key})) {
7339: if (exists($menufields{$field})) {
7340: $checked{$field} = 1;
7341: }
7342: }
7343: }
7344: }
7345: if (ref($menu{$num}) eq 'HASH') {
7346: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
7347: foreach my $category (@order) {
7348: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
7349: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
7350: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 7351: if ($category eq 'text') {
7352: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
1.124 raeburn 7353: }
1.91 raeburn 7354: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 7355: if ($field eq 'disc') {
7356: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
7357: }
1.91 raeburn 7358: if ($checked{$field}) {
7359: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
7360: } else {
7361: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
7362: }
7363: $output .= '<br />';
7364: }
7365: $output .= '</fieldset>';
7366: }
7367: }
7368: $output .= '</fieldset>';
7369: }
7370: }
7371: }
7372: return $output;
7373: }
7374:
1.93 raeburn 7375: sub print_linkprotection {
1.102 raeburn 7376: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 7377:
7378: my %linkprotection;
7379: my $count = 0;
7380: my $next = 1;
1.102 raeburn 7381: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 7382: if ($noedit) {
7383: $disabled = ' disabled="disabled"';
7384: }
1.100 raeburn 7385: my %desc = &linkprot_names();
7386: my %lt = &Apache::lonlocal::texthash (
7387: 'requ' => 'Required settings',
7388: 'opti' => 'Optional settings',
7389: );
1.93 raeburn 7390: my $itemcount = 0;
7391:
1.100 raeburn 7392: my $ltiauth;
1.102 raeburn 7393: if ($context eq 'domain') {
7394: $ltiauth = 1;
7395: } else {
7396: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
7397: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
7398: } else {
7399: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
7400: $ltiauth = $domdefs{'crsltiauth'};
7401: }
7402: }
7403: if ($context eq 'domain') {
7404: $dest = '/adm/domainprefs';
1.100 raeburn 7405: } else {
1.102 raeburn 7406: $dest = '/adm/courseprefs';
7407: }
1.124 raeburn 7408:
1.102 raeburn 7409: my ($switchserver,$switchmessage);
7410: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
7411: if ($switchserver) {
7412: if ($context eq 'domain') {
1.124 raeburn 7413: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.102 raeburn 7414: } elsif ($crstype eq 'Community') {
7415: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
7416: } else {
7417: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
7418: }
1.100 raeburn 7419: }
1.99 raeburn 7420:
1.105 raeburn 7421: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 7422: if (keys(%{$settings->{'linkprot'}})) {
7423: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 7424: $next += $current[-1];
7425: for (my $i=0; $i<@current; $i++) {
7426: my $num = $current[$i];
7427: my %values;
1.102 raeburn 7428: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
7429: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 7430: } else {
7431: next;
7432: }
7433: my $selected;
7434: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
7435: $selected = ' selected="selected"';
7436: }
7437: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7438: $datatable .=
7439: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
7440: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 7441: &mt('Delete?').'</label></span></td><td>';
1.122 raeburn 7442: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7443: $onclickpassback,%checkedpassback,$passbacksty,%checkedpassbackfmt);
7444: $passbacksty = 'none';
7445: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','$i'".');"';
7446: %checkedpassback = (
7447: 'no' => ' checked="checked"',
7448: 'yes' => '',
1.124 raeburn 7449: );
1.122 raeburn 7450: %checkedpassbackfmt = (
7451: '1p1' => ' checked="checked"',
7452: '1p0' => '',
7453: );
7454: if ($values{'passback'} ne '') {
7455: $passbacksty = 'inline-block';
7456: $checkedpassback{'yes'} = ' checked="checked"';
7457: $checkedpassback{'no'} = '';
7458: if ($values{'passbackformat'} eq '1.0') {
7459: $checkedpassbackfmt{'1p0'} = ' checked="checked"';
7460: $checkedpassbackfmt{'1p1'} = '';
7461: }
7462: }
1.100 raeburn 7463: if ($ltiauth) {
7464: $usersty = 'display:none';
1.112 raeburn 7465: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 7466: %checkedrequser = (
7467: no => ' checked="checked"',
7468: yes => '',
7469: );
7470: if ($values{'requser'}) {
7471: $checkedrequser{'yes'} = $checkedrequser{'no'};
7472: $checkedrequser{'no'} = '';
7473: }
7474: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
1.124 raeburn 7475: if ($values{'requser'}) {
1.100 raeburn 7476: $usersty = 'display:inline-block';
7477: }
7478: }
1.112 raeburn 7479: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
7480: %checkedreturnurl = (
7481: no => ' checked="checked"',
7482: yes => '',
7483: );
7484: if ($values{'returnurl'} ne '') {
7485: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
7486: $checkedreturnurl{'no'} = '';
7487: }
1.100 raeburn 7488: $datatable .=
7489: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7490: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 7491: (' 'x2).
1.100 raeburn 7492: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 7493: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
7494: (' 'x2).
1.100 raeburn 7495: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 7496: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 7497: if ($values{'key'} ne '') {
1.100 raeburn 7498: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 7499: if ($noedit) {
7500: $datatable .= ': ['.&mt('not shown').']';
7501: } elsif ($switchserver) {
7502: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
7503: } else {
7504: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
7505: }
7506: $datatable .= '</span> '.(' 'x2);
7507: } elsif (!$switchserver) {
1.100 raeburn 7508: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 7509: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
7510: '</span> '.(' 'x2);
7511: }
7512: if ($switchserver) {
7513: if ($values{'usable'} ne '') {
7514: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7515: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7516: '<span class="LC_nobreak">'.&mt('Change secret?').
1.118 raeburn 7517: '<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 7518: (' 'x2).
1.118 raeburn 7519: '<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 7520: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 7521: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 7522: '</div>';
7523: } elsif ($values{'key'} eq '') {
1.102 raeburn 7524: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7525: } else {
1.102 raeburn 7526: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7527: }
1.111 raeburn 7528: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 7529: } else {
7530: if ($values{'usable'} ne '') {
7531: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 7532: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 7533: '<span class="LC_nobreak">'.&mt('Change?').
1.118 raeburn 7534: '<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 7535: (' 'x2).
1.118 raeburn 7536: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','linkprot'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 7537: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
7538: '<span class="LC_nobreak">'.&mt('New Secret').':'.
1.116 raeburn 7539: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7540: '<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 7541: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
7542: } else {
7543: $datatable .=
1.100 raeburn 7544: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.116 raeburn 7545: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7546: '<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 7547: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
7548: }
7549: }
1.112 raeburn 7550: $datatable .= '<br /><br />'.
1.122 raeburn 7551: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7552: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="0"'.
7553: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7554: '<label><input type="radio" name="linkprot_passback_'.$i.'" value="1"'.
7555: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span><br />'.
7556: '<div id="linkprot_passbackparam_'.$i.'" class="LC_floatleft" style="display:'.$passbacksty.'" />'.
7557: '<span class="LC_nobreak">'.&mt('Grade format').
7558: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.1"'.$checkedpassbackfmt{'1p1'}.' />'.
7559: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7560: '<label><input type="radio" name="linkprot_passbackformat_'.$i.'" value="1.0"'.$checkedpassbackfmt{'1p0'}.'/>'.
7561: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7562: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7563: '<br />'.
1.112 raeburn 7564: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7565: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
7566: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7567: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
7568: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.130 raeburn 7569: ' <div id="linkprot_divurlparam_'.$i.'" style="display:none">'.
1.112 raeburn 7570: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7571: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
7572: '</span></div> ';
1.100 raeburn 7573: if ($ltiauth) {
1.112 raeburn 7574: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7575: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
7576: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7577: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
7578: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 7579: '</fieldset>'.
7580: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7581: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
7582: '</fieldset>';
7583: }
1.99 raeburn 7584: $datatable .= '</td></tr>';
1.93 raeburn 7585: $itemcount ++;
7586: }
7587: }
7588: }
7589: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7590: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
7591: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 7592: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 7593: '<td width="100%">';
1.122 raeburn 7594: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl,
7595: $onclickpassback,%checkedpassback,%checkedpassbackfmt);
1.100 raeburn 7596: if ($ltiauth) {
7597: $usersty = 'display:none';
1.112 raeburn 7598: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 7599: %checkedrequser = (
7600: no => ' checked="checked"',
7601: yes => '',
7602: );
7603: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
7604: }
1.122 raeburn 7605: $onclickpassback = ' onclick="toggleLinkProtExtra(this.form,'."'passback','passbackparam','1','inline-block','add'".');"';
7606: %checkedpassback = (
7607: 'no' => ' checked="checked"',
7608: 'yes' => '',
7609: );
7610: %checkedpassbackfmt = (
7611: '1p1' => ' checked="checked"',
7612: '1p0' => '',
7613: );
1.112 raeburn 7614: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
7615: %checkedreturnurl = (
7616: no => ' checked="checked"',
7617: yes => '',
7618: );
1.100 raeburn 7619: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 7620: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 7621: (' 'x2).
1.100 raeburn 7622: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 7623: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
7624: (' 'x2).
1.112 raeburn 7625: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
7626: '<br /><br />';
1.99 raeburn 7627: if ($switchserver) {
1.102 raeburn 7628: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 7629: } else {
1.100 raeburn 7630: $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 7631: (' 'x2).
1.116 raeburn 7632: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="new-password"'.$disabled.' />'.
1.106 raeburn 7633: '<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 7634: }
1.112 raeburn 7635: $datatable .= '<br /><br />'.
1.122 raeburn 7636: '<span class="LC_nobreak">'.$desc{'passback'}.'?'.
7637: '<label><input type="radio" name="linkprot_passback_add" value="0"'.
7638: $onclickpassback.$checkedpassback{'no'}.$disabled.' />'.&mt('No').'</label> '.
7639: '<label><input type="radio" name="linkprot_passback_add" value="1"'.
7640: $onclickpassback.$checkedpassback{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.130 raeburn 7641: '<br /><div id="linkprot_passbackparam_add" class="LC_floatleft" style="display:none">'.
1.122 raeburn 7642: '<span class="LC_nobreak">'.&mt('Grade format').
7643: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.1"'.$checkedpassbackfmt{'1p1'}.$disabled.' />'.
7644: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
7645: '<label><input type="radio" name="linkprot_passbackformat_add" value="1.0"'.$checkedpassbackfmt{'1p0'}.$disabled.' />'.
7646: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
7647: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
7648: '<br />'.
1.112 raeburn 7649: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
7650: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
7651: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
7652: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
7653: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.130 raeburn 7654: ' <div id="linkprot_divurlparam_add" style="display:none">'.
1.112 raeburn 7655: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
7656: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
7657: '</span></div> ';
7658: if ($ltiauth) {
7659: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
7660: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
7661: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
7662: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 7663: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
7664: '</fieldset>'.
1.100 raeburn 7665: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
7666: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
7667: '</fieldset>';
7668: }
1.99 raeburn 7669: $datatable .= '</td></tr>';
1.93 raeburn 7670: $$rowtotal ++;
1.101 raeburn 7671: return $datatable;
1.93 raeburn 7672: }
7673:
7674: sub linkprot_names {
1.100 raeburn 7675: return &Apache::lonlocal::texthash(
1.93 raeburn 7676: 'version' => 'LTI Version',
7677: 'key' => 'Key',
7678: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 7679: 'name' => 'Launcher Application',
1.93 raeburn 7680: 'secret' => 'Secret',
1.122 raeburn 7681: 'passback' => 'Can return grades to Launcher',
1.112 raeburn 7682: 'returnurl' => 'Launcher return URL',
1.100 raeburn 7683: 'requser' => 'Use identity',
7684: 'email' => 'Email address',
7685: 'sourcedid' => 'User ID',
7686: 'other' => 'Other',
7687: 'auth' => 'Display LON-CAPA login page',
7688: 'reject' => 'Discontinue launch process',
1.93 raeburn 7689: );
7690: }
7691:
1.99 raeburn 7692: sub check_switchserver {
1.102 raeburn 7693: my ($cdom,$cnum,$context,$dest) = @_;
7694: my ($allowed,$switchserver,$home);
7695: if ($context eq 'domain') {
7696: $home = &Apache::lonnet::domain($cdom,'primary');
7697: } else {
7698: $home = &Apache::lonnet::homeserver($cnum,$cdom);
7699: }
7700: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 7701: my @ids=&Apache::lonnet::current_machine_ids();
7702: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7703: if (!$allowed) {
7704: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
7705: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 7706: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 7707: }
7708: }
7709: return $switchserver;
7710: }
7711:
1.100 raeburn 7712: sub linkprot_options {
7713: my ($num,$itemcount,$disabled,$current,$desc) = @_;
7714: my %lt;
7715: if (ref($desc) eq 'HASH') {
7716: %lt = %{$desc};
7717: }
7718: my $userfieldsty = 'none';
7719: my (%checked,$userfield);
7720: $checked{'sourcedid'} = ' checked="checked"';
7721: $checked{'reject'} = ' checked="checked"';
7722: if (ref($current) eq 'HASH') {
7723: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
7724: $checked{'sourcedid'} = '';
7725: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
7726: $checked{'email'} = ' checked="checked"';
7727: } else {
7728: $checked{'other'} = ' checked="checked"';
7729: $userfield = $current->{'mapuser'};
7730: $userfieldsty = 'inline-block';
7731: }
7732: }
7733: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
7734: $checked{'reject'} = '';
7735: $checked{'auth'} = ' checked="checked"';
7736: }
7737: }
1.112 raeburn 7738: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 7739: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
7740: &mt('Source of LON-CAPA username in LTI request').': ';
7741: foreach my $option ('sourcedid','email','other') {
7742: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
7743: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
7744: ($option eq 'other' ? '' : (' 'x2) );
7745: }
7746: $output .= '</span></div>'.
7747: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
7748: '<input type="text" name="linkprot_customuser_'.$num.'" '.
7749: 'value="'.$userfield.'"'.$disabled.' /></div>';
7750: $output .= '<br />'.
7751: '<div class="LC_floatleft"><span class="LC_nobreak">'.
7752: &mt('Action when username is not for an enrolled student').': ';
7753: foreach my $option ('reject','auth') {
7754: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
7755: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
7756: ($option eq 'auth' ? '' : (' 'x2) );
7757: }
7758: $output .= '</span></div>';
7759: return $output;
7760: }
7761:
1.114 raeburn 7762: sub print_extresource_row {
7763: my ($item,$config,$curr,$noedit) = @_;
7764: my $onchange;
7765: unless ($noedit) {
7766: $onchange = ' onchange="javascript:toggleExtRes();"';
7767: }
7768: my $id = 'LC_'.$item;
7769: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
7770: my $output = &select_from_options($item,$config->{'order'},
7771: $config->{'options'},$selected,
7772: $config->{'nullval'},
7773: undef,undef,$onchange,$noedit,$id);
1.124 raeburn 7774: my ($checked,$reusesty,$sizesty);
1.114 raeburn 7775: if ($reuse) {
7776: $checked = ' checked="checked"';
7777: }
7778: $reusesty = 'none';
7779: $sizesty = 'none';
7780: if (($selected eq 'window') || ($selected eq 'tab')) {
7781: $reusesty = 'inline-block';
7782: if ($selected eq 'window') {
7783: $sizesty = 'inline-block';
7784: }
7785: }
7786: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
7787: '<span class="LC_nobreak">'.
7788: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
7789: &mt('Re-use tab/window').'</label>'.
7790: '</span></div>'.
7791: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
7792: '<legend>'.&mt('Window size (optional)').'</legend>'.
7793: '<span class="LC_nobreak">'.
7794: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
7795: (' ' x 3).
7796: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
7797: '</span></fieldset>';
7798: return $output;
7799: }
7800:
1.1 raeburn 7801: sub print_other {
1.80 raeburn 7802: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 7803: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7804: return;
7805: }
1.3 raeburn 7806: my @ordered = &get_other_items($cdom,$settings,$allitems);
7807: my %items;
7808: foreach my $parameter (@ordered) {
7809: $items{$parameter} = {
7810: text => '<b>'.$parameter.'</b>',
7811: input => 'textbox',
7812: size => '15',
7813: },
7814: }
7815: push (@ordered,'newp_value');
7816: $items{'newp_value'} = {
7817: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
7818: '<input type="textbox" name="newp_name"'.
7819: ' value="" size="30" />',
7820: input => 'textbox',
7821: size => '30',
7822: };
1.93 raeburn 7823: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 7824: }
7825:
7826: sub get_other_items {
7827: my ($cdom,$settings,$allitems) = @_;
7828: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
7829: return;
7830: }
1.1 raeburn 7831: my @ordered;
7832: if (ref($settings) eq 'HASH') {
7833: foreach my $parameter (sort(keys(%{$settings}))) {
7834: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 7835: next if (($parameter eq 'course.helper.not.run') &&
7836: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 7837: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
7838: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
7839: || ($parameter eq 'type') ||
1.50 raeburn 7840: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 7841: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 7842: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
7843: ($parameter eq 'clonedfrom')) {
1.1 raeburn 7844: push(@ordered,$parameter);
7845: }
7846: }
7847: }
1.3 raeburn 7848: return @ordered;
1.1 raeburn 7849: }
7850:
7851: sub item_table_row_start {
1.91 raeburn 7852: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 7853: my $output;
1.56 raeburn 7854: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
7855: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 7856: if ($leftclass eq '') {
7857: $leftclass = 'LC_left_item';
7858: }
7859: if ($rightclass eq '') {
7860: $rightclass = 'LC_right_item';
7861: }
1.56 raeburn 7862: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 7863: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 7864: '</td>';
1.91 raeburn 7865: if ($colspan > 1) {
7866: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 7867: } else {
1.91 raeburn 7868: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 7869: }
1.1 raeburn 7870: return $output;
7871: }
7872:
7873: sub item_table_row_end {
7874: return '</td></tr>';
7875: }
7876:
7877: sub yesno_radio {
1.127 raeburn 7878: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit,$onclick,$reverse) = @_;
1.1 raeburn 7879: my $itemon = ' ';
7880: my $itemoff = ' checked="checked" ';
1.69 raeburn 7881: if (($valueyes eq '') && ($valueno eq '')) {
7882: $valueyes = 'yes';
7883: $valueno = '';
7884: }
1.1 raeburn 7885: if (ref($settings) eq 'HASH') {
1.69 raeburn 7886: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 7887: $itemon = $itemoff;
7888: $itemoff = ' ';
7889: }
1.69 raeburn 7890: unless (exists($settings->{$item})) {
7891: if ($unsetdefault eq $valueyes) {
7892: $itemon = $itemoff;
7893: $itemoff = ' ';
7894: }
7895: }
1.1 raeburn 7896: }
1.80 raeburn 7897: my $disabled;
7898: if ($noedit) {
7899: $disabled = ' disabled="disabled"';
1.127 raeburn 7900: } elsif ($onclick) {
7901: $onclick = ' onclick="'.$onclick.'"';
7902: }
7903: if ($reverse) {
7904: return '<span class="LC_nobreak"><label>'.
7905: '<input type="radio" name="'.$item.'"'.
7906: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label> '.
7907: '<label><input type="radio" name="'.$item.'"'.
7908: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label></span>';
7909: } else {
7910: return '<span class="LC_nobreak"><label>'.
7911: '<input type="radio" name="'.$item.'"'.
7912: $itemon.' value="'.$valueyes.'"'.$disabled.$onclick.' />'.&mt('Yes').'</label> '.
7913: '<label><input type="radio" name="'.$item.'"'.
7914: $itemoff.' value="'.$valueno.'"'.$disabled.$onclick.' />'.&mt('No').'</label></span>';
1.80 raeburn 7915: }
1.1 raeburn 7916: }
7917:
7918: sub select_from_options {
1.91 raeburn 7919: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 7920: my $output;
1.80 raeburn 7921: my $disabled;
7922: if ($noedit) {
7923: $disabled = ' disabled=disabled"';
7924: }
1.1 raeburn 7925: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
7926: $output='<select name="'.$item.'" '.$onchange;
7927: if ($multiple) {
7928: $output .= ' multiple="multiple"';
7929: my $num = @{$order};
7930: $num ++ if ($nullval ne '');
7931: if (($maxsize) && ($maxsize < $num)) {
7932: $output .= ' size="'.$maxsize.'"';
7933: }
7934: }
1.91 raeburn 7935: if ($id ne '') {
7936: $output .= ' id="'.$id.'"';
7937: }
1.80 raeburn 7938: $output .= $disabled.'>'."\n";
1.1 raeburn 7939: if ($nullval ne '') {
7940: $output .= '<option value=""';
7941: if (ref($curr) eq 'ARRAY') {
7942: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
7943: $output .= ' selected="selected" ';
7944: }
7945: } else {
7946: if ($curr eq '') {
7947: $output .= ' selected="selected" ';
7948: }
7949: }
7950: $output .= '>'.$nullval.'</option>';
7951: }
7952: foreach my $option (@{$order}) {
7953: $output.= '<option value="'.$option.'"';
7954: if (ref($curr) eq 'ARRAY') {
7955: if (grep(/^\Q$option\E$/,@{$curr})) {
7956: $output .= ' selected="selected" ';
7957: }
7958: } else {
7959: if ($option eq $curr) {
7960: $output.=' selected="selected"';
7961: }
7962: }
7963: $output.=">$options->{$option}</option>\n";
7964: }
7965: $output.="</select>";
7966: }
7967: return $output;
7968: }
7969:
7970: sub make_item_rows {
1.127 raeburn 7971: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit,$cnum) = @_;
1.1 raeburn 7972: my $datatable;
7973: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
7974: my $count = 0;
7975: foreach my $item (@{$ordered}) {
7976: $count ++;
1.56 raeburn 7977: my $colspan;
7978: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
7979: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
7980: $colspan = 2;
7981: }
1.114 raeburn 7982: my $rowdesc;
7983: if ($caller eq 'appearance') {
7984: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
7985: } else {
7986: $rowdesc = $items->{$item}{text};
7987: }
1.41 www 7988: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 7989: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 7990: } else {
1.114 raeburn 7991: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 7992: }
1.55 raeburn 7993: if ($item eq 'defaultcredits') {
7994: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
7995: my $showcredits;
7996: if ($defaultcredits ne '') {
7997: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
7998: } else {
7999: $showcredits = &mt('No default set');
8000: }
8001: $datatable .= $showcredits;
8002: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 8003: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 8004: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 8005: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 8006: } elsif ($item eq 'print_header_format') {
1.80 raeburn 8007: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 8008: } elsif ($item eq 'lti.lcmenu') {
8009: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 8010: } elsif ($item eq 'extresource') {
8011: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 8012: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 8013: my $disabled;
8014: if ($noedit) {
8015: $disabled = ' disabled="disabled"';
8016: }
1.1 raeburn 8017: $datatable .=
8018: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 8019: $settings->{$item},$disabled);
1.1 raeburn 8020: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 8021: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 8022: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 8023: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
8024: unless ($domdefs{$item} eq '0') {
8025: $unsetdefault = 1;
8026: }
8027: $valueyes = "1";
8028: $valueno = "0";
1.87 raeburn 8029: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
8030: $valueyes = '1';
1.69 raeburn 8031: }
1.80 raeburn 8032: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 8033: } elsif ($items->{$item}{input} eq 'selectbox') {
1.127 raeburn 8034: my ($id,$onchange);
1.91 raeburn 8035: if ($caller eq 'menuitems') {
8036: $id = $item;
1.127 raeburn 8037: } elsif ($caller eq 'grading') {
8038: if ($item eq 'grading') {
8039: $onchange = ' onchange="javascript:toggleGrading(this.form);"';
8040: $id = $item;
8041: }
1.91 raeburn 8042: }
1.1 raeburn 8043: my $curr = $settings->{$item};
8044: $datatable .=
8045: &select_from_options($item,$items->{$item}{'order'},
8046: $items->{$item}{'options'},$curr,
1.80 raeburn 8047: $items->{$item}{'nullval'},
1.127 raeburn 8048: undef,undef,$onchange,$noedit,$id);
8049: if ($item eq 'grading') {
8050: my ($unsetdefault,$valueyes,$valueno,$sectionbox);
8051: my $gradingsty = 'none';
8052: my $gradingsecsty = 'none';
8053: $unsetdefault = 0;
8054: my (@selsec,@sections,%current);
8055: if ($curr eq 'standard') {
8056: $gradingsty = 'inline-block';
8057: if (ref($settings) eq 'HASH') {
8058: $current{'hidetotals'} = $settings->{'hidetotals'};
8059: if ($settings->{'hidetotals'} =~ /^([\w,]+)$/) {
8060: my $secstr = $1;
8061: unless ($secstr eq 'all') {
8062: @selsec = split(/,/,$secstr);
8063: }
8064: $current{'hidetotals'} = 1;
8065: }
8066: }
8067: }
8068: $valueyes = "1";
8069: $valueno = "0";
8070: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
8071: if (keys(%sections)) {
8072: @sections = sort( { $a <=> $b } keys(%sections));
8073: }
8074: my $onclick = 'javascript:toggleHiddenTotalsSec(this.form);';
8075: my $sectionbox = '<div id="sectotalsdiv" style="display:'.$gradingsecsty.'; float:right">';
8076: my $reverse = 1;
8077: if (@sections) {
8078: $sectionbox .= ' ... '.&mt('hidden in sections').': '.
8079: '<div style="position: relative; top: 0%;">'.
8080: &select_sections('hidetotals','',\@sections,\@selsec,$noedit,'all').
8081: '</div>';
8082: }
8083: $sectionbox .= '</div>';
8084: $datatable .= '<fieldset id="hidetotalsdiv" style="display:'.$gradingsty.';">'.
8085: '<legend style="font-weight: normal;">'.
8086: &mt('Hide Course Points Totals').'</legend>'.
8087: '<div style="position: relative; top: 0%; float:left">'.
8088: &yesno_radio('hidetotals',\%current,$unsetdefault,$valueyes,$valueno,$noedit,
8089: $onclick,$reverse).'</div>'.
8090: $sectionbox.
8091: '</fieldset><div style="padding:0;clear:both;margin:0;border:0"></div>';
8092: }
1.1 raeburn 8093: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 8094: my $disabled;
8095: if ($noedit) {
8096: $disabled = ' disabled=disabled"';
8097: }
1.1 raeburn 8098: $datatable .=
8099: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 8100: $items->{$item}{size},
8101: $disabled);
1.1 raeburn 8102: }
8103: $datatable .= &item_table_row_end();
8104: }
8105: if (ref($rowtotal)) {
8106: $$rowtotal += scalar(@{$ordered});
8107: }
8108: }
8109: return $datatable;
8110: }
8111:
8112: sub nothidepriv_row {
1.80 raeburn 8113: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 8114: my ($cnum) = &get_course();
1.56 raeburn 8115: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 8116: if (ref($settings) eq 'HASH') {
8117: if ($settings->{$item} ne '') {
8118: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
8119: if ($user !~ /:/) {
8120: $nothide{join(':',split(/[\@]/,$user))}=1;
8121: } else {
8122: $nothide{$user} = 1;
8123: }
8124: }
8125: }
1.56 raeburn 8126: if ($settings->{'checkforpriv'}) {
1.124 raeburn 8127: @checkdoms = split(/,/,$settings->{'checkforpriv'});
1.56 raeburn 8128: }
1.1 raeburn 8129: }
1.56 raeburn 8130: push(@checkdoms,$cdom);
8131: my %coursepersonnel =
8132: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 8133: my @privusers;
8134: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 8135: my ($uname,$udom,$role) = split(/:/,$person);
8136: my $user = $uname.':'.$udom;
8137: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 8138: if ($end == -1 || $start == -1) {
8139: next;
8140: }
1.124 raeburn 8141: foreach my $dom (@checkdoms) {
1.56 raeburn 8142: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
8143: unless (grep(/^\Q$user\E$/,@privusers)) {
8144: push(@privusers,$user);
1.3 raeburn 8145: }
8146: }
8147: }
1.1 raeburn 8148: }
1.56 raeburn 8149: if (@privusers > 0) {
1.80 raeburn 8150: my $disabled;
8151: if ($noedit) {
8152: $disabled = ' disabled="disabled"';
8153: }
1.1 raeburn 8154: $datatable .= '<table align="right">';
8155: foreach my $user (sort(@privusers)) {
8156: my $hideon = ' checked="checked" ';
8157: my $hideoff = '';
8158: if ($nothide{$user}) {
8159: $hideoff = $hideon;
8160: $hideon = '';
8161: }
8162: my ($uname,$udom) = split(':',$user);
8163: $datatable .= '<tr><td align="left">'.
8164: &Apache::loncommon::aboutmewrapper(
8165: &Apache::loncommon::plainname($uname,$udom,'firstname'),
8166: $uname,$udom,'aboutuser').
8167: '</td><td align="left">'.
8168: '<span class="LC_nobreak"><label>'.
8169: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8170: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 8171: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 8172: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 8173: '</tr>';
8174: }
8175: $datatable .= '</table>';
8176: } else {
1.9 raeburn 8177: if ($crstype eq 'Community') {
8178: $datatable .= &mt('No Domain Coordinators have community roles');
8179: } else {
8180: $datatable .= &mt('No Domain Coordinators have course roles');
8181: }
1.1 raeburn 8182: }
8183: return $datatable;
8184: }
8185:
1.56 raeburn 8186: sub checkforpriv_row {
1.80 raeburn 8187: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 8188: my $datatable;
8189: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8190: if (keys(%domains) == 1) {
8191: $datatable = '</td><td align="right">'.
8192: &mt("Course's domain is only domain");
8193: return $datatable;
8194: }
8195: my @excdoms = ($cdom);
8196: my $num = 0;
8197: if ($settings->{$item} eq '') {
8198: $datatable = '</td><td align="right">'.
8199: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 8200: 1,1,undef,undef,\@excdoms,
8201: $noedit);
1.56 raeburn 8202: } else {
8203: my @privdoms = split(/,/,$settings->{$item});
8204: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
8205: $datatable = '</td><td align="right"><br />'.
8206: &Apache::loncommon::start_data_table();
1.80 raeburn 8207: my $disabled;
8208: if ($noedit) {
8209: $disabled = ' disabled="disabled"';
8210: }
1.56 raeburn 8211: if (@privdoms > 0) {
8212: foreach my $currdom (@privdoms) {
8213: next unless ($domains{$currdom});
8214: my $domdesc = &Apache::lonnet::domain($currdom,'description');
8215: if ($domdesc eq '') {
8216: $domdesc = $currdom;
1.124 raeburn 8217: }
1.56 raeburn 8218: $datatable .=
8219: &Apache::loncommon::start_data_table_row().
8220: '<td align="left"><span class="LC_nobreak">'.
8221: &mt('Domain:').'<b> '.$domdesc.
8222: '</b><input type="hidden" name="checkforpriv_'.$num.
8223: '" value="'.$currdom.'" /></span><br />'.
8224: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 8225: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
8226: &mt('Delete').'</label></span></td>'.
1.56 raeburn 8227: &Apache::loncommon::end_data_table_row();
8228: $num ++;
1.124 raeburn 8229: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
1.56 raeburn 8230: push(@excdoms,$currdom);
8231: }
8232: }
8233: }
8234: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
1.124 raeburn 8235: $datatable .=
1.56 raeburn 8236: &Apache::loncommon::start_data_table_row().
8237: '<td align="left"><span class="LC_nobreak">'.
8238: &mt('Additional domain:'). '</span><br />'.
8239: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 8240: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 8241: '</td>'.&Apache::loncommon::end_data_table_row();
8242: }
8243: $datatable .= &Apache::loncommon::end_data_table().
8244: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
8245: '<br />';
8246: }
8247: return $datatable;
8248: }
8249:
1.1 raeburn 8250: sub print_hdrfmt_row {
1.80 raeburn 8251: my ($item,$settings,$noedit) = @_;
1.1 raeburn 8252: my @curr;
8253: my $currnum = 0;
8254: my $maxnum = 2;
8255: my $currstr;
8256: if ($settings->{$item} ne '') {
8257: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
8258: $settings->{$item}.'</tt></span></b><br />';
8259: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 8260: foreach my $val (@current) {
8261: unless ($val eq '') {
8262: push(@curr,$val);
1.1 raeburn 8263: }
8264: }
8265: $currnum = @curr;
8266: $maxnum += $currnum;
8267: }
8268:
8269: my $output = <<ENDJS;
8270:
8271: <script type="text/javascript" language="Javascript">
8272:
8273: function reOrder(chgnum) {
8274: var maxnum = $maxnum;
8275: var oldidx = 'printfmthdr_oldpos_'+chgnum;
8276: var newidx = 'printfmthdr_pos_'+chgnum;
8277: oldidx = getIndexByName(oldidx);
8278: newidx = getIndexByName(newidx);
8279: var oldpos = document.display.elements[oldidx].value;
8280: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8281: document.display.elements[oldidx].value = newpos;
8282: var chgtype = 'up';
8283: if (newpos < oldpos) {
8284: chgtype = 'down';
8285: }
8286: for (var j=0; j<maxnum; j++) {
8287: if (j != chgnum) {
8288: oldidx = 'printfmthdr_oldpos_'+j;
8289: newidx = 'printfmthdr_pos_'+j;
8290: oldidx = getIndexByName(oldidx);
8291: newidx = getIndexByName(newidx);
8292: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8293: var currsel = document.display.elements[newidx].selectedIndex;
8294: if (chgtype == 'up') {
8295: if ((currpos > oldpos) && (currpos <= newpos)) {
8296: document.display.elements[newidx].selectedIndex = currsel-1;
8297: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8298: }
8299: } else {
8300: if ((currpos >= newpos) && (currpos < oldpos)) {
8301: document.display.elements[newidx].selectedIndex = currsel+1;
8302: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
8303: }
8304: }
8305: }
8306: }
8307: return;
8308: }
8309:
8310: function getIndexByName(item) {
8311: for (var i=0;i<document.display.elements.length;i++) {
8312: if (document.display.elements[i].name == item) {
8313: return i;
8314: }
8315: }
8316: return -1;
8317: }
8318:
8319: </script>
8320:
8321: ENDJS
1.56 raeburn 8322: $output .= '</td><td align="right"><br />'.
8323: $currstr.'<table class="LC_data_table">';
1.80 raeburn 8324: my $disabled;
8325: if ($noedit) {
8326: $disabled = ' disabled="disabled"';
8327: }
1.1 raeburn 8328: if (@curr > 0) {
8329: for (my $i=0; $i<@curr; $i++) {
8330: my $pos = $i+1;
1.10 raeburn 8331: $output .= '<tr>'.
1.1 raeburn 8332: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 8333: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 8334: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 8335: '"'.$disabled.' /></span></td>';
1.1 raeburn 8336: if ($curr[$i] =~ /^%\d*[nca]$/) {
8337: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
8338: $output .= '<td align="left">'.
1.80 raeburn 8339: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 8340: } else {
8341: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8342: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 8343: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 8344: }
1.10 raeburn 8345: $output .= '</tr>';
1.1 raeburn 8346: }
8347: }
1.80 raeburn 8348: my $pos = $currnum+1;
1.124 raeburn 8349: unless ($noedit) {
1.80 raeburn 8350: $output .=
8351: '<tr>'.
1.1 raeburn 8352: '<td align="left"><span class="LC_nobreak">'.
8353: &position_selector($pos,$currnum,$maxnum).
8354: '<b>'.&mt('New').'</b></span></td><td align="left">'.
8355: &substitution_selector($currnum).'</td>'.
1.10 raeburn 8356: '</tr>';
1.80 raeburn 8357: $pos ++;
1.82 raeburn 8358: $currnum ++;
8359: $output .=
1.80 raeburn 8360: '<tr>'.
1.1 raeburn 8361: '<td align="left"><span class="LC_nobreak">'.
8362: &position_selector($pos,$currnum,$maxnum).
8363: '<b>'.&mt('New').'</b></span></td>'.
8364: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
8365: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 8366: '" value="" size ="25" />'.
8367: '<input type="hidden" name="printfmthdr_maxnum" value="'.
8368: $maxnum.'" /></td>'.
1.80 raeburn 8369: '</tr>';
8370: }
8371: $output .= '</table><br />';
1.1 raeburn 8372: return $output;
8373: }
8374:
8375: sub position_selector {
1.80 raeburn 8376: my ($pos,$num,$maxnum,$disabled) = @_;
8377: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 8378: for (my $j=1; $j<=$maxnum; $j++) {
8379: my $sel = '';
8380: if ($pos == $j) {
8381: $sel = ' selected="selected"';
8382: }
8383: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
8384: }
8385: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
8386: '" value="'.$pos.'" />';
8387: return $output;
8388: }
8389:
8390: sub substitution_selector {
1.80 raeburn 8391: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 8392: my ($stunametxt,$crsidtxt);
8393: if ($crstype eq 'Community') {
8394: $stunametxt = 'member name';
8395: $crsidtxt = 'community ID',
8396: } else {
8397: $stunametxt = 'student name';
8398: $crsidtxt = 'course ID',
8399: }
1.1 raeburn 8400: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 8401: n => $stunametxt,
8402: c => $crsidtxt,
1.1 raeburn 8403: a => 'assignment note',
8404: );
8405: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 8406: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 8407: if ($subst eq '') {
8408: $output .= '<option value="" selected="selected"> </option>';
8409: }
8410: foreach my $field ('n','c','a') {
8411: my $sel ='';
8412: if ($subst eq $field) {
8413: $sel = ' selected="selected"';
8414: }
8415: $output .= '<option value="'.$field.'"'.$sel.'>'.
8416: $lt{$field}.'</option>';
8417: }
8418: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
8419: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 8420: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 8421: return $output;
8422: }
8423:
1.23 raeburn 8424: sub change_clone {
8425: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
8426: my $clone_crs = $cnum.':'.$cdom;
8427: if ($cnum && $cdom) {
8428: my $clone_crs = $cnum.':'.$cdom;
8429: my @allowclone;
8430: if ($clonelist =~ /,/) {
8431: @allowclone = split(',',$clonelist);
8432: } else {
8433: $allowclone[0] = $clonelist;
8434: }
8435: foreach my $currclone (@allowclone) {
8436: if (!grep(/^$currclone$/,@$oldcloner)) {
8437: if ($currclone ne '*') {
1.71 raeburn 8438: if ($currclone =~ /:/) {
8439: my ($uname,$udom) = split(/:/,$currclone);
8440: if ($uname && $udom && $uname ne '*') {
8441: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8442: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8443: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
8444: if ($currclonecrs{'cloneable'} eq '') {
8445: $currclonecrs{'cloneable'} = $clone_crs;
8446: } else {
8447: $currclonecrs{'cloneable'} .= ','.$clone_crs;
8448: }
8449: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 8450: }
8451: }
8452: }
8453: }
8454: }
8455: }
8456: }
8457: foreach my $oldclone (@$oldcloner) {
8458: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
8459: if ($oldclone ne '*') {
1.71 raeburn 8460: if ($oldclone =~ /:/) {
8461: my ($uname,$udom) = split(/:/,$oldclone);
8462: if ($uname && $udom && $uname ne '*' ) {
8463: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
8464: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
8465: my %newclonecrs = ();
8466: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
8467: if ($currclonecrs{'cloneable'} =~ /,/) {
8468: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
8469: foreach my $crs (@currclonecrs) {
8470: if ($crs ne $clone_crs) {
8471: $newclonecrs{'cloneable'} .= $crs.',';
8472: }
1.23 raeburn 8473: }
1.71 raeburn 8474: $newclonecrs{'cloneable'} =~ s/,$//;
8475: } else {
8476: $newclonecrs{'cloneable'} = '';
1.23 raeburn 8477: }
1.71 raeburn 8478: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 8479: }
8480: }
8481: }
8482: }
8483: }
8484: }
8485: }
8486: }
8487: return;
8488: }
8489:
1.108 raeburn 8490: sub devalidate_remote_courseprefs {
8491: my ($cdom,$cnum,$cachekeys) = @_;
8492: return unless (ref($cachekeys) eq 'HASH');
8493: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
8494: my %thismachine;
8495: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.120 raeburn 8496: my @posscached = ('courselti','courseltitools');
1.108 raeburn 8497: if (keys(%servers)) {
8498: foreach my $server (keys(%servers)) {
8499: next if ($thismachine{$server});
8500: my @cached;
8501: foreach my $name (@posscached) {
8502: if ($cachekeys->{$name}) {
8503: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
8504: }
8505: }
8506: if (@cached) {
8507: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
8508: }
8509: }
8510: }
8511: return;
8512: }
8513:
1.1 raeburn 8514: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>