<?php
/*
作用：取得内容页数组
使用方法：
$fid = 70;
$mid = 32;
$hot_db = get_listdb( $fid ,' ORDER BY `count` DESC LIMIT 0 , 8 ' );
*/
function get_showdb( $aid , $mid ){

	//本函数使用的缓存文件
	$cachefile = '../../cache/cache_'.make_3_rand().'.php';

	//先取得本栏目需解析的字段
	$query="SELECT * FROM `w6_module` WHERE `module_id`='".$mid."'";
	$result=mysql_query($query);
	$module_config       =  mysql_result($result,"0","module_config");
	$array = unserialize($module_config);



	unset($strdb);
	$set_str_s_b_photo = '';//是否有图片缩略图字段存在
	$strdb[]= '$showdb[\'title\']        =  stripslashes(mysql_result($result,"0","title"))';
	$strdb[]= '$showdb[\'count\']        =  stripslashes(mysql_result($result,"0","count"))';
	$strdb[]= '$showdb[\'yz\']        =  stripslashes(mysql_result($result,"0","yz"))';
	$strdb[]= '$showdb[\'shows\']        =  stripslashes(mysql_result($result,"0","shows"))';
	$strdb[]= '$showdb[\'top\']        =  stripslashes(mysql_result($result,"0","top"))';
	$strdb[]= '$showdb[\'levels\']        =  stripslashes(mysql_result($result,"0","levels"))';
	foreach( $array AS $key=>$value){
			$strdb[]='@$showdb[\''.$value['field_id'].'\']	=	stripslashes(mysql_result($result,"0","'.$value['field_id'].'"))';
			
			if( $value['form_type'] == 'upphoto' )
			{
				$set_str_s_b_photo = '1';//是否有图片缩略图字段存在
				$str_s_b_photo = '$s_b_photo_file = explode( "@@@" , $showdb[\''.$value['field_id'].'\'] );
				$showdb[\'s_'.$value['field_id'].'\'] = $s_b_photo_file[\'0\'];
				$showdb[\'b_'.$value['field_id'].'\'] = $s_b_photo_file[\'1\'];';
			}
	}
		$str=implode(";",$strdb).";";
		
		if( $set_str_s_b_photo == '1' ){//是否有图片缩略图字段存在
			$str = $str.$str_s_b_photo;
		}

		  $str="<?php\n".$str;
		  
		writetofile_w( $cachefile , $str );




	//取数据
	$result=mysql_query("SELECT * FROM `w6_module_content_".$mid."` WHERE `aid` = '".$aid."'") or die("Could not connect: " . mysql_error());

	include($cachefile);

	
	//删除缓存文件
	unlink($cachefile);
	return $showdb;

}


function get_modify_sql( $aid , $mid ){
global $tpbdh_imgUrl,$tpbdh_imgUrl2,$webdb,$web126_imgUrl;

	//本函数使用的缓存文件
	$cachefile = '../../../cache/cache_'.make_3_rand().'.php';
	
	$updatatime = time();

	//先取得本栏目需解析的字段
	$query="SELECT * FROM `w6_module` WHERE `module_id`='".$mid."'";
	$result=mysql_query($query);
	$module_config       =  mysql_result($result,"0","module_config");
	$array = unserialize($module_config);
	
	unset( $array['field_set'] );

	$str1 = '$query="UPDATE `w6_module_content_'.$mid.'` SET `title`=\'".$postdb[\'title\']."\' , `yz`=\'".$postdb[\'yz\']."\' , `shows`=\'".$postdb[\'shows\']."\' , `top`=\'".$postdb[\'top\']."\' , `levels`=\'".$postdb[\'levels\']."\' , `updatatime`=\'".$updatatime."\' , ';
		  //`titlecolor`='".$postdb['titlecolor']."' , `fonttype`='".$postdb['fonttype']."'

	$str3 = ' WHERE `aid`=".$aid ;';
	//$str3 .= '
	//echo $query;
	//'; 
	

	unset($strdb);
	$set_str_s_b_photo = '';//是否有图片缩略图字段存在


	$str0= '$postdb = $_POST[\'postdb\'];';
	$str0.= '
	$postdb[\'title\']        =  addslashes( filtrate ( $_POST[\'title\'] ) );
	$postdb[\'yz\']        =  addslashes( filtrate ( $_POST[\'yz\'] ) );
	$postdb[\'shows\']        =  addslashes( filtrate ( $_POST[\'shows\'] ) );
	$postdb[\'top\']        =  addslashes( filtrate ( $_POST[\'top\'] ) );
	$postdb[\'levels\']        =  addslashes( filtrate ( $_POST[\'levels\'] ) );
	';
	

	/*
	//zwj 加入计算文章相似度
	//$postdb['fl_message']
	//$postdb['fl_message_2']
	$str0.= '
	
	similar_text( $postdb[\'fl_message\'] , $postdb[\'fl_message_2\'] , $per ); 
	echo round($per,2),\'%\';
	if( !empty($postdb[\'fl_message\']) AND (round($per,2) >= 50 || round($per,2) == 0) ){
		$show_str =  "<h1><font color=\"#FF0000\">内容修改前与修改后过于相似，审核不通过，建议重新修改！</font></h1>";
		$postdb[\'nr_xsd\'] = "内容修改前与修改后过于相似，建议重新修改！".round($per,2);//相似度
		$postdb[\'fl_sh\'] = 0;
	}else{
		$show_str =  "<h1>审核通过</h1>";
		$postdb[\'nr_xsd\'] = "审核通过".round($per,2);//相似度
		if( empty($postdb[\'fl_message\']) ){$postdb[\'nr_xsd\'] = "审核通过-原内容为空";}
		$postdb[\'fl_sh\'] = 1;
	}
	
	if( round($per,2) == 0 ){
		similar_text( $postdb[\'yk_sm\'] , $postdb[\'yk_sm2\'] , $per ); 
		echo round($per,2),\'%\';
		if( !empty($postdb[\'yk_sm\']) AND (round($per,2) >= 50 || round($per,2) == 0) ){
			$show_str =  "<h1><font color=\"#FF0000\">内容修改前与修改后过于相似，审核不通过，建议重新修改！</font></h1>";
			$postdb[\'nr_xsd\'] = "内容修改前与修改后过于相似，建议重新修改！".round($per,2);//相似度
			$postdb[\'fl_sh\'] = 0;
		}else{
			$show_str =  "<h1>审核通过</h1>";
			$postdb[\'nr_xsd\'] = "审核通过".round($per,2);//相似度
			if( empty($postdb[\'yk_sm\']) ){$postdb[\'nr_xsd\'] = "审核通过-原内容为空";}
			$postdb[\'fl_sh\'] = 1;
		}
	}
	
	if( $postdb[\'fl_bzc\'] == 1 ){
			$show_str =  "<h1><font color=\"#FF0000\">内容异常！！</font></h1>";
			$postdb[\'nr_xsd\'] = "内容异常！！".round($per,2);//相似度
			$postdb[\'fl_sh\'] = 0;
	}
	
	echo $show_str;
	
	//echo "<br><br><br><br>".$webdb["www_url"];
	
	
	';
	
	//zwj 加入计算文章相似度
	*/
	

	foreach( $array AS $key=>$value){
			
			$strdb[]='`'.$value['field_id'].'`=\'".$postdb[\''.$value['field_id'].'\']."\'';
			$str2=implode(",",$strdb);
			
			if( $value['form_type'] == 'upphoto' )
			{
				$set_str_s_b_photo = '1';//是否有图片缩略图字段存在

				$str_s_b_photo = '$s_b_photo_file = array( $postdb[\'s_'.$value['field_id'].'\'] , $postdb[\'b_'.$value['field_id'].'\'] );
				//$postdb[\'s_fl_photo\']
				//$postdb[\'b_fl_photo\']
				$postdb[\''.$value['field_id'].'\'] = implode( \'@@@\' , $s_b_photo_file ) ;
				';
				/*
				$str_s_b_photo = '$s_b_photo_file = explode( "@@@" , $showdb[\''.$value['field_id'].'\'] );
				$postdb[\'s_'.$value['field_id'].'\'] = $s_b_photo_file[\'0\'];
				$postdb[\'b_'.$value['field_id'].'\'] = $s_b_photo_file[\'1\'];';
				*/
			}elseif( $value['form_type'] == 'checkbox' )
			{
				
				//$str0.= "\$postdb['". $value['field_id'] . "']" ." = addslashes( filtrate( \$postdb['" .$value['field_id'] . "']" ." ) ) ;";
				$str0.= "\$postdb['". $value['field_id'] ."'] = implode('|',\$postdb['". $value['field_id'] ."']);";
		  //$_show      = "\$".$rs['field_id']."   =  \$_POST[\"".$rs['field_id']."\"];\n";
		  //$_show      .= "\$".$rs['field_id']."   =  implode('|',\$".$rs['field_id'].");\n";

			}elseif( $value['form_type'] == 'textarea' )
			{
				
				$str0.= "\$postdb['". $value['field_id'] . "']" ." = addslashes( filtrate( \$postdb['" .$value['field_id'] . "']" ." ) ) ;";

			}elseif( $value['form_type'] == 'ieedit' )
			{
				
				//对地址进行还原
				$str0.= "\$postdb['". $value['field_id'] . "']" ." = str_replace(\$tpbdh_imgUrl2,\$tpbdh_imgUrl,". "\$postdb['" .$value['field_id'] . "']" .") ;";
				
				$str0.= "\$postdb['". $value['field_id'] . "']" ." = addslashes( str_replace('".$webdb['www_url']."','$web126_imgUrl',". "\$postdb['" .$value['field_id'] . "']" .") ) ;";

			}
	}
		//$str=implode(";",$strdb).";";
		
		if( $set_str_s_b_photo == '1' ){//是否有图片缩略图字段存在
			$str = $str_s_b_photo;
		}

		  $str="<?php\n".$str0.$str."\n".$str1.$str2.$str3;

		writetofile_w( $cachefile , $str );
		
		
	include($cachefile);
	
	
	
	//echo $query.'<br><br>';
	
	$result = mysql_query($query) or die(mysql_error());

	
	//删除缓存文件
	//unlink($cachefile);
	return $result;

}




//写入文件,当文件存在时替换
function writetofile_w($filename,$book)
{
$fd=fopen("$filename","w");
fwrite($fd,$book);
fclose($fd);
return true;
}