--- fenglin/bbs/search_user.php 2025/03/01 08:43:29 1.7
+++ fenglin/bbs/search_user.php 2025/04/23 05:13:56 1.25
@@ -1,283 +1,157 @@
-
+
-
-set_user_action("search_user");
+ require_once "./theme.inc.php";
-$page_max_record=20;
+ $result_set = array(
+ "return" => array(
+ "code" => 0,
+ "message" => "",
+ "errorFields" => array(),
+ )
+ );
+
+ $page = (isset($_GET["page"]) ? intval($_GET["page"]) : 1);
+ $rpp = (isset($_GET["rpp"]) ? intval($_GET["rpp"]) : 20);
+
+ $type = (isset($_GET["type"]) ? intval($_GET["type"]) : 0);
+ $online = (isset($_GET["online"]) && $_GET["online"] == "1" ? 1 : 0);
+ $friend = (isset($_GET["friend"]) && $_GET["friend"] == "1" ? 1 : 0);
+ $search_text = (isset($_GET["search_text"]) ? $_GET["search_text"] : "");
+
+ $sql = "SELECT IF(UID = 0, 1, 0) AS is_guest, COUNT(*) AS u_count FROM user_online
+ WHERE last_tm >= SUBDATE(NOW(), INTERVAL $BBS_user_off_line SECOND)
+ GROUP BY is_guest";
-if (isset($_GET["page"]))
- $page=intval($_GET["page"]);
-else
- $page=1;
-if ($page<1)
- $page=1;
-
-if (isset($_GET["type"]))
- $type=intval($_GET["type"]);
-else
- $type=2;
-
-if (isset($_GET["online"]))
- $online=($_GET["online"]=="on");
-else
- $online=0;
-
-if (isset($_GET["friend"]))
- $friend=($_GET["friend"]=="on");
-else
- $friend=0;
-
-if (isset($_GET["search_text"]))
- $search_text=trim($_GET["search_text"]);
-else
- $search_text="";
-$search_author=addslashes(stripslashes($search_text));
-
-$db_conn=include "./db_open.inc.php";
-
-$rs=mysql_query("select user_online.SID from user_online".
- " where UID=0 and current_action not in".
- " ('max_user_limit','max_ip_limit','max_session_limit','exit')".
- " group by SID")
- or die("Count guest error!");
-$guest_count=mysql_num_rows($rs);
-mysql_free_result($rs);
-
-$rs=mysql_query("select user_online.SID from user_online".
- " where UID<>0 and current_action not in".
- " ('max_user_limit','max_ip_limit','max_session_limit','exit')".
- " group by SID")
- or die("Count user error!");
-$user_count=mysql_num_rows($rs);
-mysql_free_result($rs);
-
-$rs=mysql_query("select count(user_list.UID) as rec_count from user_list".
- ($online?" inner join user_online on user_list.UID=user_online.UID":"").
- ($friend?" inner join friend_list on user_list.UID=friend_list.fUID":"").
- " inner join user_pubinfo on user_list.UID=user_pubinfo.UID where".
- " user_list.enable and ".($type==1?"user_pubinfo.nickname":"user_list.username").
- " like '%$search_author%'".
- ($online ? " and current_action not in".
- " ('max_user_limit','max_ip_limit','max_session_limit','exit')":"").
- ($friend ? " and friend_list.UID=".$_SESSION["BBS_uid"]:"")
- )
- or die("Query user error!");
-
-$row=mysql_fetch_array($rs);
-$u_count=$row["rec_count"];
-
-mysql_free_result($rs);
-
-$toa=$u_count;
-if ($toa==0)
- $toa=1;
-
-$page_total=intval($toa/$page_max_record);
-if (($toa % $page_max_record)>0)
- $page_total++;
-if ($page>$page_total)
- $page=$page_total;
-?>
-
-
-
- 用户查找结果
-
-
-
-
-
-
-
-
-
-
- |
- 枫林在线论坛>>查找 echo ($online?"在线":""); ?> echo ($friend?"好友":"用户"); ?>
- |
-
-
- |
-
- |
-
- if ($u_count==0)
-{
-?>
- 未找到指定用户 }
- else
-{
-?>用户查找结果(共 echo $u_count; ?>位) } ?>
- (当前在线注册用户 echo $user_count; ?>位,游客 echo $guest_count; ?>位)
- |
-
-
-
-
-
- |
- 用户ID |
- 昵称 |
- 等级 |
- 最后登陆时间 |
- |
- |
-
-
-$color[0]="#f0F3Fa";
-$color[1]="#FAFBFC";
-$color_index=-1;
-$color_count=2;
-
-$rs=mysql_query("select user_list.UID,username,nickname,exp,".
- "gender,gender_pub,last_login_dt from user_list".
- ($online?" inner join user_online on user_list.UID=user_online.UID":"").
- ($friend?" inner join friend_list on user_list.UID=friend_list.fUID":"").
- " inner join user_pubinfo on user_list.UID=user_pubinfo.UID where".
- " user_list.enable and ".($type==1?"user_pubinfo.nickname":"user_list.username").
- " like '%$search_author%'".
- ($online ? " and current_action not in".
- " ('max_user_limit','max_ip_limit','max_session_limit','exit')":"").
- ($friend ? " and friend_list.UID=".$_SESSION["BBS_uid"]:"").
- " order by ".($type==1?"nickname":"username").
- " limit ".($page-1)*$page_max_record.",$page_max_record")
- or die("Query user error!");
-
-while($row=mysql_fetch_array($rs))
-{
- $color_index=($color_index+1)%$color_count;
-?>
-
- |
-
- if ($row["gender_pub"])
+ $rs = mysqli_query($db_conn, $sql);
+ if ($rs == false)
+ {
+ echo("Count online user error" . mysqli_error($db_conn));
+ exit();
+ }
+
+ $guest_online = 0;
+ $user_online = 0;
+
+ while ($row = mysqli_fetch_array($rs))
{
- if ($row["gender"] == 'M')
- echo ("♂");
+ if ($row["is_guest"])
+ {
+ $guest_online = $row["u_count"];
+ }
else
- echo ("♀");
+ {
+ $user_online = $row["u_count"];
+ }
}
- else
+ mysqli_free_result($rs);
+
+ $sql = "SELECT COUNT(user_list.UID) AS rec_count FROM user_list" .
+ ($online ? " INNER JOIN user_online ON user_list.UID = user_online.UID" : "") .
+ ($friend ? " INNER JOIN friend_list ON user_list.UID = friend_list.fUID" : "") .
+ ($type == 1 ? " INNER JOIN user_pubinfo ON user_list.UID = user_pubinfo.UID" : "") .
+ " WHERE user_list.enable AND ".
+ ($type == 1 ? "nickname" : "username") .
+ " LIKE '%" . mysqli_real_escape_string($db_conn, $search_text) . "%'" .
+ ($online ? " AND last_tm >= SUBDATE(NOW(), INTERVAL $BBS_user_off_line SECOND)" : "").
+ ($friend ? " AND friend_list.UID = " . $_SESSION["BBS_uid"] : "");
+
+ $rs = mysqli_query($db_conn, $sql);
+ if ($rs == false)
{
- echo ("?");
+ echo("Query user error" . mysqli_error($db_conn));
+ exit();
}
-?>
- |
-
- )"> echo $row["username"]; ?>
- |
-
- echo $row["nickname"]; ?>
- |
-
- echo user_level($row["exp"]); ?>
- |
-
- echo $row["last_login_dt"]; ?>
- |
-
- ','send_msg',500,300)">发送消息
- ','send_msg',500,300)">发送邮件
- |
-
- |
-
-
-}
-?>
-
-
-mysql_free_result($rs);
-mysql_close($db_conn);
-?>
-
-
- |
- |
-
-
- |
- |
-
-
- |
-
- |
-
-
- |
-
- |
-
-
-
-
- include "./foot.inc.php";
-?>
-
-
+ if ($row = mysqli_fetch_array($rs))
+ {
+ $toa = $row["rec_count"];
+ }
+
+ mysqli_free_result($rs);
+
+ if (!in_array($rpp, $BBS_list_rpp_options))
+ {
+ $rpp = $BBS_list_rpp_options[0];
+ }
+
+ $page_total = ceil($toa / $rpp);
+ if ($page > $page_total)
+ {
+ $page = $page_total;
+ }
+
+ if ($page <= 0)
+ {
+ $page = 1;
+ }
+
+ // Fill up result data
+ $result_set["data"] = array(
+ "type" => $type,
+ "online" => $online,
+ "friend" => $friend,
+ "search_text" => $search_text,
+ "page" => $page,
+ "rpp" => $rpp,
+ "page_total" => $page_total,
+ "toa" => $toa,
+ "user_online" => $user_online,
+ "guest_online" => $guest_online,
+
+ "users" => array(),
+ );
+
+ $sql = "SELECT user_list.UID, username, nickname, exp, gender, gender_pub, last_login_dt FROM user_list" .
+ ($online ? " INNER JOIN user_online ON user_list.UID = user_online.UID" : "") .
+ ($friend ? " INNER JOIN friend_list ON user_list.UID = friend_list.fUID" : "") .
+ " INNER JOIN user_pubinfo ON user_list.UID = user_pubinfo.UID WHERE user_list.enable AND ".
+ ($type == 1 ? "nickname" : "username") .
+ " LIKE '%" . mysqli_real_escape_string($db_conn, $search_text) . "%'" .
+ ($online ? " AND last_tm >= SUBDATE(NOW(), INTERVAL $BBS_user_off_line SECOND)" : "").
+ ($friend ? " AND friend_list.UID = " . $_SESSION["BBS_uid"] : "") .
+ " ORDER BY " . ($type == 1 ? "nickname" : "username") .
+ " LIMIT " . ($page - 1) * $rpp . ", $rpp";
+
+ $rs = mysqli_query($db_conn, $sql);
+ if ($rs == false)
+ {
+ echo("Query user error" . mysqli_error($db_conn));
+ exit();
+ }
+
+ while ($row = mysqli_fetch_array($rs))
+ {
+ array_push($result_set["data"]["users"], array(
+ "uid" => $row["UID"],
+ "username" => $row["username"],
+ "nickname" => $row["nickname"],
+ "exp" => $row["exp"],
+ "gender" => $row["gender"],
+ "gender_pub" => $row["gender_pub"],
+ "last_login_dt" => (new DateTimeImmutable($row["last_login_dt"]))->setTimezone($_SESSION["BBS_user_tz"]),
+ ));
+ }
+ mysqli_free_result($rs);
+
+ // Cleanup
+ unset($type);
+ unset($online);
+ unset($friend);
+ unset($search_text);
+ unset($page);
+ unset($rpp);
+ unset($page_total);
+ unset($toa);
+ unset($user_online);
+ unset($guest_online);
+
+ // Output with theme view
+ $theme_view_file = get_theme_file("view/search_user", $_SESSION["BBS_theme_name"]);
+ if ($theme_view_file == null)
+ {
+ exit(json_encode($result_set)); // Output data in Json
+ }
+ include $theme_view_file;
+?>