Index: customdestination.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/customdestination/customdestination.install,v
retrieving revision 1.1
diff -u -r1.1 customdestination.install
--- customdestination.install	23 May 2008 18:12:01 -0000	1.1
+++ customdestination.install	7 Feb 2010 08:17:53 -0000
@@ -1,4 +1,14 @@
 <?php
+// $Id$
+
+/**
+ * @file
+ * Installation of Custom Destination.
+ */
+
+/**
+ * Implementation of hook_schema().
+ */
 function customdestination_schema() {
   $schema['customdestination'] = array(
     'description' => t('The base table for customdestinations.'),
@@ -15,18 +25,45 @@
         'length' => 255,
         'not null' => TRUE,
         'default' => ''),
-      ),
+      'clear_dsm' => array(
+        'description' => t('Status on whether or not to clear messages when redirecting.'),
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 0),
+    ),
     'primary key' => array('fid'),
   );
   return $schema;
 }
 
+/**
+ * Implementation of hook_install().
+ */
 function customdestination_install() {
   // Create my tables.
   drupal_install_schema('customdestination');
 }
 
+/**
+ * Implementation of hook_uninstall().
+ */
 function customdestination_uninstall() {
   // Drop my tables.
   drupal_uninstall_schema('customdestination');
 }
+
+/**
+ * Add the clear_dsm field.
+ */
+function customdestination_update_6000() {
+  $ret = array();
+  db_add_field($ret, 'customdestination', 'clear_dsm', array(
+    'description' => t('Status on whether or not to clear messages when redirecting.'),
+    'type' => 'int',
+    'size' => 'tiny',
+    'not null' => TRUE,
+    'default' => 0)
+  );
+  return $ret;
+}
Index: customdestination.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/customdestination/customdestination.module,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 customdestination.module
--- customdestination.module	7 Jan 2009 20:55:48 -0000	1.1.2.5
+++ customdestination.module	7 Feb 2010 08:17:53 -0000
@@ -2,6 +2,11 @@
 // $Id: customdestination.module,v 1.1.2.5 2009/01/07 20:55:48 flevour Exp $
 
 /**
+ * @file
+ * Redirects specific forms to an alternate location.
+ */
+
+/**
  * Implementation of hook_help().
  */
 function customdestination_help($path, $arg) {
@@ -23,7 +28,7 @@
 
 
 /**
- * Implementation of hook_menu
+ * Implementation of hook_menu().
  */
 function customdestination_menu() {
   $items['admin/settings/customdestination'] = array(
@@ -41,20 +46,20 @@
     'title' => 'Add custom destination',
     'description' => 'Add a new custom destination',
     'page callback' => 'customdestination_edit',
-    'access arguments' => array('access administration pages'),
+    'access arguments' => array('administer custom destination'),
     'type' => MENU_LOCAL_TASK,
   );
   $items['admin/settings/customdestination/edit'] = array(
     'title' => 'Edit',
     'page callback' => 'customdestination_edit',
-    'access arguments' => array('access administration pages'),
+    'access arguments' => array('administer custom destination'),
     'type' => MENU_CALLBACK,
   );
   $items['admin/settings/customdestination/delete'] = array(
     'title' => 'Delete custom destination',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('customdestination_delete_confirm'),
-    'access arguments' => array('access administration pages'),
+    'access arguments' => array('administer custom destination'),
     'type' => MENU_CALLBACK,
   );
 
@@ -84,7 +89,7 @@
  * @see customdestination_form_validate()
  * @see customdestination_form_submit()
  */
-function customdestination_form(&$form_state, $edit = array('fid' => '', 'dst' => '')) {
+function customdestination_form(&$form_state, $edit = array('fid' => '', 'dst' => '', 'clear_dsm' => 0)) {
   $form['fid'] = array(
     '#type' => 'textfield',
     '#title' => t('Form ID'),
@@ -101,6 +106,13 @@
     '#description' => t("The destination path to redirect to upon form submission. No leading and trailing slash."),
     '#required' => TRUE,
   );
+  $form['clear_dsm'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Wipe messages on destination'),
+    '#default_value' => $edit['clear_dsm'],
+    '#required' => FALSE,
+    '#description' => t('Suppress any status, warning, or error messages that would otherwise display on the destination page.')
+  );
   if ($edit['fid']) {
     // use hidden value here if can't usere INSERT OR UPDATE
     $form['submit'] = array('#type' => 'submit', '#value' => t('Update custom destination'));
@@ -113,18 +125,7 @@
 }
 
 /**
- * Save a new custom destination to the database.
- */
-function customdestination_form_submit($form, &$form_state) {
-  customdestination_save($form_state['values']['fid'], $form_state['values']['dst']);
-
-  drupal_set_message(t('The custom destination has been saved.'));
-  $form_state['redirect'] = 'admin/settings/customdestination';
-  return;
-}
-
-/**
- * Verify that a new URL alias is valid
+ * Verify that a new URL alias is valid.
  */
 function customdestination_form_validate($form, &$form_state) {
   $fid = $form_state['values']['fid'];
@@ -147,21 +148,33 @@
 }
 
 /**
- * Checks whether a form exists or not
+ * Save a new custom destination to the database.
+ */
+function customdestination_form_submit($form, &$form_state) {
+  customdestination_save($form_state['values']['fid'], $form_state['values']['dst'], $form_state['values']['clear_dsm']);
+
+  drupal_set_message(t('The custom destination has been saved.'));
+  $form_state['redirect'] = 'admin/settings/customdestination';
+  return;
+}
+
+/**
+ * Checks whether a form exists or not.
+ *
  * @param $form_id
- *   The form id to validate
+ *   The form id to validate.
  * @return
- *   Returns TRUE for success, FALSE if $form_id doesn't exist
+ *   Returns TRUE for success, FALSE if $form_id doesn't exist.
  */
 function _customdestination_form_exists($form_id) {
   // logic borrowed from drupal_retrieve_form code
   // seems like at the moment customdestination_form__validate() is called, the other modules
   // are not loaded, hence function_exists() fails miserably
-  // e.g.: contact_mail_page() is a function defining Contact form, but checking if it exists 
+  // e.g.: contact_mail_page() is a function defining Contact form, but checking if it exists
   // from inside a validate hook returns FALSE
-  
+
   return TRUE; // returning TRUE while issue above is fixed
-  
+
   static $forms;
   if (function_exists($form_id)) {
     return TRUE;
@@ -170,13 +183,13 @@
     if (!isset($forms) || !isset($forms[$form_id])) {
       $forms = module_invoke_all('forms', $form_id, array());
     }
-    if (isset($forms[$form_id]) && 
-        isset($forms[$form_id]['callback']) && 
+    if (isset($forms[$form_id]) &&
+        isset($forms[$form_id]['callback']) &&
         function_exists($forms[$form_id]['callback'])) {
       return TRUE;
     }
   }
-  
+
   return FALSE;
 }
 
@@ -195,7 +208,7 @@
 }
 
 /**
- * Execute URL alias deletion
+ * Execute URL alias deletion.
  */
 function customdestination_delete_confirm_submit($form, &$form_state) {
   if ($form_state['values']['confirm']) {
@@ -209,7 +222,7 @@
  * Fetch a specific custom destination from the database.
  */
 function customdestination_load($fid) {
-  return db_fetch_array(db_query("SELECT * FROM {customdestination} WHERE fid = '%s'", $fid));
+  return db_fetch_array(db_query_range("SELECT * FROM {customdestination} WHERE fid = '%s'", $fid, 0, 1));
 }
 
 /**
@@ -222,21 +235,22 @@
 /**
  * Save a custom destination to the database.
  */
-function customdestination_save($fid, $dst) {
+function customdestination_save($fid, $dst, $clear_dsm) {
   $customdestination = customdestination_load($fid);
   if (!empty($customdestination)) {
     // There is already a custom destination defined for this fid
     // Update the entry with new dst
-    db_query("UPDATE {customdestination} SET dst = '%s' WHERE fid = '%s'", $dst, $fid);
+    db_query("UPDATE {customdestination} SET dst = '%s', clear_dsm = %d WHERE fid = '%s'", $dst, $clear_dsm, $fid);
   }
   else {
     // A new custom destination. Add it to the database.
-    db_query("INSERT INTO {customdestination} (fid, dst) VALUES ('%s', '%s')", $fid, $dst);
+    db_query("INSERT INTO {customdestination} (fid, dst, clear_dsm) VALUES ('%s', '%s', %d)", $fid, $dst, $clear_dsm);
   }
 }
 
 /**
  * Return a listing of all defined URL aliases.
+ *
  * When filter key passed, perform a standard search on the given key,
  * and return the list of matching URL aliases.
  */
@@ -246,6 +260,7 @@
   $header = array(
     array('data' => t('Form ID'), 'field' => 'fid', 'sort' => 'asc'),
     array('data' => t('Destination'), 'field' => 'dst'),
+    array('data' => t('Clear messages'), 'field' => 'clear_dsm'),
     array('data' => t('Operations'), 'colspan' => '2')
   );
 
@@ -255,12 +270,12 @@
   $rows = array();
   $destination = drupal_get_destination();
   while ($data = db_fetch_object($result)) {
-    $row = array(check_plain($data->fid), check_plain($data->dst), l(t('edit'), "admin/settings/customdestination/edit/$data->fid", array('query' => $destination)), l(t('delete'), "admin/settings/customdestination/delete/$data->fid", array('query' => $destination)));
+    $row = array(check_plain($data->fid), check_plain($data->dst), $data->clear_dsm ? t('On') : t('Off'), l(t('edit'), "admin/settings/customdestination/edit/$data->fid", array('query' => $destination)), l(t('delete'), "admin/settings/customdestination/delete/$data->fid", array('query' => $destination)));
     $rows[] = $row;
   }
 
   if (empty($rows)) {
-    $rows[] = array(array('data' => t('No custom destinations found.'), 'colspan' => 4));
+    $rows[] = array(array('data' => t('No custom destinations found.'), 'colspan' => 5));
   }
 
   $output .= theme('table', $header, $rows);
@@ -270,12 +285,26 @@
 }
 
 /**
- * The core of the module, form_alter #redirect value with custom destination
+ * The core of the module, form_alter #redirect value with custom destination.
  */
 function customdestination_form_alter(&$form, $form_state, $form_id) {
   $customdestination = customdestination_load($form_id);
   if (!empty($customdestination)) {
     $form['#redirect'] = $customdestination['dst'];
+    if ($customdestination['clear_dsm'] > 0) {
+      $form['#submit'][] = 'customdestination_clear_dsm';
+    }
   }
 }
 
+function customdestination_clear_dsm($form = array(), &$form_state = array()) {
+  static $form_set;
+  if (!empty($form) || !empty($form_set)) {
+    $form_set = TRUE;
+    $_SESSION['messages'] = array();
+  }
+}
+
+function customdestination_exit() {
+  customdestination_clear_dsm();
+}
