--- loncom/interface/loncommon.pm 2013/07/05 19:53:11 1.1075.2.41 +++ loncom/interface/loncommon.pm 2013/04/11 15:30:37 1.1121 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1075.2.41 2013/07/05 19:53:11 raeburn Exp $ +# $Id: loncommon.pm,v 1.1121 2013/04/11 15:30:37 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) { @@ -2527,7 +2557,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,6 +3053,45 @@ 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 @@ -3030,6 +3099,31 @@ sub get_related_words { =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 +4932,7 @@ sub designparm { Inputs: $url (usually will be undef). -Returns: Path to Authoring Space containing the resource or +Returns: Path to Construction 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 +4995,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 Authoring Space pages + To be included on Construction Space pages =cut @@ -4932,7 +5026,7 @@ sub CSTR_pageheader { my $output = '
' .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it? - .''.&mt('Authoring Space:').' ' + .''.&mt('Construction Space:').' ' .'
' #FIXME lonpubdir: target="_parent" .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef); @@ -4991,9 +5085,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 +5106,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')) @@ -5064,14 +5155,16 @@ sub bodytag { my $bodytag = "". &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'}); - &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']); - - if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) { + if ($bodyonly) { return $bodytag; - } + } + my $name = &plainname($env{'user.name'},$env{'user.domain'}); if ($public) { undef($role); + } else { + $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'}, + undef,'LC_menubuttons_link'); } my $titleinfo = '

'.$title.'

'; @@ -5087,48 +5180,37 @@ sub bodytag { } $role = '('.$role.')' if $role; + &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']); - if ($env{'request.state'} eq 'construct') { $forcereg=1; } - - + if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { + return $bodytag; + } - 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 # } - $bodytag .= Apache::lonhtmlcommon::scripttag( - Apache::lonmenu::utilityfunctions(), 'start'); - 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|
$name $role
+ $realm $dc_info
|; return $bodytag; } unless ($env{'request.symb'} =~ m/\.page___\d+___/) { - $bodytag .= qq|
$left $role
|; + $bodytag .= qq|
$name $role
|; } - $bodytag .= $right; + $bodytag .= Apache::lonhtmlcommon::scripttag( + Apache::lonmenu::utilityfunctions(), 'start'); + + $bodytag .= Apache::lonmenu::primary_menu(); if ($dc_info) { $dc_info = &dc_courseid_toggle($dc_info); @@ -5143,18 +5225,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 +5243,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 +5274,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; @@ -5382,14 +5410,6 @@ form, .inline { vertical-align:middle; } -.LC_floatleft { - float: left; -} - -.LC_floatright { - float: right; -} - .LC_400Box { width:400px; } @@ -6460,11 +6480,6 @@ div.LC_edit_problem_saves { padding-bottom: 5px; } -.LC_edit_opt { - padding-left: 1em; - white-space: nowrap; -} - img.stift { border-width: 0; vertical-align: middle; @@ -6479,7 +6494,6 @@ div.LC_createcourse { } .LC_dccid { - float: right; margin: 0.2em 0 0 0; padding: 0; font-size: 90%; @@ -6577,6 +6591,7 @@ fieldset > legend { } ol.LC_primary_menu { + float: right; margin: 0; padding: 0; background-color: $pgbg_or_bgcolor; @@ -6688,7 +6703,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 +7262,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'} @@ -7458,16 +7472,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 +7509,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 +7550,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; } @@ -7806,9 +7813,11 @@ sub LCprogressbar { $LCcurrentid=$$.'_'.$LCidcnt; my $starting=&mt('Starting'); my $content=(<
$starting
+

ENDPROGBAR &r_print($r,$content.&LCprogressbar_script($LCcurrentid)); } @@ -8234,7 +8243,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,14 +8557,11 @@ sub get_user_info { =item * &get_user_quota() -Retrieves quota assigned for storage of user files. -Default is to report quota for portfolio files. +Retrieves quota assigned for storage of portfolio files for a user 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). Returns: 1. Disk quota (in Mb) assigned to student. @@ -8569,7 +8575,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 institutional status(es) in the domain. +defined for the user's instituional status(es) in the domain. =cut @@ -8577,7 +8583,7 @@ defined for the user's institutional sta sub get_user_quota { - my ($uname,$udom,$quotaname) = @_; + my ($uname,$udom) = @_; my ($quota,$quotatype,$settingstatus,$defquota); if (!defined($udom)) { $udom = $env{'user.domain'}; @@ -8592,52 +8598,27 @@ sub get_user_quota { $defquota = 0; } else { my $inststatus; - 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'}; - } + 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'; } else { - 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); - $defquota = $domdefs{'uploadquota'}; - } else { - ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname); - } - if ($quota eq '') { - $quota = $defquota; - $quotatype = 'default'; - } else { - $quotatype = 'custom'; - } + $quotatype = 'custom'; } } if (wantarray) { @@ -8662,9 +8643,7 @@ 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. -3. quota name - portfolio, author, or course - (if no quota name provided, defaults to portfolio). + default quota will be returned. Returns: 1. Default disk quota (in Mb) for user portfolios in the domain. @@ -8688,29 +8667,25 @@ default quota returned. sub default_quota { - my ($udom,$inststatus,$quotaname) = @_; + my ($udom,$inststatus) = @_; 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'}{$key}) eq 'HASH') { - if ($quotahash{'quotas'}{$key}{$item} ne '') { + if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') { + if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') { if ($defquota eq '') { - $defquota = $quotahash{'quotas'}{$key}{$item}; + $defquota = $quotahash{'quotas'}{'defaultquota'}{$item}; $settingstatus = $item; - } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) { - $defquota = $quotahash{'quotas'}{$key}{$item}; + } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) { + $defquota = $quotahash{'quotas'}{'defaultquota'}{$item}; $settingstatus = $item; } } - } elsif ($key eq 'defaultquota') { + } else { if ($quotahash{'quotas'}{$item} ne '') { if ($defquota eq '') { $defquota = $quotahash{'quotas'}{$item}; @@ -8724,20 +8699,16 @@ sub default_quota { } } if ($defquota eq '') { - if (ref($quotahash{'quotas'}{$key}) eq 'HASH') { - $defquota = $quotahash{'quotas'}{$key}{'default'}; - } elsif ($key eq 'defaultquota') { + if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') { + $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'}; + } else { $defquota = $quotahash{'quotas'}{'default'}; } $settingstatus = 'default'; } } else { $settingstatus = 'default'; - if ($quotaname eq 'author') { - $defquota = 500; - } else { - $defquota = 20; - } + $defquota = 20; } if (wantarray) { return ($defquota,$settingstatus); @@ -8746,47 +8717,6 @@ sub default_quota { } } -############################################### - -=pod - -=item * &excess_filesize_authorspace() - -Returns warning message if upload of file to authoring space, or copying -of existing file within authoring space will cause quota to be exceeded. - -Inputs: 6 -1. username -2. domain -3. directory path for top level of current authoring space -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_authorspace { - my ($uname,$udom,$authorspace,$filename,$filesize,$action) = @_; - my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in MB - $disk_quota = int($disk_quota * 1000); - my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace); - 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); @@ -9630,23 +9560,18 @@ sub ask_for_embedded_content { my $heading = &mt('Upload embedded files'); my $buttontext = &mt('Upload'); - my ($navmap,$cdom,$cnum); + my $navmap; if ($env{'request.course.id'}) { - if ($actionurl eq '/adm/dependencies') { - $navmap = Apache::lonnavmaps::navmap->new(); - } - $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + $navmap = Apache::lonnavmaps::navmap->new(); } - if (($actionurl eq '/adm/portfolio') || - ($actionurl eq '/adm/coursegrp_portfolio')) { + if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { my $current_path='/'; if ($env{'form.currentpath'}) { $current_path = $env{'form.currentpath'}; } if ($actionurl eq '/adm/coursegrp_portfolio') { - $udom = $cdom; - $uname = $cnum; + $udom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $uname = $env{'course.'.$env{'request.course.id'}.'.num'}; $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio'; } else { $udom = $env{'user.domain'}; @@ -9670,50 +9595,32 @@ 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'}; if (ref($args) eq 'HASH') { $url = $args->{'docs_url'}; $title = $args->{'docs_title'}; - $toplevel = $url; - unless ($toplevel =~ m{^/}) { - $toplevel = "/$url"; - } + $toplevel = "/$url"; ($rem) = ($toplevel =~ m{^(.+/)[^/]+$}); - if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) { - $path = $1; - } else { - ($path) = - ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/}); - } + ($path) = + ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/}); $fileloc = &Apache::lonnet::filelocation('',$toplevel); $fileloc =~ s{^/}{}; ($filename) = ($fileloc =~ m{.+/([^/]+)$}); $heading = &mt('Status of dependencies in [_1]',"$title ($filename)"); } } - } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") { - $udom = $cdom; - $uname = $cnum; - $url = "/uploaded/$cdom/$cnum/portfolio/syllabus"; - $toplevel = $url; - $path = $url; - $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/'; - $fileloc =~ s{^/}{}; - } - foreach my $file (keys(%{$allfiles})) { - my $embed_file; - if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) { - $embed_file = $1; - } else { - $embed_file = $file; - } + } + my $now = time(); + foreach my $embed_file (keys(%{$allfiles})) { my $absolutepath; if ($embed_file =~ m{^\w+://}) { $newfiles{$embed_file} = 1; @@ -9751,8 +9658,7 @@ 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') { @@ -9768,15 +9674,9 @@ sub ask_for_embedded_content { } } elsif (($actionurl eq '/adm/dependencies') || (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') && - ($args->{'context'} eq 'paste')) || - ($actionurl eq "/public/$cdom/$cnum/syllabus")) { + ($args->{'context'} eq 'paste'))) { if ($env{'request.course.id'} ne '') { - my $dir; - if ($actionurl eq "/public/$cdom/$cnum/syllabus") { - $dir = $fileloc; - } else { - ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); - } + my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); if ($dir ne '') { my ($sublistref,$listerror) = &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/'); @@ -9824,8 +9724,7 @@ sub ask_for_embedded_content { } } my %currfile; - if (($actionurl eq '/adm/portfolio') || - ($actionurl eq '/adm/coursegrp_portfolio')) { + if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { my ($dirlistref,$listerror) = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath); if (ref($dirlistref) eq 'ARRAY') { @@ -9841,8 +9740,7 @@ sub ask_for_embedded_content { } } elsif (($actionurl eq '/adm/dependencies') || (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') && - ($args->{'context'} eq 'paste')) || - ($actionurl eq "/public/$cdom/$cnum/syllabus")) { + ($args->{'context'} eq 'paste'))) { if ($env{'request.course.id'} ne '') { my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); if ($dir ne '') { @@ -9877,14 +9775,12 @@ sub ask_for_embedded_content { ($file eq $filename.'.bak') || ($dependencies{$file})) { if ($actionurl eq '/adm/dependencies') { - unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) { - next if (($rem ne '') && - (($env{"httpref.$rem".$file} ne '') || - (ref($navmap) && - (($navmap->getResourceByUrl($rem.$file) ne '') || - (($file =~ /^(.*\.s?html?)\.bak$/i) && - ($navmap->getResourceByUrl($rem.$1))))))); - } + next if (($rem ne '') && + (($env{"httpref.$rem".$file} ne '') || + (ref($navmap) && + (($navmap->getResourceByUrl($rem.$file) ne '') || + (($file =~ /^(.*\.s?html?)\.bak$/i) && + ($navmap->getResourceByUrl($rem.$1))))))); } $unused{$file} = 1; } @@ -9893,38 +9789,28 @@ sub ask_for_embedded_content { ($args->{'context'} eq 'paste')) { $counter = scalar(keys(%existing)); $numpathchg = scalar(keys(%pathchanges)); - return ($output,$counter,$numpathchg,\%existing); - } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") && - (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) { - $counter = scalar(keys(%existing)); - $numpathchg = scalar(keys(%pathchanges)); - return ($output,$counter,$numpathchg,\%existing,\%mapping); + return ($output,$counter,$numpathchg,\%existing); } foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) { if ($actionurl eq '/adm/dependencies') { next if ($embed_file =~ m{^\w+://}); } $upload_output .= &start_data_table_row(). - ' '. + ' '. ''.$embed_file.''; unless ($mapping{$embed_file} eq $embed_file) { - $upload_output .= '
'. - &mt('changed from: [_1]',$mapping{$embed_file}).''; + $upload_output .= '
'.&mt('changed from: [_1]',$mapping{$embed_file}).''; } - $upload_output .= ''; + $upload_output .= ''; if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) { - $upload_output.=''. - ''. - &mt("URL points to web address").''; + $upload_output.=''.&mt("URL points to other server.").''; $numremref++; } elsif ($args->{'error_on_invalid_names'} && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) { - $upload_output.=''. - &mt('Invalid characters').''; + $upload_output.=''.&mt('Invalid characters').''; $numinvalid++; } else { - $upload_output .= ''. - &embedded_file_element('upload_embedded',$counter, + $upload_output .= &embedded_file_element('upload_embedded',$counter, $embed_file,\%mapping, $allfiles,$codebase,'upload'); $counter ++; @@ -9953,9 +9839,8 @@ sub ask_for_embedded_content { $counter ++; } else { $upload_output .= &start_data_table_row(). - ' '. - ''.$embed_file.''. - ''.&mt('Already exists').''. + ''.$embed_file.''; + ''.&mt('Already exists').''. &Apache::loncommon::end_data_table_row()."\n"; } } @@ -10050,7 +9935,7 @@ sub ask_for_embedded_content { $output = ''.&mt('Referenced files').':
'; if ($applies > 1) { $output .= - &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'
    '; + &mt('No files need to be uploaded, as one of the following applies to each reference:').'
      '; if ($numremref) { $output .= '
    • '.&mt('reference is to a URL which points to another server').'
    • '."\n"; } @@ -10093,7 +9978,7 @@ sub ask_for_embedded_content { $chgcount ++; } } - if (($counter) || ($numunused)) { + if ($counter) { if ($numpathchg) { $output .= ''."\n"; @@ -10106,13 +9991,13 @@ sub ask_for_embedded_content { } elsif ($actionurl eq '/adm/dependencies') { $output .= ''; } - $output .= ''."\n".''."\n"; + $output .= ''."\n".''."\n"; } elsif ($numpathchg) { my %pathchange = (); $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output); if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { $output .= '

      '.&mt('or').'

      '; - } + } } return ($output,$counter,$numpathchg); } @@ -10252,19 +10137,17 @@ sub upload_embedded { next; } $env{'form.embedded_item_'.$i.'.filename'}=$fname; - my $subdir = $path; - $subdir =~ s{/+$}{}; if ($context eq 'portfolio') { my $result; if ($state eq 'existingfile') { $result= &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile', - $dirpath.$env{'form.currentpath'}.$subdir); + $dirpath.$env{'form.currentpath'}.$path); } else { $result= &Apache::lonnet::userfileupload('embedded_item_'.$i,'', $dirpath. - $env{'form.currentpath'}.$subdir); + $env{'form.currentpath'}.$path); if ($result !~ m|^/uploaded/|) { $output .= '' .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].' @@ -10276,11 +10159,10 @@ sub upload_embedded { $path.$fname.'').'
      '; } } - } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) { - my $extendedsubdir = $dirpath.'/'.$subdir; - $extendedsubdir =~ s{/+$}{}; + } elsif ($context eq 'coursedoc') { my $result = - &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir); + &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc', + $dirpath.'/'.$path); if ($result !~ m|^/uploaded/|) { $output .= '' .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].' @@ -10290,9 +10172,6 @@ sub upload_embedded { } else { $output .= &mt('Uploaded [_1]',''. $path.$fname.'').'
      '; - if ($context eq 'syllabus') { - &Apache::lonnet::make_public_indefinitely($result); - } } } else { # Save the file @@ -10424,7 +10303,7 @@ sub modify_html_form { } sub modify_html_refs { - my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_; + my ($context,$dirpath,$uname,$udom,$dir_root) = @_; my $container; if ($context eq 'portfolio') { $container = $env{'form.container'}; @@ -10433,14 +10312,12 @@ sub modify_html_refs { } elsif ($context eq 'manage_dependencies') { (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'}); $container = "/$container"; - } elsif ($context eq 'syllabus') { - $container = $url; } else { $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'}; } my (%allfiles,%codebase,$output,$content); my @changes = &get_env_multiple('form.namechange'); - unless ((@changes > 0) || ($context eq 'syllabus')) { + unless (@changes > 0) { if (wantarray) { return ('',0,0); } else { @@ -10448,7 +10325,7 @@ sub modify_html_refs { } } if (($context eq 'portfolio') || ($context eq 'coursedoc') || - ($context eq 'manage_dependencies') || ($context eq 'syllabus')) { + ($context eq 'manage_dependencies')) { unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) { if (wantarray) { return ('',0,0); @@ -10504,7 +10381,6 @@ sub modify_html_refs { if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) { my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi); $count += $numchg; - $allfiles{$newname} = $allfiles{$ref}; } if ($env{'form.embedded_codebase_'.$i} ne '') { $codebase = &unescape($env{'form.embedded_codebase_'.$i}); @@ -10513,11 +10389,10 @@ sub modify_html_refs { } } } - my $skiprewrites; if ($count || $codebasecount) { my $saveresult; if (($context eq 'portfolio') || ($context eq 'coursedoc') || - ($context eq 'manage_dependencies') || ($context eq 'syllabus')) { + ($context eq 'manage_dependencies')) { my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult); if ($url eq $container) { my ($fname) = ($container =~ m{/([^/]+)$}); @@ -10530,11 +10405,6 @@ sub modify_html_refs { ''. $container.'').'

      '; } - if ($context eq 'syllabus') { - unless ($saveresult eq 'ok') { - $skiprewrites = 1; - } - } } else { if (open(my $fh,">$container")) { print $fh $content; @@ -10550,47 +10420,6 @@ sub modify_html_refs { } } } - if (($context eq 'syllabus') && (!$skiprewrites)) { - my ($actionurl,$state); - $actionurl = "/public/$udom/$uname/syllabus"; - my ($ignore,$num,$numpathchanges,$existing,$mapping) = - &ask_for_embedded_content($actionurl,$state,\%allfiles, - \%codebase, - {'context' => 'rewrites', - 'ignore_remote_references' => 1,}); - if (ref($mapping) eq 'HASH') { - my $rewrites = 0; - foreach my $key (keys(%{$mapping})) { - next if ($key =~ m{^https?://}); - my $ref = $mapping->{$key}; - my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key"; - my $attrib; - if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') { - $attrib = join('|',@{$allfiles{$mapping->{$key}}}); - } - if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) { - my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi); - $rewrites += $numchg; - } - } - if ($rewrites) { - my $saveresult; - my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult); - if ($url eq $container) { - my ($fname) = ($container =~ m{/([^/]+)$}); - $output .= '

      '.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].', - $count,''. - $fname.'').'

      '; - } else { - $output .= '

      '. - &mt('Error: could not update links in [_1].', - ''. - $container.'').'

      '; - - } - } - } - } } else { &logthis('Failed to parse '.$container. ' to modify references: '.$parse_result); @@ -11583,7 +11412,7 @@ sub process_extracted_files { $folders{'0'} = $items[-2]; if ($env{'form.folderpath'} =~ /\:1$/) { $containers{'0'}='page'; - } else { + } else { $containers{'0'}='sequence'; } } @@ -11703,7 +11532,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++) { @@ -11725,7 +11554,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}}"; @@ -11772,12 +11601,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; } } @@ -11787,7 +11616,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)) { @@ -11893,7 +11722,7 @@ sub get_folder_hierarchy { my @pcs = split(/,/,$pcslist); foreach my $pc (@pcs) { if ($pc == 1) { - push(@pathitems,&mt('Main Content')); + push(@pathitems,&mt('Main Course Documents')); } else { my $res = $navmap->getByMapPc($pc); if (ref($res)) { @@ -11908,7 +11737,7 @@ sub get_folder_hierarchy { } if ($showitem) { if ($mapres->{ID} eq '0.0') { - push(@pathitems,&mt('Main Content')); + push(@pathitems,&mt('Main Course Documents')); } else { my $maptitle = $mapres->compTitle(); $maptitle =~ s/\W+/_/g; @@ -13509,7 +13338,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; @@ -14221,7 +14050,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'}; @@ -14469,7 +14298,7 @@ sub symb_to_docspath { $path =~ s/^\&//; my $maptitle = $mapresobj->title(); if ($mapurl eq 'default') { - $maptitle = 'Main Content'; + $maptitle = 'Main Course Documents'; } $path .= (($path ne '')? '&' : ''). &Apache::lonhtmlcommon::entity_encode($mapurl).'&'. @@ -14483,14 +14312,14 @@ sub symb_to_docspath { my $maptitle = &Apache::lonnet::gettitle($mapurl); my $ispage = (($type eq 'page')? 1 : ''); if ($mapurl eq 'default') { - $maptitle = 'Main Content'; + $maptitle = 'Main Course Documents'; } $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'. &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage; } unless ($mapurl eq 'default') { $path = 'default&'. - &Apache::lonhtmlcommon::entity_encode('Main Content'). + &Apache::lonhtmlcommon::entity_encode('Main Course Documents'). ':::::&'.$path; } return $path; @@ -14503,12 +14332,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); @@ -14633,7 +14462,7 @@ sub create_recaptcha { return $captcha->get_options_setter({theme => 'white'})."\n". $captcha->get_html($pubkey). &mt('If either word is hard to read, [_1] will replace them.', - 'reCAPTCHA refresh'). + 'reCAPTCHA refresh'). '

      '; }