<?php
	/* 
	 * 商品管理
	 */
	
	switch($ts){
	
		//商品列表
		case "":
			//商品分类函数
			function get_c_html($cate_name){
			global $db;
			$arrcate = $db->fetch_all_assoc("select cate_name from ".dbprefix."goods_cate where cate_id>1 and parent_id=0 order by cate_id asc");
			
		foreach($arrcate as $key=>$item){
			
					$cateData = $db->once_fetch_assoc("select cate_id from ".dbprefix."goods_cate where cate_name like '".$item['cate_name']."'");
					$c	= $db->fetch_all_assoc("select cate_name from ".dbprefix."goods_cate where parent_id ='".$cateData['cate_id']."'");

					if(is_array($c)){
						$cate_html .= $cate_name==$item['cate_name']?'<option value="'.$item['cate_name'].'" selected="selected">'.$item['cate_name'].'</option>':'<option value="'.$item['cate_name'].'">'.$item['cate_name'].'</option>';
					foreach($c as $k=>$v){
						$cate_html .= $cate_name==$v['cate_name']?'<option value="'.$v['cate_name'].'" selected="selected">&nbsp;&nbsp; - '.$v['cate_name'].'</option>':'<option value="'.$v['cate_name'].'">&nbsp;&nbsp; - '.$v['cate_name'].'</option>';
					}
				
			}
		}
			return $cate_html;
		
			}
		
		
		
		    $selecttype=$_REQUEST['selecttype'];
			$selectvalue=$_REQUEST['selectvalue'];
			$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
			$lstart = $page*15-15;
			if($selecttype){
				$url = 'index.php?app=mobile&ac=admin&mg=today&selecttype='.$selecttype.'&selectvalue='.$selectvalue.'&page=';
			}else{
				$url = 'index.php?app=mobile&ac=admin&mg=today&page=';
			}
			$wherestr="";
			
			
			if($selecttype&&$selectvalue){
			  if($selecttype=='goods_id'||$selecttype=='name'){
				$wherestr="where ".$selecttype." like '%".$selectvalue."%'";  
				
			  }
			  if($selecttype=='uid'){
				 $wherestr="where ".$selecttype." in (select userid from ".dbprefix."user_info where username like '%".$selectvalue."%')";
				  
			  }
			 if($selecttype=='cate_id'){
				 $wherestr="where ".$selecttype." in (select cate_id from ".dbprefix."goods_cate where cate_name like '%".$selectvalue."%')";
				  
			  }
			   $url = 'index.php?app=mobile&ac=admin&mg=today&selecttype='.$selecttype.'&selectvalue='.$selectvalue.'&page='; 
			}
			$arrgood = $db->fetch_all_assoc("select * from ".dbprefix."share_goods ".$wherestr." order by mobile_today desc, goods_id desc limit $lstart,15");
			
			foreach($arrgood as $key=>$item){
				$arrgoods[] = $item;
				$strcate = $db->once_fetch_assoc("select cate_name,appname from ".dbprefix."goods_cate where cate_id = '".$item['cate_id']."'");
				$arrgoods[$key]['cate_name'] = $strcate['cate_name'];
				$arrgoods[$key]['user'] = aac('user')->getUserForApp($item['uid']);
				
			}
			
			$goodsNum = $db->once_num_rows("select * from ".dbprefix."share_goods ".$wherestr);
			$pageUrl = pagination($goodsNum, 15, $page, $url);

			include template("admin/today");
			break;
		
		case "settoday":
		
			$goods_id = $_POST['goods_id'];
			$mobile_today  = $_POST['mobile_today'];

			$db->query("UPDATE ".dbprefix."share_goods SET  mobile_today='".$mobile_today."',uptime='".time()."' where goods_id = '".$goods_id."'");
			echo 1;
			

			break;
			
			//修改标题
		case "setname":
		
			$goods_id = $_POST['goods_id'];
			$name  = $_POST['name'];
		
			$db->query("UPDATE ".dbprefix."share_goods SET  name='".$name."' where goods_id = '".$goods_id."'");
			
			echo 1;
			

			break;
	}