Bug 797

Summary: [Chameleon-Widget]Unable to save a context file with "sample_ogc.phtml" application
Product: Chameleon Reporter: Normand Savard <nsavard@mapgears.com>
Component: WidgetAssignee: Paul Spencer <pspencer@dmsolutions.ca>
Status: RESOLVED FIXED    
Severity: normal CC: chameleon-dev@lists.maptools.org
Priority: P2    
Version: 1.99   
Target Milestone: 1.99 beta 4   
Hardware: PC   
OS: Linux   
Whiteboard:

Description From 2004-10-29 11:03:55
Steps to reproduce:
1.  Load "sample_ogc.phtml
2.  Click on "Select a context"
3.  Select "gmap"
4.  Click on "Save Context" button
5.  A popup message appears, no other error appears (see below)

Fedora Core 2
Mozilla 1.6
Chameleon beta 3 20041022



-----------------
Popup message:
file id not set or empty
------- Comment #1 From 2004-10-29 11:39:17 -------
interesting.  Cariad reported a similar issue to me when I was fixing another
bug for her application.  The problem was intermittent for her, for some reason.
 I've tried this locally on windows with no problem, I can't reproduce.  The
code reads:

if ($szFileName == '')
{
    if (!isset( $http_form_vars["file_name"] ) ||
trim($http_form_vars["file_name"]) == "" )
    {
        echo "file id not set or empty";
        exit;
    }

$szFileName is set if SESSION['DOWNLOADFILE'] is set.  The DownloadContext
widget sets this session variable before loading the download.phtml file.  So
this error should not be occurring.  Norm, can you investigate this further by
dumping the contents of $_GET and $_SESSION where the error is triggered in
download.phtml (line 149) by adding:

print_r($_GET);
print_r($_SESSION);

and also adding an echo "here!"; on line 131 to see if the code is going into
that section.
------- Comment #2 From 2004-10-29 12:05:24 -------
No problem Paul.  I will do that as soon as I complete investigating another
issue.
------- Comment #3 From 2004-10-29 12:09:57 -------
Changed target to 1.99 RC 1.
------- Comment #4 From 2004-10-29 13:25:42 -------
Paul, I added the lines to output variable values.  I got no PHP output.  I only
see the message "here" I added in the popup.  Here is a snippet of the code I
modified.

----------------------
Code snippet:


   ....

$http_form_vars = (count($_POST) > 0) ?
$_POST : ((count($_GET) > 0) ? $_GET : array() );

$szFileName = '';
$szSaveAs = '';
$szURL = '';

if (isset($_GET['sid']))
{
    include_once( 'session.inc.php' );
    
    if (isset($_SESSION['DOWNLOADFILE']))
        $szFileName = $_SESSION['DOWNLOADFILE'];
    if (isset($_SESSION['DOWNLOADFILE_SAVEAS']))
        $szSaveAs = $_SESSION['DOWNLOADFILE_SAVEAS'];
    if (isset($_SESSION['DOWNLOAD_URL']))
        $szURL = $_SESSION['DOWNLOAD_URL'];
        
echo "here!";
     unset($_SESSION['DOWNLOADFILE']);
     unset($_SESSION['DOWNLOADFILE_SAVEAS']);
     unset($_SESSION['DOWNLOAD_URL']);
}

//make sure file_name is set.
if ($szFileName == '')
{
    if (!isset( $http_form_vars["file_name"] ) ||
trim($http_form_vars["file_name"]) == "" )
    {
        echo "file id not set or empty";
        exit;
    }
    else
        $szFileName = trim($http_form_vars["file_name"]);

    //download it
    $szSaveAs = ((isset($http_form_vars['save_as'])) ?
$http_form_vars['save_as'] : basename( $file_name ));

print_r($_GET);
print_r($_SESSION);


    //make sure file_name is valid

   ....
------- Comment #5 From 2004-10-29 13:35:59 -------
I have the same issue with SLD.

Steps to reproduce:

1.  Load "sample_ogc.phtml"
2.  Select "Tools" tab
3.  Open "world" context
4.  Click on "OpenSLD" button
5.  Type in the following URL for SLD:
http://www2.dmsolutions.ca/msapps/world_testdata/tests/sld_tests/sld_line_width.xml

6.  Click "Ok"
7.  Click the "SaveSLD" button
8.  Click the "Save SLD" button
9.  Same message "here!file id not set or empty"

Both functionalities go through the same code (logic)
------- Comment #6 From 2004-11-08 15:42:01 -------
I guess I'll need to fix this since I broke it ;)
------- Comment #7 From 2004-12-01 10:45:46 -------
fixed in cvs.  Turns out that you need to call session_write_close(); before
issuing a header() directive to redirect the page IF you have made changes in
the session.  This affected all widgets that download stuff.  download.phtml was
also made much more restrictive, it now enforces use of session variables to set
the download file rather than allowing it via the url.