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