/**
 * promotion_dialog_markup()
 */
function promotion_dialog_markup($href_this, $current_player, $row, $col, $history)
{
    $current_player = !$current_player;
    $player_pieces = get_player_pieces($current_player);
    $field = rowcol_to_field($row, $col);
    $ret = "<ul class=\"popup\">\n";
    $field_code = encode_field($field);
    $code_r = '(' . $field_code . $player_pieces[PIECE_ROOK] . ')';
    $code_k = '(' . $field_code . $player_pieces[PIECE_KNIGHT] . ')';
    $code_b = '(' . $field_code . $player_pieces[PIECE_BISHOP] . ')';
    $code_q = '(' . $field_code . $player_pieces[PIECE_QUEEN] . ')';
    if ($current_player == WHITES_MOVE) {
        $color = GET_WHITE;
        $next_player = GET_BLACK;
    } else {
        $color = GET_BLACK;
        $next_player = GET_WHITE;
    }
    $t_color = ucfirst($color);
    $href_this = update_href($href_this, GET_PLAYER, $next_player);
    $href_r = update_href($href_this, GET_HISTORY, $history . $code_r);
    $href_n = update_href($href_this, GET_HISTORY, $history . $code_k);
    $href_b = update_href($href_this, GET_HISTORY, $history . $code_b);
    $href_q = update_href($href_this, GET_HISTORY, $history . $code_q);
    if (USE_UNICODE_GLYPHS) {
        $r = '&#9814;';
        $n = '&#9816;';
        $b = '&#9815;';
        $q = '&#9813;';
    } else {
        $r = $player_pieces[PIECE_ROOK];
        $n = $player_pieces[PIECE_KNIGHT];
        $b = $player_pieces[PIECE_BISHOP];
        $q = $player_pieces[PIECE_QUEEN];
    }
    $ret .= "<li><a href=\"{$href_r}\"><div class=\"{$color} rook\" title=\"{$t_color} rook\">{$r}</div></a>\n";
    $ret .= "<li><a href=\"{$href_n}\"><div class=\"{$color} knight\" title=\"{$t_color} knight\">{$n}</div></a>\n";
    $ret .= "<li><a href=\"{$href_b}\"><div class=\"{$color} bishop\" title=\"{$t_color} bishop\">{$b}</div></a>\n";
    $ret .= "<li><a href=\"{$href_q}\"><div class=\"{$color} queen\" title=\"{$t_color} queen\">{$q}</div></a>\n";
    $ret .= "</ul>\n\n";
    return $ret;
}
/**
 * find_movable_pieces() - Creates  $clickable (Array of field names)
 * Checks the board for pieces that can be moved.
 * If all your pieces are boxed in or any move would result in your king to
 * get into check, an empty array is returned, indicating the end of the game.
 */
function find_movable_pieces($board_array, $current_player)
{
    $ret = array();
    $player_pieces = get_player_pieces($current_player);
    for ($row = 0; $row < 8; $row++) {
        for ($col = 0; $col < 8; $col++) {
            $piece = $board_array[$row][$col];
            if ($piece != '' && strpos($player_pieces, $piece) !== false) {
                $field = rowcol_to_field($row, $col);
                // Check, if piece can move at all
                $moves = possible_move_list($board_array, $current_player, $field);
                // First entry of the returned move list is
                // the FIELD of the currently checked piece:
                if (isset($moves[1])) {
                    $ret[] = $field;
                    // == $moves[0];
                }
            }
        }
    }
    return $ret;
}