You are here

function _jeditable_ajax_save in jEditable inline content editing 6

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

Helper function to save a value using the jeditable callback

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

File

./jeditable.module, line 192
jeditable.module

Code

function _jeditable_ajax_save() {

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

        // check to see that current user has update permissions on the node
        $value = 'access denied';

        // this is the value that will be returned, but no updates made
      }
      else {
        $node->{$field_name} = $value;
        $node->revision = variable_get('jeditable_create_new_revisions', false);
        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;
        }
        $node->revision = variable_get('jeditable_create_new_revisions', false);
      }
      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;
}