CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 PHP Treeview

Print topic Send  topic

Author Message
dekalaked
Posted: 01/31/2005, 5:46 PM

Does anyone have an example of a CCS Treeview written in PHP?
Nicole

Posts: 586
Posted: 02/01/2005, 12:41 AM

Hello,
Have you tried CCS Directory component? A corresponding builder creates a tree form automatically if source table(s) contains the following fields
Category ID, Name, Parent category ID.

_________________
Regards,
Nicole
View profile  Send private message
isoftware_com

Posts: 13
Posted: 02/01/2005, 4:00 PM

I am looking for a proper treeview not a directory as well.

If there is enough demand in the community I may build one anyway.

Evan
_________________
isoftware.com
Looking for Codecharge VB.NET Freelance Developers
View profile  Send private message
lvalverdeb

Posts: 299
Posted: 02/02/2005, 7:53 AM

I've successfully implemented the tree and treemenu available from http://www.phpguru.org. There are some examples at http://www.phpguru.org/static/treemenu.html.

In order to use it in CCS you need to set up a wrapper function or class which saves the generated html and javascript code to a variable that can displayed in a Label control with the "contents" set to HTML. Drop me an email atlvalverdeb@yahoo.com if you'd like some extra pointers and sample code.

Best Regards

Luis

_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4
View profile  Send private message
Jase
Posted: 05/18/2005, 9:35 AM

Here is some code that implements what Ivalverdeb describes.

Download the TreeMenu scripts from http://www.phpguru.org/static/treemenu.html

Create a label and name it Label_TreeMenu.
Add a "Server" "Before Show" "Custom Code" event, and insert the code below, between the //-- Start Here --- and // --- End Here ---.

upload the Images, Treemenu.php and treemenu.js scripts along with the CCS generated pages. If you copy them to the CCS Project folder, they will be uploaded when the project is published.



//Custom Code @70-48EC3426
// -------------------------
global $Label_TreeMenu;

// ---- Start here ---- Omit lines above ---

// Build a TreeView from a database.
// Interface phpguru.com's TreeMenu to CCS. http://www.phpguru.org/static/treemenu.html
// 5-18-05 jnorris

// DB table requires a branch, parent_branch, and contents columns.
// I'm also filtering by UserID for my application. Adjust as necessary.

// Get UserID for use with query...
$UserID = CCGetFromGet("UserID",0);

