From 1f76aec60755c062be1d4c22d7b94c0d7554c97a Mon Sep 17 00:00:00 2001
From: Jinson <Jinson@50400.no-reply.drupal.org>
Date: Sun, 21 Aug 2011 04:23:04 +0800
Subject: [PATCH] Updated module to work with Drupal 7

---
 mibbit_irc.info    |    3 +-
 mibbit_irc.install |    4 +-
 mibbit_irc.module  |   60 +++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/mibbit_irc.info b/mibbit_irc.info
index 1f5518a..5a66596 100755
--- a/mibbit_irc.info
+++ b/mibbit_irc.info
@@ -1,3 +1,4 @@
 name = Mibbit IRC
 description = Allows users to participate in IRC chats via a web page in the community.
-package = Other
\ No newline at end of file
+package = Other
+files[] = mibbit_irc.module
\ No newline at end of file
diff --git a/mibbit_irc.install b/mibbit_irc.install
index 1cb3f04..6d4ace2 100755
--- a/mibbit_irc.install
+++ b/mibbit_irc.install
@@ -4,8 +4,8 @@
 * Implementation of hook_install().
 */
 function mibbit_irc_install() {
-  drupal_set_message(t('Mibbit IRC has been successfully installed.'));
-  drupal_set_message(t('You can configure the Mibbit IRC module on the <a href="@url">Mibbit IRC settings page</a>.', array('@url' => url('admin/settings/mibbitirc'))));
+  drupal_set_message(st('Mibbit IRC has been successfully installed.'));
+  drupal_set_message(st('You can configure the Mibbit IRC module on the <a href="@url">Mibbit IRC settings page</a>.', array('@url' => url('admin/settings/mibbitirc'))));
 }
 
 /**
diff --git a/mibbit_irc.module b/mibbit_irc.module
index c29987d..7a0999c 100755
--- a/mibbit_irc.module
+++ b/mibbit_irc.module
@@ -1,9 +1,9 @@
 <?php
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  */
-function mibbit_irc_perm() {
+function mibbit_irc_permission() {
   return array('access mibbit irc', 'administer mibbit irc');
 }
 
@@ -93,10 +93,16 @@ Feel free to join the conversations that are taking place.</p>')),
   );
   
   // Define a validation function.
-  $form['#validate'] = array(
-    'mibbit_irc_admin_settings_validate' => array()
+  $form['#validate'][] = 'mibbit_irc_admin_settings_validate';
+     
+  // Define submit details
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => 'Save Configuration',
+    '#submit' => array('mibbit_irc_admin_settings_submit'),
   );
-  return system_settings_form($form);
+  	 
+  return $form;
 }
 
 // Validate the settings form.
@@ -109,6 +115,50 @@ function mibbit_irc_admin_settings_validate($form, &$form_state) {
   }
 }
 
+//  Submit the settings form. Custom submit handler instead of using the default if we were to use system_settings_form() to build the form
+function mibbit_irc_admin_settings_submit($form, &$form_state) {
+ 
+  $values = array(
+  	'@title' => $form_state['values']['mibbit_irc_page_title'], 
+  	'@server' => $form_state['values']['mibbit_irc_server'],
+  	'@channel' => $form_state['values']['mibbit_irc_channel'],
+  	'@width' => $form_state['values']['mibbit_irc_width'],
+  	'@height' => $form_state['values']['mibbit_irc_height'],
+  	'@welcome' => $form_state['values']['mibbit_irc_welcome'],
+  	'@custom_prompt' => $form_state['values']['mibbit_irc_custom_prompt'],
+  	'@custom_loading' => $form_state['values']['mibbit_irc_custom_loading'],
+  	'@help' => $form_state['values']['mibbit_irc_help'],  
+  );
+  
+  // lets log it into our tracker too
+  watchdog('mibbit_irc', $form_state['values']['form_id'] . " form submitted. <br />
+  	Page title: @title <br />
+  	Server: @server <br />
+  	Channel[s]: @channel <br />
+  	Widget width: @width <br />
+  	Widget height: @height <br />
+  	Welcome message: <pre>@welcome</pre> <br />
+  	Custom prompt: @custom_prompt <br />
+  	Custom load: @custom_loading <br />
+  	Help: @help", $values, WATCHDOG_DEBUG); 
+
+  $message = t($form_state['values']['form_id'] . ' form submitted. <br /> The configuration options have been saved. <br /> ' . '<em>Refer to logs for full details</em>');
+  drupal_set_message($message);
+  
+  // Based on system_settings_form_submit from system.module
+  // Exclude unnecessary elements.
+  form_state_values_clean($form_state);
+  
+  foreach ($form_state['values'] as $key => $value) {
+  	if (is_array($value) && isset($form_state['values']['array_filter'])) {
+  		$value = array_keys(array_filter($value));
+  	}
+  	variable_set($key, $value);
+  }  
+}
+
+
+
 function mibbit_irc_page() {
   global $user;
   
-- 
1.7.6.msysgit.0

