Create HTML5-Based Mobile-Friendly Interactive Images and Maps
FLDraw Interactive Floor Plan Software  >  Developer Guide  >  Implementing Server-side Script

Implementing Server-side Script

The server-side script passes information between the Flash object and your server (file system, database, ...).
It can be written in different languages, like PHP, ASP, .NET, JAVA, CFML, ... .

The Flash object sends an HTTP request (using the POST and GET methods) to the server when it needs to:
  • Read the list of files (List);
  • Create a new plan file (New);
  • Open a plan file (Read);
  • Save a plan file (Write).
The server receives the request, generates a response, and sends it back to the Flash object.

After you create the server-side files, modify the list_script, new_script, load_script and save_script nodes inside the configuration file, to point to your new files.
(You can put all of the server-side code inside a single file, and check the valRequest parameter to recognize the request type.)

The package includes a sample in PHP. See Package.

 
Testing Server-side Script

The package includes an HTML file (in the fldraw/samples/server_side/test folder) that you can use it to test your server-side code.
Save a copy of test.html in the same directory as the server-side script files,
then open your browser and enter the address of the test.html page, something like: http://localhost/.../test.html  or  http://YOUR WEBSITE/.../test.html .

To test your server-side code, do the following:
  1. Set the script file name.
  2. Set the required parameters and click the Submit button to send the data to the specified script file.
    The server response is displayed in the Response frame.
  3. Repeat step 2.

 

Request Types (List, New, Read, and Write)

List

The Flash object sends this request when a user opens the File dialog box, or double-clicks a folder name inside the File dialog box.

Parameters (Request Method: POST)

Name Description
valRequest Request type ("L").
valPlanPath The path of the folder to return the list of files (and subfolders) inside it.
valExtra1, valExtra2, valExtra3 Additional parameters (optional).
See Adding FLDraw to a Web Page and JavaScript Interaction.
 
Returns
  • List of Files and Folders,
    if successful.
  • Error Message,
    on failure. See Error Messages.

 

List of Files and Folders

Usage
<list path="path">
  <folder title="subfolder title 1 (optional)">subfolder 1</folder>
  <folder title="subfolder title 2 (optional)">subfolder 2</folder>
  ...
  <file title="file title 1 (optional)">file 1</file>
  <file title="file title 2 (optional)">file 2</file>
  ...
</list>
 
Example
When the server returns this code:
<list path="">
  <folder>folder1</folder>
  <file>file1</file>
  <file>file2</file>
</list>

 
The Flash object shows this dialog box: File Dialog Box
 
Example
Assume that you are using a database for storing plans, something like this:
 
year user plan_name plan_source
2009 Mike plan1 <plan>
...
</plan>
2010 Mike plan2 <plan>
...
</plan>
2008 Kimberly plan1 <plan>
...
</plan>

When Mike opens the File dialog box, the Flash object sends a List request, and the server should return something like this code:

<list path="">
  <file>plan1</file>
  <file>plan2</file>
</list>

 

path Attribute and folder Tag

If you want to organize the data in a manner to make selection easy, you can use the path attribute and the folder tag.

Example
Assume that you are using the filesystem for storing plans, and you have a directory like this:
  • users
    • Mike
      • folder1
        • file1.fdw
        • file2.fdw
      • folder2
    • Kimberly
      • folder1
        • file1.fdw
When Mike opens the File dialog box, the Flash object sends a List request, and the server should return something like this code:
<list path="">
  <folder>folder1</folder>
  <folder>folder2</folder>
</list>
 
Then, if he double-clicks the folder1 item, the server should return something like this code:
<list path="folder1">
  <folder>..</folder>
  <file>file1.fdw</file>
  <file>file2.fdw</file>
</list>
 
 
Example
Assume that you have a database like this:
 
year user plan_name plan_source
2009 Mike plan1 <plan>
...
</plan>
2010 Mike plan2 <plan>
...
</plan>
2008 Kimberly plan1 <plan>
...
</plan>
And you want to organize the data according to year.
 
When Mike opens the File dialog box, the Flash object sends a List request, and the server should return something like this code:
<list path="">
  <folder>2009</folder>
  <folder>2010</folder>
</list>
(Using a SQL query like this: " SELECT year FROM plans WHERE user='Mike' GROUP BY year ")

 
Then, if he double-clicks the 2009 item, the server should return something like this code:
<list path="2009">
  <folder>..</folder>
  <file>plan1</file>
</list>
(Using a SQL query like this: " SELECT plan_name FROM plans WHERE user='Mike' AND year=2009 ")
 

 

