Annotation of loncom/interface/courseprefs.pm, revision 1.115
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.115 ! raeburn 4: # $Id: courseprefs.pm,v 1.114 2022/08/28 02:41:29 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.1 raeburn 228:
1.66 raeburn 229: my $registered_cleanup;
230: my $modified_courses;
231:
1.1 raeburn 232: sub handler {
233: my $r=shift;
234: if ($r->header_only) {
235: &Apache::loncommon::content_type($r,'text/html');
236: $r->send_http_header;
237: return OK;
238: }
239: my $context = 'course';
240: my $cid = $env{'request.course.id'};
1.66 raeburn 241: my ($cnum,$cdom,$chome) = &get_course($cid);
1.1 raeburn 242: my $crstype = &Apache::loncommon::course_type();
1.80 raeburn 243: my ($parm_permission,$allowed) = &get_permission($cid);
1.1 raeburn 244: my $navmap = Apache::lonnavmaps::navmap->new();
1.80 raeburn 245: if ($allowed && $navmap) {
1.1 raeburn 246: &Apache::loncommon::content_type($r,'text/html');
247: $r->send_http_header;
248: } else {
249: if ($navmap) {
1.9 raeburn 250: if ($crstype eq 'Community') {
251: $env{'user.error.msg'}=
252: "/adm/courseprefs:opa:0:0:Cannot modify community settings";
253: } else {
254: $env{'user.error.msg'}=
255: "/adm/courseprefs:opa:0:0:Cannot modify course settings";
256: }
1.1 raeburn 257: } else {
1.9 raeburn 258: if ($crstype eq 'Community') {
259: $env{'user.error.msg'}=
260: "/adm/courseprefs::0:1:Course environment gone, reinitialize the community";
261: } else {
262: $env{'user.error.msg'}=
263: "/adm/courseprefs::0:1:Course environment gone, reinitialize the course";
264:
265: }
1.1 raeburn 266: }
267: return HTTP_NOT_ACCEPTABLE;
268: }
269:
1.66 raeburn 270: $registered_cleanup=0;
271: @{$modified_courses}=();
272:
1.4 raeburn 273: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
274: ['phase','actions','origin']);
1.1 raeburn 275: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.4 raeburn 276: if ($env{'form.origin'} eq 'params') {
277: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/parmset",
278: text=>"Parameter Manager"});
279: }
1.9 raeburn 280: my ($brtext,$brtitle,$crsinfotext,$crsinfodesc,$crscateg,$crshide);
281: my %lt;
282: if ($crstype eq 'Community') {
283: %lt = (
1.40 www 284: conf => 'Community Settings',
285: edit => 'Edit Community Settings',
1.9 raeburn 286: gens => 'General community settings',
287: idnu => 'Community ID or number',
1.64 raeburn 288: unco => 'Unique code',
1.9 raeburn 289: desc => 'Community Description',
1.24 raeburn 290: ownr => 'Community Owner',
1.25 raeburn 291: cown => 'Community Co-owners',
1.9 raeburn 292: catg => 'Categorize community',
293: excc => 'Exclude from community catalog',
294: clon => 'Users allowed to clone community',
295: rept => 'Replacement titles for standard community roles',
1.115 ! raeburn 296: time => 'Time Zone where the community is located',
1.9 raeburn 297: date => 'Locale used for community calendar',
298: coco => 'Community Content',
299: copo => 'Community Policy',
1.13 bisitz 300: priv => 'Domain Coordinators in community',
1.9 raeburn 301: defd => 'Default dates for member access',
302: stuv => 'Member-viewable membership list options',
303: stul => 'Member agreement needed to be listed',
1.42 www 304: clas => 'Membership and facilitator listing',
1.57 raeburn 305: prus => 'Privileged users (Domain Coordinators) in facilitator listing',
1.9 raeburn 306: defc => 'Default Community Spreadsheet',
307: defs => 'Default User Spreadsheet',
308: seme => 'Send message to member when clicking Done on Tasks'
309: );
310: } else {
311: %lt = (
1.40 www 312: conf => 'Course Settings',
313: edit => 'Edit Course Settings',
1.20 faziophi 314: gens => 'General course settings',
315: idnu => 'Course ID or number',
1.64 raeburn 316: unco => 'Unique code',
1.20 faziophi 317: desc => 'Course Description',
1.55 raeburn 318: cred => 'Student credits',
1.24 raeburn 319: ownr => 'Course Owner',
1.25 raeburn 320: cown => 'Course Co-owners',
1.9 raeburn 321: catg => 'Categorize course',
322: excc => 'Exclude from course catalog',
323: clon => 'Users allowed to clone course',
324: rept => 'Replacement titles for standard course roles',
1.115 ! raeburn 325: time => 'Time Zone in which the course takes place',
1.20 faziophi 326: date => 'Locale used for course calendar',
1.9 raeburn 327: coco => 'Course Content',
328: copo => 'Course Policy',
1.13 bisitz 329: priv => 'Domain Coordinators in course',
1.9 raeburn 330: defd => 'Default dates for student access',
331: stuv => 'Student-viewable classlist options',
332: stul => 'Student agreement needed to be listed',
1.42 www 333: clas => 'Classlists and staff listing',
1.57 raeburn 334: prus => 'Privileged users (Domain Coordinators) in staff listing',
1.56 raeburn 335: prdo => "Domains to check for privileged users (besides course's domain)",
1.9 raeburn 336: defc => 'Default Course Spreadsheet',
337: defs => 'Default Student Spreadsheet',
338: seme => 'Send message to student when clicking Done on Tasks',
339: );
340: }
1.35 raeburn 341: $lt{'lcrv'} = 'Required LON-CAPA version';
1.1 raeburn 342: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/courseprefs',
1.9 raeburn 343: text=>$lt{'conf'}});
1.1 raeburn 344: my $breadcrumbs =
1.9 raeburn 345: &Apache::lonhtmlcommon::breadcrumbs($lt{'edit'});
1.1 raeburn 346:
347: my $phase = 'pickactions';
348: if ( exists($env{'form.phase'}) ) {
349: $phase = $env{'form.phase'};
350: }
351:
1.80 raeburn 352: if (($phase eq 'categorizecourse') && ($parm_permission->{'categorizecourse'})) {
1.9 raeburn 353: &assign_course_categories($r,$crstype);
1.1 raeburn 354: return OK;
355: }
356:
1.80 raeburn 357: if (($phase eq 'releaseinfo') && ($parm_permission->{'releaseinfo'})) {
1.36 raeburn 358: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
359: if ($loncaparev) {
1.66 raeburn 360: if (&display_loncaparev_constraints($r,$navmap,$loncaparev,$crstype)) {
361: push(@{$modified_courses},[$cdom,$cnum,$chome,$crstype]);
362: unless ($registered_cleanup) {
363: my $handlers = $r->get_handlers('PerlCleanupHandler');
364: $r->set_handlers('PerlCleanupHandler' => [\&update_releasereq,@{$handlers}]);
365: $registered_cleanup=1;
366: }
367: }
1.36 raeburn 368: return OK;
369: }
370: }
371:
1.1 raeburn 372: my %values=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.102 raeburn 373: my %linkprot=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1.99 raeburn 374: my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1);
1.102 raeburn 375: foreach my $id (keys(%linkprot)) {
376: if (ref($linkprot{$id}) eq 'HASH') {
1.99 raeburn 377: if (ref($ltienc{$id}) eq 'HASH') {
1.102 raeburn 378: $values{'linkprot'}{$id} = { %{$linkprot{$id}}, %{$ltienc{$id}} };
1.99 raeburn 379: } else {
1.102 raeburn 380: $values{'linkprot'}{$id} = $linkprot{$id};
1.99 raeburn 381: }
382: }
383: unless ($phase eq 'process') {
1.102 raeburn 384: if (ref($values{'linkprot'}{$id}) eq 'HASH') {
385: delete($values{'linkprot'}{$id}{'secret'});
1.99 raeburn 386: }
387: }
388: }
1.102 raeburn 389: if ($linkprot{'lock'}) {
390: delete($linkprot{'lock'});
1.93 raeburn 391: }
1.1 raeburn 392: my @prefs_order = ('courseinfo','localization','feedback','discussion',
393: 'classlists','appearance','grading','printouts',
1.102 raeburn 394: 'menuitems','linkprot','spreadsheet','bridgetasks',
1.93 raeburn 395: 'lti','other');
1.1 raeburn 396:
397: my %prefs = (
398: 'courseinfo' =>
1.9 raeburn 399: { text => $lt{'gens'},
1.44 www 400: help => 'Course_Prefs_General',
1.35 raeburn 401: ordered => ['owner','co-owners','loncaparev','description',
1.64 raeburn 402: 'clonedfrom','courseid','uniquecode','categories',
1.88 raeburn 403: 'hidefromcat','syllabus','cloners','url',
1.64 raeburn 404: 'rolenames'],
1.3 raeburn 405: itemtext => {
1.25 raeburn 406: 'owner' => $lt{'ownr'},
407: 'co-owners' => $lt{'cown'},
408: 'description' => $lt{'desc'},
409: 'courseid' => $lt{'idnu'},
1.64 raeburn 410: 'uniquecode' => $lt{'unco'},
1.25 raeburn 411: 'categories' => $lt{'catg'},
412: 'hidefromcat' => $lt{'excc'},
413: 'cloners' => $lt{'clon'},
1.88 raeburn 414: 'syllabus' => 'Syllabus status',
1.25 raeburn 415: 'url' => 'Top Level Map',
416: 'rolenames' => $lt{'rept'},
1.35 raeburn 417: 'loncaparev' => $lt{'lcrv'},
1.63 raeburn 418: 'clonedfrom' => 'Cloned from',
1.3 raeburn 419: },
1.1 raeburn 420: },
421: 'localization' =>
1.42 www 422: { text => 'Language and time localization',
1.44 www 423: help => 'Course_Prefs_Language',
1.1 raeburn 424: ordered => ['languages','timezone','datelocale'],
1.3 raeburn 425: itemtext => {
1.20 faziophi 426: languages => 'Languages used',
1.9 raeburn 427: timezone => $lt{'time'},
428: datelocale => $lt{'date'},
1.3 raeburn 429: },
1.1 raeburn 430: },
431: 'feedback' =>
1.20 faziophi 432: { text => 'Feedback messages',
1.44 www 433: help => 'Course_Prefs_Feedback',
1.1 raeburn 434: header => [{col1 => 'Questions about:',
1.20 faziophi 435: col2 => 'Recipients'}],
1.3 raeburn 436: ordered => ['question.email','comment.email','policy.email'],
437: itemtext => {
438: 'question.email' => 'Resource Content',
1.9 raeburn 439: 'comment.email' => $lt{'coco'},
440: 'policy.email' => $lt{'copo'},
1.3 raeburn 441: },
1.1 raeburn 442: },
443: 'discussion' =>
444: { text => 'Discussion and Chat',
1.44 www 445: help => 'Course_Prefs_Discussions',
1.31 raeburn 446: ordered => ['pch.roles.denied','pch.users.denied',
1.77 raeburn 447: 'pac.roles.denied','pac.users.denied',
1.31 raeburn 448: 'plc.roles.denied','plc.users.denied',
1.1 raeburn 449: 'allow_limited_html_in_feedback',
1.50 raeburn 450: 'allow_discussion_post_editing',
451: 'discussion_post_fonts'],
1.3 raeburn 452: itemtext => {
1.31 raeburn 453: 'pch.roles.denied' => 'No Resource Discussion',
454: 'pch.users.denied' => 'No Resource Discussion',
455: 'plc.roles.denied' => 'No Chat room use',
456: 'plc.users.denied' => 'No Chat room use',
1.77 raeburn 457: 'pac.roles.denied' => 'No Anonymous Resource Discussion',
458: 'pac.users.denied' => 'No Anonymous Resource Discussion',
1.20 faziophi 459: allow_limited_html_in_feedback => 'Allow limited HTML in discussion',
460: allow_discussion_post_editing => 'Users can edit/delete own discussion posts',
1.77 raeburn 461: discussion_post_fonts => 'Discussion post fonts based on likes/unlikes',
1.3 raeburn 462: },
1.1 raeburn 463: },
464: 'classlists' =>
1.9 raeburn 465: { text => $lt{'clas'},
1.44 www 466: help => 'Course_Prefs_Classlists',
1.1 raeburn 467: header => [{col1 => 'Type',
1.9 raeburn 468: col2 => $lt{'defd'}},
1.1 raeburn 469: {col1 => 'Setting',
1.9 raeburn 470: col2 => $lt{'priv'}},
1.1 raeburn 471: {col1 => 'Setting',
1.9 raeburn 472: col2 => $lt{'stuv'}}],
1.1 raeburn 473: ordered => ['default_enrollment_start_date',
474: 'default_enrollment_end_date',
1.55 raeburn 475: 'defaultcredits',
1.56 raeburn 476: 'nothideprivileged','checkforpriv',
477: 'student_classlist_view',
1.26 raeburn 478: 'student_classlist_opt_in','student_classlist_portfiles'],
1.3 raeburn 479: itemtext => {
480: default_enrollment_start_date => 'Start date',
481: default_enrollment_end_date => 'End date',
1.57 raeburn 482: nothideprivileged => $lt{'prus'},
1.56 raeburn 483: checkforpriv => $lt{'prdo'},
1.9 raeburn 484: student_classlist_view => $lt{'stuv'},
1.26 raeburn 485: student_classlist_opt_in => $lt{'stul'},
1.3 raeburn 486: student_classlist_portfiles => 'Include link to accessible portfolio files',
1.55 raeburn 487: defaultcredits => $lt{'cred'},
1.3 raeburn 488: },
1.1 raeburn 489: },
490: 'appearance' =>
1.20 faziophi 491: { text => 'Display of resources ',
1.44 www 492: help => 'Course_Prefs_Display',
1.1 raeburn 493: ordered => ['default_xml_style','pageseparators',
494: 'disable_receipt_display','texengine',
1.114 raeburn 495: 'tthoptions','uselcmath','usejsme',
496: 'inline_chem','extresource'],
1.3 raeburn 497: itemtext => {
1.17 faziophi 498: default_xml_style => 'Default XML style file',
1.20 faziophi 499: pageseparators => 'Visibly Separate Items on Pages',
500: disable_receipt_display => 'Disable display of problem receipts',
501: texengine => 'Force use of a specific math rendering engine',
1.3 raeburn 502: tthoptions => 'Default set of options to pass to tth/m when converting TeX',
1.69 raeburn 503: uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up',
504: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.95 raeburn 505: inline_chem => 'Chemical reaction response uses inline preview, not pop-up',
1.114 raeburn 506: extresource => 'Display of external resources',
1.3 raeburn 507: },
1.1 raeburn 508: },
509: 'grading' =>
510: { text => 'Grading',
1.44 www 511: help => 'Course_Prefs_Grading',
1.1 raeburn 512: ordered => ['grading','rndseed',
513: 'receiptalg','disablesigfigs'],
1.3 raeburn 514: itemtext => {
1.20 faziophi 515: grading => 'Grading',
516: rndseed => 'Randomization algorithm used',
517: receiptalg => 'Receipt algorithm used',
518: disablesigfigs => 'Disable checking of Significant Figures',
1.3 raeburn 519: },
520:
1.1 raeburn 521: },
522: 'printouts' =>
1.20 faziophi 523: { text => 'Printout generation',
1.44 www 524: help => 'Course_Prefs_Printouts',
1.1 raeburn 525: ordered => ['problem_stream_switch','suppress_tries',
526: 'default_paper_size','print_header_format',
1.14 raeburn 527: 'disableexampointprint','canuse_pdfforms'],
1.3 raeburn 528: itemtext => {
529: problem_stream_switch => 'Allow problems to be split over pages',
530: suppress_tries => 'Suppress number of tries in printing',
531: default_paper_size => 'Default paper type',
532: print_header_format => 'Print header format',
1.51 bisitz 533: disableexampointprint => 'Disable automatically printing point values on bubblesheet exams',
1.14 raeburn 534: canuse_pdfforms => 'Users can print problems as PDF forms and upload later for grading',
1.3 raeburn 535: },
1.1 raeburn 536: },
537: 'spreadsheet' =>
538: { text => 'Spreadsheets',
1.44 www 539: help => 'Course_Prefs_Spreadsheet',
1.1 raeburn 540: ordered => ['spreadsheet_default_classcalc',
541: 'spreadsheet_default_studentcalc',
542: 'spreadsheet_default_assesscalc','hideemptyrows'],
1.3 raeburn 543: itemtext => {
1.9 raeburn 544: spreadsheet_default_classcalc => $lt{'defc'},
545: spreadsheet_default_studentcalc => $lt{'defs'},
1.3 raeburn 546: spreadsheet_default_assesscalc => 'Default Assessment Spreadsheet',
547: hideemptyrows => 'Hide Empty Rows in Spreadsheets',
548: },
1.1 raeburn 549: },
550: 'bridgetasks' =>
551: { text => 'Bridge tasks',
1.44 www 552: help => 'Course_Prefs_Bridgetasks',
1.1 raeburn 553: ordered => ['task_messages','task_grading',
554: 'suppress_embed_prompt'],
1.3 raeburn 555: itemtext => {
1.9 raeburn 556: task_messages => $lt{'seme'},
1.3 raeburn 557: task_grading => 'Bridge Task grading by instructors and TAs in sections' ,
1.5 raeburn 558: suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio',
1.3 raeburn 559: },
1.1 raeburn 560: },
1.87 raeburn 561: 'lti' =>
562: {
563: text => 'LTI provider settings',
564: help => 'Course_Prefs_LTIProvider',
565: ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'],
566: itemtext => {
567: 'lti.override' => 'Override domain defaults',
568: 'lti.topmenu' => 'Display LON-CAPA page header',
569: 'lti.inlinemenu' => 'Display LON-CAPA inline menu',
570: 'lti.lcmenu' => 'Menu items',
571: },
572: },
1.91 raeburn 573: 'menuitems' =>
574: {
575: text => 'Menu display',
576: help => 'Course_Prefs_Menus',
577: header => [{col1 => 'Default Menu',
578: col2 => 'Value',},
579: {col1 => 'Menu collections',
580: col2 => 'Settings',
581: }],
582: ordered => ['menudefault','menucollections'],
583: itemtext => {
584: menudefault => 'Choose default collection of menu items for course',
585: menucollections => 'Menu collections',
586: },
587: },
1.102 raeburn 588: 'linkprot' =>
1.93 raeburn 589: {
590: text => 'Link protection',
591: help => 'Course_Prefs_Linkprotection',
592: header => [{col1 => 'Item',
593: col2 => 'Settings',
594: }],
595: },
1.1 raeburn 596: 'other' =>
597: { text => 'Other settings',
1.44 www 598: help => 'Course_Prefs_Other',
1.1 raeburn 599: header => [ {col1 => 'Item',
600: col2 => 'Value',
601: }],
602: },
603: );
1.80 raeburn 604: if (($phase eq 'process') && ($parm_permission->{'process'})) {
1.3 raeburn 605: my @allitems = &get_allitems(%prefs);
1.108 raeburn 606: my $result = &Apache::lonconfigsettings::make_changes($r,$cdom,$phase,$context,
607: \@prefs_order,\%prefs,\%values,
608: $cnum,undef,\@allitems,
609: 'coursepref',$parm_permission);
610: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
611: $r->rflush();
612: &devalidate_remote_courseprefs($cdom,$cnum,$result);
613: }
1.80 raeburn 614: } elsif (($phase eq 'display') && ($parm_permission->{'display'})) {
1.91 raeburn 615: my $noedit;
616: if (ref($parm_permission) eq 'HASH') {
617: unless ($parm_permission->{'process'}) {
618: $noedit = 1;
619: }
620: }
621: my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit);
1.3 raeburn 622: my @allitems = &get_allitems(%prefs);
1.1 raeburn 623: &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context,
1.99 raeburn 624: \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype,
1.80 raeburn 625: 'coursepref',$parm_permission);
1.1 raeburn 626: } else {
627: &Apache::lonconfigsettings::display_choices($r,$phase,$context,
1.80 raeburn 628: \@prefs_order,\%prefs,
629: 'coursepref',$parm_permission);
1.1 raeburn 630: }
631: return OK;
632: }
633:
1.80 raeburn 634: sub get_permission {
635: my ($cid) = @_;
636: my %permission;
637: my $allowed = 0;
638: return (\%permission,$allowed) unless ($cid);
639: if (&Apache::lonnet::allowed('opa',$cid)) {
640: %permission= (
641: 'pickactions' => 1,
642: 'categorizecourse' => 1,
643: 'releaseinfo' => 1,
644: 'process' => 1,
645: 'display' => 1,
646: );
647: } elsif (&Apache::lonnet::allowed('vpa',$env{'request.course.id'})) {
648: %permission = (
649: 'pickactions' => 1,
650: 'releaseinfo' => 1,
651: 'display' => 1,
652: );
653: }
654: foreach my $perm (values(%permission)) {
655: if ($perm) { $allowed=1; last; }
656: }
657: return (\%permission,$allowed);
658: }
659:
1.3 raeburn 660: sub get_allitems {
661: my (%prefs) = @_;
662: my @allitems;
663: foreach my $item (keys(%prefs)) {
664: if (ref($prefs{$item}) eq 'HASH') {
665: if (ref($prefs{$item}{'ordered'}) eq 'ARRAY') {
666: push(@allitems,@{$prefs{$item}{'ordered'}});
667: if ($item eq 'feedback') {
668: push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}}));
669: }
670: }
671: }
672: }
673: return @allitems;
674: }
675:
1.1 raeburn 676: sub print_config_box {
1.99 raeburn 677: my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_;
1.1 raeburn 678: my $ordered = $item->{'ordered'};
1.3 raeburn 679: my $itemtext = $item->{'itemtext'};
1.80 raeburn 680: my $noedit;
681: if (ref($parm_permission) eq 'HASH') {
682: unless ($parm_permission->{'process'}) {
683: $noedit = 1;
684: }
685: }
1.1 raeburn 686: my $rowtotal = 0;
687: my $output =
1.45 www 688: '<table class="LC_nested_outer">
689: <tr>
690: <th align="left" valign="middle"><span class="LC_nobreak" style="font-size: larger;" >'.
1.52 raeburn 691: &mt($item->{text});
692: if ($item->{'help'}) {
1.53 raeburn 693: $output .= ' '.
1.52 raeburn 694: &Apache::loncommon::help_open_topic($item->{'help'});
695: }
696: $output .= '</span></th>'."\n".
697: '</tr>';
1.91 raeburn 698: if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) {
1.1 raeburn 699: $output .= '
1.45 www 700: <tr>
701: <td>
1.18 faziophi 702: <table class="LC_nested">';
703: if (exists $item->{'header'}->[0]->{'col1'} ||
704: exists $item->{'header'}->[0]->{'col2'}) {
705: $output .= '
706: <tr class="LC_info_row">
1.56 raeburn 707: <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
708: if ($action eq 'feedback') {
709: $output .= '
710: <td class="LC_right_item" colspan="2">';
711: } else {
712: $output .= '
713: <td class="LC_right_item">';
714: }
715: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 716: </tr>';
717: }
1.1 raeburn 718: $rowtotal ++;
719: if ($action eq 'feedback') {
1.80 raeburn 720: $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 721: } elsif ($action eq 'classlists') {
1.80 raeburn 722: $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 723: } elsif ($action eq 'menuitems') {
724: $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 725: }
726: $output .= '
727: </table>
1.45 www 728: </td>
729: </tr>
730: <tr>
731: <td>
1.1 raeburn 732: <table class="LC_nested">
733: <tr class="LC_info_row">
734: <td class="LC_left_item">'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.56 raeburn 735: if ($action eq 'classlists') {
736: $output .= '
737: <td class="LC_right_item" colspan="2">';
738: } else {
739: $output .= '
740: <td class="LC_right_item">';
741: }
742: $output .= &mt($item->{'header'}->[1]->{'col2'}).'</td>
1.1 raeburn 743: </tr>';
744: if ($action eq 'classlists') {
1.80 raeburn 745: $output .= &print_classlists('middle',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit).
1.1 raeburn 746: '
747: </table>
1.45 www 748: </td>
749: </tr>
750: <tr>
751: <td>
1.18 faziophi 752: <table class="LC_nested">';
1.43 www 753: if (exists $item->{'header'}->[2]->{'col1'} ||
754: exists $item->{'header'}->[2]->{'col2'}) {
1.18 faziophi 755: $output .= '
756: <tr class="LC_info_row">
1.43 www 757: <td class="LC_left_item">'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
758: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.18 faziophi 759: </tr>';
760: }
1.1 raeburn 761: }
762: } else {
763: $output .= '
1.45 www 764: <tr>
765: <td>
1.18 faziophi 766: <table class="LC_nested">';
767: if (exists $item->{'header'}->[0]->{'col1'} ||
768: exists $item->{'header'}->[0]->{'col2'}) {
769: $output .= '
770: <tr class="LC_info_row">
1.56 raeburn 771: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
772: if (($action eq 'courseinfo') || ($action eq 'localization') ||
773: ($action eq 'print_discussion')) {
774: $output .= '<td class="LC_right_item" valign="top" colspan="2">';
775: } else {
776: $output .= '<td class="LC_right_item" valign="top">';
777: }
778: $output .= &mt($item->{'header'}->[0]->{'col2'}).'</td>
1.18 faziophi 779: </tr>';
780: }
1.1 raeburn 781: }
782: $rowtotal ++;
783: if ($action eq 'courseinfo') {
1.80 raeburn 784: $output .= &print_courseinfo($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 785: } elsif ($action eq 'localization') {
1.80 raeburn 786: $output .= &print_localization($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 787: } elsif ($action eq 'feedback') {
1.80 raeburn 788: $output .= &print_feedback('bottom',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.1 raeburn 789: } elsif ($action eq 'discussion') {
1.80 raeburn 790: $output .= &print_discussion($cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit);
1.52 raeburn 791: } elsif (($action eq 'classlists') || ($action eq 'viewableroster')) {
1.80 raeburn 792: $output .= &print_classlists('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 793: } elsif ($action eq 'appearance') {
1.80 raeburn 794: $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 795: } elsif ($action eq 'grading') {
1.80 raeburn 796: $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 797: } elsif ($action eq 'printouts') {
1.80 raeburn 798: $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 799: } elsif ($action eq 'spreadsheet') {
1.80 raeburn 800: $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.1 raeburn 801: } elsif ($action eq 'bridgetasks') {
1.80 raeburn 802: $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.87 raeburn 803: } elsif ($action eq 'lti') {
804: $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit);
1.91 raeburn 805: } elsif ($action eq 'menuitems') {
806: $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit);
1.102 raeburn 807: } elsif ($action eq 'linkprot') {
808: $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit,'course');
1.1 raeburn 809: } elsif ($action eq 'other') {
1.80 raeburn 810: $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit);
1.1 raeburn 811: }
812: $output .= '
813: </table>
1.45 www 814: </td>
815: </tr>
816: </table><br />';
1.1 raeburn 817: return ($output,$rowtotal);
818: }
819:
820: sub process_changes {
1.108 raeburn 821: my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype,$lastactref) = @_;
1.102 raeburn 822: my (%newvalues,$errors);
1.3 raeburn 823: if (ref($item) eq 'HASH') {
824: if (ref($changes) eq 'HASH') {
825: my @ordered;
826: if ($action eq 'other') {
827: @ordered = &get_other_items($cdom,$values,$allitems);
828: if ($env{'form.newp_name'} ne '') {
829: my $newp = $env{'form.newp_name'};
830: if ($env{'form.newp_value'} ne '') {
831: if (ref($allitems) eq 'ARRAY') {
832: unless ((grep(/^\Q$newp\E$/,@ordered)) ||
833: (grep(/^\Q$newp\E$/,@{$allitems}))) {
834: $changes->{$newp} = $env{'form.newp_value'};
835: }
836: }
837: }
838: }
1.102 raeburn 839: } elsif ($action eq 'linkprot') {
1.99 raeburn 840: if (ref($values->{$action}) eq 'HASH') {
841: foreach my $id (keys(%{$values->{$action}})) {
1.93 raeburn 842: if ($id =~ /^\d+$/) {
843: push(@ordered,$id);
844: }
845: }
846: }
847: @ordered = sort { $a <=> $b } @ordered;
848: if (($env{'form.linkprot_add'}) && ($env{'form.linkprot_maxnum'} =~ /^\d+$/)) {
849: push(@ordered,$env{'form.linkprot_maxnum'});
850: }
1.3 raeburn 851: } elsif (ref($item->{'ordered'}) eq 'ARRAY') {
1.49 raeburn 852: if ($action eq 'courseinfo') {
853: my ($can_toggle_cat,$can_categorize) =
854: &can_modify_catsettings($cdom,$crstype);
855: foreach my $entry (@{$item->{'ordered'}}) {
856: next if (($entry eq 'hidefromcat') &&
857: (!$can_toggle_cat));
858: next if (($entry eq 'categories') &&
859: (!$can_categorize));
860: next if (($entry eq 'loncaparev') ||
1.63 raeburn 861: ($entry eq 'owner') ||
1.88 raeburn 862: ($entry eq 'clonedfrom') ||
863: ($entry eq 'syllabus'));
1.49 raeburn 864: push(@ordered,$entry);
865: }
1.55 raeburn 866: } elsif ($action eq 'classlists') {
867: foreach my $entry (@{$item->{'ordered'}}) {
868: next if ($entry eq 'defaultcredits');
869: push(@ordered,$entry);
870: }
1.49 raeburn 871: } else {
872: @ordered = @{$item->{'ordered'}};
873: }
1.3 raeburn 874: }
875: if (@ordered > 0) {
876: if ($action eq 'feedback') {
877: foreach my $entry (@ordered) {
878: my $userstr = '';
879: my $total = $env{'form.'.$entry.'_total'};
880: if ($total) {
881: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
882: for (my $i=0; $i<$total; $i++) {
883: unless (grep(/^$i$/,@deletes)) {
884: $userstr .= $env{'form.'.$entry.'_user_'.$i}.
885: &get_sec_str($entry,$i).',';
886: }
887: }
888: } else {
889: $total = 0;
890: }
891: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
892: my $uname = $env{'form.'.$entry.'_uname_'.$total};
893: my $udom = $env{'form.'.$entry.'_udom_'.$total};
894: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
895: $userstr =~ s/,$//;
896: $disallowed->{'feedback'}{$entry} = $uname.':'.$udom;
897: } else {
898: $userstr .= $uname.':'.$udom.&get_sec_str($entry,$total);
899: }
900: } else {
901: $userstr =~ s/,$//;
902: }
903: $newvalues{$entry} = $userstr;
904: if ($newvalues{$entry} ne $values->{$entry}) {
905: $changes->{$entry} = $newvalues{$entry};
906: }
907: my $ext_entry = $entry.'.text';
908: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
909: if ($newvalues{$ext_entry} ne $values->{$ext_entry}) {
910: $changes->{$ext_entry} = $newvalues{$ext_entry};
911: }
912: }
1.91 raeburn 913: } elsif ($action eq 'menuitems') {
914: my (%current,@colls);
915: my $next = 1;
916: if ($values->{'menucollections'}) {
917: foreach my $item (split(/;/,$values->{'menucollections'})) {
918: my ($num,$value) = split(/\%/,$item);
919: if ($num =~ /^\d+$/) {
920: unless (grep(/^$num$/,@colls)) {
921: push(@colls,$num);
922: }
923: my @entries = split(/\&/,$value);
924: foreach my $entry (@entries) {
925: my ($name,$fields) = split(/=/,$entry);
926: $current{$num}{$name} = $fields;
927: }
928: }
929: }
930: }
931: if (@colls) {
932: @colls = sort { $a <=> $b } @colls;
933: $next += $colls[-1];
934: }
935: if ($env{'form.menucollections_add'} eq $next) {
936: push(@colls,$next);
937: }
938: my $currdef = $values->{'menudefault'};
939: my $possdef = $env{'form.menudefault'};
940: if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) {
1.92 raeburn 941: if ($currdef ne $possdef) {
1.91 raeburn 942: $changes->{'menudefault'} = $possdef;
943: }
1.92 raeburn 944: } elsif ($currdef) {
1.91 raeburn 945: $changes->{'menudefault'} = '';
946: }
947: my $menucoll;
948: if (@colls) {
949: my ($ordered,$cats) = &menuitems_categories();
950: my %shortcats = &menuitems_abbreviations();
951: foreach my $num (@colls) {
952: my ($entry,%include);
953: map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num);
954: foreach my $item (@{$ordered}) {
955: if ($item eq 'shown') {
956: foreach my $type (@{$cats->{$item}}) {
957: $entry .= $type.'=';
958: if ($include{$type}) {
959: $entry .= 'y';
960: } else {
961: $entry .= 'n';
962: }
963: $entry .= '&';
964: }
965: } else {
966: $entry .= $shortcats{$item}.'=';
967: foreach my $type (@{$cats->{$item}}) {
968: if ($include{$type}) {
969: $entry .= $type.',';
970: }
971: }
972: $entry =~ s/,$//;
973: $entry .= '&';
974: }
975: }
976: $entry =~ s/\&$//;
977: if ($menucoll) {
978: $menucoll .= ';';
979: }
980: $menucoll .= $num.'%'.$entry;
981: }
982: if ($menucoll ne $values->{'menucollections'}) {
983: $changes->{'menucollections'} = $menucoll;
984: }
985: } elsif ($values->{'menucollections'}) {
986: $changes->{'menucollections'} = '';
987: }
1.102 raeburn 988: } elsif ($action eq 'linkprot') {
989: if (ref($values) eq 'HASH') {
1.108 raeburn 990: $errors = &process_linkprot($cdom,$cnum,$values->{$action},$changes,'course',$lastactref);
1.93 raeburn 991: }
1.3 raeburn 992: } else {
993: foreach my $entry (@ordered) {
994: if ($entry eq 'cloners') {
995: if ($env{'form.cloners_all'}) {
996: $newvalues{$entry} = '*';
997: } else {
998: my @clonedoms;
999: if (exists($env{'form.cloners_activate'})) {
1000: my $actnum = $env{'form.cloners_activate'};
1.71 raeburn 1001: if ($actnum ne '-1') {
1.33 raeburn 1002: if ($env{'form.cloners_dom_'.$actnum} ne '') {
1003: my $clonedom = $env{'form.cloners_dom_'.$actnum};
1.3 raeburn 1004: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1005: $newvalues{$entry} = '*:'.$clonedom;
1006: push(@clonedoms,$newvalues{$entry});
1007: }
1008: }
1009: }
1010: } else {
1011: my $num = $env{'form.cloners_total'};
1012: my @deletes =
1013: &Apache::loncommon::get_env_multiple('form.cloners_delete');
1014: for (my $i=0; $i<$num; $i++) {
1015: if (!grep(/^$i$/,@deletes)) {
1016: my $clonedom = $env{'form.cloners_dom_'.$i};
1017: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1018: if (!grep(/^\*:\Q$clonedom\E$/,@clonedoms)) {
1.71 raeburn 1019: push(@clonedoms,'*:'.$clonedom);
1.3 raeburn 1020: }
1021: }
1022: }
1023: }
1024: if (@clonedoms) {
1025: $newvalues{$entry}=join(',',@clonedoms);
1026: }
1027: }
1028: if ($env{'form.cloners_newdom'} ne '') {
1029: my $clonedom = $env{'form.cloners_newdom'};
1030: if (&check_clone($clonedom,$disallowed) eq 'ok') {
1031: my $newdom = '*:'.$env{'form.cloners_newdom'};
1.93 raeburn 1032: if (@clonedoms) {
1.3 raeburn 1033: if (!grep(/^\Q$newdom\E$/,@clonedoms)) {
1034: $newvalues{$entry} .= ','.$newdom;
1035: }
1036: } else {
1037: $newvalues{$entry} = $newdom;
1038: }
1039: }
1040: }
1041: if ($env{'form.'.$entry} ne '') {
1042: my @cloners = split(',',$env{'form.'.$entry});
1043: my @okcloners;
1044: foreach my $cloner (@cloners) {
1.23 raeburn 1045: $cloner =~ s/^\s+//;
1046: $cloner =~ s/\s+$//;
1047: unless ($cloner eq '') {
1048: my ($uname,$udom) = split(':',$cloner);
1049: if (&check_clone($udom,$disallowed,$uname) eq 'ok') {
1050: if (!grep(/^\Q$cloner\E$/,@okcloners)) {
1051: push(@okcloners,$cloner);
1052: }
1.3 raeburn 1053: }
1054: }
1055: }
1056: if (@okcloners) {
1057: my $okclonestr = join(',',@okcloners);
1058: if ($newvalues{$entry} ne '') {
1059: $newvalues{$entry} .= ','.$okclonestr;
1060: } else {
1061: $newvalues{$entry} = $okclonestr;
1062: }
1063: }
1064: }
1.71 raeburn 1065: if (ref($values) eq 'HASH') {
1066: my (@code_order,%codedefaults);
1067: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
1068: \@code_order);
1069: my $clonebycode;
1070: if ($env{'form.cloners_instcode'}) {
1071: if (@code_order > 0) {
1072: my @standardnames = &Apache::loncommon::get_standard_codeitems();
1073: my %local_to_standard;
1074: for (my $i=0; $i<@code_order; $i++) {
1075: $local_to_standard{$code_order[$i]} = $standardnames[$i];
1076: }
1077: foreach my $item (@code_order) {
1078: my $key = $local_to_standard{$item};
1079: if ($key ne '') {
1080: if ($env{'form.'.$key}) {
1081: $clonebycode .= $key.'='.&escape($env{'form.'.$key}).'&';
1082: }
1083: }
1084: }
1085: $clonebycode =~ s/\&$//;
1086: }
1087: }
1088: if ($clonebycode) {
1089: if ($newvalues{$entry}) {
1090: $newvalues{$entry} .= ','.$clonebycode;
1091: } else {
1092: $newvalues{$entry} = $clonebycode;
1093: }
1094: }
1095: }
1.3 raeburn 1096: }
1097: if (ref($disallowed) eq 'HASH') {
1098: if (ref($disallowed->{'cloners'}) eq 'HASH') {
1099: foreach my $key (keys(%{$disallowed->{'cloners'}})) {
1100: $disallowed->{'cloners'}{$key} =~ s/,$//;
1101: }
1102: }
1103: }
1.25 raeburn 1104: } elsif ($entry eq 'co-owners') {
1105: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1106: my $coowners = $values->{'internal.co-owners'};
1107: my @currcoown;
1108: if ($coowners) {
1109: @currcoown = split(',',$coowners);
1110: }
1111: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1112: my $autocoowner;
1113: if (($crstype eq 'Course') &&
1114: ($values->{'internal.coursecode'})) {
1115: my %domconf =
1116: &Apache::lonnet::get_dom('configuration',['autoenroll'],$cdom);
1117: if (ref($domconf{'autoenroll'}) eq 'HASH') {
1118: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
1119: }
1120: }
1.96 raeburn 1121: if ($autocoowner) {
1122: $newvalues{'co-owners'} = $values->{'internal.co-owners'};
1123: } else {
1.25 raeburn 1124: my @keepcoowners = &Apache::loncommon::get_env_multiple('form.coowners');
1125: my @pendingcoowners = &Apache::loncommon::get_env_multiple('form.pendingcoowners');
1126: my @invitecoowners = &Apache::loncommon::get_env_multiple('form.invitecoowners');
1127: if (@invitecoowners) {
1128: push(@pendingcoowners,@invitecoowners);
1129: }
1130: $newvalues{'pendingco-owners'} = join(',',sort(@pendingcoowners));
1131: $newvalues{'co-owners'} = join(',',sort(@keepcoowners));
1132: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1133: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1134: push(@{$changes->{$entry}{'changed'}},'co-owners');
1135: }
1136: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1137: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1138: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1139: }
1140: }
1141: } else {
1142: my (@newpending,@newcoown);
1143: my $uname = $env{'user.name'};
1144: my $udom = $env{'user.domain'};
1145: my $pendingcoowners = $values->{'internal.pendingco-owners'};
1146: my @pendingcoown = split(',',$pendingcoowners);
1.90 raeburn 1147: if ($env{'form.pending_coowner'}) {
1.25 raeburn 1148: foreach my $item (@pendingcoown) {
1149: unless ($item eq $uname.':'.$udom) {
1150: push(@newpending,$item);
1151: }
1152: }
1153: @newcoown = @currcoown;
1.90 raeburn 1154: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 1155: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
1156: push(@newcoown,$uname.':'.$udom);
1157: }
1158: }
1.90 raeburn 1159: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 1160: foreach my $item (@currcoown) {
1161: unless ($item eq $uname.':'.$udom) {
1162: push(@newcoown,$item);
1163: }
1164: }
1165: if ($pendingcoowners ne '') {
1166: @newpending = @pendingcoown;
1167: }
1.96 raeburn 1168: } else {
1169: @newcoown = @currcoown;
1.25 raeburn 1170: }
1171: $newvalues{'pendingco-owners'} = join(',',sort(@newpending));
1172: $newvalues{'co-owners'} = join(',',sort(@newcoown));
1173: if ($newvalues{'co-owners'} ne $values->{'internal.co-owners'}) {
1174: $changes->{$entry}{'co-owners'} = $newvalues{'co-owners'};
1175: push(@{$changes->{$entry}{'changed'}},'co-owners');
1176: }
1177: if ($newvalues{'pendingco-owners'} ne $values->{'internal.pendingco-owners'}) {
1178: $changes->{$entry}{'pendingco-owners'} = $newvalues{'pendingco-owners'};
1179: push(@{$changes->{$entry}{'changed'}},'pendingco-owners');
1180: }
1181: }
1.3 raeburn 1182: } elsif ($entry =~ /^default_enrollment_(start|end)_date$/) {
1183: $newvalues{$entry}=&Apache::lonhtmlcommon::get_date_from_form($entry);
1184: } elsif ($entry eq 'rolenames') {
1185: my %adv_roles =
1186: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1.9 raeburn 1187: my @stds;
1188: if ($crstype eq 'Community') {
1189: @stds = ('co');
1190: } else {
1191: @stds = ('cc');
1192: }
1193: push(@stds,('in','ta','ep','ad','st'));
1.3 raeburn 1194: my (@replacements,@regulars);
1195: foreach my $role (@stds) {
1196: if ($values->{$role.'.plaintext'} ne '') {
1.9 raeburn 1197: push(@replacements,$role);
1.3 raeburn 1198: } else {
1199: push(@regulars,$role);
1200: }
1.9 raeburn 1201: }
1.3 raeburn 1202: foreach my $stdrole (@stds) {
1203: my $ext_entry = $entry.'_'.$stdrole;
1204: my $stdname = &Apache::lonnet::plaintext($stdrole,$crstype,
1205: $env{'request.course.id'},1);
1206: if ($env{'form.'.$ext_entry} eq $stdname) {
1207: $newvalues{$ext_entry} = '';
1208: } else {
1209: $newvalues{$ext_entry} = $env{'form.'.$ext_entry};
1210: }
1211: if ($newvalues{$ext_entry} ne $values->{$stdrole.'.plaintext'}) {
1212: my $dupname = 0;
1213: if ($newvalues{$ext_entry} ne '') {
1214: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@replacements)) {
1215: $dupname = 1;
1216: push(@{$disallowed->{'rolenames'}{'replacements'}},$newvalues{$ext_entry});
1217: }
1218: if (!$dupname) {
1219: if (grep(/^\Q$newvalues{$ext_entry}\E$/,@regulars)) {
1220: $dupname = 1;
1221: push(@{$disallowed->{rolenames}{'regulars'}},$newvalues{$ext_entry});
1222: }
1223: }
1224: if (!$dupname) {
1225: foreach my $role (keys(%adv_roles)) {
1226: if ($role =~ m{^cr/$match_domain/$match_name/\Q$newvalues{$ext_entry}\E$}) {
1227: $dupname = 1;
1228: push(@{$disallowed->{rolenames}{'customrole'}},$newvalues{$ext_entry});
1229: last;
1230: }
1231: }
1232: }
1233: }
1234: if (!$dupname) {
1235: $changes->{$ext_entry} = $newvalues{$ext_entry};
1236: }
1237: }
1238: }
1.77 raeburn 1239: } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') ||
1240: ($entry eq 'pac.roles.denied')) {
1.3 raeburn 1241: my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry);
1242: @denied = sort(@denied);
1243: my $deniedstr = '';
1244: if (@denied > 0) {
1245: $deniedstr = join(',',@denied);
1246: }
1247: $newvalues{$entry} = $deniedstr;
1.77 raeburn 1248: } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') ||
1249: ($entry eq 'pac.users.denied')) {
1.3 raeburn 1250: my $total = $env{'form.'.$entry.'_total'};
1251: my $userstr = '';
1252: my @denied;
1253: if ($total > 0) {
1254: my @deletes =
1255: &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1256: for (my $i=0; $i<$total; $i++) {
1257: unless (grep(/^$i$/,@deletes)) {
1258: $userstr .= $env{'form.'.$entry.'_user_'.$i}.',';
1259: push(@denied,$env{'form.'.$entry.'_user_'.$i});
1260: }
1261: }
1262: } else {
1263: $total = 0;
1264: }
1265: if ($env{'form.'.$entry.'_uname_'.$total} ne '') {
1266: my $uname = $env{'form.'.$entry.'_uname_'.$total};
1267: my $udom = $env{'form.'.$entry.'_udom_'.$total};
1268: if (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
1269: $userstr =~ s/,$//;
1270: $disallowed->{'discussion'}{$entry} = $uname.':'.$udom;
1271: } else {
1272: my $newuser .= $uname.':'.$udom;
1273: if (grep(/^\Q$newuser\E$/,@denied)) {
1274: $userstr =~ s/,$//;
1275: } else {
1276: $userstr .= $newuser;
1277: }
1278: }
1279: } else {
1280: $userstr =~ s/,$//;
1281: }
1282: $newvalues{$entry} = $userstr;
1283: } elsif ($entry eq 'allow_discussion_post_editing') {
1284: my @canedit = &Apache::loncommon::get_env_multiple('form.'.$entry);
1285: @canedit = sort(@canedit);
1286: foreach my $role (@canedit) {
1287: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$role);
1288: if ((grep(/^\s*$/,@secs)) || (@secs == 0)) {
1289: $newvalues{$entry} .= $role.',';
1290: } else {
1291: foreach my $sec (@secs) {
1292: $newvalues{$entry} .= $role.':'.$sec.',';
1293: }
1294: }
1295: }
1296: $newvalues{$entry} =~ s/,$//;
1.50 raeburn 1297: } elsif ($entry eq 'discussion_post_fonts') {
1298: my ($classorder,$classtitles) = &discussion_vote_classes();
1299: my $fontchange = 0;
1300: foreach my $class (@{$classorder}) {
1301: my $ext_entry = $entry.'_'.$class;
1302: my $size = $env{'form.'.$ext_entry.'_size'};
1303: my $unit = $env{'form.'.$ext_entry.'_unit'};
1304: my $weight = $env{'form.'.$ext_entry.'_weight'};
1305: my $style = $env{'form.'.$ext_entry.'_style'};
1306: my $other = $env{'form.'.$ext_entry.'_other'};
1307: $size =~ s/,//g;
1308: $unit =~ s/,//g;
1309: $weight =~ s/,//g;
1310: $style =~ s/,//g;
1311: $other =~ s/[^\w;:\s\-\%.]//g;
1312: $other =~ s/(^\s+|\s+$)//g;
1313: $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other));
1314: my $current = $values->{$ext_entry};
1315: if ($values->{$ext_entry} eq '') {
1316: $current = ',,,';
1317: }
1318: if ($newvalues{$ext_entry} ne $current) {
1319: $changes->{$ext_entry} = $newvalues{$ext_entry};
1320: $fontchange ++;
1321: }
1322: }
1323: if ($fontchange) {
1324: $changes->{$entry} = 1;
1325: }
1.3 raeburn 1326: } elsif ($entry eq 'nothideprivileged') {
1327: my @curr_nothide;
1328: my @new_nothide;
1329: if ($values->{$entry} ne '') {
1330: foreach my $user (split(/\s*\,\s*/,$values->{$entry})) {
1331: my $nothide;
1332: if ($user !~ /:/) {
1333: $nothide = join(':',split(/[\@]/,$user));
1334: } else {
1335: $nothide = $user;
1336: }
1337: if ((defined($nothide)) &&
1338: (!grep(/^\Q$nothide\E$/,@curr_nothide))) {
1339: push(@curr_nothide,$nothide);
1340: }
1341: }
1342: }
1343: foreach my $key (keys(%env)) {
1344: if ($key =~ /^form\.\Q$entry\E_($match_username:$match_domain)$/) {
1.7 raeburn 1345: if ($env{$key}) {
1.3 raeburn 1346: my $nothide = $1;
1347: if (!grep(/^\Q$nothide\E$/,@new_nothide)) {
1348: push(@new_nothide,$nothide);
1349: }
1350: }
1351: }
1352: }
1353: @new_nothide = sort(@new_nothide);
1354: my @differences =
1355: &Apache::loncommon::compare_arrays(\@curr_nothide,
1356: \@new_nothide);
1357: if (@differences > 0) {
1358: if (@new_nothide > 0) {
1359: $newvalues{$entry} = join(',',@new_nothide);
1360: } else {
1361: $newvalues{$entry} = '';
1362: }
1363: } else {
1364: $newvalues{$entry} = $values->{$entry};
1365: }
1366: } elsif ($entry eq 'print_header_format') {
1367: my $maxnum = $env{'form.printfmthdr_maxnum'};
1368: my @newhdr;
1369: if ($maxnum > 2) {
1370: for (my $i=0; $i<$maxnum-2; $i++) {
1371: if ($env{'form.printfmthdr_del_'.$i}) {
1372: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = '';
1373: } else {
1374: my $hdr;
1375: if ($env{'form.printfmthdr_sub_'.$i} =~ /^[nca]$/) {
1376: $hdr = '%';
1377: if ($env{'form.printfmthdr_limit_'.$i} =~ /^\d+$/) {
1378: $hdr .= $env{'form.printfmthdr_limit_'.$i};
1379: }
1380: $hdr .= $env{'form.printfmthdr_sub_'.$i};
1.29 raeburn 1381: } elsif ($env{'form.printfmthdr_text_'.$i} ne '') {
1382: $hdr = $env{'form.printfmthdr_text_'.$i};
1.3 raeburn 1383: }
1384: $newhdr[$env{'form.printfmthdr_pos_'.$i}] = $hdr;
1385: }
1386: }
1387: }
1388: my $newsub = $maxnum-2;
1389: if ($env{'form.printfmthdr_sub_'.$newsub} =~ /^[nca]$/) {
1390: my $hdr = '%';
1391: if ($env{'form.printfmthdr_limit_'.$newsub} =~ /^\d+$/) {
1392: $hdr .= $env{'form.printfmthdr_limit_'.$newsub};
1393: }
1394: $hdr .= $env{'form.printfmthdr_sub_'.$newsub};
1395: $newhdr[$env{'form.printfmthdr_pos_'.$newsub}] = $hdr;
1396: }
1397: my $newtext = $maxnum-1;
1398: $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext};
1399: $newvalues{$entry} = join('',@newhdr);
1.56 raeburn 1400: } elsif (($entry eq 'languages') ||
1401: ($entry eq 'checkforpriv')) {
1402: my $settings;
1.3 raeburn 1403: my $total = $env{'form.'.$entry.'_total'};
1404: if ($total) {
1405: my @deletes = &Apache::loncommon::get_env_multiple('form.'.$entry.'_delete');
1406: for (my $i=0; $i<$total; $i++) {
1407: unless (grep(/^$i$/,@deletes)) {
1.56 raeburn 1408: $settings .= $env{'form.'.$entry.'_'.$i}.',';
1.3 raeburn 1409: }
1410: }
1411: } else {
1412: $total = 0;
1413: }
1414: if ($env{'form.'.$entry.'_'.$total} ne '') {
1.56 raeburn 1415: my $new = $env{'form.'.$entry.'_'.$total};
1416: if ($entry eq 'languages') {
1417: my %langchoices = &get_lang_choices();
1418: if ($langchoices{$new}) {
1419: $settings .= $new;
1420: } else {
1421: $settings =~ s/,$//;
1422: $disallowed->{'localization'}{$entry} = $new;
1423: }
1.3 raeburn 1424: } else {
1.56 raeburn 1425: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
1426: if ($domains{$new}) {
1427: $settings .= $new;
1428: } else {
1429: $settings =~ s/,$//;
1430: $disallowed->{'classlists'}{$entry} = $new;
1431: }
1.3 raeburn 1432: }
1433: } else {
1.56 raeburn 1434: $settings =~ s/,$//;
1.3 raeburn 1435: }
1.56 raeburn 1436: $newvalues{$entry} = $settings;
1.87 raeburn 1437: } elsif ($action eq 'lti') {
1438: if ($entry eq 'lti.override') {
1439: $newvalues{$entry} = $env{'form.'.$entry};
1440: } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) {
1441: if ($env{'form.lti.override'}) {
1442: $newvalues{$entry} = $env{'form.'.$entry};
1443: } else {
1444: $newvalues{$entry} = '';
1445: }
1446: } elsif ($entry eq 'lti.lcmenu') {
1447: if (($env{'form.lti.override'}) &&
1448: (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) {
1449: my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu');
1450: my @newlcmenu;
1451: if (@lcmenu) {
1452: my @menuitems = ('fullname','coursetitle','role','logout','grades');
1453: foreach my $item (@menuitems) {
1454: next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'}));
1455: if (grep(/^\Q$item\E$/,@lcmenu)) {
1456: push(@newlcmenu,$item);
1457: }
1458: }
1459: }
1460: if (@newlcmenu) {
1461: $newvalues{$entry} = join(',',@newlcmenu);
1462: } else {
1463: $newvalues{$entry} = 'none';
1464: }
1465: } else {
1466: $newvalues{$entry} = '';
1467: }
1468: }
1.114 raeburn 1469: } elsif ($entry eq 'extresource') {
1470: if ($env{'form.'.$entry} =~ /^iframe|tab|window$/) {
1471: $newvalues{$entry} = $env{'form.'.$entry};
1472: if ($env{'form.'.$entry} ne 'iframe') {
1473: if ($env{'form.extwintabreuse'}) {
1474: $newvalues{$entry} .= ':1';
1475: } else {
1476: $newvalues{$entry} .= ':0';
1477: }
1478: if ($env{'form.'.$entry} eq 'window') {
1479: foreach my $dim ('width','height') {
1480: $env{'form.extreswin'.$dim} =~ s/^\s+|\s+$//g;
1481: if ($env{'form.extreswin'.$dim} =~ /^\d+$/) {
1482: $newvalues{$entry} .= ':'.$env{'form.extreswin'.$dim};
1483: } else {
1484: $newvalues{$entry} .= ':';
1485: }
1486: }
1487: }
1488: }
1489: }
1490: unless (($newvalues{$entry} eq 'iframe') && ($values->{$entry} eq '')) {
1491: if ($newvalues{$entry} ne $values->{$entry}) {
1492: $changes->{$entry} = $newvalues{$entry};
1493: }
1494: }
1.115 ! raeburn 1495: } elsif ($entry eq 'timezone') {
! 1496: if ($env{'form.'.$entry}) {
! 1497: $newvalues{$entry} = $env{'form.'.$entry};
! 1498: if ($newvalues{$entry} ne $values->{$entry}) {
! 1499: $changes->{$entry} = $newvalues{$entry};
! 1500: }
! 1501: if ($env{'form.tzover'}) {
! 1502: $newvalues{'tzover'} = $env{'form.tzover'};
! 1503: if ($newvalues{'tzover'} ne $values->{'tzover'}) {
! 1504: $changes->{'tzover'} = $newvalues{'tzover'};
! 1505: }
! 1506: } elsif ($values->{'tzover'}) {
! 1507: $changes->{'tzover'} = '';
! 1508: }
! 1509: } elsif ($values->{$entry}) {
! 1510: $changes->{$entry} = '';
! 1511: }
1.3 raeburn 1512: } else {
1513: $newvalues{$entry} = $env{'form.'.$entry};
1514: }
1.115 ! raeburn 1515: unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') ||
! 1516: ($entry eq 'extresource') || ($entry eq 'timezone')) {
1.25 raeburn 1517: if ($newvalues{$entry} ne $values->{$entry}) {
1518: $changes->{$entry} = $newvalues{$entry};
1519: }
1.3 raeburn 1520: }
1521: }
1522: }
1523: }
1524: }
1525: }
1.93 raeburn 1526: return $errors;
1527: }
1528:
1.102 raeburn 1529: sub process_linkprot {
1.108 raeburn 1530: my ($cdom,$cnum,$values,$changes,$context,$lastactref) = @_;
1.103 raeburn 1531: my ($home,$dest,$ltiauth,$privkey,$privnum,$cipher,$errors,%linkprot);
1.102 raeburn 1532: if (ref($values) eq 'HASH') {
1533: foreach my $id (keys(%{$values})) {
1534: if ($id =~ /^\d+$/) {
1535: unless (ref($values->{$id}) eq 'HASH') {
1536: $linkprot{$id} = '';
1537: }
1538: }
1539: }
1540: }
1.103 raeburn 1541: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1542: my @ids=&Apache::lonnet::current_machine_ids();
1543: if ($context eq 'domain') {
1544: $home = &Apache::lonnet::domain($cdom,'primary');
1545: } else {
1546: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1547: }
1548: if ((($context eq 'domain') && ($domdefs{'linkprotenc_dom'})) ||
1549: (($context eq 'course') && ($domdefs{'linkprotenc_crs'}))) {
1550: unless (($home eq 'no_host') || ($home eq '')) {
1551: if (grep(/^\Q$home\E$/,@ids)) {
1552: if (ref($domdefs{'privhosts'}) eq 'ARRAY') {
1553: if (grep(/^\Q$home\E$/,@{$domdefs{'privhosts'}})) {
1.104 raeburn 1554: my %privhash = &Apache::lonnet::restore_dom('lti','private',$cdom,$home,1);
1.103 raeburn 1555: $privkey = $privhash{'key'};
1556: $privnum = $privhash{'version'};
1557: if (($privnum) && ($privkey ne '')) {
1558: $cipher = Crypt::CBC->new({'key' => $privkey,
1559: 'cipher' => 'DES'});
1560: }
1561: }
1562: }
1563: }
1564: }
1565: }
1.102 raeburn 1566: if ($context eq 'domain') {
1567: $dest = '/adm/domainprefs';
1568: $ltiauth = 1;
1569: } else {
1570: $dest = '/adm/courseprefs';
1571: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
1572: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
1573: } else {
1574: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1575: $ltiauth = $domdefs{'crsltiauth'};
1576: }
1577: }
1578: my $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
1579: my (@items,%deletions,%itemids,%haschanges);
1580: if ($env{'form.linkprot_add'}) {
1581: my $name = $env{'form.linkprot_name_add'};
1582: $name =~ s/(`)/'/g;
1583: my ($newid,$error) = &get_linkprot_id($cdom,$cnum,$name,$context);
1584: if ($newid) {
1585: $itemids{'add'} = $newid;
1586: push(@items,'add');
1587: $haschanges{$newid} = 1;
1588: } else {
1589: $errors .= '<span class="LC_error">'.
1590: &mt('Failed to acquire unique ID for link protection').
1591: '</span>';
1592: }
1593: }
1594: if (ref($values) eq 'HASH') {
1595: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del');
1596: my $maxnum = $env{'form.linkprot_maxnum'};
1.111 raeburn 1597: for (my $i=0; $i<$maxnum; $i++) {
1.102 raeburn 1598: my $itemid = $env{'form.linkprot_id_'.$i};
1599: $itemid =~ s/\D+//g;
1600: if ($itemid) {
1601: if (ref($values->{$itemid}) eq 'HASH') {
1602: push(@items,$i);
1603: $itemids{$i} = $itemid;
1604: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
1605: $deletions{$itemid} = $values->{$itemid}->{'name'};
1606: }
1607: }
1608: }
1609: }
1610: }
1611: foreach my $idx (@items) {
1612: my $itemid = $itemids{$idx};
1613: next unless ($itemid);
1614: if (exists($deletions{$itemid})) {
1615: $linkprot{$itemid} = $deletions{$itemid};
1616: $haschanges{$itemid} = 1;
1617: next;
1618: }
1619: my %current;
1620: if (ref($values) eq 'HASH') {
1621: if (ref($values->{$itemid}) eq 'HASH') {
1622: foreach my $key (keys(%{$values->{$itemid}})) {
1623: $current{$key} = $values->{$itemid}->{$key};
1624: }
1625: }
1626: }
1627: foreach my $inner ('name','lifetime','version') {
1628: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1629: $env{$formitem} =~ s/(`)/'/g;
1630: if ($inner eq 'lifetime') {
1631: $env{$formitem} =~ s/[^\d.]//g;
1632: }
1633: unless ($idx eq 'add') {
1634: if ($current{$inner} ne $env{$formitem}) {
1635: $haschanges{$itemid} = 1;
1636: }
1637: }
1638: if ($env{$formitem} ne '') {
1639: $linkprot{$itemid}{$inner} = $env{$formitem};
1640: }
1641: }
1.112 raeburn 1642: my $urlitem = 'form.linkprot_returnurl_'.$idx;
1643: my $urlparamname = 'form.linkprot_urlparam_'.$idx;
1644: if ($env{$urlitem} == 1) {
1645: $env{$urlparamname} =~ s/(`)/'/g;
1646: } elsif (exists($env{$urlparamname})) {
1647: $env{$urlparamname} = '';
1648: }
1649: unless ($idx eq 'add') {
1650: if ((!$current{'returnurl'} && ($env{$urlparamname} ne '')) ||
1651: ($current{'returnurl'} && ($env{$urlparamname} eq ''))) {
1652: $haschanges{$itemid} = 1;
1653: }
1654: }
1655: if ($env{$urlparamname} ne '') {
1656: $linkprot{$itemid}{'returnurl'} = $env{$urlparamname};
1657: }
1.102 raeburn 1658: if ($ltiauth) {
1659: my $reqitem = 'form.linkprot_requser_'.$idx;
1660: $env{$reqitem} =~ s/(`)/'/g;
1661: unless ($idx eq 'add') {
1.104 raeburn 1662: if ((!$current{'requser'} && $env{$reqitem}) ||
1663: ($current{'requser'} && !$env{$reqitem})) {
1.102 raeburn 1664: $haschanges{$itemid} = 1;
1665: }
1666: }
1667: if ($env{$reqitem} == 1) {
1668: $linkprot{$itemid}{'requser'} = $env{$reqitem};
1669: foreach my $inner ('mapuser','notstudent') {
1670: my $formitem = 'form.linkprot_'.$inner.'_'.$idx;
1671: $env{$formitem} =~ s/(`)/'/g;
1672: if ($inner eq 'mapuser') {
1673: if ($env{$formitem} eq 'other') {
1674: my $mapuser = $env{'form.linkprot_customuser_'.$idx};
1675: $mapuser =~ s/(`)/'/g;
1676: $mapuser =~ s/^\s+|\s+$//g;
1677: if ($mapuser ne '') {
1678: $linkprot{$itemid}{$inner} = $mapuser;
1679: } else {
1680: delete($linkprot{$itemid}{'requser'});
1681: last;
1682: }
1683: } elsif ($env{$formitem} eq 'sourcedid') {
1684: $linkprot{$itemid}{$inner} = 'lis_person_sourcedid';
1685: } elsif ($env{$formitem} eq 'email') {
1686: $linkprot{$itemid}{$inner} = 'lis_person_contact_email_primary';
1687: }
1688: } else {
1689: $linkprot{$itemid}{$inner} = $env{$formitem};
1690: }
1691: unless ($idx eq 'add') {
1692: if ($current{$inner} ne $linkprot{$itemid}{$inner}) {
1693: $haschanges{$itemid} = 1;
1694: }
1695: }
1696: }
1697: }
1698: }
1699: unless ($switchserver) {
1700: my $keyitem = 'form.linkprot_key_'.$idx;
1701: $env{$keyitem} =~ s/(`)/'/g;
1702: unless ($idx eq 'add') {
1703: if ($current{'key'} ne $env{$keyitem}) {
1704: $haschanges{$itemid} = 1;
1705: }
1706: }
1707: if ($env{$keyitem} ne '') {
1708: $linkprot{$itemid}{'key'} = $env{$keyitem};
1709: }
1710: my $secretitem = 'form.linkprot_secret_'.$idx;
1711: $env{$secretitem} =~ s/(`)/'/g;
1712: if ($current{'usable'}) {
1713: if ($env{'form.linkprot_changesecret_'.$idx}) {
1714: if ($env{$secretitem} ne '') {
1.103 raeburn 1715: if ($privnum && $cipher) {
1716: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1717: $linkprot{$itemid}{'cipher'} = $privnum;
1718: } else {
1719: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1720: }
1.102 raeburn 1721: $haschanges{$itemid} = 1;
1722: }
1723: } else {
1724: $linkprot{$itemid}{'secret'} = $current{'secret'};
1.111 raeburn 1725: $linkprot{$itemid}{'cipher'} = $current{'cipher'};
1.102 raeburn 1726: }
1727: } elsif ($env{$secretitem} ne '') {
1.103 raeburn 1728: if ($privnum && $cipher) {
1729: $linkprot{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
1730: $linkprot{$itemid}{'cipher'} = $privnum;
1731: } else {
1732: $linkprot{$itemid}{'secret'} = $env{$secretitem};
1733: }
1.102 raeburn 1734: $haschanges{$itemid} = 1;
1735: }
1736: }
1737: }
1738: if (keys(%haschanges)) {
1739: foreach my $entry (keys(%haschanges)) {
1740: $changes->{$entry} = $linkprot{$entry};
1741: }
1.108 raeburn 1742: if (ref($lastactref) eq 'HASH') {
1.110 raeburn 1743: $lastactref->{'courselti'} = 1;
1.108 raeburn 1744: }
1.102 raeburn 1745: }
1746: return $errors;
1747: }
1748:
1749: sub get_linkprot_id {
1750: my ($cdom,$cnum,$name,$context) = @_;
1751: # get lock on lti db in course or linkprot db in domain
1.93 raeburn 1752: my $lockhash = {
1753: lock => $env{'user.name'}.
1754: ':'.$env{'user.domain'},
1755: };
1756: my $tries = 0;
1.102 raeburn 1757: my $gotlock;
1758: if ($context eq 'domain') {
1759: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1760: } else {
1761: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1762: }
1.93 raeburn 1763: my ($id,$error);
1764: while (($gotlock ne 'ok') && ($tries<10)) {
1765: $tries ++;
1766: sleep (0.1);
1.102 raeburn 1767: if ($context eq 'domain') {
1768: $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom);
1769: } else {
1770: $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum);
1771: }
1.93 raeburn 1772: }
1773: if ($gotlock eq 'ok') {
1.102 raeburn 1774: my %currids;
1775: if ($context eq 'domain') {
1776: %currids = &Apache::lonnet::dump_dom('linkprot',$cdom);
1777: } else {
1778: %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1);
1779: }
1.93 raeburn 1780: if ($currids{'lock'}) {
1781: delete($currids{'lock'});
1782: if (keys(%currids)) {
1783: my @curr = sort { $a <=> $b } keys(%currids);
1784: if ($curr[-1] =~ /^\d+$/) {
1785: $id = 1 + $curr[-1];
1786: } else {
1787: $id = 1;
1788: }
1789: } else {
1790: $id = 1;
1791: }
1792: if ($id) {
1.102 raeburn 1793: if ($context eq 'domain') {
1794: unless (&Apache::lonnet::newput_dom('linkprot',{ $id => $name },$cdom) eq 'ok') {
1795: $error = 'nostore';
1796: }
1797: } else {
1798: unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') {
1799: $error = 'nostore';
1800: }
1.93 raeburn 1801: }
1802: } else {
1803: $error = 'nonumber';
1804: }
1805: }
1.102 raeburn 1806: my $dellockoutcome;
1807: if ($context eq 'domain') {
1808: $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom);
1809: } else {
1810: $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum);
1811: }
1.93 raeburn 1812: } else {
1813: $error = 'nolock';
1814: }
1815: return ($id,$error);
1.3 raeburn 1816: }
1817:
1818: sub get_sec_str {
1819: my ($entry,$num) = @_;
1820: my @secs = &Apache::loncommon::get_env_multiple('form.'.$entry.'_sections_'.$num);
1821: my $secstr;
1822: if (grep(/^\s*$/,@secs)) {
1823: $secstr = '';
1824: } elsif (@secs > 0) {
1825: $secstr = join(';',@secs);
1826: }
1827: if ($secstr ne '') {
1828: return '('.$secstr.')';
1829: }
1830: return;
1831: }
1832:
1833: sub check_clone {
1834: my ($clonedom,$disallowed,$clonename) = @_;
1835: return if (ref($disallowed) ne 'HASH');
1836: if ($clonedom !~ /^$match_domain$/) {
1837: $disallowed->{'cloners'}{'format'} .= $clonedom.',';
1838: return;
1839: } elsif (!&Apache::lonnet::domain($clonedom)) {
1840: $disallowed->{'cloners'}{'domain'} .= $clonedom.',';
1841: return;
1842: }
1843: if ($clonename ne '') {
1844: if ($clonename !~ /^$match_username$/) {
1845: $disallowed->{'cloners'}{'format'} .= $clonename.':'.$clonedom.',';
1846: return;
1847: } else {
1848: if (&Apache::lonnet::homeserver($clonename,$clonedom) eq 'no_host') {
1849: $disallowed->{'cloners'}{'newuser'} .= $clonename.':'.$clonedom.',';
1850: return;
1851: }
1852: }
1853: }
1854: return 'ok';
1855: }
1856:
1857: sub store_changes {
1.9 raeburn 1858: my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_;
1.3 raeburn 1859: my ($chome,$output);
1.93 raeburn 1860: my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot);
1.3 raeburn 1861: if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) {
1.102 raeburn 1862: if (ref($values->{'linkprot'}) eq 'HASH') {
1863: %oldlinkprot = %{$values->{'linkprot'}};
1.93 raeburn 1864: }
1.102 raeburn 1865: delete($values->{'linkprot'});
1.3 raeburn 1866: %storehash = %{$values};
1867: } else {
1.9 raeburn 1868: if ($crstype eq 'Community') {
1869: $output = &mt('No changes made to community settings.');
1870: } else {
1871: $output = &mt('No changes made to course settings.');
1872: }
1873: return $output;
1.3 raeburn 1874: }
1.93 raeburn 1875: my ($numchanges,$skipstore);
1876: if (ref($changes) eq 'HASH') {
1877: $numchanges = scalar(keys(%{$changes}));
1.102 raeburn 1878: if (($numchanges == 1) && (exists($changes->{'linkprot'}))) {
1.93 raeburn 1879: $skipstore = 1;
1880: } elsif (!$numchanges) {
1881: if ($crstype eq 'Community') {
1882: $output = &mt('No changes made to community settings.');
1883: } else {
1884: $output = &mt('No changes made to course settings.');
1885: }
1886: return $output;
1887: }
1888: }
1.3 raeburn 1889: my %yesno = (
1890: hidefromcat => '1',
1891: problem_stream_switch => '1',
1892: suppress_tries => '1',
1893: disableexampointprint => '1',
1894: hideemptyrows => '1',
1895: suppress_embed_prompt => '1',
1896: );
1897: foreach my $item (@{$prefs_order}) {
1898: if (grep(/^\Q$item\E$/,@{$actions})) {
1899: $output .= '<h3>'.&mt($prefs->{$item}{'text'}).'</h3>';
1900: if (ref($changes->{$item}) eq 'HASH') {
1.99 raeburn 1901: if (keys(%{$changes->{$item}}) > 0) {
1.22 wenzelju 1902: $output .= &mt('Changes made:').'<ul style="list-style:none;">';
1.3 raeburn 1903: if ($item eq 'other') {
1904: foreach my $key (sort(keys(%{$changes->{$item}}))) {
1905: $storehash{$key} = $changes->{$item}{$key};
1906: if ($changes->{$item}{$key} eq '') {
1907: push(@delkeys,$key);
1.22 wenzelju 1908: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'.$key.'</i>')).'</li>';
1.3 raeburn 1909: } else {
1.22 wenzelju 1910: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$key.'</i>',
1911: "'$storehash{$key}'")).'</li>';
1.3 raeburn 1912: }
1913: }
1.102 raeburn 1914: } elsif ($item eq 'linkprot') {
1915: $output .= &store_linkprot($cdom,$cnum,'course',$changes->{$item},\%oldlinkprot);
1.3 raeburn 1916: } else {
1917: if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') {
1918: my @settings = @{$prefs->{$item}->{'ordered'}};
1919: if ($item eq 'feedback') {
1920: push(@settings,(map { $_.'.text'; } @settings));
1921: }
1922: foreach my $key (@settings) {
1923: if ($key eq 'rolenames') {
1924: my $displayname = $prefs->{$item}->{'itemtext'}{$key};
1925: my $msg;
1.9 raeburn 1926: my @roles;
1927: if ($crstype eq 'Community') {
1928: @roles = ('co');
1929: } else {
1930: @roles = ('cc');
1931: }
1932: push(@roles,('in','ta','ep','ad','st'));
1933: foreach my $role (@roles) {
1.3 raeburn 1934: next if (!exists($changes->{$item}{$key.'_'.$role}));
1935: my $stdname = &Apache::lonnet::plaintext($role,$crstype,undef,1);
1936: my $newname = $changes->{$item}{$key.'_'.$role};
1937: $storehash{$role.'.plaintext'} = $newname;
1938: if ($newname eq '') {
1939: $newname = $stdname;
1940: }
1941: $msg .= '<li>'.&mt('[_1] set to [_2]','<i>'.$stdname.'</i>',
1942: "'<b>".$newname."</b>'").'</li>';
1943: }
1944: if ($msg ne '') {
1.22 wenzelju 1945: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt($displayname)).'<ul class="LC_success">'.$msg.'</ul></li>';
1.3 raeburn 1946: }
1.115 ! raeburn 1947: } elsif ($key eq 'timezone') {
! 1948: next unless ((exists($changes->{$item}{$key})) || (exists($changes->{$item}{'tzover'})));
! 1949: my ($displayname,$text);
! 1950: $text = $prefs->{$item}->{'itemtext'}{$key};
! 1951: my $displayval;
! 1952: if (exists($changes->{$item}{$key})) {
! 1953: $displayname = &mt($text);
! 1954: $storehash{$key} = $changes->{$item}{$key};
! 1955: if ($changes->{$item}{$key} ne '') {
! 1956: $displayval = '<b>'.$changes->{$item}{$key}.'</b>';
! 1957: } else {
! 1958: push(@delkeys,$key);
! 1959: if (exists($values->{'tzover'})) {
! 1960: push(@delkeys,'tzover');
! 1961: }
! 1962: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
! 1963: '<i>'.$displayname.'</i>')).'</li>';
! 1964: }
! 1965: }
! 1966: unless (grep(/^\Q$key\E$/,@delkeys)) {
! 1967: if (exists($changes->{$item}{'tzover'})) {
! 1968: $storehash{'tzover'} = $changes->{$item}{'tzover'};
! 1969: my $tzovertext;
! 1970: if ($changes->{$item}{'tzover'} ne '') {
! 1971: $tzovertext = &mt('Course Time Zone overrides individual user preference');
! 1972: } else {
! 1973: push(@delkeys,'tzover');
! 1974: $tzovertext = &mt('Course Time Zone does not override individual user preference');
! 1975: }
! 1976: if ($displayval eq '') {
! 1977: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success($tzovertext).'</li>';
! 1978: } else {
! 1979: $displayval .= '<br />'.(' 'x5).$tzovertext;
! 1980: }
! 1981: }
! 1982: if ($displayval ne '') {
! 1983: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
! 1984: '<i>'.$displayname.'</i>',$displayval)).'</li>';
! 1985: }
! 1986: }
1.3 raeburn 1987: } else {
1988: next if (!exists($changes->{$item}{$key}));
1989: my ($displayname,$text);
1990: $text = $prefs->{$item}->{'itemtext'}{$key};
1.25 raeburn 1991: my $displayval;
1.114 raeburn 1992: unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) {
1.25 raeburn 1993: $displayval = $changes->{$item}{$key};
1994: }
1.3 raeburn 1995: if ($item eq 'feedback') {
1996: if ($key =~ /^(question|policy|comment)(\.email)\.text$/) {
1997: $text = $prefs->{$item}->{'itemtext'}{$1.$2};
1998: $displayname = &mt('Custom text for '.$text.' questions');
1999: } else {
2000: $displayname = &mt('Recipients of '.$text.' questions');
2001: }
2002: } elsif ($item eq 'discussion') {
2003: if ($key =~ /^p(lc|ch)\.roles\.denied/) {
2004: $displayname = &mt("$text (role-based)");
2005: if ($displayval ne '') {
2006: my @roles = split(',',$displayval);
2007: @roles = map { &Apache::lonnet::plaintext($_); } @roles;
2008: $displayval = join(', ',@roles);
2009: }
2010: } elsif ($key =~ /^p(lc|ch)\.users\.denied/) {
2011: $displayname = &mt("$text (specific user(s))");
2012: } else {
2013: if ($key eq 'allow_discussion_post_editing') {
2014: if ($displayval ne '') {
2015: my @roles = split(',',$displayval);
2016: my @longroles;
2017: foreach my $role (@roles) {
2018: my ($trole,$sec) = split(':',$role);
2019: my $rolename =
2020: &Apache::lonnet::plaintext($trole);
2021: if ($sec ne '') {
2022: $rolename .= ':'.$sec;
2023: }
2024: push(@longroles,$rolename);
2025: }
2026: $displayval = join(', ',@longroles);
2027: }
1.50 raeburn 2028: } elsif ($key eq 'discussion_post_fonts') {
2029: my ($classorder,$classtitles)=&discussion_vote_classes();
2030: my ($styleorder,$styleitems)=&discussion_vote_styles();
2031: my $count = 1;
2032: my $total = scalar(keys(%{$changes->{$item}}));
2033: foreach my $class (@{$classorder}) {
2034: $count ++;
2035: next unless ($changes->{$item}{$key.'_'.$class});
2036: my @vals = split(/,/,$changes->{$item}{$key.'_'.$class});
2037: my $showval = '';
2038: for (my $i=0; $i<@{$styleorder}; $i++) {
2039: if ($vals[$i] ne '') {
2040: $showval .= 'font-'.$styleorder->[$i].': '.$vals[$i].'; ';
2041: }
2042: }
2043: if ($vals[3] ne '') {
2044: $showval .= $vals[3];
2045: }
2046: if ($showval ne '') {
2047: $displayval .= $classtitles->{$class}.':{ '.
2048: $showval.'}';
2049: $storehash{$key.'_'.$class} = $changes->{$item}{$key.'_'.$class};
2050: } else {
2051: $displayval .= $classtitles->{$class}.': '.&mt('None');
2052: push(@delkeys,$key.'_'.$class);
2053: }
2054: unless ($count == $total) {
2055: $displayval .= (' 'x2);
2056: }
2057: }
1.3 raeburn 2058: }
2059: $displayname = &mt($text);
2060: }
2061: } elsif ($item eq 'spreadsheet') {
2062: if ($key =~ /^spreadsheet_default_(studentcalc|assesscalc)$/x) {
2063: my $sheettype = $1;
2064: if ($sheettype eq 'studentcalc') {
2065: &Apache::lonnet::expirespread('','','studentcalc');
2066: } else {
2067: &Apache::lonnet::expirespread('','','assesscalc');
2068: &Apache::lonnet::expirespread('','','studentcalc');
2069: }
2070: }
2071: $displayname = &mt($text);
1.87 raeburn 2072: } elsif ($item eq 'lti') {
2073: if ($key eq 'lti.lcmenu') {
2074: if ($changes->{$item}{$key} eq 'none') {
2075: $displayval = &mt('None of the configurable menu items displayed');
2076: } else {
2077: my %ltititles = <imenu_titles();
2078: $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key}));
2079: }
2080: } else {
2081: if ($changes->{$item}{$key} eq '1') {
2082: $displayval = &mt('Yes');
2083: } elsif ($changes->{$item}{$key} eq '') {
2084: $displayval = &mt('No');
2085: }
2086: }
2087: $displayname = &mt($text);
1.91 raeburn 2088: } elsif ($item eq 'menuitems') {
2089: unless ($changes->{$item}{$key} eq '') {
2090: if ($key eq 'menudefault') {
2091: $displayname = &mt('Default collection of menu items');
2092: $displayval = &mt('Collection: [_1]',
2093: $changes->{$item}{$key});
2094: } elsif ($key eq 'menucollections') {
2095: $displayval = &menucollections_display($changes->{$item}{$key});
2096: }
2097: }
1.3 raeburn 2098: } else {
2099: $displayname = &mt($text);
2100: }
2101: if (defined($yesno{$key})) {
1.14 raeburn 2102: $displayval = &mt('No');
1.3 raeburn 2103: if ($changes->{$item}{$key} eq 'yes') {
1.14 raeburn 2104: $displayval = &mt('Yes');
1.3 raeburn 2105: }
2106: } elsif (($key =~ /^default_enrollment_(start|end)_date$/) && ($displayval)) {
2107: $displayval = &Apache::lonlocal::locallocaltime($displayval);
2108: } elsif ($key eq 'categories') {
2109: $displayval = $env{'form.categories_display'};
1.95 raeburn 2110: } elsif (($key eq 'canuse_pdfforms') || ($key eq 'usejsme') ||
2111: ($key eq 'uselcmath') || ($key eq 'inline_chem')) {
1.14 raeburn 2112: if ($changes->{$item}{$key} eq '1') {
2113: $displayval = &mt('Yes');
2114: } elsif ($changes->{$item}{$key} eq '0') {
2115: $displayval = &mt('No');
2116: }
1.114 raeburn 2117: } elsif ($key eq 'extresource') {
2118: if ($changes->{$item}{$key} eq 'iframe') {
2119: $displayval = &mt('In iframe');
2120: } else {
2121: my ($selected,$reuse,$width,$height) = split(/:/,$changes->{$item}{$key});
2122: if ($selected eq 'tab') {
2123: if ($reuse) {
2124: $displayval = &mt('[_1]In tab[_2],[_3] and tab re-used for different external resources in course',
2125: "'<b>","</b>'",'<br />');
2126: } else {
2127: $displayval = &mt('[_1]In tab[_2],[_3] with new tab for each external resource in course',
2128: "'<b>","</b>'",'<br />');
2129: }
2130: } elsif ($selected eq 'window') {
2131: if ($reuse) {
2132: $displayval = &mt('[_1]In pop-up window[_2],[_3] and window re-used for different external resources in course',
2133: "'<b>","</b>'",'<br />');
2134: } else {
2135: $displayval = &mt('[_1]In pop-up window[_2],[_3] with new window for each external resource in course',
2136: "'<b>","</b>'",'<br />');
2137: }
2138: if (($width ne '') || ($height ne '')) {
2139: if ($width ne '') {
2140: $displayval .= '<br />'.&mt('Window width: [_1]px',$width);
2141: }
2142: if ($height ne '') {
2143: $displayval .= '<br />'.&mt('Window height: [_1]px',$height);
2144: }
2145: }
2146: }
2147: }
1.14 raeburn 2148: }
1.25 raeburn 2149: if ($key eq 'co-owners') {
2150: if (ref($changes->{$item}{$key}) eq 'HASH') {
2151: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2152: foreach my $type ('co-owners','pendingco-owners') {
2153: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2154: if ($type eq 'pendingco-owners') {
2155: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2156: $displayname = &mt('Invited as co-owners, pending acceptance');
2157: }
2158: }
2159: if ($changes->{$item}{$key}{$type} eq '') {
2160: push(@delkeys,'internal.'.$type);
2161: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2162: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2163: '<i>'.$displayname.'</i>')).'</li>';
2164: }
2165: } elsif (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
2166: $displayval = join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } split(',',$changes->{$item}{$key}{$type}));
2167: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2168: '<i>'.$displayname.'</i>',
2169: "'<b>$displayval</b>'")).'</li>';
2170: }
2171: }
2172: }
2173: unless (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
1.90 raeburn 2174: if ($env{'form.pending_coowner'} eq 'accept') {
1.25 raeburn 2175: $displayval = &mt('on');
1.90 raeburn 2176: } elsif ($env{'form.pending_coowner'} eq 'decline') {
1.25 raeburn 2177: $displayval = '';
2178: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Invitation to be co-owner declined')).'</li>';
1.90 raeburn 2179: } elsif ($env{'form.remove_coowner'}) {
1.25 raeburn 2180: $displayval = &mt('off');
2181: }
2182: if ($displayval) {
2183: $displayname = &mt('Your co-ownership status');
2184: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2185: '<i>'.$displayname.'</i>',
2186: "'<b>$displayval</b>'")).'</li>';
2187: }
2188: }
2189: }
2190: } elsif ($changes->{$item}{$key} eq '') {
1.3 raeburn 2191: push(@delkeys,$key);
1.87 raeburn 2192: if ($item eq 'lti') {
2193: if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) {
2194: if (($key eq 'lti.lcmenu') &&
2195: ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) {
2196: $output .= '<li>'.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'</li>';
2197: } else {
2198: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
2199: '<i>'.$displayname.'</i>',
2200: "'<b>$displayval</b>'")).'</li>';
2201: }
2202: } elsif (!exists($changes->{$item}{'lti.override'})) {
2203: $output .= '<li>'.&mt('LTI settings only saved if Override is set to "Yes"').'</li>';
2204: }
1.91 raeburn 2205: } elsif ($item eq 'menuitems') {
2206: if ($key eq 'menudefault') {
2207: $output .= '<li>'.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'</li>';
2208: } elsif ($key eq 'menucollections') {
2209: $output .= '<li>'.&mt('Specific collections of menus no longer available').'</li>';
2210: }
1.87 raeburn 2211: } else {
2212: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',
2213: '<i>'.$displayname.'</i>')).'</li>';
2214: }
1.91 raeburn 2215: } elsif ($key eq 'menucollections') {
2216: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'<br />'.
2217: $displayval.'</li>';
1.3 raeburn 2218: } else {
1.114 raeburn 2219: unless (($key eq 'extresource') && ($changes->{$item}{$key} ne 'iframe')) {
2220: $displayval = "'<b>$displayval</b>'";
2221: }
1.22 wenzelju 2222: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',
1.114 raeburn 2223: '<i>'.$displayname.'</i>',$displayval));
1.3 raeburn 2224: if ($key eq 'url') {
2225: my $bkuptime=time;
2226: $output .= (' 'x2).&mt('(Previous URL backed up)').': '.
1.32 raeburn 2227: $storehash{'top level map backup '.$bkuptime} = $values->{$key};
1.3 raeburn 2228: }
2229: $output .= '</li>';
2230: }
1.25 raeburn 2231: if ($key eq 'co-owners') {
2232: if (ref($changes->{$item}{$key}) eq 'HASH') {
2233: if (ref($changes->{$item}{$key}{'changed'}) eq 'ARRAY') {
2234: foreach my $type ('co-owners','pendingco-owners') {
2235: next unless (grep(/^\Q$type\E$/,@{$changes->{$item}{$key}{'changed'}}));
2236: $storehash{'internal.'.$type} = $changes->{$item}{$key}{$type};
2237: }
2238: }
2239: }
2240: } else {
1.50 raeburn 2241: unless ($key eq 'discussion_post_fonts') {
2242: $storehash{$key} = $changes->{$item}{$key};
2243: }
1.25 raeburn 2244: }
1.3 raeburn 2245: }
1.23 raeburn 2246: if ($key eq 'cloners') {
2247: # Get existing cloners
2248: my %clonenames =
2249: &Apache::lonnet::dump('environment',$cdom,$cnum,'cloners');
2250: if ($clonenames{'cloners'} =~ /,/) {
2251: @oldcloner = split(/\s*\,\s*/,$clonenames{'cloners'});
2252: } else {
2253: $oldcloner[0] = $clonenames{'cloners'};
2254: }
2255: }
1.3 raeburn 2256: if (($key eq 'description') || ($key eq 'cloners') ||
1.25 raeburn 2257: ($key eq 'hidefromcat') || ($key eq 'categories') ||
1.87 raeburn 2258: ($key eq 'co-owners') || ($key eq 'lti.override') ||
2259: ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') ||
2260: ($key eq 'lti.lcmenu')) {
1.3 raeburn 2261: push(@need_env_update,$key);
2262: }
2263: }
2264: }
2265: }
2266: $output .= '</ul>';
2267: } else {
1.9 raeburn 2268: if ($crstype eq 'Community') {
1.46 raeburn 2269: $output .= &mt('No changes made to community settings.');
1.9 raeburn 2270: } else {
1.46 raeburn 2271: $output .= &mt('No changes made to course settings.');
1.9 raeburn 2272: }
1.3 raeburn 2273: }
2274: }
2275: }
2276: }
1.93 raeburn 2277: if ($skipstore) {
2278: return $output;
2279: }
1.3 raeburn 2280: if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') {
1.23 raeburn 2281: if (ref($changes) eq 'HASH') {
2282: if (ref($changes->{'courseinfo'}) eq 'HASH') {
2283: if (exists($changes->{'courseinfo'}{'cloners'})) {
2284: &change_clone($cdom,$cnum,$changes->{'courseinfo'}{'cloners'},
2285: \@oldcloner);
2286: }
2287: }
2288: }
1.3 raeburn 2289: if (@delkeys) {
2290: if (&Apache::lonnet::del('environment',\@delkeys,$cdom,$cnum) ne 'ok') {
1.9 raeburn 2291: $output .= '<br /><span class="LC_error">';
2292: if ($crstype eq 'Community') {
2293: $output .= &mt('An error occurred when removing community settings which are no longer in use.');
2294: } else {
2295: $output .= &mt('An error occurred when removing course settings which are no longer in use.');
2296: }
2297: $output .= '</span>';
1.14 raeburn 2298: } else {
2299: foreach my $key (@delkeys) {
2300: &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.'.$key);
2301: }
1.3 raeburn 2302: }
2303: }
2304: if (@need_env_update) {
2305: $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2306: &update_env($cnum,$cdom,$chome,\@need_env_update,\%storehash);
2307: }
2308: &Apache::lonnet::coursedescription($env{'request.course.id'},
2309: {'freshen_cache' => 1});
2310: } else {
1.9 raeburn 2311: $output = '<span class="LC_error">';
2312: if ($crstype eq 'Community') {
2313: $output .= &mt('An error occurred when saving changes to community settings, which remain unchanged.');
2314: } else {
2315: $output .= &mt('An error occurred when saving changes to course settings, which remain unchanged.');
2316: }
2317: $output .= '</span>';
1.3 raeburn 2318: }
2319: return $output;
2320: }
2321:
1.102 raeburn 2322: sub store_linkprot {
2323: my ($cdom,$cnum,$context,$changes,$oldlinkprot) = @_;
1.103 raeburn 2324: my ($ltiauth,$home,$lti_save_error,$output,$error,%ltienc,@deletions);
1.102 raeburn 2325: if ($context eq 'domain') {
2326: $ltiauth = 1;
1.103 raeburn 2327: $home = &Apache::lonnet::domain($cdom,'primary');
1.102 raeburn 2328: } else {
1.103 raeburn 2329: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1.102 raeburn 2330: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
2331: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
2332: } else {
2333: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
2334: $ltiauth = $domdefs{'crsltiauth'};
2335: }
2336: }
2337: if (ref($changes) eq 'HASH') {
2338: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
2339: if (ref($changes->{$id}) eq 'HASH') {
2340: if (exists($changes->{$id}->{'key'})) {
2341: $ltienc{$id}{'key'} = $changes->{$id}->{'key'};
2342: delete($changes->{$id}->{'key'});
2343: }
2344: if (exists($changes->{$id}->{'secret'})) {
2345: $ltienc{$id}{'secret'} = $changes->{$id}->{'secret'};
2346: delete($changes->{$id}->{'secret'});
2347: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
2348: if (exists($oldlinkprot->{$id}{'usable'})) {
2349: $changes->{$id}->{'usable'} = 1;
2350: }
1.109 raeburn 2351: if (exists($oldlinkprot->{$id}{'cipher'})) {
2352: $changes->{$id}->{'cipher'} = $oldlinkprot->{$id}{'cipher'};
2353: }
1.102 raeburn 2354: }
2355: }
2356: }
2357: }
2358: my @ids=&Apache::lonnet::current_machine_ids();
2359: if (keys(%ltienc) > 0) {
2360: if ($context eq 'domain') {
2361: foreach my $id (keys(%ltienc)) {
2362: if (exists($ltienc{$id}{'secret'})) {
2363: $changes->{$id}->{'usable'} = 1;
2364: }
2365: }
2366: } else {
1.103 raeburn 2367: unless (($home eq 'no_host') || ($home eq '')) {
1.102 raeburn 2368: my $allowed;
2369: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2370: if ($allowed) {
2371: if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') {
2372: foreach my $id (keys(%ltienc)) {
2373: if (exists($ltienc{$id}{'secret'})) {
2374: $changes->{$id}->{'usable'} = 1;
2375: }
2376: }
2377: } else {
2378: $lti_save_error = 1;
2379: }
2380: }
2381: }
2382: }
2383: }
2384: unless ($lti_save_error) {
2385: if ($context eq 'course') {
2386: if (&Apache::lonnet::put('lti',$changes,$cdom,$cnum,1) eq 'ok') {
2387: my $hashid=$cdom.'_'.$cnum;
2388: &Apache::lonnet::devalidate_cache_new('courselti',$hashid);
1.103 raeburn 2389: unless (($home eq 'no_host') || ($home eq '')) {
2390: if (grep(/^\Q$home\E$/,@ids)) {
1.102 raeburn 2391: &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid);
2392: }
2393: }
2394: } else {
2395: $lti_save_error = 1;
2396: }
2397: }
2398: unless ($lti_save_error) {
2399: foreach my $id (sort { $a <=> $b } %{$changes}) {
2400: if (ref($changes->{$id}) eq 'HASH') {
2401: my %values = %{$changes->{$id}};
2402: my %desc = &linkprot_names();
2403: my $display;
1.112 raeburn 2404: foreach my $title ('name','lifetime','version','key','secret','returnurl') {
1.102 raeburn 2405: if (($title eq 'key') || ($title eq 'secret')) {
2406: if (ref($ltienc{$id}) eq 'HASH') {
2407: if (exists($ltienc{$id}{$title})) {
2408: if ($title eq 'secret') {
2409: my $length = length($ltienc{$id}{$title});
1.103 raeburn 2410: $display .= $desc{$title}.': ['.&mt('not shown').'], ';
1.102 raeburn 2411: } else {
2412: $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', ';
2413: }
2414: }
2415: }
2416: } elsif ($title eq 'version') {
2417: if ($values{$title} eq 'LTI-1p0') {
2418: $display .= $desc{$title}.': 1.1, ';
2419: }
1.112 raeburn 2420: } elsif ($title eq 'returnurl') {
2421: if ($values{$title}) {
2422: $display .= &mt('Return URL parameter').': '.$values{$title}.', ';
2423: }
1.102 raeburn 2424: } else {
2425: $display .= $desc{$title}.': '.$values{$title}.', ';
2426: }
2427: }
2428: if ($ltiauth) {
2429: if (($values{'requser'}) && ($values{'mapuser'} ne '')) {
2430: if ($values{'mapuser'} eq 'lis_person_contact_email_primary') {
2431: $display .= &mt('Source of username: Email address [_1]',
2432: '(lis_person_contact_email_primary)').', ';
2433: } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') {
2434: $display .= &mt('Source of username: User ID [_1]',
2435: '(lis_person_sourcedid)').', ';
2436: } else {
2437: $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', ';
2438: }
2439: if ($values{'notstudent'} eq 'auth') {
2440: $display .= &mt('Display LON-CAPA login page if no match').', ';
2441: } elsif ($values{'notstudent'} eq 'reject') {
2442: $display .= &mt('Discontinue launch if no match').', ';
2443: }
2444: }
2445: }
2446: $display =~ s/, $//;
2447: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.$id.'</i>',
2448: "'$display'")).'</li>';
2449: } elsif (ref($oldlinkprot->{$id}) eq 'HASH') {
2450: my $oldname = $oldlinkprot->{$id}{'name'};
2451: $output .= '<li>'.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]','<i>'."$id ($oldname)".'</i>')).'</li>';
2452: }
2453: }
2454: } else {
2455: $lti_save_error = 1;
2456: }
2457: }
2458: unless ($lti_save_error) {
2459: foreach my $id (sort { $a <=> $b } keys(%{$changes})) {
2460: unless (ref($changes->{$id}) eq 'HASH') {
2461: push(@deletions,$id);
2462: }
2463: }
2464: if (@deletions) {
2465: if ($context eq 'course') {
2466: &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum);
2467: }
2468: }
2469: }
2470: if ($lti_save_error) {
2471: $output .= '<li>'.
2472: '<span class="LC_error">'.
2473: &mt('An error occurred when saving changes to link protection settings, which remain unchanged.').
2474: '</span>'.
2475: '</li>';
2476: }
2477: return $output;
2478: }
2479:
1.3 raeburn 2480: sub update_env {
2481: my ($cnum,$cdom,$chome,$need_env_update,$storehash) = @_;
2482: my $count = 0;
2483: if ((ref($need_env_update) eq 'ARRAY') && (ref($storehash) eq 'HASH')) {
2484: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
2485: if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') {
2486: foreach my $key (@{$need_env_update}) {
2487: if ($key eq 'description' && defined($storehash->{$key})) {
2488: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.description' => $storehash->{$key}});
2489: $crsinfo{$env{'request.course.id'}}{'description'} = $storehash->{$key};
2490: $count ++;
2491: } elsif (($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories')) {
2492: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
2493: $crsinfo{$env{'request.course.id'}}{$key} = $storehash->{$key};
2494: $count ++;
1.25 raeburn 2495: } elsif ($key eq 'co-owners') {
2496: if ($storehash->{'internal.co-owners'} ne '') {
2497: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.co-owners' => $storehash->{'internal.co-owners'}});
2498: }
2499: if ($storehash->{'internal.pendingco-owners'} ne '') {
2500: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.internal.pendingco-owners' => $storehash->{'internal.pendingco-owners'}});
2501: }
2502: my @coowners = split(',',$storehash->{'internal.'.$key});
2503: $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners;
2504: $count ++;
1.87 raeburn 2505: } elsif ($key =~ /^lti\./) {
2506: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}});
1.3 raeburn 2507: }
2508: }
2509: if ($count) {
2510: my $putresult = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
2511: }
2512: }
2513: }
2514: return;
2515: }
2516:
2517: sub display_disallowed {
1.9 raeburn 2518: my ($item,$disallowed,$prefs,$crstype) = @_;
1.3 raeburn 2519: my $output;
2520: if ((ref($disallowed) eq 'HASH') && (ref($prefs) eq 'HASH')) {
2521: if (keys(%{$disallowed})) {
2522: if ($item eq 'cloners') {
2523: my @fails;
2524: my %lt = &Apache::lonlocal::texthash (
2525: format => 'Invalid format',
2526: domain => 'Domain does not exist',
2527: newuser => 'LON-CAPA user(s) do(es) not exist.',
2528: );
2529: foreach my $error ('format','domain','newuser') {
2530: if (defined($disallowed->{$error})) {
2531: my $msg = '<b>'.$disallowed->{$error}.'</b>, '.&mt('reason').' - '.
2532: $lt{$error};
2533: if ($error eq 'newuser') {
1.9 raeburn 2534: $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 2535: }
2536: push(@fails,$msg);
2537: }
2538: }
2539: if (@fails) {
2540: $output .= '<span class="LC_warning">'.&mt('Unable to add to allowed cloners: ').
2541: '</span>'.join('; ',@fails).'.<br />';
2542: }
2543: } elsif ($item eq 'rolenames') {
2544: my %lt = &Apache::lonlocal::texthash (
2545: replacements => 'Name already used to replace a different standard role name',
2546: regulars => 'Name already used as a standard role name',
2547: customrole => 'Name already used as the name of a custom role',
2548: );
2549: my @fails;
2550: foreach my $error ('replacements','regulars','customrole') {
2551: if (ref($disallowed->{$error}) eq 'ARRAY') {
2552: push(@fails,'<b>'.join(', ',@{$disallowed->{$error}}).
2553: '</b>, '.&mt('reason').' - '.$lt{'error'});
2554: }
2555: }
2556: if (@fails) {
2557: $output .= '<span class="LC_warning">'.
2558: &mt('Unable to include amongst replacements for role names: ').
2559: '</span>'.join('; ',@fails).'.<br />';
2560: }
2561:
2562: } elsif (($item eq 'feedback') || ($item eq 'discussion') || ($item eq 'localization')) {
2563: $output .= '<span class="LC_warning">';
2564: if ($item eq 'feedback') {
1.9 raeburn 2565: if ($crstype eq 'Community') {
2566: $output .= &mt('Unable to include as a recipient of community feedback for:');
2567: } else {
2568: $output .= &mt('Unable to include as a recipient of course feedback for:');
2569: }
1.3 raeburn 2570: } elsif ($item eq 'discussion') {
2571: $output .= &mt('Unable to include in user-based access control for:');
2572: } elsif ($item eq 'localization') {
1.9 raeburn 2573: if ($crstype eq 'Community') {
2574: $output .= &mt('Unable to include in community localization:');
2575: } else {
2576: $output .= &mt('Unable to include in course localization:');
2577: }
1.3 raeburn 2578: }
2579: $output .= '</span><ul>';
2580: foreach my $key (sort(keys(%{$disallowed}))) {
2581: my $itemtext = $prefs->{$item}{'itemtext'}{$key};
2582: $output .= '<li><i>'.$itemtext.'</i> - ';
2583: if ($item eq 'localization') {
2584: $output .= &mt('reason - unsupported language: [_1]',
2585: '<b>'.$disallowed->{$key}.'</b>');
2586: } else {
2587: $output .= &mt('reason - invalid user: [_1]',
2588: '<b>'.$disallowed->{$key}.'</b>').'</li>';
2589: }
2590: }
2591: $output .= '</ul><br />';
2592: }
2593: }
1.1 raeburn 2594: }
1.3 raeburn 2595: return $output;
1.1 raeburn 2596: }
2597:
2598: sub get_course {
2599: my ($courseid) = @_;
2600: if (!defined($courseid)) {
2601: $courseid = $env{'request.course.id'};
2602: }
2603: my $cdom=$env{'course.'.$courseid.'.domain'};
2604: my $cnum=$env{'course.'.$courseid.'.num'};
1.66 raeburn 2605: my $chome=$env{'course.'.$courseid.'.home'};
2606: return ($cnum,$cdom,$chome);
1.1 raeburn 2607: }
2608:
2609: sub get_jscript {
1.91 raeburn 2610: my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_;
1.12 raeburn 2611: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.115 ! raeburn 2612: my ($jscript,$categorize_js,$loncaparev_js,$instcode_js,$extresource_js,$localization_js);
1.1 raeburn 2613: my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript();
2614: my $browse_js = &Apache::loncommon::browser_and_searcher_javascript('parmset');
1.3 raeburn 2615: my $cloners_js = &cloners_javascript($phase);
1.71 raeburn 2616: my @code_order;
2617: if ($crstype ne 'Community') {
2618: if (ref($settings) eq 'HASH') {
2619: my %codedefaults;
2620: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
2621: \@code_order);
2622: if (@code_order > 0) {
2623: if ($phase eq 'display') {
2624: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
2625: if (grep(/^courseinfo$/,@actions)) {
2626: if ($settings->{'cloners'} ne '') {
2627: unless ($settings->{'cloners'} eq '*') {
2628: my @cloners = split(/,/,$settings->{'cloners'});
2629: my @standardnames = &Apache::loncommon::get_standard_codeitems();
2630: my %local_to_standard;
2631: for (my $i=0; $i<@code_order; $i++) {
2632: $local_to_standard{$code_order[$i]} = $standardnames[$i];
2633: }
2634: foreach my $cloner (@cloners) {
2635: if (($cloner !~ /^\Q*:\E$match_domain$/) &&
2636: ($cloner !~ /^$match_username\:$match_domain$/)) {
2637: foreach my $item (split(/\&/,$cloner)) {
2638: my ($key,$val) = split(/\=/,$item);
2639: $val = &unescape($val);
2640: foreach my $code (@code_order) {
2641: if ($key eq $local_to_standard{$code}) {
2642: $env{'form.'.$key} = $val;
2643: }
2644: }
2645: }
2646: }
2647: }
2648: }
2649: }
2650: }
2651: }
2652: my @codetitles;
2653: (undef,$instcode_js) =
2654: &Apache::courseclassifier::instcode_selectors($cdom,'display',undef,
2655: \@codetitles);
2656: $instcode_js .= <<ENDSCRIPT;
2657: function toggleCloners(callerradio) {
2658: if (document.getElementById('LC_cloners_instcode')) {
2659: if (callerradio.value == 1) {
2660: document.getElementById('LC_cloners_instcode').style.display = "block";
2661: } else {
2662: uncheckOfficialLists();
2663: document.getElementById('LC_cloners_instcode').style.display = "none";
2664: }
2665: }
2666: }
2667:
2668: if (!document.getElementsByClassName) {
2669: function getElementsByClassName(node, classname) {
2670: var a = [];
2671: var re = new RegExp('(^| )'+classname+'( |$)');
2672: var els = node.getElementsByTagName("*");
2673: for(var i=0,j=els.length; i<j; i++)
2674: if(re.test(els[i].className))a.push(els[i]);
2675: return a;
2676: }
2677: }
2678:
2679: function uncheckOfficialLists() {
2680: var codepicks;
2681: if (document.getElementsByClassName) {
2682: codepicks = document.getElementsByClassName('LC_cloners_instcodes');
2683: } else {
2684: codepicks = getElementsByClassName(document.body,'LC_cloners_instcodes');
2685: }
2686: if (codepicks.length) {
2687: for (var i=0; i<codepicks.length; i++) {
2688: codepicks[i].selectedIndex = 0;
2689: }
2690: }
2691: }
2692:
2693: ENDSCRIPT
2694: }
2695: }
2696: }
1.1 raeburn 2697: if ($can_categorize) {
2698: $categorize_js = <<ENDSCRIPT;
2699: function catsbrowser() {
2700: var catswin = null;
2701: var url = '/adm/courseprefs?phase=categorizecourse';
2702: if (!catswin || catswin.closed) {
2703: catswin=window.open(url,'categorieswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2704: } else {
2705: catswin.focus();
2706: }
2707: }
2708: ENDSCRIPT
2709: }
1.36 raeburn 2710: my $loncaparev = $env{'course.'.$cid.'.internal.releaserequired'};
2711: if ($loncaparev) {
2712: $loncaparev_js = <<ENDSCRIPT;
2713: function loncaparevinfo() {
2714: var lcrevwin = null;
2715: var url = '/adm/courseprefs?phase=releaseinfo';
2716: if (!lcrevwin || lcrevwin.closed) {
2717: lcrevwin=window.open(url,'releasewin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2718: } else {
2719: lcrevwin.focus();
2720: }
2721: }
2722: ENDSCRIPT
2723: }
1.60 raeburn 2724: my $cnum = $env{'course.'.$cid.'.num'};
2725: my $syllabus_js = <<ENDSCRIPT;
2726: function syllabusinfo() {
2727: var syllwin = null;
2728: var url = '/public/$cdom/$cnum/syllabus?only_body=1';
2729: if (!syllwin || syllwin.closed) {
2730: syllwin=window.open(url,'syllabuswin','height=480,width=600,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2731: } else {
2732: syllwin.focus();
2733: }
2734: }
2735: ENDSCRIPT
1.91 raeburn 2736: my $menuitems_js;
2737: unless ($noedit) {
2738: my $collections;
2739: my $next = 1;
2740: if (ref($settings) eq 'HASH') {
2741: if ($settings->{'menucollections'} ne '') {
2742: my @current;
2743: foreach my $item (split(/;/,$settings->{'menucollections'})) {
2744: my ($num) = split(/\%/,$item);
2745: if ($num =~ /^\d+$/) {
2746: push(@current,$num);
2747: }
2748: }
2749: $collections = join("','",sort { $a <=> $b } @current);
2750: if ($collections) {
2751: $collections = "'$collections'";
2752: }
2753: $next += $current[-1];
2754: }
2755: }
2756: my $deftext = &mt('Standard (all menus shown)');
2757: $menuitems_js = <<ENDSCRIPT;
2758: function toggleAddmenucoll() {
2759: if (document.getElementById('menucollections_add')) {
2760: var state = 'none';
2761: var add = document.getElementById('menucollections_add').checked;
2762: if (add) {
2763: state = 'inline-block';
2764: }
2765: var fieldsets = new Array('shown','text','links','list','inline');
2766: for (var i=0; i<fieldsets.length; i++) {
2767: if (document.getElementById('addmenucoll_'+fieldsets[i])) {
2768: document.getElementById('addmenucoll_'+fieldsets[i]).style.display = state;
2769: }
2770: }
2771: var box = document.getElementsByClassName('LC_menucoll_add');
2772: if (box.length) {
2773: for (var i=0; i<box.length; i++) {
2774: if (add) {
2775: box[i].checked = true;
2776: } else {
2777: box[i].checked = false;
2778: }
2779: }
2780: }
2781: if (document.getElementById('menudefault')) {
2782: var menudef = document.getElementById('menudefault');
2783: var currsel = menudef.selectedIndex;
2784: var colls = new Array($collections);
2785: menudef.options.length = 0;
2786: if (!add) {
2787: if (currsel == 1 + colls.length) {
2788: currsel = 0;
2789: }
2790: }
2791: if (currsel == 0) {
2792: menudef.options[0] = new Option('$deftext','',true,true);
2793: } else {
2794: menudef.options[0] = new Option('$deftext','',false,false);
2795: }
2796: if (colls.length) {
2797: for (var i=0; i<colls.length; i++) {
2798: var idx = i+1;
2799: if (currsel == colls[i]) {
2800: menudef.options[idx] = new Option(colls[i],colls[i],true,true);
2801: } else {
2802: menudef.options[idx] = new Option(colls[i],colls[i],false,false);
2803: }
2804: }
2805: }
2806: if (add) {
2807: var addidx = 1 + colls.length;
2808: if (currsel == addidx) {
2809: menudef.options[addidx] = new Option('$next','$next',true,true);
2810: } else {
2811: menudef.options[addidx] = new Option('$next','$next',false,false);
2812: }
2813: }
2814: }
2815: }
2816: }
2817: ENDSCRIPT
2818: }
1.114 raeburn 2819: $extresource_js = <<"ENDSCRIPT";
2820: function toggleExtRes() {
2821: if (document.getElementById('LC_extresource')) {
2822: var extressel = document.getElementById('LC_extresource').value;
2823: if (document.getElementById('LC_extresreusediv')) {
2824: var extresreuse = document.getElementById('LC_extresreusediv');
2825: if (document.getElementById('LC_extressize')) {
2826: var extressize = document.getElementById('LC_extressize');
2827: var setvis;
2828: if ((extressel == 'tab') || (extressel == 'window')) {
2829: extresreuse.style.display = 'inline-block';
2830: setvis = 1;
2831: if (extressel == 'window') {
2832: extressize.style.display = 'inline-block';
2833: } else {
2834: extressize.style.display = 'none';
2835: }
2836: }
2837: if (!setvis) {
2838: extresreuse.style.display = 'none';
2839: extressize.style.display = 'none';
2840: }
2841: }
2842: }
2843: }
2844: }
2845: ENDSCRIPT
1.115 ! raeburn 2846: $localization_js = <<"ENDSCRIPT";
! 2847: function toggleTimeZone() {
! 2848: if (document.getElementById('LC_set_timezone')) {
! 2849: var timezonesel = document.getElementById('LC_set_timezone').value;
! 2850: if (document.getElementById('LC_tzoverdiv')) {
! 2851: var tzoverdiv = document.getElementById('LC_tzoverdiv');
! 2852: if (timezonesel == '') {
! 2853: tzoverdiv.style.display = 'none';
! 2854: } else {
! 2855: tzoverdiv.style.display = 'block';
! 2856: }
! 2857: }
! 2858: }
! 2859: }
! 2860: ENDSCRIPT
1.1 raeburn 2861: $jscript = '<script type="text/javascript" language="Javascript">'."\n".
1.56 raeburn 2862: '// <![CDATA['."\n".
1.36 raeburn 2863: $browse_js."\n".$categorize_js."\n".$loncaparev_js."\n".
1.115 ! raeburn 2864: $cloners_js."\n".$instcode_js."\n".$localization_js."\n".
1.114 raeburn 2865: $syllabus_js."\n".$menuitems_js."\n".$extresource_js."\n".
1.102 raeburn 2866: &linkprot_javascript()."\n".'//]]>'."\n".
1.56 raeburn 2867: '</script>'."\n".$stubrowse_js."\n";
1.1 raeburn 2868: return $jscript;
2869: }
2870:
1.3 raeburn 2871: sub cloners_javascript {
2872: my ($formname) = @_;
2873: return <<"ENDSCRIPT";
2874:
2875: function update_cloners(caller,num) {
2876: var delidx = getIndexByName('cloners_delete');
2877: var actidx = getIndexByName('cloners_activate');
2878: if (caller == 'cloners_all') {
2879: var selall;
2880: for (var i=0; i<document.$formname.cloners_all.length; i++) {
2881: if (document.$formname.cloners_all[i].checked) {
2882: selall = document.$formname.cloners_all[i].value;
2883: }
2884: }
2885: if (selall == 1) {
2886: if (delidx != -1) {
2887: if (document.$formname.cloners_delete.length) {
2888: for (var j=0; j<document.$formname.cloners_delete.length; j++) {
2889: document.$formname.cloners_delete[j].checked = true;
2890: }
2891: } else {
2892: document.$formname.elements[delidx].checked = true;
2893: }
2894: }
2895: if (actidx != -1) {
2896: if (document.$formname.cloners_activate.length) {
2897: for (var i=0; i<document.$formname.cloners_activate.length; i++) {
2898: if (document.$formname.cloners_activate[i].value == '0') {
2899: document.$formname.cloners_activate[i].checked = false;
2900: }
1.71 raeburn 2901: if (document.$formname.cloners_activate[i].value == '-1') {
1.3 raeburn 2902: document.$formname.cloners_activate[i].checked = true;
2903: }
2904: }
2905: }
2906: }
2907: document.$formname.cloners_newdom.selectedIndex = 0;
2908: }
2909: }
2910: if (caller == 'cloners_activate') {
2911: if (document.$formname.cloners_activate.length) {
2912: for (var j=0; j<document.$formname.cloners_activate.length; j++) {
2913: if (document.$formname.cloners_activate[j].value == num) {
2914: if (document.$formname.cloners_activate[j].checked) {
2915: for (var i=0; i<document.$formname.cloners_all.length; i++) {
2916: if (document.$formname.cloners_all[i].value == '1') {
2917: document.$formname.cloners_all[i].checked = false;
2918: }
2919: if (document.$formname.cloners_all[i].value == '0') {
2920: document.$formname.cloners_all[i].checked = true;
2921: }
2922: }
2923: }
2924: }
2925: }
2926: } else {
2927: for (var i=0; i<document.$formname.cloners_all.length; i++) {
2928: if (document.$formname.cloners_all[i].value == '1') {
2929: document.$formname.cloners_all[i].checked = false;
2930: }
2931: if (document.$formname.cloners_all[i].value == '0') {
2932: document.$formname.cloners_all[i].checked = true;
2933: }
2934: }
2935: }
2936: }
2937: return;
2938: }
2939:
2940: function getIndexByName(item) {
2941: for (var i=0;i<document.$formname.elements.length;i++) {
2942: if (document.$formname.elements[i].name == item) {
2943: return i;
2944: }
2945: }
2946: return -1;
2947: }
2948:
2949: ENDSCRIPT
2950: }
2951:
1.102 raeburn 2952: sub linkprot_javascript {
2953: return <<"ENDSCRIPT";
2954: function toggleLinkProt(form,num,item) {
2955: var radioname = '';
2956: var currdivid = '';
2957: var newdivid = '';
2958: if ((document.getElementById('linkprot_divcurr'+item+'_'+num)) &&
2959: (document.getElementById('linkprot_divchg'+item+'_'+num))) {
2960: currdivid = document.getElementById('linkprot_divcurr'+item+'_'+num);
2961: newdivid = document.getElementById('linkprot_divchg'+item+'_'+num);
2962: radioname = form.elements['linkprot_change'+item+'_'+num];
2963: if (radioname) {
2964: if (radioname.length > 0) {
2965: var setvis;
2966: for (var i=0; i<radioname.length; i++) {
2967: if (radioname[i].checked == true) {
2968: if (radioname[i].value == 1) {
2969: newdivid.style.display = 'inline-block';
2970: currdivid.style.display = 'none';
2971: setvis = 1;
2972: }
2973: break;
2974: }
2975: }
2976: if (!setvis) {
2977: newdivid.style.display = 'none';
2978: currdivid.style.display = 'inline-block';
2979: }
2980: }
2981: }
2982: }
2983: return;
2984: }
2985:
1.112 raeburn 2986: function toggleLinkProtExtra(form,item,extra,valon,styleon,num) {
1.102 raeburn 2987: if (document.getElementById('linkprot_'+extra+'_'+num)) {
2988: var extraid = document.getElementById('linkprot_'+extra+'_'+num);
2989: var itemname = form.elements['linkprot_'+item+'_'+num];
2990: if (itemname) {
2991: if (itemname.length > 0) {
2992: var setvis;
2993: for (var i=0; i<itemname.length; i++) {
2994: if (itemname[i].checked == true) {
2995: if (itemname[i].value == valon) {
2996: extraid.style.display = styleon;
2997: setvis = 1;
2998: }
2999: break;
3000: }
3001: }
3002: if (!setvis) {
3003: extraid.style.display = 'none';
3004: }
3005: }
3006: }
3007: }
3008: return;
3009: }
1.106 raeburn 3010:
3011: function uncheckLinkProtMakeVis(item,num) {
3012: if (document.getElementById('linkprot_'+item+'_'+num)) {
3013: var currtype = document.getElementById('linkprot_'+item+'_'+num).type;
3014: if (currtype.toLowerCase() == 'checkbox') {
3015: document.getElementById('linkprot_'+item+'_'+num).checked = false;
3016: }
3017: }
3018: return;
3019: }
1.102 raeburn 3020: ENDSCRIPT
3021:
3022: }
3023:
1.3 raeburn 3024:
1.1 raeburn 3025: sub print_courseinfo {
1.80 raeburn 3026: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 3027: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 3028: return;
3029: }
1.83 raeburn 3030: my ($cathash,$categoriesform,$autocoowner,$clonedefaults,$disabled);
3031: if ($noedit) {
3032: $disabled = ' disabled="disabled"';
3033: }
1.1 raeburn 3034: my %domconf =
1.71 raeburn 3035: &Apache::lonnet::get_dom('configuration',
3036: ['coursecategories','autoenroll','coursedefaults'],$cdom);
1.1 raeburn 3037: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3038: $cathash = $domconf{'coursecategories'}{'cats'};
3039: if (ref($cathash) eq 'HASH') {
3040: $categoriesform =
3041: &Apache::loncommon::assign_categories_table($cathash,
1.83 raeburn 3042: $settings->{'categories'},$crstype,$disabled)."\n";
1.1 raeburn 3043: }
3044: }
1.25 raeburn 3045: if (ref($domconf{'autoenroll'}) eq 'HASH') {
3046: $autocoowner = $domconf{'autoenroll'}{'co-owners'};
3047: }
1.71 raeburn 3048: my ($currcanclone,@code_order,$cloner_instcode);
3049: my %codedefaults;
3050: &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
3051: \@code_order);
3052: if ($settings->{'cloners'}) {
3053: unless ($settings->{'cloners'} eq '*') {
3054: my @currclone = split(/,/,$settings->{'cloners'});
3055: foreach my $item (@currclone) {
3056: unless ($item eq '*') {
3057: if (($item !~ /\:/) && ($item =~ /=/)) {
3058: $cloner_instcode = 1;
3059: }
3060: }
3061: }
3062: }
3063: }
3064: if (ref($domconf{'coursedefaults'}) eq 'HASH') {
3065: my $canclone = $domconf{'coursedefaults'}{'canclone'};
3066: if (ref($canclone) eq 'HASH') {
3067: if (ref($canclone->{'instcode'}) eq 'ARRAY') {
3068: if ($settings->{'internal.coursecode'}) {
3069: my @posscodes;
3070: if (@code_order > 0) {
3071: $currcanclone = 'instcode';
3072: foreach my $item (@{$canclone->{'instcode'}}) {
3073: if (grep(/^\Q$item\E$/,@code_order)) {
3074: push(@posscodes,$item);
3075: }
3076: }
3077: my $codestr = join(' + ',@posscodes);
3078: $clonedefaults = &mt('Default for official courses is to also allow cloning if [_1] match in cloner and cloned.',
3079: '"<span class="LC_nobreak" style="font-style:italic">'.$codestr.'</span>"').'<br />';
3080: }
3081: }
3082: }
3083: } elsif ($canclone eq 'domain') {
3084: $clonedefaults = &mt('Default is for any course requester in [_1] domain to be able to clone.',
3085: '<span class="LC_nobreak" style="font-style:italic">'.$cdom.'</span>').'<br />';
3086: $currcanclone = 'domain';
3087: }
3088: if ($clonedefaults) {
3089: if ($settings->{'cloners'} ne '') {
3090: $clonedefaults .= '<br />'.&mt('Default does [_1]not[_2] currently apply because values have been set in the course.','<b>','</b>');
3091: } else {
3092: $clonedefaults .= &mt('Default is disregarded if [_1]any[_2] values are set here in the course.','<i>','</i>');
3093: }
3094: $clonedefaults = '<br /><br />'.$clonedefaults;
3095: }
3096: }
1.1 raeburn 3097: if (!defined($categoriesform)) {
1.15 raeburn 3098: $categoriesform = &mt('No categories defined in this domain.');
1.1 raeburn 3099: }
1.12 raeburn 3100: my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype);
1.60 raeburn 3101: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 raeburn 3102:
1.9 raeburn 3103: my $replace;
3104: if ($crstype eq 'Community') {
3105: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3106: } else {
3107: $replace = &mt('To replace the standard title for a course role, enter a title, otherwise leave blank');
3108: }
1.84 raeburn 3109: my ($editmap,$editsyllabus);
3110: unless ($noedit) {
3111: $editmap = (' 'x2).
3112: '<a href="javascript:openbrowser'.
3113: "('display','url','sequence')\">".
3114: &mt('Select Map').'</a><br /><span class="LC_warning"> '.
3115: &mt('Modification may make assessment data inaccessible!').
3116: '</span>';
3117: $editsyllabus = &mt('[_1]Edit[_2]','<a href="/public/'.$cdom.'/'.$cnum.'/syllabus?forceedit=1">',
3118: '</a>');
3119: }
1.1 raeburn 3120: my %items = (
1.3 raeburn 3121: 'url' => {
1.84 raeburn 3122: text => '<b>'.&mt($itemtext->{'url'}).'</b>'.$editmap,
1.1 raeburn 3123: input => 'textbox',
1.55 raeburn 3124: size => '55',
1.19 faziophi 3125: advanced => 1
1.1 raeburn 3126: },
3127: 'description' => {
1.3 raeburn 3128: text => '<b>'.&mt($itemtext->{'description'}).'</b>',
1.1 raeburn 3129: input => 'textbox',
1.55 raeburn 3130: size => '55',
1.1 raeburn 3131: },
1.24 raeburn 3132: 'owner' => {
3133: text => '<b>'.&mt($itemtext->{'owner'}).'</b>',
3134: },
1.25 raeburn 3135: 'co-owners' => {
3136: text => '<b>'.&mt($itemtext->{'co-owners'}).'</b>',
3137: },
1.63 raeburn 3138: 'clonedfrom' => {
3139: text => '<b>'.&mt($itemtext->{'clonedfrom'}).'</b>',
3140: },
1.1 raeburn 3141: 'courseid' => {
1.3 raeburn 3142: text => '<b>'.&mt($itemtext->{'courseid'}).'</b><br />'.'('.
3143: &mt('internal, optional').')',
1.1 raeburn 3144: input => 'textbox',
3145: size => '25',
3146: },
1.64 raeburn 3147: 'uniquecode' => {
3148: text => '<b>'.&mt($itemtext->{'uniquecode'}).'</b>',
3149: },
1.1 raeburn 3150: 'cloners' => {
1.3 raeburn 3151: text => '<b>'.&mt($itemtext->{'cloners'}).'</b><br />'.
1.71 raeburn 3152: &mt('Owner and Coordinators included automatically').
3153: $clonedefaults,
1.1 raeburn 3154: input => 'textbox',
1.41 www 3155: size => '40'
1.1 raeburn 3156: },
3157: 'rolenames' => {
1.3 raeburn 3158: text => '<b>'.&mt($itemtext->{'rolenames'}).'</b><br />'.
1.9 raeburn 3159: '('.$replace.')',
1.1 raeburn 3160: input => 'textbox',
3161: size => '20',
1.19 faziophi 3162: advanced => 1
1.1 raeburn 3163: },
1.88 raeburn 3164: 'syllabus' => {
3165: text => '<b>'.&mt($itemtext->{'syllabus'}).'</b><br />'.
1.60 raeburn 3166: &mt('(Syllabus type in use)').(' ' x2).
1.84 raeburn 3167: $editsyllabus,
1.1 raeburn 3168: },
3169: 'hidefromcat' => {
1.3 raeburn 3170: text => '<b>'.&mt($itemtext->{'hidefromcat'}).'</b><br />'.
1.1 raeburn 3171: ' ('.&mt('included by default if assigned institutional code, or categorized').')',
3172: input => 'radio',
3173: },
3174: 'categories' => {
1.3 raeburn 3175: text => '<b>'.&mt($itemtext->{'categories'}).'</b> <a href="javascript:catsbrowser()">'.
1.1 raeburn 3176: &mt('Display Categories').'</a>',
3177: input => 'textbox',
3178: size => '25',
3179: },
1.35 raeburn 3180: 'loncaparev' => {
3181: text => '<b>'.&mt($itemtext->{'loncaparev'}).'</b>',
3182: },
1.55 raeburn 3183: 'defaultcredits' => {
3184: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
3185: },
1.1 raeburn 3186: );
3187: my $datatable;
3188: my $count = 0;
3189: foreach my $item (@{$ordered}) {
1.56 raeburn 3190: my $colspan;
1.1 raeburn 3191: if ($item eq 'hidefromcat') {
3192: next if (!$can_toggle_cat);
3193: } elsif ($item eq 'categories') {
3194: next if (!$can_categorize);
1.64 raeburn 3195: } elsif ($item eq 'uniquecode') {
3196: next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'});
1.1 raeburn 3197: }
1.56 raeburn 3198: unless (($item eq 'cloners') || ($item eq 'rolenames')) {
3199: $colspan = 2;
3200: }
1.1 raeburn 3201: $count ++;
1.19 faziophi 3202: if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) {
1.56 raeburn 3203: $datatable .= &item_table_row_start($items{$item}{text},$count,"advanced",$colspan);
1.19 faziophi 3204: } else {
1.56 raeburn 3205: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.19 faziophi 3206: }
1.1 raeburn 3207: if ($items{$item}{input} eq 'radio') {
1.80 raeburn 3208: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 3209: } elsif ($item eq 'cloners') {
3210: my $includeempty = 1;
3211: my $num = 0;
1.56 raeburn 3212: $datatable .= '</td><td align="right">'.
3213: &Apache::loncommon::start_data_table().
1.1 raeburn 3214: &Apache::loncommon::start_data_table_row().
3215: '<td><span class="LC_nobreak"><label>'.
3216: &mt('Any user in any domain:').
3217: ' <input type="radio" name="cloners_all" value="1" ';
3218: if ($settings->{$item} eq '*') {
3219: $datatable .= ' checked="checked" ';
3220: }
3221: $datatable .= 'onchange="javascript:update_cloners('.
1.80 raeburn 3222: "'cloners_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 3223: (' 'x2).'<label>'.
3224: '<input type="radio" name="cloners_all" value="0" ';
1.1 raeburn 3225: if ($settings->{$item} ne '*') {
3226: $datatable .= ' checked="checked" ';
3227: }
3228: $datatable .= ' onchange="javascript:update_cloners('.
1.80 raeburn 3229: "'cloners_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.1 raeburn 3230: &Apache::loncommon::end_data_table_row().
3231: &Apache::loncommon::end_data_table().
1.56 raeburn 3232: '<table><tr><td align="left"><b>'.&mt('Or').
3233: '</b></td></tr></table>'.
1.1 raeburn 3234: &Apache::loncommon::start_data_table();
3235: my @cloners;
3236: if ($settings->{$item} eq '') {
1.80 raeburn 3237: unless ($noedit) {
3238: my $default;
3239: if ($currcanclone eq 'domain') {
3240: $default = '0';
3241: }
3242: $datatable .= &new_cloners_dom_row($cdom,'0',$default);
1.71 raeburn 3243: }
1.1 raeburn 3244: } elsif ($settings->{$item} ne '*') {
3245: my @entries = split(/,/,$settings->{$item});
3246: if (@entries > 0) {
3247: foreach my $entry (@entries) {
3248: my ($uname,$udom) = split(/:/,$entry);
1.23 raeburn 3249: if ($udom =~ /^$match_domain$/) {
3250: unless (&Apache::lonnet::domain($udom)) {
3251: next;
3252: }
3253: } else {
3254: next;
3255: }
1.1 raeburn 3256: if ($uname eq '*') {
3257: $datatable .=
3258: &Apache::loncommon::start_data_table_row().
1.3 raeburn 3259: '<td valign="top" align="left"><span class="LC_nobreak">'.
1.23 raeburn 3260: &mt('Any user in domain:').'<b> '.$udom.
1.1 raeburn 3261: '</b><input type="hidden" name="cloners_dom_'.$num.
3262: '" value="'.$udom.'" /></span><br />'.
3263: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 3264: 'name="cloners_delete" value="'.$num.'" onchange="javascript:update_cloners('."'cloners_delete','$num'".');"'.$disabled.' />'.
1.1 raeburn 3265: &mt('Delete').'</label></span></td>'.
3266: &Apache::loncommon::end_data_table_row();
3267: $num ++;
1.23 raeburn 3268: } elsif (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
3269: unless (grep(/^\Q$entry\E$/,@cloners)) {
3270: push(@cloners,$entry);
3271: }
1.1 raeburn 3272: }
3273: }
3274: }
3275: }
3276: my $add_domtitle = &mt('Any user in additional domain:');
3277: if ($settings->{$item} eq '*') {
3278: $add_domtitle = &mt('Any user in specific domain:');
3279: } elsif ($settings->{$item} eq '') {
3280: $add_domtitle = &mt('Any user in other domain:');
3281: }
3282: my $cloners_str = join(',',@cloners);
3283: $datatable .= &Apache::loncommon::start_data_table_row().
3284: '<td align="left"><span class="LC_nobreak">'.
3285: $add_domtitle.'</span><br />'.
3286: &Apache::loncommon::select_dom_form('','cloners_newdom',
1.80 raeburn 3287: $includeempty,undef,undef,
3288: undef,undef,$noedit).
1.1 raeburn 3289: '<input type="hidden" name="cloners_total" value="'.$num.'" />'.
3290: '</td>'.&Apache::loncommon::end_data_table_row().
1.3 raeburn 3291: &Apache::loncommon::end_data_table().
1.56 raeburn 3292: '<table><tr><td align="left"><b>'.&mt('And').
3293: '</b></td></tr></table>'.
1.1 raeburn 3294: &Apache::loncommon::start_data_table().
3295: &Apache::loncommon::start_data_table_row().
3296: '<td align="left">'.
3297: &mt('Specific users').' (<tt>'.
3298: &mt('user:domain,user:domain').'</tt>)<br />'.
3299: &Apache::lonhtmlcommon::textbox($item,$cloners_str,
1.80 raeburn 3300: $items{$item}{'size'},$disabled).
1.1 raeburn 3301: '</td>'.&Apache::loncommon::end_data_table_row().
3302: &Apache::loncommon::end_data_table();
1.71 raeburn 3303: if (@code_order > 0) {
3304: my (%cat_items,@codetitles,%cat_titles,%cat_order);
3305: my ($jscript,$totcodes,$numtitles,$lasttitle) =
3306: &Apache::courseclassifier::instcode_selectors_data($cdom,'display',
3307: \%cat_items,\@codetitles,
3308: \%cat_titles,\%cat_order);
3309: my $showncodes = 'off';
3310: my $checkedoff = ' checked="checked"';
3311: my $checkedon = '';
3312: if ($cloner_instcode) {
3313: $checkedon = $checkedoff;
3314: $checkedoff = '';
3315: $showncodes = 'on';
3316: }
3317: $datatable .= '<table><tr><td align="left"><b>'.&mt('And').
3318: '</b></td></tr></table>'.
3319: &Apache::loncommon::start_data_table().
3320: &Apache::loncommon::start_data_table_row().
3321: '<td align="left"><span class="LC_nobreak">'.
3322: &mt('Cloning by official course(s) based on course category').(' 'x2).
3323: '<label>'.
1.80 raeburn 3324: '<input type="radio" name="cloners_instcode" value="1" onclick="toggleCloners(this);"'.$checkedon.$disabled.' />'.&mt('Yes').'</label>'.
1.71 raeburn 3325: (' ').
3326: '<label>'.
1.80 raeburn 3327: '<input type="radio" name="cloners_instcode" value="0" onclick="toggleCloners(this);"'.$checkedoff.$disabled.' />'.&mt('No').'</label>'.
1.71 raeburn 3328: &Apache::courseclassifier::build_instcode_selectors($numtitles,
3329: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order,
1.80 raeburn 3330: $showncodes,'LC_cloners_instcodes','LC_cloners_instcode',$noedit).
1.71 raeburn 3331: '</td>'.&Apache::loncommon::end_data_table_row().
3332: &Apache::loncommon::end_data_table();
3333: }
1.1 raeburn 3334: } elsif ($item eq 'rolenames') {
1.56 raeburn 3335: $datatable .= '</td><td align="right">'.
3336: &Apache::loncommon::start_data_table();
1.9 raeburn 3337: my @roles;
3338: if ($crstype eq 'Community') {
3339: @roles = ('co');
3340: } else {
3341: @roles = ('cc');
3342: }
3343: push (@roles,('in','ta','ep','ad','st'));
3344: foreach my $role (@roles) {
1.1 raeburn 3345: $datatable .= &Apache::loncommon::start_data_table_row().
3346: '<td align="left"><span class="LC_nobreak">'.
3347: &Apache::lonnet::plaintext($role,$crstype,undef,1).
3348: '</span></td><td align="left">'.
3349: &Apache::lonhtmlcommon::textbox('rolenames_'.$role,
3350: $settings->{$role.'.plaintext'},
1.80 raeburn 3351: $items{$item}{size},$disabled).'</td>'.
1.1 raeburn 3352: &Apache::loncommon::end_data_table_row();
3353: }
3354: $datatable .= &Apache::loncommon::end_data_table().'</td>';
3355: } elsif ($item eq 'categories') {
1.80 raeburn 3356: my $launcher;
3357: if ($noedit) {
3358: $launcher = $disabled;
3359: } else {
3360: $launcher = 'onfocus="this.blur();javascript:catsbrowser();"';
3361: }
1.3 raeburn 3362: $datatable .= '<input type="hidden" name="categories" value="'.$settings->{$item}.'" />'.
3363: &Apache::lonhtmlcommon::textbox($item.'_display',$settings->{$item},
3364: $items{$item}{size},$launcher);
1.24 raeburn 3365: } elsif ($item eq 'owner') {
3366: my $owner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
3367: if ($owner =~ /:/) {
3368: my ($ownername,$ownerdom) = split(':',$owner);
3369: $owner = &Apache::loncommon::plainname($ownername,$ownerdom);
3370: } elsif ($owner ne '') {
3371: $owner = &Apache::loncommon::plainname($owner,$cdom);
3372: } else {
3373: $owner = &mt('None specified');
3374: }
3375: $datatable .= $owner;
1.63 raeburn 3376: } elsif ($item eq 'clonedfrom') {
3377: my $clonesrc = $env{'course.'.$env{'request.course.id'}.'.clonedfrom'};
3378: my $clonedfrom = &mt('None');
3379: if ($clonesrc =~ m{/$match_domain/$match_courseid}) {
1.65 raeburn 3380: my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc);
1.63 raeburn 3381: if ($clonesrcinfo{'description'}) {
3382: $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc);
3383: }
3384: }
3385: $datatable .= $clonedfrom;
1.64 raeburn 3386: } elsif ($item eq 'uniquecode') {
3387: my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'};
3388: if ($code) {
3389: $datatable .= $code;
3390: }
1.25 raeburn 3391: } elsif ($item eq 'co-owners') {
3392: my $coowners = $env{'course.'.$env{'request.course.id'}.'.internal.co-owners'};
3393: my @currcoown;
3394: if ($coowners) {
3395: @currcoown = split(',',$coowners);
3396: }
3397: if (&Apache::lonnet::is_course_owner($cdom,$cnum)) {
3398: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
3399: $datatable .= &show_autocoowners(@currcoown);
3400: } else {
1.80 raeburn 3401: $datatable .= &coowner_invitations($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 3402: }
3403: } else {
3404: if (($crstype eq 'Course') && ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) && ($autocoowner)) {
3405: $datatable .= &show_autocoowners(@currcoown);
3406: } else {
1.80 raeburn 3407: $datatable .= &manage_coownership($cnum,$cdom,\@currcoown,$noedit);
1.25 raeburn 3408: }
3409: }
1.88 raeburn 3410: } elsif ($item eq 'syllabus') {
1.60 raeburn 3411: my $external = $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'};
3412: my $uploaded = $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'};
3413: my $minimal = $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'};
3414: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
3415: if ($minimal =~/\w/) {
3416: if ($external =~ m{\Q$minimal\E$}) {
3417: undef($external);
3418: }
3419: } elsif ($uploaded =~/\w/) {
3420: if ($external =~ m{\Q$uploaded\E$}) {
3421: undef($external);
3422: }
3423: }
3424: } elsif ($external!~/\w/) {
3425: undef($external);
3426: }
3427: if ($external) {
3428: $datatable .= &mt('External URL');
3429: } elsif ($minimal) {
3430: $datatable .= &mt('Minimal template');
3431: } elsif ($uploaded) {
3432: $datatable .= &mt('Uploaded file');
3433: } else {
3434: $datatable .= &mt('Standard template');
3435: }
3436: $datatable .= (' ' x 2).
3437: &mt('[_1]View[_2]',
3438: '<a href="javascript:syllabusinfo();">',
3439: '</a>');
1.35 raeburn 3440: } elsif ($item eq 'loncaparev') {
3441: my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
3442: my $showreqd;
3443: if ($loncaparev) {
1.36 raeburn 3444: $showreqd = &mt('[_1] or newer',$loncaparev).' <a href="javascript:loncaparevinfo()">'.
1.37 raeburn 3445: &mt('Details').'</a>';
1.35 raeburn 3446: } else {
3447: $showreqd = &mt('No specific version required');
3448: }
3449: $datatable .= $showreqd;
1.1 raeburn 3450: } else {
1.80 raeburn 3451: $datatable .= &Apache::lonhtmlcommon::textbox($item,$settings->{$item},$items{$item}{size},$disabled);
1.1 raeburn 3452: }
3453: $datatable .= &item_table_row_end();
3454: }
3455: $$rowtotal += scalar(@{$ordered});
3456: return $datatable;
3457: }
3458:
3459: sub new_cloners_dom_row {
1.71 raeburn 3460: my ($newdom,$num,$default) = @_;
3461: my ($output,$checkedon,$checkedoff);
1.1 raeburn 3462: if ($newdom ne '') {
1.71 raeburn 3463: if ($num eq $default) {
3464: $checkedon = 'checked="checked" ';
3465: } else {
3466: $checkedoff = 'checked="checked" ';
3467: }
1.1 raeburn 3468: $output .= &Apache::loncommon::start_data_table_row().
3469: '<td valign="top"><span class="LC_nobreak">'.
3470: &mt('Any user in domain:').' <b>'.$newdom.'</b>'.
3471: (' 'x2).'<label><input type="radio" '.
1.71 raeburn 3472: 'name="cloners_activate" value="'.$num.'" '.$checkedon.
1.3 raeburn 3473: 'onchange="javascript:update_cloners('.
1.1 raeburn 3474: "'cloners_activate','$num'".');" />'.
3475: &mt('Yes').'</label>'.(' 'x2).
3476: '<label><input type="radio" '.
1.71 raeburn 3477: 'name="cloners_activate" value="-1" '.$checkedoff.
1.3 raeburn 3478: 'onchange="javascript:update_cloners('.
1.1 raeburn 3479: "'cloners_activate','$num'".');" />'.
1.3 raeburn 3480: &mt('No').'</label><input type="hidden" name="cloners_dom_'.
3481: $num.'" value="'.$newdom.'" /></span></td>'.
1.1 raeburn 3482: &Apache::loncommon::end_data_table_row();
3483: }
3484: return $output;
3485: }
3486:
3487: sub can_modify_catsettings {
1.12 raeburn 3488: my ($dom,$crstype) = @_;
1.1 raeburn 3489: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
3490: my ($can_toggle_cat,$can_categorize);
3491: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1.12 raeburn 3492: if ($crstype eq 'Community') {
3493: if ($domconf{'coursecategories'}{'togglecatscomm'} eq 'comm') {
3494: $can_toggle_cat = 1;
3495: }
3496: if ($domconf{'coursecategories'}{'categorizecomm'} eq 'comm') {
3497: $can_categorize = 1;
3498: }
3499: } else {
3500: if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') {
3501: $can_toggle_cat = 1;
3502: }
3503: if ($domconf{'coursecategories'}{'categorize'} eq 'crs') {
3504: $can_categorize = 1;
3505: }
1.1 raeburn 3506: }
3507: }
3508: return ($can_toggle_cat,$can_categorize);
3509: }
3510:
3511: sub assign_course_categories {
1.9 raeburn 3512: my ($r,$crstype) = @_;
1.1 raeburn 3513: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3514: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3515: my $hascats = 0;
3516: my $cathash;
3517: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
3518: if (ref($domconf{'coursecategories'}) eq 'HASH') {
3519: $cathash = $domconf{'coursecategories'}{'cats'};
3520: if (ref($cathash) eq 'HASH') {
1.12 raeburn 3521: foreach my $cat (keys(%{$cathash})) {
3522: next if ($cat eq 'instcode::0');
3523: unless ($crstype eq 'Community') {
3524: next if ($cat eq 'communities::0');
3525: }
3526: $hascats ++;
3527: }
1.1 raeburn 3528: }
3529: }
3530: my $catwin_js;
3531: if ($hascats) {
1.9 raeburn 3532: my $alert;
3533: if ($crstype eq 'Community') {
3534: $alert = &mt("Use 'Save' in the main window to save community categories");
3535: } else {
3536: $alert = &mt("Use 'Save' in the main window to save course categories");
3537: }
1.72 damieng 3538: &js_escape(\$alert);
1.1 raeburn 3539: $catwin_js = <<ENDSCRIPT;
3540: <script type="text/javascript">
3541:
3542: function updateCategories() {
3543: var newcategories = '';
3544: var unescapedcats = '';
3545: if (document.chgcats.usecategory.length) {
3546: for (var i=0; i<document.chgcats.usecategory.length; i++) {
3547: if (document.chgcats.usecategory[i].checked == true) {
3548: newcategories = newcategories + document.chgcats.usecategory[i].value + '&';
3549: unescapedcats = unescapedcats + document.chgcats.catname[i].value + ' & ';
3550: }
3551: }
3552: if (newcategories.length > 0) {
3553: newcategories = newcategories.slice(0,-1);
3554: }
3555: if (unescapedcats.length > 0) {
3556: unescapedcats = unescapedcats.slice(0,-3);
3557: }
3558: } else {
3559: if (document.chgcats.usecategory.checked == true) {
3560: newcategories = document.chgcats.usecategory.value;
3561: unescapedcats = document.chgcats.catname.value;
3562: }
3563: }
3564: opener.document.display.categories.value = newcategories;
3565: opener.document.display.categories_display.value = unescapedcats;
3566: alert("$alert");
3567: self.close();
3568: return;
3569: }
3570:
3571: </script>
3572: ENDSCRIPT
3573: } else {
3574: my $onload;
3575: }
1.9 raeburn 3576: my ($crscat,$catcrs,$assign);
3577: if ($crstype eq 'Community') {
3578: $crscat = 'Community Categories';
3579: $catcrs = &mt('Categorize Community');
3580: $assign = &mt('Assign one or more categories to this community.')
3581: } else {
3582: $crscat = 'Course Categories';
3583: $catcrs = &mt('Categorize Course');
3584: $assign = &mt('Assign one or more categories to this course.')
3585: }
1.1 raeburn 3586: my $start_page =
1.9 raeburn 3587: &Apache::loncommon::start_page($crscat,$catwin_js,
1.1 raeburn 3588: {'only_body' => 1,});
3589: my $end_page = &Apache::loncommon::end_page();
1.9 raeburn 3590: my $categoriesform = '<h3>'.$catcrs.'</h3>';
1.1 raeburn 3591: if ($hascats) {
3592: my %currsettings =
3593: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1.12 raeburn 3594: my $cattable = &Apache::loncommon::assign_categories_table($cathash,
3595: $currsettings{'categories'},$crstype);
3596: if ($cattable eq '') {
3597: $categoriesform .= &mt('No suitable categories defined for this course type in this domain.');
3598: } else {
3599: $categoriesform .= $assign.'<br /><br />'.
3600: '<form name="chgcats" action="/adm/courseprefs" method="post">'."\n".
3601: $cattable."\n".
3602: '<br /><input type="button" name="changes" value="'.
3603: &mt('Copy to main window').'" '.
3604: 'onclick="javascript:updateCategories()" /></form><br />';
3605: }
1.1 raeburn 3606: } else {
1.12 raeburn 3607: $categoriesform .= &mt('No categories defined in this domain.');
1.1 raeburn 3608: }
3609: $r->print($start_page.$categoriesform.$end_page);
3610: return;
3611: }
3612:
1.36 raeburn 3613: sub display_loncaparev_constraints {
3614: my ($r,$navmap,$loncaparev,$crstype) = @_;
1.66 raeburn 3615: my ($reqdmajor,$reqdminor);
1.36 raeburn 3616: my $cid = $env{'request.course.id'};
3617: my $cdom = $env{'course.'.$cid.'.domain'};
3618: my $cnum = $env{'course.'.$cid.'.num'};
3619: my $output;
1.39 raeburn 3620: my %lt = &Apache::lonlocal::texthash (
3621: 'all' => 'all',
3622: 'section/group' => 'section/group',
3623: 'user' => 'user',
3624: );
1.66 raeburn 3625: &Apache::lonrelrequtils::init_global_hashes();
3626: if (defined($Apache::lonrelrequtils::checkcrstypes{$crstype})) {
3627: ($reqdmajor,$reqdminor) = split(/\./,$Apache::lonrelrequtils::checkcrstypes{$crstype});
1.36 raeburn 3628: $output .= '<h4>'.&mt('Course type: [_1] requires [_2] or newer',$crstype,
1.66 raeburn 3629: $Apache::lonrelrequtils::checkcrstypes{$crstype}).'</h4>';
1.36 raeburn 3630: }
3631: my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps,
1.85 raeburn 3632: %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype);
1.39 raeburn 3633: @scopeorder = ('all','section/group','user');
1.67 raeburn 3634: my $now = time;
1.36 raeburn 3635: my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom);
3636: if (ref($resourcedata) eq 'HASH') {
3637: foreach my $key (keys(%{$resourcedata})) {
1.70 raeburn 3638: my %found;
1.66 raeburn 3639: foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) {
1.36 raeburn 3640: if ($key =~ /(\Q$item\E)$/) {
1.70 raeburn 3641: if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') {
3642: my $value = $resourcedata->{$key};
3643: if ($item eq 'examcode') {
3644: if (&Apache::lonnet::validCODE($value)) {
3645: $value = 'valid';
3646: } else {
3647: $value = '';
3648: }
3649: } elsif ($item eq 'printstartdate') {
1.67 raeburn 3650: if ($value =~ /^\d+$/) {
1.70 raeburn 3651: if ($value > $now) {
3652: $value = 'future';
3653: }
3654: }
3655: } elsif ($item eq 'printenddate') {
3656: if ($value =~ /^\d+$/) {
3657: if ($value < $now) {
3658: $value = 'past';
3659: }
3660: }
3661: }
3662: if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) {
3663: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
3664: $found{$item}{'valname'} = &get_param_description($stdtype,$value);
1.76 raeburn 3665: $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'};
1.70 raeburn 3666: }
3667: }
3668: }
3669: }
1.79 raeburn 3670: foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) {
3671: if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') {
1.70 raeburn 3672: my $value = $resourcedata->{$key};
1.79 raeburn 3673: foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) {
1.70 raeburn 3674: if ($value =~ /$valuematch/) {
3675: my $stdtype = &Apache::lonparmset::standard_parameter_types($item);
1.74 raeburn 3676: $found{$item}{'valname'} = &get_param_description($stdtype,$value,1);
1.70 raeburn 3677: $found{$item}{'rev'} =
1.76 raeburn 3678: $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'};
1.70 raeburn 3679: last;
3680: }
3681: }
3682: }
3683: }
1.76 raeburn 3684: foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) {
3685: my $regexp;
3686: if ($item eq 'maplevelrecurse') {
3687: $regexp = '\.(?:sequence|page)___\(rec\)\.';
3688: }
3689: if ($regexp ne '') {
3690: if ($key =~ /$regexp.*\.(\w+)$/) {
3691: my $name = $1;
3692: my $value = $resourcedata->{$key};
3693: if ($name eq 'type') {
3694: last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') ||
3695: ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') ||
3696: ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library'));
3697: }
3698: my $stdtype = &Apache::lonparmset::standard_parameter_types($name);
3699: $found{$name}{'valname'} = &get_param_description($stdtype,$value);
3700: $found{$name}{'extra'} = &mt('Recursive into sub-folders');
3701: $found{$name}{'rev'} =
3702: $Apache::lonnet::needsrelease{'parameter::::'.$item};
3703: }
3704: }
3705: }
1.70 raeburn 3706: foreach my $item (keys(%found)) {
3707: my $stdname = &Apache::lonparmset::standard_parameter_names($item);
3708: my $rev = $found{$item}{'rev'};
3709: my $valname = $found{$item}{'valname'};
1.76 raeburn 3710: my $extra = $found{$item}{'extra'};
1.70 raeburn 3711: my ($middle,$scope,$which,$level,$map,$resource);
3712: my $start = $cid.'.';
3713: if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) {
3714: $middle = $1;
3715: $which = $2;
3716: $scope = 'user';
3717: } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) {
3718: $middle = $1;
3719: $which = $2;
3720: $scope = 'section/group';
3721: } else {
3722: $scope = 'all';
3723: }
3724: my $what="$stdname=$valname";
1.76 raeburn 3725: if ($extra) {
3726: $what .= "<br/>$extra<br />";
3727: }
1.70 raeburn 3728: if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) {
3729: $level = 'general';
3730: if ($scope eq 'all') {
3731: if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
3732: unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) {
3733: push(@{$fromparam{$rev}{$scope}},$what);
3734: }
3735: } else {
3736: push(@{$fromparam{$rev}{$scope}},$what);
3737: }
3738: } else {
3739: if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') {
3740: unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) {
3741: push(@{$fromparam{$rev}{$scope}{$which}},$what);
3742: }
3743: } else {
3744: push(@{$fromparam{$rev}{$scope}{$which}},$what);
3745: }
3746: }
3747: $rowspan{$rev} ++;
1.76 raeburn 3748: } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) {
1.70 raeburn 3749: $level = 'folder';
3750: $map = $1;
3751: if ($scope eq 'all') {
3752: if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') {
3753: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) {
3754: push(@{$bymap{$map}{$rev}{$scope}},$what);
3755: }
3756: } else {
3757: push(@{$bymap{$map}{$rev}{$scope}},$what);
3758: }
3759: } else {
3760: if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') {
3761: unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) {
3762: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
3763: }
3764: } else {
3765: push(@{$bymap{$map}{$rev}{$scope}{$which}},$what);
3766: }
3767: }
3768: } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) {
3769: $level = 'resource';
3770: $resource = $1;
3771: if ($scope eq 'all') {
3772: if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') {
3773: unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) {
3774: push(@{$byresource{$resource}{$rev}{$scope}},$what);
3775: }
3776: } else {
3777: push(@{$byresource{$resource}{$rev}{$scope}},$what);
3778: }
3779: } else {
3780: if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') {
3781: unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) {
3782: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
3783: }
3784: } else {
3785: push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what);
1.36 raeburn 3786: }
3787: }
3788: }
3789: }
3790: }
3791: if (keys(%fromparam)) {
3792: $output .= '<h4>'.&mt('Requirements from general settings').'</h4>'.
3793: &Apache::loncommon::start_data_table().
3794: &Apache::loncommon::start_data_table_header_row().
3795: '<th>'.&mt('Release').'</th><th>'.&mt('Scope').'</th>'.
3796: '<th>'.&mt('Extent').'</th><th>'.&mt('Setting').'</th>'.
3797: &Apache::loncommon::end_data_table_header_row();
3798: foreach my $rev (keys(%fromparam)) {
1.66 raeburn 3799: my ($major,$minor) = split(/\./,$rev);
3800: ($reqdmajor,$reqdminor) =
3801: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
1.36 raeburn 3802: $output .= &Apache::loncommon::start_data_table_row().
3803: '<td rowspan="'.$rowspan{$rev}.'">'.$rev.'</td>';
3804: my $newrow;
3805: foreach my $scope (@scopeorder) {
3806: if (ref($fromparam{$rev}{$scope}) eq 'HASH') {
3807: if ($newrow) {
3808: $output .= &Apache::loncommon::continue_data_table_row();
3809: }
1.39 raeburn 3810: $output .= '<td>'.$lt{$scope}.'</td>';
1.36 raeburn 3811: foreach my $which (sort(keys(%{$fromparam{$rev}{$scope}}))) {
3812: $output .= '<td>'.$which.'</td><td>'.
3813: join('<br />',@{$fromparam{$rev}{$scope}{$which}}).'</td>';
3814: }
3815: $output .= &Apache::loncommon::end_data_table_row();
3816: $newrow = 1;
3817: } elsif (ref($fromparam{$rev}{$scope}) eq 'ARRAY') {
3818: if ($newrow) {
3819: $output .= &Apache::loncommon::continue_data_table_row();
3820: }
1.39 raeburn 3821: $output .= '<td>'.$lt{$scope}.'</td><td> </td><td>'.
1.36 raeburn 3822: join('<br />',@{$fromparam{$rev}{$scope}}).'</td>'.
3823: &Apache::loncommon::end_data_table_row();
3824: $newrow = 1;
3825: }
3826: }
3827: }
3828: $output .= &Apache::loncommon::end_data_table().'<br />';
3829: }
3830: }
3831:
1.66 raeburn 3832: my %comm_blocks = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3833: my $now = time;
3834: if (keys(%comm_blocks) > 0) {
3835: foreach my $block (keys(%comm_blocks)) {
3836: if ($block =~ /^firstaccess____(.+)$/) {
1.78 raeburn 3837: my $rev = $Apache::lonnet::needsrelease{'course:commblock:timer'};
1.66 raeburn 3838: if (ref($comm_blocks{$block}) eq 'HASH') {
3839: push(@{$fromblocks{'timer'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
3840: ' '.&mt('set by [_1]',
3841: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
3842: }
3843: next;
3844: } elsif ($block =~ /^(\d+)____(\d+)$/) {
3845: my ($start,$end) = ($1,$2);
3846: next if ($end < $now);
3847: }
3848: if (ref($comm_blocks{$block}) eq 'HASH') {
3849: if (ref($comm_blocks{$block}{'blocks'}) eq 'HASH') {
3850: if (ref($comm_blocks{$block}{'blocks'}{'docs'}) eq 'HASH') {
3851: if (keys(%{$comm_blocks{$block}{'blocks'}{'docs'}}) > 0) {
1.78 raeburn 3852: my $rev = $Apache::lonnet::needsrelease{'course:commblock:docs'};
1.66 raeburn 3853: push(@{$fromblocks{'docs'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
3854: ' '.
3855: &mt('set by [_1]',
3856: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
3857: }
3858: } elsif ($comm_blocks{$block}{'blocks'}{'printout'} eq 'on') {
1.78 raeburn 3859: my $rev = $Apache::lonnet::needsrelease{'course:commblock:printout'};
1.66 raeburn 3860: push(@{$fromblocks{'printout'}{$rev}},&unescape($comm_blocks{$block}{'event'}).
3861: ' '.
3862: &mt('set by [_1]',
3863: &Apache::loncommon::plainname(split(/:/,$comm_blocks{$block}{'setter'}))));
3864:
3865: }
3866: }
3867: }
3868: }
3869: if (keys(%fromblocks)) {
3870: my %lt = (
3871: docs => 'Content blocking',
3872: printout => 'Printout generation',
3873: timer => 'Timed quiz trigger',
3874: );
3875: $output .= '<h4>'.&mt('Requirements from exam blocking').'</h4>'.
3876: &Apache::loncommon::start_data_table().
3877: &Apache::loncommon::start_data_table_header_row().
3878: '<th>'.&mt('Release').'</th><th>'.&mt('Setting').'</th>'.
3879: '<th>'.&mt('Event(s)').'</th>'.
3880: &Apache::loncommon::end_data_table_header_row();
3881: foreach my $type ('docs','printout','timer') {
3882: if (ref($fromblocks{$type}) eq 'HASH') {
3883: foreach my $rev (keys(%{$fromblocks{$type}})) {
3884: my ($major,$minor) = split(/\./,$rev);
3885: ($reqdmajor,$reqdminor) =
3886: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
3887: $output .= &Apache::loncommon::start_data_table_row().
3888: '<td>'.$rev.'</td><td>'.$lt{$type}.'</td><td>';
3889: foreach my $event (sort(@{$fromblocks{$type}{$rev}})) {
3890: $output .= $event.'<br />';
3891: }
3892: $output =~ s{\Q<br />\E$}{};
3893: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
3894: }
3895: }
3896: }
3897: $output .= &Apache::loncommon::end_data_table().'<br />';
3898: }
3899: }
3900:
1.36 raeburn 3901: if (defined($navmap)) {
3902: my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum);
1.76 raeburn 3903: my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'};
1.36 raeburn 3904: my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum);
1.76 raeburn 3905: my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'};
1.85 raeburn 3906: my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'};
1.36 raeburn 3907: my $stdtype=&Apache::lonparmset::standard_parameter_types('type');
3908: my $stdname=&Apache::lonparmset::standard_parameter_names('type');
3909: my $valanon=&get_param_description($stdtype,'anonsurvey');
3910: my $valrandtry=&get_param_description($stdtype,'randomizetry');
1.66 raeburn 3911: my %checkedrev;
1.85 raeburn 3912: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
1.36 raeburn 3913: my @parts = @{$res->parts()};
3914: my $symb = $res->symb();
3915: my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src());
1.85 raeburn 3916: if ($res->is_tool()) {
3917: my $rev = $rev_exttool;
3918: $bycrsrestype{$symb}{$rev} = &mt('External Tool');
3919: $allmaps{$enclosing_map} = 1;
3920: next;
3921: }
1.36 raeburn 3922: foreach my $part (@parts) {
3923: if (exists($anonsubms{$symb."\0".$part})) {
3924: my $rev = $rev_anonsurv;
3925: my $what="$stdname=$valanon";
3926: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
3927: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
3928: push(@{$bysubmission{$symb}{$rev}},$what);
3929: }
3930: } else {
3931: push(@{$bysubmission{$symb}{$rev}},$what);
3932: }
3933: $allmaps{$enclosing_map} = 1;
1.66 raeburn 3934: unless ($checkedrev{'anonsurvey'}) {
3935: my ($major,$minor) = split(/\./,$rev);
3936: ($reqdmajor,$reqdminor) =
3937: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
3938: $reqdmajor,$reqdminor);
3939: $checkedrev{'anonsurvey'} = 1;
3940: }
1.36 raeburn 3941: }
3942: if (exists($randtrysubms{$symb."\0".$part})) {
3943: my $rev = $rev_randtry;
3944: my $what="$stdname=$valrandtry";
3945: if (ref($bysubmission{$symb}{$rev}) eq 'ARRAY') {
3946: unless (grep(/^\Q$what\E/,@{$bysubmission{$symb}{$rev}})) {
3947: push(@{$bysubmission{$symb}{$rev}},$what);
3948: }
3949: } else {
3950: push(@{$bysubmission{$symb}{$rev}},$what);
3951: }
3952: $allmaps{$enclosing_map} = 1;
1.66 raeburn 3953: unless ($checkedrev{'randomizetry'}) {
3954: my ($major,$minor) = split(/\./,$rev);
3955: ($reqdmajor,$reqdminor) =
3956: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
3957: $reqdmajor,$reqdminor);
3958: $checkedrev{'randomizetry'} = 1;
3959: }
1.36 raeburn 3960: }
3961: }
3962: my %responses = $res->responseTypes();
3963: foreach my $key (keys(%responses)) {
1.66 raeburn 3964: if (exists($Apache::lonrelrequtils::checkresponsetypes{$key})) {
3965: my $rev = $Apache::lonrelrequtils::checkresponsetypes{$key};
3966: unless ($checkedrev{$key}) {
3967: my ($major,$minor) = split(/\./,$rev);
3968: ($reqdmajor,$reqdminor) =
3969: &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,
3970: $reqdmajor,$reqdminor);
3971: $checkedrev{$key} = 1;
3972: }
3973: push(@{$byresponsetype{$symb}{$rev}},$key);
1.36 raeburn 3974: $allmaps{$enclosing_map} = 1;
3975: }
3976: }
3977: }
3978: if (keys(%byresource) > 0) {
3979: foreach my $symb (keys(%byresource)) {
3980: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
3981: $allmaps{$map} = 1;
3982: }
3983: }
3984: if (keys(%bymap) > 0) {
3985: foreach my $map (keys(%bymap)) {
3986: $allmaps{$map} = 1;
3987: }
3988: }
3989: foreach my $map (keys(%allmaps)) {
3990: my $mapres = $navmap->getResourceByUrl($map);
3991: if (ref($mapres)) {
1.68 raeburn 3992: my $mapsymb = $mapres->symb();
3993: $toshow{$mapsymb} = 1;
1.36 raeburn 3994: my $pcslist = $mapres->map_hierarchy();
3995: if ($pcslist ne '') {
3996: foreach my $pc (split(/,/,$pcslist)) {
3997: my $res = $navmap->getByMapPc($pc);
3998: if (ref($res)) {
3999: my $symb = $res->symb();
4000: unless ($symb eq '______') {
4001: $toshow{$symb} = 1;
4002: }
4003: }
4004: }
4005: }
4006: }
4007: }
4008: }
1.86 raeburn 4009: my $suppmap = 'supplemental.sequence';
4010: my ($suppcount,$supptools,$errors) = (0,0,0);
4011: ($suppcount,$supptools,$errors) = &Apache::loncommon::recurse_supplemental($cnum,$cdom,
4012: $suppmap,$suppcount,$supptools,$errors);
1.36 raeburn 4013: my $mapres_header = '<h4>'.
4014: &mt('Requirements for specific folders or resources').
4015: '</h4>';
4016: if ((keys(%toshow) > 0) || (keys(%byresource) > 0) ||
4017: (keys(%bysubmission) > 0) || (keys(%byresponsetype))) {
4018: $output .= $mapres_header;
4019: }
4020: my $top_header = '<h3>'.&mt('LON-CAPA version dependencies').'</h3>';
4021: my $title = 'Version Constraints';
4022: my $start_page =
4023: &Apache::loncommon::start_page($title,undef,{'only_body' => 1,});
4024: $r->print($start_page.$top_header);
4025: if ($output) {
4026: $r->print($output);
1.86 raeburn 4027: if (defined($navmap) || $supptools) {
1.36 raeburn 4028: &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission,
1.86 raeburn 4029: \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools);
1.36 raeburn 4030: }
4031: $r->print('<br /><br />');
4032: } else {
4033: $r->print('<p class="LC_info">'.
4034: &mt('No version requirements from resource content or settings.').
4035: '</p>');
4036: }
4037: $r->print(&Apache::loncommon::end_page());
1.66 raeburn 4038: my ($currmajor,$currminor) = split(/\./,$loncaparev);
4039: if (($currmajor != $reqdmajor) || ($currminor != $reqdminor)) {
4040: return 1;
4041: }
1.36 raeburn 4042: return;
4043: }
4044:
4045: sub show_contents_view {
1.39 raeburn 4046: my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype,
1.86 raeburn 4047: $bycrsrestype,$scopeorder,$lt,$supptools) = @_;
4048: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
4049: my $whitespace = '<img src="'.$location.'/whitespace_21.gif" alt="" />';
4050: my $showmaincontent;
4051: if ((ref($navmap)) &&
4052: ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) ||
4053: (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) ||
4054: (keys(%{$bycrsrestype}) > 0))) {
4055: $showmaincontent = 1;
4056: }
4057: if ($showmaincontent || $supptools) {
4058: $r->print(&Apache::loncommon::start_data_table());
4059: }
4060: if ($showmaincontent) {
4061: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
1.36 raeburn 4062: my $topmap = $env{'course.'.$cid.'.url'};
1.86 raeburn 4063: $r->print(&Apache::loncommon::start_data_table_header_row().
1.36 raeburn 4064: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4065: '<th>'.&mt('Attribute/Setting').'</th>'.
4066: &Apache::loncommon::end_data_table_header_row().
4067: &Apache::loncommon::start_data_table_row().
1.58 raeburn 4068: '<td> '.$icon.' '.&mt('Main Content').'</td>');
1.86 raeburn 4069: &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt);
4070: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4071: my $it=$navmap->getIterator(undef,undef,undef,1,1,undef);
4072: my $curRes;
4073: my $depth = 0;
4074: my %parent = ();
4075: my $startcount = 5;
4076: my $lastcontainer = $startcount;
4077: while ($curRes = $it->next()) {
4078: if ($curRes == $it->BEGIN_MAP()) {
4079: $depth++;
4080: $parent{$depth}= $lastcontainer;
4081: }
4082: if ($curRes == $it->END_MAP()) {
4083: $depth--;
4084: $lastcontainer = $parent{$depth};
4085: }
4086: my $indent;
4087: for (my $i=0; $i<$depth; $i++) {
4088: $indent.= $whitespace;
4089: }
4090: if (ref($curRes)) {
4091: my $symb = $curRes->symb();
4092: my $ressymb = $symb;
4093: my $srcf = $curRes->src();
4094: my $title = &Apache::lonnet::gettitle($srcf);
4095: if (($curRes->is_sequence()) || ($curRes->is_page())) {
4096: next unless($toshow->{$symb});
4097: my ($parent,$ind,$url) = &Apache::lonnet::decode_symb($symb);
4098: $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4099: if ($curRes->is_page()) {
4100: $icon = '<img src="'.$location.'/navmap.page.open.gif" alt="" />';
4101: }
4102: my $rowspan = 1;
4103: if (ref($bymap->{$url}) eq 'HASH') {
4104: $rowspan = scalar(keys(%{$bymap->{$url}}));
4105: }
4106: $r->print(&Apache::loncommon::start_data_table_row().
4107: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
1.48 raeburn 4108: &releases_by_map($r,$bymap,$url,$scopeorder,$lt);
1.36 raeburn 4109: $r->print(&Apache::loncommon::end_data_table_row());
4110: } else {
4111: my $rowspan;
4112: if (ref($byresource->{$symb}) eq 'HASH') {
4113: $rowspan += scalar(keys(%{$byresource->{$symb}}));
4114: }
4115: if (ref($bysubmission->{$symb}) eq 'HASH') {
4116: $rowspan += scalar(keys(%{$bysubmission->{$symb}}));
4117: }
4118: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4119: $rowspan += scalar(keys(%{$byresponsetype->{$symb}}));
4120: }
1.85 raeburn 4121: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
4122: $rowspan += scalar(keys(%{$bycrsrestype->{$symb}}));
4123: }
1.36 raeburn 4124: next if (!$rowspan);
4125: $icon = '<img class="LC_contentImage" src="'.$location.'/problem.gif" alt="'.
4126: &mt('Problem').'" />';
4127: $r->print(&Apache::loncommon::start_data_table_row().
4128: '<td rowspan="'.$rowspan.'">'.$indent.$icon.' '.$title.'</td>');
4129: my $newrow;
4130: if (ref($byresource->{$symb}) eq 'HASH') {
4131: foreach my $rev (sort(keys(%{$byresource->{$symb}}))) {
4132: if ($newrow) {
4133: $r->print(&Apache::loncommon::continue_data_table_row());
4134: }
4135: $r->print('<td valign="middle">'.$rev.'</td><td>');
4136: if (ref($byresource->{$symb}{$rev}) eq 'HASH') {
4137: $r->print('<table border="0">');
4138: foreach my $scope (@{$scopeorder}) {
4139: if (ref($byresource->{$symb}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4140: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4141: foreach my $which (sort(keys(%{$byresource->{$symb}{$rev}{$scope}}))) {
4142: $r->print('<td>'.$which.'</td><td>'.
4143: join('<br />',@{$byresource->{$symb}{$rev}{$scope}{$which}}).
4144: '</td>');
4145: }
4146: $r->print('</tr>');
4147: } elsif (ref($byresource->{$symb}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4148: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>'.
1.36 raeburn 4149: '<td> </td><td>'.
4150: join('<br />',@{$byresource->{$symb}{$rev}{$scope}}).'</td></tr>');
4151: }
4152: }
4153: $r->print('</table>');
4154: }
4155: $r->print('</td>');
4156: $r->print(&Apache::loncommon::end_data_table_row());
4157: $newrow = 1;
4158: }
4159: }
4160: if (ref($bysubmission->{$symb}) eq 'HASH') {
4161: foreach my $rev (sort(keys(%{$bysubmission->{$symb}}))) {
4162: if ($newrow) {
4163: $r->print(&Apache::loncommon::continue_data_table_row());
4164: }
4165: $r->print('<td>'.$rev.'</td><td>');
4166: if (ref($bysubmission->{$symb}{$rev}) eq 'ARRAY') {
4167: $r->print(&mt('Submissions to: ').' '.
4168: join(', ',@{$bysubmission->{$symb}{$rev}}));
4169: }
4170: $r->print('</td>');
4171: $r->print(&Apache::loncommon::end_data_table_row());
4172: $newrow = 1;
4173: }
4174: }
4175: if (ref($byresponsetype->{$symb}) eq 'HASH') {
4176: foreach my $rev (sort(keys(%{$byresponsetype->{$symb}}))) {
4177: if ($newrow) {
4178: $r->print(&Apache::loncommon::continue_data_table_row());
4179: }
4180: $r->print('<td>'.$rev.'</td><td>');
4181: if (ref($byresponsetype->{$symb}{$rev}) eq 'ARRAY') {
4182: $r->print(&mt('Response Type(s): ').' '.
4183: join('<br />',@{$byresponsetype->{$symb}{$rev}}));
4184: }
4185: $r->print('</td>');
4186: }
4187: $r->print(&Apache::loncommon::end_data_table_row());
1.85 raeburn 4188: $newrow = 1;
4189: }
4190: if (ref($bycrsrestype->{$symb}) eq 'HASH') {
4191: foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) {
4192: if ($newrow) {
4193: $r->print(&Apache::loncommon::continue_data_table_row());
4194: }
4195: $r->print('<td>'.$rev.'</td><td>'.$bycrsrestype->{$symb}{$rev}.'</td>');
4196: }
1.86 raeburn 4197: $r->print(&Apache::loncommon::end_data_table_row());
1.36 raeburn 4198: }
4199: }
4200: }
4201: }
1.86 raeburn 4202: }
4203: if ($supptools) {
4204: my $icon = '<img src="'.$location.'/navmap.folder.open.gif" alt="" />';
4205: $r->print(&Apache::loncommon::start_data_table_header_row().
4206: '<th>'.&mt('Location').'</th><th>'.&mt('Release').'</th>'.
4207: '<th>'.&mt('Resource Type').'</th>'.
4208: &Apache::loncommon::end_data_table_header_row().
4209: &Apache::loncommon::start_data_table_row().
4210: '<td> '.$icon.' '.&mt('Supplemental Content').'</td>'.
4211: '<td valign="middle">'.
4212: $Apache::lonrelrequtils::exttool{'major'}.'.'.
4213: $Apache::lonrelrequtils::exttool{'minor'}.
4214: '</td><td>'.&mt('[quant,_1,External Tool,External Tools]',
4215: $supptools).'</td>'.
4216: &Apache::loncommon::end_data_table_row());
4217: }
4218: if ($showmaincontent || $supptools) {
1.36 raeburn 4219: $r->print(&Apache::loncommon::end_data_table());
4220: }
1.66 raeburn 4221: return;
1.36 raeburn 4222: }
4223:
4224: sub releases_by_map {
1.39 raeburn 4225: my ($r,$bymap,$url,$scopeorder,$lt) = @_;
1.36 raeburn 4226: return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY'));
1.73 raeburn 4227: my $newrow = 0;
1.36 raeburn 4228: if (ref($bymap->{$url}) eq 'HASH') {
4229: foreach my $rev (sort(keys(%{$bymap->{$url}}))) {
1.73 raeburn 4230: if ($newrow) {
4231: $r->print(&Apache::loncommon::end_data_table_row().
4232: &Apache::loncommon::continue_data_table_row());
4233: }
1.36 raeburn 4234: $r->print('<td valign="middle">'.$rev.'</td><td>');
4235: if (ref($bymap->{$url}{$rev}) eq 'HASH') {
4236: $r->print('<table border="0">');
4237: foreach my $scope (@{$scopeorder}) {
4238: if (ref($bymap->{$url}{$rev}{$scope}) eq 'HASH') {
1.39 raeburn 4239: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).'</td>');
1.36 raeburn 4240: foreach my $which (sort(keys(%{$bymap->{$url}{$rev}{$scope}}))) {
4241: $r->print('<td>'.$which.'</td><td>'.
4242: join('<br />',@{$bymap->{$url}{$rev}{$scope}{$which}}).
4243: '</td>');
4244: }
4245: $r->print('</tr>');
4246: } elsif (ref($bymap->{$url}{$rev}{$scope}) eq 'ARRAY') {
1.39 raeburn 4247: $r->print('<tr><td>'.&mt('Setting - scope: [_1]',$lt->{$scope}).
1.36 raeburn 4248: '</td><td> </td><td>'.
4249: join('<br />',@{$bymap->{$url}{$rev}{$scope}}).'</td></tr>');
4250: }
4251: }
4252: $r->print('</table>');
4253: }
4254: $r->print('</td>');
1.73 raeburn 4255: $newrow = 1;
1.36 raeburn 4256: }
4257: } else {
4258: $r->print('<td colspan="2"> </td>');
4259: }
4260: return;
4261: }
4262:
4263: sub get_param_description {
1.70 raeburn 4264: my ($stdtype,$value,$regexp) = @_;
4265: my ($name,$parammatches,$paramstrings,@possibles);
1.74 raeburn 4266: if ($stdtype =~ /^string/) {
4267: $paramstrings = &Apache::lonparmset::standard_string_options($stdtype);
4268: } elsif ($stdtype eq 'date_interval') {
4269: $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype);
4270: }
1.70 raeburn 4271: if ($regexp) {
1.74 raeburn 4272: if ($stdtype =~ /^string/) {
4273: $parammatches = &Apache::lonparmset::standard_string_matches($stdtype);
4274: } elsif ($stdtype eq 'date_interval') {
4275: $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype);
4276: }
1.70 raeburn 4277: if (ref($parammatches) eq 'ARRAY') {
4278: @possibles = @{$parammatches};
4279: } else {
4280: undef($regexp);
4281: $name = $value;
4282: }
4283: }
4284: unless ($regexp) {
4285: $name = $value;
4286: if (ref($paramstrings) eq 'ARRAY') {
4287: @possibles = @{$paramstrings};
4288: } else {
1.76 raeburn 4289: if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) {
4290: if ($name == 0) {
4291: $name = &mt('Never');
4292: } elsif (($name ne '') && ($name !~ /\D/)) {
4293: $name = &Apache::lonlocal::locallocaltime($name);
4294: }
4295: }
1.70 raeburn 4296: return $name;
4297: }
1.36 raeburn 4298: }
1.70 raeburn 4299: foreach my $possibilities (@possibles) {
1.36 raeburn 4300: next unless (ref($possibilities) eq 'ARRAY');
1.70 raeburn 4301: my $gotregexmatch = '';
4302: if ($regexp) {
4303: last if ($gotregexmatch);
4304: my ($item,$pattern) = @{ $possibilities };
4305: if ($value =~ /$pattern/) {
4306: if (ref($paramstrings) eq 'ARRAY') {
4307: foreach my $possibles (@{$paramstrings}) {
4308: next unless (ref($possibles) eq 'ARRAY');
4309: my ($thing,$description) = @{$possibles};
4310: if ($thing eq $item) {
4311: $name = $description;
4312: $gotregexmatch = 1;
4313: last;
4314: }
4315: }
4316: last if ($gotregexmatch);
4317: }
4318: }
4319: } else {
4320: my ($thing,$description) = @{ $possibilities };
4321: if ($thing eq $value) {
4322: $name = $description;
4323: last;
4324: }
1.36 raeburn 4325: }
4326: }
4327: return $name;
4328: }
4329:
1.66 raeburn 4330: sub update_releasereq {
4331: my $readmap = 1;
4332: my $getrelreq = 1;
4333: if (ref($modified_courses) eq 'ARRAY') {
4334: foreach my $item (@{$modified_courses}) {
4335: if (ref($item) eq 'ARRAY') {
4336: my ($cdom,$cnum,$chome,$crstype) = @{$item};
4337: &Apache::lonrelrequtils::modify_course_relreq(undef,undef,$cnum,$cdom,
4338: $chome,$crstype,$cdom.'_'.$cnum,
4339: $readmap,$getrelreq);
4340: }
4341: }
4342: $modified_courses = [];
4343: }
4344: undef($registered_cleanup);
4345: return;
4346: }
4347:
1.25 raeburn 4348: sub show_autocoowners {
4349: my (@currcoown) = @_;
1.56 raeburn 4350: 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 4351: if (@currcoown > 0) {
4352: $output .= '<br />'.&mt('Current co-owners are:').' '.
4353: join(', ',map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
4354: } else {
4355: $output .= '<br />'.&mt('Currently no co-owners.');
4356: }
4357: return $output;
4358: }
4359:
4360: sub coowner_invitations {
1.80 raeburn 4361: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
4362: my ($output,@pendingcoown,@othercoords,@currcoown);
1.25 raeburn 4363: my $pendingcoowners =
4364: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
4365: if ($pendingcoowners) {
4366: @pendingcoown = split(',',$pendingcoowners);
4367: }
1.80 raeburn 4368: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 4369: @currcoown = @{$currcoownref};
1.80 raeburn 4370: }
4371: my $disabled;
4372: if ($noedit) {
4373: $disabled = ' disabled="disabled"';
4374: }
1.25 raeburn 4375: my $ccrole = 'cc';
4376: my %ccroles = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,[$ccrole]);
4377: foreach my $key (sort(keys(%ccroles))) {
4378: my ($ccname,$ccdom,$role) = split(':',$key);
4379: next if ($key eq $env{'user.name'}.':'.$env{'user.domain'}.':'.$ccrole);
4380: unless (grep(/^\Q$ccname\E:\Q$ccdom\E$/,@currcoown,@pendingcoown)) {
4381: push(@othercoords,$ccname.':'.$ccdom);
4382: }
4383: }
4384: my $coowner_rows = @currcoown + @pendingcoown + @othercoords;
4385: if ($coowner_rows) {
4386: $output .= &Apache::loncommon::start_data_table();
4387: if (@currcoown) {
4388: $output .= &Apache::loncommon::start_data_table_row().
4389: '<td><i>'.&mt('Current co-owners').'</i></td><td>';
4390: foreach my $person (@currcoown) {
4391: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 4392: $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 4393: }
4394: $output .= '</td>'.
4395: &Apache::loncommon::end_data_table_row();
4396: }
4397: if ($pendingcoowners) {
4398: $output .= &Apache::loncommon::start_data_table_row().
4399: '<td><i>'.&mt('Invited as co-owners [_1](agreement pending)','<br />').'</i></td><td>';
4400: foreach my $person (@pendingcoown) {
4401: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 4402: $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 4403: }
4404: $output .= '</td>'.
4405: &Apache::loncommon::end_data_table_row();
4406: }
4407: if (@othercoords) {
4408: $output .= &Apache::loncommon::start_data_table_row().
4409: '<td><i>'.&mt('Invite other Coordinators [_1]to become co-owners','<br />').'</i></td><td>';
4410: foreach my $person (@othercoords) {
4411: my ($co_uname,$co_dom) = split(':',$person);
1.80 raeburn 4412: $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 4413: }
4414: $output .= '</td>'.
4415: &Apache::loncommon::end_data_table_row();
4416: }
4417: $output .= &Apache::loncommon::end_data_table();
4418: } else {
4419: $output = &mt('There are no coordinators to select as co-owners');
4420: }
4421: return $output;
4422: }
4423:
4424: sub manage_coownership {
1.80 raeburn 4425: my ($cnum,$cdom,$currcoownref,$noedit) = @_;
4426: my (@pendingcoown,@currcoown);
1.25 raeburn 4427: my $pendingcoowners =
4428: $env{'course.'.$env{'request.course.id'}.'.internal.pendingco-owners'};
4429: if ($pendingcoowners) {
4430: @pendingcoown = split(',',$pendingcoowners);
4431: }
1.80 raeburn 4432: if (ref($currcoownref) eq 'ARRAY') {
1.97 raeburn 4433: @currcoown = @{$currcoownref};
1.80 raeburn 4434: }
4435: my $disabled;
4436: if ($noedit) {
4437: $disabled = ' disabled="disabled"';
4438: }
1.25 raeburn 4439: my ($is_coowner,$is_pending,$output);
4440: my $uname = $env{'user.name'};
4441: my $udom = $env{'user.domain'};
4442: if (grep(/^\Q$uname\E:\Q$udom\E$/,@currcoown)) {
4443: $is_coowner = 1;
4444: }
4445: if (grep(/^\Q$uname\E:\Q$udom\E$/,@pendingcoown)) {
4446: $is_pending = 1;
4447: }
4448: if (@currcoown && ($is_coowner || $is_pending)) {
4449: $output = &Apache::loncommon::start_data_table();
4450: }
4451: if (@currcoown) {
4452: if ($is_coowner || $is_pending) {
4453: $output .= &Apache::loncommon::start_data_table().
4454: &Apache::loncommon::start_data_table_row().'<td>';
4455: }
4456: $output .= &mt('Current co-owners are:').' '.
4457: join(', ', map { &Apache::loncommon::plainname(split(':',$_)); } (@currcoown));
4458: if ($is_coowner || $is_pending) {
4459: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4460: }
4461: }
4462: if ($is_coowner || $is_pending) {
4463: if (@currcoown) {
4464: $output .= &Apache::loncommon::start_data_table_row().'<td>';
4465: }
4466: $output .= '<span class="LC_nobreak">';
4467: if ($is_coowner) {
1.90 raeburn 4468: $output .= &mt('You are currently a co-owner:').' <label><input type="checkbox" name="remove_coowner" value="'.$uname.':'.$udom.'" />'.&mt('Discontinue?').'</label>';
1.25 raeburn 4469: } else {
1.90 raeburn 4470: $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).
4471: '<label><input type="radio" name=pending_coowner" value="decline"'.$disabled.' />'.&mt('Decline?').'</label>';
1.25 raeburn 4472: }
4473: $output .= '</span>';
4474: if (@currcoown) {
4475: $output .= '</td>'.&Apache::loncommon::end_data_table_row();
4476: }
4477: }
4478: if (@currcoown && ($is_coowner || $is_pending)) {
4479: $output .= &Apache::loncommon::end_data_table();
4480: }
4481: return $output;
4482: }
4483:
1.1 raeburn 4484: sub print_localization {
1.80 raeburn 4485: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 4486: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4487: return;
4488: }
4489: my %items = (
4490: languages => {
1.17 faziophi 4491: text => '<b>'.&mt($itemtext->{'languages'}).'</b><br />'.
4492: &mt("(overrides individual user preference)"),
1.1 raeburn 4493: input => 'selectbox',
4494: },
4495: timezone => {
1.17 faziophi 4496: text => '<b>'.&mt($itemtext->{'timezone'}).'</b>',
1.1 raeburn 4497: input => 'selectbox',
4498: },
4499: datelocale => {
1.17 faziophi 4500: text => '<b>'.&mt($itemtext->{'datelocale'}).'</b>',
1.1 raeburn 4501: input => 'selectbox',
4502: },
4503: );
1.80 raeburn 4504: my ($datatable,$disabled);
1.1 raeburn 4505: my $count = 0;
1.80 raeburn 4506: if ($noedit) {
4507: $disabled = ' disabled="disabled"';
4508: }
1.1 raeburn 4509: foreach my $item (@{$ordered}) {
4510: $count ++;
1.56 raeburn 4511: my $colspan;
4512: unless ($item eq 'languages') {
1.80 raeburn 4513: $colspan = 2;
1.56 raeburn 4514: }
4515: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 4516: if ($item eq 'timezone') {
4517: my $includeempty = 1;
4518: my $timezone = &Apache::lonlocal::gettimezone();
1.115 ! raeburn 4519: my $onchange;
! 4520: unless ($noedit) {
! 4521: $onchange = ' onchange="javascript:toggleTimeZone();"';
! 4522: }
! 4523: my $id = ' id="LC_set_timezone"';
1.1 raeburn 4524: $datatable .=
1.115 ! raeburn 4525: &Apache::loncommon::select_timezone($item,$timezone,$onchange,
! 4526: $includeempty,$id,$disabled);
! 4527: my $tzsty = 'none';
! 4528: if ($timezone ne '') {
! 4529: $tzsty = 'block';
! 4530: }
! 4531: $datatable .= '<div id="LC_tzoverdiv" style="display:'.$tzsty.';">'.
! 4532: '<span class="LC_nobreak">'.
! 4533: &mt('Override individual user preference?').
! 4534: &yesno_radio('tzover',$settings,undef,1,'',$noedit).
! 4535: '</span></div>';
1.1 raeburn 4536: } elsif ($item eq 'datelocale') {
4537: my $includeempty = 1;
4538: my $locale_obj = &Apache::lonlocal::getdatelocale();
4539: my $currdatelocale;
4540: if (ref($locale_obj)) {
4541: $currdatelocale = $locale_obj->id();
4542: }
4543: $datatable .=
4544: &Apache::loncommon::select_datelocale($item,$currdatelocale,
1.80 raeburn 4545: undef,$includeempty,$disabled);
1.1 raeburn 4546: } else {
4547: if ($settings->{$item} eq '') {
1.80 raeburn 4548: unless ($noedit) {
4549: $datatable .= '</td><td align="right">'.
4550: &Apache::loncommon::select_language('languages_0','',1);
4551: }
1.1 raeburn 4552: } else {
4553: my $num = 0;
1.3 raeburn 4554: my @languages = split(/\s*[,;:]\s*/,$settings->{$item});
1.56 raeburn 4555: $datatable .= '</td><td align="right"><br />'.
4556: &Apache::loncommon::start_data_table();
1.1 raeburn 4557: if (@languages > 0) {
1.3 raeburn 4558: my %langchoices = &get_lang_choices();
1.1 raeburn 4559: foreach my $lang (@languages) {
4560: my $showlang = $lang;
1.3 raeburn 4561: if (exists($langchoices{$lang})) {
4562: $showlang = $langchoices{$lang};
1.1 raeburn 4563: }
4564: $datatable .=
4565: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4566: '<td align="left"><span class="LC_nobreak">'.
1.1 raeburn 4567: &mt('Language:').'<b> '.$showlang.
4568: '</b><input type="hidden" name="languages_'.$num.
4569: '" value="'.$lang.'" /></span><br />'.
4570: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.80 raeburn 4571: 'name="languages_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 4572: &mt('Delete').'</label></span></td>'.
1.3 raeburn 4573: &Apache::loncommon::end_data_table_row();
1.1 raeburn 4574: $num ++;
4575: }
4576: }
1.80 raeburn 4577: unless ($noedit) {
4578: $datatable .=
4579: &Apache::loncommon::start_data_table_row().
1.3 raeburn 4580: '<td align="left"><span class="LC_nobreak">'.
4581: &mt('Additional language:'). '</span><br />'.
4582: &Apache::loncommon::select_language('languages_'.$num,'',1).
1.1 raeburn 4583: '<input type="hidden" name="languages_total" value="'.$num.'" />'.
1.80 raeburn 4584: '</td>'.&Apache::loncommon::end_data_table_row();
4585: }
4586: $datatable .= &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 4587: }
4588: }
4589: $datatable .= &item_table_row_end();
4590: }
4591: $$rowtotal += scalar(@{$ordered});
4592: return $datatable;
4593: }
4594:
1.3 raeburn 4595: sub get_lang_choices {
4596: my %langchoices;
4597: foreach my $id (&Apache::loncommon::languageids()) {
4598: my $code = &Apache::loncommon::supportedlanguagecode($id);
4599: if ($code) {
4600: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4601: }
4602: }
4603: return %langchoices;
4604: }
4605:
1.1 raeburn 4606: sub print_feedback {
1.80 raeburn 4607: my ($position,$cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 4608: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4609: return;
4610: }
4611: my %items = (
1.3 raeburn 4612: 'question.email' => {
4613: text => '<b>'.&mt($itemtext->{'question.email'}).'</b>',
1.1 raeburn 4614: input => 'textbox',
4615: size => '50',
4616: },
4617:
1.3 raeburn 4618: 'comment.email' => {
4619: text => '<b>'.&mt($itemtext->{'comment.email'}).'</b>',
1.1 raeburn 4620: input => 'textbox',
4621: size => '50',
4622: },
4623:
1.3 raeburn 4624: 'policy.email' => {
4625: text => '<b>'.&mt($itemtext->{'policy.email'}).'</b>',
1.1 raeburn 4626: input => 'textbox',
4627: size => '50',
4628: },
4629: );
4630: my $datatable;
4631: my $count = 0;
4632: my ($cnum) = &get_course();
4633: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
4634: my @sections = sort( { $a <=> $b } keys(%sections));
4635: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 4636: currone => 'Current recipient:',
4637: currmult => 'Current recipients:',
4638: add => 'Additional recipient:',
4639: del => 'Delete?',
4640: sec => 'Sections:',
1.1 raeburn 4641: );
1.80 raeburn 4642: my $disabled;
4643: if ($noedit) {
4644: $disabled = ' disabled="disabled"';
4645: }
1.1 raeburn 4646: foreach my $item (@{$ordered}) {
4647: $count ++;
1.20 faziophi 4648: if ($position eq 'top') {
4649: $datatable .= &item_table_row_start($items{$item}{text},$count);
4650: } else {
1.56 raeburn 4651: $datatable .= &item_table_row_start($items{$item}{text}."<br/>(Custom text)",$count, "advanced",2);
1.20 faziophi 4652: }
1.1 raeburn 4653: if ($position eq 'top') {
4654: my $includeempty = 0;
1.94 raeburn 4655: $datatable .= '</td><td align="right">'.
4656: &user_table($cdom,$item,\@sections,
1.80 raeburn 4657: $settings->{$item},\%lt,$noedit);
1.1 raeburn 4658: } else {
1.3 raeburn 4659: $datatable .= &Apache::lonhtmlcommon::textbox($item.'.text',
1.80 raeburn 4660: $settings->{$item.'.text'},$items{$item}{size},$disabled);
1.1 raeburn 4661: }
4662: $datatable .= &item_table_row_end();
4663: }
4664: $$rowtotal += scalar(@{$ordered});
4665: return $datatable;
4666: }
4667:
4668: sub user_table {
1.80 raeburn 4669: my ($cdom,$item,$sections,$currvalue,$lt,$noedit) = @_;
1.1 raeburn 4670: my $output;
4671: if ($currvalue eq '') {
1.80 raeburn 4672: unless ($noedit) {
4673: $output .= &select_recipient($item,'0',$cdom,$sections);
4674: }
1.1 raeburn 4675: } else {
4676: my $num = 0;
4677: my @curr = split(/,/,$currvalue);
1.56 raeburn 4678: $output .= '<table class="LC_data_table">';
1.1 raeburn 4679: my ($currusers);
1.80 raeburn 4680: my $disabled;
4681: if ($noedit) {
4682: $disabled = ' disabled="disabled"';
4683: }
1.1 raeburn 4684: foreach my $val (@curr) {
4685: next if ($val eq '');
4686: my ($uname,$udom,$seclist) = ($val =~ /^($match_username):($match_domain)(\(?[^\)]*\)?)$/);
4687: my @selsec;
4688: if ($seclist) {
4689: $seclist =~ s/(^\(|\)$)//g;
4690: @selsec = split(/\s*;\s*/,$seclist);
4691: }
4692: $currusers .= '<tr>'.
4693: '<td valign="top"><span class="LC_nobreak">'.
4694: '<label><input type="checkbox" '.
1.80 raeburn 4695: 'name="'.$item.'_delete" value="'.$num.'"'.$disabled.' />'.
1.1 raeburn 4696: $lt->{'del'}.'</label>'.
4697: '<input type="hidden" name="'.$item.'_user_'.
1.3 raeburn 4698: $num.'" value="'.$uname.':'.$udom.'" />'.(' 'x2).
1.1 raeburn 4699: &Apache::loncommon::aboutmewrapper(
4700: &Apache::loncommon::plainname($uname,$udom,'firstname'),
4701: $uname,$udom,'aboutuser');
4702: if (ref($sections) eq 'ARRAY') {
4703: if (@{$sections}) {
4704: $currusers.= (' 'x3).$lt->{'sec'}.' '.
4705: &select_sections($item,$num,$sections,
1.80 raeburn 4706: \@selsec,$noedit);
1.1 raeburn 4707: }
4708: }
4709: $currusers .= '</span></td></tr>';
4710: $num ++;
4711: }
4712: if ($num) {
1.10 raeburn 4713: $output .= '<tr>'.
1.1 raeburn 4714: '<td align="left"><i>';
1.20 faziophi 4715: if ($num == 1) {
1.1 raeburn 4716: $output .= $lt->{'currone'};
4717: } else {
1.21 raeburn 4718: $output .= $lt->{'currmult'};
1.1 raeburn 4719: }
4720: $output .= '</i><br />'.
4721: '<table>'.$currusers.'</table></td>'.
1.10 raeburn 4722: '</tr>';
1.1 raeburn 4723: }
1.80 raeburn 4724: unless ($noedit) {
4725: $output .=
4726: '<tr>'.
1.1 raeburn 4727: '<td align="left"><span class="LC_nobreak"><i>'.
4728: $lt->{'add'}.'</i></span><br />'.
4729: &select_recipient($item,$num,$cdom,$sections).
4730: '<input type="hidden" name="'.$item.'_total" value="'.$num.'" />'.
1.80 raeburn 4731: '</td></tr>';
4732: }
4733: $output .= '</table>';
1.1 raeburn 4734: }
4735: return $output;
4736: }
4737:
4738: sub select_recipient {
4739: my ($item,$num,$cdom,$sections,$selected,$includeempty) = @_;
4740: my $domform = &Apache::loncommon::select_dom_form($cdom,$item.'_udom_'.$num,$includeempty);
4741: my $selectlink =
4742: &Apache::loncommon::selectstudent_link('display',$item.'_uname_'.$num,
1.89 raeburn 4743: $item.'_udom_'.$num,'only');
1.1 raeburn 4744: my $output =
1.10 raeburn 4745: '<table><tr><td align="center">'.&mt('Username').'<br />'.
1.1 raeburn 4746: '<input type="text" name="'.$item.'_uname_'.$num.'" value="" /></td>'.
4747: '<td align="center">'.&mt('Domain').'<br />'.$domform.'</td>';
4748: if (ref($sections) eq 'ARRAY') {
4749: if (@{$sections}) {
4750: $output .= '<td align="center">'.&mt('Sections').'<br />'.
4751: &select_sections($item,$num,$sections,$selected).'</td>';
4752: }
4753: }
4754: $output .= '<td valign="top">'.
4755: $selectlink.'</td></tr></table>';
4756: return $output;
4757: }
4758:
4759: sub select_sections {
1.80 raeburn 4760: my ($item,$num,$sections,$selected,$noedit) = @_;
4761: my ($output,@currsecs,$allsec,$disabled);
1.1 raeburn 4762: if (ref($selected) eq 'ARRAY') {
4763: @currsecs = @{$selected};
4764: }
4765: if (!@currsecs) {
4766: $allsec = ' selected="selected"';
4767: }
1.80 raeburn 4768: if ($noedit) {
4769: $disabled = ' disabled="disabled"';
4770: }
1.1 raeburn 4771: if (ref($sections) eq 'ARRAY') {
4772: if (@{$sections}) {
4773: my $mult;
4774: if (@{$sections} > 1) {
4775: $mult = ' multiple="multiple"';
4776: if (@{$sections} > 3) {
4777: $mult .= ' size="4"';
4778: }
4779: }
1.80 raeburn 4780: $output = '<select name="'.$item.'_sections_'.$num.'"'.$mult.$disabled.'>'.
1.1 raeburn 4781: ' <option value=""'.$allsec.'>'.&mt('All').'</option>';
4782: foreach my $sec (@{$sections}) {
4783: my $is_sel;
4784: if ((@currsecs) && (grep(/^\Q$sec\E$/,@currsecs))) {
4785: $is_sel = 'selected="selected"';
4786: }
4787: $output .= '<option value="'.$sec.'"'.$is_sel.'>'.$sec.'</option>';
4788: }
4789: $output .= '</select>';
4790: }
4791: }
4792: return $output;
4793: }
4794:
4795: sub print_discussion {
1.80 raeburn 4796: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$noedit) = @_;
1.3 raeburn 4797: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 4798: return;
4799: }
4800: my %items = (
4801: 'plc.roles.denied' => {
1.10 raeburn 4802: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'plc.roles.denied'}).'</b>'.
4803: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.5 raeburn 4804: &mt('(role-based)'),
1.1 raeburn 4805: input => 'checkbox',
4806: },
4807:
4808: 'plc.users.denied' => {
1.3 raeburn 4809: text => '<b>'.&mt($itemtext->{'plc.users.denied'}).'</b><br />'.
4810: &mt('(specific user(s))'),
1.1 raeburn 4811: input => 'checkbox',
4812: },
4813:
4814: 'pch.roles.denied' => {
1.10 raeburn 4815: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pch.roles.denied'}).'</b>'.
4816: &Apache::loncommon::help_open_topic("Course_Disable_Discussion").'</span><br />'.
1.3 raeburn 4817: &mt('(role-based)'),
1.1 raeburn 4818: input => 'checkbox',
4819: },
4820:
4821: 'pch.users.denied' => {
1.3 raeburn 4822: text => '<b>'.&mt($itemtext->{'pch.users.denied'}).'</b><br />'.
4823: &mt('(specific user(s))'),
1.1 raeburn 4824: input => 'checkbox',
4825: },
1.77 raeburn 4826:
4827: 'pac.roles.denied' => {
4828: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.roles.denied'}).'</b>'.
4829: &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'</span><br />'.
4830: &mt('(role-based)'),
4831: input => 'checkbox',
4832: },
4833:
4834: 'pac.users.denied' => {
4835: text => '<span class="LC_nobreak"><b>'.&mt($itemtext->{'pac.users.denied'}).'</b><br />'.
4836: &mt('(specific user(s))'),
4837: input => 'checkbox',
4838: },
4839:
1.1 raeburn 4840: 'allow_limited_html_in_feedback' => {
1.3 raeburn 4841: text => '<b>'.&mt($itemtext->{'allow_limited_html_in_feedback'}).'</b>',
1.1 raeburn 4842: input => 'radio',
4843: },
4844:
4845: 'allow_discussion_post_editing' => {
1.3 raeburn 4846: text => '<b>'.&mt($itemtext->{'allow_discussion_post_editing'}).'</b>',
1.1 raeburn 4847: input => 'checkbox',
4848: },
1.50 raeburn 4849: 'discussion_post_fonts' => {
4850: text => '<b>'.&mt($itemtext->{'discussion_post_fonts'}).'</b>',
4851: input => 'textbox',
4852: size => '20',
4853: },
1.1 raeburn 4854: );
4855: my $datatable;
4856: my $count;
4857: my ($cnum) = &get_course();
4858: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
4859: my @sections = sort( { $a <=> $b } keys(%sections));
4860: my %lt = &Apache::lonlocal::texthash (
1.21 raeburn 4861: currone => 'Disallowed:',
4862: currmult => 'Disallowed:',
4863: add => 'Disallow more:',
4864: del => 'Delete?',
4865: sec => 'Sections:',
1.1 raeburn 4866: );
4867: foreach my $item (@{$ordered}) {
4868: $count ++;
1.56 raeburn 4869: my $colspan;
4870: if ($item eq 'allow_limited_html_in_feedback') {
4871: $colspan = 2;
4872: }
4873: $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan);
1.1 raeburn 4874: if ($item eq 'plc.roles.denied') {
1.56 raeburn 4875: $datatable .= '</td><td align="right">'.
1.80 raeburn 4876: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 4877: '</table>';
4878: } elsif ($item eq 'plc.users.denied') {
1.94 raeburn 4879: $datatable .= '</td><td align="right">'.
4880: &user_table($cdom,$item,undef,
1.80 raeburn 4881: $settings->{$item},\%lt,$noedit);
1.1 raeburn 4882: } elsif ($item eq 'pch.roles.denied') {
1.56 raeburn 4883: $datatable .= '</td><td align="right">'.
1.80 raeburn 4884: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.1 raeburn 4885: '</table>';
4886: } elsif ($item eq 'pch.users.denied') {
1.56 raeburn 4887: $datatable .= '</td><td align="right">'.
4888: &user_table($cdom,$item,undef,
1.80 raeburn 4889: $settings->{$item},\%lt,$noedit);
1.77 raeburn 4890: } elsif ($item eq 'pac.roles.denied') {
4891: $datatable .= '</td><td align="right">'.
1.80 raeburn 4892: '<table>'.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit).
1.77 raeburn 4893: '</table>';
4894: } elsif ($item eq 'pac.users.denied') {
4895: $datatable .= '</td><td align="right">'.
4896: &user_table($cdom,$item,undef,
1.80 raeburn 4897: $settings->{$item},\%lt,$noedit);
1.1 raeburn 4898: } elsif ($item eq 'allow_limited_html_in_feedback') {
1.80 raeburn 4899: $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit);
1.1 raeburn 4900: } elsif ($item eq 'allow_discussion_post_editing') {
1.56 raeburn 4901: $datatable .= '</td><td align="right"><br />'.
4902: &Apache::loncommon::start_data_table().
1.1 raeburn 4903: &Apache::loncommon::start_data_table_row().
4904: '<th align="left">'.&mt('Role').'</th><th>'.
4905: &mt('Sections').'</th>'.
4906: &Apache::loncommon::end_data_table_row().
1.80 raeburn 4907: &role_checkboxes($cdom,$cnum,$item,$settings,1,undef,$noedit).
1.56 raeburn 4908: &Apache::loncommon::end_data_table().'<br />';
1.50 raeburn 4909: } elsif ($item eq 'discussion_post_fonts') {
1.56 raeburn 4910: $datatable .= '</td><td align="right"><br />'.
4911: &Apache::loncommon::start_data_table().
1.50 raeburn 4912: &Apache::loncommon::start_data_table_row().
4913: '<th align="center">'.&mt('Sum of likes/dislikes').'</th>'.
4914: '<th align="center">'.&mt('font-size').'</th>'.
4915: '<th align="center">'.&mt('font-weight').'</th>'.
4916: '<th align="center">'.&mt('font-style').'</th>'.
4917: '<th align="center">'.&mt('Other css').'</th>'.
4918: &Apache::loncommon::end_data_table_row().
1.80 raeburn 4919: &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit).
1.56 raeburn 4920: &Apache::loncommon::end_data_table().'<br />';
1.1 raeburn 4921: }
4922: $datatable .= &item_table_row_end();
4923: }
4924: $$rowtotal += scalar(@{$ordered});
4925: return $datatable;
4926: }
4927:
4928: sub role_checkboxes {
1.80 raeburn 4929: my ($cdom,$cnum,$item,$settings,$showsections,$crstype,$noedit) = @_;
1.9 raeburn 4930: my @roles = ('st','ad','ta','ep','in');
4931: if ($crstype eq 'Community') {
4932: push(@roles,'co');
4933: } else {
4934: push(@roles,'cc');
4935: }
1.1 raeburn 4936: my $output;
4937: my (@current,@curr_roles,%currsec,@sections);
4938: if ($showsections) {
4939: my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
4940: @sections = sort( { $a <=> $b } keys(%sections));
4941: }
4942: if (ref($settings) eq 'HASH') {
4943: if ($settings->{$item}) {
4944: @current = split(',',$settings->{$item});
4945: if ($showsections) {
4946: foreach my $role (@current) {
4947: if ($role =~ /:/) {
4948: my ($trole,$sec) = split(':',$role);
4949: push(@curr_roles,$trole);
4950: if (ref($currsec{$trole}) eq 'ARRAY') {
4951: if (!grep(/^\Q$sec\E/,@{$currsec{$trole}})) {
4952: push(@{$currsec{$trole}},$sec);
4953: }
1.3 raeburn 4954: } else {
4955: $currsec{$trole} = [$sec];
1.1 raeburn 4956: }
4957: } else {
4958: push(@curr_roles,$role);
4959: }
4960: }
4961: @current = @curr_roles;
4962: }
4963: }
4964: }
4965: my $numinrow = 3;
4966: my $count = 0;
1.80 raeburn 4967: my $disabled;
4968: if ($noedit) {
4969: $disabled = ' disabled="disabled"';
4970: }
1.1 raeburn 4971: foreach my $role (@roles) {
4972: my $checked = '';
4973: if (grep(/^\Q$role\E$/,@current)) {
4974: $checked = ' checked="checked" ';
4975: }
1.9 raeburn 4976: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.1 raeburn 4977: if ($showsections) {
4978: $output .= &Apache::loncommon::start_data_table_row();
4979: } else {
4980: my $rem = $count%($numinrow);
4981: if ($rem == 0) {
4982: if ($count > 0) {
4983: $output .= '</tr>';
4984: }
4985: $output .= '<tr>';
4986: }
4987: }
1.30 raeburn 4988: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 4989: $item.'" value="'.$role.'"'.$checked.$disabled.'/> '.
1.1 raeburn 4990: $plrole.'</label></span></td>';
4991: if ($showsections) {
4992: $output .= '<td align="left">'.
1.80 raeburn 4993: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 4994: '</td></tr>';
4995: }
4996: $count ++;
4997: }
4998: my %adv_roles =
4999: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
5000: my $total = @roles;
5001: foreach my $role (sort(keys(%adv_roles))) {
5002: if ($role =~ m{^cr/($match_domain)/($match_name)/\w$}) {
5003: my $rolename = $3;
5004: my $value = 'cr_'.$1.'_'.$2.'_'.$rolename;
5005: my $checked = '';
5006: if (grep(/^\Q$value\E$/,@current)) {
5007: $checked = ' checked="checked" ';
5008: }
5009: if ($showsections) {
5010: $output .= &Apache::loncommon::start_data_table_row();
5011: } else {
5012: my $rem = $count%($numinrow);
5013: if ($rem == 0) {
5014: if ($count > 0) {
5015: $output .= '</tr>';
5016: }
5017: $output .= '<tr>';
5018: }
5019: }
1.30 raeburn 5020: $output .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
1.80 raeburn 5021: $item.'" value="'.$value.'"'.$checked.$disabled.' /> '.$rolename.
1.1 raeburn 5022: '</label></span></td>';
5023: if ($showsections) {
5024: $output .= '<td>'.
1.80 raeburn 5025: &select_sections($item,$role,\@sections,$currsec{$role},$noedit).
1.1 raeburn 5026: '</td>'.&Apache::loncommon::end_data_table_row();
5027: }
5028: $total ++;
5029: $count ++;
5030: }
5031: }
5032: if (!$showsections) {
5033: my $rem = $total%($numinrow);
5034: my $colsleft = $numinrow - $rem;
5035: if ($colsleft > 1 ) {
5036: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5037: ' </td>';
5038: } elsif ($colsleft == 1) {
5039: $output .= '<td class="LC_left_item"> </td>';
5040: }
5041: $output .= '</tr>';
5042: }
5043: return $output;
5044: }
5045:
1.50 raeburn 5046: sub set_discussion_fonts {
1.80 raeburn 5047: my ($cdom,$cnum,$item,$settings,$noedit) = @_;
1.50 raeburn 5048: my ($classorder,$classtitles) = &discussion_vote_classes();
5049: my ($styleorder,$styleitems) = &discussion_vote_styles();
5050: my $output;
5051: if (ref($classorder) eq 'ARRAY') {
1.80 raeburn 5052: my $disabled;
5053: if ($noedit) {
5054: $disabled = ' disabled="disabled"';
5055: }
1.50 raeburn 5056: foreach my $cat (@{$classorder}) {
5057: my %curr = ();
5058: ($curr{'size'},$curr{'weight'},$curr{'style'},$curr{'other'}) =
5059: split(/,/,$settings->{'discussion_post_fonts_'.$cat});
5060: $output .= &Apache::loncommon::start_data_table_row().
5061: '<td>'.$classtitles->{$cat}.'</td>';
5062: if (ref($styleorder) eq 'ARRAY') {
5063: foreach my $item (@{$styleorder}) {
5064: $output .= '<td><span class="LC_nobreak">';
5065: my $selitem = $item;
5066: if ($item eq 'size') {
5067: my ($currsize,$currunit);
5068: if ($curr{'size'} =~ /^(\d+)(px|%)$/) {
5069: ($currsize,$currunit) = ($1,$2);
5070: $curr{'size'} = $currunit;
5071: }
1.81 raeburn 5072: $output .= '<input type="textbox" name="discussion_post_fonts_'.$cat.'_'.$item.'" value="'.$currsize.'" size="5"'.$disabled.' />'.
1.50 raeburn 5073: ' ';
5074: $selitem = 'unit';
5075: }
5076: if ((ref($styleitems) eq 'HASH') && (ref($styleitems->{$item}) eq 'ARRAY')) {
1.80 raeburn 5077: $output .= '<select name="discussion_post_fonts_'.$cat.'_'.$selitem.'"'.$disabled.'>';
1.50 raeburn 5078: foreach my $val (@{$styleitems->{$item}}) {
5079: my $sel;
5080: if ($val eq $curr{$item}) {
5081: $sel = ' selected="selected"';
5082: }
5083: $output .= '<option value="'.$val.'"'.$sel.'>'.$val.'</option>';
5084: }
5085: }
5086: }
5087: }
1.80 raeburn 5088: $output .= '</span></td><td><input type="textbox" size="10" name="discussion_post_fonts_'.$cat.'_other" value="'.$curr{'other'}.'"'.$disabled.' /></td>';
1.50 raeburn 5089: }
5090: $output .= &Apache::loncommon::end_data_table_row();
5091: }
5092: return $output;
5093: }
5094:
5095: sub discussion_vote_classes {
5096: my $classorder = ['twoplus','oneplus','zero','oneminus','twominus'];
5097: my %classtitles = &Apache::lonlocal::texthash(
5098: 'twoplus' => 'Two sigma above mean',
5099: 'oneplus' => 'One sigma above mean',
5100: 'zero' => 'Within one sigma of mean',
5101: 'oneminus' => 'One sigma below mean',
5102: 'twominus' => 'Two sigma below mean',
5103: );
5104: return ($classorder,\%classtitles);
5105: }
5106:
5107: sub discussion_vote_styles {
5108: my $styleorder = ['size','weight','style'];
5109: my $styleitems = {
5110: size => ['','px','%','xx-small','x-small','small','medium','large',
5111: 'x-large','xx-large','smaller','larger'],
5112: weight => ['','normal','bold','bolder','lighter','100','200','300','400',
5113: '500','600','700','800','900'],
5114: style => ['','normal','italic','oblique'],
5115: };
5116: return ($styleorder,$styleitems);
5117: }
5118:
1.1 raeburn 5119: sub print_classlists {
1.80 raeburn 5120: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 5121: my @ordered;
5122: if ($position eq 'top') {
5123: @ordered = ('default_enrollment_start_date',
5124: 'default_enrollment_end_date');
1.55 raeburn 5125: if ($crstype eq 'Course') {
5126: push(@ordered,'defaultcredits');
5127: }
1.1 raeburn 5128: } elsif ($position eq 'middle') {
1.56 raeburn 5129: @ordered = ('nothideprivileged','checkforpriv');
1.1 raeburn 5130: } else {
5131: @ordered = ('student_classlist_view',
1.26 raeburn 5132: 'student_classlist_opt_in',
5133: 'student_classlist_portfiles');
1.1 raeburn 5134: }
1.9 raeburn 5135: my %lt;
5136:
5137: if ($crstype eq 'Community') {
5138: %lt = &Apache::lonlocal::texthash (
5139: disabled => 'No viewable membership list',
5140: section => "Membership of viewer's section",
5141: all => 'List of all members',
5142: );
5143: } else {
5144: %lt = &Apache::lonlocal::texthash (
5145: disabled => 'No viewable classlist',
5146: section => "Classlist of viewer's section",
5147: all => 'Classlist of all students',
5148: );
5149: }
5150:
1.1 raeburn 5151: my %items = (
5152: 'default_enrollment_start_date' => {
1.3 raeburn 5153: text => '<b>'.&mt($itemtext->{'default_enrollment_start_date'}).'</b>',
1.1 raeburn 5154: input => 'dates',
5155: },
5156: 'default_enrollment_end_date' => {
1.3 raeburn 5157: text => '<b>'.&mt($itemtext->{'default_enrollment_end_date'}).'</b>',
1.1 raeburn 5158: input => 'dates',
5159: },
1.55 raeburn 5160: 'defaultcredits' => {
5161: text => '<b>'.&mt($itemtext->{'defaultcredits'}).'</b>',
5162: },
5163:
1.1 raeburn 5164: 'nothideprivileged' => {
1.3 raeburn 5165: text => '<b>'.&mt($itemtext->{'nothideprivileged'}).'</b>',
1.1 raeburn 5166: input => 'checkbox',
5167: },
5168:
1.56 raeburn 5169: 'checkforpriv' => {
5170: text => '<b>'.&mt($itemtext->{'checkforpriv'}).'</b>',
5171: input => 'selectbox',
5172: },
5173:
1.1 raeburn 5174: 'student_classlist_view' => {
1.3 raeburn 5175: text => '<b>'.&mt($itemtext->{'student_classlist_view'}).'</b>',
1.1 raeburn 5176: input => 'selectbox',
1.9 raeburn 5177: options => \%lt,
1.1 raeburn 5178: order => ['disabled','all','section'],
5179: },
1.26 raeburn 5180: 'student_classlist_opt_in' => {
5181: text => '<b>'.&mt($itemtext->{'student_classlist_opt_in'}).'</b>',
1.1 raeburn 5182: input => 'radio',
5183: },
5184:
5185: 'student_classlist_portfiles' => {
1.3 raeburn 5186: text => '<b>'.&mt($itemtext->{'student_classlist_portfiles'}).'</b>',
1.1 raeburn 5187: input => 'radio',
5188: },
5189: );
5190: unless (($settings->{'student_classlist_view'} eq 'all') ||
5191: ($settings->{'student_classlist_view'} eq 'section')) {
5192: $settings->{'student_classlist_view'} = 'disabled';
5193: }
1.80 raeburn 5194: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'classlists',$noedit);
1.1 raeburn 5195: }
5196:
5197: sub print_appearance {
1.80 raeburn 5198: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5199: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5200: return;
5201: }
1.9 raeburn 5202: my $mathdef;
5203: if ($crstype eq 'Community') {
5204: $mathdef = &mt("None specified - use member's choice");
5205: } else {
5206: $mathdef = &mt("None specified - use student's choice");
5207: }
1.1 raeburn 5208: my %items = (
5209: 'default_xml_style' => {
1.3 raeburn 5210: text => '<b>'.&mt($itemtext->{'default_xml_style'}).'</b> '.
1.1 raeburn 5211: '<a href="javascript:openbrowser'.
5212: "('display','default_xml_style'".
5213: ",'sty')".'">'.&mt('Select Style File').'</a>',
5214: input => 'textbox',
5215: size => 35,
5216: },
5217:
5218: 'pageseparators' => {
1.3 raeburn 5219: text => '<b>'.&mt($itemtext->{'pageseparators'}).'</b>',
1.1 raeburn 5220: input => 'radio',
5221: },
5222: 'disable_receipt_display' => {
1.3 raeburn 5223: text => '<b>'.&mt($itemtext->{'disable_receipt_display'}).'</b>',
1.1 raeburn 5224: input => 'radio',
5225: },
5226: 'texengine' => {
1.3 raeburn 5227: text => '<b>'.&mt($itemtext->{'texengine'}).'</b>',
1.1 raeburn 5228: input => 'selectbox',
5229: options => {
1.61 raeburn 5230: MathJax => 'MathJax',
1.1 raeburn 5231: mimetex => &mt('Convert to Images'),
5232: tth => &mt('TeX to HTML'),
5233: },
1.75 raeburn 5234: order => ['MathJax','mimetex','tth'],
1.9 raeburn 5235: nullval => $mathdef,
1.1 raeburn 5236: },
5237: 'tthoptions' => {
1.3 raeburn 5238: text => '<b>'.&mt($itemtext->{'tthoptions'}).'</b>',
1.1 raeburn 5239: input => 'textbox',
5240: size => 40,
5241: },
1.69 raeburn 5242: 'uselcmath' => {
5243: text => '<b>'.&mt($itemtext->{'uselcmath'}).'</b>',
5244: input => 'radio',
5245: },
5246: 'usejsme' => {
5247: text => '<b>'.&mt($itemtext->{'usejsme'}).'</b>',
5248: input => 'radio',
5249: },
1.95 raeburn 5250: 'inline_chem' => {
5251: text => '<b>'.&mt($itemtext->{'inline_chem'}).'</b>',
5252: input => 'radio',
5253: },
1.114 raeburn 5254: 'extresource' => {
5255: text => '<b>'.&mt($itemtext->{'extresource'}).'</b>',
5256: input => 'selectbox',
5257: options => {
5258: iframe => 'In iframe',
5259: tab => 'In new tab',
5260: window => 'In pop-up window',
5261: },
5262: order => ['iframe','tab','window'],
5263: },
1.1 raeburn 5264: );
1.80 raeburn 5265: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'appearance',$noedit);
1.1 raeburn 5266: }
5267:
5268: sub print_grading {
1.80 raeburn 5269: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5270: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5271: return;
5272: }
5273: my %items = (
5274: 'grading' => {
1.3 raeburn 5275: text => '<b>'.&mt($itemtext->{'grading'}).'</b>'.
1.1 raeburn 5276: &Apache::loncommon::help_open_topic('GradingOptions'),
5277: input => 'selectbox',
5278: options => {
5279: standard => &mt('Standard: shows points'),
1.34 www 5280: categories => &mt('Categories: shows points according to categories'),
1.11 www 5281: external => &mt('External: shows number of completed parts and totals'),
5282: externalnototals => &mt('External: shows only number of completed parts'),
1.1 raeburn 5283: spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'),
5284: },
1.34 www 5285: order => ['standard','categories','external','externalnototals','spreadsheet'],
1.1 raeburn 5286: },
5287: 'rndseed' => {
1.3 raeburn 5288: text => '<b>'.&mt($itemtext->{'rndseed'}).'</b>'.
1.17 faziophi 5289: '<span class="LC_warning">'.'<br />'.
1.1 raeburn 5290: &mt('Modifying this will make problems have different numbers and answers!').
5291: '</span>',
5292: input => 'selectbox',
5293: options => {
5294: '32bit' => '32bit',
5295: '64bit' => '64bit',
5296: '64bit2' => '64bit2',
5297: '64bit3' => '64bit3',
5298: '64bit4' => '64bit4',
5299: '64bit5' => '64bit5',
5300: },
5301: order => ['32bit','64bit','64bit2','64bit3','64bit4','64bit5'],
1.41 www 5302: advanced => 1
1.1 raeburn 5303: },
5304: 'receiptalg' => {
1.3 raeburn 5305: text => '<b>'.&mt($itemtext->{'receiptalg'}).'</b><br />'.
1.5 raeburn 5306: &mt('This controls how receipt numbers are generated'),
1.1 raeburn 5307: input => 'selectbox',
5308: options => {
5309: receipt => 'receipt',
5310: receipt2 => 'receipt2',
5311: receipt3 => 'receipt3',
5312: },
5313: order => ['receipt','receipt2','receipt3'],
1.41 www 5314: advanced => 1
1.1 raeburn 5315: },
5316: 'disablesigfigs' => {
1.3 raeburn 5317: text => '<b>'.&mt($itemtext->{'disablesigfigs'}).'</b>',
1.1 raeburn 5318: input => 'radio',
5319: },
5320: );
1.80 raeburn 5321: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'grading',$noedit);
1.1 raeburn 5322: }
5323:
5324: sub print_printouts {
1.80 raeburn 5325: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5326: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5327: return;
5328: }
5329: my %items = (
5330: problem_stream_switch => {
1.3 raeburn 5331: text => '<b>'.&mt($itemtext->{'problem_stream_switch'}).'</b>',
1.1 raeburn 5332: input => 'radio',
5333: },
5334: suppress_tries => {
1.3 raeburn 5335: text => '<b>'.&mt($itemtext->{'suppress_tries'}).'</b>',
1.1 raeburn 5336: input => 'radio',
5337: },
5338: default_paper_size => {
1.3 raeburn 5339: text => '<b>'.&mt($itemtext->{'default_paper_size'}).'</b>',
1.1 raeburn 5340: input => 'selectbox',
5341: options => {
5342: Letter => &mt('Letter').' [8 1/2x11 in]',
5343: Legal => &mt('Legal').' [8 1/2x14 in]',
5344: Tabloid => &mt('Tabloid').' [11x17 in]',
5345: Executive => &mt('Executive').' [7 1/2x10 in]',
5346: A2 => &mt('A2').' [420x594 mm]',
5347: A3 => &mt('A3').' [297x420 mm]',
5348: A4 => &mt('A4').' [210x297 mm]',
5349: A5 => &mt('A5').' [148x210 mm]',
5350: A6 => &mt('A6').' [105x148 mm]',
5351: },
5352: order => ['Letter','Legal','Tabloid','Executive','A2','A3','A4','A5','A6'],
1.54 bisitz 5353: nullval => &mt('None specified'),
1.1 raeburn 5354: },
5355: print_header_format => {
1.3 raeburn 5356: text => '<b>'.&mt($itemtext->{'print_header_format'}).'</b>',
1.1 raeburn 5357: input => 'checkbox',
5358: },
5359: disableexampointprint => {
1.3 raeburn 5360: text => '<b>'.&mt($itemtext->{'disableexampointprint'}).'</b>',
1.1 raeburn 5361: input => 'radio',
5362: },
1.14 raeburn 5363: canuse_pdfforms => {
5364: text => '<b>'.&mt($itemtext->{'canuse_pdfforms'}).'</b>',
5365: input => 'selectbox',
5366: options => {
5367: 1 => &mt('Yes'),
5368: 0 => &mt('No'),
5369: },
5370: order => ['1','0'],
1.54 bisitz 5371: nullval => &mt('None specified - use domain default'),
1.14 raeburn 5372: }
1.1 raeburn 5373: );
1.80 raeburn 5374: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'printouts',$noedit);
1.1 raeburn 5375: }
5376:
5377: sub print_spreadsheet {
1.80 raeburn 5378: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5379: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5380: return;
5381: }
5382: my $SelectSpreadsheetFile=&mt('Select Spreadsheet File');
5383: my %items = (
5384: spreadsheet_default_classcalc => {
1.3 raeburn 5385: text => '<b>'.&mt($itemtext->{'spreadsheet_default_classcalc'}).'</b> '.
1.1 raeburn 5386: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
5387: "('display','spreadsheet_default_classcalc'".
5388: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
5389: input => 'textbox',
5390: },
5391: spreadsheet_default_studentcalc => {
1.3 raeburn 5392: text => '<b>'.&mt($itemtext->{'spreadsheet_default_studentcalc'}).'</b> '.
1.1 raeburn 5393: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
5394: "('display','spreadsheet_default_calc'".
5395: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
5396: input => 'textbox',
5397: },
5398: spreadsheet_default_assesscalc => {
1.3 raeburn 5399: text => '<b>'.&mt($itemtext->{'spreadsheet_default_assesscalc'}).'</b> '.
1.1 raeburn 5400: '<span class="LC_nobreak"><a href="javascript:openbrowser'.
5401: "('display','spreadsheet_default_assesscalc'".
5402: ",'spreadsheet')".'">'.$SelectSpreadsheetFile.'</a></span>',
5403: input => 'textbox',
5404: },
5405: hideemptyrows => {
1.3 raeburn 5406: text => '<b>'.&mt($itemtext->{'hideemptyrows'}).'</b>',
1.1 raeburn 5407: input => 'radio',
5408: },
5409: );
1.80 raeburn 5410: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'spreadsheet',$noedit);
1.9 raeburn 5411: }
1.1 raeburn 5412:
5413: sub print_bridgetasks {
1.80 raeburn 5414: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
1.3 raeburn 5415: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
1.1 raeburn 5416: return;
5417: }
1.9 raeburn 5418: my ($stumsg,$msgnote);
5419: if ($crstype eq 'Community') {
5420: $stumsg = &mt('Send message to member');
5421: $msgnote = &mt('Message to member and add to user notes');
5422: } else {
5423: $stumsg = &mt('Send message to student');
5424: $msgnote = &mt('Message to student and add to user notes');
5425: }
1.1 raeburn 5426: my %items = (
5427: task_messages => {
1.3 raeburn 5428: text => '<b>'.&mt($itemtext->{'task_messages'}).'</b>',
1.1 raeburn 5429: input => 'selectbox',
5430: options => {
1.9 raeburn 5431: only_student => $stumsg,
5432: student_and_user_notes_screen => $msgnote,
1.1 raeburn 5433: },
5434: order => ['only_student','student_and_user_notes_screen'],
5435: nullval => &mt('No message or record in user notes'),
5436: },
5437: task_grading => {
1.3 raeburn 5438: text => '<b>'.&mt($itemtext->{'task_grading'}).'</b>',
1.1 raeburn 5439: input => 'selectbox',
5440: options => {
5441: any => &mt('Grade BTs in any section'),
5442: section => &mt('Grade BTs only in own section')
5443: },
5444: order => ['any','section'],
5445: },
5446: suppress_embed_prompt => {
1.3 raeburn 5447: text => '<b>'.&mt($itemtext->{'suppress_embed_prompt'}).'</b><span class="LC_nobreak">'.
5448: ' '.&mt('(applies when current role is student)').'</span>',
1.1 raeburn 5449: input => 'radio',
5450: },
5451: );
1.80 raeburn 5452: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit);
1.1 raeburn 5453: }
5454:
1.87 raeburn 5455: sub print_lti {
5456: my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_;
5457: unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) {
5458: return;
5459: }
5460: my @menuitems = ('fullname','coursetitle','role','logout','grades');
5461: my %menutitles = <imenu_titles();
5462: my ($domdefs,$displaydefs);
5463: if ($env{'request.lti.login'}) {
5464: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
5465: my @domdefsmenu;
5466: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
5467: if ($lti{$env{'request.lti.login'}}{'topmenu'}) {
5468: $domdefs = &mt('Header shown').', ';
5469: }
5470: if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
5471: $domdefs .= &mt('Inline menu shown');
5472: }
5473: $domdefs =~ s/,\s$//;
5474: if (!$domdefs) {
5475: $domdefs = &mt('No header or inline menu shown');
5476: }
5477: $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')';
5478: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
5479: @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
5480: }
5481: }
5482: $displaydefs = &mt('Domain defaults');
5483: if (@domdefsmenu) {
5484: my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu);
5485: if (@diffs) {
5486: my $missing;
5487: foreach my $item (@menuitems) {
5488: unless (grep(/^\Q$item\E$/,@domdefsmenu)) {
5489: $missing .= ' '.$menutitles{$item}.',';
5490: }
5491: }
5492: $missing =~ s/,$//;
5493: $displaydefs .= ': '.&mt('Not shown').' --'.$missing;
5494: } else {
5495: $displaydefs .= ': '.&mt('All shown');
5496: }
5497: } else {
5498: $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems);
5499: }
5500: } else {
5501: $displaydefs = &mt('Domain defaults only available in LTI context');
5502: }
5503: my %items = (
5504: 'lti.override' => {
5505: text => '<b>'.&mt($itemtext->{'lti.override'}).'</b>'.$domdefs,
5506: input => 'radio',
5507: },
5508: 'lti.topmenu' => {
5509: text => '<b>'.&mt($itemtext->{'lti.topmenu'}).'</b>',
5510: input => 'radio',
5511: },
5512: 'lti.inlinemenu' => {
5513: text => '<b>'.&mt($itemtext->{'lti.inlinemenu'}).'</b>',
5514: input => 'radio',
5515: },
5516: 'lti.lcmenu' => {
5517: text => '<b>'.&mt($itemtext->{'lti.lcmenu'}).'</b><br />'.$displaydefs,
5518: input => 'custom',
5519: },
5520: );
5521: return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit);
5522: }
5523:
5524: sub lcmenu_checkboxes {
5525: my ($cdom,$caller,$settings,$crstype,$noedit) = @_;
5526: my @menuitems = ('fullname','coursetitle','role','logout','grades');
5527: my %menutitles = <imenu_titles();
5528: my (@current,@domdefs);
5529: if ($env{'request.lti.login'}) {
5530: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
5531: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
5532: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
5533: @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
5534: }
5535: }
5536: }
5537: if (ref($settings) eq 'HASH') {
5538: if ($settings->{'lti.lcmenu'}) {
5539: unless ($settings->{'lti.lcmenu'} eq 'none') {
5540: @current = split(',',$settings->{'lti.lcmenu'});
5541: }
5542: } else {
5543: @current = @domdefs;
5544: }
5545: } else {
5546: @current = @domdefs;
5547: }
5548: my $numinrow = 3;
5549: my $count = 0;
5550: my $disabled;
5551: if ($noedit) {
5552: $disabled = ' disabled="disabled"';
5553: }
5554: my $output = '<table>';
5555: foreach my $item (@menuitems) {
5556: my $checked = '';
5557: if (grep(/^\Q$item\E$/,@current)) {
5558: $checked = ' checked="checked" ';
5559: }
5560: my $rem = $count%($numinrow);
5561: if ($rem == 0) {
5562: if ($count > 0) {
5563: $output .= '</tr>';
5564: }
5565: $output .= '<tr>';
5566: }
5567: $output .= '<td align="left"><span class="LC_nobreak"><label><input type="checkbox" '.
5568: 'name="lti.lcmenu" value="'.$item.'"'.$checked.$disabled.'/> '.
5569: $menutitles{$item}.'</label></span></td>';
5570: $count ++;
5571: }
5572: my $rem = $count%($numinrow);
5573: my $colsleft = $numinrow - $rem;
5574: if ($colsleft > 1 ) {
5575: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5576: ' </td>';
5577: } elsif ($colsleft == 1) {
5578: $output .= '<td class="LC_left_item"> </td>';
5579: }
5580: $output .= '</tr></table>';
5581: }
5582:
5583: sub ltimenu_titles {
5584: return &Apache::lonlocal::texthash(
5585: fullname => 'Full name',
5586: coursetitle => 'Course title',
5587: role => 'Role',
5588: logout => 'Logout',
5589: grades => 'Grades',
5590: );
5591: }
5592:
1.91 raeburn 5593: sub print_menuitems {
5594: my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_;
5595: unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) {
5596: return;
5597: }
5598: if ($position eq 'top') {
5599: my (%defaultmenu_options,@defaultmenu_order,$addcollection);
5600: if ($settings->{'menucollections'} ne '') {
5601: foreach my $item (split(/;/,$settings->{'menucollections'})) {
5602: my ($num,$value) = split(/\%/,$item);
5603: if ($num =~ /^\d+$/) {
5604: $defaultmenu_options{$num} = $num;
5605: }
5606: }
5607: @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options);
5608: $addcollection = $defaultmenu_order[-1] + 1;
5609: } else {
5610: $addcollection = 1;
5611: }
5612: $defaultmenu_options{$addcollection} = $addcollection;
5613: my %items = (
5614: 'menudefault' => {
5615: text => '<b>'.&mt($itemtext->{'menudefault'}).'</b><br />'.
5616: &mt("(can be overriden in deep-link context)"),
5617: input => 'selectbox',
5618: options => \%defaultmenu_options,
5619: order => \@defaultmenu_order,
5620: nullval => &mt('Standard (all menus shown)'),
5621: },
5622: );
5623: return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit);
5624: } else {
5625: my %menu;
5626: my $count = 0;
5627: my $next = 1;
5628: my ($datatable,$disabled);
5629: if ($noedit) {
5630: $disabled = ' disabled="disabled"';
5631: }
5632:
5633: my ($ordered,$cats) = &menuitems_categories();
5634: my @order = @{$ordered};
5635: my %categories = %{$cats};
5636: my %menutitles = &menuitems_titles();
5637: my %menufields = &menuitems_fields();
5638:
5639: if ($settings->{'menucollections'} ne '') {
5640: foreach my $item (split(/;/,$settings->{'menucollections'})) {
5641: my ($num,$value) = split(/\%/,$item);
5642: if ($num =~ /^\d+$/) {
5643: my @entries = split(/\&/,$value);
5644: foreach my $entry (@entries) {
5645: my ($name,$fields) = split(/=/,$entry);
5646: $menu{$num}{$name} = $fields;
5647: }
5648: }
5649: }
5650: if (keys(%menu)) {
5651: my @current = sort { $a <=> $b } keys(%menu);
5652: $next += $current[-1];
5653: foreach my $num (@current) {
5654: my %checked;
5655: my $on = ' checked="checked"';
5656: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 5657: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 5658: if ($menu{$num}{$key} eq 'y') {
5659: $checked{$key} = $on;
5660: }
5661: } else {
5662: foreach my $field (split(/,/,$menu{$num}{$key})) {
5663: if (exists($menufields{$field})) {
5664: $checked{$field} = $on;
5665: }
5666: }
5667: }
5668: }
5669: if (ref($menu{$num}) eq 'HASH') {
5670: $datatable .= &item_table_row_start('<em class="LC_nav_bar">'.$num.'</em>',$count,'','','','LC_left_item');
5671: foreach my $category (@order) {
5672: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
5673: $datatable .= '<fieldset style="vertical-align:top; display:inline-block"><legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 5674: if ($category eq 'text') {
5675: $datatable .= '<i>'.&mt('Header').'</i><br />';
5676: }
1.91 raeburn 5677: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 5678: if ($field eq 'disc') {
5679: $datatable .= '<br /><i>'.&mt('Footer').'</i><br />';
5680: }
1.91 raeburn 5681: $datatable .= '<label><input type="checkbox" name="menucollections_'.$num.'" value="'.$field.'"'.$checked{$field}.$disabled.' />'.
5682: $menufields{$field}.'</label><br />';
5683: }
5684: $datatable .= '</fieldset>';
5685: }
5686: }
5687: $datatable .= &item_table_row_end();
5688: $count ++;
5689: }
5690: }
5691: }
5692: } elsif ($noedit) {
5693: my $text = &mt('No menu collections defined for this course.');
5694: $datatable .= &item_table_row_start($text,$count);
5695: }
5696: unless ($noedit) {
5697: my $add = '<label><input type="checkbox" name="menucollections_add" id="menucollections_add" value="'.$next.'" '.
5698: 'onclick="javascript:toggleAddmenucoll();" />'.&mt('Add').'</label>';
5699: $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item');
5700: foreach my $category (@order) {
5701: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
5702: $datatable .= '<fieldset id="addmenucoll_'.$category.'" style="display:none; vertical-align:top;"><legend>'.$menutitles{$category}.'</legend>'."\n";
5703: foreach my $field (@{$categories{$category}}) {
5704: $datatable .= '<label><input type="checkbox" class="LC_menucoll_add" name="menucollections_'.$next.'" value="'.$field.'"'.$disabled.' />'.
5705: $menufields{$field}.'</label><br />';
5706: }
5707: $datatable .= '</fieldset>';
5708: }
5709: }
5710: $datatable .= &item_table_row_end();
5711: $count ++;
5712: }
5713: return $datatable;
5714: }
5715: }
5716:
5717: sub menuitems_abbreviations {
5718: my %briefcats = (
5719: text => 'pt',
5720: links => 'p',
5721: list => 'ps',
5722: inline => 's',
5723: );
5724: return %briefcats;
5725: }
5726:
5727: sub menuitems_categories {
5728: my @order = ('shown','text','links','list','inline');
5729: my %categories = (
1.94 raeburn 5730: shown => ['top','inline','foot','main'],
5731: text => ['name','role','crs','disc','fdbk'],
1.92 raeburn 5732: links => ['pers','logo','menu','comm','roles','help','logout'],
1.91 raeburn 5733: list => ['about','prefs','port','wish','anno','rss'],
5734: inline => ['cont','grades','chat','people','groups','resv','syll','feeds'],
5735: );
5736: return (\@order,\%categories);
5737: }
5738:
5739: sub menuitems_titles {
5740: return &Apache::lonlocal::texthash (
5741: shown => 'Hierarchy',
1.94 raeburn 5742: text => 'Text',
1.91 raeburn 5743: links => 'Header links',
5744: list => 'Drop-down list',
5745: inline => 'Inline links',
5746: );
5747: }
5748:
5749: sub menuitems_fields {
5750: return &Apache::lonlocal::texthash (
5751: top => 'Display header',
5752: inline => 'Display inline menu',
1.94 raeburn 5753: foot => 'Display footer',
1.91 raeburn 5754: main => 'Access to main menu',
1.92 raeburn 5755: pers => 'Personal',
5756: logo => 'LON-CAPA',
1.91 raeburn 5757: menu => 'Home',
5758: comm => 'Messages',
5759: roles => 'Roles/Courses',
5760: help => 'Help',
5761: logout => 'Logout',
5762: name => 'Fullname',
5763: crs => 'Course Title',
5764: role => 'Current Role',
1.94 raeburn 5765: disc => 'Discussion',
5766: fdbk => 'Feedback',
1.91 raeburn 5767: about => 'Information',
5768: prefs => 'Preferences',
5769: port => 'Portfolio',
5770: wish => 'Stored Links',
5771: anno => 'Calendar',
5772: rss => 'RSS Feeds',
5773: cont => 'Contents',
5774: grades => 'Grades',
5775: chat => 'Chat',
5776: people => 'People',
5777: groups => 'Groups',
5778: resv => 'Reservations',
5779: syll => 'Syllabus',
5780: feeds => 'Feeds',
5781: );
5782: }
5783:
5784: sub menucollections_display {
5785: my ($collections) = @_;
5786: my %menu;
5787: my ($ordered,$cats) = &menuitems_categories();
5788: my @order = @{$ordered};
5789: my %categories = %{$cats};
5790: my %menutitles = &menuitems_titles();
5791: my %menufields = &menuitems_fields();
5792: foreach my $item (split(/;/,$collections)) {
5793: my ($num,$value) = split(/\%/,$item);
5794: if ($num =~ /^\d+$/) {
5795: my @entries = split(/\&/,$value);
5796: foreach my $entry (@entries) {
5797: my ($name,$fields) = split(/=/,$entry);
5798: $menu{$num}{$name} = $fields;
5799: }
5800: }
5801: }
5802: my $output = '';
5803: if (keys(%menu)) {
5804: my @current = sort { $a <=> $b } keys(%menu);
5805: foreach my $num (@current) {
5806: my %checked;
5807: foreach my $key (keys(%{$menu{$num}})) {
1.94 raeburn 5808: if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) {
1.91 raeburn 5809: if ($menu{$num}{$key} eq 'y') {
5810: $checked{$key} = 1;
5811: }
5812: } else {
5813: foreach my $field (split(/,/,$menu{$num}{$key})) {
5814: if (exists($menufields{$field})) {
5815: $checked{$field} = 1;
5816: }
5817: }
5818: }
5819: }
5820: if (ref($menu{$num}) eq 'HASH') {
5821: $output .= '<fieldset><legend>'.&mt('Collection [_1]',$num).'</legend>';
5822: foreach my $category (@order) {
5823: if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) {
5824: $output .= '<fieldset style="vertical-align:top; display:inline-block">'.
5825: '<legend>'.$menutitles{$category}.'</legend>'."\n";
1.94 raeburn 5826: if ($category eq 'text') {
5827: $output .= '<b>'.&mt('Header Text').'</b><br /><br />';
5828: }
1.91 raeburn 5829: foreach my $field (@{$categories{$category}}) {
1.94 raeburn 5830: if ($field eq 'disc') {
5831: $output .= '<br /><b>'.&mt('Footer Text').'</b><br /><br />';
5832: }
1.91 raeburn 5833: if ($checked{$field}) {
5834: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field});
5835: } else {
5836: $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1);
5837: }
5838: $output .= '<br />';
5839: }
5840: $output .= '</fieldset>';
5841: }
5842: }
5843: $output .= '</fieldset>';
5844: }
5845: }
5846: }
5847: return $output;
5848: }
5849:
1.93 raeburn 5850: sub print_linkprotection {
1.102 raeburn 5851: my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit,$context) = @_;
1.93 raeburn 5852:
5853: my %linkprotection;
5854: my $count = 0;
5855: my $next = 1;
1.102 raeburn 5856: my ($datatable,$disabled,$css_class,$dest);
1.93 raeburn 5857: if ($noedit) {
5858: $disabled = ' disabled="disabled"';
5859: }
1.100 raeburn 5860: my %desc = &linkprot_names();
5861: my %lt = &Apache::lonlocal::texthash (
5862: 'requ' => 'Required settings',
5863: 'opti' => 'Optional settings',
5864: );
1.93 raeburn 5865: my $itemcount = 0;
5866:
1.100 raeburn 5867: my $ltiauth;
1.102 raeburn 5868: if ($context eq 'domain') {
5869: $ltiauth = 1;
5870: } else {
5871: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
5872: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
5873: } else {
5874: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
5875: $ltiauth = $domdefs{'crsltiauth'};
5876: }
5877: }
5878: if ($context eq 'domain') {
5879: $dest = '/adm/domainprefs';
1.100 raeburn 5880: } else {
1.102 raeburn 5881: $dest = '/adm/courseprefs';
5882: }
5883:
5884: my ($switchserver,$switchmessage);
5885: $switchserver = &check_switchserver($cdom,$cnum,$context,$dest);
5886: if ($switchserver) {
5887: if ($context eq 'domain') {
5888: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5889: } elsif ($crstype eq 'Community') {
5890: $switchmessage = &mt("submit from community's home server: [_1].",$switchserver);
5891: } else {
5892: $switchmessage = &mt("submit from course's home server: [_1].",$switchserver);
5893: }
1.100 raeburn 5894: }
1.99 raeburn 5895:
1.105 raeburn 5896: if ((ref($settings) eq 'HASH') && (ref($settings->{'linkprot'}) eq 'HASH')) {
1.102 raeburn 5897: if (keys(%{$settings->{'linkprot'}})) {
5898: my @current = sort { $a <=> $b } keys(%{$settings->{'linkprot'}});
1.93 raeburn 5899: $next += $current[-1];
5900: for (my $i=0; $i<@current; $i++) {
5901: my $num = $current[$i];
5902: my %values;
1.102 raeburn 5903: if (ref($settings->{'linkprot'}->{$num}) eq 'HASH') {
5904: %values = %{$settings->{'linkprot'}->{$num}};
1.93 raeburn 5905: } else {
5906: next;
5907: }
5908: my $selected;
5909: if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) {
5910: $selected = ' selected="selected"';
5911: }
5912: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5913: $datatable .=
5914: '<tr '.$css_class.'><td><span class="LC_nobreak">'.
5915: '<label><input type="checkbox" name="linkprot_del" value="'.$i.'"'.$disabled.' />'.
1.100 raeburn 5916: &mt('Delete?').'</label></span></td><td>';
1.112 raeburn 5917: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl);
1.100 raeburn 5918: if ($ltiauth) {
5919: $usersty = 'display:none';
1.112 raeburn 5920: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','$i'".');"';
1.100 raeburn 5921: %checkedrequser = (
5922: no => ' checked="checked"',
5923: yes => '',
5924: );
5925: if ($values{'requser'}) {
5926: $checkedrequser{'yes'} = $checkedrequser{'no'};
5927: $checkedrequser{'no'} = '';
5928: }
5929: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
5930: if ($values{'requser'}) {
5931: $usersty = 'display:inline-block';
5932: }
5933: }
1.112 raeburn 5934: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','$i'".');"';
5935: %checkedreturnurl = (
5936: no => ' checked="checked"',
5937: yes => '',
5938: );
5939: if ($values{'returnurl'} ne '') {
5940: $checkedreturnurl{'yes'} = $checkedreturnurl{'no'};
5941: $checkedreturnurl{'no'} = '';
5942: }
1.100 raeburn 5943: $datatable .=
5944: '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 5945: ':<input type="text" size="15" name="linkprot_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off"'.$disabled.' /></span> '.
1.93 raeburn 5946: (' 'x2).
1.100 raeburn 5947: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_'.$i.'"'.$disabled.'>'.
1.93 raeburn 5948: '<option value="LTI-1p0" '.$selected.'>1.1</option></select></span> '."\n".
5949: (' 'x2).
1.100 raeburn 5950: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" name="linkprot_lifetime_'.$i.'"'.
1.112 raeburn 5951: ' value="'.$values{'lifetime'}.'" size="3"'.$disabled.' /></span><br /><br />';
1.99 raeburn 5952: if ($values{'key'} ne '') {
1.100 raeburn 5953: $datatable .= '<span class="LC_nobreak">'.$desc{'key'};
1.99 raeburn 5954: if ($noedit) {
5955: $datatable .= ': ['.&mt('not shown').']';
5956: } elsif ($switchserver) {
5957: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5958: } else {
5959: $datatable .= ':<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />';
5960: }
5961: $datatable .= '</span> '.(' 'x2);
5962: } elsif (!$switchserver) {
1.100 raeburn 5963: $datatable .= '<span class="LC_nobreak">'.$desc{'key'}.':'.
1.99 raeburn 5964: '<input type="text" size="25" name="linkprot_key_'.$i.'" value="'.$values{'key'}.'" autocomplete="off"'.$disabled.' />'.
5965: '</span> '.(' 'x2);
5966: }
5967: if ($switchserver) {
5968: if ($values{'usable'} ne '') {
5969: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 5970: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 5971: '<span class="LC_nobreak">'.&mt('Change secret?').
1.102 raeburn 5972: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLinkProt(this.form,'."'$i','secret'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
1.99 raeburn 5973: (' 'x2).
1.102 raeburn 5974: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLinkProt(this.form,'."'$i','secret'".');" '.$disabled.' />'.&mt('Yes').'</label>'.(' 'x2).
1.99 raeburn 5975: '</span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
1.102 raeburn 5976: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
1.99 raeburn 5977: '</div>';
5978: } elsif ($values{'key'} eq '') {
1.102 raeburn 5979: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 5980: } else {
1.102 raeburn 5981: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 5982: }
1.111 raeburn 5983: $datatable .= '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" />';
1.99 raeburn 5984: } else {
5985: if ($values{'usable'} ne '') {
5986: $datatable .= '<div id="linkprot_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
1.100 raeburn 5987: $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
1.99 raeburn 5988: '<span class="LC_nobreak">'.&mt('Change?').
1.102 raeburn 5989: '<label><input type="radio" value="0" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLinkProt(this.form,'."'$i','secret'".');" checked="checked"'.$disabled.' />'.&mt('No').'</label>'.
1.99 raeburn 5990: (' 'x2).
1.102 raeburn 5991: '<label><input type="radio" value="1" name="linkprot_changesecret_'.$i.'" onclick="javascript:toggleLinkProt(this.form,'."'$i','secret'".');"'.$disabled.' />'.&mt('Yes').
1.99 raeburn 5992: '</label> </span><div id="linkprot_divchgsecret_'.$i.'" style="display:none" />'.
5993: '<span class="LC_nobreak">'.&mt('New Secret').':'.
5994: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="off"'.$disabled.' />'.
1.106 raeburn 5995: '<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 5996: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span></div>';
5997: } else {
5998: $datatable .=
1.100 raeburn 5999: '<span class="LC_nobreak">'.$desc{'secret'}.':'.
1.99 raeburn 6000: '<input type="password" size="20" name="linkprot_secret_'.$i.'" value="" autocomplete="off"'.$disabled.' />'.
1.106 raeburn 6001: '<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 6002: '<input type="hidden" name="linkprot_id_'.$i.'" value="'.$num.'" /></span>';
6003: }
6004: }
1.112 raeburn 6005: $datatable .= '<br /><br />'.
6006: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
6007: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="0"'.
6008: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
6009: '<label><input type="radio" name="linkprot_returnurl_'.$i.'" value="1"'.
6010: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
6011: ' </span><div id="linkprot_divurlparam_'.$i.'" style="display:none" />'.
6012: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
6013: '<input type="text" size="15" name="linkprot_urlparam_'.$i.'" value="'.$values{'returnurl'}.'" autocomplete="off"'.$disabled.' />'.
6014: '</span></div> ';
1.100 raeburn 6015: if ($ltiauth) {
1.112 raeburn 6016: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
6017: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="0"'.
6018: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
6019: '<label><input type="radio" name="linkprot_requser_'.$i.'" value="1"'.
6020: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
1.100 raeburn 6021: '</fieldset>'.
6022: '<fieldset id="linkprot_optional_'.$i.'" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
6023: &linkprot_options($i,$itemcount,$disabled,\%values,\%desc).
6024: '</fieldset>';
6025: }
1.99 raeburn 6026: $datatable .= '</td></tr>';
1.93 raeburn 6027: $itemcount ++;
6028: }
6029: }
6030: }
6031: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6032: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6033: '<input type="hidden" name="linkprot_maxnum" value="'.$next.'" />'."\n".
1.98 raeburn 6034: '<input type="checkbox" name="linkprot_add" value="1"'.$disabled.' />'.&mt('Add').'</span></td>'."\n".
1.105 raeburn 6035: '<td width="100%">';
1.112 raeburn 6036: my ($usersty,$onclickrequser,%checkedrequser,$onclickreturnurl,%checkedreturnurl);
1.100 raeburn 6037: if ($ltiauth) {
6038: $usersty = 'display:none';
1.112 raeburn 6039: $onclickrequser = ' onclick="toggleLinkProtExtra(this.form,'."'requser','optional','1','block','add'".');"';
1.100 raeburn 6040: %checkedrequser = (
6041: no => ' checked="checked"',
6042: yes => '',
6043: );
6044: $datatable .= '<fieldset><legend>'.$lt{'requ'}.'</legend>';
6045: }
1.112 raeburn 6046: $onclickreturnurl = ' onclick="toggleLinkProtExtra(this.form,'."'returnurl','divurlparam','1','inline-block','add'".');"';
6047: %checkedreturnurl = (
6048: no => ' checked="checked"',
6049: yes => '',
6050: );
1.100 raeburn 6051: $datatable .= '<span class="LC_nobreak">'.$desc{'name'}.
1.98 raeburn 6052: ':<input type="text" size="15" name="linkprot_name_add" value="" autocomplete="off"'.$disabled.' /></span> '."\n".
1.93 raeburn 6053: (' 'x2).
1.100 raeburn 6054: '<span class="LC_nobreak">'.$desc{'version'}.':<select name="linkprot_version_add"'.$disabled.'>'.
1.93 raeburn 6055: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6056: (' 'x2).
1.112 raeburn 6057: '<span class="LC_nobreak">'.$desc{'lifetime'}.':<input type="text" size="3" name="linkprot_lifetime_add" value="300"'.$disabled.' /></span> '."\n".
6058: '<br /><br />';
1.99 raeburn 6059: if ($switchserver) {
1.102 raeburn 6060: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
1.99 raeburn 6061: } else {
1.100 raeburn 6062: $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 6063: (' 'x2).
1.100 raeburn 6064: '<span class="LC_nobreak">'.$desc{'secret'}.':<input type="password" size="20" name="linkprot_secret_add" value="" autocomplete="off"'.$disabled.' />'.
1.106 raeburn 6065: '<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 6066: }
1.112 raeburn 6067: $datatable .= '<br /><br />'.
6068: '<span class="LC_nobreak">'.$desc{'returnurl'}.'?'.
6069: '<label><input type="radio" name="linkprot_returnurl_add" value="0"'.
6070: $onclickreturnurl.$checkedreturnurl{'no'}.$disabled.' />'.&mt('No').'</label> '.
6071: '<label><input type="radio" name="linkprot_returnurl_add" value="1"'.
6072: $onclickreturnurl.$checkedreturnurl{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
6073: ' </span><div id="linkprot_divurlparam_add" style="display:none" />'.
6074: '<span class="LC_nobreak">'.&mt('Parameter name').':'.
6075: '<input type="text" size="15" name="linkprot_urlparam_add" value="" autocomplete="off"'.$disabled.' />'.
6076: '</span></div> ';
6077: if ($ltiauth) {
6078: $datatable .= (' 'x2).'<span class="LC_nobreak">'.$desc{'requser'}.'?'.
6079: '<label><input type="radio" name="linkprot_requser_add" value="0"'.
6080: $onclickrequser.$checkedrequser{'no'}.$disabled.' />'.&mt('No').'</label> '.
6081: '<label><input type="radio" name="linkprot_requser_add" value="1"'.
1.113 raeburn 6082: $onclickrequser.$checkedrequser{'yes'}.$disabled.' />'.&mt('Yes').'</label></span>'.
6083: '</fieldset>'.
1.100 raeburn 6084: '<fieldset id="linkprot_optional_add" style="'.$usersty.'"><legend>'.$lt{'opti'}.'</legend>'.
6085: &linkprot_options('add',$itemcount,$disabled,{},\%desc).
6086: '</fieldset>';
6087: }
1.99 raeburn 6088: $datatable .= '</td></tr>';
1.93 raeburn 6089: $$rowtotal ++;
1.101 raeburn 6090: return $datatable;
1.93 raeburn 6091: }
6092:
6093: sub linkprot_names {
1.100 raeburn 6094: return &Apache::lonlocal::texthash(
1.93 raeburn 6095: 'version' => 'LTI Version',
6096: 'key' => 'Key',
6097: 'lifetime' => 'Nonce lifetime (s)',
1.100 raeburn 6098: 'name' => 'Launcher Application',
1.93 raeburn 6099: 'secret' => 'Secret',
1.112 raeburn 6100: 'returnurl' => 'Launcher return URL',
1.100 raeburn 6101: 'requser' => 'Use identity',
6102: 'email' => 'Email address',
6103: 'sourcedid' => 'User ID',
6104: 'other' => 'Other',
6105: 'auth' => 'Display LON-CAPA login page',
6106: 'reject' => 'Discontinue launch process',
1.93 raeburn 6107: );
6108: }
6109:
1.99 raeburn 6110: sub check_switchserver {
1.102 raeburn 6111: my ($cdom,$cnum,$context,$dest) = @_;
6112: my ($allowed,$switchserver,$home);
6113: if ($context eq 'domain') {
6114: $home = &Apache::lonnet::domain($cdom,'primary');
6115: } else {
6116: $home = &Apache::lonnet::homeserver($cnum,$cdom);
6117: }
6118: unless (($home eq 'no_host') || ($home eq '')) {
1.99 raeburn 6119: my @ids=&Apache::lonnet::current_machine_ids();
6120: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6121: if (!$allowed) {
6122: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
6123: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
1.102 raeburn 6124: '&destinationurl='.$dest.'">'.&mt('Switch Server').'</a>';
1.99 raeburn 6125: }
6126: }
6127: return $switchserver;
6128: }
6129:
1.100 raeburn 6130: sub linkprot_options {
6131: my ($num,$itemcount,$disabled,$current,$desc) = @_;
6132: my %lt;
6133: if (ref($desc) eq 'HASH') {
6134: %lt = %{$desc};
6135: }
6136: my $userfieldsty = 'none';
6137: my (%checked,$userfield);
6138: $checked{'sourcedid'} = ' checked="checked"';
6139: $checked{'reject'} = ' checked="checked"';
6140: if (ref($current) eq 'HASH') {
6141: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6142: $checked{'sourcedid'} = '';
6143: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6144: $checked{'email'} = ' checked="checked"';
6145: } else {
6146: $checked{'other'} = ' checked="checked"';
6147: $userfield = $current->{'mapuser'};
6148: $userfieldsty = 'inline-block';
6149: }
6150: }
6151: if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) {
6152: $checked{'reject'} = '';
6153: $checked{'auth'} = ' checked="checked"';
6154: }
6155: }
1.112 raeburn 6156: my $onclickuser = ' onclick="toggleLinkProtExtra(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"';
1.100 raeburn 6157: my $output = '<div class="LC_floatleft"><span class="LC_nobreak">'.
6158: &mt('Source of LON-CAPA username in LTI request').': ';
6159: foreach my $option ('sourcedid','email','other') {
6160: $output .= '<label><input type="radio" name="linkprot_mapuser_'.$num.'" value="'.$option.'"'.
6161: $checked{$option}.$onclickuser.$disabled.' />'.$lt{$option}.'</label>'.
6162: ($option eq 'other' ? '' : (' 'x2) );
6163: }
6164: $output .= '</span></div>'.
6165: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="linkprot_userfield_'.$num.'">'.
6166: '<input type="text" name="linkprot_customuser_'.$num.'" '.
6167: 'value="'.$userfield.'"'.$disabled.' /></div>';
6168: $output .= '<br />'.
6169: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6170: &mt('Action when username is not for an enrolled student').': ';
6171: foreach my $option ('reject','auth') {
6172: $output .= '<label><input type="radio" name="linkprot_notstudent_'.$num.'" value="'.$option.'"'.
6173: $checked{$option}.$disabled.' />'.$lt{$option}.'</label>'.
6174: ($option eq 'auth' ? '' : (' 'x2) );
6175: }
6176: $output .= '</span></div>';
6177: return $output;
6178: }
6179:
1.114 raeburn 6180: sub print_extresource_row {
6181: my ($item,$config,$curr,$noedit) = @_;
6182: my $onchange;
6183: unless ($noedit) {
6184: $onchange = ' onchange="javascript:toggleExtRes();"';
6185: }
6186: my $id = 'LC_'.$item;
6187: my ($selected,$reuse,$width,$height) = split(/:/,$curr);
6188: my $output = &select_from_options($item,$config->{'order'},
6189: $config->{'options'},$selected,
6190: $config->{'nullval'},
6191: undef,undef,$onchange,$noedit,$id);
6192: my ($checked,$reusesty,$sizesty);
6193: if ($reuse) {
6194: $checked = ' checked="checked"';
6195: }
6196: $reusesty = 'none';
6197: $sizesty = 'none';
6198: if (($selected eq 'window') || ($selected eq 'tab')) {
6199: $reusesty = 'inline-block';
6200: if ($selected eq 'window') {
6201: $sizesty = 'inline-block';
6202: }
6203: }
6204: $output .= '<div id="LC_extresreusediv" style="display:'.$reusesty.';">'.
6205: '<span class="LC_nobreak">'.
6206: '<label><input type="checkbox" name="extwintabreuse" value="1"'.$checked.'>'.
6207: &mt('Re-use tab/window').'</label>'.
6208: '</span></div>'.
6209: '<fieldset id="LC_extressize" style="display:'.$sizesty.';">'.
6210: '<legend>'.&mt('Window size (optional)').'</legend>'.
6211: '<span class="LC_nobreak">'.
6212: &mt('width').':<input type="text" name="extreswinwidth" value="'.$width.'" size="3" />px'.
6213: (' ' x 3).
6214: &mt('height').':<input type="text" name="extreswinheight" value="'.$height.'" size="3" />px'.
6215: '</span></fieldset>';
6216: return $output;
6217: }
6218:
1.1 raeburn 6219: sub print_other {
1.80 raeburn 6220: my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_;
1.1 raeburn 6221: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
6222: return;
6223: }
1.3 raeburn 6224: my @ordered = &get_other_items($cdom,$settings,$allitems);
6225: my %items;
6226: foreach my $parameter (@ordered) {
6227: $items{$parameter} = {
6228: text => '<b>'.$parameter.'</b>',
6229: input => 'textbox',
6230: size => '15',
6231: },
6232: }
6233: push (@ordered,'newp_value');
6234: $items{'newp_value'} = {
6235: text => '<b>'.&mt('Create New Environment Variable').'</b><br />'.
6236: '<input type="textbox" name="newp_name"'.
6237: ' value="" size="30" />',
6238: input => 'textbox',
6239: size => '30',
6240: };
1.93 raeburn 6241: return &make_item_rows($cdom,\%items,\@ordered,$settings,$rowtotal,$crstype,'other',$noedit);
1.3 raeburn 6242: }
6243:
6244: sub get_other_items {
6245: my ($cdom,$settings,$allitems) = @_;
6246: unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) {
6247: return;
6248: }
1.1 raeburn 6249: my @ordered;
6250: if (ref($settings) eq 'HASH') {
6251: foreach my $parameter (sort(keys(%{$settings}))) {
6252: next if (grep/^\Q$parameter\E$/,@{$allitems});
1.3 raeburn 6253: next if (($parameter eq 'course.helper.not.run') &&
6254: (!exists($env{'user.role.dc./'.$env{'request.role.domain'}.'/'})));
1.1 raeburn 6255: unless (($parameter =~ m/^internal\./)||($parameter =~ m/^metadata\./) ||
6256: ($parameter =~ m/^selfenroll_/) || ($parameter =~ /_selfenroll$/)
6257: || ($parameter eq 'type') ||
1.50 raeburn 6258: ($parameter =~ m/^(cc|co|in|ta|ep|ad|st)\.plaintext$/)
1.62 raeburn 6259: || ($parameter =~ m/^discussion_post_fonts/) ||
1.63 raeburn 6260: ($parameter =~ m{^(minimal|updated|uploaded|external)syllabus$}) ||
6261: ($parameter eq 'clonedfrom')) {
1.1 raeburn 6262: push(@ordered,$parameter);
6263: }
6264: }
6265: }
1.3 raeburn 6266: return @ordered;
1.1 raeburn 6267: }
6268:
6269: sub item_table_row_start {
1.91 raeburn 6270: my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_;
1.1 raeburn 6271: my $output;
1.56 raeburn 6272: my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row';
6273: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.91 raeburn 6274: if ($leftclass eq '') {
6275: $leftclass = 'LC_left_item';
6276: }
6277: if ($rightclass eq '') {
6278: $rightclass = 'LC_right_item';
6279: }
1.56 raeburn 6280: $output .= '<tr class="'.$css_class.'">'."\n".
1.91 raeburn 6281: '<td class="'.$leftclass.'">'.$text.
1.56 raeburn 6282: '</td>';
1.91 raeburn 6283: if ($colspan > 1) {
6284: $output .= '<td class="'.$rightclass.'" colspan="'.$colspan.'">';
1.56 raeburn 6285: } else {
1.91 raeburn 6286: $output .= '<td class="'.$rightclass.'">';
1.56 raeburn 6287: }
1.1 raeburn 6288: return $output;
6289: }
6290:
6291: sub item_table_row_end {
6292: return '</td></tr>';
6293: }
6294:
6295: sub yesno_radio {
1.80 raeburn 6296: my ($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit) = @_;
1.1 raeburn 6297: my $itemon = ' ';
6298: my $itemoff = ' checked="checked" ';
1.69 raeburn 6299: if (($valueyes eq '') && ($valueno eq '')) {
6300: $valueyes = 'yes';
6301: $valueno = '';
6302: }
1.1 raeburn 6303: if (ref($settings) eq 'HASH') {
1.69 raeburn 6304: if ($settings->{$item} eq $valueyes) {
1.1 raeburn 6305: $itemon = $itemoff;
6306: $itemoff = ' ';
6307: }
1.69 raeburn 6308: unless (exists($settings->{$item})) {
6309: if ($unsetdefault eq $valueyes) {
6310: $itemon = $itemoff;
6311: $itemoff = ' ';
6312: }
6313: }
1.1 raeburn 6314: }
1.80 raeburn 6315: my $disabled;
6316: if ($noedit) {
6317: $disabled = ' disabled="disabled"';
6318: }
1.1 raeburn 6319: return '<span class="LC_nobreak"><label>'.
6320: '<input type="radio" name="'.$item.'"'.
1.80 raeburn 6321: $itemon.' value="'.$valueyes.'"'.$disabled.' />'.&mt('Yes').'</label> '.
1.1 raeburn 6322: '<label><input type="radio" name="'.$item.'"'.
1.80 raeburn 6323: $itemoff.' value="'.$valueno.'"'.$disabled.' />'.&mt('No').'</label></span>';
1.1 raeburn 6324: }
6325:
6326: sub select_from_options {
1.91 raeburn 6327: my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_;
1.1 raeburn 6328: my $output;
1.80 raeburn 6329: my $disabled;
6330: if ($noedit) {
6331: $disabled = ' disabled=disabled"';
6332: }
1.1 raeburn 6333: if ((ref($order) eq 'ARRAY') && (ref($options) eq 'HASH')) {
6334: $output='<select name="'.$item.'" '.$onchange;
6335: if ($multiple) {
6336: $output .= ' multiple="multiple"';
6337: my $num = @{$order};
6338: $num ++ if ($nullval ne '');
6339: if (($maxsize) && ($maxsize < $num)) {
6340: $output .= ' size="'.$maxsize.'"';
6341: }
6342: }
1.91 raeburn 6343: if ($id ne '') {
6344: $output .= ' id="'.$id.'"';
6345: }
1.80 raeburn 6346: $output .= $disabled.'>'."\n";
1.1 raeburn 6347: if ($nullval ne '') {
6348: $output .= '<option value=""';
6349: if (ref($curr) eq 'ARRAY') {
6350: if ((@{$curr} == 0) || (grep(/^$/,@{$curr}))) {
6351: $output .= ' selected="selected" ';
6352: }
6353: } else {
6354: if ($curr eq '') {
6355: $output .= ' selected="selected" ';
6356: }
6357: }
6358: $output .= '>'.$nullval.'</option>';
6359: }
6360: foreach my $option (@{$order}) {
6361: $output.= '<option value="'.$option.'"';
6362: if (ref($curr) eq 'ARRAY') {
6363: if (grep(/^\Q$option\E$/,@{$curr})) {
6364: $output .= ' selected="selected" ';
6365: }
6366: } else {
6367: if ($option eq $curr) {
6368: $output.=' selected="selected"';
6369: }
6370: }
6371: $output.=">$options->{$option}</option>\n";
6372: }
6373: $output.="</select>";
6374: }
6375: return $output;
6376: }
6377:
6378: sub make_item_rows {
1.80 raeburn 6379: my ($cdom,$items,$ordered,$settings,$rowtotal,$crstype,$caller,$noedit) = @_;
1.1 raeburn 6380: my $datatable;
6381: if ((ref($items) eq 'HASH') && (ref($ordered) eq 'ARRAY')) {
6382: my $count = 0;
6383: foreach my $item (@{$ordered}) {
6384: $count ++;
1.56 raeburn 6385: my $colspan;
6386: if ((($caller eq 'classlists') && ($item eq 'nothideprivileged')) ||
6387: (($caller eq 'printouts') && ($item ne 'print_header_format'))) {
6388: $colspan = 2;
6389: }
1.114 raeburn 6390: my $rowdesc;
6391: if ($caller eq 'appearance') {
6392: $rowdesc = '<span class="LC_nobreak">'.$items->{$item}{text}.'</span>';
6393: } else {
6394: $rowdesc = $items->{$item}{text};
6395: }
1.41 www 6396: if (exists $items->{$item}{advanced} && $items->{$item}{advanced} == 1) {
1.114 raeburn 6397: $datatable .= &item_table_row_start($rowdesc,$count,"advanced",$colspan);
1.41 www 6398: } else {
1.114 raeburn 6399: $datatable .= &item_table_row_start($rowdesc,$count,undef,$colspan);
1.41 www 6400: }
1.55 raeburn 6401: if ($item eq 'defaultcredits') {
6402: my $defaultcredits = $env{'course.'.$env{'request.course.id'}.'.internal.defaultcredits'};
6403: my $showcredits;
6404: if ($defaultcredits ne '') {
6405: $showcredits = &mt('Default is [quant,_1,credit]',$defaultcredits);
6406: } else {
6407: $showcredits = &mt('No default set');
6408: }
6409: $datatable .= $showcredits;
6410: } elsif ($item eq 'nothideprivileged') {
1.80 raeburn 6411: $datatable .= ¬hidepriv_row($cdom,$item,$settings,$crstype,$noedit);
1.56 raeburn 6412: } elsif ($item eq 'checkforpriv') {
1.80 raeburn 6413: $datatable .= &checkforpriv_row($cdom,$item,$settings,$crstype,$noedit);
1.1 raeburn 6414: } elsif ($item eq 'print_header_format') {
1.80 raeburn 6415: $datatable .= &print_hdrfmt_row($item,$settings,$noedit);
1.87 raeburn 6416: } elsif ($item eq 'lti.lcmenu') {
6417: $datatable .= &lcmenu_checkboxes($cdom,$item,$settings,$crstype,$noedit);
1.114 raeburn 6418: } elsif ($item eq 'extresource') {
6419: $datatable .= &print_extresource_row($item,$items->{$item},$settings->{$item},$noedit);
1.1 raeburn 6420: } elsif ($items->{$item}{input} eq 'dates') {
1.80 raeburn 6421: my $disabled;
6422: if ($noedit) {
6423: $disabled = ' disabled="disabled"';
6424: }
1.1 raeburn 6425: $datatable .=
6426: &Apache::lonhtmlcommon::date_setter('display',$item,
1.80 raeburn 6427: $settings->{$item},$disabled);
1.1 raeburn 6428: } elsif ($items->{$item}{input} eq 'radio') {
1.69 raeburn 6429: my ($unsetdefault,$valueyes,$valueno);
1.95 raeburn 6430: if (($item eq 'usejsme') || ($item eq 'uselcmath') || ($item eq 'inline_chem')) {
1.69 raeburn 6431: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
6432: unless ($domdefs{$item} eq '0') {
6433: $unsetdefault = 1;
6434: }
6435: $valueyes = "1";
6436: $valueno = "0";
1.87 raeburn 6437: } elsif (($item eq 'lti.topmenu') || ($item eq 'lti.inlinemenu')) {
6438: $valueyes = '1';
1.69 raeburn 6439: }
1.80 raeburn 6440: $datatable .= &yesno_radio($item,$settings,$unsetdefault,$valueyes,$valueno,$noedit);
1.1 raeburn 6441: } elsif ($items->{$item}{input} eq 'selectbox') {
1.91 raeburn 6442: my $id;
6443: if ($caller eq 'menuitems') {
6444: $id = $item;
6445: }
1.1 raeburn 6446: my $curr = $settings->{$item};
6447: $datatable .=
6448: &select_from_options($item,$items->{$item}{'order'},
6449: $items->{$item}{'options'},$curr,
1.80 raeburn 6450: $items->{$item}{'nullval'},
1.91 raeburn 6451: undef,undef,undef,$noedit,$id);
1.1 raeburn 6452: } elsif ($items->{$item}{input} eq 'textbox') {
1.80 raeburn 6453: my $disabled;
6454: if ($noedit) {
6455: $disabled = ' disabled=disabled"';
6456: }
1.1 raeburn 6457: $datatable .=
6458: &Apache::lonhtmlcommon::textbox($item,$settings->{$item},
1.80 raeburn 6459: $items->{$item}{size},
6460: $disabled);
1.1 raeburn 6461: }
6462: $datatable .= &item_table_row_end();
6463: }
6464: if (ref($rowtotal)) {
6465: $$rowtotal += scalar(@{$ordered});
6466: }
6467: }
6468: return $datatable;
6469: }
6470:
6471: sub nothidepriv_row {
1.80 raeburn 6472: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.1 raeburn 6473: my ($cnum) = &get_course();
1.56 raeburn 6474: my ($datatable,%nothide,@checkdoms);
1.1 raeburn 6475: if (ref($settings) eq 'HASH') {
6476: if ($settings->{$item} ne '') {
6477: foreach my $user (split(/\s*\,\s*/,$settings->{$item})) {
6478: if ($user !~ /:/) {
6479: $nothide{join(':',split(/[\@]/,$user))}=1;
6480: } else {
6481: $nothide{$user} = 1;
6482: }
6483: }
6484: }
1.56 raeburn 6485: if ($settings->{'checkforpriv'}) {
6486: @checkdoms = split(/,/,$settings->{'checkforpriv'});
6487: }
1.1 raeburn 6488: }
1.56 raeburn 6489: push(@checkdoms,$cdom);
6490: my %coursepersonnel =
6491: &Apache::lonnet::get_my_roles($cnum,$cdom,'',['previous','future','active']);
1.1 raeburn 6492: my @privusers;
6493: foreach my $person (keys(%coursepersonnel)) {
1.56 raeburn 6494: my ($uname,$udom,$role) = split(/:/,$person);
6495: my $user = $uname.':'.$udom;
6496: my ($start,$end) = split(/:/,$coursepersonnel{$person});
1.1 raeburn 6497: if ($end == -1 || $start == -1) {
6498: next;
6499: }
1.56 raeburn 6500: foreach my $dom (@checkdoms) {
6501: if (&Apache::lonnet::privileged($uname,$udom,\@checkdoms,['dc','su'])) {
6502: unless (grep(/^\Q$user\E$/,@privusers)) {
6503: push(@privusers,$user);
1.3 raeburn 6504: }
6505: }
6506: }
1.1 raeburn 6507: }
1.56 raeburn 6508: if (@privusers > 0) {
1.80 raeburn 6509: my $disabled;
6510: if ($noedit) {
6511: $disabled = ' disabled="disabled"';
6512: }
1.1 raeburn 6513: $datatable .= '<table align="right">';
6514: foreach my $user (sort(@privusers)) {
6515: my $hideon = ' checked="checked" ';
6516: my $hideoff = '';
6517: if ($nothide{$user}) {
6518: $hideoff = $hideon;
6519: $hideon = '';
6520: }
6521: my ($uname,$udom) = split(':',$user);
6522: $datatable .= '<tr><td align="left">'.
6523: &Apache::loncommon::aboutmewrapper(
6524: &Apache::loncommon::plainname($uname,$udom,'firstname'),
6525: $uname,$udom,'aboutuser').
6526: '</td><td align="left">'.
6527: '<span class="LC_nobreak"><label>'.
6528: '<input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 6529: $hideon.' value=""'.$disabled.' />'.&mt('Hidden').'</label> '.
1.69 raeburn 6530: '<label><input type="radio" name="'.$item.'_'.$user.'"'.
1.80 raeburn 6531: $hideoff.' value="yes"'.$disabled.' />'.&mt('Shown').'</label></span></td>'.
1.1 raeburn 6532: '</tr>';
6533: }
6534: $datatable .= '</table>';
6535: } else {
1.9 raeburn 6536: if ($crstype eq 'Community') {
6537: $datatable .= &mt('No Domain Coordinators have community roles');
6538: } else {
6539: $datatable .= &mt('No Domain Coordinators have course roles');
6540: }
1.1 raeburn 6541: }
6542: return $datatable;
6543: }
6544:
1.56 raeburn 6545: sub checkforpriv_row {
1.80 raeburn 6546: my ($cdom,$item,$settings,$crstype,$noedit) = @_;
1.56 raeburn 6547: my $datatable;
6548: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
6549: if (keys(%domains) == 1) {
6550: $datatable = '</td><td align="right">'.
6551: &mt("Course's domain is only domain");
6552: return $datatable;
6553: }
6554: my @excdoms = ($cdom);
6555: my $num = 0;
6556: if ($settings->{$item} eq '') {
6557: $datatable = '</td><td align="right">'.
6558: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,
1.80 raeburn 6559: 1,1,undef,undef,\@excdoms,
6560: $noedit);
1.56 raeburn 6561: } else {
6562: my @privdoms = split(/,/,$settings->{$item});
6563: my %domains=map { $_ => 1; } &Apache::lonnet::all_domains();
6564: $datatable = '</td><td align="right"><br />'.
6565: &Apache::loncommon::start_data_table();
1.80 raeburn 6566: my $disabled;
6567: if ($noedit) {
6568: $disabled = ' disabled="disabled"';
6569: }
1.56 raeburn 6570: if (@privdoms > 0) {
6571: foreach my $currdom (@privdoms) {
6572: next unless ($domains{$currdom});
6573: my $domdesc = &Apache::lonnet::domain($currdom,'description');
6574: if ($domdesc eq '') {
6575: $domdesc = $currdom;
6576: }
6577: $datatable .=
6578: &Apache::loncommon::start_data_table_row().
6579: '<td align="left"><span class="LC_nobreak">'.
6580: &mt('Domain:').'<b> '.$domdesc.
6581: '</b><input type="hidden" name="checkforpriv_'.$num.
6582: '" value="'.$currdom.'" /></span><br />'.
6583: '<span class="LC_nobreak"><label><input type="checkbox" '.
1.82 raeburn 6584: 'name="checkforpriv_delete" value="'.$num.'"'.$disabled.' />'.
6585: &mt('Delete').'</label></span></td>'.
1.56 raeburn 6586: &Apache::loncommon::end_data_table_row();
6587: $num ++;
6588: unless (grep(/^\Q$currdom\E$/,@excdoms)) {
6589: push(@excdoms,$currdom);
6590: }
6591: }
6592: }
6593: if ((scalar(keys(%domains)) - scalar(@excdoms)) > 0) {
6594: $datatable .=
6595: &Apache::loncommon::start_data_table_row().
6596: '<td align="left"><span class="LC_nobreak">'.
6597: &mt('Additional domain:'). '</span><br />'.
6598: &Apache::loncommon::select_dom_form('','checkforpriv_'.$num,1,
1.80 raeburn 6599: 1,undef,undef,\@excdoms,$noedit).
1.56 raeburn 6600: '</td>'.&Apache::loncommon::end_data_table_row();
6601: }
6602: $datatable .= &Apache::loncommon::end_data_table().
6603: '<input type="hidden" name="checkforpriv_total" value="'.$num.'" />'.
6604: '<br />';
6605: }
6606: return $datatable;
6607: }
6608:
1.1 raeburn 6609: sub print_hdrfmt_row {
1.80 raeburn 6610: my ($item,$settings,$noedit) = @_;
1.1 raeburn 6611: my @curr;
6612: my $currnum = 0;
6613: my $maxnum = 2;
6614: my $currstr;
6615: if ($settings->{$item} ne '') {
6616: $currstr .= '<b>'.&mt('Current print header:').' <span class="LC_warning"><tt>'.
6617: $settings->{$item}.'</tt></span></b><br />';
6618: my @current = split(/(%\d*[nca])/,$settings->{$item});
1.23 raeburn 6619: foreach my $val (@current) {
6620: unless ($val eq '') {
6621: push(@curr,$val);
1.1 raeburn 6622: }
6623: }
6624: $currnum = @curr;
6625: $maxnum += $currnum;
6626: }
6627:
6628: my $output = <<ENDJS;
6629:
6630: <script type="text/javascript" language="Javascript">
6631:
6632: function reOrder(chgnum) {
6633: var maxnum = $maxnum;
6634: var oldidx = 'printfmthdr_oldpos_'+chgnum;
6635: var newidx = 'printfmthdr_pos_'+chgnum;
6636: oldidx = getIndexByName(oldidx);
6637: newidx = getIndexByName(newidx);
6638: var oldpos = document.display.elements[oldidx].value;
6639: var newpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
6640: document.display.elements[oldidx].value = newpos;
6641: var chgtype = 'up';
6642: if (newpos < oldpos) {
6643: chgtype = 'down';
6644: }
6645: for (var j=0; j<maxnum; j++) {
6646: if (j != chgnum) {
6647: oldidx = 'printfmthdr_oldpos_'+j;
6648: newidx = 'printfmthdr_pos_'+j;
6649: oldidx = getIndexByName(oldidx);
6650: newidx = getIndexByName(newidx);
6651: var currpos = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
6652: var currsel = document.display.elements[newidx].selectedIndex;
6653: if (chgtype == 'up') {
6654: if ((currpos > oldpos) && (currpos <= newpos)) {
6655: document.display.elements[newidx].selectedIndex = currsel-1;
6656: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
6657: }
6658: } else {
6659: if ((currpos >= newpos) && (currpos < oldpos)) {
6660: document.display.elements[newidx].selectedIndex = currsel+1;
6661: document.display.elements[oldidx].value = document.display.elements[newidx].options[document.display.elements[newidx].selectedIndex].value;
6662: }
6663: }
6664: }
6665: }
6666: return;
6667: }
6668:
6669: function getIndexByName(item) {
6670: for (var i=0;i<document.display.elements.length;i++) {
6671: if (document.display.elements[i].name == item) {
6672: return i;
6673: }
6674: }
6675: return -1;
6676: }
6677:
6678: </script>
6679:
6680: ENDJS
1.56 raeburn 6681: $output .= '</td><td align="right"><br />'.
6682: $currstr.'<table class="LC_data_table">';
1.80 raeburn 6683: my $disabled;
6684: if ($noedit) {
6685: $disabled = ' disabled="disabled"';
6686: }
1.1 raeburn 6687: if (@curr > 0) {
6688: for (my $i=0; $i<@curr; $i++) {
6689: my $pos = $i+1;
1.10 raeburn 6690: $output .= '<tr>'.
1.1 raeburn 6691: '<td align="left"><span class="LC_nobreak">'.
1.80 raeburn 6692: &position_selector($pos,$i,$maxnum,$disabled).&mt('Delete:').
1.1 raeburn 6693: '<input type="checkbox" name="printfmthdr_del_'.$i.
1.80 raeburn 6694: '"'.$disabled.' /></span></td>';
1.1 raeburn 6695: if ($curr[$i] =~ /^%\d*[nca]$/) {
6696: my ($limit,$subst) = ($curr[$i] =~ /^%(\d*)([nca])$/);
6697: $output .= '<td align="left">'.
1.80 raeburn 6698: &substitution_selector($i,$subst,$limit,$disabled).'</td>';
1.1 raeburn 6699: } else {
6700: $output .= '<td colspan="2" align="left">'.&mt('Text').'<br />'.
6701: '<input type="textbox" name="printfmthdr_text_'.$i.'"'.
1.80 raeburn 6702: ' value="'.$curr[$i].'" size="25"'.$disabled.' /></td>';
1.1 raeburn 6703: }
1.10 raeburn 6704: $output .= '</tr>';
1.1 raeburn 6705: }
6706: }
1.80 raeburn 6707: my $pos = $currnum+1;
6708: unless ($noedit) {
6709: $output .=
6710: '<tr>'.
1.1 raeburn 6711: '<td align="left"><span class="LC_nobreak">'.
6712: &position_selector($pos,$currnum,$maxnum).
6713: '<b>'.&mt('New').'</b></span></td><td align="left">'.
6714: &substitution_selector($currnum).'</td>'.
1.10 raeburn 6715: '</tr>';
1.80 raeburn 6716: $pos ++;
1.82 raeburn 6717: $currnum ++;
6718: $output .=
1.80 raeburn 6719: '<tr>'.
1.1 raeburn 6720: '<td align="left"><span class="LC_nobreak">'.
6721: &position_selector($pos,$currnum,$maxnum).
6722: '<b>'.&mt('New').'</b></span></td>'.
6723: '<td colspan="2" align="left">'.&mt('Text').'<br />'.
6724: '<input type="textbox" name="printfmthdr_text_'.$currnum.
1.3 raeburn 6725: '" value="" size ="25" />'.
6726: '<input type="hidden" name="printfmthdr_maxnum" value="'.
6727: $maxnum.'" /></td>'.
1.80 raeburn 6728: '</tr>';
6729: }
6730: $output .= '</table><br />';
1.1 raeburn 6731: return $output;
6732: }
6733:
6734: sub position_selector {
1.80 raeburn 6735: my ($pos,$num,$maxnum,$disabled) = @_;
6736: my $output = '<select name="printfmthdr_pos_'.$num.'" onchange="reOrder('."'$num'".');"'.$disabled.'>';
1.1 raeburn 6737: for (my $j=1; $j<=$maxnum; $j++) {
6738: my $sel = '';
6739: if ($pos == $j) {
6740: $sel = ' selected="selected"';
6741: }
6742: $output .= '<option value="'.$j.'"'.$sel.'">'.$j.'</option>';
6743: }
6744: $output .= '</select><input type="hidden" name="printfmthdr_oldpos_'.$num.
6745: '" value="'.$pos.'" />';
6746: return $output;
6747: }
6748:
6749: sub substitution_selector {
1.80 raeburn 6750: my ($num,$subst,$limit,$crstype,$disabled) = @_;
1.9 raeburn 6751: my ($stunametxt,$crsidtxt);
6752: if ($crstype eq 'Community') {
6753: $stunametxt = 'member name';
6754: $crsidtxt = 'community ID',
6755: } else {
6756: $stunametxt = 'student name';
6757: $crsidtxt = 'course ID',
6758: }
1.1 raeburn 6759: my %lt = &Apache::lonlocal::texthash(
1.9 raeburn 6760: n => $stunametxt,
6761: c => $crsidtxt,
1.1 raeburn 6762: a => 'assignment note',
6763: );
6764: my $output .= &mt('Substitution').'<br />'.
1.80 raeburn 6765: '<select name="printfmthdr_sub_'.$num.'"'.$disabled.'>';
1.1 raeburn 6766: if ($subst eq '') {
6767: $output .= '<option value="" selected="selected"> </option>';
6768: }
6769: foreach my $field ('n','c','a') {
6770: my $sel ='';
6771: if ($subst eq $field) {
6772: $sel = ' selected="selected"';
6773: }
6774: $output .= '<option value="'.$field.'"'.$sel.'>'.
6775: $lt{$field}.'</option>';
6776: }
6777: $output .= '</select></td><td align="left">'.&mt('Size limit').'<br />'.
6778: '<input type="textbox" name="printfmthdr_limit_'.$num.
1.82 raeburn 6779: '" value="'.$limit.'" size="5"'.$disabled.' /></span>';
1.1 raeburn 6780: return $output;
6781: }
6782:
1.23 raeburn 6783: sub change_clone {
6784: my ($cdom,$cnum,$clonelist,$oldcloner) = @_;
6785: my $clone_crs = $cnum.':'.$cdom;
6786: if ($cnum && $cdom) {
6787: my $clone_crs = $cnum.':'.$cdom;
6788: my @allowclone;
6789: if ($clonelist =~ /,/) {
6790: @allowclone = split(',',$clonelist);
6791: } else {
6792: $allowclone[0] = $clonelist;
6793: }
6794: foreach my $currclone (@allowclone) {
6795: if (!grep(/^$currclone$/,@$oldcloner)) {
6796: if ($currclone ne '*') {
1.71 raeburn 6797: if ($currclone =~ /:/) {
6798: my ($uname,$udom) = split(/:/,$currclone);
6799: if ($uname && $udom && $uname ne '*') {
6800: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
6801: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
6802: if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
6803: if ($currclonecrs{'cloneable'} eq '') {
6804: $currclonecrs{'cloneable'} = $clone_crs;
6805: } else {
6806: $currclonecrs{'cloneable'} .= ','.$clone_crs;
6807: }
6808: &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
1.23 raeburn 6809: }
6810: }
6811: }
6812: }
6813: }
6814: }
6815: }
6816: foreach my $oldclone (@$oldcloner) {
6817: if (!grep(/^\Q$oldclone\E$/,@allowclone)) {
6818: if ($oldclone ne '*') {
1.71 raeburn 6819: if ($oldclone =~ /:/) {
6820: my ($uname,$udom) = split(/:/,$oldclone);
6821: if ($uname && $udom && $uname ne '*' ) {
6822: if (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') {
6823: my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
6824: my %newclonecrs = ();
6825: if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
6826: if ($currclonecrs{'cloneable'} =~ /,/) {
6827: my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
6828: foreach my $crs (@currclonecrs) {
6829: if ($crs ne $clone_crs) {
6830: $newclonecrs{'cloneable'} .= $crs.',';
6831: }
1.23 raeburn 6832: }
1.71 raeburn 6833: $newclonecrs{'cloneable'} =~ s/,$//;
6834: } else {
6835: $newclonecrs{'cloneable'} = '';
1.23 raeburn 6836: }
1.71 raeburn 6837: &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
1.23 raeburn 6838: }
6839: }
6840: }
6841: }
6842: }
6843: }
6844: }
6845: }
6846: return;
6847: }
6848:
1.108 raeburn 6849: sub devalidate_remote_courseprefs {
6850: my ($cdom,$cnum,$cachekeys) = @_;
6851: return unless (ref($cachekeys) eq 'HASH');
6852: my %servers = &Apache::lonnet::internet_dom_servers($cdom);
6853: my %thismachine;
6854: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
6855: my @posscached = ('courselti');
6856: if (keys(%servers)) {
6857: foreach my $server (keys(%servers)) {
6858: next if ($thismachine{$server});
6859: my @cached;
6860: foreach my $name (@posscached) {
6861: if ($cachekeys->{$name}) {
6862: push(@cached,&escape($name).':'.&escape($cdom.'_'.$cnum));
6863: }
6864: }
6865: if (@cached) {
6866: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
6867: }
6868: }
6869: }
6870: return;
6871: }
6872:
1.1 raeburn 6873: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>