--- loncom/interface/lonsimplepage.pm 2006/07/20 03:11:52 1.45
+++ loncom/interface/lonsimplepage.pm 2008/12/17 09:44:04 1.62
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Simple Page Editor
#
-# $Id: lonsimplepage.pm,v 1.45 2006/07/20 03:11:52 raeburn Exp $
+# $Id: lonsimplepage.pm,v 1.62 2008/12/17 09:44:04 ehlerst Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,6 +31,7 @@ package Apache::lonsimplepage;
use strict;
use Apache::Constants qw(:common);
use Apache::loncommon;
+use Apache::lontemplate;
use Apache::lonnet;
use Apache::lontexconvert;
use Apache::lonfeedback;
@@ -38,8 +39,29 @@ use Apache::lonlocal;
use Apache::lonprintout;
use Apache::lonxml;
use Apache::longroup;
+use HTML::Entities();
use LONCAPA;
+sub get_db_name {
+ my ($url) = @_;
+ my ($udom,$uname,$marker)=(split(m{/},$url))[2,3,4];
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ my $db_name;
+
+ if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
+ $marker =~ s/\W//g;
+ $db_name = 'grppage_'.$marker;
+ } else {
+ $marker=~s/\D//g;
+ $db_name = 'smppage_'.$marker;
+ }
+ return if (!defined($marker));
+
+ return $db_name;
+}
+
sub handler {
my $r = shift;
&Apache::loncommon::content_type($r,'text/html');
@@ -50,7 +72,7 @@ sub handler {
if ($target eq 'tex') {
$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
}
- my (undef,undef,$udom,$uname,$marker)=split(/\//,$r->uri);
+
# Is this even in a course?
unless ($env{'request.course.id'}) {
if ($target ne 'tex') {
@@ -61,15 +83,17 @@ sub handler {
return OK;
}
+ my $db_name = &get_db_name($r->uri);
+
my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
- my ($namespace,$group,$group_desc,$group_home_view,$group_home_edit,
+ my ($group,$group_desc,$group_home_view,$group_home_edit,
$group_view_perm,$group_edit_perm);
my %curr_group = ();
my %groupinfo = ();
- if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
- $marker =~ s/\W//g;
- $group = $marker;
+ if ($db_name =~ /^grppage_/) {
+ $group = (split(m{/},$r->uri))[4];
+ $group =~ s/\W//g;
my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
if (!%curr_groups) {
&Apache::loncommon::simple_error_page($r,'','Invalid group name');
@@ -78,13 +102,9 @@ sub handler {
%groupinfo =
&Apache::longroup::get_group_settings($curr_groups{$group});
$group_desc = &unescape($groupinfo{'description'});
- $namespace = 'grppage_'.$group;
- } else {
- $marker=~s/\D//g;
- $namespace = 'smppage_'.$marker;
}
- if (!$marker) {
+ if (!$db_name) {
&Apache::loncommon::simple_error_page($r,'','Invalid call');
return OK;
}
@@ -114,7 +134,7 @@ sub handler {
$refarg = '&ref='.$env{'form.ref'};
}
- my %syllabus=&Apache::lonnet::dump($namespace,$dom,$crs);
+ my %syllabus=&Apache::lonnet::dump($db_name,$dom,$crs);
# --------------------------------------- There is such a user, get environment
@@ -149,8 +169,13 @@ sub handler {
$r->print(&grouppage_breadcrumbs($dom,$crs,$group,$group_desc));
}
if ((!$group_home_edit) && (!$group_home_view) &&
- (!$group_view_perm) && (!$group_edit_perm)) {
+ (!$group_view_perm) && (!$group_edit_perm)) {
&display_group_links($r,$target,$group,'view',$refarg,%groupinfo);
+ if ($env{'form.grade_target'} ne 'tex') {
+ $r->print(&Apache::loncommon::end_page());
+ } else {
+ $r->print('\end{document}');
+ }
return OK;
}
} else {
@@ -164,6 +189,13 @@ sub handler {
}
return OK;
}
+ my ($blocked,$blocktext) =
+ &Apache::loncommon::blocking_status('groups');
+ if ($blocked) {
+ $r->print($blocktext);
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
}
my $allowed;
@@ -182,11 +214,13 @@ sub handler {
}
if ($forcestudent or $target eq 'tex') { $allowed=0; }
-
+
if ($allowed) {
- $r->print('
'.
- &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').' '.&mt('Show Student View').''.
- &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'
');
+ $r->print('
'.' '
+ .''.&mt('Show Student View').''.
+ &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
+ &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes'))
+ .'
');
} elsif ($privileged and $target ne 'tex') {
my $edittext = &mt('Edit');
if ($group ne '') {
@@ -217,64 +251,84 @@ sub handler {
}
}
$syllabus{'uploaded.lastmodified'}=time;
- &Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
+ &Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
+ }
+ if ($allowed && $env{'form.delupl'}) {
+ if ($syllabus{'uploaded.photourl'}) {
+ &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
+ delete($syllabus{'uploaded.photourl'});
+ &Apache::lonnet::del('simplepage',['uploaded.photourl']);
+ }
}
if (($allowed) && ($env{'form.storesyl'})) {
- foreach (keys %syllabusfields) {
- my $field=$env{'form.'.$_};
+ foreach my $syl_field (keys(%syllabusfields)) {
+ my $field=$env{'form.'.$syl_field};
chomp($field);
$field=~s/\s+$//s;
$field=~s/^\s+//s;
$field=~s/\ $//s;
$field=&Apache::lonfeedback::clear_out_html($field,1);
- $syllabus{$_}=$field;
+ $syllabus{$syl_field}=$field;
}
$syllabus{'uploaded.lastmodified'}=time;
- &Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
+ &Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
}
# ---------------------------------------------------------------- Get syllabus
if ((($syllabus{'uploaded.lastmodified'}) &&
- (($group ne '' && ($group_home_view || $group_edit_perm ||
- $group_view_perm)) || ($group eq ''))) || ($allowed)) {
+ (($group ne '' && ($group_home_view || $group_edit_perm ||
+ $group_view_perm)) || ($group eq ''))) || ($allowed)) {
+ my $image;
if ($syllabus{'uploaded.photourl'}) {
&Apache::lonnet::allowuploaded('/adm/smppg',
$syllabus{'uploaded.photourl'});
- my $image='';
if ($target eq 'tex') {
$image=&Apache::lonxml::xmlparse($r,'tex',$image);
- }
- $r->print($image);
- }
+ }
+ }
if ($allowed) {
$r->print(
'');
}
- foreach (sort keys %syllabusfields) {
- if (($syllabus{$_}) || ($allowed)) {
- my $message=$syllabus{$_};
+ &Apache::lontemplate::start_columnSection($r);
+ if($allowed){
+ $r->print($image.'
';
+ &mt($menu{$tool}{text}).'';
}
}
$output .= '';
@@ -392,7 +449,7 @@ sub display_group_links {
if ($context eq 'edit') {
$output = &mt('No group functionality.');
} else {
- $output = &mt('No group functionality (e.g., e-mail, discussion, chat or file upload) is currently available to you in this group: [_1].',&unescape($groupinfo{'description'}));
+ $output = &mt('No group functionality (e.g., e-mail, discussion, chat or file upload) is currently available to you in this group: [_1].',''.&unescape($groupinfo{'description'}).'');
}
if ($target eq 'tex') {
$r->print(&Apache::lonxml::xmlparse($r,'tex',$output));