function general_validation_message($record, $message, $type)
 {
     //need the plugin class for some utility functions
     $file = get_plugin_directory('dhimport', 'version1') . '/version1.class.php';
     require_once $file;
     // "action" is not always provided. In that case, return only the specific message
     if (empty($record->action)) {
         //missing action, general message will be fairly generic
         $type_display = ucfirst($type);
         return "{$type_display} could not be processed. {$message}";
         return $message;
     }
     $msg = "";
     if ($type == "enrolment") {
         if ($record->action != 'create' && $record->action != 'delete') {
             //invalid action
             return 'Enrolment could not be processed. ' . $message;
         }
         if (!$this->track_role_actions && !$this->track_enrolment_actions) {
             //error without sufficient information to properly provide details
             if ($record->action == 'create') {
                 return 'Enrolment could not be created. ' . $message;
             } else {
                 if ($record->action == 'delete') {
                     return 'Enrolment could not be deleted. ' . $message;
                 }
             }
         }
         //collect role assignment and enrolment messages
         $lines = array();
         if ($this->track_role_actions) {
             //determine if a user identifier was set
             $user_identifier_set = !empty($record->username) || !empty($record->email) || !empty($record->idnumber);
             //determine if all required fields were set
             $required_fields_set = !empty($record->role) && $user_identifier_set && !empty($record->context);
             //list of contexts at which role assignments are allowed for specific instances
             $valid_contexts = array('coursecat', 'course', 'user');
             //descriptive string for user and context
             $user_descriptor = rlip_importplugin_version1::get_user_descriptor($record);
             $context_descriptor = rlip_importplugin_version1::get_context_descriptor($record);
             switch ($record->action) {
                 case "create":
                     if ($required_fields_set && in_array($record->context, $valid_contexts) && !empty($record->instance)) {
                         //assignment on a specific context
                         $lines[] = "User with {$user_descriptor} could not be assigned role " . "with shortname \"{$record->role}\" on {$context_descriptor}.";
                     } else {
                         if ($required_fields_set && $record->context == 'system') {
                             //assignment on the system context
                             $lines[] = "User with {$user_descriptor} could not be assigned role " . "with shortname \"{$record->role}\" on the system context.";
                         } else {
                             //not valid
                             $lines[] = "Role assignment could not be created.";
                         }
                     }
                     break;
                 case "delete":
                     if ($required_fields_set && in_array($record->context, $valid_contexts) && !empty($record->instance)) {
                         //unassignment from a specific context
                         $lines[] = "User with {$user_descriptor} could not be unassigned role " . "with shortname \"{$record->role}\" on {$context_descriptor}.";
                     } else {
                         if ($required_fields_set && $record->context == 'system') {
                             //unassignment from the system context
                             $lines[] = "User with {$user_descriptor} could not be unassigned role " . "with shortname \"{$record->role}\" on the system context.";
                         } else {
                             //not valid
                             $lines[] = "Role assignment could not be deleted. ";
                         }
                     }
                     break;
             }
         }
         if ($this->track_enrolment_actions) {
             //determine if a user identifier was set
             $user_identifier_set = !empty($record->username) || !empty($record->email) || !empty($record->idnumber);
             //determine if some required field is missing
             $missing_required_field = !$user_identifier_set || empty($record->instance);
             //descriptive string for user
             $user_descriptor = rlip_importplugin_version1::get_user_descriptor($record);
             switch ($record->action) {
                 case "create":
                     if ($missing_required_field) {
                         //required field missing, so use generic failure message
                         $lines[] = "Enrolment could not be created.";
                     } else {
                         //more accurate failure message
                         $lines[] = "User with {$user_descriptor} could not be enrolled in " . "course with shortname \"{$record->instance}\".";
                     }
                     break;
                 case "delete":
                     if ($missing_required_field) {
                         //required field missing, so use generic failure message
                         $lines[] = "Enrolment could not be deleted.";
                     } else {
                         //more accurate failure message
                         $lines[] = "User with {$user_descriptor} could not be unenrolled " . "from course with shortname \"{$record->instance}\".";
                     }
                     break;
             }
         }
         //create combined message, potentially containing role assignment and
         //enrolment components
         $msg = implode(' ', $lines) . ' ' . $message;
     }
     if ($type == "course") {
         $type = ucfirst($type);
         switch ($record->action) {
             case "create":
                 if (empty($record->shortname)) {
                     $msg = "Course could not be created. " . $message;
                 } else {
                     $msg = "{$type} with shortname \"{$record->shortname}\" could not be created. " . $message;
                 }
                 break;
             case "update":
                 if (empty($record->shortname)) {
                     $msg = "Course could not be updated. " . $message;
                 } else {
                     $msg = "{$type} with shortname \"{$record->shortname}\" could not be updated. " . $message;
                 }
                 break;
             case "delete":
                 if (empty($record->shortname)) {
                     $msg = "Course could not be deleted. " . $message;
                 } else {
                     $msg = "{$type} with shortname \"{$record->shortname}\" could not be deleted. " . $message;
                 }
                 break;
             default:
                 //invalid action
                 $msg = 'Course could not be processed. ' . $message;
                 break;
         }
     }
     if ($type == "user") {
         $type = ucfirst($type);
         switch ($record->action) {
             case "create":
                 //make sure all required fields are specified
                 if (empty($record->username) || empty($record->email)) {
                     $msg = "User could not be created. " . $message;
                 } else {
                     $user_descriptor = rlip_importplugin_version1::get_user_descriptor($record);
                     $msg = "{$type} with {$user_descriptor} could not be created. " . $message;
                 }
                 break;
             case "update":
                 //make sure all required fields are specified
                 if (empty($record->username) && empty($record->email) && empty($record->idnumber)) {
                     $msg = "User could not be updated. " . $message;
                 } else {
                     $user_descriptor = rlip_importplugin_version1::get_user_descriptor($record);
                     $msg = "{$type} with {$user_descriptor} could not be updated. " . $message;
                 }
                 break;
             case "delete":
                 //make sure all required fields are specified
                 if (empty($record->username) && empty($record->email) && empty($record->idnumber)) {
                     $msg = "User could not be deleted. " . $message;
                 } else {
                     $user_descriptor = rlip_importplugin_version1::get_user_descriptor($record);
                     $msg = "{$type} with {$user_descriptor} could not be deleted. " . $message;
                 }
                 break;
             default:
                 //invalid action
                 $msg = 'User could not be processed. ' . $message;
                 break;
         }
     }
     return $msg;
 }