<?php	
define('IN_OUN', true);
include_once( "includes/command.php");
include_once(ROOT_PATH . 'class/cls_image.php');
$image = new cls_image($_CFG['bgcolor']);

$db_table = $pre."admin_user";
//post

if( $_POST['action'] == 'edit'){
    $_POST['user_id'] = $_POST['user_id'] +0;
	/*处理图片*/
	$my_photo = $_POST['old_my_photo'];
	if($_FILES['my_photo']['size'] > 0 )
	{
		/* 判断图像类型 */
        if (!$image->check_img_type_1($_FILES['my_photo']['type']))
        {
            $strMessage =  '图片类型错误';			
        }
		else
		{

	       if(!empty($_POST['old_my_photo']))
	       {
               $my_photo = basename($image->upload_image($_FILES['my_photo'],'myphoto',$_POST['old_my_photo']));
	       }
	       else
	       {
		       $my_photo = basename($image->upload_image($_FILES['my_photo'],'myphoto'));

	       }
		}
	}

	if (trim($_POST['password']) != '')
	{

		$password  = md5(trim($_POST['password'])); 
		$Afields=array('password'=>$password);
        $db_table = $pre."admin_user";
	    if ($_SESSION[$un_auser_id]== $_SESSION[$un_domain_user_id])
	    {
	         $condition = 'user_id='.$_POST['user_id'].' AND domain_id = '.$_SESSION[$un_domain_id];
		}else{
			 $condition = 'user_id='.$_SESSION[$un_auser_id].' AND domain_id = '.$_SESSION[$un_domain_id];
		}
        $oPub->update($db_table,$Afields,$condition);
	}

    /*查询基本资料表是否有此数据*/
    $db_table = $pre."admin_userbase";  
    $sql = "SELECT user_id  FROM ".$db_table."  WHERE  user_id = '".$_SESSION[$un_auser_id]."'";
    $tmp = $oPub->selectrow($sql);
    if($tmp['user_id']>0)
	{    
		$Afields=array('my_name'=>$_POST['my_name'],'idc'=>$_POST['idc'],'email'=>$_POST['email'],'address'=>$_POST['address'],'zipcode'=>$_POST['zipcode'],'sex'=>$_POST['sex'],'mymsn'=>$_POST['mymsn'],'qq'=>$_POST['qq'],'office_phone'=>$_POST['office_phone'],'home_phone'=>$_POST['home_phone'],'mobile_phone'=>$_POST['mobile_phone'],'my_photo'=>$my_photo);
	    if ($_SESSION[$un_auser_id]== $_SESSION[$un_domain_user_id])
	    {
	         $condition = "user_id='".$_POST['user_id']."'";
		}else{
			 $condition = "user_id='".$_SESSION[$un_auser_id]."'";
		}
		
		$oPub->update($db_table,$Afields,$condition);		
	}
	else
	{
        $Afields=array('user_id'=>$_SESSION[$un_auser_id],'my_name'=>$_POST['my_name'],'idc'=>$_POST['idc'],'email'=>$_POST['email'],'address'=>$_POST['address'],'zipcode'=>$_POST['zipcode'],'sex'=>$_POST['sex'],'mymsn'=>$_POST['mymsn'],'qq'=>$_POST['qq'],'office_phone'=>$_POST['office_phone'],'home_phone'=>$_POST['home_phone'],'mobile_phone'=>$_POST['mobile_phone'],'my_photo'=>$my_photo,'domain_id'=>$_SESSION[$un_domain_id]);
        $oPub->install($db_table,$Afields);        
	}	
	$strMessage .= "修改设置成功！";
}

//get
$db_table = $pre."admin_user";
$sql = "SELECT a.user_id,a.user_name 
	       FROM ".$pre."admin_user as a  
		   WHERE  a.user_id = '".$_SESSION[$un_auser_id]. "' 
		   AND a.domain_id='".$_SESSION[$un_domain_id]."'";		   
$Auser = $oPub->selectrow($sql);
$sql = "SELECT b.my_name,b.idc,b.email,b.address,b.zipcode,b.sex,
	    b.mymsn,b.qq,b.office_phone,b.home_phone,b.mobile_phone,b.my_photo  
	    FROM ".$pre."admin_userbase  as b   
		WHERE  b.user_id = '".$Auser['user_id']."'";
