<?php

define('CURSCRIPT', 'panel');

require_once './engine/common.inc.php';

if($_GSESSION['gid']==4 || !$_GSESSION['gid']){
	showmsg("访问被禁止");
}
if(!in_array($action,array('','deletemsg','update','changepwd','panel'))){
	showmsg("参数有误");
}
if(!in_array($ipart,array('','msglist','msgcontent','memberinfo','memberpwd'))){
	showmsg("参数有误");
}


if($action=="deletemsg"){
	if($_POST['check_uid']!=$uid){
		showmsg("不能删除别人的消息");
	}
	$msg_check_str=implode(",",$msg_check);
	$db->query("delete from g_member_msg where mmid in ($msg_check_str)");
	$newmsgcount=$newmsgcount?$newmsgcount-count($msg_check):0;
	$db->query("update g_sessions set newmsgcount = $newmsgcount where uid=$uid");
	showmsg("消息删除成功","panel.php?ipart=msglist",1);
}

if($action=="update"){

if(strlen($modify_username)>50){
	showmsg("用户姓名不能超出50字符");
}
if(!isemail($modify_email)){
	showmsg("请输入正确的email账号");
}
if(empty($modify_username) || strlen($modify_username)>50){
	showmsg("用户名不能为空");
}
if(strlen($modify_phone)>20 || strlen($modify_mobile)>20 || strlen($modify_qq)>20 || strlen($modify_address)>200){
	showmsg("电话,手机,qq,地址信息不能超出指定范围值");
}

  $db->query("update g_members a , g_member_info b set a.username='$modify_username' , a.email='$modify_email' , b.sex=$modify_sex , b.phone='$modify_phone' , b.mobile='$modify_mobile' , b.qq='$modify_qq' , b.address='$modify_address' , a.userface='$modify_userface' where a.uid=$modify_uid and a.uid=b.uid");
  showmsg("个人信息修改成功","panel.php?ipart=memberinfo",1);
}
if($action=="changepwd"){
	if(empty($new_userpwd)||empty($confirm_userpwd)){
		showmsg("密码不能为空");
	}
	if(strlen($new_userpwd)<6||strlen($confirm_userpwd)<6){
		showmsg("密码长度不能小于六位");
	}
	if(strlen($new_userpwd)>20||strlen($confirm_userpwd)>20){
		showmsg("密码长度不能大于二十位");
	}
	if(strcmp($new_userpwd,$confirm_userpwd)){
		showmsg("两次输入的密码不一致");
	}
	$change_userpwd=md5($new_userpwd);
    $db->query("update g_members set userpwd = '$change_userpwd' where uid=$change_uid");
	 showmsg("个人密码修改成功","panel.php?ipart=msglist",1);
}

if($ipart=='msglist'){
	$membermsgs=array();
	$pagerecords=15;
	$i=0;
	$curpage=isset($page)?$page:1;
	$startrecord=($curpage-1)*$pagerecords;
	$totalrecord=$db->result($db->query("SELECT count(*) FROM g_member_msg where uid=$uid"),0);
	$q=$db->query("select * from g_member_msg where uid=$uid order by sendtime desc limit $startrecord,$pagerecords");
	$multipage=multi($totalrecord, $pagerecords , $curpage, "panel.php?ipart=msglist");
	$i=0;
	while($membermsg=$db->fetch_array($q)){
		$membermsg['checkid']=$i;
		if(!$membermsg['readed']){
			$membermsg['title']="<b>".$membermsg['title']."</b>";
		}
		$membermsgs[$membermsg['mmid']]=$membermsg;
		$i++;
	}
 }
 if($ipart=='msgcontent'){
	 require_once './engine/gateweicode.func.php';
	 $msgid=intval($msgid);
	 $q=$db->query("select * from g_member_msg where mmid=$msgid");
	 $db->query("update g_member_msg set readed=1 where mmid=$msgid");
	 $newmsgcount=$newmsgcount?$newmsgcount-1:0;
	 $db->query("update g_sessions set newmsgcount = $newmsgcount where uid=$uid");
	 if(!$membermsgbody=$db->fetch_array($q)){
		showmsg("查询有误");
	 }
	 $message=gateweicode($membermsgbody['content']);
 }
  if($ipart=='memberinfo'){
		$q=$db->query("select * from g_members a ,g_member_info b where a.uid=$uid and a.uid=b.uid");
		$memberinfo=$db->fetch_array($q);
		$sexcheck=array('','','');
		$sexcheck[$memberinfo['sex']]='checked';
  }
include($templatedir."panel.tpl.php");
