--- regcode.module.old	2007-02-22 14:10:18.000000000 -0500
+++ regcode.module	2007-03-29 13:39:34.203125000 -0400
@@ -9,107 +9,133 @@
 // Initial written by nevets (http://drupal.org/user/12856).
 // See http://drupal.org/node/85861 for details.
 // Edited and hacked on by colan (http://drupal.org/user/58704).
+// Updated to Drupal 5.x by kaushik_sarkar (http://drupal.org/user/95377).
 
-/** 
- * Display help and module information.
- *
- * @param section
- *   which section of the site we're displaying help
- * @return
- *   help text for section
- */
+/**
+* Display help and module information.
+*
+* @param section
+* which section of the site we're displaying help
+* @return
+* help text for section
+*/
 function regcode_help($section) {
-  switch ($section) {
-    case 'admin/help#regcode':
-      return t('<p>Allows administrators to set a registration code or codes
-        that new users must enter before they can complete the registration
-        process.  If a new user enters a code that is not in the list of
-        valid codes, he or she is denied registration.</p>
-        <p>To set the codes, go to administer->settings->regcode and enter
-        them there.  To disable the registration code requirement for new
-        users, simply disable the module (in administer->modules).</p>');
-    case 'admin/modules#description':
-      return t('If enabled, users must enter a valid registration code to
-        register');
-  }
+switch ($section) {
+case 'admin/help#regcode':
+return t('
+
+Allows administrators to set a registration code or codes
+that new users must enter before they can complete the registration
+process. If a new user enters a code that is not in the list of
+valid codes, he or she is denied registration.
+
+To set the codes, go to Administer->Site Configuration->Regcode and enter
+them there. To disable the registration code requirement for new
+users, simply disable the module (in administer->modules).
+
+');
+case 'admin/modules#description':
+return t('If enabled, users must enter a valid registration code to
+register');
+}
 }
-
 
 /**
- * Set valid permissions for this module.
- *
- * @return
- *   An array of valid permissions for the module
- */
+* Set valid permissions for this module.
+*
+* @return
+* An array of valid permissions for the module
+*/
 function regcode_perm() {
-  return array('administer registration codes');
+return array('administer registration codes');
 }
 
-
 /**
- * Declare administrative settings for a module.
- *
- * @return
- *   An array containing form items to place on the module settings page
- */
-function regcode_settings() {
-  $form['regcode_codes'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Registration Code(s)'),
-    '#required' => TRUE,
-    '#default_value' => variable_get('regcode_codes', ''),
-    '#description' => t('If set, new users must correctly enter one of these
-      codes in order to register.  Enter one code per line.')
-  );
-  return $form;
-}
-
+* Declare administrative settings for a module.
+*
+* @return
+* An array containing form items to place on the module settings page
+*/
+/* Actually hook_setting does not work in Drupal 5.1 environment So, the equivalent is hook_menu($may_cache) api, I implement this api
+*/
+function regcode_menu($may_cache)
+{
+$items = array();
+
+$items[] = array('path' => 'admin/settings/regcode',
+'title' => t('Regcode'),
+'callback' => 'drupal_get_form',
+'callback arguments' => array('regcode_admin_settings'),
+'access' => user_access('administer registration codes
+'),
+'description' => t('Display registration code on the registration page.')
+
+);
+
+return $items;
+
+}//end of function regcode_menu
+
+function regcode_admin_settings()
+{
+$form['regcode_codes'] = array(
+'#type' => 'textarea',
+'#title' => t('Registration Code(s)'),
+'#required' => TRUE,
+'#default_value' => variable_get('regcode_codes', ''),
+'#description' => t('If set, new users must correctly enter one of these
+codes in order to register. Enter one code per line.')
+);
+$form = system_settings_form($form);
+return $form;
 
+}
 /**
- * Act on user account actions.
- *
- * @param $op
- *   The kind of action is being performed
- * @param $edit
- *   The array of form values submitted by the user
- * @param $account
- *   The user object on which the operation is being performed
- * @param $category
- *   The active category of user information being edited
- * @return
- *   This varies depending on the operation.
- */
+* Act on user account actions.
+*
+* @param $op
+* The kind of action is being performed
+* @param $edit
+* The array of form values submitted by the user
+* @param $account
+* The user object on which the operation is being performed
+* @param $category
+* The active category of user information being edited
+* @return
+* This varies depending on the operation.
+*/
 function regcode_user($op, &$edit, &$account, $category = NULL) {
 
-  // Get the array of registration codes.
-  $regcodes = variable_get('regcode_codes', '');
+// Get the array of registration codes.
+$regcodes = variable_get('regcode_codes', '');
 
-  // Only do the checking if the codes variable is set.
-  if (strlen(trim($regcodes))) {
-    switch ($op) {
-
-      case 'register':
-        // Inject the registration code field into the registration form.
-        $form['regcode_code'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Registration Code'),
-          '#required' => TRUE,
-          '#description' => t('Please enter your registration code.')
-        );
-        return $form;
-
-      case 'validate':
-        if ($category == 'account') {
-          // Make sure that the entered code is in the list.
-          $regcodes = explode("\n", $regcodes);
-          array_walk($regcodes, create_function('&$a', '$a = trim($a);'));
-          if (!in_array(trim($edit['regcode_code']), $regcodes)) {
-            form_set_error('regcode_code', t('Invalid registration code'));
-            watchdog('regcode', t('User entered invalid registration code: ') .
-              $edit['regcode_code'], WATCHDOG_WARNING);
-          }
-        }
-        break;
-    }
-  }
+// Only do the checking if the codes variable is set.
+if (strlen(trim($regcodes))) {
+switch ($op) {
+
+case 'register':
+// Inject the registration code field into the registration form.
+$form['regcode_code'] = array(
+'#type' => 'textfield',
+'#title' => t('Registration Code'),
+//'#default_value' => variable_get('regcode_codes', ''),
+'#required' => TRUE,
+'#description' => t('Please enter your registration code.')
+);
+return $form;
+
+case 'validate':
+if ($category == 'account') {
+// Make sure that the entered code is in the list.
+$regcodes = explode("\n", $regcodes);
+array_walk($regcodes, create_function('&$a', '$a = trim($a);'));
+if (!in_array(trim($edit['regcode_code']), $regcodes)) {
+form_set_error('regcode_code', t('Invalid registration code'));
+watchdog('regcode', t('User entered invalid registration code: ') .
+$edit['regcode_code'], WATCHDOG_WARNING);
+}
+}
+break;
+}
 }
+}
\ No newline at end of file
