version 1.1043, 2009/11/12 15:58:34
|
version 1.1056.4.1, 2010/05/18 04:22:00
|
Line 99 use LONCAPA::Configuration;
|
Line 99 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 1353 sub get_domain_defaults {
|
Line 1351 sub get_domain_defaults {
|
my %domdefaults; |
my %domdefaults; |
my %domconfig = |
my %domconfig = |
&Apache::lonnet::get_dom('configuration',['defaults','quotas', |
&Apache::lonnet::get_dom('configuration',['defaults','quotas', |
'requestcourses','inststatus'],$domain); |
'requestcourses','inststatus', |
|
'coursedefaults'],$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 1388 sub get_domain_defaults {
|
Line 1387 sub get_domain_defaults {
|
$domdefaults{$item} = $domconfig{'inststatus'}{$item}; |
$domdefaults{$item} = $domconfig{'inststatus'}{$item}; |
} |
} |
} |
} |
|
if (ref($domconfig{'coursedefaults'}) eq 'HASH') { |
|
foreach my $item ('canuse_pdfforms') { |
|
$domdefaults{$item} = $domconfig{'coursedefaults'}{$item}; |
|
} |
|
} |
&Apache::lonnet::do_cache_new('domdefaults',$domain,\%domdefaults, |
&Apache::lonnet::do_cache_new('domdefaults',$domain,\%domdefaults, |
$cachetime); |
$cachetime); |
return %domdefaults; |
return %domdefaults; |
Line 1722 sub userenvironment {
|
Line 1726 sub userenvironment {
|
unless ($uhome eq 'no_host') { |
unless ($uhome eq 'no_host') { |
my @answer=split(/\&/, |
my @answer=split(/\&/, |
&reply('get:'.$udom.':'.$unam.':environment:'.$items,$uhome)); |
&reply('get:'.$udom.':'.$unam.':environment:'.$items,$uhome)); |
|
if ($#answer==0 && $answer[0] =~ /^(con_lost|error:|no_such_host)/i) { |
|
return %returnhash; |
|
} |
my $i; |
my $i; |
for ($i=0;$i<=$#what;$i++) { |
for ($i=0;$i<=$#what;$i++) { |
$returnhash{$what[$i]}=&unescape($answer[$i]); |
$returnhash{$what[$i]}=&unescape($answer[$i]); |
Line 2147 sub clean_filename {
|
Line 2154 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 |
# This Function checks if an Image's dimensions exceed either $resizewidth (width) |
|
# or $resizeheight (height) - both pixels. If so, the image is scaled to produce an |
|
# image with the same aspect ratio as the original, but with dimensions which do |
|
# not exceed $resizewidth and $resizeheight. |
|
|
sub resizeImage { |
sub resizeImage { |
my($img_url) = @_; |
my ($img_path,$resizewidth,$resizeheight) = @_; |
my $ima = Image::Magick->new; |
my $ima = Image::Magick->new; |
$ima->Read($img_url); |
my $resized; |
if($ima->Get('width') > 400) |
if (-e $img_path) { |
{ |
$ima->Read($img_path); |
my $factor = $ima->Get('width')/400; |
if (($resizewidth =~ /^\d+$/) && ($resizeheight > 0)) { |
$ima->Scale( width=>400, height=>$ima->Get('height')/$factor ); |
my $width = $ima->Get('width'); |
} |
my $height = $ima->Get('height'); |
if($ima->Get('height') > 500) |
if ($width > $resizewidth) { |
{ |
my $factor = $width/$resizewidth; |
my $factor = $ima->Get('height')/500; |
my $newheight = $height/$factor; |
$ima->Scale( width=>$ima->Get('width')/$factor, height=>500); |
$ima->Scale(width=>$resizewidth,height=>$newheight); |
} |
$resized = 1; |
|
} |
$ima->Write($img_url); |
} |
} |
if (($resizeheight =~ /^\d+$/) && ($resizeheight > 0)) { |
|
my $width = $ima->Get('width'); |
#Wrapper function for userphotoupload |
my $height = $ima->Get('height'); |
sub userphotoupload |
if ($height > $resizeheight) { |
{ |
my $factor = $height/$resizeheight; |
my($formname,$subdir) = @_; |
my $newwidth = $width/$factor; |
$upload_photo_form = 1; |
$ima->Scale(width=>$newwidth,height=>$resizeheight); |
return &userfileupload($formname,undef,$subdir); |
$resized = 1; |
|
} |
|
} |
|
if ($resized) { |
|
$ima->Write($img_path); |
|
} |
|
} |
|
return; |
} |
} |
|
|
# --------------- Take an uploaded file and put it into the userfiles directory |
# --------------- Take an uploaded file and put it into the userfiles directory |
Line 2187 sub userphotoupload
|
Line 2205 sub userphotoupload
|
# $dsetudom - domain for permanaent storage of uploaded file |
# $dsetudom - domain for permanaent storage of uploaded file |
# $thumbwidth - width (pixels) of thumbnail to make for uploaded image |
# $thumbwidth - width (pixels) of thumbnail to make for uploaded image |
# $thumbheight - height (pixels) of thumbnail to make for uploaded image |
# $thumbheight - height (pixels) of thumbnail to make for uploaded image |
|
# $resizewidth - width (pixels) to which to resize uploaded image |
|
# $resizeheight - height (pixels) to which to resize uploaded image |
# |
# |
# output: url of file in userspace, or error: <message> |
# output: url of file in userspace, or error: <message> |
# or /adm/notfound.html if failure to upload occurse |
# or /adm/notfound.html if failure to upload occurse |
|
|
|
|
sub userfileupload { |
sub userfileupload { |
my ($formname,$coursedoc,$subdir,$parser,$allfiles,$codebase,$destuname, |
my ($formname,$coursedoc,$subdir,$parser,$allfiles,$codebase,$destuname, |
$destudom,$thumbwidth,$thumbheight)=@_; |
$destudom,$thumbwidth,$thumbheight,$resizewidth,$resizeheight)=@_; |
if (!defined($subdir)) { $subdir='unknown'; } |
if (!defined($subdir)) { $subdir='unknown'; } |
my $fname=$env{'form.'.$formname.'.filename'}; |
my $fname=$env{'form.'.$formname.'.filename'}; |
$fname=&clean_filename($fname); |
$fname=&clean_filename($fname); |
Line 2244 sub userfileupload {
|
Line 2263 sub userfileupload {
|
if ($env{'form.folder'} =~ m/^(default|supplemental)/) { |
if ($env{'form.folder'} =~ m/^(default|supplemental)/) { |
return &finishuserfileupload($docuname,$docudom, |
return &finishuserfileupload($docuname,$docudom, |
$formname,$fname,$parser,$allfiles, |
$formname,$fname,$parser,$allfiles, |
$codebase,$thumbwidth,$thumbheight); |
$codebase,$thumbwidth,$thumbheight, |
|
$resizewidth,$resizeheight); |
} else { |
} else { |
$fname=$env{'form.folder'}.'/'.$fname; |
$fname=$env{'form.folder'}.'/'.$fname; |
return &process_coursefile('uploaddoc',$docuname,$docudom, |
return &process_coursefile('uploaddoc',$docuname,$docudom, |
Line 2256 sub userfileupload {
|
Line 2276 sub userfileupload {
|
my $docudom=$destudom; |
my $docudom=$destudom; |
return &finishuserfileupload($docuname,$docudom,$formname,$fname, |
return &finishuserfileupload($docuname,$docudom,$formname,$fname, |
$parser,$allfiles,$codebase, |
$parser,$allfiles,$codebase, |
$thumbwidth,$thumbheight); |
$thumbwidth,$thumbheight, |
|
$resizewidth,$resizeheight); |
|
|
} else { |
} else { |
my $docuname=$env{'user.name'}; |
my $docuname=$env{'user.name'}; |
Line 2267 sub userfileupload {
|
Line 2288 sub userfileupload {
|
} |
} |
return &finishuserfileupload($docuname,$docudom,$formname,$fname, |
return &finishuserfileupload($docuname,$docudom,$formname,$fname, |
$parser,$allfiles,$codebase, |
$parser,$allfiles,$codebase, |
$thumbwidth,$thumbheight); |
$thumbwidth,$thumbheight, |
|
$resizewidth,$resizeheight); |
} |
} |
} |
} |
|
|
sub finishuserfileupload { |
sub finishuserfileupload { |
my ($docuname,$docudom,$formname,$fname,$parser,$allfiles,$codebase, |
my ($docuname,$docudom,$formname,$fname,$parser,$allfiles,$codebase, |
$thumbwidth,$thumbheight) = @_; |
$thumbwidth,$thumbheight,$resizewidth,$resizeheight) = @_; |
my $path=$docudom.'/'.$docuname.'/'; |
my $path=$docudom.'/'.$docuname.'/'; |
my $filepath=$perlvar{'lonDocRoot'}; |
my $filepath=$perlvar{'lonDocRoot'}; |
|
|
Line 2305 sub finishuserfileupload {
|
Line 2327 sub finishuserfileupload {
|
return '/adm/notfound.html'; |
return '/adm/notfound.html'; |
} |
} |
close(FH); |
close(FH); |
if($upload_photo_form==1) |
if ($resizewidth && $resizeheight) { |
{ |
my $mm = new File::MMagic; |
resizeImage($filepath.'/'.$file); |
my $mime_type = $mm->checktype_filename($filepath.'/'.$file); |
$upload_photo_form = 0; |
if ($mime_type =~ m{^image/}) { |
|
&resizeImage($filepath.'/'.$file,$resizewidth,$resizeheight); |
|
} |
} |
} |
} |
} |
if ($parser eq 'parse') { |
if ($parser eq 'parse') { |
Line 2760 sub courserolelog {
|
Line 2784 sub courserolelog {
|
if (($trole eq 'cc') || ($trole eq 'in') || |
if (($trole eq 'cc') || ($trole eq 'in') || |
($trole eq 'ep') || ($trole eq 'ad') || |
($trole eq 'ep') || ($trole eq 'ad') || |
($trole eq 'ta') || ($trole eq 'st') || |
($trole eq 'ta') || ($trole eq 'st') || |
($trole=~/^cr/) || ($trole eq 'gr')) { |
($trole=~/^cr/) || ($trole eq 'gr') || |
|
($trole eq 'co')) { |
if ($area =~ m-^/($match_domain)/($match_courseid)/?([^/]*)-) { |
if ($area =~ m-^/($match_domain)/($match_courseid)/?([^/]*)-) { |
my $cdom = $1; |
my $cdom = $1; |
my $cnum = $2; |
my $cnum = $2; |
Line 2994 sub getannounce {
|
Line 3019 sub getannounce {
|
|
|
sub courseidput { |
sub courseidput { |
my ($domain,$storehash,$coursehome,$caller) = @_; |
my ($domain,$storehash,$coursehome,$caller) = @_; |
|
return unless (ref($storehash) eq 'HASH'); |
my $outcome; |
my $outcome; |
if ($caller eq 'timeonly') { |
if ($caller eq 'timeonly') { |
my $cids = ''; |
my $cids = ''; |
Line 3078 sub courseiddump {
|
Line 3104 sub courseiddump {
|
return %returnhash; |
return %returnhash; |
} |
} |
|
|
|
sub courselastaccess { |
|
my ($cdom,$cnum,$hostidref) = @_; |
|
my %returnhash; |
|
if ($cdom && $cnum) { |
|
my $chome = &homeserver($cnum,$cdom); |
|
if ($chome ne 'no_host') { |
|
my $rep = &reply('courselastaccess:'.$cdom.':'.$cnum,$chome); |
|
&extract_lastaccess(\%returnhash,$rep); |
|
} |
|
} else { |
|
if (!$cdom) { $cdom=''; } |
|
my %libserv = &all_library(); |
|
foreach my $tryserver (keys(%libserv)) { |
|
if (ref($hostidref) eq 'ARRAY') { |
|
next unless (grep(/^\Q$tryserver\E$/,@{$hostidref})); |
|
} |
|
if (($cdom eq '') || (&host_domain($tryserver) eq $cdom)) { |
|
my $rep = &reply('courselastaccess:'.&host_domain($tryserver).':',$tryserver); |
|
&extract_lastaccess(\%returnhash,$rep); |
|
} |
|
} |
|
} |
|
return %returnhash; |
|
} |
|
|
|
sub extract_lastaccess { |
|
my ($returnhash,$rep) = @_; |
|
if (ref($returnhash) eq 'HASH') { |
|
unless ($rep eq 'unknown_command' || $rep eq 'no_such_host' || |
|
$rep eq 'con_lost' || $rep eq 'rejected' || $rep eq 'refused' || |
|
$rep eq '') { |
|
my @pairs=split(/\&/,$rep); |
|
foreach my $item (@pairs) { |
|
my ($key,$value)=split(/\=/,$item,2); |
|
$key = &unescape($key); |
|
next if ($key =~ /^error: 2 /); |
|
$returnhash->{$key} = &thaw_unescape($value); |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
# ---------------------------------------------------------- DC e-mail |
# ---------------------------------------------------------- DC e-mail |
|
|
sub dcmailput { |
sub dcmailput { |
Line 4028 sub role_status {
|
Line 4097 sub role_status {
|
); |
); |
my $spec=$$role.'.'.$$where; |
my $spec=$$role.'.'.$$where; |
my ($tdummy,$tdomain,$trest)=split(/\//,$$where); |
my ($tdummy,$tdomain,$trest)=split(/\//,$$where); |
if ($$role eq 'gr') { |
|
my %rolehash = &get('roles',[$$where.'_'.$$role],$env{'user.domain'}, |
|
$env{'user.name'})=@_; |
|
my ($trole) = split('_',$role,1); |
|
(undef,my $group_privs) = split(/\//,$trole); |
|
$group_privs = &unescape($group_privs); |
|
} |
|
if ($$role =~ /^cr\//) { |
if ($$role =~ /^cr\//) { |
&custom_roleprivs(\%allroles,$$role,$tdomain,$trest,$spec,$$where); |
&custom_roleprivs(\%allroles,$$role,$tdomain,$trest,$spec,$$where); |
} elsif ($$role eq 'gr') { |
} elsif ($$role eq 'gr') { |
Line 4562 sub get_portfolio_access {
|
Line 4624 sub get_portfolio_access {
|
my (%allgroups,%allroles); |
my (%allgroups,%allroles); |
my ($start,$end,$role,$sec,$group); |
my ($start,$end,$role,$sec,$group); |
foreach my $envkey (%env) { |
foreach my $envkey (%env) { |
if ($envkey =~ m-^user\.role\.(gr|cc|in|ta|ep|st)\./($match_domain)/($match_courseid)/?([^/]*)$-) { |
if ($envkey =~ m-^user\.role\.(gr|cc|co|in|ta|ep|ad|st)\./($match_domain)/($match_courseid)/?([^/]*)$-) { |
my $cid = $2.'_'.$3; |
my $cid = $2.'_'.$3; |
if ($1 eq 'gr') { |
if ($1 eq 'gr') { |
$group = $4; |
$group = $4; |
Line 4810 sub usertools_access {
|
Line 4872 sub usertools_access {
|
} |
} |
} |
} |
|
|
|
sub is_course_owner { |
|
my ($cdom,$cnum,$udom,$uname) = @_; |
|
if (($udom eq '') || ($uname eq '')) { |
|
$udom = $env{'user.domain'}; |
|
$uname = $env{'user.name'}; |
|
} |
|
unless (($udom eq '') || ($uname eq '')) { |
|
if (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'})) { |
|
if ($env{'course.'.$cdom.'_'.$cnum.'.internal.courseowner'} eq $uname.':'.$udom) { |
|
return 1; |
|
} else { |
|
my %courseinfo = &Apache::lonnet::coursedescription($cdom.'/'.$cnum); |
|
if ($courseinfo{'internal.courseowner'} eq $uname.':'.$udom) { |
|
return 1; |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
sub is_advanced_user { |
sub is_advanced_user { |
my ($udom,$uname) = @_; |
my ($udom,$uname) = @_; |
my %roleshash = &get_my_roles($uname,$udom,'userroles',undef,undef,undef,1); |
my %roleshash = &get_my_roles($uname,$udom,'userroles',undef,undef,undef,1); |
Line 6141 sub devalidate_getgroups_cache {
|
Line 6224 sub devalidate_getgroups_cache {
|
|
|
sub plaintext { |
sub plaintext { |
my ($short,$type,$cid,$forcedefault) = @_; |
my ($short,$type,$cid,$forcedefault) = @_; |
if ($short =~ /^cr/) { |
if ($short =~ m{^cr/}) { |
return (split('/',$short))[-1]; |
return (split('/',$short))[-1]; |
} |
} |
if (!defined($cid)) { |
if (!defined($cid)) { |
Line 6230 sub assignrole {
|
Line 6313 sub assignrole {
|
$refused = 1; |
$refused = 1; |
} |
} |
if ($refused) { |
if ($refused) { |
if (($selfenroll == 1) && ($role eq 'st') && ($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) { |
my ($cdom,$cnum) = ($cwosec =~ m{^/?($match_domain)/($match_courseid)$}); |
|
if (!$selfenroll && $context eq 'course') { |
|
my %crsenv; |
|
if ($role eq 'cc' || $role eq 'co') { |
|
%crsenv = &userenvironment($cdom,$cnum,('internal.courseowner')); |
|
if (($role eq 'cc') && ($cnum !~ /^$match_community$/)) { |
|
if ($env{'request.role'} eq 'cc./'.$cdom.'/'.$cnum) { |
|
if ($crsenv{'internal.courseowner'} eq |
|
$env{'user.name'}.':'.$env{'user.domain'}) { |
|
$refused = ''; |
|
} |
|
} |
|
} elsif (($role eq 'co') && ($cnum =~ /^$match_community$/)) { |
|
if ($env{'request.role'} eq 'co./'.$cdom.'/'.$cnum) { |
|
if ($crsenv{'internal.courseowner'} eq |
|
$env{'user.name'}.':'.$env{'user.domain'}) { |
|
$refused = ''; |
|
} |
|
} |
|
} |
|
} |
|
} elsif (($selfenroll == 1) && ($role eq 'st') && ($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) { |
$refused = ''; |
$refused = ''; |
} elsif ($context eq 'requestcourses') { |
} elsif ($context eq 'requestcourses') { |
my @possroles = ('st','ta','ep','in','cc','co'); |
my @possroles = ('st','ta','ep','in','cc','co'); |
if ((grep(/^\Q$role\E$/,@possroles)) && ($env{'user.name'} ne '' && $env{'user.domain'} ne '')) { |
if ((grep(/^\Q$role\E$/,@possroles)) && ($env{'user.name'} ne '' && $env{'user.domain'} ne '')) { |
my ($cdom,$cnum) = ($cwosec =~ m{^/?($match_domain)/($match_courseid)$}); |
|
my $wrongcc; |
my $wrongcc; |
if ($cnum =~ /^$match_community$/) { |
if ($cnum =~ /^$match_community$/) { |
$wrongcc = 1 if ($role eq 'cc'); |
$wrongcc = 1 if ($role eq 'cc'); |
Line 6298 sub assignrole {
|
Line 6401 sub assignrole {
|
&Apache::longroup::group_changes($udom,$uname,$url,$role,$origend, |
&Apache::longroup::group_changes($udom,$uname,$url,$role,$origend, |
$origstart,$selfenroll,$context); |
$origstart,$selfenroll,$context); |
} |
} |
|
if ($role eq 'cc') { |
|
&autoupdate_coowners($url,$end,$start,$uname,$udom); |
|
} |
} |
} |
return $answer; |
return $answer; |
} |
} |
|
|
|
sub autoupdate_coowners { |
|
my ($url,$end,$start,$uname,$udom) = @_; |
|
my ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_courseid)}); |
|
if (($cdom ne '') && ($cnum ne '')) { |
|
my $now = time; |
|
my %domdesign = &Apache::loncommon::get_domainconf($cdom); |
|
if ($domdesign{$cdom.'.autoassign.co-owners'}) { |
|
my %coursehash = &coursedescription($cdom.'_'.$cnum); |
|
my $instcode = $coursehash{'internal.coursecode'}; |
|
if ($instcode ne '') { |
|
if (($start && $start <= $now) && ($end == 0) || ($end > $now)) { |
|
unless ($coursehash{'internal.courseowner'} eq $uname.':'.$udom) { |
|
my ($delcoowners,@newcoowners,$putresult,$delresult,$coowners); |
|
my ($result,$desc) = &auto_validate_instcode($cnum,$cdom,$instcode,$uname.':'.$udom); |
|
if ($result eq 'valid') { |
|
if ($coursehash{'internal.co-owners'}) { |
|
foreach my $coowner (split(',',$coursehash{'internal.co-owners'})) { |
|
push(@newcoowners,$coowner); |
|
} |
|
unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) { |
|
push(@newcoowners,$uname.':'.$udom); |
|
} |
|
@newcoowners = sort(@newcoowners); |
|
} else { |
|
push(@newcoowners,$uname.':'.$udom); |
|
} |
|
} else { |
|
if ($coursehash{'internal.co-owners'}) { |
|
foreach my $coowner (split(',',$coursehash{'internal.co-owners'})) { |
|
unless ($coowner eq $uname.':'.$udom) { |
|
push(@newcoowners,$coowner); |
|
} |
|
} |
|
unless (@newcoowners > 0) { |
|
$delcoowners = 1; |
|
$coowners = ''; |
|
} |
|
} |
|
} |
|
if (@newcoowners || $delcoowners) { |
|
&store_coowners($cdom,$cnum,$coursehash{'home'}, |
|
$delcoowners,@newcoowners); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
sub store_coowners { |
|
my ($cdom,$cnum,$chome,$delcoowners,@newcoowners) = @_; |
|
my $cid = $cdom.'_'.$cnum; |
|
my ($coowners,$delresult,$putresult); |
|
if (@newcoowners) { |
|
$coowners = join(',',@newcoowners); |
|
my %coownershash = ( |
|
'internal.co-owners' => $coowners, |
|
); |
|
$putresult = &put('environment',\%coownershash,$cdom,$cnum); |
|
if ($putresult eq 'ok') { |
|
if ($env{'course.'.$cid.'.num'} eq $cnum) { |
|
&appenv({'course.'.$cid.'.internal.co-owners' => $coowners}); |
|
} |
|
} |
|
} |
|
if ($delcoowners) { |
|
$delresult = &Apache::lonnet::del('environment',['internal.co-owners'],$cdom,$cnum); |
|
if ($delresult eq 'ok') { |
|
if ($env{'course.'.$cid.'.internal.co-owners'}) { |
|
&Apache::lonnet::delenv('course.'.$cid.'.internal.co-owners'); |
|
} |
|
} |
|
} |
|
if (($putresult eq 'ok') || ($delresult eq 'ok')) { |
|
my %crsinfo = |
|
&Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.'); |
|
if (ref($crsinfo{$cid}) eq 'HASH') { |
|
$crsinfo{$cid}{'co-owners'} = \@newcoowners; |
|
my $cidput = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime'); |
|
} |
|
} |
|
} |
|
|
# -------------------------------------------------- Modify user authentication |
# -------------------------------------------------- Modify user authentication |
# Overrides without validation |
# Overrides without validation |
|
|
Line 6334 sub modifyuser {
|
Line 6524 sub modifyuser {
|
my ($udom, $uname, $uid, |
my ($udom, $uname, $uid, |
$umode, $upass, $first, |
$umode, $upass, $first, |
$middle, $last, $gene, |
$middle, $last, $gene, |
$forceid, $desiredhome, $email, $inststatus)=@_; |
$forceid, $desiredhome, $email, $inststatus, $candelete)=@_; |
$udom= &LONCAPA::clean_domain($udom); |
$udom= &LONCAPA::clean_domain($udom); |
$uname=&LONCAPA::clean_username($uname); |
$uname=&LONCAPA::clean_username($uname); |
|
my $showcandelete = 'none'; |
|
if (ref($candelete) eq 'ARRAY') { |
|
if (@{$candelete} > 0) { |
|
$showcandelete = join(', ',@{$candelete}); |
|
} |
|
} |
&logthis('Call to modify user '.$udom.', '.$uname.', '.$uid.', '. |
&logthis('Call to modify user '.$udom.', '.$uname.', '.$uid.', '. |
$umode.', '.$first.', '.$middle.', '. |
$umode.', '.$first.', '.$middle.', '. |
$last.', '.$gene.'(forceid: '.$forceid.')'. |
$last.', '.$gene.'(forceid: '.$forceid.'; candelete: '.$showcandelete.')'. |
(defined($desiredhome) ? ' desiredhome = '.$desiredhome : |
(defined($desiredhome) ? ' desiredhome = '.$desiredhome : |
' desiredhome not specified'). |
' desiredhome not specified'). |
' by '.$env{'user.name'}.' at '.$env{'user.domain'}. |
' by '.$env{'user.name'}.' at '.$env{'user.domain'}. |
Line 6403 sub modifyuser {
|
Line 6599 sub modifyuser {
|
} else { |
} else { |
%names = @tmp; |
%names = @tmp; |
} |
} |
# |
# If name, email and/or uid are blank (e.g., because an uploaded file |
# Make sure to not trash student environment if instructor does not bother |
# of users did not contain them), do not overwrite existing values |
# to supply name and email information |
# unless field is in $candelete array ref. |
# |
# |
|
|
|
my @fields = ('firstname','middlename','lastname','generation', |
|
'permanentemail','id'); |
|
my %newvalues; |
|
if (ref($candelete) eq 'ARRAY') { |
|
foreach my $field (@fields) { |
|
if (grep(/^\Q$field\E$/,@{$candelete})) { |
|
if ($field eq 'firstname') { |
|
$names{$field} = $first; |
|
} elsif ($field eq 'middlename') { |
|
$names{$field} = $middle; |
|
} elsif ($field eq 'lastname') { |
|
$names{$field} = $last; |
|
} elsif ($field eq 'generation') { |
|
$names{$field} = $gene; |
|
} elsif ($field eq 'permanentemail') { |
|
$names{$field} = $email; |
|
} elsif ($field eq 'id') { |
|
$names{$field} = $uid; |
|
} |
|
} |
|
} |
|
} |
if ($first) { $names{'firstname'} = $first; } |
if ($first) { $names{'firstname'} = $first; } |
if (defined($middle)) { $names{'middlename'} = $middle; } |
if (defined($middle)) { $names{'middlename'} = $middle; } |
if ($last) { $names{'lastname'} = $last; } |
if ($last) { $names{'lastname'} = $last; } |
Line 6626 sub createcourse {
|
Line 6845 sub createcourse {
|
} |
} |
return $uname if ($uname =~ /^error/); |
return $uname if ($uname =~ /^error/); |
# -------------------------------------------------- Check supplied server name |
# -------------------------------------------------- Check supplied server name |
$course_server = $env{'user.homeserver'} if (! defined($course_server)); |
if (!defined($course_server)) { |
if (! &is_library($course_server)) { |
if (defined(&domain($udom,'primary'))) { |
return 'error:bad server name '.$course_server; |
$course_server = &domain($udom,'primary'); |
|
} else { |
|
$course_server = $env{'user.home'}; |
|
} |
|
} |
|
my %host_servers = |
|
&Apache::lonnet::get_servers($udom,'library'); |
|
unless ($host_servers{$course_server}) { |
|
return 'error: invalid home server for course: '.$course_server; |
} |
} |
# ------------------------------------------------------------- Make the course |
# ------------------------------------------------------------- Make the course |
my $reply=&reply('encrypt:makeuser:'.$udom.':'.$uname.':none::', |
my $reply=&reply('encrypt:makeuser:'.$udom.':'.$uname.':none::', |
Line 6675 ENDINITMAP
|
Line 6902 ENDINITMAP
|
} |
} |
# ----------------------------------------------------------- Write preferences |
# ----------------------------------------------------------- Write preferences |
&writecoursepref($udom.'_'.$uname, |
&writecoursepref($udom.'_'.$uname, |
('description' => $description, |
('description' => $description, |
'url' => $topurl)); |
'url' => $topurl, |
|
'internal.creator' => $env{'user.name'}.':'. |
|
$env{'user.domain'}, |
|
'internal.created' => $now, |
|
'internal.creationcontext' => $context) |
|
); |
return '/'.$udom.'/'.$uname; |
return '/'.$udom.'/'.$uname; |
} |
} |
|
|
Line 10120 modifyuserauth($udom,$uname,$umode,$upas
|
Line 10352 modifyuserauth($udom,$uname,$umode,$upas
|
|
|
=item * |
=item * |
|
|
modifyuser($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene, |
modifyuser($udom,$uname,$uid,$umode,$upass,$first,$middle,$last, $gene, |
$forceid,$desiredhome,$email,$inststatus) : |
$forceid,$desiredhome,$email,$inststatus,$candelete) : |
modify user |
|
|
will update user information (firstname,middlename,lastname,generation, |
|
permanentemail), and if forceid is true, student/employee ID also. |
|
A user's institutional affiliation(s) can also be updated. |
|
User information fields will not be overwritten with empty entries |
|
unless the field is included in the $candelete array reference. |
|
This array is included when a single user is modified via "Manage Users", |
|
or when Autoupdate.pl is run by cron in a domain. |
|
|
=item * |
=item * |
|
|