Custom Pro Sites code produces error in media upload page.

All of my sub sites (except the main site = blog_id = 1), when attempting to upload the image, it produces this error >> “An error occurred in the upload. Please try again later.” (Please see attached.) without showing the progress bar over the image thumbnail and yet the image was uploaded successfully though. After several testings, I found out that the code in my prosites-plugin.php inside the “mu-plugins” folder was causing the aforementioned error:

<?php
global $wpdb;
$blog_id = $wpdb->blogid;
$sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";

$level = $wpdb->get_var($sql);

if ( 1 == $level ) {

function remove_admin_menus_perlevel () {
// Check that the built-in WordPress function remove_menu_page() exists in the current installation
if ( function_exists('remove_menu_page') ) {
remove_menu_page('tools.php'); // Tools
} ?>

<style type="text/css">
/*STYLE HERE*/
</style>

<?php
}
add_action('admin_menu', 'remove_admin_menus_perlevel');

function restrict_with_redirect_perlevel() {
$r_php_self = $_SERVER['PHP_SELF'];
$r_full_query = $r_php_self."?".$_SERVER['QUERY_STRING'];

$restrictions = array(
//PAGE TO RESTRICT FROM ACCESS
);
foreach ( $restrictions as $restriction ) {
if (stristr($r_full_query,$restriction)) {
if ( ! current_user_can( 'manage_network' ) ) {
wp_redirect( admin_url() );
exit;
}
}
}
}
add_action( 'admin_init', 'restrict_with_redirect_perlevel' );
}

When remove the “<style type=”text/css”>…</style>” part off completely from the plugin – coded with just a pure php, it doesn’t produce any error and started working as it should be.

I need to hide some of the menu though, that’s why I need to add a custom style according to user level on the Pro Sites.

1. After checking from Chrome browser, it looks like something to do with the wp-admin/ajax-upload.php file conflict in which the css is called before the HTML document. I might be wrong. I want to get rid of that error on the media upload page while still be able to use CSS custom inside the code above. please advice.

2. Is there another better way to hide some menus depending on their level apart from {display:none;}?