? contact_full.patch
? files
Index: database/database.mysql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.mysql,v
retrieving revision 1.195
diff -u -r1.195 database.mysql
--- database/database.mysql	30 Aug 2005 15:19:20 -0000	1.195
+++ database/database.mysql	9 Sep 2005 19:02:01 -0000
@@ -203,10 +203,12 @@
 --
 
 CREATE TABLE contact (
+  cid int(11) NOT NULL,
   category varchar(255) NOT NULL default '',
   recipients longtext NOT NULL default '',
   reply longtext NOT NULL default '',
-  PRIMARY KEY (category)
+  PRIMARY KEY (cid),
+  UNIQUE KEY category (category)
 ) TYPE=MyISAM;
 
 --
Index: database/database.pgsql
===================================================================
RCS file: /cvs/drupal/drupal/database/database.pgsql,v
retrieving revision 1.134
diff -u -r1.134 database.pgsql
--- database/database.pgsql	30 Aug 2005 15:19:20 -0000	1.134
+++ database/database.pgsql	9 Sep 2005 19:02:08 -0000
@@ -199,10 +199,12 @@
 --
 
 CREATE TABLE contact (
+  cid int NOT NULL,
   category varchar(255) NOT NULL default '',
   recipients text NOT NULL default '',
   reply text NOT NULL default '',
-  PRIMARY KEY (category)
+  PRIMARY KEY (cid),
+  UNIQUE (category)
 );
 
 --
Index: database/updates.inc
===================================================================
RCS file: /cvs/drupal/drupal/database/updates.inc,v
retrieving revision 1.131
diff -u -r1.131 updates.inc
--- database/updates.inc	8 Sep 2005 19:17:34 -0000	1.131
+++ database/updates.inc	9 Sep 2005 19:13:38 -0000
@@ -45,7 +45,8 @@
   "2005-08-08" => "update_144",
   "2005-08-15" => "update_145",
   "2005-08-25" => "update_146",
-  "2005-09-07" => "update_147"
+  "2005-09-07" => "update_147",
+  "2005-09-08" => "update_148"
 );
 
 function update_110() {
@@ -790,6 +791,19 @@
   return $ret;
 }
 
+function update_148() {
+  $ret = array();
+
+  if ($GLOBALS['db_type'] == 'mysql') {
+    $ret[] = update_sql("ALTER TABLE {contact} DROP PRIMARY KEY");
+    $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int(11) NOT NULL PRIMARY KEY");
+    $ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE KEY category (category)");
+  } else { //pgsql
+    $ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT {contact}_pkey category");
+    $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int PRIMARY KEY");
+    $ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE (category)");
+  }
+
 function update_sql($sql) {
   $edit = $_POST["edit"];
   $result = db_query($sql);
Index: modules/contact.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact.module,v
retrieving revision 1.22
diff -u -r1.22 contact.module
--- modules/contact.module	25 Aug 2005 21:14:16 -0000	1.22
+++ modules/contact.module	9 Sep 2005 19:02:26 -0000
@@ -166,7 +166,7 @@
   }
 }
 
-function contact_admin_edit($category = NULL) {
+function contact_admin_edit($cid = NULL) {
   if (isset($_POST['edit'])) {
     $edit = $_POST['edit'];
 
@@ -178,13 +178,14 @@
     }
 
     if (!form_get_errors()) {
-      db_query("DELETE FROM {contact} WHERE category = '%s'", $category);
-      db_query("INSERT INTO {contact} (category, recipients, reply) VALUES ('%s', '%s', '%s')", $edit['category'], $edit['recipients'], $edit['reply']);
+      db_query("DELETE FROM {contact} WHERE cid = '%d'", $cid);
+      db_query("INSERT INTO {contact} (cid, category, recipients, reply) VALUES ('%d', '%s', '%s', '%s')", db_next_id("contact"), $edit['category'], $edit['recipients'], $edit['reply']);
       drupal_goto('admin/contact');
     }
   }
   else {
-    $category           = db_fetch_object(db_query("SELECT * FROM {contact} WHERE category = '%s'", $category));
+    $category           = db_fetch_object(db_query("SELECT * FROM {contact} WHERE cid = '%d'", $cid));
+    $edit['cid'] = $category->cid;
     $edit['category']   = $category->category;
     $edit['recipients'] = $category->recipients;
     $edit['reply']      = $category->reply;
@@ -198,27 +199,28 @@
   return form($form);
 }
 
-function contact_admin_delete($category) {
+function contact_admin_delete($cid) {
+  $category = db_fetch_object(db_query("SELECT cid, category FROM {contact} WHERE cid = '%d'",$cid));
   if ($_POST['op'] != t('Delete')) {
     return theme('confirm',
-                  t('Are you sure you want to delete %category?', array('%category' => theme('placeholder', $category))),
-                  'admin/contact/delete/'. $category,
+                  t('Are you sure you want to delete %category?', array('%category' => theme('placeholder', $category->category))),
+                  'admin/contact/delete/'. $category->cid,
                   t('This action cannot be undone.'),
                   t('Delete'),
                   t('Cancel'));
   }
   else {
-    db_query("DELETE FROM {contact} WHERE category = '%s'", $category);
+    db_query("DELETE FROM {contact} WHERE cid = '%d'", $cid);
     drupal_goto('admin/contact');
   }
 }
 
 
 function contact_admin() {
-  $result = db_query('SELECT category, recipients FROM {contact} ORDER BY category');
+  $result = db_query('SELECT cid, category, recipients FROM {contact}');
   $rows = array();
   while ($category = db_fetch_object($result)) {
-    $rows[] = array($category->category, $category->recipients, l(t('edit'), 'admin/contact/edit/'. urlencode($category->category)), l(t('delete'), 'admin/contact/delete/'. urlencode($category->category)));
+    $rows[] = array($category->category, $category->recipients, l(t('edit'), 'admin/contact/edit/'. urlencode($category->cid)), l(t('delete'), 'admin/contact/delete/'. urlencode($category->cid) . '/'));
   }
   $header = array(t('Category'), t('Recipients'), array('data' => t('Operations'), 'colspan' => 2));
   return theme('table', $header, $rows);
@@ -312,7 +314,7 @@
       $edit['mail'] = $user->mail;
     }
 
-    $result = db_query('SELECT category FROM {contact} ORDER BY category');
+    $result = db_query('SELECT cid, category FROM {contact}');
     $categories[] = '--';
     while ($category = db_fetch_object($result)) {
       $categories[$category->category] = $category->category;