--- loncom/interface/courseprefs.pm 2022/01/16 18:27:09 1.49.2.29 +++ loncom/interface/courseprefs.pm 2022/02/07 06:16:44 1.101 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set configuration settings for a course # -# $Id: courseprefs.pm,v 1.49.2.29 2022/01/16 18:27:09 raeburn Exp $ +# $Id: courseprefs.pm,v 1.101 2022/02/07 06:16:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -310,7 +310,7 @@ sub handler { idnu => 'Course ID or number', unco => 'Unique code', desc => 'Course Description', - cred => 'Student credits', + cred => 'Student credits', ownr => 'Course Owner', cown => 'Course Co-owners', catg => 'Categorize course', @@ -365,9 +365,29 @@ sub handler { } my %values=&Apache::lonnet::dump('environment',$cdom,$cnum); + my %lti=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1); + my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1); + foreach my $id (keys(%lti)) { + if (ref($lti{$id}) eq 'HASH') { + if (ref($ltienc{$id}) eq 'HASH') { + $values{'linkprotection'}{$id} = { %{$lti{$id}}, %{$ltienc{$id}} }; + } else { + $values{'linkprotection'}{$id} = $lti{$id}; + } + } + unless ($phase eq 'process') { + if (ref($values{'linkprotection'}{$id}) eq 'HASH') { + delete($values{'linkprotection'}{$id}{'secret'}); + } + } + } + if ($lti{'lock'}) { + delete($lti{'lock'}); + } my @prefs_order = ('courseinfo','localization','feedback','discussion', 'classlists','appearance','grading','printouts', - 'spreadsheet','bridgetasks','other'); + 'menuitems','linkprotection','spreadsheet','bridgetasks', + 'lti','other'); my %prefs = ( 'courseinfo' => @@ -382,7 +402,7 @@ sub handler { 'co-owners' => $lt{'cown'}, 'description' => $lt{'desc'}, 'courseid' => $lt{'idnu'}, - 'uniquecode' => $lt{'unco'}, + 'uniquecode' => $lt{'unco'}, 'categories' => $lt{'catg'}, 'hidefromcat' => $lt{'excc'}, 'cloners' => $lt{'clon'}, @@ -419,6 +439,7 @@ sub handler { { text => 'Discussion and Chat', help => 'Course_Prefs_Discussions', ordered => ['pch.roles.denied','pch.users.denied', + 'pac.roles.denied','pac.users.denied', 'plc.roles.denied','plc.users.denied', 'allow_limited_html_in_feedback', 'allow_discussion_post_editing', @@ -428,9 +449,11 @@ sub handler { 'pch.users.denied' => 'No Resource Discussion', 'plc.roles.denied' => 'No Chat room use', 'plc.users.denied' => 'No Chat room use', + 'pac.roles.denied' => 'No Anonymous Resource Discussion', + 'pac.users.denied' => 'No Anonymous Resource Discussion', allow_limited_html_in_feedback => 'Allow limited HTML in discussion', allow_discussion_post_editing => 'Users can edit/delete own discussion posts', - discussion_post_fonts => 'Discussion post fonts based on likes/unlikes', + discussion_post_fonts => 'Discussion post fonts based on likes/unlikes', }, }, 'classlists' => @@ -494,7 +517,7 @@ sub handler { help => 'Course_Prefs_Printouts', ordered => ['problem_stream_switch','suppress_tries', 'default_paper_size','print_header_format', - 'disableexampointprint'], + 'disableexampointprint','canuse_pdfforms'], itemtext => { problem_stream_switch => 'Allow problems to be split over pages', suppress_tries => 'Suppress number of tries in printing', @@ -528,6 +551,41 @@ sub handler { suppress_embed_prompt => 'Hide upload references prompt if uploading file to portfolio', }, }, + 'lti' => + { + text => 'LTI provider settings', + help => 'Course_Prefs_LTIProvider', + ordered => ['lti.override','lti.topmenu','lti.inlinemenu','lti.lcmenu'], + itemtext => { + 'lti.override' => 'Override domain defaults', + 'lti.topmenu' => 'Display LON-CAPA page header', + 'lti.inlinemenu' => 'Display LON-CAPA inline menu', + 'lti.lcmenu' => 'Menu items', + }, + }, + 'menuitems' => + { + text => 'Menu display', + help => 'Course_Prefs_Menus', + header => [{col1 => 'Default Menu', + col2 => 'Value',}, + {col1 => 'Menu collections', + col2 => 'Settings', + }], + ordered => ['menudefault','menucollections'], + itemtext => { + menudefault => 'Choose default collection of menu items for course', + menucollections => 'Menu collections', + }, + }, + 'linkprotection' => + { + text => 'Link protection', + help => 'Course_Prefs_Linkprotection', + header => [{col1 => 'Item', + col2 => 'Settings', + }], + }, 'other' => { text => 'Other settings', help => 'Course_Prefs_Other', @@ -543,10 +601,16 @@ sub handler { $cnum,undef,\@allitems, 'coursepref',$parm_permission); } elsif (($phase eq 'display') && ($parm_permission->{'display'})) { - my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values); + my $noedit; + if (ref($parm_permission) eq 'HASH') { + unless ($parm_permission->{'process'}) { + $noedit = 1; + } + } + my $jscript = &get_jscript($cid,$cdom,$phase,$crstype,\%values,$noedit); my @allitems = &get_allitems(%prefs); &Apache::lonconfigsettings::display_settings($r,$cdom,$phase,$context, - \@prefs_order,\%prefs,\%values,undef,$jscript,\@allitems,$crstype, + \@prefs_order,\%prefs,\%values,$cnum,$jscript,\@allitems,$crstype, 'coursepref',$parm_permission); } else { &Apache::lonconfigsettings::display_choices($r,$phase,$context, @@ -599,7 +663,7 @@ sub get_allitems { } sub print_config_box { - my ($r,$cdom,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_; + my ($r,$cdom,$cnum,$phase,$action,$item,$settings,$allitems,$crstype,$parm_permission) = @_; my $ordered = $item->{'ordered'}; my $itemtext = $item->{'itemtext'}; my $noedit; @@ -620,7 +684,7 @@ sub print_config_box { } $output .= ''."\n". ''; - if (($action eq 'feedback') || ($action eq 'classlists')) { + if (($action eq 'feedback') || ($action eq 'classlists') || ($action eq 'menuitems')) { $output .= ' @@ -645,6 +709,8 @@ sub print_config_box { $output .= &print_feedback('top',$cdom,$settings,$ordered,$itemtext,\$rowtotal,$noedit); } elsif ($action eq 'classlists') { $output .= &print_classlists('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit); + } elsif ($action eq 'menuitems') { + $output .= &print_menuitems('top',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit); } $output .= ' @@ -723,6 +789,12 @@ sub print_config_box { $output .= &print_spreadsheet($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit); } elsif ($action eq 'bridgetasks') { $output .= &print_bridgetasks($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit); + } elsif ($action eq 'lti') { + $output .= &print_lti($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit); + } elsif ($action eq 'menuitems') { + $output .= &print_menuitems('bottom',$cdom,$settings,$itemtext,\$rowtotal,$crstype,$noedit); + } elsif ($action eq 'linkprotection') { + $output .= &print_linkprotection($cdom,$cnum,$settings,\$rowtotal,$crstype,$noedit); } elsif ($action eq 'other') { $output .= &print_other($cdom,$settings,$allitems,\$rowtotal,$crstype,$noedit); } @@ -735,8 +807,8 @@ sub print_config_box { } sub process_changes { - my ($cdom,$action,$values,$item,$changes,$allitems,$disallowed,$crstype) = @_; - my %newvalues; + my ($cdom,$cnum,$action,$values,$item,$changes,$allitems,$disallowed,$crstype) = @_; + my (%newvalues,%lti,%ltienc,$ltiauth,$errors); if (ref($item) eq 'HASH') { if (ref($changes) eq 'HASH') { my @ordered; @@ -753,6 +825,27 @@ sub process_changes { } } } + } elsif ($action eq 'linkprotection') { + if (ref($values->{$action}) eq 'HASH') { + foreach my $id (keys(%{$values->{$action}})) { + if ($id =~ /^\d+$/) { + push(@ordered,$id); + unless (ref($values->{$action}->{$id}) eq 'HASH') { + $lti{$id} = ''; + } + } + } + } + @ordered = sort { $a <=> $b } @ordered; + if (($env{'form.linkprot_add'}) && ($env{'form.linkprot_maxnum'} =~ /^\d+$/)) { + push(@ordered,$env{'form.linkprot_maxnum'}); + } + if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) { + $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'}; + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); + $ltiauth = $domdefs{'crsltiauth'}; + } } elsif (ref($item->{'ordered'}) eq 'ARRAY') { if ($action eq 'courseinfo') { my ($can_toggle_cat,$can_categorize) = @@ -815,6 +908,221 @@ sub process_changes { $changes->{$ext_entry} = $newvalues{$ext_entry}; } } + } elsif ($action eq 'menuitems') { + my (%current,@colls); + my $next = 1; + if ($values->{'menucollections'}) { + foreach my $item (split(/;/,$values->{'menucollections'})) { + my ($num,$value) = split(/\%/,$item); + if ($num =~ /^\d+$/) { + unless (grep(/^$num$/,@colls)) { + push(@colls,$num); + } + my @entries = split(/\&/,$value); + foreach my $entry (@entries) { + my ($name,$fields) = split(/=/,$entry); + $current{$num}{$name} = $fields; + } + } + } + } + if (@colls) { + @colls = sort { $a <=> $b } @colls; + $next += $colls[-1]; + } + if ($env{'form.menucollections_add'} eq $next) { + push(@colls,$next); + } + my $currdef = $values->{'menudefault'}; + my $possdef = $env{'form.menudefault'}; + if (($possdef =~ /^\d+$/) && (grep(/^$possdef$/,@colls))) { + if ($currdef ne $possdef) { + $changes->{'menudefault'} = $possdef; + } + } elsif ($currdef) { + $changes->{'menudefault'} = ''; + } + my $menucoll; + if (@colls) { + my ($ordered,$cats) = &menuitems_categories(); + my %shortcats = &menuitems_abbreviations(); + foreach my $num (@colls) { + my ($entry,%include); + map { $include{$_}= 1; } &Apache::loncommon::get_env_multiple('form.menucollections_'.$num); + foreach my $item (@{$ordered}) { + if ($item eq 'shown') { + foreach my $type (@{$cats->{$item}}) { + $entry .= $type.'='; + if ($include{$type}) { + $entry .= 'y'; + } else { + $entry .= 'n'; + } + $entry .= '&'; + } + } else { + $entry .= $shortcats{$item}.'='; + foreach my $type (@{$cats->{$item}}) { + if ($include{$type}) { + $entry .= $type.','; + } + } + $entry =~ s/,$//; + $entry .= '&'; + } + } + $entry =~ s/\&$//; + if ($menucoll) { + $menucoll .= ';'; + } + $menucoll .= $num.'%'.$entry; + } + if ($menucoll ne $values->{'menucollections'}) { + $changes->{'menucollections'} = $menucoll; + } + } elsif ($values->{'menucollections'}) { + $changes->{'menucollections'} = ''; + } + } elsif ($action eq 'linkprotection') { + my %menutitles = <imenu_titles(); + my $switchserver = &check_switchserver($cdom,$cnum); + my (@items,%deletions,%itemids,%haschanges); + if ($env{'form.linkprot_add'}) { + my $name = $env{'form.linkprot_name_add'}; + $name =~ s/(`)/'/g; + my ($newid,$error) = &get_courselti_id($cdom,$cnum,$name); + if ($newid) { + $itemids{'add'} = $newid; + push(@items,'add'); + $haschanges{$newid} = 1; + } else { + $errors .= ''. + &mt('Failed to acquire unique ID for link protection'). + ''; + } + } + if (ref($values->{$action}) eq 'HASH') { + my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_del'); + my $maxnum = $env{'form.linkprot_maxnum'}; + for (my $i=0; $i<=$maxnum; $i++) { + my $itemid = $env{'form.linkprot_id_'.$i}; + $itemid =~ s/\D+//g; + if ($itemid) { + if (ref($values->{$action}->{$itemid}) eq 'HASH') { + push(@items,$i); + $itemids{$i} = $itemid; + if ((@todelete > 0) && (grep(/^$i$/,@todelete))) { + $deletions{$itemid} = $values->{$action}->{$itemid}->{'name'}; + } + } + } + } + } + + foreach my $idx (@items) { + my $itemid = $itemids{$idx}; + next unless ($itemid); + if (exists($deletions{$itemid})) { + $lti{$itemid} = $deletions{$itemid}; + $haschanges{$itemid} = 1; + next; + } + my %current; + if (ref($values->{$action}) eq 'HASH') { + if (ref($values->{$action}->{$itemid}) eq 'HASH') { + foreach my $key (keys(%{$values->{$action}->{$itemid}})) { + $current{$key} = $values->{$action}->{$itemid}->{$key}; + } + } + } + foreach my $inner ('name','lifetime','version') { + my $formitem = 'form.linkprot_'.$inner.'_'.$idx; + $env{$formitem} =~ s/(`)/'/g; + if ($inner eq 'lifetime') { + $env{$formitem} =~ s/[^\d.]//g; + } + unless ($idx eq 'add') { + if ($current{$inner} ne $env{$formitem}) { + $haschanges{$itemid} = 1; + } + } + if ($env{$formitem} ne '') { + $lti{$itemid}{$inner} = $env{$formitem}; + } + } + if ($ltiauth) { + my $reqitem = 'form.linkprot_requser_'.$idx; + $env{$reqitem} =~ s/(`)/'/g; + unless ($idx eq 'add') { + if ($current{'requser'} ne $env{$reqitem}) { + $haschanges{$itemid} = 1; + } + } + if ($env{$reqitem} ne '') { + $lti{$itemid}{'requser'} = $env{$reqitem}; + foreach my $inner ('mapuser','notstudent') { + my $formitem = 'form.linkprot_'.$inner.'_'.$idx; + $env{$formitem} =~ s/(`)/'/g; + if ($inner eq 'mapuser') { + if ($env{$formitem} eq 'other') { + my $mapuser = $env{'form.linkprot_customuser_'.$idx}; + $mapuser =~ s/(`)/'/g; + $mapuser =~ s/^\s+|\s+$//g; + if ($mapuser ne '') { + $lti{$itemid}{$inner} = $mapuser; + } else { + delete($lti{$itemid}{'requser'}); + last; + } + } elsif ($env{$formitem} eq 'sourcedid') { + $lti{$itemid}{$inner} = 'lis_person_sourcedid'; + } elsif ($env{$formitem} eq 'email') { + $lti{$itemid}{$inner} = 'lis_person_contact_email_primary'; + } + } else { + $lti{$itemid}{$inner} = $env{$formitem}; + } + unless ($idx eq 'add') { + if ($current{$inner} ne $lti{$itemid}{$inner}) { + $haschanges{$itemid} = 1; + } + } + } + } + } + unless ($switchserver) { + my $keyitem = 'form.linkprot_key_'.$idx; + $env{$keyitem} =~ s/(`)/'/g; + unless ($idx eq 'add') { + if ($current{'key'} ne $env{$keyitem}) { + $haschanges{$itemid} = 1; + } + } + if ($env{$keyitem} ne '') { + $lti{$itemid}{'key'} = $env{$keyitem}; + } + my $secretitem = 'form.linkprot_secret_'.$idx; + $env{$secretitem} =~ s/(`)/'/g; + if ($current{'usable'}) { + if ($env{'form.linkprot_changesecret_'.$idx}) { + if ($env{$secretitem} ne '') { + $lti{$itemid}{'secret'} = $env{$secretitem}; + $haschanges{$itemid} = 1; + } + } else { + $lti{$itemid}{'secret'} = $current{'secret'}; + } + } elsif ($env{$secretitem} ne '') { + $lti{$itemid}{'secret'} = $env{$secretitem}; + $haschanges{$itemid} = 1; + } + } + } + if (keys(%haschanges)) { + foreach my $entry (keys(%haschanges)) { + $changes->{$entry} = $lti{$entry}; + } + } } else { foreach my $entry (@ordered) { if ($entry eq 'cloners') { @@ -855,7 +1163,7 @@ sub process_changes { my $clonedom = $env{'form.cloners_newdom'}; if (&check_clone($clonedom,$disallowed) eq 'ok') { my $newdom = '*:'.$env{'form.cloners_newdom'}; - if (@clonedoms) { + if (@clonedoms) { if (!grep(/^\Q$newdom\E$/,@clonedoms)) { $newvalues{$entry} .= ','.$newdom; } @@ -1062,7 +1370,8 @@ sub process_changes { } } } - } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied')) { + } elsif (($entry eq 'plc.roles.denied') || ($entry eq 'pch.roles.denied') || + ($entry eq 'pac.roles.denied')) { my @denied = &Apache::loncommon::get_env_multiple('form.'.$entry); @denied = sort(@denied); my $deniedstr = ''; @@ -1070,7 +1379,8 @@ sub process_changes { $deniedstr = join(',',@denied); } $newvalues{$entry} = $deniedstr; - } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied')) { + } elsif (($entry eq 'plc.users.denied') || ($entry eq 'pch.users.denied') || + ($entry eq 'pac.users.denied')) { my $total = $env{'form.'.$entry.'_total'}; my $userstr = ''; my @denied; @@ -1122,14 +1432,14 @@ sub process_changes { my ($classorder,$classtitles) = &discussion_vote_classes(); my $fontchange = 0; foreach my $class (@{$classorder}) { - my $ext_entry = $entry.'_'.$class; + my $ext_entry = $entry.'_'.$class; my $size = $env{'form.'.$ext_entry.'_size'}; my $unit = $env{'form.'.$ext_entry.'_unit'}; my $weight = $env{'form.'.$ext_entry.'_weight'}; my $style = $env{'form.'.$ext_entry.'_style'}; my $other = $env{'form.'.$ext_entry.'_other'}; $size =~ s/,//g; - $unit =~ s/,//g; + $unit =~ s/,//g; $weight =~ s/,//g; $style =~ s/,//g; $other =~ s/[^\w;:\s\-\%.]//g; @@ -1137,7 +1447,7 @@ sub process_changes { $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other)); my $current = $values->{$ext_entry}; if ($values->{$ext_entry} eq '') { - $current = ',,,'; + $current = ',,,'; } if ($newvalues{$ext_entry} ne $current) { $changes->{$ext_entry} = $newvalues{$ext_entry}; @@ -1146,7 +1456,7 @@ sub process_changes { } if ($fontchange) { $changes->{$entry} = 1; - } + } } elsif ($entry eq 'nothideprivileged') { my @curr_nothide; my @new_nothide; @@ -1221,7 +1531,7 @@ sub process_changes { my $newtext = $maxnum-1; $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext}; $newvalues{$entry} = join('',@newhdr); - } elsif (($entry eq 'languages') || + } elsif (($entry eq 'languages') || ($entry eq 'checkforpriv')) { my $settings; my $total = $env{'form.'.$entry.'_total'}; @@ -1237,7 +1547,7 @@ sub process_changes { } if ($env{'form.'.$entry.'_'.$total} ne '') { my $new = $env{'form.'.$entry.'_'.$total}; - if ($entry eq 'languages') { + if ($entry eq 'languages') { my %langchoices = &get_lang_choices(); if ($langchoices{$new}) { $settings .= $new; @@ -1258,6 +1568,38 @@ sub process_changes { $settings =~ s/,$//; } $newvalues{$entry} = $settings; + } elsif ($action eq 'lti') { + if ($entry eq 'lti.override') { + $newvalues{$entry} = $env{'form.'.$entry}; + } elsif (($entry eq 'lti.topmenu') || ($entry eq 'lti.inlinemenu')) { + if ($env{'form.lti.override'}) { + $newvalues{$entry} = $env{'form.'.$entry}; + } else { + $newvalues{$entry} = ''; + } + } elsif ($entry eq 'lti.lcmenu') { + if (($env{'form.lti.override'}) && + (($env{'form.lti.topmenu'}) || ($env{'form.lti.inlinemenu'}))) { + my @lcmenu = &Apache::loncommon::get_env_multiple('form.lti.lcmenu'); + my @newlcmenu; + if (@lcmenu) { + my @menuitems = ('fullname','coursetitle','role','logout','grades'); + foreach my $item (@menuitems) { + next if (($item eq 'grades') && (!$newvalues{'lti.inlinemenu'})); + if (grep(/^\Q$item\E$/,@lcmenu)) { + push(@newlcmenu,$item); + } + } + } + if (@newlcmenu) { + $newvalues{$entry} = join(',',@newlcmenu); + } else { + $newvalues{$entry} = 'none'; + } + } else { + $newvalues{$entry} = ''; + } + } } else { $newvalues{$entry} = $env{'form.'.$entry}; } @@ -1271,7 +1613,51 @@ sub process_changes { } } } - return; + return $errors; +} + +sub get_courselti_id { + my ($cdom,$cnum,$name) = @_; + # get lock on lti db in course + my $lockhash = { + lock => $env{'user.name'}. + ':'.$env{'user.domain'}, + }; + my $tries = 0; + my $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum); + my ($id,$error); + while (($gotlock ne 'ok') && ($tries<10)) { + $tries ++; + sleep (0.1); + $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum); + } + if ($gotlock eq 'ok') { + my %currids = &Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1); + if ($currids{'lock'}) { + delete($currids{'lock'}); + if (keys(%currids)) { + my @curr = sort { $a <=> $b } keys(%currids); + if ($curr[-1] =~ /^\d+$/) { + $id = 1 + $curr[-1]; + } else { + $id = 1; + } + } else { + $id = 1; + } + if ($id) { + unless (&Apache::lonnet::newput('lti',{ $id => $name },$cdom,$cnum) eq 'ok') { + $error = 'nostore'; + } + } else { + $error = 'nonumber'; + } + } + my $dellockoutcome = &Apache::lonnet::del('lti',['lock'],$cdom,$cnum); + } else { + $error = 'nolock'; + } + return ($id,$error); } sub get_sec_str { @@ -1316,8 +1702,12 @@ sub check_clone { sub store_changes { my ($cdom,$cnum,$prefs_order,$actions,$prefs,$values,$changes,$crstype) = @_; my ($chome,$output); - my (%storehash,@delkeys,@need_env_update,@oldcloner); + my (%storehash,@delkeys,@need_env_update,@oldcloner,%oldlinkprot); if ((ref($values) eq 'HASH') && (ref($changes) eq 'HASH')) { + if (ref($values->{'linkprotection'}) eq 'HASH') { + %oldlinkprot = %{$values->{'linkprotection'}}; + } + delete($values->{'linkprotection'}); %storehash = %{$values}; } else { if ($crstype eq 'Community') { @@ -1327,6 +1717,20 @@ sub store_changes { } return $output; } + my ($numchanges,$skipstore); + if (ref($changes) eq 'HASH') { + $numchanges = scalar(keys(%{$changes})); + if (($numchanges == 1) && (exists($changes->{'linkprotection'}))) { + $skipstore = 1; + } elsif (!$numchanges) { + if ($crstype eq 'Community') { + $output = &mt('No changes made to community settings.'); + } else { + $output = &mt('No changes made to course settings.'); + } + return $output; + } + } my %yesno = ( hidefromcat => '1', problem_stream_switch => '1', @@ -1352,6 +1756,127 @@ sub store_changes { "'$storehash{$key}'")).''; } } + } elsif ($item eq 'linkprotection') { + my ($ltiauth,%ltienc,$lti_save_error); + if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) { + $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'}; + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); + $ltiauth = $domdefs{'crsltiauth'}; + } + if (ref($changes->{$item}) eq 'HASH') { + foreach my $id (sort { $a <=> $b } keys(%{$changes->{$item}})) { + if (ref($changes->{$item}->{$id}) eq 'HASH') { + if (exists($changes->{$item}->{$id}->{'key'})) { + $ltienc{$id}{'key'} = $changes->{$item}->{$id}->{'key'}; + delete($changes->{$item}->{$id}->{'key'}); + } + if (exists($changes->{$item}->{$id}->{'secret'})) { + $ltienc{$id}{'secret'} = $changes->{$item}->{$id}->{'secret'}; + delete($changes->{$item}->{$id}->{'secret'}); + } elsif (ref($oldlinkprot{$id}) eq 'HASH') { + if (exists($oldlinkprot{$id}{'usable'})) { + $changes->{$item}->{$id}->{'usable'} = 1; + } + } + } + } + } + if (keys(%ltienc) > 0) { + if (&Apache::lonnet::put('nohist_ltienc',\%ltienc,$cdom,$cnum,1) eq 'ok') { + foreach my $id (keys(%ltienc)) { + if (exists($ltienc{$id}{'secret'})) { + $changes->{$item}->{$id}->{'usable'} = 1; + } + } + } else { + $lti_save_error = 1; + } + } + unless ($lti_save_error) { + if (&Apache::lonnet::put('lti',$changes->{$item},$cdom,$cnum,1) eq 'ok') { + my $hashid=$cdom.'_'.$cnum; + &Apache::lonnet::devalidate_cache_new('courselti',$hashid); + $chome = &Apache::lonnet::homeserver($cnum,$cdom); + unless (($chome eq 'no_host') || ($chome eq '')) { + my @ids=&Apache::lonnet::current_machine_ids(); + if (grep(/^\Q$chome\E$/,@ids)) { + &Apache::lonnet::devalidate_cache_new('courseltienc',$hashid); + } + } + foreach my $id (sort { $a <=> $b } %{$changes->{$item}}) { + if (ref($changes->{$item}->{$id}) eq 'HASH') { + my %values = %{$changes->{$item}->{$id}}; + my %desc = &linkprot_names(); + my $display; + foreach my $title ('name','lifetime','version','key','secret') { + if (($title eq 'key') || ($title eq 'secret')) { + if (ref($ltienc{$id}) eq 'HASH') { + if (exists($ltienc{$id}{$title})) { + if ($title eq 'secret') { + my $length = length($ltienc{$id}{$title}); + $display .= $desc{$title}.': '.('*' x $length).', '; + } else { + $display .= $desc{$title}.': '.$ltienc{$id}{$title}.', '; + } + } + } + } elsif ($title eq 'version') { + if ($values{$title} eq 'LTI-1p0') { + $display .= $desc{$title}.': 1.1, '; + } + } else { + $display .= $desc{$title}.': '.$values{$title}.', '; + } + } + if ($ltiauth) { + if (($values{'requser'}) && ($values{'mapuser'} ne '')) { + if ($values{'mapuser'} eq 'lis_person_contact_email_primary') { + $display .= &mt('Source of username: Email address [_1]', + '(lis_person_contact_email_primary)').', '; + } elsif ($values{'mapuser'} eq 'lis_person_sourcedid') { + $display .= &mt('Source of username: User ID [_1]', + '(lis_person_sourcedid)').', '; + } else { + $display .= &mt('Source of username: [_1]',$values{'mapuser'}).', '; + } + if ($values{'notstudent'} eq 'auth') { + $display .= &mt('Display LON-CAPA login page if no match').', '; + } elsif ($values{'notstudent'} eq 'reject') { + $display .= &mt('Discontinue launch if no match').', '; + } + } + } + $display =~ s/, $//; + $output .= '
  • '.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',''.$id.'', + "'$display'")).'
  • '; + } elsif (ref($oldlinkprot{$id}) eq 'HASH') { + my $oldname = $oldlinkprot{$id}{'name'}; + $output .= '
  • '.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]',''."$id ($oldname)".'')).'
  • '; + } + } + } else { + $lti_save_error = 1; + } + } + unless ($lti_save_error) { + my @deletions; + foreach my $id (sort { $a <=> $b } keys(%{$changes->{$item}})) { + unless (ref($changes->{$item}->{$id}) eq 'HASH') { + push (@deletions,$id); + } + } + if (@deletions) { + &Apache::lonnet::del('nohist_ltienc',\@deletions,$cdom,$cnum); + } + } + if ($lti_save_error) { + $output .= '
  • '. + ''. + &mt('An error occurred when saving changes to link protection settings, which remain unchanged.'). + ''. + '
  • '; + } } else { if (ref($prefs->{$item}->{'ordered'}) eq 'ARRAY') { my @settings = @{$prefs->{$item}->{'ordered'}}; @@ -1468,6 +1993,32 @@ sub store_changes { } } $displayname = &mt($text); + } elsif ($item eq 'lti') { + if ($key eq 'lti.lcmenu') { + if ($changes->{$item}{$key} eq 'none') { + $displayval = &mt('None of the configurable menu items displayed'); + } else { + my %ltititles = <imenu_titles(); + $displayval = join(', ', map { $ltititles{$_}; } split(/,/,$changes->{$item}{$key})); + } + } else { + if ($changes->{$item}{$key} eq '1') { + $displayval = &mt('Yes'); + } elsif ($changes->{$item}{$key} eq '') { + $displayval = &mt('No'); + } + } + $displayname = &mt($text); + } elsif ($item eq 'menuitems') { + unless ($changes->{$item}{$key} eq '') { + if ($key eq 'menudefault') { + $displayname = &mt('Default collection of menu items'); + $displayval = &mt('Collection: [_1]', + $changes->{$item}{$key}); + } elsif ($key eq 'menucollections') { + $displayval = &menucollections_display($changes->{$item}{$key}); + } + } } else { $displayname = &mt($text); } @@ -1531,8 +2082,32 @@ sub store_changes { } } elsif ($changes->{$item}{$key} eq '') { push(@delkeys,$key); - $output .= '
  • '.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]', - ''.$displayname.'')).'
  • '; + if ($item eq 'lti') { + if (($key eq 'lti.override') || (($key ne 'lti.override') && ($env{'form.lti.override'} ne ''))) { + if (($key eq 'lti.lcmenu') && + ((!$env{'form.lti.topmenu'}) && (!$env{'form.lti.inlinemenu'}))) { + $output .= '
  • '.&mt('LTI settings for menu items only saved if page header and/or inline menu is set to be displayed').'
  • '; + } else { + $output .= '
  • '.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]', + ''.$displayname.'', + "'$displayval'")).'
  • '; + } + } elsif (!exists($changes->{$item}{'lti.override'})) { + $output .= '
  • '.&mt('LTI settings only saved if Override is set to "Yes"').'
  • '; + } + } elsif ($item eq 'menuitems') { + if ($key eq 'menudefault') { + $output .= '
  • '.&mt("Default collection of menu items set to: 'Standard' (all menus shown)").'
  • '; + } elsif ($key eq 'menucollections') { + $output .= '
  • '.&mt('Specific collections of menus no longer available').'
  • '; + } + } else { + $output .= '
  • '.&Apache::lonhtmlcommon::confirm_success(&mt('Deleted setting for [_1]', + ''.$displayname.'')).'
  • '; + } + } elsif ($key eq 'menucollections') { + $output .= '
  • '.&Apache::lonhtmlcommon::confirm_success(&mt('Numbered menu collections:')).'
    '. + $displayval.'
  • '; } else { $output .= '
  • '.&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]', ''.$displayname.'', @@ -1571,7 +2146,9 @@ sub store_changes { } if (($key eq 'description') || ($key eq 'cloners') || ($key eq 'hidefromcat') || ($key eq 'categories') || - ($key eq 'co-owners')) { + ($key eq 'co-owners') || ($key eq 'lti.override') || + ($key eq 'lti.topmenu') || ($key eq 'lti.inlinemenu') || + ($key eq 'lti.lcmenu')) { push(@need_env_update,$key); } } @@ -1588,6 +2165,9 @@ sub store_changes { } } } + if ($skipstore) { + return $output; + } if (&Apache::lonnet::put('environment',\%storehash,$cdom,$cnum) eq 'ok') { if (ref($changes) eq 'HASH') { if (ref($changes->{'courseinfo'}) eq 'HASH') { @@ -1655,6 +2235,8 @@ sub update_env { my @coowners = split(',',$storehash->{'internal.'.$key}); $crsinfo{$env{'request.course.id'}}{'co-owners'} = \@coowners; $count ++; + } elsif ($key =~ /^lti\./) { + &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash->{$key}}); } } if ($count) { @@ -1758,7 +2340,7 @@ sub get_course { } sub get_jscript { - my ($cid,$cdom,$phase,$crstype,$settings) = @_; + my ($cid,$cdom,$phase,$crstype,$settings,$noedit) = @_; my ($can_toggle_cat,$can_categorize) = &can_modify_catsettings($cdom,$crstype); my ($jscript,$categorize_js,$loncaparev_js,$instcode_js); my $stubrowse_js = &Apache::loncommon::studentbrowser_javascript(); @@ -1783,7 +2365,7 @@ sub get_jscript { $local_to_standard{$code_order[$i]} = $standardnames[$i]; } foreach my $cloner (@cloners) { - if (($cloner !~ /^\Q*:\E$match_domain$/) && + if (($cloner !~ /^\Q*:\E$match_domain$/) && ($cloner !~ /^$match_username\:$match_domain$/)) { foreach my $item (split(/\&/,$cloner)) { my ($key,$val) = split(/\=/,$item); @@ -1884,11 +2466,153 @@ function syllabusinfo() { } } ENDSCRIPT + my $menuitems_js; + unless ($noedit) { + my $collections; + my $next = 1; + if (ref($settings) eq 'HASH') { + if ($settings->{'menucollections'} ne '') { + my @current; + foreach my $item (split(/;/,$settings->{'menucollections'})) { + my ($num) = split(/\%/,$item); + if ($num =~ /^\d+$/) { + push(@current,$num); + } + } + $collections = join("','",sort { $a <=> $b } @current); + if ($collections) { + $collections = "'$collections'"; + } + $next += $current[-1]; + } + } + my $deftext = &mt('Standard (all menus shown)'); + $menuitems_js = < 0) { + var setvis; + for (var i=0; i 0) { + var setvis; + for (var i=0; i'."\n". + $syllabus_js."\n".$menuitems_js."\n". + $linkprotector_js."\n".'//]]>'."\n". ''."\n".$stubrowse_js."\n"; return $jscript; } @@ -2068,7 +2792,7 @@ sub print_courseinfo { &mt('Modification may make assessment data inaccessible!'). ''; $editsyllabus = &mt('[_1]Edit[_2]','', - ''); + ''); } my %items = ( 'url' => { @@ -2149,7 +2873,7 @@ sub print_courseinfo { next if (!$env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'}); } unless (($item eq 'cloners') || ($item eq 'rolenames')) { - $colspan = 2; + $colspan = 2; } $count ++; if (exists $items{$item}{advanced} && $items{$item}{advanced} == 1) { @@ -2193,7 +2917,7 @@ sub print_courseinfo { $default = '0'; } $datatable .= &new_cloners_dom_row($cdom,'0',$default); - } + } } elsif ($settings->{$item} ne '*') { my @entries = split(/,/,$settings->{$item}); if (@entries > 0) { @@ -2332,12 +3056,12 @@ sub print_courseinfo { if ($clonesrc =~ m{/$match_domain/$match_courseid}) { my %clonesrcinfo = &Apache::lonnet::coursedescription($clonesrc); if ($clonesrcinfo{'description'}) { - $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc); + $clonedfrom = $clonesrcinfo{'description'}.' '.($clonesrc); } } $datatable .= $clonedfrom; } elsif ($item eq 'uniquecode') { - my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'}; + my $code = $env{'course.'.$env{'request.course.id'}.'.internal.uniquecode'}; if ($code) { $datatable .= $code; } @@ -2384,12 +3108,12 @@ sub print_courseinfo { } elsif ($uploaded) { $datatable .= &mt('Uploaded file'); } else { - $datatable .= &mt('Standard template'); + $datatable .= &mt('Standard template'); } $datatable .= (' ' x 2). &mt('[_1]View[_2]', '', - ''); + ''); } elsif ($item eq 'loncaparev') { my $loncaparev = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'}; my $showreqd; @@ -2414,7 +3138,7 @@ sub new_cloners_dom_row { my ($output,$checkedon,$checkedoff); if ($newdom ne '') { if ($num eq $default) { - $checkedon = 'checked="checked" '; + $checkedon = 'checked="checked" '; } else { $checkedoff = 'checked="checked" '; } @@ -2565,7 +3289,7 @@ ENDSCRIPT sub display_loncaparev_constraints { my ($r,$navmap,$loncaparev,$crstype) = @_; - my ($reqdmajor,$reqdminor); + my ($reqdmajor,$reqdminor); my $cid = $env{'request.course.id'}; my $cdom = $env{'course.'.$cid.'.domain'}; my $cnum = $env{'course.'.$cid.'.num'}; @@ -2582,116 +3306,160 @@ sub display_loncaparev_constraints { $Apache::lonrelrequtils::checkcrstypes{$crstype}).''; } my (%fromparam,%rowspan,%bymap,%byresource,@scopeorder,%toshow,%allmaps, - %byresponsetype,%bysubmission,%fromblocks); + %byresponsetype,%bysubmission,%fromblocks,%bycrsrestype); @scopeorder = ('all','section/group','user'); my $now = time; my $resourcedata = &Apache::lonparmset::readdata($cnum,$cdom); if (ref($resourcedata) eq 'HASH') { foreach my $key (keys(%{$resourcedata})) { + my %found; foreach my $item (keys(%Apache::lonrelrequtils::checkparms)) { if ($key =~ /(\Q$item\E)$/) { - if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') { - my $value = $resourcedata->{$key}; - if ($item eq 'examcode') { - if (&Apache::lonnet::validCODE($value)) { - $value = 'valid'; - } else { - $value = ''; - } - } elsif ($item eq 'printstartdate') { - if ($value =~ /^\d+$/) { - if ($value > $now) { - $value = 'future'; - } - } - } elsif ($item eq 'printenddate') { - if ($value =~ /^\d+$/) { - if ($value < $now) { - $value = 'past'; - } - } - - } - my ($middle,$scope,$which,$level,$map,$resource); - if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) { - my $stdtype = &Apache::lonparmset::standard_parameter_types($item); - my $stdname = &Apache::lonparmset::standard_parameter_names($item); - my $valname = &get_param_description($stdtype,$value); - my $rev = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value}; - my $start = $cid.'.'; - if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) { - $middle = $1; - $which = $2; - $scope = 'user'; - } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) { - $middle = $1; - $which = $2; - $scope = 'section/group'; - } else { - $scope = 'all'; - } - my $what="$stdname=$valname"; - if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) { - $level = 'general'; - if ($scope eq 'all') { - if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') { - unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) { - push(@{$fromparam{$rev}{$scope}},$what); - } - } else { - push(@{$fromparam{$rev}{$scope}},$what); - } - } else { - if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') { - unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) { - push(@{$fromparam{$rev}{$scope}{$which}},$what); - } - } else { - push(@{$fromparam{$rev}{$scope}{$which}},$what); - } - } - $rowspan{$rev} ++; - } elsif ($key =~ /^\Q$start$middle\E(.+)___\(all\).\w+\.\Q$item\E$/) { - $level = 'folder'; - $map = $1; - if ($scope eq 'all') { - if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') { - unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) { - push(@{$bymap{$map}{$rev}{$scope}},$what); - } - } else { - push(@{$bymap{$map}{$rev}{$scope}},$what); - } - } else { - if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') { - unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) { - push(@{$bymap{$map}{$rev}{$scope}{$which}},$what); - } - } else { - push(@{$bymap{$map}{$rev}{$scope}{$which}},$what); - } - } - } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) { - $level = 'resource'; - $resource = $1; - if ($scope eq 'all') { - if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') { - unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) { - push(@{$byresource{$resource}{$rev}{$scope}},$what); - } - } else { - push(@{$byresource{$resource}{$rev}{$scope}},$what); - } - } else { - if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') { - unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) { - push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what); - } - } else { - push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what); - } - } - } + if (ref($Apache::lonrelrequtils::checkparms{$item}) eq 'ARRAY') { + my $value = $resourcedata->{$key}; + if ($item eq 'examcode') { + if (&Apache::lonnet::validCODE($value)) { + $value = 'valid'; + } else { + $value = ''; + } + } elsif ($item eq 'printstartdate') { + if ($value =~ /^\d+$/) { + if ($value > $now) { + $value = 'future'; + } + } + } elsif ($item eq 'printenddate') { + if ($value =~ /^\d+$/) { + if ($value < $now) { + $value = 'past'; + } + } + } + if (grep(/^\Q$value\E$/,@{$Apache::lonrelrequtils::checkparms{$item}})) { + my $stdtype = &Apache::lonparmset::standard_parameter_types($item); + $found{$item}{'valname'} = &get_param_description($stdtype,$value); + $found{$item}{'rev'} = $Apache::lonnet::needsrelease{'parameter:'.$item.':'.$value.'::'}; + } + } + } + } + foreach my $item (keys(%Apache::lonrelrequtils::checkparmvalsmatch)) { + if (ref($Apache::lonrelrequtils::checkparmvalsmatch{$item}) eq 'ARRAY') { + my $value = $resourcedata->{$key}; + foreach my $valuematch (@{$Apache::lonrelrequtils::checkparmvalsmatch{$item}}) { + if ($value =~ /$valuematch/) { + my $stdtype = &Apache::lonparmset::standard_parameter_types($item); + $found{$item}{'valname'} = &get_param_description($stdtype,$value,1); + $found{$item}{'rev'} = + $Apache::lonnet::needsrelease{'parameter:'.$item.'::'.$valuematch.':'}; + last; + } + } + } + } + foreach my $item (keys(%Apache::lonrelrequtils::checkparmnamesmatch)) { + my $regexp; + if ($item eq 'maplevelrecurse') { + $regexp = '\.(?:sequence|page)___\(rec\)\.'; + } + if ($regexp ne '') { + if ($key =~ /$regexp.*\.(\w+)$/) { + my $name = $1; + my $value = $resourcedata->{$key}; + if ($name eq 'type') { + last unless (($value eq 'problem') || ($value eq 'practice') || ($value eq 'exam') || + ($value eq 'survey') || ($value eq 'surveycred') || ($value eq 'anonsurvey') || + ($value eq 'anonsurveycred') || ($value eq 'randomizetry') || ($value eq 'library')); + } + my $stdtype = &Apache::lonparmset::standard_parameter_types($name); + $found{$name}{'valname'} = &get_param_description($stdtype,$value); + $found{$name}{'extra'} = &mt('Recursive into sub-folders'); + $found{$name}{'rev'} = + $Apache::lonnet::needsrelease{'parameter::::'.$item}; + } + } + } + foreach my $item (keys(%found)) { + my $stdname = &Apache::lonparmset::standard_parameter_names($item); + my $rev = $found{$item}{'rev'}; + my $valname = $found{$item}{'valname'}; + my $extra = $found{$item}{'extra'}; + my ($middle,$scope,$which,$level,$map,$resource); + my $start = $cid.'.'; + if ($key =~ /^\Q$start\E(\[useropt\:($match_username\:$match_domain)\]\.)/) { + $middle = $1; + $which = $2; + $scope = 'user'; + } elsif ($key =~ /^\Q$start\E(\[(\w+)\]\.)/) { + $middle = $1; + $which = $2; + $scope = 'section/group'; + } else { + $scope = 'all'; + } + my $what="$stdname=$valname"; + if ($extra) { + $what .= "
    $extra
    "; + } + if ($key =~ /^\Q$start$middle\E\w+\.\Q$item\E$/) { + $level = 'general'; + if ($scope eq 'all') { + if (ref($fromparam{$rev}{$scope}) eq 'ARRAY') { + unless(grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}})) { + push(@{$fromparam{$rev}{$scope}},$what); + } + } else { + push(@{$fromparam{$rev}{$scope}},$what); + } + } else { + if (ref($fromparam{$rev}{$scope}{$which}) eq 'ARRAY') { + unless (grep(/^\Q$what\E$/,@{$fromparam{$rev}{$scope}{$which}})) { + push(@{$fromparam{$rev}{$scope}{$which}},$what); + } + } else { + push(@{$fromparam{$rev}{$scope}{$which}},$what); + } + } + $rowspan{$rev} ++; + } elsif ($key =~ /^\Q$start$middle\E(.+)___\((all|rec)\).\w+\.\Q$item\E$/) { + $level = 'folder'; + $map = $1; + if ($scope eq 'all') { + if (ref($bymap{$map}{$rev}{$scope}) eq 'ARRAY') { + unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}})) { + push(@{$bymap{$map}{$rev}{$scope}},$what); + } + } else { + push(@{$bymap{$map}{$rev}{$scope}},$what); + } + } else { + if (ref($bymap{$map}{$rev}{$scope}{$which}) eq 'ARRAY') { + unless(grep(/^\Q$what\E$/,@{$bymap{$map}{$rev}{$scope}{$which}})) { + push(@{$bymap{$map}{$rev}{$scope}{$which}},$what); + } + } else { + push(@{$bymap{$map}{$rev}{$scope}{$which}},$what); + } + } + } elsif ($key =~ /^\Q$start$middle\E(.+)\.\w+\.\Q$item\E$/) { + $level = 'resource'; + $resource = $1; + if ($scope eq 'all') { + if (ref($byresource{$resource}{$rev}{$scope}) eq 'ARRAY') { + unless(grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}})) { + push(@{$byresource{$resource}{$rev}{$scope}},$what); + } + } else { + push(@{$byresource{$resource}{$rev}{$scope}},$what); + } + } else { + if (ref($byresource{$resource}{$rev}{$scope}{$which}) eq 'ARRAY') { + unless (grep(/^\Q$what\E$/,@{$byresource{$resource}{$rev}{$scope}{$which}})) { + push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what); + } + } else { + push(@{$byresource{$resource}{$rev}{$scope}{$which}},$what); } } } @@ -2791,7 +3559,7 @@ sub display_loncaparev_constraints { if (ref($fromblocks{$type}) eq 'HASH') { foreach my $rev (keys(%{$fromblocks{$type}})) { my ($major,$minor) = split(/\./,$rev); - ($reqdmajor,$reqdminor) = + ($reqdmajor,$reqdminor) = &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor); $output .= &Apache::loncommon::start_data_table_row(). ''.$rev.''.$lt{$type}.''; @@ -2809,18 +3577,25 @@ sub display_loncaparev_constraints { if (defined($navmap)) { my %anonsubms=&Apache::lonnet::dump('nohist_anonsurveys',$cdom,$cnum); - my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'}; + my $rev_anonsurv=$Apache::lonnet::needsrelease{'parameter:type:anonsurvey::'}; my %randtrysubms=&Apache::lonnet::dump('nohist_randomizetry',$cdom,$cnum); - my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry'}; + my $rev_randtry=$Apache::lonnet::needsrelease{'parameter:type:randomizetry::'}; + my $rev_exttool=$Apache::lonnet::needsrelease{'course:courserestype:exttool'}; my $stdtype=&Apache::lonparmset::standard_parameter_types('type'); my $stdname=&Apache::lonparmset::standard_parameter_names('type'); my $valanon=&get_param_description($stdtype,'anonsurvey'); my $valrandtry=&get_param_description($stdtype,'randomizetry'); my %checkedrev; - foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) { + foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) { my @parts = @{$res->parts()}; my $symb = $res->symb(); my $enclosing_map = &Apache::lonnet::declutter($res->enclosing_map_src()); + if ($res->is_tool()) { + my $rev = $rev_exttool; + $bycrsrestype{$symb}{$rev} = &mt('External Tool'); + $allmaps{$enclosing_map} = 1; + next; + } foreach my $part (@parts) { if (exists($anonsubms{$symb."\0".$part})) { my $rev = $rev_anonsurv; @@ -2871,7 +3646,7 @@ sub display_loncaparev_constraints { &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor, $reqdmajor,$reqdminor); $checkedrev{$key} = 1; - } + } push(@{$byresponsetype{$symb}{$rev}},$key); $allmaps{$enclosing_map} = 1; } @@ -2908,6 +3683,10 @@ sub display_loncaparev_constraints { } } } + my $suppmap = 'supplemental.sequence'; + my ($suppcount,$supptools,$errors) = (0,0,0); + ($suppcount,$supptools,$errors) = &Apache::loncommon::recurse_supplemental($cnum,$cdom, + $suppmap,$suppcount,$supptools,$errors); my $mapres_header = '

    '. &mt('Requirements for specific folders or resources'). '

    '; @@ -2922,9 +3701,9 @@ sub display_loncaparev_constraints { $r->print($start_page.$top_header); if ($output) { $r->print($output); - if (defined($navmap)) { + if (defined($navmap) || $supptools) { &show_contents_view($r,$navmap,$cid,\%toshow,\%bymap,\%byresource,\%bysubmission, - \%byresponsetype,\@scopeorder,\%lt); + \%byresponsetype,\%bycrsrestype,\@scopeorder,\%lt,$supptools); } $r->print('

    '); } else { @@ -2942,22 +3721,30 @@ sub display_loncaparev_constraints { sub show_contents_view { my ($r,$navmap,$cid,$toshow,$bymap,$byresource,$bysubmission,$byresponsetype, - $scopeorder,$lt) = @_; - if ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) || - (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0)) { - my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons"); - my $whitespace = ''; - my $icon = ''; + $bycrsrestype,$scopeorder,$lt,$supptools) = @_; + my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons"); + my $whitespace = ''; + my $showmaincontent; + if ((ref($navmap)) && + ((keys(%{$toshow}) > 0) || (keys(%{$byresource}) > 0) || + (keys(%{$bysubmission}) > 0) || (keys(%{$byresponsetype}) > 0) || + (keys(%{$bycrsrestype}) > 0))) { + $showmaincontent = 1; + } + if ($showmaincontent || $supptools) { + $r->print(&Apache::loncommon::start_data_table()); + } + if ($showmaincontent) { + my $icon = ''; my $topmap = $env{'course.'.$cid.'.url'}; - $r->print(&Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). + $r->print(&Apache::loncommon::start_data_table_header_row(). ''.&mt('Location').''.&mt('Release').''. ''.&mt('Attribute/Setting').''. &Apache::loncommon::end_data_table_header_row(). &Apache::loncommon::start_data_table_row(). ' '.$icon.' '.&mt('Main Content').''); - &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt); - $r->print(&Apache::loncommon::end_data_table_row()); + &releases_by_map($r,$bymap,$topmap,$scopeorder,$lt); + $r->print(&Apache::loncommon::end_data_table_row()); my $it=$navmap->getIterator(undef,undef,undef,1,1,undef); my $curRes; my $depth = 0; @@ -3008,6 +3795,9 @@ sub show_contents_view { if (ref($byresponsetype->{$symb}) eq 'HASH') { $rowspan += scalar(keys(%{$byresponsetype->{$symb}})); } + if (ref($bycrsrestype->{$symb}) eq 'HASH') { + $rowspan += scalar(keys(%{$bycrsrestype->{$symb}})); + } next if (!$rowspan); $icon = ''.
                             &mt('Problem').''; @@ -3072,10 +3862,37 @@ sub show_contents_view { $r->print(''); } $r->print(&Apache::loncommon::end_data_table_row()); + $newrow = 1; + } + if (ref($bycrsrestype->{$symb}) eq 'HASH') { + foreach my $rev (sort(keys(%{$bycrsrestype->{$symb}}))) { + if ($newrow) { + $r->print(&Apache::loncommon::continue_data_table_row()); + } + $r->print(''.$rev.''.$bycrsrestype->{$symb}{$rev}.''); + } + $r->print(&Apache::loncommon::end_data_table_row()); } } } } + } + if ($supptools) { + my $icon = ''; + $r->print(&Apache::loncommon::start_data_table_header_row(). + ''.&mt('Location').''.&mt('Release').''. + ''.&mt('Resource Type').''. + &Apache::loncommon::end_data_table_header_row(). + &Apache::loncommon::start_data_table_row(). + ' '.$icon.' '.&mt('Supplemental Content').''. + ''. + $Apache::lonrelrequtils::exttool{'major'}.'.'. + $Apache::lonrelrequtils::exttool{'minor'}. + ''.&mt('[quant,_1,External Tool,External Tools]', + $supptools).''. + &Apache::loncommon::end_data_table_row()); + } + if ($showmaincontent || $supptools) { $r->print(&Apache::loncommon::end_data_table()); } return; @@ -3084,7 +3901,7 @@ sub show_contents_view { sub releases_by_map { my ($r,$bymap,$url,$scopeorder,$lt) = @_; return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY')); - my $newrow = 0; + my $newrow = 0; if (ref($bymap->{$url}) eq 'HASH') { foreach my $rev (sort(keys(%{$bymap->{$url}}))) { if ($newrow) { @@ -3121,18 +3938,67 @@ sub releases_by_map { } sub get_param_description { - my ($stdtype,$value) = @_; - my $name = $value; - my $paramstrings = &Apache::lonparmset::standard_string_options($stdtype); - unless (ref($paramstrings) eq 'ARRAY') { - return $name; + my ($stdtype,$value,$regexp) = @_; + my ($name,$parammatches,$paramstrings,@possibles); + if ($stdtype =~ /^string/) { + $paramstrings = &Apache::lonparmset::standard_string_options($stdtype); + } elsif ($stdtype eq 'date_interval') { + $paramstrings = &Apache::lonparmset::standard_interval_options($stdtype); + } + if ($regexp) { + if ($stdtype =~ /^string/) { + $parammatches = &Apache::lonparmset::standard_string_matches($stdtype); + } elsif ($stdtype eq 'date_interval') { + $parammatches = &Apache::lonparmset::standard_interval_matches($stdtype); + } + if (ref($parammatches) eq 'ARRAY') { + @possibles = @{$parammatches}; + } else { + undef($regexp); + $name = $value; + } } - foreach my $possibilities (@{$paramstrings}) { + unless ($regexp) { + $name = $value; + if (ref($paramstrings) eq 'ARRAY') { + @possibles = @{$paramstrings}; + } else { + if (($stdtype eq 'date_start') || ($stdtype eq 'date_end')) { + if ($name == 0) { + $name = &mt('Never'); + } elsif (($name ne '') && ($name !~ /\D/)) { + $name = &Apache::lonlocal::locallocaltime($name); + } + } + return $name; + } + } + foreach my $possibilities (@possibles) { next unless (ref($possibilities) eq 'ARRAY'); - my ($thing, $description) = @{ $possibilities }; - if ($thing eq $value) { - $name = $description; - last; + my $gotregexmatch = ''; + if ($regexp) { + last if ($gotregexmatch); + my ($item,$pattern) = @{ $possibilities }; + if ($value =~ /$pattern/) { + if (ref($paramstrings) eq 'ARRAY') { + foreach my $possibles (@{$paramstrings}) { + next unless (ref($possibles) eq 'ARRAY'); + my ($thing,$description) = @{$possibles}; + if ($thing eq $item) { + $name = $description; + $gotregexmatch = 1; + last; + } + } + last if ($gotregexmatch); + } + } + } else { + my ($thing,$description) = @{ $possibilities }; + if ($thing eq $value) { + $name = $description; + last; + } } } return $name; @@ -3342,7 +4208,7 @@ sub print_localization { undef,$includeempty,$disabled); } else { if ($settings->{$item} eq '') { - unless ($noedit) { + unless ($noedit) { $datatable .= ''. &Apache::loncommon::select_language('languages_0','',1); } @@ -3372,15 +4238,15 @@ sub print_localization { } } unless ($noedit) { - $datatable .= + $datatable .= &Apache::loncommon::start_data_table_row(). ''. &mt('Additional language:'). '
    '. &Apache::loncommon::select_language('languages_'.$num,'',1). ''. ''.&Apache::loncommon::end_data_table_row(); - } - $datatable .= &Apache::loncommon::end_data_table().'
    '; + } + $datatable .= &Apache::loncommon::end_data_table().'
    '; } } $datatable .= &item_table_row_end(); @@ -3468,7 +4334,7 @@ sub user_table { if ($currvalue eq '') { unless ($noedit) { $output .= &select_recipient($item,'0',$cdom,$sections); - } + } } else { my $num = 0; my @curr = split(/,/,$currvalue); @@ -3620,6 +4486,20 @@ sub print_discussion { &mt('(specific user(s))'), input => 'checkbox', }, + + 'pac.roles.denied' => { + text => ''.&mt($itemtext->{'pac.roles.denied'}).''. + &Apache::loncommon::help_open_topic("Course_Disable_Anonymous_Discussion").'
    '. + &mt('(role-based)'), + input => 'checkbox', + }, + + 'pac.users.denied' => { + text => ''.&mt($itemtext->{'pac.users.denied'}).'
    '. + &mt('(specific user(s))'), + input => 'checkbox', + }, + 'allow_limited_html_in_feedback' => { text => ''.&mt($itemtext->{'allow_limited_html_in_feedback'}).'', input => 'radio', @@ -3652,7 +4532,7 @@ sub print_discussion { my $colspan; if ($item eq 'allow_limited_html_in_feedback') { $colspan = 2; - } + } $datatable .= &item_table_row_start($items{$item}{text},$count,undef,$colspan); if ($item eq 'plc.roles.denied') { $datatable .= ''. @@ -3670,6 +4550,14 @@ sub print_discussion { $datatable .= ''. &user_table($cdom,$item,undef, $settings->{$item},\%lt,$noedit); + } elsif ($item eq 'pac.roles.denied') { + $datatable .= ''. + ''.&role_checkboxes($cdom,$cnum,$item,$settings,undef,undef,$noedit). + '
    '; + } elsif ($item eq 'pac.users.denied') { + $datatable .= ''. + &user_table($cdom,$item,undef, + $settings->{$item},\%lt,$noedit); } elsif ($item eq 'allow_limited_html_in_feedback') { $datatable .= &yesno_radio($item,$settings,undef,undef,undef,$noedit); } elsif ($item eq 'allow_discussion_post_editing') { @@ -3689,7 +4577,7 @@ sub print_discussion { ''.&mt('font-size').''. ''.&mt('font-weight').''. ''.&mt('font-style').''. - ''.&mt('Other css').''. + ''.&mt('Other css').''. &Apache::loncommon::end_data_table_row(). &set_discussion_fonts($cdom,$cnum,$item,$settings,$noedit). &Apache::loncommon::end_data_table().'
    '; @@ -3741,7 +4629,7 @@ sub role_checkboxes { my $count = 0; my $disabled; if ($noedit) { - $disabled = ' disabled="disabled"'; + $disabled = ' disabled="disabled"'; } foreach my $role (@roles) { my $checked = ''; @@ -3869,7 +4757,7 @@ sub set_discussion_fonts { sub discussion_vote_classes { my $classorder = ['twoplus','oneplus','zero','oneminus','twominus']; - my %classtitles = &Apache::lonlocal::texthash( + my %classtitles = &Apache::lonlocal::texthash( 'twoplus' => 'Two sigma above mean', 'oneplus' => 'One sigma above mean', 'zero' => 'Within one sigma of mean', @@ -3935,7 +4823,7 @@ sub print_classlists { 'defaultcredits' => { text => ''.&mt($itemtext->{'defaultcredits'}).'', }, - + 'nothideprivileged' => { text => ''.&mt($itemtext->{'nothideprivileged'}).'', input => 'checkbox', @@ -4042,11 +4930,12 @@ sub print_grading { input => 'selectbox', options => { standard => &mt('Standard: shows points'), + categories => &mt('Categories: shows points according to categories'), external => &mt('External: shows number of completed parts and totals'), externalnototals => &mt('External: shows only number of completed parts'), spreadsheet => &mt('Spreadsheet: (with link to detailed scores)'), }, - order => ['standard','external','externalnototals','spreadsheet'], + order => ['standard','categories','external','externalnototals','spreadsheet'], }, 'rndseed' => { text => ''.&mt($itemtext->{'rndseed'}).''. @@ -4216,6 +5105,680 @@ sub print_bridgetasks { return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'bridgetasks',$noedit); } +sub print_lti { + my ($cdom,$settings,$ordered,$itemtext,$rowtotal,$crstype,$noedit) = @_; + unless ((ref($settings) eq 'HASH') && (ref($ordered) eq 'ARRAY') && (ref($itemtext) eq 'HASH')) { + return; + } + my @menuitems = ('fullname','coursetitle','role','logout','grades'); + my %menutitles = <imenu_titles(); + my ($domdefs,$displaydefs); + if ($env{'request.lti.login'}) { + my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); + my @domdefsmenu; + if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { + if ($lti{$env{'request.lti.login'}}{'topmenu'}) { + $domdefs = &mt('Header shown').', '; + } + if ($lti{$env{'request.lti.login'}}{'inlinemenu'}) { + $domdefs .= &mt('Inline menu shown'); + } + $domdefs =~ s/,\s$//; + if (!$domdefs) { + $domdefs = &mt('No header or inline menu shown'); + } + $domdefs = ' ('.&mt('Domain default').': '.$domdefs.')'; + if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') { + @domdefsmenu = @{$lti{$env{'request.lti.login'}}{'lcmenu'}}; + } + } + $displaydefs = &mt('Domain defaults'); + if (@domdefsmenu) { + my @diffs = &Apache::loncommon::compare_arrays(\@menuitems,\@domdefsmenu); + if (@diffs) { + my $missing; + foreach my $item (@menuitems) { + unless (grep(/^\Q$item\E$/,@domdefsmenu)) { + $missing .= ' '.$menutitles{$item}.','; + } + } + $missing =~ s/,$//; + $displaydefs .= ': '.&mt('Not shown').' --'.$missing; + } else { + $displaydefs .= ': '.&mt('All shown'); + } + } else { + $displaydefs .= ': '.&mt('Not shown').' -- '.join(', ', map { $menutitles{$_}; } @menuitems); + } + } else { + $displaydefs = &mt('Domain defaults only available in LTI context'); + } + my %items = ( + 'lti.override' => { + text => ''.&mt($itemtext->{'lti.override'}).''.$domdefs, + input => 'radio', + }, + 'lti.topmenu' => { + text => ''.&mt($itemtext->{'lti.topmenu'}).'', + input => 'radio', + }, + 'lti.inlinemenu' => { + text => ''.&mt($itemtext->{'lti.inlinemenu'}).'', + input => 'radio', + }, + 'lti.lcmenu' => { + text => ''.&mt($itemtext->{'lti.lcmenu'}).'
    '.$displaydefs, + input => 'custom', + }, + ); + return &make_item_rows($cdom,\%items,$ordered,$settings,$rowtotal,$crstype,'lti',$noedit); +} + +sub lcmenu_checkboxes { + my ($cdom,$caller,$settings,$crstype,$noedit) = @_; + my @menuitems = ('fullname','coursetitle','role','logout','grades'); + my %menutitles = <imenu_titles(); + my (@current,@domdefs); + if ($env{'request.lti.login'}) { + my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider'); + if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { + if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') { + @domdefs = @{$lti{$env{'request.lti.login'}}{'lcmenu'}}; + } + } + } + if (ref($settings) eq 'HASH') { + if ($settings->{'lti.lcmenu'}) { + unless ($settings->{'lti.lcmenu'} eq 'none') { + @current = split(',',$settings->{'lti.lcmenu'}); + } + } else { + @current = @domdefs; + } + } else { + @current = @domdefs; + } + my $numinrow = 3; + my $count = 0; + my $disabled; + if ($noedit) { + $disabled = ' disabled="disabled"'; + } + my $output = ''; + foreach my $item (@menuitems) { + my $checked = ''; + if (grep(/^\Q$item\E$/,@current)) { + $checked = ' checked="checked" '; + } + my $rem = $count%($numinrow); + if ($rem == 0) { + if ($count > 0) { + $output .= ''; + } + $output .= ''; + } + $output .= ''; + $count ++; + } + my $rem = $count%($numinrow); + my $colsleft = $numinrow - $rem; + if ($colsleft > 1 ) { + $output .= ''; + } elsif ($colsleft == 1) { + $output .= ''; + } + $output .= '
    '. + '  
    '; +} + +sub ltimenu_titles { + return &Apache::lonlocal::texthash( + fullname => 'Full name', + coursetitle => 'Course title', + role => 'Role', + logout => 'Logout', + grades => 'Grades', + ); +} + +sub print_menuitems { + my ($position,$cdom,$settings,$itemtext,$rowtotal,$crstype,$noedit) = @_; + unless ((ref($settings) eq 'HASH') && (ref($itemtext) eq 'HASH')) { + return; + } + if ($position eq 'top') { + my (%defaultmenu_options,@defaultmenu_order,$addcollection); + if ($settings->{'menucollections'} ne '') { + foreach my $item (split(/;/,$settings->{'menucollections'})) { + my ($num,$value) = split(/\%/,$item); + if ($num =~ /^\d+$/) { + $defaultmenu_options{$num} = $num; + } + } + @defaultmenu_order = sort { $a <=> $b } keys(%defaultmenu_options); + $addcollection = $defaultmenu_order[-1] + 1; + } else { + $addcollection = 1; + } + $defaultmenu_options{$addcollection} = $addcollection; + my %items = ( + 'menudefault' => { + text => ''.&mt($itemtext->{'menudefault'}).'
    '. + &mt("(can be overriden in deep-link context)"), + input => 'selectbox', + options => \%defaultmenu_options, + order => \@defaultmenu_order, + nullval => &mt('Standard (all menus shown)'), + }, + ); + return &make_item_rows($cdom,\%items,['menudefault'],$settings,$rowtotal,$crstype,'menuitems',$noedit); + } else { + my %menu; + my $count = 0; + my $next = 1; + my ($datatable,$disabled); + if ($noedit) { + $disabled = ' disabled="disabled"'; + } + + my ($ordered,$cats) = &menuitems_categories(); + my @order = @{$ordered}; + my %categories = %{$cats}; + my %menutitles = &menuitems_titles(); + my %menufields = &menuitems_fields(); + + if ($settings->{'menucollections'} ne '') { + foreach my $item (split(/;/,$settings->{'menucollections'})) { + my ($num,$value) = split(/\%/,$item); + if ($num =~ /^\d+$/) { + my @entries = split(/\&/,$value); + foreach my $entry (@entries) { + my ($name,$fields) = split(/=/,$entry); + $menu{$num}{$name} = $fields; + } + } + } + if (keys(%menu)) { + my @current = sort { $a <=> $b } keys(%menu); + $next += $current[-1]; + foreach my $num (@current) { + my %checked; + my $on = ' checked="checked"'; + foreach my $key (keys(%{$menu{$num}})) { + if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) { + if ($menu{$num}{$key} eq 'y') { + $checked{$key} = $on; + } + } else { + foreach my $field (split(/,/,$menu{$num}{$key})) { + if (exists($menufields{$field})) { + $checked{$field} = $on; + } + } + } + } + if (ref($menu{$num}) eq 'HASH') { + $datatable .= &item_table_row_start(''.$num.'',$count,'','','','LC_left_item'); + foreach my $category (@order) { + if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) { + $datatable .= '
    '.$menutitles{$category}.''."\n"; + if ($category eq 'text') { + $datatable .= ''.&mt('Header').'
    '; + } + foreach my $field (@{$categories{$category}}) { + if ($field eq 'disc') { + $datatable .= '
    '.&mt('Footer').'
    '; + } + $datatable .= '
    '; + } + $datatable .= '
    '; + } + } + $datatable .= &item_table_row_end(); + $count ++; + } + } + } + } elsif ($noedit) { + my $text = &mt('No menu collections defined for this course.'); + $datatable .= &item_table_row_start($text,$count); + } + unless ($noedit) { + my $add = ''; + $datatable .= &item_table_row_start($add,$count,'','','','LC_left_item'); + foreach my $category (@order) { + if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) { + $datatable .= ''; + } + } + $datatable .= &item_table_row_end(); + $count ++; + } + return $datatable; + } +} + +sub menuitems_abbreviations { + my %briefcats = ( + text => 'pt', + links => 'p', + list => 'ps', + inline => 's', + ); + return %briefcats; +} + +sub menuitems_categories { + my @order = ('shown','text','links','list','inline'); + my %categories = ( + shown => ['top','inline','foot','main'], + text => ['name','role','crs','disc','fdbk'], + links => ['pers','logo','menu','comm','roles','help','logout'], + list => ['about','prefs','port','wish','anno','rss'], + inline => ['cont','grades','chat','people','groups','resv','syll','feeds'], + ); + return (\@order,\%categories); +} + +sub menuitems_titles { + return &Apache::lonlocal::texthash ( + shown => 'Hierarchy', + text => 'Text', + links => 'Header links', + list => 'Drop-down list', + inline => 'Inline links', + ); +} + +sub menuitems_fields { + return &Apache::lonlocal::texthash ( + top => 'Display header', + inline => 'Display inline menu', + foot => 'Display footer', + main => 'Access to main menu', + pers => 'Personal', + logo => 'LON-CAPA', + menu => 'Home', + comm => 'Messages', + roles => 'Roles/Courses', + help => 'Help', + logout => 'Logout', + name => 'Fullname', + crs => 'Course Title', + role => 'Current Role', + disc => 'Discussion', + fdbk => 'Feedback', + about => 'Information', + prefs => 'Preferences', + port => 'Portfolio', + wish => 'Stored Links', + anno => 'Calendar', + rss => 'RSS Feeds', + cont => 'Contents', + grades => 'Grades', + chat => 'Chat', + people => 'People', + groups => 'Groups', + resv => 'Reservations', + syll => 'Syllabus', + feeds => 'Feeds', + ); +} + +sub menucollections_display { + my ($collections) = @_; + my %menu; + my ($ordered,$cats) = &menuitems_categories(); + my @order = @{$ordered}; + my %categories = %{$cats}; + my %menutitles = &menuitems_titles(); + my %menufields = &menuitems_fields(); + foreach my $item (split(/;/,$collections)) { + my ($num,$value) = split(/\%/,$item); + if ($num =~ /^\d+$/) { + my @entries = split(/\&/,$value); + foreach my $entry (@entries) { + my ($name,$fields) = split(/=/,$entry); + $menu{$num}{$name} = $fields; + } + } + } + my $output = ''; + if (keys(%menu)) { + my @current = sort { $a <=> $b } keys(%menu); + foreach my $num (@current) { + my %checked; + foreach my $key (keys(%{$menu{$num}})) { + if (($key eq 'top') || ($key eq 'inline') || ($key eq 'foot') || ($key eq 'main')) { + if ($menu{$num}{$key} eq 'y') { + $checked{$key} = 1; + } + } else { + foreach my $field (split(/,/,$menu{$num}{$key})) { + if (exists($menufields{$field})) { + $checked{$field} = 1; + } + } + } + } + if (ref($menu{$num}) eq 'HASH') { + $output .= '
    '.&mt('Collection [_1]',$num).''; + foreach my $category (@order) { + if ((ref($categories{$category}) eq 'ARRAY') && (@{$categories{$category}} > 0)) { + $output .= '
    '. + ''.$menutitles{$category}.''."\n"; + if ($category eq 'text') { + $output .= ''.&mt('Header Text').'

    '; + } + foreach my $field (@{$categories{$category}}) { + if ($field eq 'disc') { + $output .= '
    '.&mt('Footer Text').'

    '; + } + if ($checked{$field}) { + $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field}); + } else { + $output .= &Apache::lonhtmlcommon::confirm_success($menufields{$field},1); + } + $output .= '
    '; + } + $output .= '
    '; + } + } + $output .= '
    '; + } + } + } + return $output; +} + +sub print_linkprotection { + my ($cdom,$cnum,$settings,$rowtotal,$crstype,$noedit) = @_; + unless (ref($settings) eq 'HASH') { + return; + } + + my %linkprotection; + my $count = 0; + my $next = 1; + my ($datatable,$disabled,$css_class); + if ($noedit) { + $disabled = ' disabled="disabled"'; + } + my %desc = &linkprot_names(); + my %lt = &Apache::lonlocal::texthash ( + 'requ' => 'Required settings', + 'opti' => 'Optional settings', + ); + my $itemcount = 0; + + my $ltiauth; + if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) { + $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'}; + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); + $ltiauth = $domdefs{'crsltiauth'}; + } + my $switchserver = &check_switchserver($cdom,$cnum); + + if (ref($settings->{'linkprotection'}) eq 'HASH') { + if (keys(%{$settings->{'linkprotection'}})) { + my @current = sort { $a <=> $b } keys(%{$settings->{'linkprotection'}}); + $next += $current[-1]; + for (my $i=0; $i<@current; $i++) { + my $num = $current[$i]; + my %values; + if (ref($settings->{'linkprotection'}->{$num}) eq 'HASH') { + %values = %{$settings->{'linkprotection'}->{$num}}; + } else { + next; + } + my $selected; + if (($values{'version'} eq 'LTI-1p0') || ($values{'version'} eq '')) { + $selected = ' selected="selected"'; + } + $css_class = $itemcount%2?' class="LC_odd_row"':''; + $datatable .= + ''. + ''; + my ($usersty,$onclickrequser,%checkedrequser); + if ($ltiauth) { + $usersty = 'display:none'; + $onclickrequser = ' onclick="toggleLTIReqUser(this.form,'."'requser','optional','1','block','$i'".');"'; + %checkedrequser = ( + no => ' checked="checked"', + yes => '', + ); + if ($values{'requser'}) { + $checkedrequser{'yes'} = $checkedrequser{'no'}; + $checkedrequser{'no'} = ''; + } + $datatable .= '
    '.$lt{'requ'}.''; + if ($values{'requser'}) { + $usersty = 'display:inline-block'; + } + } + $datatable .= + ''.$desc{'name'}. + ': '. + (' 'x2). + ''.$desc{'version'}.': '."\n". + (' 'x2). + ''.$desc{'lifetime'}.':'; + if ($ltiauth) { + $datatable .= (' 'x2).''.$desc{'requser'}.'?'. + ' '. + ''; + } + $datatable .= '

    '; + if ($values{'key'} ne '') { + $datatable .= ''.$desc{'key'}; + if ($noedit) { + $datatable .= ': ['.&mt('not shown').']'; + } elsif ($switchserver) { + $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']'; + } else { + $datatable .= ':'; + } + $datatable .= ' '.(' 'x2); + } elsif (!$switchserver) { + $datatable .= ''.$desc{'key'}.':'. + ''. + ' '.(' 'x2); + } + if ($switchserver) { + if ($values{'usable'} ne '') { + $datatable .= '
    '. + $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'
    '. + ''.&mt('Change secret?'). + ''. + (' 'x2). + ''.(' 'x2). + ''; + } elsif ($values{'key'} eq '') { + $datatable .= ''.&mt('Key and Secret are required').' - '.&mt("submit from course's home server: [_1].",$switchserver).''."\n"; + } else { + $datatable .= ''.&mt('Secret required').' - '.&mt("submit from course's home server: [_1].",$switchserver).''."\n"; + } + } else { + if ($values{'usable'} ne '') { + $datatable .= '
    '. + $desc{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'
    '. + ''.&mt('Change?'). + ''. + (' 'x2). + '  '; + } else { + $datatable .= + ''.$desc{'secret'}.':'. + ''. + ''. + ''; + } + } + if ($ltiauth) { + $datatable .= + '
    '. + '
    '.$lt{'opti'}.''. + &linkprot_options($i,$itemcount,$disabled,\%values,\%desc). + '
    '; + } + $datatable .= ''; + $itemcount ++; + } + } + } + $css_class = $itemcount%2?' class="LC_odd_row"':''; + $datatable .= ''."\n". + ''."\n". + ''.&mt('Add').''."\n". + ''; + my ($usersty,$onclickrequser,%checkedrequser); + if ($ltiauth) { + $usersty = 'display:none'; + $onclickrequser = ' onclick="toggleLTIReqUser(this.form,'."'requser','optional','1','block','add'".');"'; + %checkedrequser = ( + no => ' checked="checked"', + yes => '', + ); + $datatable .= '
    '.$lt{'requ'}.''; + } + $datatable .= ''.$desc{'name'}. + ': '."\n". + (' 'x2). + ''.$desc{'version'}.': '."\n". + (' 'x2). + ''.$desc{'lifetime'}.': '."\n"; + if ($ltiauth) { + $datatable .= (' 'x2).''.$desc{'requser'}.'?'. + ' '. + ''; + } + $datatable .= '

    '; + if ($switchserver) { + $datatable .= ''.&mt('Key and Secret are required').' - '.&mt("submit from course's home server: [_1].",$switchserver).''."\n"; + } else { + $datatable .= ''.$desc{'key'}.': '."\n". + (' 'x2). + ''.$desc{'secret'}.':'. + ' '."\n"; + } + if ($ltiauth) { + $datatable .= '
    '. + '
    '.$lt{'opti'}.''. + &linkprot_options('add',$itemcount,$disabled,{},\%desc). + '
    '; + } + $datatable .= ''; + $$rowtotal ++; + return $datatable; +} + +sub linkprot_names { + return &Apache::lonlocal::texthash( + 'version' => 'LTI Version', + 'key' => 'Key', + 'lifetime' => 'Nonce lifetime (s)', + 'name' => 'Launcher Application', + 'secret' => 'Secret', + 'requser' => 'Use identity', + 'email' => 'Email address', + 'sourcedid' => 'User ID', + 'other' => 'Other', + 'auth' => 'Display LON-CAPA login page', + 'reject' => 'Discontinue launch process', + ); +} + +sub check_switchserver { + my ($cdom,$cnum) = @_; + my ($allowed,$switchserver); + my $home = &Apache::lonnet::homeserver($cnum,$cdom); + unless ($home eq 'no_host') { + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } } + if (!$allowed) { + $switchserver=''.&mt('Switch Server').''; + } + } + return $switchserver; +} + +sub linkprot_options { + my ($num,$itemcount,$disabled,$current,$desc) = @_; + my %lt; + if (ref($desc) eq 'HASH') { + %lt = %{$desc}; + } + my $userfieldsty = 'none'; + my (%checked,$userfield); + $checked{'sourcedid'} = ' checked="checked"'; + $checked{'reject'} = ' checked="checked"'; + if (ref($current) eq 'HASH') { + if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) { + $checked{'sourcedid'} = ''; + if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') { + $checked{'email'} = ' checked="checked"'; + } else { + $checked{'other'} = ' checked="checked"'; + $userfield = $current->{'mapuser'}; + $userfieldsty = 'inline-block'; + } + } + if (($current->{'notstudent'} ne '') && ($current->{'notstudent'} ne 'reject')) { + $checked{'reject'} = ''; + $checked{'auth'} = ' checked="checked"'; + } + } + my $onclickuser = ' onclick="toggleLTIReqUser(this.form,'."'mapuser','userfield','other','inline-block','$num'".');"'; + my $output = '
    '. + &mt('Source of LON-CAPA username in LTI request').': '; + foreach my $option ('sourcedid','email','other') { + $output .= ''. + ($option eq 'other' ? '' : (' 'x2) ); + } + $output .= '
    '. + '
    '. + '
    '; + $output .= '
    '. + '
    '. + &mt('Action when username is not for an enrolled student').': '; + foreach my $option ('reject','auth') { + $output .= ''. + ($option eq 'auth' ? '' : (' 'x2) ); + } + $output .= '
    '; + return $output; +} + sub print_other { my ($cdom,$settings,$allitems,$rowtotal,$crstype,$noedit) = @_; unless ((ref($settings) eq 'HASH') && (ref($allitems) eq 'ARRAY')) { @@ -4267,17 +5830,23 @@ sub get_other_items { } sub item_table_row_start { - my ($text,$count,$add_class,$colspan) = @_; + my ($text,$count,$add_class,$colspan,$leftclass,$rightclass) = @_; my $output; my $css_class = ($count % 2) ? 'LC_odd_row' : 'LC_even_row'; $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq ''); + if ($leftclass eq '') { + $leftclass = 'LC_left_item'; + } + if ($rightclass eq '') { + $rightclass = 'LC_right_item'; + } $output .= ''."\n". - ''.$text. + ''.$text. ''; - if ($colspan) { - $output .= ''; + if ($colspan > 1) { + $output .= ''; } else { - $output .= ''; + $output .= ''; } return $output; } @@ -4318,7 +5887,7 @@ sub yesno_radio { } sub select_from_options { - my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit) = @_; + my ($item,$order,$options,$curr,$nullval,$multiple,$maxsize,$onchange,$noedit,$id) = @_; my $output; my $disabled; if ($noedit) { @@ -4334,6 +5903,9 @@ sub select_from_options { $output .= ' size="'.$maxsize.'"'; } } + if ($id ne '') { + $output .= ' id="'.$id.'"'; + } $output .= $disabled.'>'."\n"; if ($nullval ne '') { $output .= '