version 1.491, 2011/07/21 09:18:40
|
version 1.493, 2011/07/26 17:14:51
|
Line 170 sub file_delchk_js {
|
Line 170 sub file_delchk_js {
|
return <<"ENDSCRIPT"; |
return <<"ENDSCRIPT"; |
<script type="text/javascript"> |
<script type="text/javascript"> |
// <![CDATA[ |
// <![CDATA[ |
function file_deletion_check(formname) { |
function file_deletion_check(formname,uploadid) { |
var elemnum = formname.elements.length; |
var elemnum = formname.elements.length; |
if (elemnum == 0) { |
if (elemnum == 0) { |
return true; |
return true; |
} |
} |
var str = new RegExp("^HWFILE.+_delete\$"); |
var alluploads = new Array(); |
var delboxes = new Array(); |
if ((uploadid != '') && (uploadid != undefined)) { |
|
alluploads.push(uploadid); |
|
} else { |
|
var uploadstr = /^HWFILE.+\$/; |
|
for (var i=0; i<formname.elements.length; i++) { |
|
var id = formname.elements[i].id; |
|
if (id != '') { |
|
if (uploadstr.test(id)) { |
|
if (formname.elements[i].type == 'file') { |
|
alluploads.push(id); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
for (var i=0; i<alluploads.length; i++) { |
|
var delstr = new RegExp('^'+alluploads[i]+'_\\\\d+_delete\$'); |
|
var delboxes = new Array(); |
|
for (var j=0; j<formname.elements.length; j++) { |
|
var id = formname.elements[j].id; |
|
if (id != '') { |
|
if (delstr.test(id)) { |
|
if (formname.elements[j].type == 'checkbox') { |
|
if (formname.elements[j].checked) { |
|
delboxes.push(id); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
if (delboxes.length > 0) { |
|
if (!confirm("$delfilewarn")) { |
|
for (var j=0; j<delboxes.length; j++) { |
|
formname.elements[delboxes[j]].checked = false; |
|
} |
|
return false; |
|
} |
|
} |
|
} |
|
return true; |
|
} |
|
// ]]> |
|
</script> |
|
ENDSCRIPT |
|
} |
|
|
|
sub file_overwritechk_js { |
|
my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item').'\\n'. |
|
&mt('Continue submission and overwrite the file(s)?'); |
|
return <<"ENDSCRIPT"; |
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
function file_overwrite_check(formname,path,multiresp) { |
|
var elemnum = formname.elements.length; |
|
if (elemnum == 0) { |
|
return true; |
|
} |
|
var alluploads = new Array(); |
|
var uploaded = new Array(); |
|
var uploadstr = /^HWFILE.+\$/; |
|
var fnametrim = /[^\\/\\\\]+\$/; |
for (var i=0; i<formname.elements.length; i++) { |
for (var i=0; i<formname.elements.length; i++) { |
var id = formname.elements[i].id; |
var id = formname.elements[i].id; |
if (id != '') { |
if (id != '') { |
if (str.test(id)) { |
if (uploadstr.test(id)) { |
if (formname.elements[i].type == 'checkbox') { |
if (formname.elements[i].type == 'file') { |
if (formname.elements[i].checked) { |
alluploads.push(id); |
delboxes.push(id); |
if ((formname.elements[i].value != undefined) && |
|
(formname.elements[i].value != '')) { |
|
uploaded.push(id); |
} |
} |
} |
} |
} |
} |
} |
} |
} |
} |
if (delboxes.length > 0) { |
for (var i=0; i<alluploads.length; i++) { |
if (confirm("$delfilewarn")) { |
var delstr = new RegExp("^"+alluploads[i]+"_\\\\d+_delete\$"); |
return true; |
var delboxes = new Array(); |
} else { |
for (var j=0; j<formname.elements.length; j++) { |
for (var j=0; j<delboxes.length; j++) { |
var id = formname.elements[j].id; |
formname.elements[delboxes[j]].checked = false; |
if (id != '') { |
|
if (delstr.test(id)) { |
|
if (formname.elements[j].type == 'checkbox') { |
|
delboxes.push(id); |
|
} |
|
} |
|
} |
|
} |
|
var overwrites = new Array(); |
|
if (delboxes.length > 0) { |
|
if ((formname.elements[alluploads[i]].value != undefined) && |
|
(formname.elements[alluploads[i]].value != '')) { |
|
var filepath = formname.elements[alluploads[i]].value; |
|
var newfilename = fnametrim.exec(filepath); |
|
if (newfilename != null) { |
|
var filename = String(newfilename); |
|
var nospaces = filename.replace(/\\s+/g,'_'); |
|
var nospecials = nospaces.replace(/[^\\/\\w\\.\\-]/g,''); |
|
var cleanfilename = nospecials.replace(/\\.(\\d+\\.)/g,"_\$1"); |
|
if (cleanfilename != '') { |
|
var fullpath = path+"/"+cleanfilename; |
|
if (multiresp == 1) { |
|
var partid = String(alluploads[i]); |
|
var subdir = partid.replace(/^HWFILE/,''); |
|
if (subdir != "" && subdir != undefined) { |
|
fullpath = path+"/"+subdir+"/"+cleanfilename; |
|
} |
|
} |
|
for (var k=0; k<delboxes.length; k++) { |
|
if (fullpath == formname.elements[delboxes[k]].value) { |
|
var id = formname.elements[delboxes[k]].id; |
|
if (id != '') { |
|
if (!formname.elements[delboxes[k]].checked) { |
|
overwrites.push(id); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
if (overwrites.length > 0) { |
|
if (confirm("$overwritewarn")) { |
|
var delcheck = file_deletion_check(formname,alluploads[i]); |
|
if (delcheck == false) { |
|
return false; |
|
} |
|
} else { |
|
for (var n=0; n<overwrites.length; n++) { |
|
formname.elements[overwrites[n]].value = ""; |
|
} |
|
return false; |
|
} |
|
} else { |
|
var delcheck = file_deletion_check(formname); |
|
if (delcheck == false) { |
|
return false; |
|
} |
} |
} |
return false; |
|
} |
} |
} else { |
|
return true; |
|
} |
} |
|
return true; |
} |
} |
// ]]> |
// ]]> |
</script> |
</script> |
Line 232 sub page_start {
|
Line 349 sub page_start {
|
$extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); |
$extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); |
} |
} |
my $is_task = ($env{'request.uri'} =~ /\.task$/); |
my $is_task = ($env{'request.uri'} =~ /\.task$/); |
|
my $needs_upload; |
if ($is_task) { |
if ($is_task) { |
$extra_head .= &file_delchk_js(); |
$extra_head .= &file_delchk_js(); |
|
} else { |
|
if (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.uploadedfiletypes") ne '') { |
|
$needs_upload = 1; |
|
} else { |
|
unless ($env{'request.state'} eq 'construct') { |
|
my ($symb)= &Apache::lonnet::whichuser(); |
|
my $navmap = Apache::lonnavmaps::navmap->new(); |
|
if (ref($navmap)) { |
|
my $res = $navmap->getBySymb($symb); |
|
if (ref($res)) { |
|
my $partlist = $res->parts(); |
|
if (ref($partlist) eq 'ARRAY') { |
|
foreach my $part (@{$partlist}) { |
|
my @types = $res->responseType($part); |
|
my @ids = $res->responseIds($part); |
|
for (my $i=0; $i < scalar(@ids); $i++) { |
|
if ($types[$i] eq 'essay') { |
|
my $partid = $part.'_'.$ids[$i]; |
|
if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') { |
|
$needs_upload = 1; |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
if ($needs_upload) { |
|
$extra_head .= &file_overwritechk_js()."\n". |
|
&file_delchk_js(); |
} |
} |
|
|
my %body_args; |
my %body_args; |
Line 316 sub page_start {
|
Line 468 sub page_start {
|
if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') { |
if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') { |
$page_start .= &Apache::lonxml::message_location(); |
$page_start .= &Apache::lonxml::message_location(); |
} |
} |
|
|
my $form_tag_start; |
my $form_tag_start; |
if (!defined($found{'form'})) { |
if (!defined($found{'form'})) { |
$form_tag_start='<form name="lonhomework" enctype="multipart/form-data" method="post" action="'; |
$form_tag_start='<form name="lonhomework" enctype="multipart/form-data" method="post" action="'; |
Line 327 sub page_start {
|
Line 478 sub page_start {
|
if ($target eq 'edit') { |
if ($target eq 'edit') { |
$form_tag_start.=&Apache::edit::form_change_detection(); |
$form_tag_start.=&Apache::edit::form_change_detection(); |
} |
} |
|
my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser(); |
|
my ($path,$multiresp) = |
|
&Apache::loncommon::get_turnedin_filepath($symb,$uname,$udom); |
if ($is_task) { |
if ($is_task) { |
$form_tag_start .= ' onsubmit="return file_deletion_check(this);"'; |
$form_tag_start .= ' onsubmit="return file_deletion_check(this);"'; |
|
} elsif ($needs_upload) { |
|
$form_tag_start .= ' onsubmit="return file_overwrite_check(this,'."'$path','$multiresp'".');"'; |
} |
} |
$form_tag_start.='>'."\n"; |
$form_tag_start.='>'."\n"; |
|
|
Line 1290 sub end_problem {
|
Line 1446 sub end_problem {
|
} else { |
} else { |
$frontmatter.= $begin_doc.$toc_line; |
$frontmatter.= $begin_doc.$toc_line; |
if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { |
if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { |
$frontmatter .= '\fbox{\textit{'.$weight.&mt(' pt').'}}'; |
$frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}'; |
} |
} |
} |
} |
} else { |
} else { |
Line 1300 sub end_problem {
|
Line 1456 sub end_problem {
|
if (not $env{'request.symb'} =~ m/\.page_/) { |
if (not $env{'request.symb'} =~ m/\.page_/) { |
$frontmatter .= $begin_doc.$toc_line; |
$frontmatter .= $begin_doc.$toc_line; |
if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { |
if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { |
$frontmatter .= '\fbox{\textit{'.$weight.&mt(' pt').'}}'; |
$frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}'; |
} |
} |
} else { |
} else { |
$frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage; |
$frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage; |
Line 1991 sub start_part {
|
Line 2147 sub start_part {
|
$allow_print_points=0; |
$allow_print_points=0; |
} |
} |
if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { |
if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { |
$result .= '\vskip |
$result .= '\vskip 10mm\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}'; |
10mm\fbox{\textit{'.$weight.&mt(' pt').'}}'; |
|
|
|
} |
} |
} elsif ($target eq 'web') { |
} elsif ($target eq 'web') { |