<submit> </form> '>Add new category</div> <a href="#" onclick="jQuery('#example-advanced').treetable('expandAll'); return false;">Expand all</a> <a href="#" onclick="jQuery('#example-advanced').treetable('collapseAll'); return false;">Collapse all</a> </caption> <thead> <tr> <th>Category</th> <th>Actions</th> </tr> </thead> <?php //$recursive_count = 0; //$category_array = get_category_array(0,null); echo get_category_children_table_from_root(); //echo $output_html; //print_r_pre($category_array); ?> </table> </div> <script> $("#example-basic").treetable({ expandable: true }); $("#example-basic-static").treetable(); $("#example-basic-expandable").treetable({ expandable: true }); $("#example-advanced").treetable({ expandable: true });
function get_category_children_array_from_root($category_parent = 0) { global $category_array_organised; static $output_category_array = array(); static $recursive_count = 0; global $database; $datas = $GLOBALS['datas']; $data = array(); //$output_html .= "<tr>".PHP_EOL; $categories = get_category_array_ignore_level($category_parent); $catsize = sizeof($categories); for ($n = 0; $n <= $catsize - 1; $n++) { //$loop_category_level = $categories[$n]['category_level']; $loop_category_parent = $categories[$n]['category_parent']; $loop_category_id = $categories[$n]['category_id']; $loop_category_name = $categories[$n]['category_name']; //get payments $item_html = ""; for ($d = 0; $d <= 5; $d++) { //display each payment in this type foreach ($datas[$d] as $data) { //print_r_pre($datas); $item_cat = $data['payment_category']; $item_id = $data['payment_id']; $item_name = $data['payment_name']; $transactions_cat_total = $database->sum("history_transactions", "transaction_amount", ["transaction_category" => $loop_category_id]); //If (isset($data['payment_category'])) {$output_html.=$data['payment_category'];} //$item_html .= $loop_category_id; if ($item_cat == $loop_category_id) { $item_html_array[] = "data-pay-id='" . $item_id . "' data-tt-id='item-" . $item_id . "' data-tt-parent-id='" . $loop_category_id; // first item in this array is always the tr attribute for this row, can be blank $item_html_array[] = "<nobr><span class='file'>" . $item_name . "</span></nobr>"; } } } $output_category_array[] = "data-tt-id='" . $loop_category_id . "' data-tt-parent-id='" . $loop_category_parent; // first item in this array is always the tr attribute for this row, can be blank $output_category_array[] = "<nobr><span class='folder'>" . $categories[$n]['category_name'] . "</span></nobr>" . " <small><a href='#' class='xedit' id='category_name_edit_" . $categories[$n]['category_id'] . "' data-name='category_name' data-type='text' data-pk='" . $categories[$n]['category_id'] . "' data-url='/forecast/post.php' data-value='" . $categories[$n]['category_name'] . "' data-title='Enter Category Name'>edit...</a></small>"; //$output_category_array[]="$".$transactions_cat_total if ($loop_category_parent == '') { $loop_category_parent = null; } //$recursive_nodes_count = $loop_category_level; unset($category_nodes); $category_nodes = array(); //get_category_nodes(null, $loop_category_parent); //create an array indicating levels $category_array_organised[] = array("category_count" => $recursive_count, "category_id" => $loop_category_id, "category_name" => $loop_category_name); //print_r_pre($category_array_organised); $recursive_count++; get_category_children_table_from_root($loop_category_id); $recursive_count--; } //$output_html .="</tr>".PHP_EOL.'middle'.PHP_EOL; //debugger_stop_debug_mode(); return $output_html; }