Adding Flex 3.0 swf to Joomla 1.6

Adding Flex 3.0 using MySQL to Joomla 1.6

I redesigned a web application to take advantage of Joomla 1.6. One of the key features of the old web site was its use of interactive charts that were created in Adobe Flex 3.0. These charts used their own MySQL DB to query data that they would display.

Name Description
joom16 Joomla 1.6 Database
shread legacy database containing chart data

This is how I included them into Joomla.

Create the environment

alt

Within Joomla root directory, I created a new directory to hold my custom code and I named it ./user. In here is where all my custom non-joomla code exists for the website. For this tutorial we will be focusing on the ./shread directory. I don't know if creating a directory of my own is what Joomla recommends, I suspect it isn't. But I was unable to find a Joomla approved answer to this question so I just created my own.

I copied my Flex .swf files to the ./shread directory. The Action Script code for each of these files makes a call to the ./scripts/ directory where .php files are located that contain code that does the following.

  1. Connects to the shread database
  2. Makes a SQL query to get the data
  3. Passes the result back to the .swf via HTTPService

How this is done in ActionScript is beyond the scope of this tutorial.

I ran into some problems connecting to the database. Because my code is outside of Joomla, I was altunable to use the recommended Joomla calls to JFactory. So, I had to use regular php mysqli_connect statements. I used to mysqli_connect statements, one connected to shread, and the other connected to joom16.

These steps were placed in the file named connect_to_mysql.php.

Another file named checkuserlingin.php contained code to determine the joomla user.

Find logged in user info from outside of Joomla 1.6

<?php
session_start();

//makes connection to databases
include_once "connect_to_mysql.php";       
if (isset($_SESSION['id'])) {
    $id = $_SESSION['id'];   //I save the id in a session variable   
    saveUserData($id);
// activeProfile is the name of the cookie used by Joomla/Jomsocial
} elseif (isset($_COOKIE['activeProfile'])) { 
    $id = $_COOKIE['activeProfile'];
    saveUserData($id);
} else {
    $return_msg = "not_logged_in";
}
 
function saveUserData($id) {
// this is where I save the id in a session variable
    $_SESSION['id'] = $id;   
  
    $myConnJ = mysqli_connect("localhost","username","passwd","joom16") or die ("could not connect to shooterr_joomla");
//query login info from Joomla
    $sql = "SELECT * FROM jos_users WHERE id='".$id."'"; 
    $result = mysqli_query($myConnJ, $sql) or die('ERROR: jos_user query failed for id = $id ');
    $row = mysqli_fetch_array($result);

// user data I need for charts is saved in session vars
    $username = $row['username'];             session_register('username');
    $_SESSION['username'] = $username;
    
    $email = $row['email'];
    session_register('email');
    $_SESSION['email'] = $email;
 
  //I save have a custom field in Jomsocial that I also need   
    $sql = "SELECT * FROM jos_community_fields_values WHERE user_id='".$id."' AND field_id='16'";
    $result = mysqli_query($myConnJ, $sql) or die('ERROR: jos_community_fields_values failed for id = $id ');
    $row = mysqli_fetch_array($result);
    
    $primary_club = $row['value'];
    session_register('primary_club');
    $_SESSION['primary_club'] = $primary_club;

}
?>

I have Jomsocial 2.2 also installed on this website. I did some testing and found that a common cookie named "activeProfile" contains the user_id of the jos_sessions table.

Executing the Flex swf file from inside Joomla 1.6

I created a Joomla Menu Item with type = Iframe Wrapper. In the URL I used my website root with the path to the .swf that matches the directory tree:

 http:www.mydomain.com/user/shread/shooterStageScores.swf

Powered by Bullraider.com

Social Icons