<?php

/* No empty dropdowns please */
if ($field != '' AND $id != '') {
	$out = wp_cache_get( 'wct_select_'.$field , 'wct');
	if ($out == false) {
		$limit = (integer)$limit;
		if ($limit <= '0') { $limit = '1'; }
		$qry = $wpdb->get_results("SELECT `".mres($field)."` AS `item`,count(".mres($field).") AS `anz`  FROM `".$wpdb->prefix."wct".mres($id)."` WHERE `status`='active' GROUP BY `".mres($field)."` ORDER BY `anz` DESC LIMIT ".$limit.";");
		if (count($qry) >= '1') {
			$out = "<select class=\"wct-select\" onChange=\"selector('".$field."')\" style=\"font-weight: bold;\" id=\"wctdrop_".$field."\" name=\"wctdrop_".$field."\"><option style=\"font-weight: bold;\" value=\"NULL\">".$maintext."</option>";
			foreach ($qry as $row) {
				$jsvalue = $row->item;

				$out .= "<option class=\"wct-option\" style=\"font-weight: normal;\" value=\"".rawurlencode(base64_encode($jsvalue))."\" ";
				if ((base64_decode($_GET['wctdrop']) == $jsvalue AND $row->item != '') OR ($_GET['wctdrof'] != '' AND $_GET['wctdrop'] != 'NULL' AND $row->item == '' AND $field == $_GET['wctdrof'])) { $out .= " selected"; }
				$out .= ">";
				if ($row->item == '') { $out .= "-- ".__('Empty','wct')." --"; } else { $out .= $row->item; }
 
				$out .= " (".$row->anz.")</option>";
			}
			$out .= "</select>";
		}
		/* If field not existing or no options to dropdown, no cache! */
		if ($out != '') { wp_cache_set( 'wct_select'.$field, $out, 'wct', $this->settings['wct_cachetime']); $include_js = '1'; }
	}
}

?>