if($UserID > 0) {

require_once('./TreeMenu.php');

$icon = 'folder.gif';
$expandedIcon = 'folder-expanded.gif';
$i = 0; //index

// connect to DB...
$db = new clsDBConnection1();
$SQL = "SELECT * FROM box WHERE box_client_id = ".$UserID;

$db->query($SQL);
$Result = $db->next_record();

$menu = new HTML_TreeMenu();

while($Result > 0) {

// populate variables from db...
$branch = $db->f("box_compartment");
$branch_parent = $db->f("box_parent_compartment");
$branch_value = $db->f("box_value");

// Build tree...
if($branch_parent) {
$$branch = &$$branch_parent->addItem(new HTML_TreeNode(array('text' => $branch, 'link' => $branch_value, 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
} else {
$$branch = new HTML_TreeNode(array('text' => $branch, 'link' => $branch_value, 'icon' => $icon, 'expandedIcon' => $expandedIcon));
$tree[$i++] = &$$branch; // Indexed reference for final tree consruction.
}

unset($branch);
unset($branch_parent);
unset($branch_value);

$Result = $db->next_record();
} //wend

$db->close();


// FOREACH was uncooperative for some reason...
$temp = 0;
while($temp < $i){
$menu->addItem($tree[$temp]);
$temp++;
}

// Stuff menu DHTML into the label...
$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => './images', 'defaultClass' => 'treeMenuDefault'));
$Label_TreeMenu->SetValue($treeMenu->toHTML());

} else { // Error message stuffed into label instead...
$Label_TreeMenu->SetValue("TREEMENU: No UserID");
} //endif

// --- End here --- Omit lines below ----

// -------------------------
//End Custom Code




Jase
Posted: 05/22/2005, 5:52 AM

I forgot to mention that you will also need to add

<script src="./TreeMenu.js" language="JavaScript" type="text/javascript"></script>

to your HTML.

-Jase
frankie

Posts: 6
Posted: 05/31/2005, 6:21 AM

Dear Jase,

Thanks for the example codes. However, I failed to implament the codes in my application. When the page is loaded, the only items that I see in my own tree menu is nothing but folder pictures. I know I did something wrong. I deployed the "the Images, Treemenu.php and treemenu.js scripts along with the CCS generated pages" and since I do not need any filter, I removed;
------------------------------------------------------------------
//$UserID = CCGetFromGet("UserID",0);
//if($UserID > 0) {
.........
.........
//} else { // Error message stuffed into label instead...
//$Label_TreeMenu->SetValue("TREEMENU: No UserID");
//} //endif

WHERE parameter from SQL statement
-----------------------------------------------------------------
Would it be because of construction of MySQL table?

Also the TreeMenu.js is in its place.

Any notion of yours to help me out?

Thanks.



View profile  Send private message
edpmatrix

Posts: 3
Posted: 06/12/2005, 9:42 AM

The problem is in treemenu.php .
Search function toHTML() in treemenu.php and split it in two functions like:
function toHTML()
{
static $count = 0;
$menuObj = $this->jsObjectName . '_' . ++$count;

$html = "\n";
$html .= '<script language="javascript" type="text/javascript">' . "\n//<![CDATA[\n\t";
$html .= sprintf('%s = new TreeMenu("%s", "%s", "%s", "%s", %s, %s);',
$menuObj,
$this->images,
$menuObj,
$this->linkTarget,
$this->defaultClass,
$this->usePersistence ? 'true' : 'false',
$this->noTopLevelImages ? 'true' : 'false');

$html .= "\n";

/**
* Loop through subnodes
*/
if (isset($this->menu->items)) {
for ($i=0; $i<count($this->menu->items); $i++) {
$html .= $this->_nodeToHTML($this->menu->items[$i], $menuObj);
}
}
$html .= "\n// ]]>\n</script>";

return $html;
}

function BuildHTML()
{
static $count = 0;
$menuObj = $this->jsObjectName . '_' . ++$count;

$html = "\n";
$html .= '<script language="javascript" type="text/javascript">' . "\n//<![CDATA[\n\t";

$html .= sprintf("\n\t%s.drawMenu();", $menuObj);
$html .= sprintf("\n\t%s.writeOutput();", $menuObj);

if ($this->usePersistence && $this->isDynamic) {
$html .= sprintf("\n\t%s.resetBranches();", $menuObj);
}
$html .= "\n// ]]>\n</script>";

return $html;
}
the first build HTML code and put it in the output, then you can use te second to recall it where you wont or put directly trought a CCS label this code rows in beforeshow event:

$TestoJava = "\n".'<script language="javascript" type="text/javascript">
objTreeMenu_1.drawMenu();
objTreeMenu_1.writeOutput();
objTreeMenu_1.resetBranches();
</script><html>'."\n";

$Menu->Label1->SetValue($TestoJava);
View profile  Send private message
Darren
Posted: 06/27/2005, 1:02 AM

HI all i'm using treeMenu to build a menu from a database but am having lots of issues.
1: i'm working with php and firebird and have little OOP knowlage.
2: I get this response at the moment and don't know why - Call to a member function addItem() on a non-object in
3: there are 2 function toHTML() in my TreeMenu.php file should I replace the top one or the bottom one and do I replace the whole function or just parts of it?
4: my id and parent id's are int's is that ok?

Thanks Darren
stachu
Posted: 07/06/2005, 8:49 AM

Quote Jase:
Here is some code that implements what Ivalverdeb describes.

Download the TreeMenu scripts from http://www.phpguru.org/static/treemenu.html

Create a label and name it Label_TreeMenu.
Add a "Server" "Before Show" "Custom Code" event, and insert the code below, between the //-- Start Here --- and // --- End Here ---.

upload the Images, Treemenu.php and treemenu.js scripts along with the CCS generated pages. If you copy them to the CCS Project folder, they will be uploaded when the project is published.



//Custom Code @70-48EC3426
// -------------------------
global $Label_TreeMenu;

// ---- Start here ---- Omit lines above ---

// Build a TreeView from a database.
// Interface phpguru.com's TreeMenu to CCS. http://www.phpguru.org/static/treemenu.html
// 5-18-05 jnorris

// DB table requires a branch, parent_branch, and contents columns.
// I'm also filtering by UserID for my application. Adjust as necessary.

// Get UserID for use with query...
$UserID = CCGetFromGet("UserID",0);

if($UserID > 0) {

require_once('./TreeMenu.php');

$icon = 'folder.gif';
$expandedIcon = 'folder-expanded.gif';
$i = 0; //index

// connect to DB...
$db = new clsDBConnection1();
$SQL = "SELECT * FROM box WHERE box_client_id = ".$UserID;

$db->query($SQL);
$Result = $db->next_record();

$menu = new HTML_TreeMenu();

while($Result > 0) {

// populate variables from db...
$branch = $db->f("box_compartment");
$branch_parent = $db->f("box_parent_compartment");
$branch_value = $db->f("box_value");

// Build tree...
if($branch_parent) {
$$branch = &$$branch_parent->addItem(new HTML_TreeNode(array('text' => $branch, 'link' => $branch_value, 'icon' => $icon, 'expandedIcon' => $expandedIcon)));
} else {
$$branch = new HTML_TreeNode(array('text' => $branch, 'link' => $branch_value, 'icon' => $icon, 'expandedIcon' => $expandedIcon));
$tree[$i++] = &$$branch; // Indexed reference for final tree consruction.
}

unset($branch);
unset($branch_parent);
unset($branch_value);

$Result = $db->next_record();
} //wend

$db->close();


// FOREACH was uncooperative for some reason...
$temp = 0;
while($temp < $i){
$menu->addItem($tree[$temp]);
$temp++;
}

// Stuff menu DHTML into the label...
$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => './images', 'defaultClass' => 'treeMenuDefault'));
$Label_TreeMenu->SetValue($treeMenu->toHTML());

} else { // Error message stuffed into label instead...
$Label_TreeMenu->SetValue("TREEMENU: No UserID");
} //endif

// --- End here --- Omit lines below ----

// -------------------------
//End Custom Code






Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.