--- loncom/xml/lonxml.pm 2001/08/09 20:32:36 1.108 +++ loncom/xml/lonxml.pm 2001/08/15 23:19:20 1.115 @@ -13,7 +13,7 @@ # 6/12,6/13 H. K. Ng # 6/16 Gerd Kortemeyer # 7/27 H. K. Ng -# 8/7,8/9 Gerd Kortemeyer +# 8/7,8/9,8/10,8/11,8/15 Gerd Kortemeyer package Apache::lonxml; use vars @@ -97,6 +97,12 @@ sub xmlbegin { sub xmlend { my $discussion=''; if ($ENV{'request.course.id'}) { + my $crs='/'.$ENV{'request.course.id'}; + if ($ENV{'request.course.sec'}) { + $crs.='_'.$ENV{'request.course.sec'}; + } + $crs=~s/\_/\//g; + my $seeid=&Apache::lonnet::allowed('rin',$crs); my $symb=&Apache::lonnet::symbread(); if ($symb) { my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, @@ -107,13 +113,37 @@ sub xmlend { '

Course Discussion of Resource

'; my $idx; for ($idx=1;$idx<=$contrib{'version'};$idx++) { - my $message=$contrib{$idx.':message'}; - $message=~s/\n/\
/g; - $discussion.='

'.$contrib{$idx.':sendername'}.' at '. - $contrib{$idx.':senderdomain'}.' ('. + my $hidden=($contrib{'hidden'}=~/\.$idx\./); + unless (($hidden) && (!$seeid)) { + my $message=$contrib{$idx.':message'}; + $message=~s/\n/\
/g; + if ($message) { + if ($hidden) { + $message=''.$message.''; + } + my $sender='Anonymous'; + if ((!$contrib{$idx.':anonymous'}) || ($seeid)) { + $sender=$contrib{$idx.':sendername'}.' at '. + $contrib{$idx.':senderdomain'}; + if ($contrib{$idx.':anonymous'}) { + $sender.=' (anonymous)'; + } + if ($seeid) { + if ($hidden) { + $sender.=' Make Visible'; + } else { + $sender.=' Hide'; + } + } + } + $discussion.='

'.$sender.' ('. localtime($contrib{$idx.':timestamp'}). '):

'.$message. - '

'; + '

'; + } + } } $discussion.='
'; } @@ -122,6 +152,66 @@ sub xmlend { return $discussion.''; } +sub checkout { + my ($target,$symb,$tuname,$tudom,$tcrsid)=@_; + unless ($symb) { + $symb=&Apache::lonnet::symbread(); + } + unless ($tuname) { + $tuname=$ENV{'user.name'}; + $tudom=$ENV{'user.domain'}; + $tcrsid=$ENV{'request.course.id'}; + } + my $now=time; + my $lonhost = $Apache::lonnet::perlvar{'lonHostID'}; + my $infostr=&Apache::lonnet::escape( + $tuname.'&'. + $tudom.'&'. + $tcrsid.'&'. + $symb.'&'. + $now.'&'.$ENV{'REMOTE_ADDR'}); + my $token=Apache::lonnet::reply('tmpput:'.$infostr,$lonhost); + if ($token=~/^error\:/) { return ''; } + $token=~s/^(\d+)\_.*\_(\d+)$/$1\*$2\*$lonhost/; + $token=~tr/a-z/A-Z/; + + my %infohash=('token' => $token, + 'checktime' => $now, + 'remote' => $ENV{'REMOTE_ADDR'}); + + unless ( + &Apache::lonnet::cstore(\%infohash,$symb,$tcrsid,$tudom,$tuname) eq 'ok') { + return ''; + } + + if (&Apache::lonnet::log($tudom,$tuname, + &Apache::lonnet::homeserver($tuname,$tudom), + &Apache::lonnet::escape('Checkout '.$infostr.' - '. + $token)) ne 'ok') { + return ''; + } + + my %reply=&Apache::lonnet::get('environment', + ['firstname','middlename','lastname','generation'], + $tudom,$tuname); + my $plainname=$reply{'firstname'}.' '. + $reply{'middlename'}.' '. + $reply{'lastname'}.' '. + $reply{'generation'}; + + if ($target eq 'web') { + return + ''. + 'Checked out for '.$plainname. + '
User: '.$tuname.' at '.$tudom. + '
CourseID: '.$tcrsid.')'. + '
DocID: '.$token. + '
Time: '.localtime($now).'
'; + } else { + return $token; + } +} + sub fontsettings() { my $headerstring=''; if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) { @@ -295,8 +385,8 @@ sub htmlclean { my $output= $tree->as_HTML(undef,' '); - $output=~s/\<(br|hr|img)([^\>\/]*)\>/\<$1$2 \/\>/gis; - $output=~s/\<\/(br|hr|img)\>//gis; + $output=~s/\<(br|hr|img|meta|allow)([^\>\/]*)\>/\<$1$2 \/\>/gis; + $output=~s/\<\/(br|hr|img|meta|allow)\>//gis; unless ($full) { $output=~s/\<[\/]*(body|head|html)\>//gis; } @@ -747,6 +837,9 @@ sub parstring { sub writeallows { my $thisurl='/res/'.&Apache::lonnet::declutter(shift); + if ($ENV{'httpref.'.$thisurl}) { + $thisurl=$ENV{'httpref.'.$thisurl}; + } my $thisdir=$thisurl; $thisdir=~s/\/[^\/]+$//; my %httpref=();