--- loncom/interface/loncommon.pm 2013/06/05 13:25:41 1.1075.2.39 +++ loncom/interface/loncommon.pm 2013/07/11 18:24:31 1.1138 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1075.2.39 2013/06/05 13:25:41 raeburn Exp $ +# $Id: loncommon.pm,v 1.1138 2013/07/11 18:24:31 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -72,6 +72,7 @@ use Apache::lonuserstate(); use LONCAPA qw(:DEFAULT :match); use DateTime::TimeZone; use DateTime::Locale::Catalog; +use Text::Aspell; use Authen::Captcha; use Captcha::reCAPTCHA; @@ -158,6 +159,7 @@ sub ssi_with_retries { # ----------------------------------------------- Filetypes/Languages/Copyright my %language; my %supported_language; +my %supported_codes; my %latex_language; # For choosing hyphenation in my %latex_language_bykey; # for choosing hyphenation from metadata my %cprtag; @@ -192,14 +194,15 @@ BEGIN { while (my $line = <$fh>) { next if ($line=~/^\#/); chomp($line); - my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line)); + my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line)); $language{$key}=$val.' - '.$enc; if ($sup) { $supported_language{$key}=$sup; + $supported_codes{$key} = $code; } if ($latex) { $latex_language_bykey{$key} = $latex; - $latex_language{$two} = $latex; + $latex_language{$code} = $latex; } } close($fh); @@ -663,7 +666,7 @@ if (!Array.prototype.indexOf) { var n = 0; if (arguments.length > 0) { n = Number(arguments[1]); - if (n !== n) { // shortcut for verifying if it's NaN + if (n !== n) { // shortcut for verifying if it is NaN n = 0; } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { n = (n > 0 || -1) * Math.floor(Math.abs(n)); @@ -899,12 +902,12 @@ sub check_uncheck_jscript { function checkAll(field) { if (field.length > 0) { for (i = 0; i < field.length; i++) { - if (!field[i].disabled) { + if (!field[i].disabled) { field[i].checked = true; } } } else { - if (!field.disabled) { + if (!field.disabled) { field.checked = true; } } @@ -1014,6 +1017,33 @@ sub select_language { =pod + +=item * &list_languages() + +Returns an array reference that is suitable for use in language prompters. +Each array element is itself a two element array. The first element +is the language code. The second element a descsriptiuon of the +language itself. This is suitable for use in e.g. +&Apache::edit::select_arg (once dereferenced that is). + +=cut + +sub list_languages { + my @lang_choices; + + foreach my $id (&languageids()) { + my $code = &supportedlanguagecode($id); + if ($code) { + my $selector = $supported_codes{$id}; + my $description = &plainlanguagedescription($id); + push (@lang_choices, [$selector, $description]); + } + } + return \@lang_choices; +} + +=pod + =item * &linked_select_forms(...) linked_select_forms returns a string containing a block @@ -2161,7 +2191,7 @@ sub select_level_form { =pod -=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoma,$excdoms) +=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) Returns a string containing a \n"; foreach my $dom (@domains) { @@ -2319,6 +2349,8 @@ Outputs: =item * $clientos +=item * $clientmobile + =back =back @@ -2337,6 +2369,7 @@ sub decode_user_agent { my $clientversion='0'; my $clientmathml=''; my $clientunicode='0'; + my $clientmobile=0; for (my $i=0;$i<=$#browsertype;$i++) { my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]); if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) { @@ -2359,8 +2392,11 @@ sub decode_user_agent { ($httpbrowser=~/powerpc/i)) { $clientos='mac'; } if ($httpbrowser=~/win/i) { $clientos='win'; } if ($httpbrowser=~/embed/i) { $clientos='pda'; } + if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) { + $clientmobile=lc($1); + } return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml, - $clientunicode,$clientos,); + $clientunicode,$clientos,$clientmobile); } ############################################################### @@ -2527,7 +2563,7 @@ sub authform_nochange { kerb_def_dom => 'MSU.EDU', @_, ); - my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); + my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); my $result; if (!$authnum) { $result = &mt('Under your current role you are not permitted to change login settings for this user'); @@ -3023,13 +3059,77 @@ sub get_related_words { untie %thesaurus_db; return @Words; } +############################################################### +# +# Spell checking +# =pod +=head1 Spell checking + +=over 4 + +=item * &check_spelling($wordlist $language) + +Takes a string containing words and feeds it to an external +spellcheck program via a pipeline. Returns a string containing +them mis-spelled words. + +Parameters: + +=over 4 + +=item - $wordlist + +String that will be fed into the spellcheck program. + +=item - $language + +Language string that specifies the language for which the spell +check will be performed. + =back +=back + +Note: This sub assumes that aspell is installed. + + =cut + +=pod + +=back + +=cut + +sub check_spelling { + my ($wordlist, $language) = @_; + my @misspellings; + + # Generate the speller and set the langauge. + # if explicitly selected: + + my $speller = Text::Aspell->new; + if ($language) { + $speller->set_option('lang', $language); + } + + # Turn the word list into an array of words by splittingon whitespace + + my @words = split(/\s+/, $wordlist); + + foreach my $word (@words) { + if(! $speller->check($word)) { + push(@misspellings, $word); + } + } + return join(' ', @misspellings); + +} + # -------------------------------------------------------------- Plaintext name =pod @@ -4838,7 +4938,7 @@ sub designparm { Inputs: $url (usually will be undef). -Returns: Path to Construction Space containing the resource or +Returns: Path to Authoring Space containing the resource or directory being viewed (or for which action is being taken). If $url is provided, and begins /priv// the path will be that portion of the $context argument. @@ -4901,7 +5001,7 @@ Input: (optional) filename from which br is appropriate for use in building the breadcrumb trail. Returns: HTML div with CSTR path and recent box - To be included on Construction Space pages + To be included on Authoring Space pages =cut @@ -4932,7 +5032,7 @@ sub CSTR_pageheader { my $output = '
' .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it? - .''.&mt('Construction Space:').' ' + .''.&mt('Authoring Space:').' ' .'
' #FIXME lonpubdir: target="_parent" .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef); @@ -4991,9 +5091,6 @@ 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, @@ -5015,7 +5112,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,$advtoolsref)=@_; my $public; if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) @@ -5088,23 +5185,7 @@ sub bodytag { $role = '('.$role.')' if $role; - if ($env{'request.state'} eq 'construct') { $forcereg=1; } - - - - my $funclist; - if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) { - $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions(), 'start')."\n". - Apache::lonmenu::serverform(); - my $forbodytag; - &Apache::lonmenu::prepare_functions($env{'request.noversionuri'}, - $forcereg,$args->{'group'}, - $args->{'bread_crumbs'}, - $advtoolsref,'',\$forbodytag); - unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') { - $funclist = $forbodytag; - } - } else { + 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 @@ -5116,11 +5197,11 @@ sub bodytag { my ($left,$right) = Apache::lonmenu::primary_menu(); if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { - if ($dc_info) { + if ($dc_info) { $dc_info = qq|$dc_info|; - } - $bodytag .= qq|
$left $role
- $realm $dc_info
|; + } + $bodytag .= qq|
$left $role
+ $realm $dc_info
|; return $bodytag; } @@ -5143,18 +5224,15 @@ sub bodytag { if ($env{'request.state'} eq 'construct') { $bodytag .= &Apache::lonmenu::innerregister($forcereg, $args->{'bread_crumbs'}); - } elsif ($forcereg) { + } elsif ($forcereg) { $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef, $args->{'group'}); } else { - my $forbodytag; - &Apache::lonmenu::prepare_functions($env{'request.noversionuri'}, - $forcereg,$args->{'group'}, - $args->{'bread_crumbs'}, - $advtoolsref,'',\$forbodytag); - unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') { - $bodytag .= $forbodytag; - } + $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 @@ -5164,50 +5242,6 @@ sub bodytag { } return $bodytag; - } - -# -# Top frame rendering, Remote is up -# - - my $imgsrc = $img; - if ($img =~ /^\/adm/) { - $imgsrc = &lonhttpdurl($img); - } - my $upperleft=''.$function.''; - - # 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)|; - } - - my $name = &plainname($env{'user.name'},$env{'user.domain'}); - unless ($public) { - $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'}, - undef,'LC_menubuttons_link'); - } - - unless ($env{'form.inhibitmenu'}) { - $bodytag .= qq|
$name $role
-
    -
  1. $menu
  2. -
$realm $dc_info
|; - } - 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 $bodytag."\n".$funclist; } sub dc_courseid_toggle { @@ -5239,15 +5273,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; @@ -6688,7 +6715,6 @@ ul#LC_secondary_menu li { font-weight: bold; line-height: 1.8em; border-right: 1px solid black; - vertical-align: middle; float: left; } @@ -7248,8 +7274,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'} @@ -7292,6 +7318,11 @@ ADDMETA .'' .$inhibitprint .$head_extra; + if ($env{'browser.mobile'}) { + $result .= ' + +'; + } return $result.''; } @@ -7458,16 +7489,14 @@ $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 + group -> includes the current group, if page is for a + specific group =back @@ -7497,8 +7526,8 @@ 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, + \@advtools); } } @@ -7538,11 +7567,6 @@ sub start_page { }else{ $result .= &Apache::lonhtmlcommon::breadcrumbs(); } - } elsif (($env{'environment.remote'} eq 'on') && - ($env{'form.inhibitmenu'} ne 'yes') && - ($env{'request.noversionuri'} =~ m{^/res/}) && - ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) { - $result .= '

'; } return $result; } @@ -7684,7 +7708,7 @@ sub modal_adhoc_inner { my $innerwidth=$width-20; $content=&js_ready( &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}). - &start_scrollbox($width.'px',$innerwidth.'px',$height.'px'). + &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','modal'). $content. &end_scrollbox(). &end_page() @@ -7904,20 +7928,76 @@ sub validate_page { sub start_scrollbox { - my ($outerwidth,$width,$height,$id,$bgcolor)=@_; + my ($outerwidth,$width,$height,$id,$bgcolor,$cursor) = @_; unless ($outerwidth) { $outerwidth='520px'; } unless ($width) { $width='500px'; } unless ($height) { $height='200px'; } my ($table_id,$div_id,$tdcol); if ($id ne '') { $table_id = " id='table_$id'"; - $div_id = " id='div_$id'"; + $div_id = ' id="div_'.$id.'"'; } if ($bgcolor ne '') { $tdcol = "background-color: $bgcolor;"; } + my $nicescroll_js; + if ($env{'browser.mobile'}) { + my %options; + if (ref($cursor) eq 'HASH') { + %options = %{$cursor}; + } + unless ($options{'railalign'} =~ /^left|right$/) { + $options{'railalign'} = 'left'; + } + unless ($options{'cursorcolor'} =~ /^\#\w+$/) { + my $function = &get_users_function(); + $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'}); + unless ($options{'cursorcolor'} =~ /^\#\w+$/) { + $options{'cursorcolor'} = '#00F'; + } + } + if ($options{'cursoropacity'} =~ /^[\d.]+$/) { + unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) { + $options{'cursoropacity'}='1.0'; + } + } else { + $options{'cursoropacity'}='1.0'; + } + if ($options{'cursorfixedheight'} eq 'none') { + delete($options{'cursorfixedheight'}); + } else { + unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; } + } + unless ($options{'railoffset'} =~ /^{[\w\:\d]+}$/) { + delete($options{'railoffset'}); + } + my @niceoptions; + while (my($key,$value) = each(%options)) { + if ($value =~ /^\{.+\}$/) { + push(@niceoptions,$key.':'.$value); + } else { + push(@niceoptions,$key.':"'.$value.'"'); + } + } + $nicescroll_js = ' + +'; + } + return <<"END"; -
+$nicescroll_js + +
+
END } @@ -8234,7 +8314,7 @@ sub get_sections { } } - if ($check_students) { + if ($check_students) { my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum); my $sec_index = &Apache::loncoursedata::CL_SECTION(); my $status_index = &Apache::loncoursedata::CL_STATUS(); @@ -8548,11 +8628,16 @@ sub get_user_info { =item * &get_user_quota() -Retrieves quota assigned for storage of portfolio files for a user +Retrieves quota assigned for storage of user files. +Default is to report quota for portfolio files. Incoming parameters: 1. user's username 2. user's domain +3. quota name - portfolio, author, or course + (if no quota name provided, defaults to portfolio). +4. crstype - official, unofficial or community, if quota name is + course Returns: 1. Disk quota (in Mb) assigned to student. @@ -8566,7 +8651,7 @@ Returns: If a value has been stored in the user's environment, it will return that, otherwise it returns the maximal default -defined for the user's instituional status(es) in the domain. +defined for the user's institutional status(es) in the domain. =cut @@ -8574,7 +8659,7 @@ defined for the user's instituional stat sub get_user_quota { - my ($uname,$udom) = @_; + my ($uname,$udom,$quotaname,$crstype) = @_; my ($quota,$quotatype,$settingstatus,$defquota); if (!defined($udom)) { $udom = $env{'user.domain'}; @@ -8589,27 +8674,57 @@ sub get_user_quota { $defquota = 0; } else { my $inststatus; - if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) { - $quota = $env{'environment.portfolioquota'}; - $inststatus = $env{'environment.inststatus'}; - } else { - my %userenv = - &Apache::lonnet::get('environment',['portfolioquota', - 'inststatus'],$udom,$uname); - my ($tmp) = keys(%userenv); - if ($tmp !~ /^(con_lost|error|no_such_host)/i) { - $quota = $userenv{'portfolioquota'}; - $inststatus = $userenv{'inststatus'}; - } else { - undef(%userenv); - } - } - ($defquota,$settingstatus) = &default_quota($udom,$inststatus); - if ($quota eq '') { - $quota = $defquota; - $quotatype = 'default'; + if ($quotaname eq 'course') { + if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) && + ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) { + $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'}; + } else { + my %cenv = &Apache::lonnet::coursedescription("$udom/$uname"); + $quota = $cenv{'internal.uploadquota'}; + } } else { - $quotatype = 'custom'; + if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) { + if ($quotaname eq 'author') { + $quota = $env{'environment.authorquota'}; + } else { + $quota = $env{'environment.portfolioquota'}; + } + $inststatus = $env{'environment.inststatus'}; + } else { + my %userenv = + &Apache::lonnet::get('environment',['portfolioquota', + 'authorquota','inststatus'],$udom,$uname); + my ($tmp) = keys(%userenv); + if ($tmp !~ /^(con_lost|error|no_such_host)/i) { + if ($quotaname eq 'author') { + $quota = $userenv{'authorquota'}; + } else { + $quota = $userenv{'portfolioquota'}; + } + $inststatus = $userenv{'inststatus'}; + } else { + undef(%userenv); + } + } + } + if ($quota eq '' || wantarray) { + if ($quotaname eq 'course') { + my %domdefs = &Apache::lonnet::get_domain_defaults($udom); + if (($crstype eq 'official') || ($crstype eq 'unofficial') || ($crstype eq 'community')) { + $defquota = $domdefs{$crstype.'quota'}; + } + if ($defquota eq '') { + $defquota = 500; + } + } else { + ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname); + } + if ($quota eq '') { + $quota = $defquota; + $quotatype = 'default'; + } else { + $quotatype = 'custom'; + } } } if (wantarray) { @@ -8634,7 +8749,9 @@ Incoming parameters: status types (e.g., faculty, staff, student etc.) which apply to the user for whom the default is being retrieved. If the institutional status string in undefined, the domain - default quota will be returned. + default quota will be returned. +3. quota name - portfolio, author, or course + (if no quota name provided, defaults to portfolio). Returns: 1. Default disk quota (in Mb) for user portfolios in the domain. @@ -8658,25 +8775,29 @@ default quota returned. sub default_quota { - my ($udom,$inststatus) = @_; + my ($udom,$inststatus,$quotaname) = @_; my ($defquota,$settingstatus); my %quotahash = &Apache::lonnet::get_dom('configuration', ['quotas'],$udom); + my $key = 'defaultquota'; + if ($quotaname eq 'author') { + $key = 'authorquota'; + } if (ref($quotahash{'quotas'}) eq 'HASH') { if ($inststatus ne '') { my @statuses = map { &unescape($_); } split(/:/,$inststatus); foreach my $item (@statuses) { - if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') { - if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') { + if (ref($quotahash{'quotas'}{$key}) eq 'HASH') { + if ($quotahash{'quotas'}{$key}{$item} ne '') { if ($defquota eq '') { - $defquota = $quotahash{'quotas'}{'defaultquota'}{$item}; + $defquota = $quotahash{'quotas'}{$key}{$item}; $settingstatus = $item; - } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) { - $defquota = $quotahash{'quotas'}{'defaultquota'}{$item}; + } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) { + $defquota = $quotahash{'quotas'}{$key}{$item}; $settingstatus = $item; } } - } else { + } elsif ($key eq 'defaultquota') { if ($quotahash{'quotas'}{$item} ne '') { if ($defquota eq '') { $defquota = $quotahash{'quotas'}{$item}; @@ -8690,16 +8811,20 @@ sub default_quota { } } if ($defquota eq '') { - if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') { - $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'}; - } else { + if (ref($quotahash{'quotas'}{$key}) eq 'HASH') { + $defquota = $quotahash{'quotas'}{$key}{'default'}; + } elsif ($key eq 'defaultquota') { $defquota = $quotahash{'quotas'}{'default'}; } $settingstatus = 'default'; } } else { $settingstatus = 'default'; - $defquota = 20; + if ($quotaname eq 'author') { + $defquota = 500; + } else { + $defquota = 20; + } } if (wantarray) { return ($defquota,$settingstatus); @@ -8708,6 +8833,61 @@ sub default_quota { } } +############################################### + +=pod + +=item * &excess_filesize_warning() + +Returns warning message if upload of file to authoring space, or copying +of existing file within authoring space will cause quota for the authoring +space to be exceeded, + +Same, if upload of a file directly to a course/community via Course Editor +will cause quota for uploaded content for the course to be exceeded. + +Inputs: 6 +1. username or coursenum +2. domain +3. context ('author' or 'course') +4. filename of file for which action is being requested +5. filesize (kB) of file +6. action being taken: copy or upload. + +Returns: 1 scalar: HTML to display containing warning if quota would be exceeded, + otherwise return null. + +=cut + +sub excess_filesize_warning { + my ($uname,$udom,$context,$filename,$filesize,$action) = @_; + my $current_disk_usage = 0; + my $disk_quota = &get_user_quota($uname,$udom,$context); #expressed in MB + if ($context eq 'author') { + my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname"; + $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace); + } else { + foreach my $subdir ('docs','supplemental') { + $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1); + } + } + $disk_quota = int($disk_quota * 1000); + if (($current_disk_usage + $filesize) > $disk_quota) { + return '

'. + &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.", + ''.$filename.'',$filesize).''. + '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.', + $disk_quota,$current_disk_usage). + '

'; + } + return; +} + +############################################### + + + + sub get_secgrprole_info { my ($cdom,$cnum,$needroles,$type) = @_; my %sections_count = &get_sections($cdom,$cnum); @@ -9559,7 +9739,7 @@ sub ask_for_embedded_content { $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; } - if (($actionurl eq '/adm/portfolio') || + if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { my $current_path='/'; if ($env{'form.currentpath'}) { @@ -9591,18 +9771,18 @@ 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 '') { if (ref($args) eq 'HASH') { $url = $args->{'docs_url'}; $title = $args->{'docs_title'}; - $toplevel = $url; + $toplevel = $url; unless ($toplevel =~ m{^/}) { $toplevel = "/$url"; } @@ -9672,8 +9852,8 @@ sub ask_for_embedded_content { my $dirptr = 16384; foreach my $path (keys(%subdependencies)) { $currsubfile{$path} = {}; - if (($actionurl eq '/adm/portfolio') || - ($actionurl eq '/adm/coursegrp_portfolio')) { + if (($actionurl eq '/adm/portfolio') || + ($actionurl eq '/adm/coursegrp_portfolio')) { my ($sublistref,$listerror) = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath); if (ref($sublistref) eq 'ARRAY') { @@ -9815,7 +9995,7 @@ sub ask_for_embedded_content { $counter = scalar(keys(%existing)); $numpathchg = scalar(keys(%pathchanges)); return ($output,$counter,$numpathchg,\%existing); - } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") && + } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") && (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) { $counter = scalar(keys(%existing)); $numpathchg = scalar(keys(%pathchanges)); @@ -10361,7 +10541,7 @@ sub modify_html_refs { } my (%allfiles,%codebase,$output,$content); my @changes = &get_env_multiple('form.namechange'); - unless ((@changes > 0) || ($context eq 'syllabus')) { + unless ((@changes > 0) || ($context eq 'syllabus')) { if (wantarray) { return ('',0,0); } else { @@ -10495,7 +10675,7 @@ sub modify_html_refs { } } if ($rewrites) { - my $saveresult; + my $saveresult; my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult); if ($url eq $container) { my ($fname) = ($container =~ m{/([^/]+)$}); @@ -11504,7 +11684,7 @@ sub process_extracted_files { $folders{'0'} = $items[-2]; if ($env{'form.folderpath'} =~ /\:1$/) { $containers{'0'}='page'; - } else { + } else { $containers{'0'}='sequence'; } } @@ -11624,7 +11804,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++) { @@ -11646,7 +11826,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}}"; @@ -11693,12 +11873,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; } } @@ -11708,7 +11888,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)) { @@ -13430,7 +13610,7 @@ sub commit_studentrole { } } } else { - if ($secchange) { + if ($secchange) { $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed; } else { $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed; @@ -14066,7 +14246,7 @@ sub init_user_environment { # ------------------------------------ Check browser type and MathML capability my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml, - $clientunicode,$clientos) = &decode_user_agent($r); + $clientunicode,$clientos,$clientmobile) = &decode_user_agent($r); # ------------------------------------------------------------- Get environment @@ -14097,6 +14277,7 @@ sub init_user_environment { "browser.mathml" => $clientmathml, "browser.unicode" => $clientunicode, "browser.os" => $clientos, + "browser.mobile" => $clientmobile, "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'}, "request.course.fn" => '', "request.course.uri" => '', @@ -14142,7 +14323,7 @@ sub init_user_environment { my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'], $domain,$username); my $reqstatus = $reqauthor{'author_status'}; - if ($reqstatus eq 'approval' || $reqstatus eq 'approved') { + if ($reqstatus eq 'approval' || $reqstatus eq 'approved') { if (ref($reqauthor{'author'}) eq 'HASH') { $userenv{'requestauthorqueued'} = $reqstatus.':'. $reqauthor{'author'}{'timestamp'}; @@ -14424,12 +14605,12 @@ sub captcha_display { if ($captcha eq 'original') { $output = &create_captcha(); unless ($output) { - $error = 'captcha'; + $error = 'captcha'; } } elsif ($captcha eq 'recaptcha') { $output = &create_recaptcha($pubkey); unless ($output) { - $error = 'recaptcha'; + $error = 'recaptcha'; } } return ($output,$error);