version 1.1, 2003/05/16 20:55:11
|
version 1.6, 2003/05/27 20:05:46
|
Line 88 sub selectbox {
|
Line 88 sub selectbox {
|
return $selout.'</select>'; |
return $selout.'</select>'; |
} |
} |
|
|
|
sub file_dialogs { |
|
my ($spreadsheet) = @_; |
|
my $bgcolor = "#FFFFFF"; |
|
my $sheettype = $spreadsheet->{'type'}; |
|
my $result = ''; |
|
## |
|
## Deal with saving the spreadsheet |
|
if (exists($ENV{'form.save'}) && |
|
exists($ENV{'form.savefilename'})) { |
|
$spreadsheet->filename($ENV{'form.savefilename'}); |
|
my $save_status = $spreadsheet->save(); |
|
if ($save_status ne 'ok') { |
|
$result .= "An error occurred while saving the spreadsheet". |
|
"There error is:".$save_status; |
|
return $result; |
|
} else { |
|
$result .= "Spreadsheet saved as ".$ENV{'form.savefilename'}; |
|
} |
|
} elsif (exists($ENV{'form.newformula'}) && |
|
exists($ENV{'form.cell'}) && |
|
$ENV{'form.cell'} ne '' ) { |
|
## |
|
## Make any requested modifications to the spreadsheet |
|
$spreadsheet->modify_cell($ENV{'form.cell'}, |
|
$ENV{'form.newformula'}); |
|
$spreadsheet->save_tmp(); |
|
# output that we are dealing with a temporary file |
|
$result .=&hiddenfield('workcopy',$sheettype); |
|
$result .='<pre>'.$ENV{'form.cell'}.' = '. |
|
$ENV{'form.newformula'}."</pre>\n"; |
|
} |
|
## |
|
## Editing code |
|
$result .=&hiddenfield('cell',''). |
|
&hiddenfield('newformula',''); |
|
## |
|
## Create the save and load dialogs |
|
my $filename = $spreadsheet->filename(); |
|
$filename = '' if ($filename =~ /^default\.$sheettype/i); |
|
$filename =~ s/_$sheettype$//; |
|
my $save_dialog = '<nobr>'. |
|
'<input type="submit" name="save" value="Save as" /> '. |
|
'<input type="text" name="savefilename" size="30" value="'. |
|
$filename.'" />'. |
|
'</nobr>'; |
|
my $makedefault_dialog = '<input type="submit" name="makedefault" '. |
|
'value="Make This Sheet the Default"/>'; |
|
# |
|
my $link = '<a href="javascript:openbrowser'. |
|
"('sheet','loadfilename','spreadsheet')\">Browse</a>"; |
|
my $load_dialog = <<END; |
|
<table bgcolor="$bgcolor"> |
|
<tr><td><input type="submit" name="load" value="Load" /></td> |
|
<td><nobr> |
|
<input type="text" name="loadfilename" size="25" value="$filename" /> |
|
$link</nobr> |
|
</td></tr> |
|
<tr><td> </td><td> |
|
<select name="fileselect" onchange="document.sheet.loadfilename.value=document.sheet.fileselect.value" > |
|
<option name="Default">Default</option> |
|
END |
|
foreach my $sheetfilename ($spreadsheet->othersheets()) { |
|
$sheetfilename =~ s/_$sheettype$//; |
|
$load_dialog .= ' <option name="'.$sheetfilename.'"'; |
|
if ($filename eq $sheetfilename) { |
|
$load_dialog .= ' selected'; |
|
} |
|
$load_dialog .= '>'.$sheetfilename."</option>\n"; |
|
} |
|
$load_dialog .= "</td><td> </td></tr>\n</table>\n"; |
|
# |
|
$result .=<<END; |
|
<!-- load / save dialogs --> |
|
<table cellspacing="2"> |
|
<tr> |
|
<td>$load_dialog</td> |
|
<td> |
|
<table bgcolor="$bgcolor"> |
|
<tr><td>$save_dialog</td></tr> |
|
<tr><td align="center">$makedefault_dialog</td></tr> |
|
</table> |
|
</td> |
|
</tr> |
|
</table> |
|
END |
|
return $result; |
|
} |
|
|
sub handler { |
sub handler { |
my $r=shift; |
my $r=shift; |
# |
# |
Line 99 sub handler {
|
Line 187 sub handler {
|
# Check the course homeserver |
# Check the course homeserver |
$loaderror= &Apache::lonnet::overloaderror($r, |
$loaderror= &Apache::lonnet::overloaderror($r, |
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
$ENV{'course.'.$ENV{'request.course.id'}.'.home'}); |
if ($loaderror) { return $loaderror; } |
# if ($loaderror) { return $loaderror; } |
# |
# |
# HTML Header |
# HTML Header |
# |
# |
Line 149 sub handler {
|
Line 237 sub handler {
|
$r->header_out('Cache-control','no-cache'); |
$r->header_out('Cache-control','no-cache'); |
$r->header_out('Pragma','no-cache'); |
$r->header_out('Pragma','no-cache'); |
$r->send_http_header; |
$r->send_http_header; |
|
## |
|
## Check permissions |
|
my $allowed_to_edit = &Apache::lonnet::allowed('mgr', |
|
$ENV{'request.course.id'}); |
|
my $allowed_to_view = &Apache::lonnet::allowed('vgr', |
|
$ENV{'request.course.id'}); |
|
|
# |
# |
# Check user permissions - only those able to view others grades |
# Only those able to view others grades will be allowed to continue |
# will be allowed to continue if they are not requesting their own. |
# if they are not requesting their own. |
if (($sheettype eq 'classcalc') || |
if (($sheettype eq 'classcalc') || |
($name ne $ENV{'user.name'} ) || |
($name ne $ENV{'user.name'} ) || |
($domain ne $ENV{'user.domain'})) { |
($domain ne $ENV{'user.domain'})) { |
if (! &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) { |
if (! $allowed_to_view) { |
$r->print('<h1>Access Permission Denied</h1>'. |
$r->print('<h1>Access Permission Denied</h1>'. |
'</form></body></html>'); |
'</form></body></html>'); |
return OK; |
return OK; |
Line 169 sub handler {
|
Line 264 sub handler {
|
## |
## |
## Spit out the javascript required for editing |
## Spit out the javascript required for editing |
## |
## |
if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) { |
if ($allowed_to_edit) { |
|
my $extra_javascript = |
|
&Apache::loncommon::browser_and_searcher_javascript(); |
$r->print(<<ENDSCRIPT); |
$r->print(<<ENDSCRIPT); |
<script language="JavaScript"> |
<script language="JavaScript"> |
|
|
|
$extra_javascript |
|
|
var editwin; |
var editwin; |
|
|
function celledit(cellname,cellformula) { |
function celledit(cellname,cellformula) { |
Line 216 ENDSCRIPT
|
Line 315 ENDSCRIPT
|
&hiddenfield('usymb' ,$ENV{'form.usymb'})); |
&hiddenfield('usymb' ,$ENV{'form.usymb'})); |
$r->rflush(); |
$r->rflush(); |
## |
## |
## Check permissions |
|
my $editing_is_allowed = &Apache::lonnet::allowed('mgr', |
|
$ENV{'request.course.id'}); |
|
## |
|
## Determine the filename to use |
## Determine the filename to use |
my $filename = undef; |
my $filename = undef; |
if ($editing_is_allowed) { |
if ($allowed_to_edit) { |
$filename = $ENV{'form.filename'} if (exists($ENV{'form.filename'})); |
$filename = $ENV{'form.filename'} if (exists($ENV{'form.filename'})); |
# |
# |
if (exists($ENV{'form.load'}) && exists($ENV{'form.loadfilename'})) { |
if (exists($ENV{'form.load'}) && exists($ENV{'form.loadfilename'})) { |
Line 237 ENDSCRIPT
|
Line 332 ENDSCRIPT
|
$spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef); |
$spreadsheet = Apache::classcalc->new($name,$domain,$filename,undef); |
} elsif ($sheettype eq 'studentcalc') { |
} elsif ($sheettype eq 'studentcalc') { |
$spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef); |
$spreadsheet = Apache::studentcalc->new($name,$domain,$filename,undef); |
} elsif ($sheettype eq 'assesscalc' && defined($symb)) { |
} elsif ($sheettype eq 'assesscalc' && |
|
defined($symb) && |
|
$allowed_to_edit) { |
$spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb); |
$spreadsheet = Apache::assesscalc->new($name,$domain,$filename,$symb); |
} else { |
} else { |
&Apache::lonnet::logthis('Unable to determine spreadsheet type'); |
return HTTP_NOT_ACCEPTABLE; |
|
} |
|
if (! defined($spreadsheet)) { |
|
# error error - run in circles, scream and shout |
return; |
return; |
} |
} |
|
# |
|
# Output selector |
|
$r->print('<input type="submit" value="Update Display" /><br />'); |
## |
## |
## Editing/loading/saving |
## Editing/loading/saving |
if ($editing_is_allowed) { |
if ($allowed_to_edit) { |
## |
$r->print('<table><tr><td>'.$spreadsheet->html_header().'</td>'. |
## Deal with saving the spreadsheet |
'<td valign="bottom">'. |
if (exists($ENV{'form.save'}) && |
&file_dialogs($spreadsheet)."</td></tr></table>\n"); |
exists($ENV{'form.savefilename'})) { |
|
$spreadsheet->filename($ENV{'form.savefilename'}); |
|
my $save_status = $spreadsheet->save(); |
|
if ($save_status ne 'ok') { |
|
$r->print("An error occurred while saving the spreadsheet". |
|
"There error is:".$save_status); |
|
} else { |
|
$r->print("Spreadsheet saved as ".$ENV{'form.savefilename'}); |
|
} |
|
} elsif (exists($ENV{'form.newformula'}) && |
|
exists($ENV{'form.cell'}) && |
|
$ENV{'form.cell'} ne '' ) { |
|
## |
|
## Make any requested modifications to the spreadsheet |
|
$spreadsheet->modify_cell($ENV{'form.cell'}, |
|
$ENV{'form.newformula'}); |
|
$spreadsheet->save_tmp(); |
|
# output that we are dealing with a temporary file |
|
$r->print(&hiddenfield('workcopy',$sheettype)); |
|
$r->print('<pre>'.$ENV{'form.cell'}.' = '. |
|
$ENV{'form.newformula'}.'</pre>'."\n"); |
|
} |
|
## |
|
## Editing code |
|
$r->print(&hiddenfield('cell',''). |
|
&hiddenfield('newformula','')); |
|
## |
|
## Create the save and load dialogs |
|
$filename = $spreadsheet->filename(); |
|
$filename = '' if ($filename =~ /^default\.$sheettype/i); |
|
$filename =~ s/_$sheettype$//; |
|
my $save_dialog = |
|
'<input type="submit" name="save" value="Save as ..." /> '. |
|
'<input type="text" name="savefilename" size="30" value="'. |
|
$filename.'" />'; |
|
my $makedefault_dialog = |
|
'<input type="submit" name="makedefault" value="Make Default"/>'; |
|
# |
|
my $load_dialog = |
|
'<input type="submit" name="load" value="Load ..." />'. |
|
'<select name="loadfilename">'. |
|
'<option name="Default">Default</option>'."\n"; |
|
foreach my $sheetfilename ($spreadsheet->othersheets()) { |
|
$sheetfilename =~ s/_$sheettype$//; |
|
$load_dialog .= '<option name="'.$sheetfilename.'"'; |
|
if ($filename eq $sheetfilename) { |
|
$load_dialog .= ' selected'; |
|
} |
|
$load_dialog .= '>'.$sheetfilename."</option>\n"; |
|
} |
|
# |
|
$r->print(<<END); |
|
<!-- load / save dialogs --> |
|
<table cellspacing="3"> |
|
<tr> |
|
<td>$load_dialog</td> |
|
<td>$save_dialog</td> |
|
<td>$makedefault_dialog</td> |
|
</tr> |
|
</table> |
|
END |
|
$r->rflush(); |
$r->rflush(); |
|
} else { |
|
$r->print('<table><tr><td>'.$spreadsheet->html_header(). |
|
"</td></tr></table>\n"); |
} |
} |
# |
# |
# Keep track of the filename |
# Keep track of the filename |
$r->print(&hiddenfield('filename',$filename)); |
$r->print(&hiddenfield('filename',$filename)); |
# |
# |
$r->print($spreadsheet->get_title()); |
# Keep track of the number of times we have been called, sort of. |
$r->print($spreadsheet->parent_link()); |
$r->print(&hiddenfield('not_first_run','whatever')); |
if (defined($spreadsheet)) { |
# |
|
if (exists($ENV{'form.not_first_run'}) || $sheettype ne 'classcalc') { |
|
$r->print($spreadsheet->get_html_title()); |
|
if ($allowed_to_view || $allowed_to_edit) { |
|
$r->print($spreadsheet->parent_link()); |
|
} |
$spreadsheet->display($r); |
$spreadsheet->display($r); |
|
} else { |
|
$r->print("<h2>Make your selections and bonk the 'update display' button</h2>"); |
} |
} |
$r->print('</form></body></html>'); |
$r->print('</form></body></html>'); |
return OK; |
return OK; |