--- fenglin/bbs/section_setting.php 2025/04/08 09:29:17 1.1 +++ fenglin/bbs/section_setting.php 2025/04/09 04:10:57 1.3 @@ -24,6 +24,7 @@ exit(json_encode($result_set)); } + // Load section setting $sql = "SELECT * FROM section_config WHERE SID = $sid AND enable"; $rs = mysqli_query($db_conn, $sql); @@ -36,16 +37,15 @@ exit(json_encode($result_set)); } - if($row = mysqli_fetch_array($rs)) + if ($row = mysqli_fetch_array($rs)) { - $result_set["return"]["data"] = array( + $result_set["data"] = array( "sid" => $sid, - "sname" => $row["sname"], - "s_title" => $row["title"], "announcement" => $row["announcement"], "comment" => $row["comment"], "ex_update" => $row["ex_update"], - "ex_dir" => array(), + "section_hierachy" => array(), + "masters" => array(), ); } else @@ -59,30 +59,90 @@ mysqli_free_result($rs); - $sql = "SELECT * FROM ex_dir WHERE SID = $sid AND enable ORDER BY dir"; + // Load section master + $sql = "SELECT section_master.UID, username, major, begin_dt, end_dt FROM section_master + INNER JOIN user_list ON section_master.UID = user_list.UID + WHERE SID = $sid AND section_master.enable AND (NOW() BETWEEN begin_dt AND end_dt) + ORDER BY major DESC, begin_dt ASC, end_dt ASC"; $rs = mysqli_query($db_conn, $sql); if ($rs == false) { $result_set["return"]["code"] = -2; - $result_set["return"]["message"] = "Query ex_dir error: " . mysqli_error($db_conn); + $result_set["return"]["message"] = "Query section master error: " . mysqli_error($db_conn); mysqli_close($db_conn); exit(json_encode($result_set)); } - array_push($result_set["return"]["data"]["ex_dir"], array( - "dir" => "", - "name" => "根目录", - )); - - while($row = mysqli_fetch_array($rs)) - { - array_push($result_set["return"]["data"]["ex_dir"], array( - "dir" => $row["dir"], - "name" => $row["name"], + while ($row = mysqli_fetch_array($rs)) + { + array_push($result_set["data"]["masters"], array( + "uid" => $row["UID"], + "username" => $row["username"], + "major" => $row["major"], + "begin_dt" => $row["begin_dt"], + "end_dt" => $row["end_dt"], + )); + } + mysqli_free_result($rs); + + // Load section list + $sql = "SELECT SID, section_config.CID, section_config.title AS s_title, section_class.title AS c_title + FROM section_config INNER JOIN section_class ON section_config.CID = section_class.CID + WHERE section_class.enable AND section_config.enable + ORDER BY section_class.sort_order, section_config.sort_order"; + + $rs = mysqli_query($db_conn, $sql); + if ($rs == false) + { + $result_set["return"]["code"] = -2; + $result_set["return"]["message"] = "Query section error: " . mysqli_error($db_conn); + + mysqli_close($db_conn); + exit(json_encode($result_set)); + } + + $last_cid = -1; + $last_c_title = ""; + $section_list = array(); + while ($row = mysqli_fetch_array($rs)) + { + if ($row["CID"] != $last_cid) + { + if (count($section_list) > 0) + { + array_push($result_set["data"]["section_hierachy"], array( + "cid" => $last_cid, + "title" => $last_c_title, + "sections" => $section_list, + )); + + $section_list = array(); + } + + $last_cid = $row["CID"]; + $last_c_title = $row["c_title"]; + } + + if ($_SESSION["BBS_priv"]->checkpriv($row["SID"], S_POST | S_MAN_S)) + { + array_push($section_list, array( + "sid" => $row["SID"], + "title" => $row["s_title"], + )); + } + } + + if (count($section_list) > 0) + { + array_push($result_set["data"]["section_hierachy"], array( + "cid" => $last_cid, + "title" => $last_c_title, + "sections" => $section_list, )); } + mysqli_free_result($rs); mysqli_close($db_conn);