if (!isset($imap_php))
include("../functions/imap.php");
+ // Recursive function to find the correct parent for a new node
function findParentForChild($value, $treeIndexToStart, $tree) {
+ // is $value in $tree[$treeIndexToStart]["value"]
if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]["value"]))) {
+ // do I have children, if not then must be a childnode of the current node
if ($tree[$treeIndexToStart]["doIHaveChildren"]) {
+ // loop through each subNode checking to see if we are a subNode of one of them
for ($i=0;$i< count($tree[$treeIndexToStart]["subNodes"]);$i++) {
- $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i]);
+ $result = findParentForChild($value, $tree[$treeIndexToStart]["subNodes"][$i], $tree);
if ($result > -1)
return $result;
}
+ // if we aren't a child of one of the subNodes, must be a child of current node
return $treeIndexToStart;
} else
return $treeIndexToStart;
} else {
+ // we aren't a child of this node at all
return -1;
}
}
- function addChildNodeToTree($value, &$tree) {
- $parentNode = findParentForChild($value, 0, $tree);
+ function addChildNodeToTree($comparisonValue, $value, &$tree) {
+ $parentNode = findParentForChild($comparisonValue, 0, $tree);
// create a new subNode
- $newNodeIndex = count($tree) + 1;
+ $newNodeIndex = count($tree);
$tree[$newNodeIndex]["value"] = $value;
$tree[$newNodeIndex]["doIHaveChildren"] = false;
sqimap_messages_copy($imap_stream, 1, $messageCount, $trash_folder . $dm . $subFolderName);
}
}
+
+ function simpleWalkTreePre($index, $tree) {
+ if ($tree[$index]["doIHaveChildren"]) {
+ for ($j = 0; $j < count($tree[$index]["subNodes"]); $j++) {
+ simpleWalkTreePre($tree[$index]["subNodes"][$j], $tree);
+ }
+ echo $tree[$index]["value"] . "<br>";
+ } else {
+ echo $tree[$index]["value"] . "<br>";
+ }
+ }
?>