<?php 
//引入语言包
	$mp_langpackage=new mypalslp;

//引入小纸条模块功能
	require("foundation/adata_count.php");
	require("foundation/module_scrip.php");	
	
//变量区
  $user_id=get_sess_userid();
  $user_name=get_sess_username();
  $userico=get_sess_userico();
  $req_id=short_check(get_argg('req_id'));
  $req_user_id=short_check(get_argg('req_user_id'));
  $my_pals=get_sess_mypals();
	$my_pals=",".$my_pals.",";
	
//数据表定义区
		$t_mypals=$tablePreStr."pals_mine";
		$t_pals_request=$tablePreStr."pals_request";
		$dbo=new dbex();

		dbtarget('w',$dbServs);
    if(preg_match("/,$req_user_id,/",$my_pals)){
		  $sql="update $t_mypals set accepted=2 where user_id=$req_user_id and pals_id=$user_id";
		  $dbo->exeUpdate($sql);
		  $sql="update $t_mypals set accepted=2 where user_id=$user_id and pals_id=$req_user_id";
			$dbo->exeUpdate($sql);
		  $sql="delete from $t_pals_request where user_id=$user_id and id=$req_id";
		  $dbo->exeUpdate($sql);
   	 }else{
			dbtarget('r',$dbServs);	
			$sql="select * from $t_pals_request where user_id=$user_id and id=$req_id";
			$req_user_row=$dbo->getRow($sql);
		  $res_uid=$req_user_row["req_id"];
		  $res_uname=$req_user_row["req_name"];
		  $res_usex=$req_user_row["req_sex"];
		  $res_rpid=$req_user_row["from_id"];
		  $res_ico=$req_user_row["req_ico"];			
			dbtarget('w',$dbServs); 
		  $sql="insert into $t_mypals (user_id,pals_id,pals_name,pals_sex,add_time,accepted,pals_ico)"
		                         ."value($user_id,$res_uid,'$res_uname','$res_usex',NOW(),2,'$res_ico')";
		  $dbo->exeUpdate($sql);
		  $sql="delete from $t_pals_request where user_id=$user_id and id=$req_id";
		  $dbo->exeUpdate($sql);
		  $sql="update $t_mypals set accepted=2 where user_id=$req_user_id and pals_id=$user_id";
			$dbo->exeUpdate($sql);
		  $sql="update $t_mypals set accepted=2 where user_id=$user_id and pals_id=$req_user_id";
			if($dbo->exeUpdate($sql)){
				update_count($dbo,$user_id,"pals_num",1);
			}
			$my_pals='';
			if(get_sess_mypals()){
				 $my_pals=get_sess_mypals().','.$req_user_id;
			}else{
				 $my_pals=$req_user_id;
			}
			set_sess_mypals($my_pals);
		}
		send_scrip($dbo,$user_name,$user_id,$userico,$req_user_id,0);
		update_count($dbo,$req_user_id,"pals_num",1);
//刷新提醒页面
        echo "<script type='text/javascript'>
  parent.frames['remind'].location.reload();
  </script>";

//缓存功能区
      require($webRoot.$baseLibsPath."action/mypals_update.action.cache.php");
			action_return(0,'',"");
?>  