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

	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	//当前页面参数
	$page_num=trim(get_argg('page'));
	
	//变量区
	$c_albumid=intval(short_check(get_argg('albumid')));
	$c_albumname=short_check(get_argg('albumname'));
	$c_uid=intval(short_check(get_argg('uid')));
	$c_username=short_check(get_argg('username'));
	$c_friend=short_check(get_argg('friend')); 
	$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_album where 1=1 ";
	
	if(!empty($c_uid)){
		$sql.=" and user_id = $c_uid ";
	}
	if(!empty($c_username)){
		$sql.=" and user_name = '$c_username' ";
	}		
	if(!empty($c_albumid)){
		$sql.=" and album_id = $c_albumid ";
	}
	if($c_friend !=""){
		$sql.=" and album_secret = $c_friend ";
	}
	if(!empty($c_albumname)){
		$sql.=" and album_name like '%$c_albumname%' ";
	}
	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);//设置分页
	$album_rs=$dbo->getRs($sql);
	$page_total=$dbo->totalPage;//分页总数
	
	//条件显示
	
	//访问权限
	$l_no_limit='';$l_public='';$l_pals='';$l_pri='';
	if(get_argg('friend')==''){$l_no_limit="selected";}
	if(get_argg('friend')=="0"){$l_public="selected";}
	if(get_argg('friend')=="1"){$l_pals="selected";}
	if(get_argg('friend')=="2"){$l_pri="selected";}
	
	//按字段排序
	$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($album_rs)){
		$isset_data="content_none";
		$none_data="";
		$isNull=1;
	}
	
?>
<!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_album(album_id,user_id)
{
	 create_xmlhttp();
	 xmlhttp.open("GET","album_del.action.php?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_"+album_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(album_id,type_value)
{
	create_xmlhttp();
	xmlhttp.open("GET","album_lock.action.php?album_id="+album_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_"+album_id).style.display="";
				document.getElementById("lock_button_"+album_id).style.display="none";
			}else{
				str="<?php echo $m_langpackage->m_normal?>";
				document.getElementById("unlock_button_"+album_id).style.display="none";
				document.getElementById("lock_button_"+album_id).style.display="";
			}
			window.document.getElementById("state_"+album_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_album_name?><font color=red>*</font></th>
<td width=30%><input type="text" name="albumname" value="<?php echo get_argg('albumname');?>" /></td>
<th width=10%><?php echo $m_langpackage->m_public_pro?></th>
<td width=*>
<select name="friend">
	<OPTION value="" <?php echo $l_no_limit;?>><?php echo $m_langpackage->m_astrict_no?></OPTION>
    <OPTION value="0" <?php echo $l_public;?>><?php echo $m_langpackage->m_public?></OPTION>
    <OPTION value="1" <?php echo $l_pals;?>><?php echo $m_langpackage->m_only?></OPTION> 
    <OPTION value="2" <?php echo $l_pri;?>><?php echo $m_langpackage->m_only_self?></OPTION>
</select>	
</td>
</tr>
<tr>
<th><?php echo $m_langpackage->m_album_id?></th>
<td>
<input type="text" name="albumid" value="<?php echo get_argg('albumid');?>" />
</td>
<th><?php echo $m_langpackage->m_creat_time?></th>
<td colspan="3">
<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_author_id?></th>
<td><input type="text" name="uid" value="<?php echo get_argg('uid');?>" /></td>
<th><?php echo $m_langpackage->m_author_name?></th>
<td><input type="text" name="username" value="<?php echo get_argg('username');?>" /></td>
</tr>
 
<tr>
<tr><th><?php echo $m_langpackage->m_result_order?></th>
<td colspan="3">
<select name="orderby">
	<OPTION value="album_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>
    <OPTION value='photo_num' <?php echo $o_hits;?>><?php echo $m_langpackage->m_pho_num?></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_alb_list?></div>
</div>

<form method="post" action="">
<table border="0" class='main <?php echo $isset_data;?>'>
<?php 
$isNull=1;
$i=0;
foreach($album_rs as $val){
	$isNull=0;
	if($i%2==0){
		if($i>0){ echo "</tr>"; }
		echo "<tr>";
	}
?>
<td width="15%">
<a href="photo_list.php?albumid=<?php echo $val['album_id'];?>"><img src="../<?php echo $val['album_skin'];?>" width="100" ></a></td>
<td width="20%" style='text-align:left'>
 <?php echo $m_langpackage->m_album_name?>：<?php echo $val['album_name'];?>
<br/>
<?php echo $m_langpackage->m_author_name?>: <a href="../home.php?h=<?php echo $val['user_id'];?>" target="_blank"><?php echo $val['user_name'];?></a>
<br/>
<?php echo $m_langpackage->m_time?>: <?php echo $val['add_time'];?>
<br/>
<a href="comment_list.php?idtype=albid&conid=<?php echo $val['album_id'];?>"><?php echo $m_langpackage->m_admin_com?></a>
</td>
<td>
<span id="state_<?php echo $val['album_id'];?>"><?php if($val['album_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['album_id'];?>">
<a href='javascript:del_album(<?php echo $val['album_id'];?>,<?php echo $val['user_id'];?>);' title="<?php echo $m_langpackage->m_del?>" alt="<?php echo $m_langpackage->m_del?>" onclick='return confirm("<?php echo $m_langpackage->m_ask_del?>");'><img src='images/del.png' /></a>
<?php $unlock="display:none";$lock=""; if($val['album_pass']==0){$unlock="";$lock="display:none";}?>
<span id="unlock_button_<?php echo $val['album_id'];?>" style="<?php echo $unlock;?>"><a href="javascript:lock_member(<?php echo $val['album_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['album_id'];?>" style="<?php echo $lock;?>"><a href="javascript:lock_member(<?php echo $val['album_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>
