clients.xml:
<?xml version="1.0" encoding="UTF-8"?>
<client>
<people>
<name>小李</name>
<age>30</age>
<profession>互联网</profession>
<addr>广州市天河区塘东</addr>
<tel>1326585512</tel>
</people>
<person><name>526547895</name><age/><profession/><addr/><tel/></person><person><name>小强</name><age>12</age><profession>保险</profession><addr>深圳</addr><tel>526547895</tel></person></client>
config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<user>
<admin>
<uname>admin</uname>
<pword>admin</pword>
</admin>
<admin>
<uname>admin</uname>
<pword>123456</pword>
</admin>
</user>
add.php:
<?php
session_start();
if(!isset($_SESSION['user'])){header('Content-type:text/html;charset=utf-8') ;header('Refresh:3;url=login.php');echo '未登录!';exit; };
if(isset($_GET['act'])){
if($_GET['act']=="add"){
if(isset($_GET['do'])){
$name=$_POST['name']?$_POST['name']:'';
$age=$_POST['age']?$_POST['age']:'';
$profession=$_POST['profession']?$_POST['profession']:'';
$addr=$_POST['addr']?$_POST['addr']:'';
$tel=$_POST['tel']?$_POST['tel']:'';
$xml=simplexml_load_file('clients.xml');
$id=$_GET['id']?$_GET['id']:'1';
$xml->people[$id-1]->name=$name;
$xml->people[$id-1]->age=$age;
$xml->people[$id-1]->profession=$profession;
$xml->people[$id-1]->addr=$addr;
$xml->people[$id-1]->tel=$tel;
$xml->asXML('clients.xml');
echo "修改成功!";
}else{
$name=$_POST['name']?$_POST['name']:'';
$age=$_POST['age']?$_POST['age']:'';
$profession=$_POST['profession']?$_POST['profession']:'';
$addr=$_POST['addr']?$_POST['addr']:'';
$tel=$_POST['tel']?$_POST['tel']:'';
$xml=simplexml_load_file('clients.xml');
$person=$xml->addChild('people');
$person->addChild('name',$name);
$person->addChild('age',$age);
$person->addChild('profession',$profession);
$person->addChild('addr',$addr);
$person->addChild('tel',$tel);
$xml->asXML('clients.xml');
echo "添加成功!";
}
}elseif($_GET['act']=="edit"){
$xml=simplexml_load_file('clients.xml');
$id=$_GET['id']?$_GET['id']:'1';
$name=$xml->people[$id-1]->name;
$age=$xml->people[$id-1]->age;
$profession=$xml->people[$id-1]->profession;
$addr=$xml->people[$id-1]->addr;
$tel=$xml->people[$id-1]->tel;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>添加客户</h3>
<form action="?act=add
<?php if(isset($_GET['act'])){if($_GET['act']=="edit"){echo "&do=edit&id={$id}";};}?>
" method="post" enctype="multipart/form-data">
<table width="70%" border="1" cellpadding="5" cellspacing="0" bgcolor="#cccccc">
<tr>
<td align="right">姓名</td>
<td><input type="text" name="name" placeholder="" value='<?php echo isset($name)?$name:'';?>'/></td>
</tr>
<tr>
<td align="right">年龄</td>
<td><input name="age" value='<?php echo isset($age)?$age:'';?>'/></td>
</tr>
<tr>
<td align="right">行业</td>
<td><input value='<?php echo isset($profession)?$profession:'';?>' type="text" name="profession" placeholder=""/></td>
</tr>
<tr>
<td align="right">地址</td>
<td><input value='<?php echo isset($addr)?$addr:'';?>' type="text" name="addr" placeholder=""/></td>
</tr>
<tr>
<td align="right">电话</td>
<td><input value='<?php echo isset($tel)?$tel:'';?>' type="text" name="tel" placeholder=""/></td>
</tr>
<tr>
<td colspan="4"><input type="submit" value="添加用户"/></td>
</tr>
</table>
</form>
</body>
</html>
index.php:
<?php session_start();
if(!isset($_SESSION['user'])){header('Content-type:text/html;charset=utf-8') ;header('Refresh:3;url=login.php');echo '未登录!';exit; };?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>-.-</title>
<link rel="stylesheet" href="styles/backstage.css">
</head>
<body>
<div class="head">
<div class="logo fl"><a href="#"></a></div>
<h3 class="head_text fr">客户关系管理系统</h3>
</div>
<div class="operation_user clearfix">
<!-- <div class="link fl"><a href="#">慕课</a><span>>></span><a href="#">商品管理</a><span>>></span>商品修改</div>-->
<div class="link fr">
<b>欢迎您
</b> <a href="#" class="icon icon_i">首页</a><span></span><a href="#" class="icon icon_j">前进</a><span></span><a href="#" class="icon icon_t">后退</a><span></span><a href="#" class="icon icon_n">刷新</a><span></span><a href="login.php?act=logout" class="icon icon_e">退出</a>
</div>
</div>
<div class="content clearfix">
<div class="main">
<!--右侧内容-->
<div class="cont">
<div class="title">后台管理</div>
<!-- 嵌套网页开始 -->
<iframe src="main.php" frameborder="0" name="mainFrame" width="100%" height="522"></iframe>
<!-- 嵌套网页结束 -->
</div>
</div>
<!--左侧列表-->
<div class="menu">
<div class="cont">
<div class="title">管理员</div>
<ul class="mList">
<li>
<h3><span οnclick="show('menu1','change1')" id="change1">+</span>客户管理</h3>
<dl id="menu1" style="display:none;">
<dd><a href="main.php" target="mainFrame">客户列表</a></dd>
<dd><a href="add.php" target="mainFrame">添加客户</a></dd>
</dl>
</li>
</ul>
</div>
</div>
</div>
<script type="text/javascript">
function show(num,change){
var menu=document.getElementById(num);
var change=document.getElementById(change);
if(change.innerHTML=="+"){
change.innerHTML="-";
}else{
change.innerHTML="+";
}
if(menu.style.display=='none'){
menu.style.display='';
}else{
menu.style.display='none';
}
}
</script>
</body>
</html>
login.php
<?php
session_start();
if(isset($_GET['act'])){if($_GET['act']=='logout'){session_destroy();}};
if(isset($_POST['submit'])){
$uname=isset($_POST['username'])?$_POST['username']:0;
$pword=isset($_POST['password'])?$_POST['password']:0;
//echo $uname.$pword;
if(!$uname || !$pword){$err='账号密码不能为空';}else{
$xml=simplexml_load_file('config.xml');
foreach($xml->admin as $v){
if($v->uname==$uname && $v->pword==$pword){
$_SESSION['user']=$uname;
$err= '登陆成功';
header('Refresh:3;url=index.php');
}
}
$err=isset($err)?$err:'账号或密码不正确';
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>登陆</title>
<link type="text/css" rel="stylesheet" href="styles/reset.css">
<link type="text/css" rel="stylesheet" href="styles/main.css">
<!--[if IE 6]>
<script type="text/javascript" src="../js/DD_belatedPNG_0.0.8a-min.js"></script>
<script type="text/javascript" src="../js/ie6Fixpng.js"></script>
<![endif]-->
</head>
<body>
<div class="headerBar">
<div class="logoBar login_logo">
<div class="comWidth">
<div class="logo fl">
</div>
<h3 class="welcome_title">欢迎登陆客户关系管理系统</h3>
</div>
</div>
</div>
<div class="loginBox">
<div class="login_cont">
<form action="login.php" method="post">
<ul class="login">
<li class="l_tit">管理员帐号</li>
<li class="mb_10"><input type="text" name="username" placeholder="请输入管理员帐号"class="login_input user_icon"></li>
<li class="l_tit">密码</li>
<li class="mb_10"><input type="password" name="password" class="login_input password_icon"></li>
<li><input name="submit" type="submit" value="登陆" class="login_btn" style="border:1px solid black"><div><?php echo isset($err)?$err:'';?></div></li>
</ul>
</form>
</div>
</div>
<div class="hr_25"></div>
</body>
</html>
main.php
<?php
session_start();
if(!isset($_SESSION['user'])){header('Content-type:text/html;charset=utf-8') ;header('Refresh:3;url=login.php');echo '未登录!';exit; };
$xml=simplexml_load_file('clients.xml');
$k=1;
if(isset($_GET['act'])&& isset($_GET['id'])){
unset($xml->people[$_GET['id']-1]);
$xml->asXML('config.xml');
echo "删除成功!";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<h3>客户信息</h3>
<table width="70%" border="1" cellpadding="5" cellspacing="0" bgcolor="#cccccc">
<tr>
<th>序号</th><th>姓名</th><th>年龄</th><th>行业</th><th>地址</th><th>电话</th><th>操作</th>
</tr>
<?php foreach($xml->people as $v){?>
<tr>
<td><?php echo $k++;?></td>
<td><?php echo $v->name;?></td>
<td><?php echo $v->age;?></td>
<td><?php echo $v->profession;?></td>
<td><?php echo $v->addr;?></td>
<td><?php echo $v->tel;?></td>
<td align= "center"><a href="?act=del&id=<?php echo $k-1;?>">删除</a> <a href="add.php?act=edit&id=<?php echo $k-1;?>">修改</a></td>
</tr>
<?php }?>
</table>
</center>
</body>
</html>