<?php require_once dirname(__FILE__) . '/class.db.php'; require_once dirname(__FILE__) . '/class.tree.php'; if (isset($_GET['operation'])) { $fs = new tree(db::get('mysqli://root@127.0.0.1/test'), array('structure_table' => 'tree_struct', 'data_table' => 'tree_data', 'data' => array('nm'))); try { $rslt = null; switch ($_GET['operation']) { case 'analyze': var_dump($fs->analyze(true)); die; break; case 'get_node': $node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int) $_GET['id'] : 0; $temp = $fs->get_children($node); $rslt = array(); foreach ($temp as $v) { $rslt[] = array('id' => $v['id'], 'text' => $v['nm'], 'children' => $v['rgt'] - $v['lft'] > 1); } break; case "get_content": $node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : 0; $node = explode(':', $node); if (count($node) > 1) { $rslt = array('content' => 'Multiple selected'); } else { $temp = $fs->get_node((int) $node[0], array('with_path' => true)); $rslt = array('content' => 'Selected: /' . implode('/', array_map(function ($v) { return $v['nm']; }, $temp['path'])) . '/' . $temp['nm']);