You are here

function _jeditable_ajax_save in jEditable inline content editing 6.2

Same name and namespace in other branches
  1. 6 jeditable.module \_jeditable_ajax_save()
  2. 7 jeditable.module \_jeditable_ajax_save()

Helper function to save a value using the jeditable callback.

Return value

The value of the field after it has been saved and re-read.

1 string reference to '_jeditable_ajax_save'
jeditable_menu in ./jeditable.module
Implements hook_menu().

File

./jeditable.module, line 170

Code

function _jeditable_ajax_save() {

  // Retrieve the values needed from the post to this page
  $array = explode('-', filter_xss($_POST['id']));
  list($type, $id, $field_name) = $array;
  $value = check_plain($_POST['value']);
  switch ($type) {
    case 'node':
      $node = node_load($id);

      // Check to see that current user has update permissions on the node.
      if (!node_access('update', $node)) {

        // This is the value that will be returned, but no updates made.
        $value = 'access denied';
      }
      else {
        $node->{$field_name} = $value;
        node_save($node);
      }
      break;
    case 'cck':
      $node = node_load($id);

      // Check to see that current user has update permissions on the node
      if (!node_access('update', $node)) {

        // This is the value that will be returned, but no updates made
        $value = 'access denied';
      }
      else {
        $field = content_fields($field_name, $node->type);
        switch ($field['type']) {
          case 'nodereference':
            $value = _jeditable_save_nodereference_field($node, $field, $value);
            break;
          case 'userreference':
            $value = _jeditable_save_userreference_field($node, $field, $value);
            break;
          case 'datetime':
            $value = _jeditable_save_date_field($node, $field, $value);
            break;
          default:
            $value = _jeditable_save_other_field($node, $field, $value);
            break;
        }
      }
      break;
    case 'user':

      /** should be implemented if user reference field is implemented **/
      $user = user_load(array(
        'uid' => $id,
      ));
      $user->{$field_name} = $value;
      user_save($user);
      break;
    case 'workflow':
      $node = node_load($id);
      $value = _jeditable_workflow_save($node, $value);
      break;
  }
  print $value;
  exit;
}