Download attachment - while showing a new page

English! place to talk about development, programming and coding
Post Reply
sdombora
Znuny newbie
Posts: 16
Joined: 01 Jan 2012, 20:32
Znuny Version: 4.0.7
Real Name: Sándor Dombora
Company: Asyst Solutions

Download attachment - while showing a new page

Post by sdombora »

Hi!

I have written an import page for some data.
It works well, it does it's work but, when I display the result page, does not dowload the error file.
When it downloads the error file, then does not show the result page.

I attach the codes,

This shows the result page, but does not download the attachment:

Code: Select all

        my $Output = $Self->{LayoutObject}->Header();
        $Output .= $Self->{LayoutObject}->NavigationBar();

        # output import results
        $Output .= $Self->{LayoutObject}->Block(
            Name => 'ImportResult',
            Data => {
                FileName => $SourceFile{Filename} ||= '',
                Deleted =>  $Deleted,
                ReadToWrite => $ReadToWrite,
                WriteToRead => $WriteToRead,
                NewRead => $NewRead,
                NewWrite => $NewWrite,
                Error => $Error,
                NotModified => $NotModified,
                NotFound => $NotFound,
                LinesProcessed => $line,
                LinesSuccseeded => $linesSucceeded,

            },
        );
        $Output .= $Self->{LayoutObject}->Output( TemplateFile => 'AgentITSMConfigItemGroupImport', Data => \%Param );

        # If errors occured export them
        if ($linesSucceeded != $line ) {
                my $FileContent = "";
                my $ErrorMessage;
                while (($line, $ErrorMessage) = each(%Errors)){
                        $FileContent .=  $line+1 . ";" . $ErrorMessage . "\n";
                }

                $Self->{LayoutObject}->Attachment(
                        Type        => 'attachment',
                        Filename    => 'ErrorList.csv',
                        ContentType => 'text/csv',
                        Content     => $FileContent,
                        Charset     => 'utf-8',
                )
        }

        # start output
        $Output .= $Self->{LayoutObject}->Footer();

        return $Output;

This downloads the attachment, but does not show the result page:

Code: Select all

        my $Output = $Self->{LayoutObject}->Header();
        $Output .= $Self->{LayoutObject}->NavigationBar();

        # output import results
        $Output .= $Self->{LayoutObject}->Block(
            Name => 'ImportResult',
            Data => {
                FileName => $SourceFile{Filename} ||= '',
                LinesProcessed => $line,
                LinesSuccseeded => $linesSucceeded,
            },
        );
        $Output .= $Self->{LayoutObject}->Output( TemplateFile => 'AgentITSMConfigItemGroupImport', Data => \%Param );
        $Output .= $Self->{LayoutObject}->Footer();

        # If errors occured export them
        if ($linesSucceeded != $line ) {
                my $FileContent = "";
                my $ErrorMessage;
                while (($line, $ErrorMessage) = each(%Errors)){
                        $FileContent .=  $line+1 . ";" . $ErrorMessage . "\n";
                }

                return $Self->{LayoutObject}->Attachment(
                        Type        => 'attachment',
                        Filename    => 'ErrorList.csv',
                        ContentType => 'text/csv',
                        Content     => $FileContent,
                        Charset     => 'utf-8',
                )
        }


        return $Output;
bestr regards
S
OTRS 3.0, OTRS-ITSM, Suse Linux 11.3
Post Reply