/**
  * Return a boolean to indicate whether or not this filter is displayed
  * depending upon whether any custom fields are found for this user
  * @param string       $field_type  type of custom field to check
  * @return boolean  true if the filter is to show
  */
 function check_for_custom_fields($field_type)
 {
     // Get custom course fields by context level
     $context = context_level_base::get_custom_context_level($field_type, 'block_curr_admin');
     $fields = field::get_for_context_level($context);
     $fields = $fields ? $fields : array();
     $testfields = array();
     foreach ($fields as $field) {
         //make sure the current user can access this field in at least one
         //course context
         $owners = field_owner::get_for_field($field);
         if (!block_php_report_field_accessible($owners)) {
             continue;
         }
         return true;
     }
     return false;
 }
}
$categories = field_category::get_for_context_level($context);
$categories = $categories ? $categories : array();
// divide the fields into categories
$fieldsbycategory = array();
foreach ($categories as $category) {
    $fieldsbycategory[$category->name] = array();
}
foreach ($fields as $field) {
    if (is_array($fieldidlist) && in_array($field->id, $fieldidlist)) {
        continue;
    }
    //make sure the current user can access this field in at least one
    //course context
    $owners = field_owner::get_for_field($field);
    if (!block_php_report_field_accessible($owners)) {
        continue;
    }
    $fieldsbycategory[$field->categoryname][] = $field;
}
print_header($site->shortname . ': ' . get_string('selectcustomfields', $lang_file));
// show list of available fields
if (empty($fieldsbycategory)) {
    echo '<div>' . get_string('nofieldsfound', $lang_file) . '</div>';
} else {
    echo '<div>' . get_string('customfields', $lang_file) . '</div>';
    $table = null;
    $columns = array('category' => get_string('category', $lang_file), 'name' => get_string('name', $lang_file));
    foreach ($columns as $column => $cdesc) {
        ${$column} = $cdesc;
        $table->head[] = ${$column};