<?php 
	require("session_check.php");	
	require("../foundation/fpages_bar.php");
	
	//语言包引入
	$m_langpackage=new modulelp;
	
	//数据表定义区
	$t_photo=$tablePreStr."photo";

	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	//当前页面参数
	$page_num=trim(get_argg('page'));
	
	//变量区
	$c_albumid=intval(short_check(get_argg('albumid')));
	$c_uid=intval(short_check(get_argg('uid')));
	$c_picid=intval(short_check(get_argg('picid')));
	$c_filename=short_check(get_argg('filename'));
	$c_title=short_check(get_argg('title')); 
	$c_dateline1=short_check(get_argg('dateline1')); 
	$c_dateline2=short_check(get_argg('dateline2'));
	$c_orderby=short_check(get_argg('orderby'));
	$c_ordersc=short_check(get_argg('ordersc')); 
	$c_perpage=get_argg('perpage') ? intval(short_check(get_argg('perpage'))):20;
	

	$sql="select * from $t_photo where 1=1 ";
	
	if(!empty($c_picid)){
		$sql.=" and photo_id = $c_picid ";
	}
	if(!empty($c_filename)){
		$sql.=" and photo_name like '%$c_filename%' ";
	}		
	if(!empty($c_albumid)){
		$sql.=" and album_id = $c_albumid ";
	}
	if(!empty($c_title)){
		$sql.=" and photo_information like '%$c_title%' ";
	}
	if(!empty($c_uid)){
		$sql.=" and user_id = $c_uid ";
	}
	if(!empty($c_dateline1)){
		$sql.=" and date(add_time) >= '$c_dateline1' ";
	}
	if(!empty($c_dateline2)){
		$sql.=" and date(add_time) <= '$c_dateline2' ";
	}
	if(!empty($c_orderby)){
		$sql.=" order by $c_orderby ";
	}
		
	$sql.=" $c_ordersc ";
		
	$dbo->setPages($c_perpage,$page_num);//设置分页
	$photo_rs=$dbo->getRs($sql);
	$page_total=$dbo->totalPage;//分页总数
	
	//条件显示
	
	//按字段排序
	$o_def='';$o_add_time='';$o_hits='';
	if(!get_argg('orderby')||get_argg('order_by')=="album_id"){$o_def="selected";}
	if(get_argg('orderby')=="add_time"){$o_add_time="selected";}
	if(get_argg('orderby')=="photo_num"){$o_hits="selected";}
	
	//排列方式
	$sc_desc='';$sc_asc='';
	if(get_argg('ordersc')=="desc"){$sc_desc="selected";}
	if(!get_argg('ordersc')||get_argg('ordersc')=="asc"){$sc_asc="selected";}
	
	//分页显示条数
	$p_20='';$p_50='';$p_100='';
	if(!get_argg('perpage')||get_argg('perpage')=="20"){$p_20="selected";}
	if(get_argg('perpage')=="50"){$p_50="selected";}
	if(get_argg('perpage')=="100"){$p_100="selected";}
	
	//显示控制
	$isset_data="";
	$none_data="content_none";
	$isNull=0;
	if(empty($photo_rs)){
		$isNull=1;
		$isset_data="content_none";
		$none_data="";
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/right.css">
<title>无标题文档</title>
</head>
<script type='text/javascript' src='../servtools/calendar.js'></script>
<script type='text/javascript'>
function create_xmlhttp()
{
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlhttp=new XMLHttpRequest();
	}
}
function del_pht(photo_id,album_id,user_id)
{
	 create_xmlhttp();
	 xmlhttp.open("GET","photo_del.action.php?pid="+photo_id+"&aid="+album_id+"&uid="+user_id,true);
	 xmlhttp.onreadystatechange=function(){
		 if(xmlhttp.readyState==4&&xmlhttp.status==200){
		 	var return_str=xmlhttp.responseText;
			var	return_text=return_str.replace(/[\s\n\r]/g,"");
		 	window.document.getElementById("operate_"+photo_id).innerHTML=return_text;
	 	 }
	 }
	 xmlhttp.send(null);
}
function check_form()
{
	var dateline1=document.getElementById("dateline1").value;
	var dateline2=document.getElementById("dateline2").value;
	var time_format=/\d{4}\-\d{2}\-\d{2}/;
	if(dateline1){
		if(!time_format.test(dateline1)){
			alert("<?php echo $m_langpackage->m_date_wrong?>");
			return false;
		}
	}

	if(dateline2){
		if(!time_format.test(dateline2)){
			alert("<?php echo $m_langpackage->m_date_wrong?>");
			return false;
		}
	}
}
function lock_member(photo_id,type_value)
{
	create_xmlhttp();
	xmlhttp.open("GET","photo_lock.action.php?photo_id="+photo_id+"&type_value="+type_value,true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4&&xmlhttp.status==200){
			if(type_value==0){
				str="<font color='red'><?php echo $m_langpackage->m_lock?></font>";
				document.getElementById("unlock_button_"+photo_id).style.display="";
				document.getElementById("lock_button_"+photo_id).style.display="none";
			}else{
				str="<?php echo $m_langpackage->m_normal?>";
				document.getElementById("unlock_button_"+photo_id).style.display="none";
				document.getElementById("lock_button_"+photo_id).style.display="";
			}
			window.document.getElementById("state_"+photo_id).innerHTML=str;
		}
	}
	xmlhttp.send(null);
}
</script>
<body>
<div class="container">
	<div class="rs_head"><?php echo $m_langpackage->m_check_condition?></div>
</div>

