version 1.40, 2001/04/16 23:16:31
|
version 1.44, 2001/05/21 19:45:28
|
Line 15 use Apache::hint;
|
Line 15 use Apache::hint;
|
use Apache::outputtags; |
use Apache::outputtags; |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
|
|
|
|
|
sub BEGIN { |
|
&Apache::lonxml::register_insert(); |
|
} |
|
|
sub get_target { |
sub get_target { |
if ( $ENV{'request.state'} eq "published") { |
if ( $ENV{'request.state'} eq "published") { |
if ( defined $ENV{'form.submitted'}) { |
if ( defined $ENV{'form.submitted'}) { |
Line 30 sub get_target {
|
Line 35 sub get_target {
|
return ('web'); |
return ('web'); |
} |
} |
} else { |
} else { |
return ('grade','web'); |
if ( $ENV{'form.problemmode'} eq 'View' ) { |
if ( $ENV{'form.submitted'} eq 'edit' ) { |
if ( defined $ENV{'form.submitted'}) { |
return ('modified','edit'); |
return ('grade', 'web'); |
|
} else { |
|
return ('web'); |
|
} |
|
} elsif ( $ENV{'form.problemmode'} eq 'Edit' ) { |
|
if ( $ENV{'form.submitted'} eq 'edit' ) { |
|
return ('modified','edit'); |
|
} else { |
|
return ('edit'); |
|
} |
} else { |
} else { |
return ('edit'); |
return ('web'); |
} |
} |
} |
} |
} |
} |
Line 50 sub setup_vars {
|
Line 64 sub setup_vars {
|
sub send_header { |
sub send_header { |
my ($request)= @_; |
my ($request)= @_; |
$request->print(&Apache::lontexconvert::header()); |
$request->print(&Apache::lontexconvert::header()); |
$ENV{'request.uri'}=$request->uri; |
|
# $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">'); |
# $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">'); |
} |
} |
|
|
Line 131 sub check_date {
|
Line 144 sub check_date {
|
return ($status,$datemsg); |
return ($status,$datemsg); |
} |
} |
|
|
sub handler { |
sub showhash { |
my $request=$_[0]; |
my (%hash) = @_; |
|
my $resultkey; |
if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} |
foreach $resultkey (sort keys %hash) { |
|
&Apache::lonxml::debug("$resultkey ---- $hash{$resultkey}"); |
my (@targets) = &get_target(); |
} |
|
&Apache::lonxml::debug("\n<br />restored values^</br>\n"); |
|
return ''; |
|
} |
|
|
|
sub setuppermissions { |
|
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
|
$Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); |
|
return '' |
|
} |
|
|
|
sub setupheader { |
|
my $request=$_[0]; |
if ($ENV{'browser.mathml'}) { |
if ($ENV{'browser.mathml'}) { |
$request->content_type('text/xml'); |
$request->content_type('text/xml'); |
} else { |
} else { |
Line 145 sub handler {
|
Line 169 sub handler {
|
} |
} |
$request->send_http_header; |
$request->send_http_header; |
return OK if $request->header_only; |
return OK if $request->header_only; |
|
return '' |
|
} |
|
|
#setup permissions |
sub renderpage { |
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
my ($request,$file) = @_; |
$Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); |
|
|
|
#check if we know where we are |
|
if ($ENV{'request.course.fn'} && !&Apache::lonnet::symbread()) { |
|
# if we are browsing we might not be able to know where we are |
|
if ($Apache::lonhomework::browse ne 'F') { |
|
#should know where we are, so ask |
|
$request->internal_redirect('/adm/ambiguous'); return; |
|
} |
|
} |
|
|
|
&Apache::lonhomework::send_header($request); |
my (@targets) = &get_target(); |
&Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:"); |
|
|
|
foreach my $target (@targets) { |
foreach my $target (@targets) { |
my $file=&Apache::lonnet::filelocation("",$request->uri); |
|
my $problem=&Apache::lonnet::getfile($file); |
my $problem=&Apache::lonnet::getfile($file); |
if ($problem == -1) { |
if ($problem == -1) { |
&Apache::lonxml::error("<b> Unable to find <i>$file</i></b>"); |
&Apache::lonxml::error("<b> Unable to find <i>$file</i></b>"); |
$problem=''; |
$problem=''; |
} |
} |
|
|
my %mystyle; |
my %mystyle; |
my $result = ''; |
my $result = ''; |
&Apache::inputtags::initialize_inputtags; |
&Apache::inputtags::initialize_inputtags; |
Line 188 sub handler {
|
Line 201 sub handler {
|
} |
} |
if ($Apache::lonhomework::viewgrades eq 'F') {&createmenu('grade',$request); } |
if ($Apache::lonhomework::viewgrades eq 'F') {&createmenu('grade',$request); } |
} |
} |
if ($target eq 'grade') { |
if ($target eq 'grade') { &showhash(%Apache::lonhomework::history); } |
my $resultkey; |
|
foreach $resultkey (sort keys %Apache::lonhomework::history) { |
|
&Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::history{$resultkey}"); |
|
} |
|
&Apache::lonxml::debug("\n<br />restored values^</br>\n"); |
|
} |
|
my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm'); |
my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm'); |
if ($default == -1) { |
if ($default == -1) { |
&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>"); |
&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>"); |
Line 219 sub handler {
|
Line 227 sub handler {
|
$request->print($result); |
$request->print($result); |
} |
} |
#$request->print(":Result ends"); |
#$request->print(":Result ends"); |
if ($target eq 'grade') { |
if ($target eq 'grade') { &showhash(%Apache::lonhomework::results); } |
|
|
my $resultkey; |
#store new values |
foreach $resultkey (sort keys %Apache::lonhomework::results) { |
|
&Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::results{$resultkey}"); |
|
} |
|
&Apache::lonxml::debug("\n<br />storing values^</br>\n"); |
|
} |
|
|
|
my ($temp) = keys %Apache::lonhomework::results; |
my ($temp) = keys %Apache::lonhomework::results; |
if ( $temp ne '' ) { |
if ( $temp ne '' ) { |
&Apache::lonxml::debug("Store return message:".&Apache::lonnet::cstore(\%Apache::lonhomework::results)); |
&Apache::lonxml::debug("Store return message:". |
|
&Apache::lonnet::cstore(\%Apache::lonhomework::results)); |
|
} |
|
} |
|
} |
|
|
|
# with no arg it returns a HTML <option> list of the template titles |
|
# with one arg it returns the filename associated with the arg passed |
|
sub get_template_list { |
|
my ($namewanted) = @_; |
|
my $result; |
|
foreach my $file (</home/httpd/html/res/adm/includes/templates/*.problem>) { |
|
my $name=&Apache::lonnet::metadata($file,'title'); |
|
if ($namewanted && ($name eq $namewanted)) { |
|
$result=$file; |
|
last; |
|
} else { |
|
$result.="<option>$name</option>"; |
} |
} |
} |
} |
|
return $result; |
|
} |
|
|
|
sub newproblem { |
|
my ($request) = @_; |
|
|
|
if ($ENV{'form.template'}) { |
|
use File::Copy; |
|
my $file = &get_template_list($ENV{'form.template'}); |
|
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
|
copy($file,$dest); |
|
&renderpage($request,$file); |
|
} else { |
|
my $templatelist=&get_template_list(); |
|
my $url=$request->uri; |
|
$request->print(<<ENDNEWPROBLEM); |
|
<body bgcolor="#FFFFFF"> |
|
The request file $url doesn\'t exist. You can create a new problem <br /> |
|
<form action="$url" method="POST"> |
|
<input type="submit" value="New Problem"><br /> |
|
<select name="template"> |
|
$templatelist |
|
</select> |
|
</form> |
|
</body> |
|
ENDNEWPROBLEM |
|
} |
|
|
|
return ''; |
|
} |
|
|
|
sub view_or_edit_menu { |
|
my ($request) = @_; |
|
my $url=$request->uri; |
|
$request->print(<<EDITMENU); |
|
<body bgcolor="#FFFFFF"> |
|
<form action="$url" method="POST"> |
|
Would you like to <input type="submit" name="problemmode" value="View"> or |
|
<input type="submit" name="problemmode" value="Edit"> the problem. |
|
</form> |
|
</body> |
|
EDITMENU |
|
} |
|
|
|
sub handler { |
|
my $request=$_[0]; |
|
|
|
# if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} |
|
|
|
if (&setupheader($request)) { return OK; } |
|
$ENV{'request.uri'}=$request->uri; |
|
|
|
#setup permissions |
|
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
|
$Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); |
|
&Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:"); |
|
|
|
my $file=&Apache::lonnet::filelocation("",$request->uri); |
|
|
|
#check if we know where we are |
|
if ($ENV{'request.course.fn'} && !&Apache::lonnet::symbread()) { |
|
# if we are browsing we might not be able to know where we are |
|
if ($Apache::lonhomework::browse ne 'F') { |
|
#should know where we are, so ask |
|
$request->internal_redirect('/adm/ambiguous'); return; |
|
} |
|
} |
|
|
|
if ($ENV{'request.state'} eq "construct") { |
|
if ( -e $file ) { |
|
if (!(defined $ENV{'form.problemmode'})) { |
|
#first visit to problem in construction space |
|
&view_or_edit_menu($request); |
|
#&renderpage($request,$file); |
|
} else { |
|
&renderpage($request,$file); |
|
} |
|
} else { |
|
# requested file doesn't exist in contruction space |
|
&newproblem($request); |
|
} |
|
} else { |
|
# just render the page normally outside of construction space |
|
&renderpage($request,$file); |
|
} |
|
|
&Apache::lonhomework::send_footer($request); |
&Apache::lonhomework::send_footer($request); |
# always turn of debug messages |
# always turn off debug messages |
$Apache::lonxml::debug=0; |
$Apache::lonxml::debug=0; |
return OK; |
return OK; |
|
|