--- loncom/lonnet/perl/lonnet.pm 2009/09/16 20:10:32 1.976.4.2 +++ loncom/lonnet/perl/lonnet.pm 2009/01/02 22:45:43 1.982 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.976.4.2 2009/09/16 20:10:32 raeburn Exp $ +# $Id: lonnet.pm,v 1.982 2009/01/02 22:45:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -73,6 +73,8 @@ package Apache::lonnet; use strict; use LWP::UserAgent(); use HTTP::Date; +use Image::Magick; + # use Date::Parse; use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir $_64bit %env %protocol); @@ -97,6 +99,8 @@ use LONCAPA::Configuration; my $readit; my $max_connection_retries = 10; # Or some such value. +my $upload_photo_form = 0; #Variable to check when user upload a photo 0=not 1=true + require Exporter; our @ISA = qw (Exporter); @@ -177,20 +181,6 @@ sub create_connection { return 0; } -sub get_server_timezone { - my ($cnum,$cdom) = @_; - my $home=&homeserver($cnum,$cdom); - if ($home ne 'no_host') { - my $cachetime = 24*3600; - my ($timezone,$cached)=&is_cached_new('servertimezone',$home); - if (defined($cached)) { - return $timezone; - } else { - my $timezone = &reply('servertimezone',$home); - return &do_cache_new('servertimezone',$home,$timezone,$cachetime); - } - } -} # -------------------------------------------------- Non-critical communication sub subreply { @@ -522,7 +512,7 @@ sub appenv { # ----------------------------------------------------- Delete from Environment sub delenv { - my ($delthis,$regexp) = @_; + my $delthis=shift; if (($delthis=~/user\.role/) || ($delthis=~/user\.priv/)) { &logthis("WARNING: ". "Attempt to delete from environment ".$delthis); @@ -535,17 +525,10 @@ sub delenv { tie(my %disk_env,'GDBM_File',$env{'user.environment'}, (&GDBM_WRITER()|&GDBM_NOLOCK()),0640)) { foreach my $key (keys(%disk_env)) { - if ($regexp) { - if ($key=~/^$delthis/) { - delete($env{$key}); - delete($disk_env{$key}); - } - } else { - if ($key=~/^\Q$delthis\E/) { - delete($env{$key}); - delete($disk_env{$key}); - } - } + if ($key=~/^\Q$delthis\E/) { + delete($env{$key}); + delete($disk_env{$key}); + } } untie(%disk_env); } @@ -1262,7 +1245,7 @@ sub get_domain_defaults { $domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'}; $domdefaults{'auth_arg_def'} = $domconfig{'defaults'}{'auth_arg_def'}; $domdefaults{'timezone_def'} = $domconfig{'defaults'}{'timezone_def'}; - $domdefaults{'datelocale_def'} = $domconfig{'defaults'}{'datelocale_def'}; + $domdefaults{'datelocale_def'} = $domconfig{'defaults'}{'datelocale_def'} } else { $domdefaults{'lang_def'} = &domain($domain,'lang_def'); $domdefaults{'auth_def'} = &domain($domain,'auth_def'); @@ -2033,6 +2016,14 @@ sub clean_filename { return $fname; } +#Wrapper function for userphotoupload +sub userphotoupload +{ + my($formname,$subdir) = @_; + $upload_photo_form = 1; + return &userfileupload($formname,undef,$subdir); +} + # --------------- Take an uploaded file and put it into the userfiles directory # input: $formname - the contents of the file are in $env{"form.$formname"} # the desired filenam is in $env{"form.$formname.filename"} @@ -2159,6 +2150,25 @@ sub finishuserfileupload { return '/adm/notfound.html'; } close(FH); + if($upload_photo_form==1) + { + my $ima = Image::Magick->new; + $ima->Read($filepath.'/'.$file); + if($ima->Get('width') > 300) + { + my $factor = $ima->Get('width')/300; + $ima->Scale( width=>300, height=>$ima->Get('height')/$factor ); + } + if($ima->Get('height') > 400) + { + my $factor = $ima->Get('height')/400; + $ima->Scale( width=>$ima->Get('width')/$factor, height=>400); + } + + + $ima->Write($filepath.'/'.$file); + $upload_photo_form = 0; + } } if ($parser eq 'parse') { my $parse_result = &extract_embedded_items($filepath.'/'.$file,$allfiles, @@ -2624,9 +2634,6 @@ sub courserolelog { $storehash{'section'} = $sec; } &instructor_log($namespace,\%storehash,$delflag,$username,$domain,$cnum,$cdom); - if (($trole ne 'st') || ($sec ne '')) { - &devalidate_cache_new('getcourseroles',$cdom.'_'.$cnum); - } } } return; @@ -2636,7 +2643,6 @@ sub get_course_adv_roles { my ($cid,$codes) = @_; $cid=$env{'request.course.id'} unless (defined($cid)); my %coursehash=&coursedescription($cid); - my $crstype = &Apache::loncommon::course_type($cid); my %nothide=(); foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) { if ($user !~ /:/) { @@ -2649,7 +2655,6 @@ sub get_course_adv_roles { my %dumphash= &dump('nohist_userroles',$coursehash{'domain'},$coursehash{'num'}); my $now=time; - my %privileged; foreach my $entry (keys %dumphash) { my ($tend,$tstart)=split(/\:/,$dumphash{$entry}); if (($tstart) && ($tstart<0)) { next; } @@ -2657,21 +2662,8 @@ sub get_course_adv_roles { if (($tstart) && ($now<$tstart)) { next; } my ($role,$username,$domain,$section)=split(/\:/,$entry); if ($username eq '' || $domain eq '') { next; } - unless (ref($privileged{$domain}) eq 'HASH') { - my %dompersonnel = - &Apache::lonnet::get_domain_roles($domain,['dc'],$now,$now); - $privileged{$domain} = {}; - foreach my $server (keys(%dompersonnel)) { - if (ref($dompersonnel{$server}) eq 'HASH') { - foreach my $user (keys(%{$dompersonnel{$server}})) { - my ($trole,$uname,$udom) = split(/:/,$user); - $privileged{$udom}{$uname} = 1; - } - } - } - } - if ((exists($privileged{$domain}{$username})) && - (!$nothide{$username.':'.$domain})) { next; } + if ((&privileged($username,$domain)) && + (!$nothide{$username.':'.$domain})) { next; } if ($role eq 'cr') { next; } if ($codes) { if ($section) { $role .= ':'.$section; } @@ -2681,7 +2673,7 @@ sub get_course_adv_roles { $returnhash{$role}=$username.':'.$domain; } } else { - my $key=&plaintext($role,$crstype); + my $key=&plaintext($role); if ($section) { $key.=' ('.&Apache::lonlocal::mt('Section [_1]',$section).')'; } if ($returnhash{$key}) { $returnhash{$key}.=','.$username.':'.$domain; @@ -2716,7 +2708,6 @@ sub get_my_roles { } my %returnhash=(); my $now=time; - my %privileged; foreach my $entry (keys(%dumphash)) { my ($role,$tend,$tstart); if ($context eq 'userroles') { @@ -2765,32 +2756,9 @@ sub get_my_roles { } } if ($hidepriv) { - if ($context eq 'userroles') { - if ((&privileged($username,$domain)) && - (!$nothide{$username.':'.$domain})) { - next; - } - } else { - unless (ref($privileged{$domain}) eq 'HASH') { - my %dompersonnel = - &Apache::lonnet::get_domain_roles($domain,['dc'],$now,$now); - $privileged{$domain} = {}; - if (keys(%dompersonnel)) { - foreach my $server (keys(%dompersonnel)) { - if (ref($dompersonnel{$server}) eq 'HASH') { - foreach my $user (keys(%{$dompersonnel{$server}})) { - my ($trole,$uname,$udom) = split(/:/,$user); - $privileged{$udom}{$uname} = $trole; - } - } - } - } - } - if (exists($privileged{$domain}{$username})) { - if (!$nothide{$username.':'.$domain}) { - next; - } - } + if ((&privileged($username,$domain)) && + (!$nothide{$username.':'.$domain})) { + next; } } if ($withsec) { @@ -4456,7 +4424,7 @@ sub usertools_access { if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) { if ($action ne 'reload') { return $env{'environment.availabletools.'.$tool}; - } + } } my ($toolstatus,$inststatus); @@ -5647,19 +5615,16 @@ sub devalidate_getgroups_cache { # ------------------------------------------------------------------ Plain Text sub plaintext { - my ($short,$type,$cid,$forcedefault) = @_; + my ($short,$type,$cid) = @_; if ($short =~ /^cr/) { return (split('/',$short))[-1]; } if (!defined($cid)) { $cid = $env{'request.course.id'}; } - if (defined($cid) && ($env{'course.'.$cid.'.'.$short.'.plaintext'} ne '')) { - unless ($forcedefault) { - my $roletext = $env{'course.'.$cid.'.'.$short.'.plaintext'}; - &Apache::lonlocal::mt_escape(\$roletext); - return &Apache::lonlocal::mt($roletext); - } + if (defined($cid) && defined($env{'course.'.$cid.'.'.$short.'.plaintext'})) { + return &Apache::lonlocal::mt($env{'course.'.$cid.'.'.$short. + '.plaintext'}); } my %rolenames = ( Course => 'std', @@ -9280,11 +9245,9 @@ in the user's environment.db and in %env =item * X -B: removes all items from the session -environment file that begin with $delthis. If the -optional second arg - $regexp - is true, $delthis is treated as a -regular expression, otherwise \Q$delthis\E is used. -The values are also deleted from the current processes %env. +B: removes all items from the session +environment file that matches the regular expression in $regexp. The +values are also delted from the current processes %env. =item * get_env_multiple($name) @@ -9381,13 +9344,8 @@ and course level =item * -plaintext($short,$type,$cid,$forcedefault) : return value in %prp hash -(rolesplain.tab); plain text explanation of a user role term. -$type is Course (default) or Community. -If $forcedefault evaluates to true, text returned will be default -text for $type. Otherwise, if this is a course, the text returned -will be a custom name for the role (if defined in the course's -environment). If no custom name is defined the default is returned. +plaintext($short) : return value in %prp hash (rolesplain.tab); plain text +explanation of a user role term =item *