<form method="get" action=""  onsubmit="return check_form()">
<TABLE class="main main_left">
<tr>
<th width=12%><?php echo $m_langpackage->m_alb_id?></th><td width=30%><input type="text" name="albumid" value="<?php echo get_argg('albumid');?>" /></td>
<th width=10%><?php echo $m_langpackage->m_author_id?></th><td width=*><input type="text" name="uid" value="<?php echo get_argg('uid');?>" /></td>
</tr>
<tr>
<th><?php echo $m_langpackage->m_pho_id?></th><td><input type="text" name="picid" value="<?php echo get_argg('picid');?>" /></td>
<th><?php echo $m_langpackage->m_upd_time?></th>
<td>
<input type="text" name="dateline1" AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' value="<?php echo get_argg('dateline1');?>" size="10" /> ~
<input type="text" name="dateline2" AUTOCOMPLETE=off onclick='getDateString(this,oCalendarChs)' value="<?php echo get_argg('dateline2');?>" size="10" /> (格式为: YYYY-MM-DD)
</td>
</tr>
<tr>
<th><?php echo $m_langpackage->m_pho_inf?><font color=red>*</font></th><td><input type="text" name="title" value="<?php echo get_argg('title');?>" /></td>	
</tr>
 
<tr><th><?php echo $m_langpackage->m_result_order?></th>
<td colspan="3">
<select name="orderby">
	<OPTION value="photo_id" <?php echo $o_def;?>><?php echo $m_langpackage->m_def_order?></OPTION>
	<OPTION value='add_time' <?php echo $o_add_time;?>><?php echo $m_langpackage->m_creat_time?></OPTION>
</select>
<select name="ordersc">
    <OPTION value='asc' <?php echo $sc_asc;?>><?php echo $m_langpackage->m_asc?></OPTION>
    <OPTION value='desc' <?php echo $sc_desc;?>><?php echo $m_langpackage->m_desc?></OPTION>
</select>
<select name='perpage'>
    <option value='20' <?php echo $p_20;?>><?php echo $m_langpackage->m_page_20?></option>
    <option value='50' <?php echo $p_50;?>><?php echo $m_langpackage->m_page_50?></option>
    <option value='100' <?php echo $p_100;?>><?php echo $m_langpackage->m_page_100?></option>
</select>
<input type="submit" name="searchsubmit" value="<?php echo $m_langpackage->m_search?>" class="submit">
</td>
</tr>
<tr><td colspan=2><?php echo $m_langpackage->m_red?></td></tr>
</table>
</form>

<div class="container">
	<div class="rs_head"><?php echo $m_langpackage->m_pho_list?></div>
</div>

<form method="post" action="">
<table border="0" class='main <?php echo $isset_data;?>'>
<?php 
$isNull=1;
$i=0;
foreach($photo_rs as $val){
	$isNull=0;
	if($i%2==0){
		if($i>0){ echo "</tr>"; }
		echo "<tr>";
	}
?>
<td width="15%">
<a href="../<?php echo $val['photo_src'];?>" target="_blank"><img src="../<?php echo $val['photo_src'];?>"  width="100"></img></a>
</td>
<td width="20%" style='text-align:left'>
<?php echo $m_langpackage->m_alb_id?>：album_id-<?php echo $val['album_id'];?>
<br />
<?php echo $m_langpackage->m_author_id?>：<a href="../home.php?h=<?php echo $val['user_id'];?>" target="_blank">user_id-<?php echo $val['user_id'];?></a>
<br />
<?php echo $m_langpackage->m_pho_inf?>：<?php echo $val['photo_information'];?>
<br />
<?php echo $m_langpackage->m_time?>: <?php echo $val['add_time'];?><br>
<a href="comment_list.php?idtype=picid&conid=<?php echo $val['photo_id'];?>"><?php echo $m_langpackage->m_com_admin?></a>
</td>
<td>
<span id="state_<?php echo $val['photo_id'];?>"><?php if($val['photo_pass']==1)echo $m_langpackage->m_normal;else echo "<font color='red'>$m_langpackage->m_lock</font>";?></span>
</td>
<td width="*" style='text-align:left'>
<div id="operate_<?php echo $val['photo_id'];?>">
<a href='javascript:del_pht(<?php echo $val['photo_id'];?>,<?php echo $val['album_id'];?>,<?php echo $val['user_id']?>);' onclick='return confirm("<?php echo $m_langpackage->m_ask_del?>");'><img src='images/del.png' /></a>
<?php $unlock="display:none";$lock=""; if($val['photo_pass']==0){$unlock="";$lock="display:none";}?>
<span id="unlock_button_<?php echo $val['photo_id'];?>" style="<?php echo $unlock;?>"><a href="javascript:lock_member(<?php echo $val['photo_id'];?>,1);"><img title="<?php echo $m_langpackage->m_unlock?>" alt="<?php echo $m_langpackage->m_unlock?>" src="images/unlock.png" /></a></span><span id="lock_button_<?php echo $val['photo_id'];?>" style="<?php echo $lock;?>"><a href="javascript:lock_member(<?php echo $val['photo_id'];?>,0);" onclick="return confirm('<?php echo $m_langpackage->m_ask_lock?>');"><img title="<?php echo $m_langpackage->m_lock?>" alt="<?php echo $m_langpackage->m_lock?>" src="images/lock.png" /></a></span>
</div>
</td>
<?php 
	$i++;
}
?>
</tr>
<tr>
	<td colspan=5 style="text-align:'right'">
	<?php
		page_show($isNull,$page_num,$page_total);
	?>
	</td>
</tr>
</table>
</form>
<div class='guide_info <?php echo $none_data;?>'><?php echo $m_langpackage->m_none_data?></div>
</body>
</html>
