version 1.976.2.9, 2009/05/15 20:31:04
|
version 1.993, 2009/04/11 14:47:51
|
Line 73 package Apache::lonnet;
|
Line 73 package Apache::lonnet;
|
use strict; |
use strict; |
use LWP::UserAgent(); |
use LWP::UserAgent(); |
use HTTP::Date; |
use HTTP::Date; |
# use Date::Parse; |
use Image::Magick; |
|
|
use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir |
use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir |
$_64bit %env %protocol); |
$_64bit %env %protocol); |
|
|
Line 97 use LONCAPA::Configuration;
|
Line 98 use LONCAPA::Configuration;
|
my $readit; |
my $readit; |
my $max_connection_retries = 10; # Or some such value. |
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; |
require Exporter; |
|
|
our @ISA = qw (Exporter); |
our @ISA = qw (Exporter); |
Line 146 sub logthis {
|
Line 149 sub logthis {
|
my $now=time; |
my $now=time; |
my $local=localtime($now); |
my $local=localtime($now); |
if (open(my $fh,">>$execdir/logs/lonnet.log")) { |
if (open(my $fh,">>$execdir/logs/lonnet.log")) { |
print $fh "$local ($$): $message\n"; |
my $logstring = $local. " ($$): ".$message."\n"; # Keep any \'s in string. |
|
print $fh $logstring; |
close($fh); |
close($fh); |
} |
} |
return 1; |
return 1; |
Line 192 sub get_server_timezone {
|
Line 196 sub get_server_timezone {
|
} |
} |
} |
} |
|
|
|
sub get_server_loncaparev { |
|
my ($dom,$lonhost) = @_; |
|
if (defined($lonhost)) { |
|
if (!defined(&hostname($lonhost))) { |
|
undef($lonhost); |
|
} |
|
} |
|
if (!defined($lonhost)) { |
|
if (defined(&domain($dom,'primary'))) { |
|
$lonhost=&domain($dom,'primary'); |
|
if ($lonhost eq 'no_host') { |
|
undef($lonhost); |
|
} |
|
} |
|
} |
|
if (defined($lonhost)) { |
|
my $cachetime = 24*3600; |
|
my ($loncaparev,$cached)=&is_cached_new('serverloncaparev',$lonhost); |
|
if (defined($cached)) { |
|
return $loncaparev; |
|
} else { |
|
my $loncaparev = &reply('serverloncaparev',$lonhost); |
|
return &do_cache_new('serverloncaparev',$lonhost,$loncaparev,$cachetime); |
|
} |
|
} |
|
} |
|
|
# -------------------------------------------------- Non-critical communication |
# -------------------------------------------------- Non-critical communication |
sub subreply { |
sub subreply { |
my ($cmd,$server)=@_; |
my ($cmd,$server)=@_; |
Line 535 sub delenv {
|
Line 566 sub delenv {
|
tie(my %disk_env,'GDBM_File',$env{'user.environment'}, |
tie(my %disk_env,'GDBM_File',$env{'user.environment'}, |
(&GDBM_WRITER()|&GDBM_NOLOCK()),0640)) { |
(&GDBM_WRITER()|&GDBM_NOLOCK()),0640)) { |
foreach my $key (keys(%disk_env)) { |
foreach my $key (keys(%disk_env)) { |
if ($regexp) { |
if ($regexp) { |
if ($key=~/^$delthis/) { |
if ($key=~/^$delthis/) { |
delete($env{$key}); |
delete($env{$key}); |
delete($disk_env{$key}); |
delete($disk_env{$key}); |
} |
} |
} else { |
} else { |
if ($key=~/^\Q$delthis\E/) { |
if ($key=~/^\Q$delthis\E/) { |
delete($env{$key}); |
delete($env{$key}); |
delete($disk_env{$key}); |
delete($disk_env{$key}); |
} |
} |
} |
} |
} |
} |
untie(%disk_env); |
untie(%disk_env); |
Line 999 sub put_dom {
|
Line 1030 sub put_dom {
|
sub retrieve_inst_usertypes { |
sub retrieve_inst_usertypes { |
my ($udom) = @_; |
my ($udom) = @_; |
my (%returnhash,@order); |
my (%returnhash,@order); |
if (defined(&domain($udom,'primary'))) { |
my %domdefs = &Apache::lonnet::get_domain_defaults($udom); |
my $uhome=&domain($udom,'primary'); |
if ((ref($domdefs{'inststatustypes'}) eq 'HASH') && |
my $rep=&reply("inst_usertypes:$udom",$uhome); |
(ref($domdefs{'inststatusorder'}) eq 'ARRAY')) { |
if ($rep =~ /^(con_lost|error|no_such_host|refused)/) { |
%returnhash = %{$domdefs{'inststatustypes'}}; |
&logthis("get_dom failed - $rep returned from $uhome in domain: $udom"); |
@order = @{$domdefs{'inststatusorder'}}; |
return (\%returnhash,\@order); |
|
} |
|
my ($hashitems,$orderitems) = split(/:/,$rep); |
|
my @pairs=split(/\&/,$hashitems); |
|
foreach my $item (@pairs) { |
|
my ($key,$value)=split(/=/,$item,2); |
|
$key = &unescape($key); |
|
next if ($key =~ /^error: 2 /); |
|
$returnhash{$key}=&thaw_unescape($value); |
|
} |
|
my @esc_order = split(/\&/,$orderitems); |
|
foreach my $item (@esc_order) { |
|
push(@order,&unescape($item)); |
|
} |
|
} else { |
} else { |
&logthis("get_dom failed - no primary domain server for $udom"); |
if (defined(&domain($udom,'primary'))) { |
|
my $uhome=&domain($udom,'primary'); |
|
my $rep=&reply("inst_usertypes:$udom",$uhome); |
|
if ($rep =~ /^(con_lost|error|no_such_host|refused)/) { |
|
&logthis("get_dom failed - $rep returned from $uhome in domain: $udom"); |
|
return (\%returnhash,\@order); |
|
} |
|
my ($hashitems,$orderitems) = split(/:/,$rep); |
|
my @pairs=split(/\&/,$hashitems); |
|
foreach my $item (@pairs) { |
|
my ($key,$value)=split(/=/,$item,2); |
|
$key = &unescape($key); |
|
next if ($key =~ /^error: 2 /); |
|
$returnhash{$key}=&thaw_unescape($value); |
|
} |
|
my @esc_order = split(/\&/,$orderitems); |
|
foreach my $item (@esc_order) { |
|
push(@order,&unescape($item)); |
|
} |
|
} else { |
|
&logthis("get_dom failed - no primary domain server for $udom"); |
|
} |
} |
} |
return (\%returnhash,\@order); |
return (\%returnhash,\@order); |
} |
} |
Line 1256 sub get_domain_defaults {
|
Line 1294 sub get_domain_defaults {
|
} |
} |
my %domdefaults; |
my %domdefaults; |
my %domconfig = |
my %domconfig = |
&Apache::lonnet::get_dom('configuration',['defaults','quotas'],$domain); |
&Apache::lonnet::get_dom('configuration',['defaults','quotas', |
|
'requestcourses','inststatus'],$domain); |
if (ref($domconfig{'defaults'}) eq 'HASH') { |
if (ref($domconfig{'defaults'}) eq 'HASH') { |
$domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; |
$domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; |
$domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'}; |
$domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'}; |
Line 1281 sub get_domain_defaults {
|
Line 1320 sub get_domain_defaults {
|
} |
} |
} |
} |
} |
} |
|
if (ref($domconfig{'requestcourses'}) eq 'HASH') { |
|
foreach my $item ('official','unofficial') { |
|
$domdefaults{$item} = $domconfig{'requestcourses'}{$item}; |
|
} |
|
} |
|
if (ref($domconfig{'inststatus'}) eq 'HASH') { |
|
foreach my $item ('inststatustypes','inststatusorder') { |
|
$domdefaults{$item} = $domconfig{'inststatus'}{$item}; |
|
} |
|
} |
&Apache::lonnet::do_cache_new('domdefaults',$domain,\%domdefaults, |
&Apache::lonnet::do_cache_new('domdefaults',$domain,\%domdefaults, |
$cachetime); |
$cachetime); |
return %domdefaults; |
return %domdefaults; |
Line 2032 sub clean_filename {
|
Line 2081 sub clean_filename {
|
$fname=~s/\.(\d+)(?=\.)/_$1/g; |
$fname=~s/\.(\d+)(?=\.)/_$1/g; |
return $fname; |
return $fname; |
} |
} |
|
#This Function check if a Image max 400px width and height 500px. If not then scale the image down |
|
sub resizeImage { |
|
my($img_url) = @_; |
|
my $ima = Image::Magick->new; |
|
$ima->Read($img_url); |
|
if($ima->Get('width') > 400) |
|
{ |
|
my $factor = $ima->Get('width')/400; |
|
$ima->Scale( width=>400, height=>$ima->Get('height')/$factor ); |
|
} |
|
if($ima->Get('height') > 500) |
|
{ |
|
my $factor = $ima->Get('height')/500; |
|
$ima->Scale( width=>$ima->Get('width')/$factor, height=>500); |
|
} |
|
|
|
$ima->Write($img_url); |
|
} |
|
|
|
#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 |
# --------------- Take an uploaded file and put it into the userfiles directory |
# input: $formname - the contents of the file are in $env{"form.$formname"} |
# input: $formname - the contents of the file are in $env{"form.$formname"} |
Line 2132 sub finishuserfileupload {
|
Line 2207 sub finishuserfileupload {
|
$thumbwidth,$thumbheight) = @_; |
$thumbwidth,$thumbheight) = @_; |
my $path=$docudom.'/'.$docuname.'/'; |
my $path=$docudom.'/'.$docuname.'/'; |
my $filepath=$perlvar{'lonDocRoot'}; |
my $filepath=$perlvar{'lonDocRoot'}; |
|
|
my ($fnamepath,$file,$fetchthumb); |
my ($fnamepath,$file,$fetchthumb); |
$file=$fname; |
$file=$fname; |
if ($fname=~m|/|) { |
if ($fname=~m|/|) { |
Line 2146 sub finishuserfileupload {
|
Line 2222 sub finishuserfileupload {
|
mkdir($filepath,0777); |
mkdir($filepath,0777); |
} |
} |
} |
} |
|
|
# Save the file |
# Save the file |
{ |
{ |
if (!open(FH,'>'.$filepath.'/'.$file)) { |
if (!open(FH,'>'.$filepath.'/'.$file)) { |
Line 2159 sub finishuserfileupload {
|
Line 2236 sub finishuserfileupload {
|
return '/adm/notfound.html'; |
return '/adm/notfound.html'; |
} |
} |
close(FH); |
close(FH); |
|
if($upload_photo_form==1) |
|
{ |
|
resizeImage($filepath.'/'.$file); |
|
$upload_photo_form = 0; |
|
} |
} |
} |
if ($parser eq 'parse') { |
if ($parser eq 'parse') { |
my $parse_result = &extract_embedded_items($filepath.'/'.$file,$allfiles, |
my $parse_result = &extract_embedded_items($filepath.'/'.$file,$allfiles, |
Line 2180 sub finishuserfileupload {
|
Line 2262 sub finishuserfileupload {
|
|
|
# Notify homeserver to grep it |
# Notify homeserver to grep it |
# |
# |
my $docuhome=&homeserver($docuname,$docudom); |
my $docuhome=&homeserver($docuname,$docudom); |
my $fetchresult= &reply('fetchuserfile:'.$path.$file,$docuhome); |
my $fetchresult= &reply('fetchuserfile:'.$path.$file,$docuhome); |
if ($fetchresult eq 'ok') { |
if ($fetchresult eq 'ok') { |
if ($fetchthumb) { |
if ($fetchthumb) { |
Line 2312 sub add_filetype {
|
Line 2394 sub add_filetype {
|
} |
} |
|
|
sub removeuploadedurl { |
sub removeuploadedurl { |
my ($url)=@_; |
my ($url)=@_; |
my (undef,undef,$udom,$uname,$fname)=split('/',$url,5); |
my (undef,undef,$udom,$uname,$fname)=split('/',$url,5); |
return &removeuserfile($uname,$udom,$fname); |
return &removeuserfile($uname,$udom,$fname); |
} |
} |
|
|
sub removeuserfile { |
sub removeuserfile { |
my ($docuname,$docudom,$fname)=@_; |
my ($docuname,$docudom,$fname)=@_; |
my $home=&homeserver($docuname,$docudom); |
my $home=&homeserver($docuname,$docudom); |
my $result = &reply("removeuserfile:$docudom/$docuname/$fname",$home); |
my $result = &reply("removeuserfile:$docudom/$docuname/$fname",$home); |
if ($result eq 'ok') { |
if ($result eq 'ok') { |
if (($fname !~ /\.meta$/) && (&is_portfolio_file($fname))) { |
if (($fname !~ /\.meta$/) && (&is_portfolio_file($fname))) { |
my $metafile = $fname.'.meta'; |
my $metafile = $fname.'.meta'; |
my $metaresult = &removeuserfile($docuname,$docudom,$metafile); |
my $metaresult = &removeuserfile($docuname,$docudom,$metafile); |
my $url = "/uploaded/$docudom/$docuname/$fname"; |
my $url = "/uploaded/$docudom/$docuname/$fname"; |
my ($file,$group) = (&parse_portfolio_url($url))[3,4]; |
my ($file,$group) = (&parse_portfolio_url($url))[3,4]; |
my $sqlresult = |
my $sqlresult = |
&update_portfolio_table($docuname,$docudom,$file, |
&update_portfolio_table($docuname,$docudom,$file, |
'portfolio_metadata',$group, |
'portfolio_metadata',$group, |
Line 2624 sub courserolelog {
|
Line 2706 sub courserolelog {
|
$storehash{'section'} = $sec; |
$storehash{'section'} = $sec; |
} |
} |
&instructor_log($namespace,\%storehash,$delflag,$username,$domain,$cnum,$cdom); |
&instructor_log($namespace,\%storehash,$delflag,$username,$domain,$cnum,$cdom); |
if (($trole ne 'st') || ($sec ne '')) { |
|
&devalidate_cache_new('getcourseroles',$cdom.'_'.$cnum); |
|
} |
|
} |
} |
} |
} |
return; |
return; |
Line 2636 sub get_course_adv_roles {
|
Line 2715 sub get_course_adv_roles {
|
my ($cid,$codes) = @_; |
my ($cid,$codes) = @_; |
$cid=$env{'request.course.id'} unless (defined($cid)); |
$cid=$env{'request.course.id'} unless (defined($cid)); |
my %coursehash=&coursedescription($cid); |
my %coursehash=&coursedescription($cid); |
|
my $crstype = &Apache::loncommon::course_type($cid); |
my %nothide=(); |
my %nothide=(); |
foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) { |
foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) { |
if ($user !~ /:/) { |
if ($user !~ /:/) { |
Line 2648 sub get_course_adv_roles {
|
Line 2728 sub get_course_adv_roles {
|
my %dumphash= |
my %dumphash= |
&dump('nohist_userroles',$coursehash{'domain'},$coursehash{'num'}); |
&dump('nohist_userroles',$coursehash{'domain'},$coursehash{'num'}); |
my $now=time; |
my $now=time; |
my %privileged; |
|
foreach my $entry (keys %dumphash) { |
foreach my $entry (keys %dumphash) { |
my ($tend,$tstart)=split(/\:/,$dumphash{$entry}); |
my ($tend,$tstart)=split(/\:/,$dumphash{$entry}); |
if (($tstart) && ($tstart<0)) { next; } |
if (($tstart) && ($tstart<0)) { next; } |
Line 2656 sub get_course_adv_roles {
|
Line 2735 sub get_course_adv_roles {
|
if (($tstart) && ($now<$tstart)) { next; } |
if (($tstart) && ($now<$tstart)) { next; } |
my ($role,$username,$domain,$section)=split(/\:/,$entry); |
my ($role,$username,$domain,$section)=split(/\:/,$entry); |
if ($username eq '' || $domain eq '') { next; } |
if ($username eq '' || $domain eq '') { next; } |
unless (ref($privileged{$domain}) eq 'HASH') { |
if ((&privileged($username,$domain)) && |
my %dompersonnel = |
(!$nothide{$username.':'.$domain})) { next; } |
&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 ($role eq 'cr') { next; } |
if ($role eq 'cr') { next; } |
if ($codes) { |
if ($codes) { |
if ($section) { $role .= ':'.$section; } |
if ($section) { $role .= ':'.$section; } |
Line 2680 sub get_course_adv_roles {
|
Line 2746 sub get_course_adv_roles {
|
$returnhash{$role}=$username.':'.$domain; |
$returnhash{$role}=$username.':'.$domain; |
} |
} |
} else { |
} else { |
my $key=&plaintext($role); |
my $key=&plaintext($role,$crstype); |
if ($section) { $key.=' ('.&Apache::lonlocal::mt('Section [_1]',$section).')'; } |
if ($section) { $key.=' ('.&Apache::lonlocal::mt('Section [_1]',$section).')'; } |
if ($returnhash{$key}) { |
if ($returnhash{$key}) { |
$returnhash{$key}.=','.$username.':'.$domain; |
$returnhash{$key}.=','.$username.':'.$domain; |
Line 2715 sub get_my_roles {
|
Line 2781 sub get_my_roles {
|
} |
} |
my %returnhash=(); |
my %returnhash=(); |
my $now=time; |
my $now=time; |
my %privileged; |
|
foreach my $entry (keys(%dumphash)) { |
foreach my $entry (keys(%dumphash)) { |
my ($role,$tend,$tstart); |
my ($role,$tend,$tstart); |
if ($context eq 'userroles') { |
if ($context eq 'userroles') { |
Line 2764 sub get_my_roles {
|
Line 2829 sub get_my_roles {
|
} |
} |
} |
} |
if ($hidepriv) { |
if ($hidepriv) { |
if ($context eq 'userroles') { |
if ((&privileged($username,$domain)) && |
if ((&privileged($username,$domain)) && |
(!$nothide{$username.':'.$domain})) { |
(!$nothide{$username.':'.$domain})) { |
next; |
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 ($withsec) { |
if ($withsec) { |
Line 3873 sub del {
|
Line 3915 sub del {
|
foreach my $item (@$storearr) { |
foreach my $item (@$storearr) { |
$items.=&escape($item).'&'; |
$items.=&escape($item).'&'; |
} |
} |
|
|
$items=~s/\&$//; |
$items=~s/\&$//; |
if (!$udomain) { $udomain=$env{'user.domain'}; } |
if (!$udomain) { $udomain=$env{'user.domain'}; } |
if (!$uname) { $uname=$env{'user.name'}; } |
if (!$uname) { $uname=$env{'user.name'}; } |
my $uhome=&homeserver($uname,$udomain); |
my $uhome=&homeserver($uname,$udomain); |
|
|
return &reply("del:$udomain:$uname:$namespace:$items",$uhome); |
return &reply("del:$udomain:$uname:$namespace:$items",$uhome); |
} |
} |
|
|
Line 4438 sub is_portfolio_file {
|
Line 4480 sub is_portfolio_file {
|
} |
} |
|
|
sub usertools_access { |
sub usertools_access { |
my ($uname,$udom,$tool,$action) = @_; |
my ($uname,$udom,$tool,$action,$context) = @_; |
my $access; |
my ($access,%tools); |
my %tools = ( |
if ($context eq '') { |
aboutme => 1, |
$context = 'tools'; |
blog => 1, |
} |
portfolio => 1, |
if ($context eq 'requestcourses') { |
); |
%tools = ( |
|
official => 1, |
|
unofficial => 1, |
|
); |
|
} else { |
|
%tools = ( |
|
aboutme => 1, |
|
blog => 1, |
|
portfolio => 1, |
|
); |
|
} |
return if (!defined($tools{$tool})); |
return if (!defined($tools{$tool})); |
|
|
if ((!defined($udom)) || (!defined($uname))) { |
if ((!defined($udom)) || (!defined($uname))) { |
Line 4454 sub usertools_access {
|
Line 4506 sub usertools_access {
|
|
|
if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) { |
if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) { |
if ($action ne 'reload') { |
if ($action ne 'reload') { |
return $env{'environment.availabletools.'.$tool}; |
if ($context eq 'requestcourses') { |
|
return $env{'environment.canrequest.'.$tool}; |
|
} else { |
|
return $env{'environment.availabletools.'.$tool}; |
|
} |
} |
} |
} |
} |
|
|
my ($toolstatus,$inststatus); |
my ($toolstatus,$inststatus); |
|
|
if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) { |
if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'}) && |
$toolstatus = $env{'environment.tools.'.$tool}; |
($action ne 'reload')) { |
|
$toolstatus = $env{'environment.'.$context.'.'.$tool}; |
$inststatus = $env{'environment.inststatus'}; |
$inststatus = $env{'environment.inststatus'}; |
} else { |
} else { |
my %userenv = &userenvironment($udom,$uname,'tools.'.$tool); |
my %userenv = &userenvironment($udom,$uname,$context.'.'.$tool); |
$toolstatus = $userenv{'tools.'.$tool}; |
$toolstatus = $userenv{$context.'.'.$tool}; |
$inststatus = $userenv{'inststatus'}; |
$inststatus = $userenv{'inststatus'}; |
} |
} |
|
|
Line 4521 sub usertools_access {
|
Line 4578 sub usertools_access {
|
} |
} |
} |
} |
} else { |
} else { |
$access = 1; |
if ($context eq 'tools') { |
|
$access = 1; |
|
} else { |
|
$access = 0; |
|
} |
return $access; |
return $access; |
} |
} |
} |
} |
Line 5646 sub devalidate_getgroups_cache {
|
Line 5707 sub devalidate_getgroups_cache {
|
# ------------------------------------------------------------------ Plain Text |
# ------------------------------------------------------------------ Plain Text |
|
|
sub plaintext { |
sub plaintext { |
my ($short,$type,$cid) = @_; |
my ($short,$type,$cid,$forcedefault) = @_; |
if ($short =~ /^cr/) { |
if ($short =~ /^cr/) { |
return (split('/',$short))[-1]; |
return (split('/',$short))[-1]; |
} |
} |
if (!defined($cid)) { |
if (!defined($cid)) { |
$cid = $env{'request.course.id'}; |
$cid = $env{'request.course.id'}; |
} |
} |
if (defined($cid) && defined($env{'course.'.$cid.'.'.$short.'.plaintext'})) { |
if (defined($cid) && ($env{'course.'.$cid.'.'.$short.'.plaintext'} ne '')) { |
return &Apache::lonlocal::mt($env{'course.'.$cid.'.'.$short. |
unless ($forcedefault) { |
'.plaintext'}); |
my $roletext = $env{'course.'.$cid.'.'.$short.'.plaintext'}; |
|
&Apache::lonlocal::mt_escape(\$roletext); |
|
return &Apache::lonlocal::mt($roletext); |
|
} |
} |
} |
my %rolenames = ( |
my %rolenames = ( |
Course => 'std', |
Course => 'std', |
Line 5876 sub modifyuser {
|
Line 5940 sub modifyuser {
|
if ($email=~/\@/) { $names{'permanentemail'} = $email; } |
if ($email=~/\@/) { $names{'permanentemail'} = $email; } |
} |
} |
if ($uid) { $names{'id'} = $uid; } |
if ($uid) { $names{'id'} = $uid; } |
if (defined($inststatus)) { $names{'inststatus'} = $inststatus; } |
if (defined($inststatus)) { |
|
$names{'inststatus'} = ''; |
|
my ($usertypes,$typesorder) = &retrieve_inst_usertypes($udom); |
|
if (ref($usertypes) eq 'HASH') { |
|
my @okstatuses; |
|
foreach my $item (split(/:/,$inststatus)) { |
|
if (defined($usertypes->{$item})) { |
|
push(@okstatuses,$item); |
|
} |
|
} |
|
if (@okstatuses) { |
|
$names{'inststatus'} = join(':', map { &escape($_); } @okstatuses); |
|
} |
|
} |
|
} |
my $reply = &put('environment', \%names, $udom,$uname); |
my $reply = &put('environment', \%names, $udom,$uname); |
if ($reply ne 'ok') { return 'error: '.$reply; } |
if ($reply ne 'ok') { return 'error: '.$reply; } |
my $sqlresult = &update_allusers_table($uname,$udom,\%names); |
my $sqlresult = &update_allusers_table($uname,$udom,\%names); |
Line 5898 sub modifyuser {
|
Line 5976 sub modifyuser {
|
sub modifystudent { |
sub modifystudent { |
my ($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec, |
my ($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec, |
$end,$start,$forceid,$desiredhome,$email,$type,$locktype,$cid, |
$end,$start,$forceid,$desiredhome,$email,$type,$locktype,$cid, |
$selfenroll,$context)=@_; |
$selfenroll,$context,$inststatus)=@_; |
if (!$cid) { |
if (!$cid) { |
unless ($cid=$env{'request.course.id'}) { |
unless ($cid=$env{'request.course.id'}) { |
return 'not_in_class'; |
return 'not_in_class'; |
Line 5907 sub modifystudent {
|
Line 5985 sub modifystudent {
|
# --------------------------------------------------------------- Make the user |
# --------------------------------------------------------------- Make the user |
my $reply=&modifyuser |
my $reply=&modifyuser |
($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$forceid, |
($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$forceid, |
$desiredhome,$email); |
$desiredhome,$email,$inststatus); |
unless ($reply eq 'ok') { return $reply; } |
unless ($reply eq 'ok') { return $reply; } |
# This will cause &modify_student_enrollment to get the uid from the |
# This will cause &modify_student_enrollment to get the uid from the |
# students environment |
# students environment |
Line 8995 sub get_dns {
|
Line 9073 sub get_dns {
|
|
|
return %iphost; |
return %iphost; |
} |
} |
|
|
|
# |
|
# Given a DNS returns the loncapa host name for that DNS |
|
# |
|
sub host_from_dns { |
|
my ($dns) = @_; |
|
my @hosts; |
|
my $ip; |
|
|
|
if (exists($name_to_ip{$dns})) { |
|
$ip = $name_to_ip{$dns}; |
|
} |
|
if (!$ip) { |
|
$ip = gethostbyname($dns); # Initial translation to IP is in net order. |
|
if (length($ip) == 4) { |
|
$ip = &IO::Socket::inet_ntoa($ip); |
|
} |
|
} |
|
if ($ip) { |
|
@hosts = get_hosts_from_ip($ip); |
|
return $hosts[0]; |
|
} |
|
return undef; |
|
} |
|
|
} |
} |
|
|
BEGIN { |
BEGIN { |
Line 9277 in the user's environment.db and in %env
|
Line 9380 in the user's environment.db and in %env
|
=item * |
=item * |
X<delenv()> |
X<delenv()> |
B<delenv($delthis,$regexp)>: removes all items from the session |
B<delenv($delthis,$regexp)>: removes all items from the session |
environment file that begin with $delthis. If the |
environment file that begin with $delthis. If the |
optional second arg - $regexp - is true, $delthis is treated as a |
optional second arg - $regexp - is true, $delthis is treated as a |
regular expression, otherwise \Q$delthis\E is used. |
regular expression, otherwise \Q$delthis\E is used. |
The values are also deleted from the current processes %env. |
The values are also deleted from the current processes %env. |
|
|
=item * get_env_multiple($name) |
=item * get_env_multiple($name) |
Line 9377 and course level
|
Line 9480 and course level
|
|
|
=item * |
=item * |
|
|
plaintext($short) : return value in %prp hash (rolesplain.tab); plain text |
plaintext($short,$type,$cid,$forcedefault) : return value in %prp hash |
explanation of a user role term |
(rolesplain.tab); plain text explanation of a user role term. |
|
$type is Course (default) or Group. |
|
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. |
|
|
=item * |
=item * |
|
|
get_my_roles($uname,$udom,$context,$types,$roles,$roledoms,$withsec) : |
get_my_roles($uname,$udom,$context,$types,$roles,$roledoms,$withsec) : |
Line 9888 dirlist($uri) : return directory list ba
|
Line 9996 dirlist($uri) : return directory list ba
|
|
|
spareserver() : find server with least workload from spare.tab |
spareserver() : find server with least workload from spare.tab |
|
|
|
|
|
=item * |
|
|
|
host_from_dns($dns) : Returns the loncapa hostname corresponding to a DNS name or undef |
|
if there is no corresponding loncapa host. |
|
|
=back |
=back |
|
|
|
|
=head2 Apache Request |
=head2 Apache Request |
|
|
=over 4 |
=over 4 |