You are here

function oa_sitemap_update_callback in Open Atrium Sitemap 7.2

Ajax Callback for updating fields in a space from the sitemap

Parameters

$node:

1 string reference to 'oa_sitemap_update_callback'
oa_sitemap_menu in ./oa_sitemap.module
Implements hook_menu().

File

./oa_sitemap.module, line 105

Code

function oa_sitemap_update_callback($node) {
  if (!node_access('update', $node) || empty($_REQUEST['token']) || !drupal_valid_token($_REQUEST['token'], 'sitemap-node-' . $node->nid)) {
    ajax_deliver(MENU_ACCESS_DENIED);
    return;
  }
  $new_node = $_POST['node'];

  // If empty, save all fields, else only update specified fields.
  $update_fields = !empty($_POST['save']) ? $_POST['save'] : array();
  $updated = FALSE;
  if (!$update_fields || in_array('title', $update_fields)) {
    _oa_sitemap_update_field($node, 'title', $new_node['title'], $updated);
  }
  if ($new_node['type'] == OA_SPACE_TYPE) {

    // updating a space node
    if (!$update_fields || in_array('oa_parent_space', $update_fields)) {
      _oa_sitemap_update_field($node, 'oa_parent_space', $new_node['parent_id'], $updated, 'target_id');
    }
  }
  else {

    // updating a section node
    if (!$update_fields || in_array('og_group_ref', $update_fields)) {
      _oa_sitemap_update_field($node, 'og_group_ref', $new_node['parent_id'], $updated, 'target_id');
    }
  }
  if ($updated) {
    node_save($node);

    // If a batch was set, we need to redirect to the batch and then back to
    // this space in the sitemap.
    $batch = batch_get();
    if (!empty($batch)) {
      batch_process('sitemap/' . $new_node['parent_id'], 'batch', '_oa_sitemap_batch_goto');
      $batch_redirect = _oa_sitemap_batch_goto();

      // Tell the Javascript app that we need to redirect.
      drupal_json_output(array(
        array(
          'command' => 'redirect',
          'url' => url($batch_redirect[0], array(
            'absolute' => TRUE,
          ) + $batch_redirect[1]),
        ),
      ));
    }
  }
  return TRUE;
}