title Attribute

By default, the Flash object displays the value of the file and folder tags inside the File dialog box,
you can use the title attribute to show something else.

Example
<list path="">
  <folder title="all files">folder1</folder>
  <file title="first floor">p1.fdw</file>
</list>

 

 

New

The Flash object sends this request when a user wants to create a new plan.

Parameters (Request Method: POST)

Name Description
valRequest Request type ("N").
valExtra1, valExtra2, valExtra3 Additional parameters (optional).
See Adding FLDraw to a Web Page and JavaScript Interaction.
 
Returns
  • File Name and Path,
    if the user is allowed to create a new plan file.
  • Error Message,
    otherwise. See Error Messages.

 

File Name and Path

Usage
  • <new>path;name</new>
  • <suggest>path;name</suggest>
 
Use the new tag if you want to specify a file name and path for the new plan file,
and use the suggest tag if you want to set the initial values for the path and name parameters inside the Save As dialog box.
 
 
Example
<new>../plans;plan1</new>
 

 

 

Read

The Flash object sends this request when a user wants to open an existing plan.

Parameters (Request Method: POST)

Name Description
valRequest Request type ("R").
valPlanPath The path of the plan to read.
valPlanName The name of the plan to read.
valExtra1, valExtra2, valExtra3 Additional parameters (optional).
See Adding FLDraw to a Web Page and JavaScript Interaction.
 
Returns
  • The Plan File (Binary),
    if successful.
  • Error Message,
    on failure. See Error Messages.

 

 

Write

The Flash object sends this request when a user wants to save a plan.

Parameters (Request Method: POST if compress_files=false, GET if compress_files=true)

Name Description
valRequest Request type ("W").
valPlanPath The path of the plan to save.
valPlanName The name of the plan to save.
valPlanSource Value:
if compress_files=false: The source code of the plan file.
if compress_files=true: It's empty and you can use the raw POST data ("php://input" in PHP).
valSaveAs Determines whether it's a Save or Save As request.
Values:
"true": It's a Save As request.
"false": It's a Save request.
valReplace Information about the server-side overwrite checking feature.
Values:
"true": There is a plan with the same name, and the user wants to replace it.
"false": Otherwise.
valExtra1, valExtra2, valExtra3 Additional parameters (optional).
See Adding FLDraw to a Web Page and JavaScript Interaction.
 
Returns
  • Result Message,
    if successful.
  • Yes-or-No Question,
    if the server needs the user to make a decision.
  • Error Message,
    on failure. See Error Messages.

 

Result Message

After saving, return a Result Message response.

Usage
  • <result>message</result>
  • <result2>title;message</result2>
 
Tip
If you don't like to show a message after a successful save operation, you can return <result></result> (no message text).
 
Example
When the server returns this code: <result>Message...</result>
 
The Flash object shows this dialog box: Message Window
 
Example
When the server returns this code: <result2>Title...;Description...\n...</result2>
 
The Flash object shows this dialog box: Message Window

 

Yes-or-No Question

You can use it when there is another plan with the same name, and you need the user to make a decision about replacing it or not.

Usage
<question>question</question>
 
Example
When the server returns this code: <question>File already exists.\nDo you want to replace it?</question>
 
The Flash object shows this dialog box: Message Window

 

Tip
When you have a Write request, do the following:
If it's a Save As request, and a file with the same name exists, then,
if the valReplace parameter is "false", then send a Yes_or_No Question response,
and if it's "true", then replace the existing plan with the new one.
 
Example
  1. The user selects a plan name that already exists (in Save dialog box).
  2. The server receives a Write request (valSaveAs="true", valReplace="false"),
    then checks to see if a file with the same name exists, and the result is yes,
    so returns a Yes-or-No Question response (because valReplace="false").
  3. The Flash object shows a Yes-or-No dialog box, and the user clicks the Yes button in the dialog box.
  4. The server receives a Write request (valSaveAs="true", valReplace="true"),
    then checks to see if a file with the same name exists, and the result is yes,
    then replaces the existing plan with the new one (because valReplace="true").

 

 


Error Messages

When the server fails to do the requested operation, it's necessary to return an Error Message response.

 
Usage
  • <error>description</error>
  • <error2>title;description</error2>
 
Example
When the server returns this code: <error>Error...</error>
 
The Flash object shows this dialog box: Message Window
 
Example
When the server returns this code: <error2>Title...;Description...\n...</error2>
 
The Flash object shows this dialog box: Message Window