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