File: /var/www/html/wp-content/themes/frameMyrskyNew/led_home.php
<?php
/**
 * @package WordPress
 * @subpackage framePCB_Theme
 */
/*
Template Name: Led Home 
*/
?>
<?php get_header() ?>
<?php 
global $q_config;
//var_dump($q_config[language]);
/* if (have_posts()) : while (have_posts()) : the_post(); 
	$erp_page_path = get_the_content(); 
	wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number'));
endwhile; endif; 
echo "http://".$_SERVER['SERVER_NAME'].'/'.$erp_page_path; 
*/			
?> 
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/<?php echo $servers['Lang']; ?>.js"></script>
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory');?>/js/jquery-1.4.2.min.js" ></script>  
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory');?>/js/jquery.cookie.js"></script>
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory');?>/js/led.js"></script>
<div id="ifocus">
	<div id="ifocus_pic">
		<div id="ifocus_piclist" style="left:0; top:0;">
			<ul>
				<?php 
				include_once('stock_manage.php');
				$SaleManage   = new SaleManage();
				$focusInfo = $SaleManage->getFocusPicList();
				$focusSrc  = $focusInfo['src'];
				$focusImg  = $focusInfo['focusImg'];
				$btnImg    = $focusInfo['btnImg'];
				$ifocus_tx = $focusInfo['ifocus_tx'];
				foreach($focusSrc as $focusKey=>$focusValue){
					$focusImgValue  = '/'.$focusInfo['focusImg'][$focusKey];					
					$btnImgValue    = '/'.$focusInfo['btnImg'][$focusKey];
					$focusTitleh    = $focusInfo['ifocus_txh'][$focusKey];	
					$ifocus_txValue = $focusInfo['ifocus_tx'][$focusKey];	
					$ifocusClass    = 0==$focusKey ? 'current':'normal';
				?>		 
				<li><a href="product-list/?kind=<?php $focusValue;?>" target="_blank"><img src="<?php bloginfo('stylesheet_directory');echo $focusImgValue;?>"/></a></li>
				<?php }?>
			</ul>
		</div>
		<!-- 图片下方阴影--> 
		<div id="ifocus_opdiv"></div>
		<div id="ifocus_tx">
			<ul>		
			<?php 
			foreach($focusSrc as $focusKey=>$focusValue){
				$focusImgValue  = $base_url.'/'.$focusInfo['focusImg'][$focusKey];
				$btnImgValue    = $focusInfo['btnImg'][$focusKey];
				$focusTitleh    = $focusInfo['ifocus_txh'][$focusKey];	
				$ifocus_txValue = $focusInfo['ifocus_tx'][$focusKey];	
				//$ifocusClass    = 0==$focusKey ? 'current':'normal';
				//$style_class = 0==$focusKey ? 'width:830px;padding-left:20px;font-size:20px;':'width:428px;';
				if(0==$focusKey){
					?>	
					<li class="current" style="width:830px;font-size:18px;margin-top:20px;">					 
					  <p style="font-size:16px;"><?php echo $ifocus_txValue;?></p>
					</li>
					<?php
				}else{
						?>	
					<li class="normal" style="width:428px;">
					  <h2><?php echo $focusTitleh;?></h2>
					  <p><?php echo $ifocus_txValue;?></p>
					</li>
					<?php
				}
			} 	?>
			</ul>
		</div>  	  
	</div>
	<div id="ifocus_btn">
		<ul>
			<?php foreach($focusSrc as $focusKey=>$focusValue){
				$focusImgValue  = '/'.$focusInfo['focusImg'][$focusKey];
				$btnImgValue    = '/'.$focusInfo['btnImg'][$focusKey];
				$focusTitleh    = $focusInfo['ifocus_txh'][$focusKey];	
				$ifocus_txValue = $focusInfo['ifocus_tx'][$focusKey];	
				$ifocusClass    = 0==$focusKey ? 'current':'normal';
			?>
			<li class="<?php echo $ifocusClass;?>"><img src="<?php  bloginfo('stylesheet_directory');echo $btnImgValue?>" alt="<?php echo $focusTitleh;?>" /></li>
			<?php }?>
		</ul>
	</div>
