function reorder_categories() { global $db, $template; $prev_cat_id = (int) request_var('prev', 0); $next_cat_id = (int) request_var('next', 0); $this_cat_id = (int) request_var('cat', 0); $c_move_type = request_var('move', ''); if ( ($c_move_type == 'up' && !$prev_cat_id) || ($c_move_type == 'down' && !$next_cat_id) || !$this_cat_id ) { return $this->categories_view(); } $sql = 'SELECT c.cat_id, c.cat_order FROM (' . AWARDS_CATS_TABLE . ' c) WHERE c.cat_id IN (' . ( ($c_move_type == 'up') ? $prev_cat_id : $next_cat_id ) . ', ' . (int) $this_cat_id . ')'; $result = $db->sql_query($sql); $this_cat_data = $alt_cat_data = false; while ( $row = $db->sql_fetchrow($result) ) { if ( $row['cat_id'] == $this_cat_id ) { $this_cat_data = $row; } else { $alt_cat_data = $row; } } $db->sql_freeresult($result); if ( !$this_cat_data || !$alt_cat_data ) { trigger_error('L_ERROR_SELECT_CAT_DATA'); } $db->sql_query('UPDATE ' . AWARDS_CATS_TABLE . ' SET cat_order = ' . (int) $alt_cat_data['cat_order'] . ' WHERE cat_id = ' . (int) $this_cat_data['cat_id']); $db->sql_query('UPDATE ' . AWARDS_CATS_TABLE . ' SET cat_order = ' . (int) $this_cat_data['cat_order'] . ' WHERE cat_id = ' . (int) $alt_cat_data['cat_id']); return $this->categories_view(); }