/** * Recursive function to propagate permissions from a category to all * sub-categories. * * @param integer $id ID of top-level category * @param array $perms Associative array of permissions to apply */ private static function _propagatePerms($id, $perms) { global $_TABLES; $id = (int) $id; // Locate the child categories of this one $sql = "SELECT cat_id FROM {$_TABLES['ad_category']}\n WHERE papa_id = {$id}"; //echo $sql;die; $result = DB_query($sql); // If there are no children, just return. if (!$result) { return ''; } $cats = array(); while ($row = DB_fetchArray($result, false)) { $cats[] = $A['cat_id']; } $cat_str = implode(',', $cats); // Update each located row $sql = "UPDATE {$_TABLES['ad_category']} SET\n perm_owner={$perms['perm_owner']},\n perm_group={$perms['perm_group']},\n perm_members={$perms['perm_members']},\n perm_anon={$perms['perm_anon']}\n WHERE cat_id IN ({$cat_str})"; DB_query($sql); // Now update the children of the current category's children foreach ($cats as $catid) { adCategory::_propagateCatPerms($catid, $perms); } }