</div>  
<div class="leftMenu led-box">
	<!--左产品菜单开始-->
	<h2 class="led-box-head"><span class="ledBackground left-circle"></span><a href="product-list/?">产品列表</a><span class="ledBackground right-circle"></span></h2>
	<div class="led-box-body">
		<div class="listMenu">
		<?php
		$ProductList = $SaleManage->getProductList();
		$ProListName = $SaleManage->getProListName();
		$innerHtml   = '';
		foreach($ProductList as $listKey=>$listInfo){
			//$kindName   = $ProListName[$listKey];
			//$kindName   =ucfirst(str_replace("_"," ",$listKey));	
			$kindName = $SaleManage->getCategoryChinaName($listKey,"zh");
			//$kindName = iconv("GB2312","utf-8",$kindName);
			//var_dump($ProListName);
			$innerHtml .= "<h2><a href='product-list/?kind=$listKey'>$kindName</a><span class='arrow'></span></h2><ul style='display:none;'>";			
			foreach($listInfo as $proKey=>$proInfo){		
				//echo $proInfo;
				$tmp = iconv("utf-8","GB2312",$proInfo);	//防止UTF-8中文被截取成两半
				$proInfo = strlen($tmp)>20 ? substr ($tmp,0,20)."..." : $tmp;//处理长度
				$innerHtml .="<li><a href='product-detail/?part_id=$proKey'>".iconv("GB2312","utf-8",$proInfo)."</a></li>";   
				//$innerHtml .="<li><a href='product-detail/?part_id=$proKey'>".$proInfo."</a></li>";    				
			}
			$innerHtml .='</ul>';
		}
		echo $innerHtml;
		?>
		</div> 
	</div>
	<span class="led-box-bottom"><span class="left-circle-bottom ledBackground"></span><span class="right-circle-bottom ledBackground"></span></span>
	<!--左产品菜单结束-->
	<br/>
	<!--左contact us开始-->
	<h2 class="led-box-head">
		<span class="ledBackground left-circle"></span>
		<a href="#"> 联系我们</a>
        <span class="ledBackground right-circle"></span>    
    </h2>
	<div class="led-box-body">		
		<div class="listMenu_cs">
			<?php
			echo $SaleManage->getProContactUs();
			?>
		</div>		
	</div>	  
    <span class="led-box-bottom">
        <span class="left-circle-bottom ledBackground"></span>
        <span class="right-circle-bottom ledBackground"></span>
    </span>
	<!--左contact us结束-->
