You are here

function homebox_save_user_settings in Homebox 6

Saves user settings i.e. sorting/hidding boxes Always an Ajax call

Return value

A Boolean JSON formated

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

File

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

Code

function homebox_save_user_settings() {
  global $user;
  if ($user->uid == 0) {
    drupal_json(TRUE);
    exit;
  }
  $pid = (int) trim($_POST['pid']);
  $order = trim($_POST['order']);
  $blocks = explode(" ", $order);
  for ($i = 0; $i < count($blocks); $i++) {
    $array = explode(':', $blocks[$i]);
    $regions[$array[0]][$i]['bid'] = (int) $array[1];
    $regions[$array[0]][$i]['status'] = (int) $array[2];
    $regions[$array[0]][$i]['weight'] = $i;
  }
  foreach ($regions as $key => $column) {
    $region = (int) $key;
    foreach ($column as $k => $b) {
      $block = new stdClass();
      $block->uid = $user->uid;
      $block->bid = $b['bid'];
      $block->pid = $pid;
      $block->region = $region;
      $block->weight = $b['weight'];
      $block->status = $b['status'];
      drupal_write_record('homebox_users', $block, array(
        'uid',
        'bid',
        'pid',
      ));
    }
  }
  drupal_json(TRUE);
  exit;
}