<?php
	/* 
	 * 添加画报
	 */
	
	switch($ts){
		case "":
		
		
		include template("admin/addhuabao");
		
		break;
	
		//添加画报
		case "add_p":

		$catename = 1;
		$is_im = $_POST['is_im'];
		$is_im_index = $_POST['is_im_index'];
		$title = $_POST['title'];
		$cateData = $db->once_fetch_assoc("select cate_id from ".dbprefix."goods_cate where cate_name like '".$catename."'");
		$cate_id = intval($cateData['cate_id'])?intval($cateData['cate_id']):0;
		$goodslink_arr = $_POST['goodsid'];
		$i=0;
		if(empty($title)){
					
				qiMsg("画报标题不能为空！");
					
				}
			foreach($_POST['name'] as $key=>$item){

				$img_url = $_POST['img_url'][$key];
				$tag = $_POST['tag'][$key];
				$img_url_info = getimagesize($img_url);
				$imgheigt =  $img_url_info[1];
				$imgwith =   $img_url_info[0];
				$goodslink = str_replace('，',',',$goodslink_arr[$key]);
				if(empty($img_url)||empty($item)){
					
					{qiMsg("图片和描述都不能为空");}
					
				}
				
				require_once 'letutao/class.image.php';
				//生成缩略图400x600
				$imgurl_400x600=$img_url.'_400x600.jpg';
			
				$resizeimage = new tsImg("$img_url", "400", "600", "0", "$imgurl_400x600" );
			
				//生成缩略图200x300
				$imgurl_200x300=$img_url.'_200x300.jpg';
			
				$resizeimage = new tsImg("$img_url", "200", "300", "0", "$imgurl_200x300" );
				
				$arrData = array(
					'description'		 => $item,
					'tag'				 => $tag,
					'photo'				 => $img_url,
					'width'			     => $imgwith,
					'height'	         => $imgheigt,
					'goodslink'	         => $goodslink,
					'addtime'		     => time(),
				);
				$p_id = $db->insertArr($arrData,dbprefix.'pictorial');
				
				$p_str .= $p_id.'_';
				$i++;
			}
			
			
			$arrData = array(
					'title'			     => $title,
					'p_str'				 => substr($p_str, 0, -1),
					'cateid'			 => $cate_id,
					'num'				 => $i,
					'userid'			 => 1,//暂定为管理员
					'is_im'			     => intval($is_im),
					'is_im_index'		 => intval($is_im_index),
				);
				
			$p_str = $db->insertArr($arrData,dbprefix.'p_str');
			
			qiMsg("成功添加了一个画报！");
		
			break;
		
	}