ListUser.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <?php
  2. define('EmpireCMSAdmin','1');
  3. require("../../class/connect.php");
  4. require("../../class/db_sql.php");
  5. require("../../class/functions.php");
  6. require "../".LoadLang("pub/fun.php");
  7. $link=db_connect();
  8. $empire=new mysqlquery();
  9. $editor=1;
  10. //验证用户
  11. $lur=is_login();
  12. $logininid=$lur['userid'];
  13. $loginin=$lur['username'];
  14. $loginrnd=$lur['rnd'];
  15. $loginlevel=$lur['groupid'];
  16. $loginadminstyleid=$lur['adminstyleid'];
  17. //ehash
  18. $ecms_hashur=hReturnEcmsHashStrAll();
  19. //验证权限
  20. CheckLevel($logininid,$loginin,$classid,"user");
  21. //------------------------增加用户
  22. function AddUser($username,$password,$repassword,$groupid,$adminclass,$checked,$styleid,$loginuserid,$loginusername){
  23. global $empire,$class_r,$dbtbpre;
  24. $username=str_replace(',','',$username);
  25. $username=str_replace('|','',$username);
  26. $username=RepPostVar($username);
  27. $password=RepPostVar($password);
  28. if(!$username||!$password||!$repassword)
  29. {printerror("EmptyUsername","history.go(-1)");}
  30. if($password!=$repassword)
  31. {printerror("NotRepassword","history.go(-1)");}
  32. if(strlen($password)<6)
  33. {
  34. printerror("LessPassword","history.go(-1)");
  35. }
  36. //操作权限
  37. CheckLevel($loginuserid,$loginusername,$classid,"user");
  38. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsuser where username='$username' limit 1");
  39. if($num)
  40. {printerror("ReUsername","history.go(-1)");}
  41. //管理目录
  42. $insert_class='';
  43. for($i=0;$i<count($adminclass);$i++)
  44. {
  45. $adminclass[$i]=(int)$adminclass[$i];
  46. //大栏目
  47. if(empty($class_r[$adminclass[$i]][islast]))
  48. {
  49. if(empty($class_r[$adminclass[$i]][sonclass])||$class_r[$adminclass[$i]][sonclass]=="|")
  50. {
  51. continue;
  52. }
  53. else
  54. {
  55. $andclass=substr($class_r[$adminclass[$i]][sonclass],1);
  56. }
  57. $insert_class.=$andclass;
  58. }
  59. else
  60. {
  61. $insert_class.=$adminclass[$i]."|";
  62. }
  63. }
  64. $insert_class="|".$insert_class;
  65. $styleid=(int)$styleid;
  66. $groupid=(int)$groupid;
  67. $checked=(int)$checked;
  68. $filelevel=(int)$_POST['filelevel'];
  69. $classid=(int)$_POST['classid'];
  70. $rnd=make_password(20);
  71. $salt=make_password(8);
  72. $salt2=make_password(20);
  73. $password=DoEmpireCMSAdminPassword($password,$salt,$salt2);
  74. $truename=hRepPostStr($_POST['truename'],1);
  75. $email=hRepPostStr($_POST['email'],1);
  76. $openip=hRepPostStr($_POST['openip'],1);
  77. $wname=hRepPostStr($_POST['wname'],1);
  78. $tel=hRepPostStr($_POST['tel'],1);
  79. $wxno=hRepPostStr($_POST['wxno'],1);
  80. $qq=hRepPostStr($_POST['qq'],1);
  81. $addtime=time();
  82. $addip=egetip();
  83. $addipport=egetipport();
  84. $userprikey=make_password(48);
  85. $insert_class=hRepPostStr2($insert_class);
  86. $sql=$empire->query("insert into {$dbtbpre}enewsuser(username,password,rnd,groupid,adminclass,checked,styleid,filelevel,salt,loginnum,lasttime,lastip,truename,email,classid,addtime,addip,userprikey,salt2,lastipport,preipport,addipport,wname,tel,wxno,qq) values('$username','$password','$rnd','$groupid','$insert_class','$checked','$styleid','$filelevel','$salt',0,0,'','$truename','$email','$classid','$addtime','$addip','$userprikey','$salt2','$addipport','$addipport','$addipport','$wname','$tel','$wxno','$qq');");
  87. $userid=$empire->lastid();
  88. //安全提问
  89. $equestion=(int)$_POST['equestion'];
  90. $eanswer=$_POST['eanswer'];
  91. if($equestion)
  92. {
  93. if(!$eanswer)
  94. {
  95. printerror('EmptyEAnswer','');
  96. }
  97. $eanswer=ReturnHLoginQuestionStr($userid,$username,$equestion,$eanswer);
  98. }
  99. else
  100. {
  101. $equestion=0;
  102. $eanswer='';
  103. }
  104. $empire->query("insert into {$dbtbpre}enewsuseradd(userid,equestion,eanswer,openip) values('$userid','$equestion','$eanswer','$openip');");
  105. if($sql)
  106. {
  107. $cache_enews='douserinfo';
  108. $cache_ecmstourl=urlencode('user/AddUser.php?enews=AddUser'.hReturnEcmsHashStrHref2(0));
  109. $cache_mess='AddUserSuccess';
  110. $cache_uid=$userid;
  111. $cache_url="../CreateCache.php?enews=$cache_enews&uid=$cache_uid&ecmstourl=$cache_ecmstourl&mess=$cache_mess".hReturnEcmsHashStrHref2(0);
  112. //操作日志
  113. insert_dolog("userid=".$userid."<br>username=".$username);
  114. //printerror("AddUserSuccess","AddUser.php?enews=AddUser".hReturnEcmsHashStrHref2(0));
  115. echo'<meta http-equiv="refresh" content="0;url='.$cache_url.'">';
  116. db_close();
  117. $empire=null;
  118. exit();
  119. }
  120. else
  121. {printerror("DbError","history.go(-1)");}
  122. }
  123. //------------------------修改用户
  124. function EditUser($userid,$username,$password,$repassword,$groupid,$adminclass,$oldusername,$checked,$styleid,$loginuserid,$loginusername){
  125. global $empire,$class_r,$dbtbpre;
  126. $userid=(int)$userid;
  127. $oldusername=RepPostVar($oldusername);
  128. $username=str_replace(',','',$username);
  129. $username=str_replace('|','',$username);
  130. $username=RepPostVar($username);
  131. $password=RepPostVar($password);
  132. $add='';
  133. if(!$userid||!$username)
  134. {printerror("EnterUsername","history.go(-1)");}
  135. //操作权限
  136. CheckLevel($loginuserid,$loginusername,$classid,"user");
  137. //修改用户名
  138. if($oldusername<>$username)
  139. {
  140. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsuser where username='$username' and userid<>$userid limit 1");
  141. if($num)
  142. {printerror("ReUsername","history.go(-1)");}
  143. //修改信息
  144. //$nsql=$empire->query("update {$dbtbpre}enewsnews set username='$username' where username='$oldusername'");
  145. //修改日志
  146. $lsql=$empire->query("update {$dbtbpre}enewslog set username='$username' where username='$oldusername'");
  147. $lsql=$empire->query("update {$dbtbpre}enewsdolog set username='$username' where username='$oldusername'");
  148. }
  149. //修改密码
  150. if($password)
  151. {
  152. if($password!=$repassword)
  153. {printerror("NotRepassword","history.go(-1)");}
  154. if(strlen($password)<6)
  155. {
  156. printerror("LessPassword","history.go(-1)");
  157. }
  158. $salt=make_password(8);
  159. $salt2=make_password(20);
  160. $password=DoEmpireCMSAdminPassword($password,$salt,$salt2);
  161. $add=",password='$password',salt='$salt',salt2='$salt2'";
  162. }
  163. //管理目录
  164. $insert_class='';
  165. for($i=0;$i<count($adminclass);$i++)
  166. {
  167. $adminclass[$i]=(int)$adminclass[$i];
  168. //大栏目
  169. if(empty($class_r[$adminclass[$i]][islast]))
  170. {
  171. if(empty($class_r[$adminclass[$i]][sonclass])||$class_r[$adminclass[$i]][sonclass]=="|")
  172. {
  173. continue;
  174. }
  175. else
  176. {
  177. $andclass=substr($class_r[$adminclass[$i]][sonclass],1);
  178. }
  179. $insert_class.=$andclass;
  180. }
  181. else
  182. {
  183. $insert_class.=$adminclass[$i]."|";
  184. }
  185. }
  186. $insert_class="|".$insert_class;
  187. $styleid=(int)$styleid;
  188. $groupid=(int)$groupid;
  189. $checked=(int)$checked;
  190. $filelevel=(int)$_POST['filelevel'];
  191. $classid=(int)$_POST['classid'];
  192. $truename=hRepPostStr($_POST['truename'],1);
  193. $email=hRepPostStr($_POST['email'],1);
  194. $openip=hRepPostStr($_POST['openip'],1);
  195. $wname=hRepPostStr($_POST['wname'],1);
  196. $tel=hRepPostStr($_POST['tel'],1);
  197. $wxno=hRepPostStr($_POST['wxno'],1);
  198. $qq=hRepPostStr($_POST['qq'],1);
  199. $insert_class=hRepPostStr2($insert_class);
  200. $sql=$empire->query("update {$dbtbpre}enewsuser set username='$username',groupid='$groupid',adminclass='$insert_class',checked='$checked',styleid='$styleid',filelevel='$filelevel',truename='$truename',email='$email',classid='$classid',wname='$wname',tel='$tel',wxno='$wxno',qq='$qq'".$add." where userid='$userid'");
  201. //安全提问
  202. $equestion=(int)$_POST['equestion'];
  203. $eanswer=$_POST['eanswer'];
  204. $uadd='';
  205. if($equestion)
  206. {
  207. if($equestion!=$_POST['oldequestion']&&!$eanswer)
  208. {
  209. printerror('EmptyEAnswer','');
  210. }
  211. if($eanswer)
  212. {
  213. $eanswer=ReturnHLoginQuestionStr($userid,$username,$equestion,$eanswer);
  214. $uadd=",eanswer='$eanswer'";
  215. }
  216. }
  217. else
  218. {
  219. $uadd=",eanswer=''";
  220. }
  221. $empire->query("update {$dbtbpre}enewsuseradd set equestion='$equestion',openip='$openip'".$uadd." where userid='$userid'");
  222. if($sql)
  223. {
  224. //操作日志
  225. insert_dolog("userid=".$userid."<br>username=".$username);
  226. if($_POST['oldadminclass']<>$insert_class)
  227. {
  228. DelFiletext('../../data/fc/ListEnews'.$userid.'.php');
  229. DelFiletext('../../data/fc/userclass'.$userid.'.js');
  230. //删除导航缓存
  231. $empire->query("delete from {$dbtbpre}enewsclassnavcache where navtype='userenews' and userid='$userid'");
  232. $cache_enews='douserinfo';
  233. $cache_ecmstourl=urlencode('user/ListUser.php'.hReturnEcmsHashStrHref2(1));
  234. $cache_mess='EditUserSuccess';
  235. $cache_uid=$userid;
  236. $cache_url="../CreateCache.php?enews=$cache_enews&uid=$cache_uid&ecmstourl=$cache_ecmstourl&mess=$cache_mess".hReturnEcmsHashStrHref2(0);
  237. echo'<meta http-equiv="refresh" content="0;url='.$cache_url.'">';
  238. db_close();
  239. $empire=null;
  240. exit();
  241. }
  242. printerror("EditUserSuccess","ListUser.php".hReturnEcmsHashStrHref2(1));
  243. }
  244. else
  245. {printerror("DbError","history.go(-1)");}
  246. }
  247. //-----------------------删除用户
  248. function DelUser($userid,$loginuserid,$loginusername){
  249. global $empire,$dbtbpre;
  250. $userid=(int)$userid;
  251. if(!$userid)
  252. {printerror("NotDelUserid","history.go(-1)");}
  253. //操作权限
  254. CheckLevel($loginuserid,$loginusername,$classid,"user");
  255. //验证是否最后一个管理员
  256. $num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewsuser");
  257. if($num<=1)
  258. {
  259. printerror("LastUserNotToDel","history.go(-1)");
  260. }
  261. $r=$empire->fetch1("select username from {$dbtbpre}enewsuser where userid='$userid'");
  262. $sql=$empire->query("delete from {$dbtbpre}enewsuser where userid='$userid'");
  263. $sql1=$empire->query("delete from {$dbtbpre}enewsuseradd where userid='$userid'");
  264. if($sql)
  265. {
  266. DelFiletext('../../data/fc/ListEnews'.$userid.'.php');
  267. DelFiletext('../../data/fc/userclass'.$userid.'.js');
  268. //删除导航缓存
  269. $empire->query("delete from {$dbtbpre}enewsclassnavcache where navtype='userenews' and userid='$userid'");
  270. //操作日志
  271. insert_dolog("userid=".$userid."<br>username=".$r[username]);
  272. printerror("DelUserSuccess","ListUser.php".hReturnEcmsHashStrHref2(1));
  273. }
  274. else
  275. {printerror("DbError","history.go(-1)");}
  276. }
  277. $enews=$_POST['enews'];
  278. if(empty($enews))
  279. {$enews=$_GET['enews'];}
  280. if($enews)
  281. {
  282. hCheckEcmsRHash();
  283. include('../../data/dbcache/class.php');
  284. }
  285. //增加用户
  286. if($enews=="AddUser")
  287. {
  288. $username=$_POST['username'];
  289. $password=$_POST['password'];
  290. $repassword=$_POST['repassword'];
  291. $groupid=$_POST['groupid'];
  292. $adminclass=$_POST['adminclass'];
  293. $checked=$_POST['checked'];
  294. $styleid=$_POST['styleid'];
  295. AddUser($username,$password,$repassword,$groupid,$adminclass,$checked,$styleid,$logininid,$loginin);
  296. }
  297. //修改用户
  298. elseif($enews=="EditUser")
  299. {
  300. $userid=$_POST['userid'];
  301. $username=$_POST['username'];
  302. $password=$_POST['password'];
  303. $repassword=$_POST['repassword'];
  304. $groupid=$_POST['groupid'];
  305. $adminclass=$_POST['adminclass'];
  306. $oldusername=$_POST['oldusername'];
  307. $checked=$_POST['checked'];
  308. $styleid=$_POST['styleid'];
  309. EditUser($userid,$username,$password,$repassword,$groupid,$adminclass,$oldusername,$checked,$styleid,$logininid,$loginin);
  310. }
  311. //删除用户
  312. elseif($enews=="DelUser")
  313. {
  314. $userid=$_GET['userid'];
  315. DelUser($userid,$logininid,$loginin);
  316. }
  317. $page=(int)$_GET['page'];
  318. $page=RepPIntvar($page);
  319. $start=0;
  320. $line=25;//每页显示条数
  321. $page_line=12;//每页显示链接数
  322. $offset=$page*$line;//总偏移量
  323. $url="<a href=ListUser.php".$ecms_hashur['whehref'].">管理用户</a>";
  324. //排序
  325. $mydesc=(int)$_GET['mydesc'];
  326. $desc=$mydesc?'asc':'desc';
  327. $orderby=(int)$_GET['orderby'];
  328. if($orderby==1)//用户名
  329. {
  330. $order="username ".$desc.",userid desc";
  331. $usernamedesc=$mydesc?0:1;
  332. }
  333. elseif($orderby==2)//用户组
  334. {
  335. $order="groupid ".$desc.",userid desc";
  336. $groupiddesc=$mydesc?0:1;
  337. }
  338. elseif($orderby==3)//状态
  339. {
  340. $order="checked ".$desc.",userid desc";
  341. $checkeddesc=$mydesc?0:1;
  342. }
  343. elseif($orderby==4)//登陆次数
  344. {
  345. $order="loginnum ".$desc.",userid desc";
  346. $loginnumdesc=$mydesc?0:1;
  347. }
  348. elseif($orderby==5)//最后登陆
  349. {
  350. $order="lasttime ".$desc.",userid desc";
  351. $lasttimedesc=$mydesc?0:1;
  352. }
  353. else//用户ID
  354. {
  355. $order="userid ".$desc;
  356. $useriddesc=$mydesc?0:1;
  357. }
  358. $search="&orderby=$orderby&mydesc=$mydesc".$ecms_hashur['ehref'];
  359. $query="select * from {$dbtbpre}enewsuser";
  360. $num=$empire->num($query);//取得总条数
  361. $query=$query." order by ".$order." limit $offset,$line";
  362. $sql=$empire->query($query);
  363. $returnpage=page2($num,$line,$page_line,$start,$page,$search);
  364. ?>
  365. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  366. <html>
  367. <head>
  368. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  369. <title>管理用户</title>
  370. <link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
  371. </head>
  372. <body>
  373. <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  374. <tr>
  375. <td width="50%">位置:
  376. <?=$url?>
  377. </td>
  378. <td><div align="right" class="emenubutton">
  379. <input type="button" name="Submit5" value="增加用户" onclick="self.location.href='AddUser.php?enews=AddUser<?=$ecms_hashur['ehref']?>';">&nbsp;&nbsp;
  380. <input type="button" name="Submit52" value="管理部门" onclick="self.location.href='UserClass.php<?=$ecms_hashur['whehref']?>';">
  381. </div></td>
  382. </tr>
  383. </table>
  384. <br>
  385. <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  386. <tr class="header">
  387. <td width="4%" height="25"><div align="center"><a href="ListUser.php?orderby=0&mydesc=<?=$useriddesc?><?=$ecms_hashur['ehref']?>">ID</a></div></td>
  388. <td width="22%" height="25"><div align="center"><a href="ListUser.php?orderby=1&mydesc=<?=$usernamedesc?><?=$ecms_hashur['ehref']?>">用户名</a></div></td>
  389. <td width="20%"><div align="center"><a href="ListUser.php?orderby=2&mydesc=<?=$groupiddesc?><?=$ecms_hashur['ehref']?>">等级</a></div></td>
  390. <td width="6%"><div align="center"><a href="ListUser.php?orderby=3&mydesc=<?=$checkeddesc?><?=$ecms_hashur['ehref']?>">状态</a></div></td>
  391. <td width="8%"><div align="center">证书</div></td>
  392. <td width="8%"><div align="center"><a href="ListUser.php?orderby=4&mydesc=<?=$loginnumdesc?><?=$ecms_hashur['ehref']?>">登陆次数</a></div></td>
  393. <td width="19%"><div align="center"><a href="ListUser.php?orderby=5&mydesc=<?=$lasttimedesc?><?=$ecms_hashur['ehref']?>">最后登陆</a></div></td>
  394. <td width="13%" height="25"><div align="center">操作</div></td>
  395. </tr>
  396. <?
  397. while($r=$empire->fetch($sql))
  398. {
  399. $classname='--';
  400. if($r[classid])
  401. {
  402. $cr=$empire->fetch1("select classname from {$dbtbpre}enewsuserclass where classid='$r[classid]'");
  403. $classname=$cr['classname'];
  404. }
  405. $gr=$empire->fetch1("select groupname from {$dbtbpre}enewsgroup where groupid='$r[groupid]'");
  406. if($r[checked])
  407. {$zt="禁用";}
  408. else
  409. {$zt="开启";}
  410. $lasttime='---';
  411. if($r[lasttime])
  412. {
  413. $lasttime=date("Y-m-d H:i:s",$r[lasttime]);
  414. }
  415. $usercertkey='--';
  416. ?>
  417. <tr bgcolor="ffffff" onmouseout="this.style.backgroundColor='#ffffff'" onmouseover="this.style.backgroundColor='#C3EFFF'">
  418. <td height="25"><div align="center">
  419. <?=$r[userid]?>
  420. </div></td>
  421. <td height="25"><div align="center">
  422. <?=$r[username]?>
  423. </div></td>
  424. <td> <div align="left">用户组:
  425. <?=$gr[groupname]?>
  426. <br>
  427. 部门&nbsp;&nbsp;&nbsp;:
  428. <?=$classname?>
  429. </div></td>
  430. <td><div align="center">
  431. <?=$zt?>
  432. </div></td>
  433. <td><div align="center"><?=$usercertkey?></div></td>
  434. <td><div align="center">
  435. <?=$r[loginnum]?>
  436. </div></td>
  437. <td> 时间:
  438. <?=$lasttime?>
  439. <br>
  440. IP&nbsp;&nbsp;&nbsp;:
  441. <?=$r[lastip]?$r[lastip].':'.$r[lastipport]:'---'?>
  442. </td>
  443. <td height="25"><div align="center">[<a href="AddUser.php?enews=EditUser&userid=<?=$r[userid]?><?=$ecms_hashur['ehref']?>">修改</a>]
  444. [<a href="ListUser.php?enews=DelUser&userid=<?=$r[userid]?><?=$ecms_hashur['href']?>" onclick="return confirm('确认要删除?');">删除</a>]</div></td>
  445. </tr>
  446. <?
  447. }
  448. ?>
  449. <tr bgcolor="ffffff">
  450. <td height="25" colspan="8">
  451. <?=$returnpage?>
  452. </td>
  453. </tr>
  454. </table>
  455. </body>
  456. </html>
  457. <?
  458. db_close();
  459. $empire=null;
  460. ?>