<?php 
/*
*file header*

*/
               echo "<script language=\"JavaScript\" src=\"check.js\"></script>";

function cpheader() {
	echo "<html>\n";
	echo "<head>\n";
	echo "<title> </title>\n";
	echo "<meta content=\"text/html; charset=gb2312\" http-equiv=\"Content-Type\">\n";
	echo "<link rel=\"stylesheet\" href=\"./cp.css\" type=\"text/css\">\n";
	echo "<script language=\"JavaScript\" src=\"./check.js\"></script>\n";
	echo "</head>\n";
	echo "<body leftmargin=\"20\" topmargin=\"20\" marginwidth=\"20\" marginheight=\"20\"  style=\"table-layout:fixed; word-break:break-all\">\n";
	
}

      function pageheader() {
				echo "<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"4\" class=\"tableoutline\">\n";
				echo "  <tr>\n";
				echo "    <td><div align=\"center\">编号：\n";
				echo "      <input name=\"productcode\" type=\"text\" size=\"15\">\n";
				echo "    </div></td>\n";
				echo "    <td><div align=\"center\">名称：\n";
				echo "      <input name=\"productname\" type=\"text\" size=\"15\">\n";
				echo "    </div></td>\n";
				echo "    <td><div align=\"center\">分类：\n";
				echo "<select name=\"pcategory\">\n";
				echo "<option value=\"0\">根分类</option>\n";
				$sort_string = "";
				echo get_sort_select();
				echo "</select>\n";
				echo "    </div></td>\n";
				echo "    <td><div align=\"center\">\n";
				echo "      <input name=\"searchproduct\" type=\"submit\" id=\"searchproduct\" value=\"查询\">\n";
				echo "    </div></td>\n";
				echo "  </tr>\n";
				echo "</table>\n";
      }

/*
*file footer*
*/
function cpfooter() {
	echo "\n<br>\n<center><font color=\"#000000\"></font></a></center><br>\n<center><br>\n";
	echo "</body>\n</html>";
	
/*echo "<script language=\"javascript\">\n";
echo "		for ($i=0;$i<count($cachesorts);$i++) {\n";
echo "				for (var j=0;j<document.form.elements[16].length;j++) {\n";
echo "					if ($cachesorts[$i]==document.form.elements[16].options[j].value){\n";
echo "						document.form.elements[16].options[j].selected=true;\n";
echo "					}\n";
echo "				}\n";
echo "		}\n";
echo "</script>\n";
*/
}

/*
*redirect*
*/
function redirect($msg,$url) {
	cpheader();
	echo "<p>".$msg."</p>\n";
	echo "<meta http-equiv=\"refresh\" content=\"1;URL=".$url."\">\n";
	echo "</body>\n</html>";
	exit;

}

/*
**
*/
function getrowbg() {
	global $bgcounter;
	if ($bgcounter++%2==0) {
		return "firstalt";
	} else {
		return "secondalt";
	}
}
/*
****
*/
function stripslashes_array($array) {
	while (list($k,$v) = each($array)) {
		if (is_string($v)) {
			$array[$k] = stripslashes($v);
		} else if (is_array($v))  {
			$array[$k] = stripslashes_array($v);

		}
	}
	return $array;
}


/*
*check db not null*
*/
function tep_not_null2($v) {
	if (is_array($v)) {
		if (sizeof($v) > 0) {
			return true;
		}else {
			return false;
		}
	}else {
		if (($v != "") && (strtolower($v) != 'null') && (strlen($v)>0)) {
			return true;
		}else {
			return false;
		}
	}
}

/*
**
*/
function makenav($ctitle="",$nav=array()) {
	global $nc; // nav counter
	echo "<tr class=\"tblhead\">\n";
	echo "  <td class=\"space\" align=\"center\"><span class=\"tblhead\" ><b><font color=#000000>$ctitle</font></b></span></td>\n";
	echo "</tr>\n";
	echo "<tr>\n";
	echo "  <td>\n";
	echo "    <table width=\"100%\" cellpadding=\"2\" cellspacing=\"1\" border=\"0\">\n";
    foreach ($nav AS $title=>$link)
	{
    echo "<tr>\n";
	echo "  <td align=\"center\">\n";
	echo "<a href=\"$link\" target=\"mainFrame\"><font color=\"#000000\">$title</font></a>\n";
	echo "  </td>\n";
	echo "</tr>\n";
	}
	echo "    </table>\n";
	echo "  </td>\n";
	echo "</tr>\n";
         $nc++;
}


/*
**
*/
function ga_exit($msg,$url="javascript:history.go(-1);"){
	cpheader();
	echo "<p>".$msg."</p><br>";
	echo "<a href=\"$url\"><font color=\"#000000\">點擊這裏返回!</font></a>";
	cpfooter();
	exit;
}

/*
**
*/
function print_rr($v) {
	if (is_array($v)) {
		echo "<pre>";
		print_r($v);
		echo "</pre>";
	}else {
		echo $v;
	}
}
function tableheader() {
	echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"95%\" class=\"tblborder\">\n<tr>\n<td>\n";
}


function tablefooter() {
	echo "\n</td>\n</tr>\n</table>";
}


/*取出所有GET傳遞的參數*/
function get_all_parameter() {
	global $_GET;
	$str="";
	if (is_array($_GET) && (count($_GET) > 0)) {
		reset($_GET);
		while (list($k,$v) = each($_GET)) {

			if (($k != 'x') && ($k != 'y') && ($k != 'page')) {
				$str .= $k . "=" . rawurldecode(stripslashes($v))."&";
			}
		}		
	}

	return $str;
}

/*中文字符截取*/
function cn_substr($string, $start, $len, $byte=3)

{
	$str     = "";
    $count   = 1;
    $str_len = strlen($string);
    for ($i=0; $i<$str_len; $i++) {
        if (($count+1-$start)>$len) {
            $str  .= "...";
            break;
        } elseif ((ord(substr($string,$i,1)) <= 128) && ($count < $start)) {
            $count++;
        } elseif ((ord(substr($string,$i,1)) > 128) && ($count < $start)) {
            $count = $count+2;
            $i     = $i+$byte-1;
        } elseif ((ord(substr($string,$i,1)) <= 128) && ($count >= $start)) {
            $str  .= substr($string,$i,1);
            $count++;
        } elseif ((ord(substr($string,$i,1)) > 128) && ($count >= $start)) {
            $str  .= substr($string,$i,$byte);
            $count = $count+2;
            $i     = $i+$byte-1;
        }
    }
    return $str;
}

/*替換搜索結果中的關鍵字*/
function replace_result ($keyvalue,$array) {
	$replace_str = '<b><font color="red">' .$keyvalue. '</font></b>'; 
	$arr = str_replace($keyvalue,$replace_str,$array);
	return $arr;
}


function html2txt($string) {
	if (is_string($string)) {
		$parrent = array("<", ">", "'", '"', "\n", "\t", "	", "&", " ");
		$replace = array("&lt;", "&gt;", "\'", '\"', "<br>", "<br>", " ", "&amp;", "&nbsp;");
		$string = str_replace($parrent, $replace, $string);
	}elseif (is_array($string)) {
		foreach($string as $k=>$v) {
			$string[$k] = html2txt($v);
		}
	}
	return $string;
}

?>