<?php
chdir('/var/www/cacti/'); # Cacti's directory
include('./include/global.php');
duplicate_tree(ID_FROM, ID_TO); # ID of tree
function duplicate_tree($tree_id_from, $tree_id_to) {
$tree_items = db_fetch_assoc("SELECT * FROM graph_tree_items WHERE graph_tree_id = " . $tree_id_from);
foreach ($tree_items as $item) {
$item["id"] = "";
$item["graph_tree_id"] = $tree_id_to;
$new_item = implode("','", $item);
$sql = "INSERT INTO graph_tree_items VALUES('" . $new_item . "')";
db_execute($sql);
}
}
?>
Can someone please help me make sense of the above code? it is meant to be used to create duplicate trees in cacti or moving existing trees into a new tree.
i have no idea what to give the script or how to run it. i ran it this way:
php duplicate_tree.php
and received an error:
PHP Notice: Use of undefined constant ID_FROM - assumed 'ID_FROM' in /var/home/skysmart/duplicate_tree.php on line 6
PHP Notice: Use of undefined constant ID_TO - assumed 'ID_TO' in /var/home/skysmart/duplicate_tree.php on line 6
PHP Warning: Invalid argument supplied for foreach() in /var/home/skysmart/duplicate_tree.php on line 12