You are here

function homebox_save_user_color in Homebox 6

Saves color for a box Always an Ajax call

Return value

A Boolean JSON formated

1 string reference to 'homebox_save_user_color'
homebox_menu in ./homebox.module
Implementation of hook_menu().

File

./homebox.module, line 642
Home box main file, takes care of global functions settings constants, etc.

Code

function homebox_save_user_color() {
  global $user;
  if ($user->uid == 0) {
    drupal_json(TRUE);
    exit;
  }

  // Retrieve values from POST
  $bid = (int) trim($_POST['box']);
  $pid = (int) trim($_POST['pid']);
  $color = trim($_POST['color']);

  // Build a block object
  $block = new stdClass();
  $block->uid = $user->uid;
  $block->bid = $bid;
  $block->pid = $pid;
  $block->color = $color;

  // Update record in the database
  if (drupal_write_record('homebox_users', $block, array(
    'uid',
    'bid',
    'pid',
  )) != FALSE) {
    drupal_json(TRUE);
  }
  else {
    drupal_json(FALSE);
  }
  exit;
}