--- loncom/interface/loncommon.pm 2003/11/11 22:11:09 1.153 +++ loncom/interface/loncommon.pm 2003/12/22 22:39:07 1.161 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.153 2003/11/11 22:11:09 matthew Exp $ +# $Id: loncommon.pm,v 1.161 2003/12/22 22:39:07 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,13 +25,6 @@ # # http://www.lon-capa.org/ # -# YEAR=2001 -# 2/13-12/7 Guy Albertelli -# 12/21 Gerd Kortemeyer -# 12/25,12/28 Gerd Kortemeyer -# YEAR=2002 -# 1/4 Gerd Kortemeyer -# 6/24,7/2 H. K. Ng # Makes a table out of the previous attempts # Inputs result_from_symbread, user, domain, course_id @@ -73,11 +66,9 @@ use HTML::Entities; my $readit; -=pod - -=head1 Global Variables - -=cut +## +## Global Variables +## # ----------------------------------------------- Filetypes/Languages/Copyright my %language; @@ -111,32 +102,34 @@ BEGIN { unless ($readit) { # ------------------------------------------------------------------- languages { - my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. - '/language.tab'); - if ($fh) { - while (<$fh>) { - next if /^\#/; - chomp; - my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_)); - $language{$key}=$val.' - '.$enc; - if ($sup) { - $supported_language{$key}=$sup; - } - } - } + my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}. + '/language.tab'; + if ( open(my $fh,"<$langtabfile") ) { + while (<$fh>) { + next if /^\#/; + chomp; + my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_)); + $language{$key}=$val.' - '.$enc; + if ($sup) { + $supported_language{$key}=$sup; + } + } + close($fh); + } } # ------------------------------------------------------------------ copyrights { - my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}. - '/copyright.tab'); - if ($fh) { - while (<$fh>) { - next if /^\#/; - chomp; - my ($key,$val)=(split(/\s+/,$_,2)); - $cprtag{$key}=$val; - } - } + my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}. + '/copyright.tab'; + if ( open (my $fh,"<$copyrightfile") ) { + while (<$fh>) { + next if /^\#/; + chomp; + my ($key,$val)=(split(/\s+/,$_,2)); + $cprtag{$key}=$val; + } + close($fh); + } } # -------------------------------------------------------------- domain designs @@ -147,15 +140,16 @@ BEGIN { while ($filename=readdir(DIR)) { my ($domain)=($filename=~/^(\w+)\./); { - my $fh=Apache::File->new($designdir.'/'.$filename); - if ($fh) { - while (<$fh>) { - next if /^\#/; - chomp; - my ($key,$val)=(split(/\=/,$_)); - if ($val) { $designhash{$domain.'.'.$key}=$val; } - } - } + my $designfile = $designdir.'/'.$filename; + if ( open (my $fh,"<$designfile") ) { + while (<$fh>) { + next if /^\#/; + chomp; + my ($key,$val)=(split(/\=/,$_)); + if ($val) { $designhash{$domain.'.'.$key}=$val; } + } + close($fh); + } } } @@ -164,32 +158,35 @@ BEGIN { # ------------------------------------------------------------- file categories { - my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. - '/filecategories.tab'); - if ($fh) { - while (<$fh>) { - next if /^\#/; - chomp; - my ($extension,$category)=(split(/\s+/,$_,2)); - push @{$category_extensions{lc($category)}},$extension; - } - } + my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}. + '/filecategories.tab'; + if ( open (my $fh,"<$categoryfile") ) { + while (<$fh>) { + next if /^\#/; + chomp; + my ($extension,$category)=(split(/\s+/,$_,2)); + push @{$category_extensions{lc($category)}},$extension; + } + close($fh); + } + } # ------------------------------------------------------------------ file types { - my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. - '/filetypes.tab'); - if ($fh) { + my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}. + '/filetypes.tab'; + if ( open (my $fh,"<$typesfile") ) { while (<$fh>) { - next if (/^\#/); - chomp; - my ($ending,$emb,$descr)=split(/\s+/,$_,3); - if ($descr ne '') { - $fe{$ending}=lc($emb); - $fd{$ending}=$descr; - } - } - } + next if (/^\#/); + chomp; + my ($ending,$emb,$descr)=split(/\s+/,$_,3); + if ($descr ne '') { + $fe{$ending}=lc($emb); + $fd{$ending}=$descr; + } + } + close($fh); + } } &Apache::lonnet::logthis( "INFO: Read file types"); @@ -204,10 +201,6 @@ BEGIN { =pod -=head1 General Subroutines - -=over 4 - =head1 HTML and Javascript Functions =over 4 @@ -219,8 +212,6 @@ containing javascript with two functions C. Returned string does not contain EscriptE tags. -=over 4 - =item * openbrowser(formname,elementname,only,omit) [javascript] inputs: formname, elementname, only, omit @@ -241,8 +232,6 @@ Inputs: formname, elementname formname and elementname specify the name of the html form and the name of the element the selection from the search results will be placed in. -=back - =cut sub browser_and_searcher_javascript { @@ -565,6 +554,8 @@ sub help_open_topic { my $template = ""; my $link; + $topic=~s/\W/\_/g; + if (!$stayOnPage) { $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))"; @@ -887,6 +878,8 @@ Outputs: =back +=back + =cut ############################################################### @@ -925,12 +918,6 @@ sub decode_user_agent { $clientunicode,$clientos,); } -=pod - -=back - -=cut - ############################################################### ## Authentication changing form generation subroutines ## ############################################################### @@ -971,6 +958,8 @@ See loncreateuser.pm for invocation and =back +=back + =cut #------------------------------------------- @@ -1131,7 +1120,7 @@ sub authform_local{ @_, ); my $jscall = "javascript:changed_radio('loc',$in{'formname'});"; - my $result.=&mt('[_1] Local Authentication with arguement [_2]', + my $result.=&mt('[_1] Local Authentication with argument [_2]', '', ' h1, h2, h3, th { font-family: Arial, Helvetica, sans-serif } -a:hover { color: black; background: yellow } a:focus { color: red; background: yellow } new('>'.$r->dir_config('lonDaemons'). - '/tmp/'.$datatoken.'.tmp'); - print $fh $ENV{'form.upfile'}; + my $datafile = $r->dir_config('lonDaemons'). + '/tmp/'.$datatoken.'.tmp'; + if ( open(my $fh,">$datafile") ) { + print $fh $ENV{'form.upfile'}; + close($fh); + } } return $datatoken; } @@ -2437,11 +2418,12 @@ sub load_tmp_file { my $r=shift; my @studentdata=(); { - my $fh; - if ($fh=Apache::File->new($r->dir_config('lonDaemons'). - '/tmp/'.$ENV{'form.datatoken'}.'.tmp')) { - @studentdata=<$fh>; - } + my $studentfile = $r->dir_config('lonDaemons'). + '/tmp/'.$ENV{'form.datatoken'}.'.tmp'; + if ( open(my $fh,"<$studentfile") ) { + @studentdata=<$fh>; + close($fh); + } } $ENV{'form.upfile'}=join('',@studentdata); } @@ -2730,8 +2712,12 @@ sub check_if_partid_hidden { =pod +=back + =head1 cgi-bin script and graphing routines +=over 4 + =item get_cgi_id Inputs: none @@ -2747,7 +2733,7 @@ the routine &Apache::lonnet::transfer_pr ############################################################ my $uniq=0; sub get_cgi_id { - $uniq=($uniq++)%100000; + $uniq=($uniq+1)%100000; return (time.'_'.$uniq); } @@ -3064,10 +3050,14 @@ sub DrawXYYGraph { =pod +=back + =head1 Statistics helper routines? Bad place for them but what the hell. +=over 4 + =item &chartlink Returns a link to the chart for a specific student. @@ -3084,6 +3074,8 @@ Inputs: =back +=back + =cut ############################################################ @@ -3103,6 +3095,8 @@ sub chartlink { =head1 Course Environment Routines +=over 4 + =item &restore_course_settings =item &store_course_settings @@ -3201,6 +3195,28 @@ sub restore_course_settings { ############################################################ ############################################################ +sub propath { + my ($udom,$uname)=@_; + $udom=~s/\W//g; + $uname=~s/\W//g; + my $subdir=$uname.'__'; + $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/; + my $proname="$Apache::lonnet::perlvar{'lonUsersDir'}/$udom/$subdir/$uname"; + return $proname; +} + +sub icon { + my ($file)=@_; + my @file_ext = split(/\./,$file); + my $curfext = $file_ext[-1]; + my $iconname="unknown.gif"; + my $embstyle = &Apache::loncommon::fileembstyle($curfext); + # The unless conditional that follows is a bit of overkill + $iconname = $curfext.".gif" unless + (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn'); + return $Apache::lonnet::perlvar{'lonIconsURL'}."/$iconname"; +} + =pod =back