function wppa_album_select_a($args)
{
    global $wpdb;
    $args = wp_parse_args($args, array('exclude' => '', 'selected' => '', 'disabled' => '', 'addpleaseselect' => false, 'addnone' => false, 'addall' => false, 'addgeneric' => false, 'addblank' => false, 'addselected' => false, 'addseparate' => false, 'addselbox' => false, 'disableancestors' => false, 'checkaccess' => false, 'checkowner' => false, 'checkupload' => false, 'addmultiple' => false, 'addnumbers' => false, 'path' => false, 'root' => false, 'content' => false, 'sort' => true));
    // Provide default selection if no selected given
    if ($args['selected'] === '') {
        $args['selected'] = wppa_get_last_album();
    }
    // See if selection is valid
    if ($args['selected'] == $args['exclude'] || $args['checkupload'] && !wppa_allow_uploads($args['selected']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $args['selected'])) {
        $args['selected'] = '0';
    }
    $albums = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` " . wppa_get_album_order($args['root']), ARRAY_A);
    // Add to secondary cache
    if ($albums) {
        wppa_cache_album('add', $albums);
    }
    if ($albums) {
        // Filter for root
        if ($args['root']) {
            $root = $args['root'];
            switch ($root) {
                // case '0': all, will be skipped as it returns false in 'if ( $args['root'] )'
                case '-2':
                    // Generic only
                    foreach (array_keys($albums) as $albidx) {
                        if (wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                case '-1':
                    // Separate only
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                default:
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_ancestor($root, $albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
            }
        }
        // Filter for must have content
        if ($args['content']) {
            foreach (array_keys($albums) as $albidx) {
                if (wppa_get_photo_count($albums[$albidx]['id']) <= wppa_get_mincount()) {
                    unset($albums[$albidx]);
                }
            }
        }
        // Add paths
        if ($args['path']) {
            $albums = wppa_add_paths($albums);
        } else {
            foreach (array_keys($albums) as $index) {
                $albums[$index]['name'] = __(stripslashes($albums[$index]['name']));
            }
        }
        // Sort
        if ($args['sort']) {
            $albums = wppa_array_sort($albums, 'name');
        }
    }
    // Output
    $result = '';
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addpleaseselect']) {
        $result .= '<option value="0" disabled="disabled" ' . $selected . ' >' . (is_admin() ? __('- select an album -', 'wppa') : __a('- select an album -')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addnone']) {
        $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- none ---', 'wppa') : __a('--- none ---')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- all ---', 'wppa') : __a('--- all ---')) . '</option>';
    }
    $selected = $args['selected'] == '-2' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="-2"' . $selected . ' >' . (is_admin() ? __('--- generic ---', 'wppa') : __a('--- generic ---')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addblank']) {
        $result .= '<option value="0"' . $selected . ' >' . '</option>';
    }
    $selected = $args['selected'] == '-99' ? ' selected="selected"' : '';
    if ($args['addmultiple']) {
        $result .= '<option value="-99"' . $selected . ' >' . (is_admin() ? __('--- multiple see below ---', 'wppa') : __a('--- multiple see below ---')) . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addselbox']) {
        $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- a selection box ---', 'wppa') : __a('--- a selection box ---')) . '</option>';
    }
    if ($albums) {
        foreach ($albums as $album) {
            if ($args['disabled'] == $album['id'] || $args['exclude'] == $album['id'] || $args['checkupload'] && !wppa_allow_uploads($album['id']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $album['id'])) {
                $disabled = ' disabled="disabled"';
            } else {
                $disabled = '';
            }
            if ($args['selected'] == $album['id'] && !$disabled) {
                $selected = ' selected="selected"';
            } else {
                $selected = '';
            }
            $ok = true;
            // Assume this will be in the list
            if ($args['checkaccess'] && !wppa_have_access($album['id'])) {
                $ok = false;
            }
            if ($args['checkowner'] && wppa_switch('upload_owner_only')) {
                // Need to check
                if ($album['owner'] != wppa_get_user() && $album['owner'] != '--- public ---') {
                    // Not 'mine'
                    if (!wppa_user_is('administrator')) {
                        // No admin
                        $ok = false;
                    }
                }
            }
            if ($selected && $args['addselected']) {
                $ok = true;
            }
            if ($ok) {
                if ($args['addnumbers']) {
                    $number = ' ( ' . $album['id'] . ' )';
                } else {
                    $number = '';
                }
                $result .= '<option value="' . $album['id'] . '" ' . $selected . $disabled . '>' . $album['name'] . $number . '</option>';
            }
        }
    }
    $selected = $args['selected'] == '-1' ? ' selected="selected"' : '';
    if ($args['addseparate']) {
        $result .= '<option value="-1"' . $selected . '>' . (is_admin() ? __('--- separate ---', 'wppa') : __a('--- separate ---')) . '</option>';
    }
    return $result;
}
function wppa_album_select_a($args)
{
    global $wpdb;
    $args = wp_parse_args($args, array('exclude' => '', 'selected' => '', 'disabled' => '', 'addpleaseselect' => false, 'addnone' => false, 'addall' => false, 'addgeneric' => false, 'addblank' => false, 'addselected' => false, 'addseparate' => false, 'addselbox' => false, 'addowner' => false, 'disableancestors' => false, 'checkaccess' => false, 'checkowner' => false, 'checkupload' => false, 'addmultiple' => false, 'addnumbers' => false, 'path' => false, 'root' => false, 'content' => false, 'sort' => true, 'checkarray' => false, 'array' => array(), 'optionclass' => ''));
    // Provide default selection if no selected given
    if ($args['selected'] === '') {
        $args['selected'] = wppa_get_last_album();
    }
    // See if selection is valid
    if ($args['selected'] == $args['exclude'] || $args['checkupload'] && !wppa_allow_uploads($args['selected']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $args['selected'])) {
        $args['selected'] = '0';
    }
    // Get roughly the albums that might be in the selection
    if ($args['checkarray'] && !empty($args['array'])) {
        $albums = $wpdb->get_results("SELECT `id`, `name` " . "FROM `" . WPPA_ALBUMS . "` " . "WHERE `id` IN (" . implode(',', $args['array']) . ") " . ($args['checkowner'] && wppa_switch('upload_owner_only') && !wppa_user_is('administrator') ? "AND `owner` IN ( '--- public ---', '" . wppa_get_user() . "' ) " : "") . wppa_get_album_order($args['root']), ARRAY_A);
    } else {
        $albums = $wpdb->get_results("SELECT `id`, `name` " . "FROM `" . WPPA_ALBUMS . "` " . ($args['checkowner'] && wppa_switch('upload_owner_only') && !wppa_user_is('administrator') ? "WHERE `owner` IN ( '--- public ---', '" . wppa_get_user() . "' ) " : "") . wppa_get_album_order($args['root']), ARRAY_A);
    }
    /* Can not add to cache because only "SELECT * " can be added
    	// Add to secondary cache
    	if ( $albums ) {
    		wppa_cache_album( 'add', $albums );
    	}
    	*/
    if ($albums) {
        // Filter for root
        if ($args['root']) {
            $root = $args['root'];
            switch ($root) {
                // case '0': all, will be skipped as it returns false in 'if ( $args['root'] )'
                case '-2':
                    // Generic only
                    foreach (array_keys($albums) as $albidx) {
                        if (wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                case '-1':
                    // Separate only
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_separate($albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
                default:
                    foreach (array_keys($albums) as $albidx) {
                        if (!wppa_is_ancestor($root, $albums[$albidx]['id'])) {
                            unset($albums[$albidx]);
                        }
                    }
                    break;
            }
        }
        // Filter for must have content
        if ($args['content']) {
            foreach (array_keys($albums) as $albidx) {
                if (wppa_get_photo_count($albums[$albidx]['id']) <= wppa_get_mincount()) {
                    unset($albums[$albidx]);
                }
            }
        }
        // Add paths
        if ($args['path']) {
            $albums = wppa_add_paths($albums);
        } else {
            foreach (array_keys($albums) as $index) {
                $albums[$index]['name'] = __(stripslashes($albums[$index]['name']));
            }
        }
        // Sort
        if ($args['sort']) {
            $albums = wppa_array_sort($albums, 'name');
        }
    }
    // Output
    $result = '';
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addpleaseselect']) {
        $result .= '<option value="0" disabled="disabled" ' . $selected . ' >' . __('- select an album -', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addnone']) {
        $result .= '<option value="0"' . $selected . ' >' . __('--- none ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="0"' . $selected . ' >' . __('--- all ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '-2' ? ' selected="selected"' : '';
    if ($args['addall']) {
        $result .= '<option value="-2"' . $selected . ' >' . __('--- generic ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '-3' ? ' selected="selected"' : '';
    if ($args['addowner']) {
        $result .= '<option value="-3"' . $selected . ' >' . __('--- owner/public ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addblank']) {
        $result .= '<option value="0"' . $selected . ' >' . '</option>';
    }
    $selected = $args['selected'] == '-99' ? ' selected="selected"' : '';
    if ($args['addmultiple']) {
        $result .= '<option value="-99"' . $selected . ' >' . __('--- multiple see below ---', 'wp-photo-album-plus') . '</option>';
    }
    $selected = $args['selected'] == '0' ? ' selected="selected"' : '';
    if ($args['addselbox']) {
        $result .= '<option value="0"' . $selected . ' >' . __('--- a selection box ---', 'wp-photo-album-plus') . '</option>';
    }
    // In case multiple
    if (strpos($args['selected'], ',') !== false) {
        $selarr = explode(',', $args['selected']);
    } else {
        $selarr = array($args['selected']);
    }
    if ($albums) {
        foreach ($albums as $album) {
            if ($args['disabled'] == $album['id'] || $args['exclude'] == $album['id'] || $args['checkupload'] && !wppa_allow_uploads($album['id']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $album['id'])) {
                $disabled = ' disabled="disabled"';
            } else {
                $disabled = '';
            }
            if (in_array($album['id'], $selarr, true) && !$disabled) {
                $selected = ' selected="selected"';
            } else {
                $selected = '';
            }
            $ok = true;
            // Assume this will be in the list
            if ($args['checkaccess'] && !wppa_have_access($album['id'])) {
                $ok = false;
            }
            /* This is in the query now
            		if ( $args['checkowner'] && wppa_switch( 'upload_owner_only' ) ) { 							// Need to check
            			if ( $album['owner'] != wppa_get_user() && $album['owner']  != '--- public ---' ) { 	// Not 'mine'
            				if ( ! wppa_user_is( 'administrator' ) ) {											// No admin
            					$ok = false;
            				}
            			}
            		}
            		*/
            /* This is in the query now
            		if ( $args['checkarray'] ) {
            			if ( ! in_array( $album['id'], $args['array'] ) ) {
            				$ok = false;
            			}
            		}
            		*/
            if ($selected && $args['addselected']) {
                $ok = true;
            }
            if ($ok) {
                if ($args['addnumbers']) {
                    $number = ' ( ' . $album['id'] . ' )';
                } else {
                    $number = '';
                }
                $result .= '<option class="' . $args['optionclass'] . '" value="' . $album['id'] . '" ' . $selected . $disabled . '>' . $album['name'] . $number . '</option>';
            }
        }
    }
    $selected = $args['selected'] == '-1' ? ' selected="selected"' : '';
    if ($args['addseparate']) {
        $result .= '<option value="-1"' . $selected . '>' . __('--- separate ---', 'wp-photo-album-plus') . '</option>';
    }
    return $result;
}