commit 2f75d949fdc9b17b876642977c22e94b9428c55f
Author: fago <nuppla@gmx.at>
Date:   Mon Oct 27 01:21:02 2014 +0100

    #ORD-67: Added and improved redhen unarchiving patch.

diff --git a/web/sites/all/modules/contrib/redhen/modules/redhen_contact/includes/redhen_contact.forms.inc b/web/sites/all/modules/contrib/redhen/modules/redhen_contact/includes/redhen_contact.forms.inc
index 3c2ef9f..ec1e46f 100644
--- a/web/sites/all/modules/contrib/redhen/modules/redhen_contact/includes/redhen_contact.forms.inc
+++ b/web/sites/all/modules/contrib/redhen/modules/redhen_contact/includes/redhen_contact.forms.inc
@@ -204,7 +204,7 @@ function redhen_contact_contact_archive_form($form, &$form_state, $contact) {
   $form = confirm_form($form,
     t('Are you sure you want to archive %label?', array('%label' => $full_name)),
     entity_uri('redhen_contact', $contact),
-    '<p>' . t('Archiving this contact cannot be undone.') . '</p>',
+    '<p>' . t('Archive this contact.') . '</p>',
     t('Archive'),
     t('Cancel'),
     'confirm'
@@ -233,6 +233,56 @@ function redhen_contact_contact_archive_form_submit($form, &$form_state) {
 }
 
 /**
+ * Form callback: confirmation form for unarchiving a contact.
+ *
+ * @param $contact
+ *   The contact object to be activated.
+ *
+ * @see confirm_form()
+ */
+function redhen_contact_contact_unarchive_form($form, &$form_state, $contact) {
+  $form_state['redhen_contact'] = $contact;
+
+  // Ensure this include file is loaded when the form is rebuilt from the cache.
+  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'redhen_contact') . '/includes/redhen_contact.forms.inc';
+
+  $form['#submit'][] = 'redhen_contact_contact_unarchive_form_submit';
+
+  $wrapper = entity_metadata_wrapper('redhen_contact', $contact);
+  $full_name = $wrapper->full_name->value();
+
+  $form = confirm_form($form,
+      t('Are you sure you want to unarchive %label?', array('%label' => $full_name)),
+      entity_uri('redhen_contact', $contact),
+      '<p>' . t('Activate this contact.') . '</p>',
+      t('Unarchive'),
+      t('Cancel'),
+      'confirm'
+  );
+
+  return $form;
+}
+
+/**
+ * Submit callback for redhen_contact_contact_archive_form().
+ */
+function redhen_contact_contact_unarchive_form_submit($form, &$form_state) {
+  $contact = $form_state['redhen_contact'];
+
+  $wrapper = entity_metadata_wrapper('redhen_contact', $contact);
+  $full_name = $wrapper->full_name->value();
+
+  if ($contact->setState(REDHEN_STATE_ACTIVE)) {
+    drupal_set_message(t('%label has been unarchived.', array('%label' => $full_name)));
+  }
+  else {
+    drupal_set_message(t('%label was not unarchived.', array('%label' => $full_name)), WATCHDOG_ERROR);
+  }
+  $url = entity_uri($contact->entityType(), $contact);
+  $form_state['redirect'] = $url['path'];
+}
+
+/**
  * Return a form for managing contact/user links.
  *
  * @param $form
diff --git a/web/sites/all/modules/contrib/redhen/modules/redhen_contact/redhen_contact.module b/web/sites/all/modules/contrib/redhen/modules/redhen_contact/redhen_contact.module
index 37fd1a6..7d028fe 100644
--- a/web/sites/all/modules/contrib/redhen/modules/redhen_contact/redhen_contact.module
+++ b/web/sites/all/modules/contrib/redhen/modules/redhen_contact/redhen_contact.module
@@ -273,6 +273,17 @@ function redhen_contact_menu() {
     'weight' => 5,
   );
 
+  $items['redhen/contact/%redhen_contact/view/unarchive'] = array(
+      'title' => 'Unarchive',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('redhen_contact_contact_unarchive_form', 2),
+      'access callback' => 'redhen_contact_access',
+      'access arguments' => array('unarchive', 2),
+      'type' => MENU_LOCAL_TASK,
+      'file' => 'includes/redhen_contact.forms.inc',
+      'weight' => 4,
+  );
+
   if (module_exists('devel')) {
     $items['redhen/contact/%redhen_contact/devel'] = array(
       'title' => 'Devel',
@@ -423,8 +434,11 @@ function redhen_contact_access($op, $contact = NULL, $account = NULL) {
   global $user;
   $account = isset($account) ? $account : $user;
 
-  // If it's already archived, no one can archive it again.
-  if (($op == 'archive') && ($contact->redhen_state == REDHEN_STATE_ARCHIVED)) {
+  if ($op == 'archive' && $contact->redhen_state == REDHEN_STATE_ARCHIVED) {
+    return FALSE;
+  }
+
+  if ($op == 'unarchive' && $contact->redhen_state == REDHEN_STATE_ACTIVE) {
     return FALSE;
   }
 
@@ -456,6 +470,10 @@ function redhen_contact_access($op, $contact = NULL, $account = NULL) {
     return TRUE;
   }
 
+  if ($op == 'unarchive' && user_access('manage redhen contacts', $account) && ($contact->redhen_state != REDHEN_STATE_ACTIVE)) {
+    return TRUE;
+  }
+
   if ($op == 'create' && user_access('manage redhen contacts', $account)) {
     return TRUE;
   }
diff --git a/web/sites/all/modules/contrib/redhen/modules/redhen_org/includes/redhen_org.forms.inc b/web/sites/all/modules/contrib/redhen/modules/redhen_org/includes/redhen_org.forms.inc
index 61f3468..d26bd0f 100644
--- a/web/sites/all/modules/contrib/redhen/modules/redhen_org/includes/redhen_org.forms.inc
+++ b/web/sites/all/modules/contrib/redhen/modules/redhen_org/includes/redhen_org.forms.inc
@@ -140,7 +140,7 @@ function redhen_org_org_archive_form($form, &$form_state, $org) {
   $form = confirm_form($form,
     t('Are you sure you want to archive %label?', array('%label' => $org->label)),
     entity_uri('redhen_org', $org),
-    '<p>' . t('Archiving this organization cannot be undone.') . '</p>',
+    '<p>' . t('Archive this organization.') . '</p>',
     t('Archive'),
     t('Cancel'),
     'confirm'
@@ -166,6 +166,47 @@ function redhen_org_org_archive_form_submit($form, &$form_state) {
 }
 
 /**
+ * Form callback: confirmation form for unarchiving an organization.
+ *
+ * @param $org
+ *   The org object to be activated.
+ *
+ * @see confirm_form()
+ */
+function redhen_org_org_unarchive_form($form, &$form_state, $org) {
+  $form_state['redhen_org'] = $org;
+
+  $form['#submit'][] = 'redhen_org_org_unarchive_form_submit';
+
+  $form = confirm_form($form,
+    t('Are you sure you want to unarchive %label?', array('%label' => $org->label())),
+    entity_uri('redhen_org', $org),
+    '<p>' . t('Activate this organization.') . '</p>',
+    t('Unarchive'),
+    t('Cancel'),
+    'confirm'
+  );
+
+  return $form;
+}
+
+/**
+ * Submit callback for redhen_org_org_unarchive_form().
+ */
+function redhen_org_org_unarchive_form_submit($form, &$form_state) {
+  $org = $form_state['redhen_org'];
+
+  if ($org->setState(REDHEN_STATE_ACTIVE)) {
+    drupal_set_message(t('%label has been unarchived.', array('%label' => $org->label())));
+  }
+  else {
+    drupal_set_message(t('%label was not unarchived.', array('%label' => $org->label())), WATCHDOG_ERROR);
+  }
+  $url = entity_uri($org->entityType(), $org);
+  $form_state['redirect'] = $url['path'];
+}
+
+/**
  * Form callback: confirmation form for changing the primary contact.
  *
  * @see confirm_form()
diff --git a/web/sites/all/modules/contrib/redhen/modules/redhen_org/redhen_org.module b/web/sites/all/modules/contrib/redhen/modules/redhen_org/redhen_org.module
index 10da8f9..d8cf745 100644
--- a/web/sites/all/modules/contrib/redhen/modules/redhen_org/redhen_org.module
+++ b/web/sites/all/modules/contrib/redhen/modules/redhen_org/redhen_org.module
@@ -183,6 +183,15 @@ function redhen_org_menu() {
     'type' => MENU_LOCAL_TASK,
     'weight' => 9,
   );
+  $items['redhen/org/%redhen_org/view/unarchive'] = array(
+    'title' => 'Unarchive',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('redhen_org_org_unarchive_form', 2),
+    'access callback' => 'redhen_org_access',
+    'access arguments' => array('unarchive', 2),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 4,
+  );
   $items['redhen/org/%redhen_org/revisions'] = array(
     'title' => 'Revisions',
     'type' => MENU_LOCAL_TASK,
@@ -413,6 +422,10 @@ function redhen_org_access($op, $org = NULL, $account = NULL) {
     return FALSE;
   }
 
+  if ($op == 'unarchive' && $org->redhen_state == REDHEN_STATE_ACTIVE) {
+    return FALSE;
+  }
+
   if (user_access('administer redhen orgs', $account)) {
     return TRUE;
   }
@@ -436,7 +449,11 @@ function redhen_org_access($op, $org = NULL, $account = NULL) {
     return TRUE;
   }
 
-  if (($op == 'edit' || $op == 'archive') && user_access('manage redhen orgs', $account) && ($org->redhen_state != REDHEN_STATE_ARCHIVED)) {
+  if (($op == 'edit' || $op == 'archive' || $op == 'unarchive') && user_access('manage redhen orgs', $account) && ($org->redhen_state != REDHEN_STATE_ARCHIVED)) {
+    return TRUE;
+  }
+
+  if ($op == 'unarchive' && user_access('manage redhen orgs', $account) && ($org->redhen_state != REDHEN_STATE_ACTIVE)) {
     return TRUE;
   }
 
