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