function recursive_get_posts($post) { $children = get_record_select('forum_posts', "parent = " . $post->id . " AND discussion = " . $post->discussion); $return_array = array(); $return_array["id"] = $post->id; $return_array["userid"] = $post->userid; $return_array["created"] = $post->created; $return_array["modified"] = $post->modified; $return_array["subject"] = $post->subject; $return_array["message"] = $post->message; $return_array["format"] = $post->format; $return_array["attachment"] = $post->attachment; $return_array["children"] = array(); if (is_array($children)) { foreach ($children as $child) { $return_array["children"][] = recursive_get_posts($child); } } elseif ($children) { $return_array["children"][] = recursive_get_posts($children); } return $return_array; }
} else { $json_output["errors"][] = "This server does not support mPage's password recovery."; } } } else { if ($username) { $json_output["errors"][] = "A user with the username \"{$username}\" was not found."; } else { $json_output["errors"][] = "A user with the e-mail address \"{$email}\" was not found."; } } } if (isset($_GET['forum'])) { /* $module_instances = get_records_select('course_modules', "id = " . $_POST['id'], 'id'); $instance = $module_instances[$_POST['id']]; */ $forums = get_records_select('forum', "id = " . $_POST['id'], 'id'); $forum = $forums[$_POST['id']]; $discussions = get_records_select('forum_discussions', "forum = " . $forum->id); $discussions_array = array(); foreach ($discussions as $discussion) { $original_post = get_record_select('forum_posts', "parent = 0 AND discussion = " . $discussion->id); $discussions_array[] = recursive_get_posts($original_post); } $return_array = array(); $return_array["id"] = $_POST['id']; $return_array["discussions"] = $discussions_array; $json_output["forum"] = $return_array; } echo json_encode($json_output);