<?php
/*
 * 注意：此文件由tpl_engine编译型模板引擎编译生成。
 * 如果您的模板要进行修改，请修改 templates/default/modules/mypals/pals_list.html
 * 如果您的模型要进行修改，请修改 models/modules/mypals/pals_list.php
 *
 * 修改完成之后需要您进入后台重新编译，才会重新生成。
 * 如果您开启了debug模式运行，那么您可以省去上面这一步，但是debug模式每次都会判断程序是否更新，debug模式只适合开发调试。
 * 如果您正式运行此程序时，请切换到service模式运行！
 * 
 * 如有您有问题请到官方论坛（http://tech.jooyea.com/bbs/）提问，谢谢您的支持。
 */
?><?php 
	//必须登录才能浏览该页面
	require("foundation/auser_mustlogin.php");
	
	//引入公共模块
	require("foundation/module_mypals.php");
	require("foundation/fpages_bar.php");
	require("api/base_support.php");
	
	//引入语言包
	$mp_langpackage=new mypalslp;
	
	$user_id=get_sess_userid();
	$user_ico=get_sess_userico();
	$sort_id=short_check(get_argg('sort_id'));
	$search_name=short_check(get_argp('search_name'));

	//数据表定义区
	$t_mypals=$tablePreStr."pals_mine";
	$t_pals_sort=$tablePreStr."pals_sort";
	$t_data_count=$tablePreStr."data_count";
	
	//当前页面参数
	$page_num=trim(get_argg('page'));	
	
	$dbo=new dbex;
	dbtarget('r',$dbServs);
	$sort_str='';
	$mp_list_rs=array();
	$mp_sort_list=array();
	$sql="select * from $t_mypals where user_id=$user_id and accepted > 0 ";
	if($sort_id!=''){
		$sql.=" and pals_sort_id = $sort_id ";
	}
	if($search_name!=''){
		$sql.=" and pals_name like '%$search_name%' ";
	}
	$sql.=" order by pals_sort_id desc ";
	$dbo->setPages($set_page_data_num,$page_num);//设置分页
	$mp_list_rs=$dbo->getRs($sql);
	$page_total=$dbo->totalPage;//分页总数
	$mp_sort_list=api_proxy("pals_sort");//取得好友圈分类
	
	//取得好友总数
	$sql="select pals_num from $t_data_count where user_id=$user_id";
	$pals_total=$dbo->getRow($sql);
	
	//取得为分组的好友
	$sql="select count(*) from $t_mypals where pals_sort_id=0 and user_id=$user_id";
	$not_sort_num=$dbo->getRow($sql);
	
	//控制显示
	$show_none_str=$mp_langpackage->mp_sort_pals;
	if($sort_id==''){
		$str=$mp_langpackage->mp_whole;
		$show_none_str=$mp_langpackage->mp_no_pals;
	}
	if($search_name!=''){
		$show_none_str=$mp_langpackage->mp_none_search;
	}
	$none_data="content_none";
	$isNull=0;
	if(empty($mp_list_rs)){
		$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">
<title></title>
<link rel="stylesheet" type="text/css" href="skin/<?php echo $skinUrl;?>/css/row_menus.css">
<link rel="stylesheet" type="text/css" href="skin/<?php echo $skinUrl;?>/css/iframe.css">
<link rel="stylesheet" type="text/css" href="skin/<?php echo $skinUrl;?>/css/user_ico_small.css">
<!--[if lt IE 7]>
<style type="text/css">
.uico_photo_small span { behavior: url(skin/<?php echo $skinUrl;?>/css/ie_png_fix.htc);}
</style>
<![endif]-->
<SCRIPT type='text/javascript' src="servtools/ajax_client/ajax.js"></SCRIPT>
<script type="text/javascript">
parent.guide("mypals");
function check_form(){
	if(document.getElementById("search_name").value==''){
		parent.Dialog.alert("<?php echo $mp_langpackage->mp_import_name;?>");
		return false;
	}
}
function show_sort_list(obj,p_id,old_id){
	var sortwin=document.createElement("div");
	var mypals = 'mypals_iframe';
	var parentnode = document.getElementById('mypals_iframe');
	var t=obj.offsetTop;
  var l=obj.offsetLeft;
  var height=obj.offsetHeight;
  var width=obj.offsetWidth;   
  while(obj=obj.offsetParent){
      t+=obj.offsetTop;   
      l+=obj.offsetLeft;   
  }
	sortwin.id = "sort_select_"+p_id;
	sortwin.className = "sort_select";
	sortwin.style.top = (t-45) + 'px';
	sortwin.style.left = l + 'px';
	<?php foreach($mp_sort_list as $val){?>
		<?php $sort_str.="<li><a href='javascript:void(0);' onclick=changeSort(\"+p_id+\",".$val['id'].",this,\"+old_id+\");>".$val['name']."</a></li>";?>
	<?php }?>
	sortwin.innerHTML = "<div class='sort_sel_box'><ul><?php echo $sort_str;?></ul></div>";
	parentnode.appendChild(sortwin);
	sortwin.focus();
	if(navigator.appName.indexOf("Explorer") > -1){
		sortwin.onblur=function(){window.setTimeout(function(){parentnode.removeChild(sortwin);},200);}
	}else{
		sortwin.onmousedown=function(){window.setTimeout(function(){parentnode.removeChild(sortwin);},200);}
	}
}

function changeSort(p_id,sort_id,obj,old_id){
	if(navigator.appName.indexOf("Explorer") > -1){
		var sortName = obj.innerText;
	}else{
		var sortName = obj.textContent;
	}
	xmlhttp=InitAjax();
	xmlhttp.open("POST","do.php?act=pals_change&id="+p_id,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange=function (){
		if(xmlhttp.readyState==4&&xmlhttp.status==200){
			document.getElementById('sort_name_'+p_id).innerHTML = "<span>"+sortName+"</span>";
		}
	}
	xmlhttp.send("name="+sortName+"&sort_id="+sort_id+"&old_sort_id="+old_id);
}

//0130
function changeStyle(obj,p_id){
	obj.className = 'hover';
}
function recoverStyle(obj,p_id){
	obj.className = '';
}

</script>
</head>
<body>
  <div class="main_right_title">
     <span class="main_title_dot3"></span>
     <span class="main_title_txt"><?php echo $mp_langpackage->mp_mypals;?></span>
  </div>
<div id="tabsB">
  <ul>
    <li><a href="?app=mypals" title="<?php echo $mp_langpackage->mp_list;?>" class="nowbutl"><span class="nowbutr"><?php echo $mp_langpackage->mp_list;?></span></a></li>
    <li><a href="?app=mypals_request" title="<?php echo $mp_langpackage->mp_req;?>"><span><?php echo $mp_langpackage->mp_req;?></span></a></li>
    <li><a href="?app=mypals_invite" title="<?php echo $mp_langpackage->mp_invite;?>"><span><?php echo $mp_langpackage->mp_invite;?></span></a></li>
    <li><a href="?app=mypals_sort" title="<?php echo $mp_langpackage->mp_m_sort;?>"><span><?php echo $mp_langpackage->mp_m_sort;?></span></a></li>
  </ul>
	<div class="div_but" onclick="location.href='?app=mypals_search'"><?php echo $mp_langpackage->mp_add;?></div>
</div>

<!-- mypals start 0128 -->
	<div id="mypals_iframe" class="iframe_contentbox">
	<div class="friend_list guide_info <?php echo $none_data;?>">
		<?php echo $show_none_str;?>
	</div>
	<?php if($mp_list_rs){?>

		<div class="friend_list">
			<div class="clear"></div>
			<ul id="tab0_content0" class="user_list">
				<?php foreach($mp_list_rs as $rs){?>
				<?php $psort_name=$rs['pals_sort_name']?$rs['pals_sort_name']:$mp_langpackage->mp_select_sort;?>
					<li onmouseover='changeStyle(this,<?php echo $rs["id"];?>)' onmouseout='recoverStyle(this,<?php echo $rs["id"];?>)'>
						<div class="photo">
							<a href="home.php?h=<?php echo $rs['pals_id'];?>" target="_blank">
								<img title="<?php echo $mp_langpackage->mp_en_home;?>" src=<?php echo $rs['pals_ico'];?> height='48px' width='48px' onerror="parent.pic_error(this)" />
							</a>
						</div>
						<dl>
							<dt><?php echo $rs['pals_name'];?></dt>
							<dd class="sort"><a href='javascript:void(0)' onclick='show_sort_list(this,<?php echo $rs["pals_id"];?>,<?php echo $rs["pals_sort_id"];?>)' id='sort_name_<?php echo $rs["pals_id"];?>'><span><?php echo $psort_name;?></span></a></dd>
						</dl>
						<div class="tool" id="ctrl_<?php echo $rs['id'];?>">
							<a title="<?php echo $mp_langpackage->mp_del;?>" class="del_bt" href="do.php?act=del_mypals&mypals_id=<?php echo $rs['pals_id'];?>&sort_id=<?php echo $rs['pals_sort_id'];?>" onclick='return confirm("<?php echo $mp_langpackage->mp_a_del;?>")'></a>
							<a class="send_bt" href='modules.php?app=msg_creator&2id=<?php echo $rs["pals_id"];?>' target="frame_content" title='<?php echo str_replace("{he}",get_TP_pals_sex($rs["pals_sex"]),$mp_langpackage->mp_scrip);?>'></a>
						</div>
					</li>
				<?php }?>
			</ul>
		</div>
		<?php }?>


<!--右侧好友列表栏目!-->
	<div class="grouping_list">
		<div class="grouping_top">
			<form action='' method='post' onsubmit='return check_form();'>
				<div class="search"><input id="search_name" autocomplete='off' class="text" type="text" name="search_name" /><input class="button" type="submit" value="<?php echo $mp_langpackage->mp_search;?>" /></div>
			</form>
		</div>
		<div id="grouping_list" class="grouping_ct">
			<div class="grouping_box">
				<div id="all_pals" class="name"><a href="modules.php?app=mypals&type=all"><?php echo $mp_langpackage->mp_whole;?></a></div>
				<div class="num"><?php echo $pals_total['pals_num'];?></div>
			</div>
			<div class="grouping_box">
				<div id="show_sort_0" class="name"><a href="modules.php?app=mypals&sort_id=0"><?php echo $mp_langpackage->mp_no_sort;?></a></div>
				<div class="num"><?php echo $not_sort_num[0];?></div>
			</div>
		<?php foreach($mp_sort_list as $val){?>
			<div class="grouping_box">
				<div id='show_sort_<?php echo $val["id"];?>' class="name"><a href="modules.php?app=mypals&sort_id=<?php echo $val['id'];?>"><?php echo $val['name'];?></div></a>
				<div class="num"><?php echo $val['count'];?></div>
			</div>
		<?php }?>
		</div>
		<div class="grouping_bt"></div>
	</div>
	</div>

<!-- mypals end -->
<div class="clear"></div>
<?php echo page_show($isNull,$page_num,$page_total);?>

<script type='text/javascript'>
	<?php if($sort_id!=''){?>
		document.getElementById("show_sort_<?php echo $sort_id;?>").className='name ico';
	<?php }?>
	<?php if(get_argg('type')=='all'){?>
		document.getElementById("all_pals").className='name ico';
	<?php }?>
</script>

<script type='text/javascript' src="im/ajax.php?act=updatapals"></script>
</body>
</html>