--- /dev/null
+<?php
+/**
+ * @file
+ * Allows setting notices for specific roles
+ */
+
+/**
+ * Implements hook_permission().
+ *
+ * http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_permission/7
+ * @return array An array of valid permissions for the module_name module
+ */
+function rnotices_permission() {
+ return array(
+ 'administer role notices' => array(
+ 'title' => t('Administer Role Notices'),
+ 'description' => t('Allows the user to set messages for all roles'),
+ ),
+ );
+}
+/**
+ * Implementationation of hook_menu().
+ *
+ * http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_menu/7
+ */
+function rnotices_menu() {
+ $items['admin/people/rnotices'] = array(
+ 'title' => 'Role Notices',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('rnotices_settings'),
+ 'access arguments' => array('administer role notices'),
+ 'type' => MENU_LOCAL_TASK,
+ );
+
+
+ return $items;
+}
+/**
+ * Settings form
+ * Admin may enter role notices
+ *
+ * @param array $form
+ * @param array $form_state
+ * @return array
+ */
+function rnotices_settings($form, &$form_state) {
+ $notices = variable_get('rnotices_texts',array());
+ $roles = user_roles(TRUE);
+ dpm($roles);
+ $form['rnotices_texts'] = array(
+ '#tree' => TRUE,
+ );
+ foreach ($roles as $rid => $role){
+ $form['rnotices_texts'][$rid] = array(
+ '#type' => 'textarea',
+ '#title' => t('Notice for @role', array('@role' => $role)),
+ '#default_value' => isset($notices[$rid])?$notices[$rid]:'',
+ );
+ }
+ // system_settings_form - will default buttons and
+ // Drupal will will handle the submiting of the form automatically
+ return system_settings_form($form);
+}
+/**
+ * Implements hook_user_view().
+ *
+ * Adds notices when a user is viewing their own profile
+ */
+function rnotices_user_view($account, $view_mode, $langcode) {
+ global $user;
+ if($user->uid == $account->uid){
+ $notices = _rnotices_get_notices();
+ $account->content['rnotices'] = array(
+ '#title' => t('Notices'),
+ '#items' => $notices,
+ '#theme' => 'item_list',
+ );
+ }
+}
+/**
+ * @return array An array of notices for the current user. keyed by role id(rid)
+ */
+function _rnotices_get_notices(){
+ global $user;
+ $all_notices = variable_get('rnotices_texts',array());
+ return array_intersect_key($all_notices, $user->roles);
+}
+/**
+ * Implements hook_action_info().
+ *
+ * Tells Drupal about the action functions that this module provides
+ */
+function rnotices_action_info() {
+ return array(
+ 'rnotices_messages' => array(
+ 'description' => t('Display Role Notices to the user'),
+ 'type' => 'user',
+ 'label' => t('Display Role Notices'),
+ 'triggers' => array(
+ 'user_login',
+ )
+ )
+ );
+}
+/**
+ * Displays notices for current user as messages
+ * @see rnotices_action_info
+ */
+function rnotices_messages(){
+ $notices = _rnotices_get_notices();
+ foreach ($notices as $notice) {
+ drupal_set_message($notice);
+ }
+}
+/**
+ * Implements hook_block_info().
+ *
+ * Allows the module to define blocks
+ *
+ * @return array Block keyed by delta strings
+ */
+function rnotices_block_info() {
+ $blocks['rnotices_mine'] = array(
+ 'info' => t('Role Notices'),
+ 'description' => t('Display the Role Notices for the current user')
+ );
+
+ return $blocks;
+}
+/**
+ * Implements hook_block_view().
+ *
+ * This hook is called to display a block
+ * @param string $delta
+ * key to determine which block should be displayed
+ * @return array
+ */
+function rnotices_block_view($delta = '') {
+ switch ($delta){
+ case 'rnotices_mine':
+ $notices = _rnotices_get_notices();
+ return array(
+ 'subject' => t('Notices'),
+ 'content' => theme('rnotices_display', array('notices' => $notices)),
+ );
+ break;
+ }
+}
+function theme_rnotices_display($variables){
+ return theme('item_list', array('items' => $variables['notices']));
+}
+/**
+ * Implements hook_theme().
+ *
+ * Tell Drupal what theme functions this module defines
+
+ * @param array $existing
+ * @param string $type
+ * @param string $theme
+ * @param string $path
+ * @return array An associative array of theme hook information.
+ * The keys on the outer array are the internal names of the hooks, and the values are arrays containing information about the hook. Each array may contain the following elements:
+ */
+function rnotices_theme($existing, $type, $theme, $path) {
+ return array(
+ 'rnotices_display' => array(
+ 'arguments' => array('notices' => array())
+ )
+ );
+}
\ No newline at end of file