--- loncom/interface/loncommon.pm 2012/12/12 22:59:12 1.1075.2.16
+++ loncom/interface/loncommon.pm 2012/07/21 22:10:23 1.1087
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1075.2.16 2012/12/12 22:59:12 raeburn Exp $
+# $Id: loncommon.pm,v 1.1087 2012/07/21 22:10:23 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -70,8 +70,6 @@ use Apache::lonclonecourse();
use LONCAPA qw(:DEFAULT :match);
use DateTime::TimeZone;
use DateTime::Locale::Catalog;
-use Authen::Captcha;
-use Captcha::reCAPTCHA;
# ---------------------------------------------- Designs
use vars qw(%defaultdesign);
@@ -887,14 +885,10 @@ sub check_uncheck_jscript {
function checkAll(field) {
if (field.length > 0) {
for (i = 0; i < field.length; i++) {
- if (!field[i].disabled) {
- field[i].checked = true;
- }
+ field[i].checked = true ;
}
} else {
- if (!field.disabled) {
- field.checked = true;
- }
+ field.checked = true
}
}
@@ -3232,7 +3226,7 @@ sub aboutmewrapper {
if (!defined($username) && !defined($domain)) {
return;
}
- return ''.$link.' ';
}
@@ -4960,19 +4954,12 @@ Inputs:
=item * $bgcolor, used to override the bgcolor on a webpage to a specific value
-=item * $no_inline_link, if true and in remote mode, don't show the
- 'Switch To Inline Menu' link
-
=item * $args, optional argument valid values are
no_auto_mt_title -> prevents &mt()ing the title arg
inherit_jsmath -> when creating popup window in a page,
should it have jsmath forced on by the
current page
-=item * $advtoolsref, optional argument, ref to an array containing
- inlineremote items to be added in "Functions" menu below
- breadcrumbs.
-
=back
Returns: A uniform header for LON-CAPA web pages.
@@ -4984,7 +4971,7 @@ other decorations will be returned.
sub bodytag {
my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
- $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
+ $no_nav_bar,$bgcolor,$args)=@_;
my $public;
if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
@@ -5026,8 +5013,6 @@ sub bodytag {
}
if (!$realm) { $realm=' '; }
-# Set messages
- my $messages=&domainlogo($domain);
my $extra_body_attr = &make_attr_string($forcereg,\%design);
@@ -5062,13 +5047,11 @@ sub bodytag {
$role = '('.$role.') ' if $role;
&get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
- if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
- return $bodytag;
- }
-
- if ($env{'request.state'} eq 'construct') { $forcereg=1; }
+ if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
+ return $bodytag;
+ }
- unless ($env{'environment.remote'} eq 'on') {
+ if ($env{'request.state'} eq 'construct') { $forcereg=1; }
# if ($env{'request.state'} eq 'construct') {
# $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
@@ -5077,13 +5060,11 @@ sub bodytag {
if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
- unless ($env{'request.noversionuri'} =~ m{/res/adm/pages/bookmarkmenu/}) {
- if ($dc_info) {
- $dc_info = qq|$dc_info |;
- }
- $bodytag .= qq|
$name $role
- $realm $dc_info
|;
- }
+ if ($dc_info) {
+ $dc_info = qq|$dc_info |;
+ }
+ $bodytag .= qq|$name $role
+ $realm $dc_info
|;
return $bodytag;
}
@@ -5111,12 +5092,6 @@ sub bodytag {
$args->{'bread_crumbs'});
} elsif ($forcereg) {
$bodytag .= &Apache::lonmenu::innerregister($forcereg);
- } else {
- $bodytag .=
- &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
- $forcereg,$args->{'group'},
- $args->{'bread_crumbs'},
- $advtoolsref);
}
}else{
# this is to seperate menu from content when there's no secondary
@@ -5126,55 +5101,6 @@ sub bodytag {
}
return $bodytag;
- }
-
-#
-# Top frame rendering, Remote is up
-#
-
- my $imgsrc = $img;
- if ($img =~ /^\/adm/) {
- $imgsrc = &lonhttpdurl($img);
- }
- my $upperleft=' ';
-
- # Explicit link to get inline menu
- my $menu= ($no_inline_link?''
- :''.&mt('Switch to Inline Menu Mode').' ');
-
- if ($dc_info) {
- $dc_info = qq|($dc_info) |;
- }
-
- unless ($env{'form.inhibitmenu'}) {
- $bodytag .= qq|$name $role
- $realm $dc_info
|;
- }
- my $funclist;
- if ($env{'request.state'} eq 'construct') {
- if (!$public){
- if ($env{'request.state'} eq 'construct') {
- $funclist = &Apache::lonhtmlcommon::scripttag(
- &Apache::lonmenu::utilityfunctions(), 'start').
- &Apache::lonhtmlcommon::scripttag('','end').
- &Apache::lonmenu::innerregister($forcereg,
- $args->{'bread_crumbs'});
- }
- }
- }
- return(<
-$upperleft
- $messages
-
-$titleinfo $dc_info $menu
-
-
-$funclist
-ENDBODY
}
sub dc_courseid_toggle {
@@ -5206,15 +5132,8 @@ sub make_attr_string {
delete($attr_ref->{$key});
}
}
- if ($env{'environment.remote'} eq 'on') {
- $attr_ref->{'onload'} =
- &Apache::lonmenu::loadevents(). $on_load;
- $attr_ref->{'onunload'}=
- &Apache::lonmenu::unloadevents().$on_unload;
- } else {
- $attr_ref->{'onload'} = $on_load;
- $attr_ref->{'onunload'}= $on_unload;
- }
+ $attr_ref->{'onload'} = $on_load;
+ $attr_ref->{'onunload'}= $on_unload;
}
my $attr_string;
@@ -5387,12 +5306,10 @@ form, .inline {
.LC_error {
color: red;
+ font-size: larger;
}
-.LC_warning {
- color: darkorange;
-}
-
+.LC_warning,
.LC_diff_removed {
color: red;
}
@@ -5555,11 +5472,11 @@ td.LC_table_cell_checkbox {
text-align: left;
}
-.LC_head_subbox, .LC_actionbox {
+.LC_head_subbox {
clear:both;
background: #F8F8F8; /* $sidebg; */
border: 1px solid $sidebg;
- margin: 0 0 10px 0;
+ margin: 0 0 10px 0;
padding: 3px;
text-align: left;
}
@@ -6635,53 +6552,15 @@ ul#LC_secondary_menu {
margin: 0;
width: 100%;
text-align: left;
- float: left;
}
ul#LC_secondary_menu li {
font-weight: bold;
line-height: 1.8em;
- border-right: 1px solid black;
- vertical-align: middle;
- float: left;
-}
-
-ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
- background-color: $data_table_light;
-}
-
-ul#LC_secondary_menu li a {
padding: 0 0.8em;
-}
-
-ul#LC_secondary_menu li ul {
- display: none;
-}
-
-ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
- display: block;
- position: absolute;
- margin: 0;
- padding: 0;
- list-style:none;
- float: none;
- background-color: $data_table_light;
- z-index: 2;
- margin-left: -1px;
-}
-
-ul#LC_secondary_menu li ul li {
- font-size: 90%;
- vertical-align: top;
- border-left: 1px solid black;
border-right: 1px solid black;
- background-color: $data_table_light
- list-style:none;
- float: none;
-}
-
-ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
- background-color: $data_table_dark;
+ display: inline;
+ vertical-align: middle;
}
ul.LC_TabContent {
@@ -7181,8 +7060,8 @@ sub headtag {
if (!$args->{'frameset'}) {
$result .= &Apache::lonhtmlcommon::htmlareaheaders();
}
- if ($args->{'force_register'}) {
- $result .= &Apache::lonmenu::registerurl(1);
+ if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
+ $result .= Apache::lonxml::display_title();
}
if (!$args->{'no_nav_bar'}
&& !$args->{'only_body'}
@@ -7391,16 +7270,12 @@ $args - additional optional args support
skip_phases -> hash ref of
head -> skip the generation
body -> skip all generation
- no_inline_link -> if true and in remote mode, don't show the
- 'Switch To Inline Menu' link
no_auto_mt_title -> prevent &mt()ing the title arg
inherit_jsmath -> when creating popup window in a page,
should it have jsmath forced on by the
current page
bread_crumbs -> Array containing breadcrumbs
bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
- group -> includes the current group, if page is for a
- specific group
=back
@@ -7413,7 +7288,7 @@ sub start_page {
#&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
$env{'internal.start_page'}++;
- my ($result,@advtools);
+ my $result;
if (! exists($args->{'skip_phases'}{'head'}) ) {
$result .= &xml_begin() . &headtag($title, $head_extra, $args);
@@ -7430,8 +7305,7 @@ sub start_page {
$args->{'function'}, $args->{'add_entries'},
$args->{'only_body'}, $args->{'domain'},
$args->{'force_register'}, $args->{'no_nav_bar'},
- $args->{'bgcolor'}, $args->{'no_inline_link'},
- $args, \@advtools);
+ $args->{'bgcolor'}, $args);
}
}
@@ -7855,7 +7729,7 @@ sub simple_error_page {
my ($r,$title,$msg) = @_;
my $page =
&Apache::loncommon::start_page($title).
- ''.&mt($msg).'
'.
+ &mt($msg).
&Apache::loncommon::end_page();
if (ref($r)) {
$r->print($page);
@@ -9490,13 +9364,13 @@ sub ask_for_embedded_content {
$toplevel = $url;
if ($args->{'context'} eq 'paste') {
($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
- ($path) =
+ ($path) =
($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
$fileloc = &Apache::lonnet::filelocation('',$toplevel);
$fileloc =~ s{^/}{};
}
}
- } elsif ($actionurl eq '/adm/dependencies') {
+ } elsif ($actionurl eq '/adm/dependencies') {
if ($env{'request.course.id'} ne '') {
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
$cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -9684,7 +9558,7 @@ sub ask_for_embedded_content {
($args->{'context'} eq 'paste')) {
$counter = scalar(keys(%existing));
$numpathchg = scalar(keys(%pathchanges));
- return ($output,$counter,$numpathchg,\%existing);
+ return ($output,$counter,$numpathchg,\%existing);
}
foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
if ($actionurl eq '/adm/dependencies') {
@@ -11427,7 +11301,7 @@ sub process_extracted_files {
}
}
} else {
- $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
+ $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
}
}
for (my $i=1; $i<=$numitems; $i++) {
@@ -11449,7 +11323,7 @@ sub process_extracted_files {
}
if ($itemidx eq '') {
$itemidx = 0;
- }
+ }
if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
if ($mapinner{$referrer{$i}}) {
$fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
@@ -11496,12 +11370,12 @@ sub process_extracted_files {
$showpath = "$relpath/$title";
} else {
$showpath = "/$title";
- }
+ }
$result .= ''.&mt('[_1] included as a dependency',$showpath).' '."\n";
- }
+ }
unless ($ishome) {
my $fetch = "$fullpath/$title";
- $fetch =~ s/^\Q$prefix$dir\E//;
+ $fetch =~ s/^\Q$prefix$dir\E//;
$prompttofetch{$fetch} = 1;
}
}
@@ -11511,7 +11385,7 @@ sub process_extracted_files {
$path,$env{'form.archive_content_'.$referrer{$i}}).' ';
}
} else {
- $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
+ $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
}
}
if (keys(%todelete)) {
@@ -13904,20 +13778,6 @@ sub init_user_environment {
\%userenv,\%domdef,\%is_adv);
}
- $userenv{'canrequest.author'} =
- &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
- 'reload','requestauthor',
- \%userenv,\%domdef,\%is_adv);
- my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
- $domain,$username);
- my $reqstatus = $reqauthor{'author_status'};
- if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
- if (ref($reqauthor{'author'}) eq 'HASH') {
- $userenv{'requestauthorqueued'} = $reqstatus.':'.
- $reqauthor{'author'}{'timestamp'};
- }
- }
-
$env{'user.environment'} = "$lonids/$cookie.id";
if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
@@ -14092,164 +13952,6 @@ sub parse_supplemental_title {
return $title;
}
-sub captcha_display {
- my ($context,$lonhost) = @_;
- my ($output,$error);
- my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
- if ($captcha eq 'original') {
- $output = &create_captcha();
- unless ($output) {
- $error = 'captcha';
- }
- } elsif ($captcha eq 'recaptcha') {
- $output = &create_recaptcha($pubkey);
- unless ($output) {
- $error = 'recaptcha';
- }
- }
- return ($output,$error);
-}
-
-sub captcha_response {
- my ($context,$lonhost) = @_;
- my ($captcha_chk,$captcha_error);
- my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
- if ($captcha eq 'original') {
- ($captcha_chk,$captcha_error) = &check_captcha();
- } elsif ($captcha eq 'recaptcha') {
- $captcha_chk = &check_recaptcha($privkey);
- } else {
- $captcha_chk = 1;
- }
- return ($captcha_chk,$captcha_error);
-}
-
-sub get_captcha_config {
- my ($context,$lonhost) = @_;
- my ($captcha,$pubkey,$privkey,$hashtocheck);
- my $hostname = &Apache::lonnet::hostname($lonhost);
- my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
- my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
- if ($context eq 'usercreation') {
- my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
- if (ref($domconfig{$context}) eq 'HASH') {
- $hashtocheck = $domconfig{$context}{'cancreate'};
- if (ref($hashtocheck) eq 'HASH') {
- if ($hashtocheck->{'captcha'} eq 'recaptcha') {
- if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
- $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
- $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
- }
- if ($privkey && $pubkey) {
- $captcha = 'recaptcha';
- } else {
- $captcha = 'original';
- }
- } elsif ($hashtocheck->{'captcha'} ne 'notused') {
- $captcha = 'original';
- }
- }
- } else {
- $captcha = 'captcha';
- }
- } elsif ($context eq 'login') {
- my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
- if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
- $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
- $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
- if ($privkey && $pubkey) {
- $captcha = 'recaptcha';
- } else {
- $captcha = 'original';
- }
- } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
- $captcha = 'original';
- }
- }
- return ($captcha,$pubkey,$privkey);
-}
-
-sub create_captcha {
- my %captcha_params = &captcha_settings();
- my ($output,$maxtries,$tries) = ('',10,0);
- while ($tries < $maxtries) {
- $tries ++;
- my $captcha = Authen::Captcha->new (
- output_folder => $captcha_params{'output_dir'},
- data_folder => $captcha_params{'db_dir'},
- );
- my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
-
- if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
- $output = ' '."\n".
- &mt('Type in the letters/numbers shown below').' '.
- ' '.
- ' ';
- last;
- }
- }
- return $output;
-}
-
-sub captcha_settings {
- my %captcha_params = (
- output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
- www_output_dir => "/captchaspool",
- db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
- numchars => '5',
- );
- return %captcha_params;
-}
-
-sub check_captcha {
- my ($captcha_chk,$captcha_error);
- my $code = $env{'form.code'};
- my $md5sum = $env{'form.crypt'};
- my %captcha_params = &captcha_settings();
- my $captcha = Authen::Captcha->new(
- output_folder => $captcha_params{'output_dir'},
- data_folder => $captcha_params{'db_dir'},
- );
- my $captcha_chk = $captcha->check_code($code,$md5sum);
- my %captcha_hash = (
- 0 => 'Code not checked (file error)',
- -1 => 'Failed: code expired',
- -2 => 'Failed: invalid code (not in database)',
- -3 => 'Failed: invalid code (code does not match crypt)',
- );
- if ($captcha_chk != 1) {
- $captcha_error = $captcha_hash{$captcha_chk}
- }
- return ($captcha_chk,$captcha_error);
-}
-
-sub create_recaptcha {
- my ($pubkey) = @_;
- my $captcha = Captcha::reCAPTCHA->new;
- return $captcha->get_options_setter({theme => 'white'})."\n".
- $captcha->get_html($pubkey).
- &mt('If either word is hard to read, [_1] will replace them.',
- ' ').
- ' ';
-}
-
-sub check_recaptcha {
- my ($privkey) = @_;
- my $captcha_chk;
- my $captcha = Captcha::reCAPTCHA->new;
- my $captcha_result =
- $captcha->check_answer(
- $privkey,
- $ENV{'REMOTE_ADDR'},
- $env{'form.recaptcha_challenge_field'},
- $env{'form.recaptcha_response_field'},
- );
- if ($captcha_result->{is_valid}) {
- $captcha_chk = 1;
- }
- return $captcha_chk;
-}
-
=pod
=back