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