function customAlterAdmin($user_id, $cat_id, $new_cat_id) { //return if we have nothing to do if ($cat_id === $new_cat_id) { return true; } $user_id = escape($user_id); if ($cat_id !== FALSE) { $cat_id = escape($cat_id); } if ($new_cat_id !== FALSE) { $new_cat_id = escape($new_cat_id); } $old_association = FALSE; //verify existing association if ($cat_id !== false) { $result = mysql_query("SELECT COUNT(*) FROM user_custom WHERE user_id = '{$user_id}' AND category = '{$cat_id}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $old_association = TRUE; } } //invalidate new_cat_id if it exists already // in this case, we just delete cat_id association if ($new_cat_id !== false) { $result = mysql_query("SELECT COUNT(*) FROM user_custom WHERE user_id = '{$user_id}' AND category = '{$new_cat_id}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { $new_cat_id = false; } } if ($old_association) { //update or delete existing association if ($new_cat_id === false) { mysql_query("DELETE FROM user_custom WHERE user_id = '{$user_id}' AND category = '{$cat_id}'"); //if user has no more custom categories, remove from custom field group $result = mysql_query("SELECT COUNT(*) FROM user_custom WHERE user_id = '{$user_id}'"); $row = mysql_fetch_row($result); if ($row[0] == 0) { alterAdminGroups($user_id, -2, false); } } else { mysql_query("UPDATE user_custom SET category = '{$new_cat_id}' WHERE user_id = '{$user_id}' AND category = '{$cat_id}'"); } } else { if ($new_cat_id !== false) { //only add an association if we're not trying to delete it! mysql_query("INSERT INTO user_custom (user_id, category) VALUES ('{$user_id}', '{$new_cat_id}')"); //add custom field group if needed alterAdminGroups($user_id, false, -2); } } return TRUE; }
$error = "Username not found."; } } else { if (($action == 'remove' || $action == "Remove") && isset($_REQUEST['id']) && isset($_REQUEST['group_id_orig'])) { if (substr($_REQUEST['group_id_orig'], 0, 1) == 'g') { alterAdminGroups($_REQUEST['id'], substr($_REQUEST['group_id_orig'], 1), false); } else { if (substr($_REQUEST['group_id_orig'], 0, 1) == 'c') { customAlterAdmin($_REQUEST['id'], substr($_REQUEST['group_id_orig'], 1), false); } } $success = "Admin removed successfully."; } else { if (($action == 'update' || $action == 'Update') && isset($_REQUEST['id']) && isset($_REQUEST['group_id_orig']) && isset($_REQUEST['group_id'])) { if (substr($_REQUEST['group_id'], 0, 1) == 'g') { alterAdminGroups($_REQUEST['id'], substr($_REQUEST['group_id_orig'], 1), substr($_REQUEST['group_id'], 1)); } else { if (substr($_REQUEST['group_id'], 0, 1) == 'c') { customAlterAdmin($_REQUEST['id'], substr($_REQUEST['group_id_orig'], 1), substr($_REQUEST['group_id'], 1)); } } $success = "Admin updated successfully."; } } } } //get list of possible groups //there are three types we have to consider: // 1. clubs, in user_groups // 2. special groups, in user_groups // 3. custom field groups, in user_custom