--- Desktop/Downloads/drupal-5.7/modules/contact/contact.module	2007-06-05 15:18:05.000000000 +0800
+++ workspace/raincitystudios.com/html/modules/contact/contact.module	2008-04-26 14:13:24.000000000 +0800
@@ -142,10 +142,11 @@ function contact_user($type, &$edit, &$u
  * Categories/list tab.
  */
 function contact_admin_categories() {
-  $result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category');
+  
+  $contact_categories = variable_get('contact_categories', array());
   $rows = array();
-  while ($category = db_fetch_object($result)) {
-    $rows[] = array($category->category, $category->recipients, ($category->selected ? t('Yes') : t('No')), l(t('edit'), 'admin/build/contact/edit/'. $category->cid), l(t('delete'), 'admin/build/contact/delete/'. $category->cid));
+  foreach ($contact_categories as $key=>$category) {
+    $rows[] = array($category['category'], $category['recipients'], ($category['selected'] ? t('Yes') : t('No')), l(t('edit'), 'admin/build/contact/edit/'. $category['cid']), l(t('delete'), 'admin/build/contact/delete/'. $category['cid']));
   }
   $header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2));
 
@@ -157,7 +158,13 @@ function contact_admin_categories() {
  */
 function contact_admin_edit($cid = NULL) {
   if (arg(3) == "edit" && $cid > 0) {
-    $edit = db_fetch_array(db_query("SELECT * FROM {contact} WHERE cid = %d", $cid));
+  	$contact_categories = variable_get('contact_categories', array());
+  	$edit = NULL;
+  	foreach ($contact_categories as $category) {
+      if ($category['cid'] == $cid) {
+        $edit = $category;
+      }
+  	}
   }
   $form['category'] = array('#type' => 'textfield',
     '#title' => t('Category'),
@@ -222,9 +229,14 @@ function contact_admin_edit_validate($fo
  * Process the contact category edit page form submission.
  */
 function contact_admin_edit_submit($form_id, $form_values) {
+  $contact_categories = variable_get('contact_categories', array());
   if ($form_values['selected']) {
     // Unselect all other contact categories.
-    db_query('UPDATE {contact} SET selected = 0');
+    foreach ($contact_categories as $key=>$category) {
+      if ($category['cid'] != $form_values['cid']) {
+        $contact_categories[$key]['selected'] = 0;
+      }
+  	}
   }
   $recipients = explode(',', $form_values['recipients']);
   foreach ($recipients as $key=>$recipient) {
@@ -233,15 +245,52 @@ function contact_admin_edit_submit($form
   }
   $form_values['recipients'] = implode(',', $recipients);
   if (arg(3) == 'add') {
-    db_query("INSERT INTO {contact} (category, recipients, reply, weight, selected) VALUES ('%s', '%s', '%s', %d, %d)", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected']);
+    // We create a unique cid
+    $cid = 0;
+    foreach ($contact_categories as $key=>$category) {
+      if ($category['cid'] > $cid) {
+        $cid = $category['cid'];
+      }
+  	}
+  	$cid++;
+    array_push(
+      $contact_categories,
+      array(
+        'cid' => $cid, 
+        'category' => $form_values['category'], 
+        'recipients' => $form_values['recipients'], 
+        'reply' => $form_values['reply'],
+        'weight' => $form_values['weight'],
+        'selected' => $form_values['selected'] 
+      )
+    );
+    variable_set('contact_categories', $contact_categories);
     drupal_set_message(t('Category %category has been added.', array('%category' => $form_values['category'])));
     watchdog('mail', t('Contact form: category %category added.', array('%category' => $form_values['category'])), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
 
   }
   else {
-    db_query("UPDATE {contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid = %d", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected'], $form_values['cid']);
-    drupal_set_message(t('Category %category has been updated.', array('%category' => $form_values['category'])));
-    watchdog('mail', t('Contact form: category %category updated.', array('%category' => $form_values['category'])), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
+    $category_exists = FALSE;
+  	foreach ($contact_categories as $key=>$category) {
+      if ($category['cid'] == $form_values['cid']) {
+        $category_exists = TRUE;
+      	$contact_categories[$key] = array(
+          'cid' => $form_values['cid'], 
+          'category' => $form_values['category'], 
+          'recipients' => $form_values['recipients'], 
+          'reply' => $form_values['reply'],
+          'weight' => $form_values['weight'],
+          'selected' => $form_values['selected'], 
+        );
+        variable_set('contact_categories', $contact_categories);
+        drupal_set_message(t('Category %category has been updated.', array('%category' => $form_values['category'])));
+        watchdog('mail', t('Contact form: category %category updated.', array('%category' => $form_values['category'])), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
+      }
+  	}
+  	if (!$category_exists) {
+      drupal_set_message(t('Category not found.'), 'error');
+    }
+
   }
 
   return 'admin/build/contact';
@@ -251,24 +300,31 @@ function contact_admin_edit_submit($form
  * Category delete page.
  */
 function contact_admin_delete($cid = NULL) {
-  if ($info = db_fetch_object(db_query("SELECT category FROM {contact} WHERE cid = %d", $cid))) {
-    $form['category'] = array('#type' => 'value',
-      '#value' => $info->category,
-    );
-
-    return confirm_form($form, t('Are you sure you want to delete %category?', array('%category' => $info->category)), 'admin/build/contact', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
-  }
-  else {
-    drupal_set_message(t('Category not found.'), 'error');
-    drupal_goto('admin/build/contact');
+  $contact_categories = variable_get('contact_categories', array());
+  foreach ($contact_categories as $key=>$category) {
+    if ($category['cid'] == $cid) {
+      $form['category'] = array(
+        '#type' => 'value',
+        '#value' => $category['category'],
+      );
+      return confirm_form($form, t('Are you sure you want to delete %category?', array('%category' => $category['category'])), 'admin/build/contact', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
+    }
   }
+  drupal_set_message(t('Category not found.'), 'error');
+  drupal_goto('admin/build/contact');
 }
 
 /**
  * Process category delete form submission.
  */
 function contact_admin_delete_submit($form_id, $form_values) {
-  db_query("DELETE FROM {contact} WHERE cid = %d", arg(4));
+  $contact_categories = variable_get('contact_categories', array());
+  foreach ($contact_categories as $key=>$category) {
+    if ($category['cid'] == arg(4)) {
+      unset($contact_categories[$key]);
+    }
+  }
+  variable_set('contact_categories', $contact_categories);
   drupal_set_message(t('Category %category has been deleted.', array('%category' => $form_values['category'])));
   watchdog('mail', t('Contact form: category %category deleted.', array('%category' => $form_values['category'])), WATCHDOG_NOTICE);
 
@@ -418,11 +474,11 @@ function contact_site_page() {
 function contact_mail_page() {
   global $user;
 
-  $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
-  while ($category = db_fetch_object($result)) {
-    $categories[$category->cid] = $category->category;
-    if ($category->selected) {
-      $default_category = $category->cid;
+  $contact_categories = variable_get('contact_categories', array());
+  foreach ($contact_categories as $category) {
+    $categories[$category['cid']] = $category['category'];
+    if ($category['selected']) {
+      $default_category = $category['cid'];
     }
   }
 
@@ -518,16 +574,21 @@ function contact_mail_page_submit($form_
   }
 
   // Load the category information:
-  $contact = db_fetch_object(db_query("SELECT * FROM {contact} WHERE cid = %d", $form_values['cid']));
+  $contact_categories = variable_get('contact_categories', array());
+  foreach ($contact_categories as $category) {
+    if ($category['cid'] == $form_values['cid']) {
+      $contact = $category;
+    }
+  }
 
   // Format the category:
-  $subject = t('[!category] !subject', array('!category' => $contact->category, '!subject' => $form_values['subject']));
+  $subject = t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $form_values['subject']));
 
   // Prepare the body:
   $body = implode("\n\n", $message);
 
   // Send the e-mail to the recipients:
-  drupal_mail('contact-page-mail', $contact->recipients, $subject, $body, $from);
+  drupal_mail('contact-page-mail', $contact['recipients'], $subject, $body, $from);
 
   // If the user requests it, send a copy.
   if ($form_values['copy']) {
@@ -535,13 +596,13 @@ function contact_mail_page_submit($form_
   }
 
   // Send an auto-reply if necessary:
-  if ($contact->reply) {
-    drupal_mail('contact-page-autoreply', $from, $subject, wordwrap($contact->reply), $contact->recipients);
+  if ($contact['reply']) {
+    drupal_mail('contact-page-autoreply', $from, $subject, wordwrap($contact['reply']), $contact['recipients']);
   }
 
   // Log the operation:
   flood_register_event('contact');
-  watchdog('mail', t('%name-from sent an e-mail regarding %category.', array('%name-from' => $form_values['name'] ." <$from>", '%category' => $contact->category)));
+  watchdog('mail', t('%name-from sent an e-mail regarding %category.', array('%name-from' => $form_values['name'] ." <$from>", '%category' => $contact['category'])));
 
   // Update user:
   drupal_set_message(t('Your message has been sent.'));
