PDA

View Full Version : TreePanel Mysql



julesmoulis
28 Jun 2010, 5:12 AM
Hi everyone,
I'm looking for a tutorial or an working example of a treepanel loading datas from a mysql database. I know I should work on API... But I really need something quickly to work on.
I found this example. But I'm having a hard time change the php file from his static state to a mysql connexion.

<?php
ini_set("display_errors", true);
ini_set("html_errors", true);


$node = "";
$out = "";

if (isset($_REQUEST["node"])) {
$node = $_REQUEST["node"];
}

switch ($node) {

case "project":
$out = GetProjectTree();
break;
case "datasources":
$out = GetDataSources();
break;


}
echo utf8_encode($out);


function GetProjectTree() {

$tree = "[{\"text\":\"Data Sources\",\"id\":\"datasources\",\"iconCls\":\"folder\",\"draggable\":false}]";

return $tree;
}

function GetDataSources() {

$datasrc = "[{\"text\":\"Time and Billing System\",\"id\":\"timeandbilling\",\"leaf\":true,\"iconCls\":\"datasource\"},";
$datasrc .= "{\"text\":\"Employee Management System\",\"id\":\"emplmanagement\",\"leaf\":true,\"iconCls\":\"datasource\"}]";

return $datasrc;
}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" >
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../ext3/css/ext-all.css" />

<style type="text/css">
.report
{
background:url(img/pie-chart.png) 0 no-repeat !important;
}
.dataset
{
background:url(img/table.png) 0 no-repeat !important;
}
.datasource
{
background:url(img/data.png) 0 no-repeat !important;
}
</style>

<script type="text/javascript" src="../ext3/ext-base.js"></script>

<script type="text/javascript" src="../ext3/ext-all-debug.js"></script>

<script type="text/javascript">


// TreePanel with draggable leaf nodes.

Ext.BLANK_IMAGE_URL = '../ext3/images/default/s.gif';

Ext.onReady(function() {

var tree = new Ext.tree.TreePanel({
el: 'tree-reorder',
frame:true,
width: 250,
height:400,
useArrows: true,
autoScroll: true,
animate: true,
enableDD: true,
containerScroll: true,
border: false,
dataUrl: 'tree-ajax-load.php',
root: {
nodeType: 'async',
text: 'My Reporting Project',
draggable: false,
id: 'project'
}
});

tree.render();
tree.getRootNode().expand(true);
});

</script>
</head>
<body style="padding: 20px">
<div id="tree-reorder"></div>
</body>
</html>


thanks