function recursive_get_subcategories($category_parent_id) { static $categories; if (!isset($categories)) { $categories = get_categories(); } $children = array(); if (isset($categories[$category_parent_id]['children']) && is_array($categories[$category_parent_id]['children'])) { $children = $categories[$category_parent_id]['children']; foreach ($categories[$category_parent_id]['children'] as $category_child_id) { if ($category_child_id) { $children = array_merge($children, recursive_get_subcategories($category_child_id)); } } } return $children; }
$cat_parent_id = intval($_POST['cat_parent_id']); if ($_POST['theme_parent']) { // get the theme of the parent category. $sql = "SELECT theme FROM " . TABLE_PREFIX . "course_cats WHERE cat_id={$cat_parent_id}"; $result = mysql_query($sql, $db); if ($row = mysql_fetch_assoc($result)) { $cat_theme = $row['theme']; } } if ($cat_name == '') { $msg->addError(array('EMPTY_FIELDS', _AT('title'))); } if (!$msg->containsErrors()) { if ($_POST['theme_children']) { // apply this theme to all the sub-categories recursively. $children = recursive_get_subcategories($cat_id); $children = implode(',', $children); if ($children) { $sql = "UPDATE " . TABLE_PREFIX . "course_cats SET theme='{$cat_theme}' WHERE cat_id IN ({$children})"; $result = mysql_query($sql, $db); write_to_log(AT_ADMIN_LOG_UPDATE, 'course_cats', mysql_affected_rows($db), $sql); } } $sql = "UPDATE " . TABLE_PREFIX . "course_cats SET cat_parent={$cat_parent_id}, cat_name='{$cat_name}', theme='{$cat_theme}' WHERE cat_id={$cat_id}"; $result = mysql_query($sql, $db); write_to_log(AT_ADMIN_LOG_UPDATE, 'course_cats', mysql_affected_rows($db), $sql); $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); header('Location: course_categories.php'); exit; } } else {