<?php

/**
 * Implementation of hook_menu();
 */
function chat_room_menu(){
  return array(
    'chat_room' => array(
      'title' => 'Chat room',
      'description' => 'Chat with other users of your site',
      'page callback' => 'chat_room_page',
      'access arguments' => array(
        'access chat room'
      ),
      'type' => MENU_NORMAL_ITEM
    )
  );
}

/**
 * Implementation of hook_permission().
 */
function chat_room_permission(){
  return array(
    'access chat room' => array(
      'title' => t('Access chat room')
    )
  );
}

/**
 * Call back for the chat room page
 */
function chat_room_page(){
  drupal_add_css(drupal_get_path('module', 'chat_room') . '/css/chat_room.css');
  websockets_add();
  drupal_add_js(drupal_get_path('module', 'chat_room') . '/js/chat_room.js');
  global $user;
  drupal_add_js(array(
    'chat_room' => array(
      'user' => array(
        'name' => $user->name,
        'uid' => $user->uid,
        'url' => url('user/' . $user->uid, array(
          'absolute' => TRUE
        ))
      )
    )
  ), 'setting');
  return '<div id="chat_room-messages"></div><div id="chat_room-input"><form><textarea id="chat_room-textarea" style="resize:none"></textarea></form></div>';
}