$Auser_base = $oPub->selectrow($sql);
if(is_array($Auser_base))
{
		$Auser = $Auser + $Auser_base;
}
unset($Auser_base);
?>
<?php
   include_once( "header.php");
?>
<?php
if ($strMessage != '')
{
     echo  '<SCRIPT language="javascript"> alert( "'.$strMessage.'");</script>';
}
?>
<DIV class=content>
<TABLE width="99%" border=0>
  <TR class="odd" >
  <form name="form1" method="post" action="" enctype="multipart/form-data"> 
    <TD width="13%" align="left" colspan="3">
	    <span>登陆帐号:</span>
        <?php echo ($Auser['user_id'])?$Auser['user_name']:''?>
        <span>登陆密码:</span>
		<input name="password" type="text" size="12" value="" />
        <br/><span>　　姓名:</span>
		<input name="my_name" type="text" size="12" value="<?php echo ($Auser['user_id'])?$Auser['my_name']:''?>" />
	    <span>　　性别:</span>
		 <SELECT NAME="sex">
			<OPTION VALUE="1" <?php echo ($Auser['sex'] == 1)?'SELECTED':''?>>男</OPTION>
			<OPTION VALUE="0" <?php echo ($Auser['sex'] != 1)?'SELECTED':''?>>女</OPTION>
		</SELECT>
		<span>　身份证:</span>
		<input name="idc" type="text" size="20" value="<?php echo ($Auser['user_id'])?$Auser['idc']:''?>" />

		<br/><span>　邮　编:</span>
		<input name="zipcode" type="text" size="12" value="<?php echo ($Auser['user_id'])?$Auser['zipcode']:''?>" />
        <span>通讯地址:</span>
		<input name="address" type="text" size="62" value="<?php echo ($Auser['user_id'])?$Auser['address']:''?>" />

        <br/>
		<span>办公电话:</span>
        <input name="office_phone" type="text" size="12" value="<?php echo ($Auser['user_id'])?$Auser['office_phone']:''?>" />
		<span>家庭电话:</span>
		<input name="home_phone" type="text" size="12" value="<?php echo ($Auser['user_id'])?$Auser['home_phone']:''?>" />
		<span>手机:</span>
		<input name="mobile_phone" type="text" size="12" value="<?php echo ($Auser['user_id'])?$Auser['mobile_phone']:''?>" />

		<BR/>
		<span> 　EMAIL:</span>
		<input name="email" type="text" size="22" value="<?php echo ($Auser['user_id'])?$Auser['email']:''?>" />
		<span>　M S N:</span>
		<input name="mymsn" type="text" size="22" value="<?php echo ($Auser['user_id'])?$Auser['mymsn']:''?>" />
		   QQ:
		 <input name="qq" type="text" size="12" value="<?php echo ($Auser['user_id'])?$Auser['qq']:''?>" />
		<br/>
		<span style="font-weight: bold">个人照片:</span>
		<INPUT type="file" name="my_photo" size="20" /> 
	    <?php
	   if(!empty($Auser['my_photo']))
	   {	
		$tmp = '<A HREF="../data/myphoto/'.$Auser['my_photo'].'" target="_blank">'; 
		$tmp .= '<IMG SRC="images/icon_view.gif" WIDTH="16" HEIGHT="16" BORDER="0" ALT="查看图片"></A> ';
		echo $tmp;
	   }
	?>		
		(注：支持：.jpg .gif .png 格式)
		<INPUT type="hidden" name="old_my_photo"  value="<?php echo ($Auser['user_id'])?$Auser['my_photo']:'';?>" />
		<br/>

        <input type="hidden" name="action" value="<?php echo ($Auser['user_id'])?'edit':'add'?>" />        
		<input type="hidden" name="user_id" value="<?php echo ($Auser['user_id'])?$Auser['user_id']:''?>" /> 
		<input type="submit" name="Submit" value="<?php echo ($Auser['user_id'])?'编辑修改':'增加新用户'?>" style="background-color: #FFCC66;margin-left: 50px"/>


    </TD>
    </form>
  </TR>	

  <TR class=bg5>
    <TD colspan="3" align=right>

	</TD>
  </TR>
</TABLE>
 
</DIV>
	
<?php
include_once( "footer.php");
?>