<?php
function makeDownCheckBox($table, $selected = '') {
	global $channelid, $setting;
	if(empty($setting)){
		$setting = qbase::get_object('setting', $channelid, 0)->op_get_cache();
	}
	$s = '';
	$sarr = $selected ? explode(',', $selected) : array();
	if ($selected) {
		if(is_array($setting[$channelid][$table])) foreach($setting[$channelid][$table] as $key => $val) {
			$temp = explode('|', $val);	
			if (in_array($temp[0], $sarr)) {
				$s .= " <input name='{$table}[]' checked type='checkbox' value=\"{$temp[0]}\" id=\"{$table}_{$key}\"/> <label for='{$table}_{$key}'>{$temp[1]}</label>";
			} else {
				$s .= " <input name='{$table}[]'  type='checkbox' value=\"{$temp[0]}\" id=\"{$table}_{$key}\"/> <label for='{$table}_{$key}'>{$temp[1]}</label>";
			} 
		} 
	} else {
		if(is_array($setting[$channelid][$table])) foreach($setting[$channelid][$table] as $key => $val) {
			$temp = explode('|', $val);
			$checked = intval($temp[2]) ? ' checked' : '';
			$s .= " <input name='{$table}[]' {$checked} type='checkbox' value=\"{$temp[0]}\" id=\"{$table}_{$key}\"/> <label for='{$table}_{$key}'>{$temp[1]}</label>";
		} 
	} 
	echo '<div class="modify-cate">' . $s . '</div>' ;
} 

function MakeSelectDownload($table, $selected = 0, $addNull = 0) {
	global $channelid, $setting;
	if(empty($setting)){
		$setting = qbase::get_object('setting', $channelid, 0)->op_get_cache();
	}

	if (is_array($setting[$channelid][$table])) {
		if ($selected) {
			if(is_array($setting[$channelid][$table])) foreach($setting[$channelid][$table] as $key => $val) {
				$temp = explode('|', $val);
				if ($temp[0] == $selected) {
					$s .= "<option value=\"{$temp[0]}\" selected>{$temp[1]}</option>";
				} else {
					$s .= "<option value=\"{$temp[0]}\">{$temp[1]}</option>";
				} 
			} 
		} else {
			if(is_array($setting[$channelid][$table])) foreach($setting[$channelid][$table] as $key => $val) {
				$temp = explode('|', $val);
				$selected = intval($temp[2]) ? ' selected' : '';
				$s .= "<option value=\"{$temp[0]}\" {$selected}>{$temp[1]}</option>";
			} 
		} 
	} 
	if ($addNull == 0) {
		$s = "<select name=\"{$table}\" id={$table}>" . $s . "</select>";
	} else {
		$s = "<select name=\"{$table}\" id={$table}><option value=''>请选择</option>" . $s . "</select>";
	} 
	echo $s ;
}
// +--------------------------------
// |	取得中文的拼音（罕见的没办法）
// +--------------------------------
function g($num) {
	global $d;
	require_once R_P . '/include/inc.pinyin.php';
	if ($num > 0 && $num < 160) {
		return chr($num);
	} elseif ($num < -20319 || $num > -10247) {
		return "";
	} else {
		for($i = count($d)-1;$i >= 0;$i--) {
			if ($d[$i][1] <= $num) break;
		} 
		return $d[$i][0];
	} 
} 

function c($str) {
	$ret = "";
	for($i = 0;$i < strlen($str);$i++) {
		$p = ord(substr($str, $i, 1));
		if ($p > 160) {
			$q = ord(substr($str, ++$i, 1));
			$p = $p * 256 + $q-65536;
		} 
		$ret .= g($p);
	} 
	return $ret;
} 
?>