</div> 
<div class="rightProduct">
    <!--右产品分类列表开始-->	  
	<ul class="productKind">
		<?php
		$proList = $SaleManage->getIndexProduct();
		if(empty($proList)){
		?>
		<li class="led-box">
			<h2 class="led-box-head">
			<span class="ledBackground left-circle"></span>
			<a href="ERP/led/pro_list.php?user_email={user_email}&kind={kind}">{kindName}</a>
			<span class="ledBackground right-circle"></span>  
			</h2>  
			<ul class="led-box-body productDetail"><li>		  
			<b>There is no product in stock.	</b>	
			</li></ul>  
			<span class="led-box-bottom">
			<span class="left-circle-bottom ledBackground"></span>
			<span class="right-circle-bottom ledBackground"></span>
			</span>
		</li>
		<?php
		}else{			
			$ProListName = $SaleManage->getProListName();
			foreach($proList as $kind=>$tempProList){	
				$kindName = ucfirst(str_replace("_"," ",$kind));
				?>
				<li class="led-box">
					<h2 class="led-box-head">
					<span class="ledBackground left-circle"></span>
					<a href="product-list/?kind=<?php echo $kind;?>"><?php echo $SaleManage->getCategoryChinaName($kind,"zh");?></a>
					<span class="ledBackground right-circle"></span>  
					</h2>
					<ul class="led-box-body productDetail">
						<?php										
						foreach($tempProList as $pId=>$pInfo){	
							$unit          = $pInfo["category_symbol"];
							$proName       = $pInfo['pName'];
							$proId         = $pId;
							$proImg        = "http://".$_SERVER['SERVER_NAME'].'/ERP/'.$pInfo['imgSrc'];
							$features      = msubstr($pInfo['description'],0,42,"utf-8",true)."...";
							$proPriceArray = $pInfo['UnitPrice'];
							$price         = round($proPriceArray[0]['unit_price'], 2);
							$innerHtml     = "";
							$jsArr         = "";
							$aNum          = count($proPriceArray);		
							$lead_time     =  empty($pInfo["lead_time"])?$servers['led_ledtime']:$pInfo["lead_time"] ;
							if($aNum<2){
								$quantity   = $proPriceArray[0]['quantity'];
								$unit_price = round($proPriceArray[0]['unit_price'], 2);
								$jsArr .='{quantityMin:'.$last_quantity.',quantityMax:'.$quantity.','.'unit_price:'.$unit_price.'},';
								$innerHtml  .= "<tr><td>-</td><td>$unit_price</td></tr>";
							}else{
								$last_quantity = 0;
								$fistQuantity = $proPriceArray[0]['quantity'];
								$lastQuantity = $proPriceArray[($aNum-1)]['quantity'];
								$i = 0 ;
								foreach($proPriceArray as $proPrice){				
									$quantity   = $proPrice['quantity'];
									if($quantity>$fistQuantity){	
										$ii= $i-1;
										$unit_price = round($proPriceArray[$ii]['unit_price'], 2);
										$jsArr .='{quantityMin:'.$last_quantity.',quantityMax:'.$quantity.','.'unit_price:'.$unit_price.'},';
										$innerHtml  .= "<tr><td>$last_quantity-$quantity</td><td>$unit_price</td></tr>";
										$last_quantity = $quantity;					
									}
									if($pamount>=$quantity){
										$initPrice = round($proPriceArr[$i]['unit_price'], 2);
									}
									$i++;
								}
								$unit_price = round($proPriceArray[($aNum-1)]['unit_price'], 2);
								$quantity   = $proPriceArray[($aNum-1)]['quantity'];
								$jsArr .='{quantityMin:'.$last_quantity.',quantityMax:'.$quantity.','.'unit_price:'.$unit_price.'},';
								$innerHtml  .= "<tr><td>>$last_quantity</td><td>$unit_price</td></tr>";
							}	
							if(!empty($innerHtml)){
							$innerHtml ="<table class='mytable' id='table_".$pId."'><tr><td>购买数量</td><td>价格</td></tr>".$innerHtml.'</table>';
							}	
							?>		
							<li>
							<a href="product-detail/?part_id=<?php echo $proId; ?>"><img src="<?php echo $proImg;?>" alt="<?php echo $proName;?>" /></a> 
							<span><strong>产品名称:</strong><a href="product-detail/?part_id=<?php echo $proId;?>"><?php echo $proName;?></a></span>
							<span class="proIntro"><strong>产品特点:</strong>
								<?php echo $features;?>						
							</span>
							<span><strong>单  价:</strong><code class="showPrice" pid="<?php echo $proId;?>"><?php echo $unit.$price;?></code></span>		
							<?php echo $innerHtml;?>			
							<a href="shopping-cart/?&pid=<?php echo $proId?>" title="buy now" class="shopCar addToCar" pid="<?php echo $proId ;?>" lead_time="<?php echo $lead_time ;?>"><img alt="" src="<?php bloginfo('stylesheet_directory'); ?>/images/shopCar.png"/></a>
							<span><strong>库存数量:</strong><code id="qty_<?php echo $proId;?>"><?php echo $pInfo['StockQty']?></code></span>
							<a href="product-list/?kind=<?php echo $kind;?>" title="More" class="more"><img alt="" src="<?php bloginfo('stylesheet_directory'); ?>/images/more_zh.png"/></a>    
							</li>
						<?php
						}
						?>
					</ul>	
					<span class="led-box-bottom">
					<span class="left-circle-bottom ledBackground"></span>
					<span class="right-circle-bottom ledBackground"></span>
					</span>
				</li>
			<?php
			}
		}
		?>
     </ul>
     <!--右产品分类列表结束-->
</div>
</div>
<?php get_footer() ?>
<?php
/**
 +----------------------------------------------------------
 * 字符串截取,支持中文和其他编码
 +----------------------------------------------------------
 * @static
 * @access public
 +----------------------------------------------------------
 * @param string $str 需要转换的字符串
 * @param string $start 开始位置
 * @param string $length 截取长度
 * @param string $charset 编码格式
 * @param string $suffix 截断显示字符
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
{
    if(function_exists("mb_substr"))
        return mb_substr($str, $start, $length, $charset);
    elseif(function_exists('iconv_substr')) {
        return iconv_substr($str,$start,$length,$charset);
    }
    $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
    $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
    $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
    $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
    preg_match_all($re[$charset], $str, $match);
    $slice = join("",array_slice($match[0], $start, $length));	
    if($suffix==true){
		$slice = $slice."…";	
	}
	return $slice;    
}
?>