You are here

function views_gantt_update in Views Gantt 7.2

Callback for task/project update when we change it in Gantt chart.

1 string reference to 'views_gantt_update'
views_gantt_menu in ./views_gantt.module
Implements hook_menu().

File

./views_gantt.module, line 136
Module file for Views Gantt

Code

function views_gantt_update($account = NULL) {
  $view_name = variable_get('views_gantt_view_name', NULL);

  // Show empty page in browser if request incorrect.
  if (!$view_name || empty($_POST['ids'])) {
    return NULL;
  }
  $data = $_POST;
  $id = $data['ids'];
  $style_options = views_gantt_get_style_options($view_name);
  switch ($_GET['gantt_mode']) {
    case 'tasks':
      if (isset($data[$id . '_start_date'])) {
        $fields = array(
          'date_field' => $data[$id . '_start_date'],
          'end_date_field' => $data[$id . '_end_date'],
          'progress_field' => $data[$id . '_progress'] * 100,
        );
        $node = node_load($id);
      }
      break;
    case 'links':
      if ($data[$id . '_!nativeeditor_status'] != 'deleted') {
        $source = $data[$id . '_source'];
        $target = $data[$id . '_target'];
      }
      else {
        list($source, $target) = explode('_', $id);
        $source = NULL;
      }
      $fields = array(
        'predecessor_id_field' => $source,
      );
      $node = node_load($target);
      break;
  }
  if (!empty($node) && views_gantt_update_access($node, $account)) {
    views_gantt_update_node($node, $fields, $style_options);
    $response_type = 'updated';
  }
  else {
    $response_type = 'error';
  }
  $xml = new SimpleXMLElement("<data><action type='{$response_type}' sid='{$id}' tid='{$id}' /></data>");
  drupal_add_http_header('Content-Type', 'text/xml');
  print $xml
    ->asXML();
  drupal_exit();
}