/[LeafOK_CVS]/fenglin/bbs/update_profile.php
ViewVC logotype

Annotation of /fenglin/bbs/update_profile.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Mar 31 14:15:24 2025 UTC (11 months, 2 weeks ago) by sysadm
Branch: MAIN
Move modify_profile to update_profile
Refact with AJAX support

1 sysadm 1.1 <?
2     require_once "../lib/db_open.inc.php";
3     require_once "./session_init.inc.php";
4    
5     force_login();
6     ?>
7     <?
8     $sql = "SELECT nickname, name, email, gender, gender_pub, birthday, qq
9     FROM user_reginfo INNER JOIN user_pubinfo ON user_reginfo.UID = user_pubinfo.UID
10     WHERE user_reginfo.UID = ". $_SESSION["BBS_uid"];
11    
12     $rs = mysqli_query($db_conn, $sql);
13     if ($rs == false)
14     {
15     echo "Query user info error: " . mysqli_error($db_conn);;
16     exit();
17     }
18    
19     if(!($row = mysql_fetch_array($rs)))
20     {
21     echo ("个人资料不存在!");
22     exit();
23     }
24     ?>
25     <html>
26     <head>
27     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
28     <title>更改用户资料</title>
29     <link rel="stylesheet" href="css/default.css" type="text/css">
30     <script language="JavaScript" src="/js/nw_open.js"></script>
31     <script src="../js/polyfill.min.js"></script>
32     <script src="../js/axios.min.js"></script>
33     <script type="text/javascript">
34     function reset_flag()
35     {
36     var s = document.getElementsByName("err_msg");
37    
38     s.forEach(element => {
39     element.innerHTML = "";
40     });
41     }
42    
43     function update_profile(f)
44     {
45     reset_flag();
46     instance.post('update_profile_service.php', {
47     realname: f.realname.value,
48     gender: f.gender.value,
49     gender_public: (f.gender_public.checked ? "1" : "0"),
50     year: f.year.value,
51     month: f.month.value,
52     day: f.day.value,
53     qq: f.qq.value,
54     })
55     .then(function (response) {
56     var ret = response.data;
57     switch (ret.return.code)
58     {
59     case 0: // OK
60     window.alert("更新成功");
61     break;
62     case -1: // Input validation failed
63     ret.return.errorFields.forEach(field => {
64     document.getElementById("err_msg_" + field.id).innerHTML = field.errMsg + "<br />";
65     });
66     break;
67     case -2: // Internal error
68     console.log(ret.return.message);
69     document.getElementById("err_msg_username").innerHTML = "内部错误<br />";
70     break;
71     default:
72     console.log(ret.return.code);
73     break;
74     }
75     })
76     .catch(function (error) {
77     console.log(error);
78     });
79    
80     return false;
81     }
82    
83     const instance = axios.create({
84     withCredentials: true,
85     timeout: 3000,
86     baseURL: document.location.protocol + '//' + document.location.hostname + (document.location.port=='' ? '' : (':' + document.location.port)) + '/bbs/',
87     });
88    
89     </script>
90     </head>
91     <body>
92     <?
93     include "./member_service_guide.inc.php";
94     ?>
95     <center>
96     <p style="FONT-WEIGHT: bold; FONT-SIZE: 16px; COLOR: red; FONT-FAMILY: 楷体">更改用户资料</p>
97     <form method="post" id="profile_form" name="profile_form" action="javascript: update_profile(profile_form);">
98     <table border="1" cellpadding="10" cellspacing="0" width="90%" bgcolor="#ffdead" id=TABLE1>
99     <tr>
100     <td width="26%" align="right">
101     密码
102     </td>
103     <td width="74%">
104     密码修改请<a href="reset_pass.php" target=_blank>点击此处</a>通过邮箱重置。
105     </td>
106     </tr>
107     <tr>
108     <td align="right">
109     昵称
110     </td>
111     <td>
112     <span id="err_msg_nickname" name="err_msg" style="color: red;"></span><input id="nickname" name="nickname" value="<? echo htmlspecialchars($row["nickname"], ENT_HTML401, 'UTF-8'); ?>" readonly>
113     <input type="button" onclick="NW_open('ch_nick.php','ch_nick',250,200);" value="修改昵称">
114     </td>
115     </tr>
116     <tr>
117     <td align="right">
118     姓名
119     </td>
120     <td>
121     <span id="err_msg_realname" name="err_msg" style="color: red;"></span><input id="realname" name="realname" value="<? echo htmlspecialchars($row["name"], ENT_HTML401, 'UTF-8'); ?>">
122     <span style="color: red">*</span>
123     长度不超过5个全角字符
124     </td>
125     </tr>
126     <tr>
127     <td align="right">
128     性别
129     </td>
130     <td>
131     <span id="err_msg_gender" name="err_msg" style="color: red;"></span><input type="radio" id="gender_male" name="gender" value="M" <? echo ($row["gender"] == "M" ? "checked" : ""); ?>>男
132     <input type="radio" id="gender_female" name="gender" value="F" <? echo ($row["gender"] == "F" ? "checked" : ""); ?>>女
133     <span style="color: red">*</span>
134     <input type="checkbox" id="gender_public" name="gender_public" value="1" <? echo ($row["gender_pub"] ? "checked" : ""); ?>>公开
135     </td>
136     </tr>
137     <tr>
138     <td align="right">
139     邮件地址
140     </td>
141     <td>
142     <span id="err_msg_email" name="err_msg" style="color: red;"></span><input id="email" name="email" value="<? echo $row["email"]; ?>" readonly>
143     <input type="button" onclick="NW_open('modify_email.php','modify_email',250,150);" value="修改邮箱">
144     <span style="color: red">*</span>
145     请务必准确填写,否则无法激活账号<br>
146     </td>
147     </tr>
148     <tr>
149     <td align="right">
150     出生日期
151     </td>
152     <td>
153     <span id="err_msg_birthday" name="err_msg" style="color: red;"></span><select id="year" name="year" size="1">
154     <?
155     $birthday = (new DateTimeImmutable($row["birthday"]));
156    
157     $year_current = intval(date("Y", time()));
158     $year_max = $year_current - 16; // Accept registrant of 16+ only
159     $year_min = $year_current - 80;
160     $year_selected = intval($birthday->format("Y"));
161     for ($year = $year_min; $year <= $year_max; $year++)
162     {
163     ?>
164     <option value="<? echo $year; ?>" <? echo ($year == $year_selected ? "selected" : ""); ?>><? echo $year; ?></option>
165     <?
166     }
167     ?>
168    
169     </select>年
170     <select id="month" name="month" size="1">
171     <?
172     $month_selected = intval($birthday->format("m"));
173     for ($month = 1; $month <= 12; $month++)
174     {
175     ?>
176     <option value="<? echo $month; ?>" <? echo ($month == $month_selected ? "selected" : ""); ?>><? echo $month; ?></option>
177     <?
178     }
179     ?>
180     </select>月
181     <select id="day" name="day" size="1">
182     <?
183     $day_selected = intval($birthday->format("d"));
184     for ($day = 1; $day <= 31; $day++)
185     {
186     ?>
187     <option value="<? echo $day; ?>" <? echo ($day == $day_selected ? "selected" : ""); ?>><? echo $day; ?></option>
188     <?
189     }
190     ?>
191     </select>日
192     <span style="color: red">*</span>
193     </td>
194     </tr>
195     <tr>
196     <td align="right">
197     QQ号码
198     </td>
199     <td>
200     <span id="err_msg_qq" name="err_msg" style="color: red;"></span><input id="qq" name="qq" size="20" value="<? echo $row["qq"]; ?>">
201     </td>
202     </tr>
203     </table>
204     <p>
205     <input type="submit" value="提交">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
206     <input type="reset" value="重填">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
207     <input type="button" value="关闭窗口" name="B3" onclick="self.close();"></p>
208     </p>
209     </form>
210     </center>
211     </body>
212     </html>
213     <?
214     mysqli_free_result($rs);
215     mysqli_close($db_conn);
216     ?>

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1