|
1
|
|
|
<?php namespace XoopsModules\Smallworld; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* You may not change or alter any portion of this comment or credits |
|
5
|
|
|
* of supporting developers from this source code or any supporting source code |
|
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
* |
|
8
|
|
|
* This program is distributed in the hope that it will be useful, |
|
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* SmallWorld |
|
15
|
|
|
* |
|
16
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
|
17
|
|
|
* @copyright 2011 Culex |
|
18
|
|
|
* @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
|
19
|
|
|
* @package SmallWorld |
|
20
|
|
|
* @since 1.0 |
|
21
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class SwDatabase |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* getJobsToDiv function |
|
27
|
|
|
* @param int $id |
|
28
|
|
|
* @return array |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getJobsToDiv($id) |
|
31
|
|
|
{ |
|
32
|
|
|
global $xoopsUser, $xoopsDB; |
|
33
|
|
|
$msg = []; |
|
34
|
|
|
$new = []; |
|
|
|
|
|
|
35
|
|
|
$sql = 'SELECT employer,position,jobstart,jobstop,description FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid ='" . $id . "'"; |
|
36
|
|
|
$result = $xoopsDB->query($sql); |
|
37
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
38
|
|
|
$employer = unserialize($row['employer']); |
|
39
|
|
|
$position = unserialize($row['position']); |
|
40
|
|
|
$jobstart = unserialize($row['jobstart']); |
|
41
|
|
|
$jobstop = unserialize($row['jobstop']); |
|
42
|
|
|
$description = unserialize($row['description']); |
|
43
|
|
|
} |
|
44
|
|
|
$start = 0; |
|
45
|
|
|
$end = count($employer) - 1; |
|
|
|
|
|
|
46
|
|
|
while ($start <= $end) { |
|
47
|
|
|
$msg[$start]['employer'] = $employer[$start]; |
|
48
|
|
|
$msg[$start]['position'] = $position[$start]; |
|
|
|
|
|
|
49
|
|
|
$msg[$start]['jobstart'] = $jobstart[$start]; |
|
|
|
|
|
|
50
|
|
|
$msg[$start]['jobstop'] = $jobstop[$start]; |
|
|
|
|
|
|
51
|
|
|
$msg[$start]['description'] = $description[$start]; |
|
|
|
|
|
|
52
|
|
|
++$start; |
|
53
|
|
|
} |
|
54
|
|
|
return $msg; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* getSchoolToDiv function |
|
59
|
|
|
* @param int $id |
|
60
|
|
|
* @return array |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getSchoolToDiv($id) |
|
63
|
|
|
{ |
|
64
|
|
|
global $xoopsUser, $xoopsDB, $arr7; |
|
65
|
|
|
$msg = []; |
|
66
|
|
|
$sql = 'SELECT school_type,school,schoolstart,schoolstop FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid ='" . $id . "'"; |
|
67
|
|
|
$result = $xoopsDB->query($sql); |
|
68
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
69
|
|
|
$school_type = unserialize($row['school_type']); |
|
70
|
|
|
$school = unserialize($row['school']); |
|
71
|
|
|
$schoolstart = unserialize($row['schoolstart']); |
|
72
|
|
|
$schoolstop = unserialize($row['schoolstop']); |
|
73
|
|
|
} |
|
74
|
|
|
$start = 0; |
|
75
|
|
|
$end = count($school_type) - 1; |
|
|
|
|
|
|
76
|
|
|
while ($start <= $end) { |
|
77
|
|
|
$msg[$start]['school_type'] = $school_type[$start]; |
|
78
|
|
|
$msg[$start]['school'] = $arr7[$school[$start]]; |
|
|
|
|
|
|
79
|
|
|
$msg[$start]['schoolstart'] = $schoolstart[$start]; |
|
|
|
|
|
|
80
|
|
|
$msg[$start]['schoolstop'] = $schoolstop[$start]; |
|
|
|
|
|
|
81
|
|
|
$start++; |
|
82
|
|
|
} |
|
83
|
|
|
return $msg; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* getScreennamesToDiv function |
|
88
|
|
|
* @param int $id |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getScreennamesToDiv($id) |
|
92
|
|
|
{ |
|
93
|
|
|
global $xoopsUser, $xoopsDB, $arr06; |
|
94
|
|
|
$msg = []; |
|
95
|
|
|
$sql = 'SELECT screenname_type,screenname FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid ='" . $id . "'"; |
|
96
|
|
|
$result = $xoopsDB->query($sql); |
|
97
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
98
|
|
|
$screenname_type = unserialize($row['screenname_type']); |
|
99
|
|
|
$screenname = unserialize($row['screenname']); |
|
100
|
|
|
} |
|
101
|
|
|
$start = 0; |
|
102
|
|
|
$end = count($screenname_type) - 1; |
|
|
|
|
|
|
103
|
|
|
while ($start <= $end) { |
|
104
|
|
|
$msg[$start]['screenname'] = $screenname_type[$start]; |
|
105
|
|
|
$msg[$start]['screenname_type'] = $arr06[$screenname[$start]]; |
|
|
|
|
|
|
106
|
|
|
$msg[$start]['link'] = "<span class='smallworld_website'>" . Smallworld_sociallinks($screenname[$start], $msg[$start]['screenname']); |
|
107
|
|
|
++$start; |
|
108
|
|
|
} |
|
109
|
|
|
return $msg; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* getVar function |
|
114
|
|
|
* @param int $id |
|
115
|
|
|
* @param string $var |
|
116
|
|
|
* @return array|int |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getVar($id, $var) |
|
119
|
|
|
{ |
|
120
|
|
|
global $xoopsUser, $xoopsDB; |
|
121
|
|
|
$sql = 'SELECT ' . $var . ' FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $id . "'"; |
|
122
|
|
|
$result = $xoopsDB->queryF($sql); |
|
123
|
|
|
if ($xoopsDB->getRowsNum($result) < 1) { |
|
124
|
|
|
return 0;//_SMALLWORLD_REPLY_NOTSPECIFIED; |
|
125
|
|
|
} |
|
126
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
127
|
|
|
$msg[$var] = $row[$var]; |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
return $msg[$var]; |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* updateSingleValue function |
|
134
|
|
|
* @param string $table |
|
135
|
|
|
* @param int $userid |
|
136
|
|
|
* @param string $field |
|
137
|
|
|
* @param int $value |
|
138
|
|
|
* @return void |
|
139
|
|
|
*/ |
|
140
|
|
|
public function updateSingleValue($table, $userid, $field, $value) |
|
141
|
|
|
{ |
|
142
|
|
|
global $xoopsUser, $xoopsDB; |
|
143
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
144
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix($table) . ' SET ' . $field . "='" . $myts->addSlashes($value) . "' WHERE userid='" . (int)$userid . "'"; |
|
145
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* saveImage function |
|
150
|
|
|
* @param $values |
|
151
|
|
|
* @return void |
|
152
|
|
|
*/ |
|
153
|
|
View Code Duplication |
public function saveImage($values) |
|
|
|
|
|
|
154
|
|
|
{ |
|
155
|
|
|
global $xoopsUser, $xoopsDB; |
|
156
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
|
|
157
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_images') . ' VALUES (' . $values . ')'; |
|
158
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* DeleteImage function |
|
163
|
|
|
* @param int $userid |
|
164
|
|
|
* @param string $imagename |
|
165
|
|
|
* @return void |
|
166
|
|
|
*/ |
|
167
|
|
View Code Duplication |
public function DeleteImage($userid, $imagename) |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
global $xoopsUser, $xoopsDB; |
|
170
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
|
|
171
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_images') . " WHERE imgname = '" . stripslashes($imagename) . "' AND userid='" . $userid . "'"; |
|
172
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* handlePosts function |
|
177
|
|
|
* @return void |
|
178
|
|
|
*/ |
|
179
|
|
|
public function handlePosts() |
|
180
|
|
|
{ |
|
181
|
|
|
global $xoopsUser, $xoopsDB; |
|
182
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
|
|
183
|
|
|
$uid = $xoopsUser->getVar('uid'); |
|
184
|
|
|
$user = new \XoopsUser($uid); |
|
185
|
|
|
$img = new Images(); |
|
186
|
|
|
if ('' == $this->getVar($uid, 'userimage')) { |
|
187
|
|
|
$avatar = $user->user_avatar(); |
|
188
|
|
|
} else { |
|
189
|
|
|
$avatar = $this->getVar($uid, 'userimage'); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
if ('2' != $_POST['relationship']) { |
|
193
|
|
|
$partner = Smallworld_sanitize($_POST['partner']); |
|
194
|
|
|
} else { |
|
195
|
|
|
$partner = ''; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
$regdate = time(); |
|
199
|
|
|
$username = $user->uname(); |
|
200
|
|
|
$realname = Smallworld_sanitize($_POST['realname']); |
|
201
|
|
|
$gender = isset($_POST['gender']) ? $_POST['gender'] : ''; |
|
202
|
|
|
$intingender = isset($_POST['intingender']) ? Smallworld_sanitize(serialize($_POST['intingender'])) : Smallworld_sanitize(serialize([0 => '3'])); |
|
203
|
|
|
$relationship = Smallworld_sanitize($_POST['relationship']); |
|
204
|
|
|
$searchrelat = isset($_POST['searchrelat']) ? Smallworld_sanitize(serialize($_POST['searchrelat'])) : Smallworld_sanitize(serialize([0 => '0'])); |
|
205
|
|
|
$birthday = Smallworld_sanitize(Smallworld_euroToUsDate($_POST['birthday'])); |
|
206
|
|
|
$birthplace = Smallworld_sanitize($_POST['birthplace']); |
|
207
|
|
|
$birthplace_lat = Smallworld_sanitize($_POST['birthplace_lat']); |
|
208
|
|
|
$birthplace_lng = Smallworld_sanitize($_POST['birthplace_lng']); |
|
209
|
|
|
$birthplace_country = Smallworld_sanitize($_POST['birthplace_country']); |
|
210
|
|
|
$birthplace_country_img = isset($_POST['birthplace_country_img']) ? Smallworld_sanitize($_POST['birthplace_country_img']) : ''; |
|
|
|
|
|
|
211
|
|
|
$politic = Smallworld_sanitize($_POST['politic']); |
|
212
|
|
|
$religion = Smallworld_sanitize($_POST['religion']); |
|
213
|
|
|
$emailtype = Smallworld_sanitize(serialize($_POST['emailtype'])); |
|
214
|
|
|
$screenname_type = Smallworld_sanitize(serialize($_POST['screenname_type'])); |
|
215
|
|
|
$screenname = Smallworld_sanitize(serialize($_POST['screenname'])); |
|
216
|
|
|
$mobile = Smallworld_sanitize($_POST['mobile']); |
|
217
|
|
|
$phone = Smallworld_sanitize($_POST['phone']); |
|
218
|
|
|
$adress = Smallworld_sanitize($_POST['adress']); |
|
219
|
|
|
$present_city = Smallworld_sanitize($_POST['present_city']); |
|
220
|
|
|
$present_lat = Smallworld_sanitize($_POST['present_lat']); |
|
221
|
|
|
$present_lng = Smallworld_sanitize($_POST['present_lng']); |
|
222
|
|
|
$present_country = Smallworld_sanitize($_POST['present_country']); |
|
223
|
|
|
$present_country_img = isset($_POST['present_country_img']) ? Smallworld_sanitize($_POST['present_country_img']) : ''; |
|
|
|
|
|
|
224
|
|
|
$website = Smallworld_sanitize($_POST['website']); |
|
225
|
|
|
$interests = Smallworld_sanitize($_POST['interests']); |
|
226
|
|
|
$music = Smallworld_sanitize($_POST['music']); |
|
227
|
|
|
$tvshow = Smallworld_sanitize($_POST['tvshow']); |
|
228
|
|
|
$movie = Smallworld_sanitize($_POST['movie']); |
|
229
|
|
|
$books = Smallworld_sanitize($_POST['books']); |
|
230
|
|
|
$aboutme = Smallworld_sanitize($_POST['aboutme']); |
|
231
|
|
|
$school_type = Smallworld_sanitize(serialize($_POST['school_type'])); |
|
232
|
|
|
$school = Smallworld_sanitize(serialize($_POST['school'])); |
|
233
|
|
|
$schoolstart = Smallworld_sanitize(serialize($_POST['schoolstart'])); |
|
234
|
|
|
$schoolstop = Smallworld_sanitize(serialize($_POST['schoolstop'])); |
|
235
|
|
|
$jobemployer = Smallworld_sanitize(serialize($_POST['employer'])); |
|
236
|
|
|
$jobposition = Smallworld_sanitize(serialize($_POST['position'])); |
|
237
|
|
|
$jobstart = Smallworld_sanitize(serialize(Smallworld_YearOfArray($_POST['jobstart']))); |
|
238
|
|
|
$jobstop = Smallworld_sanitize(serialize(Smallworld_YearOfArray($_POST['jobstop']))); |
|
239
|
|
|
$jobdescription = Smallworld_sanitize(serialize($_POST['description'])); |
|
240
|
|
|
|
|
241
|
|
|
$sql = ''; |
|
|
|
|
|
|
242
|
|
|
|
|
243
|
|
|
if ('edit' === $_POST['function']) { |
|
244
|
|
|
// Update all values in user_table |
|
245
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_user') . ' SET '; |
|
246
|
|
|
$sql .= "realname = '" . $realname . "', username= '" . $username . "', userimage = '" . $avatar . "', gender = '" . $gender . "',"; |
|
247
|
|
|
$sql .= "intingender = '" . $intingender . "',relationship = '" . $relationship . "', partner = '" . $partner . "', searchrelat = '" . $searchrelat . "',"; |
|
248
|
|
|
$sql .= "birthday = '" . $birthday . "',birthplace = '" . $birthplace . "',birthplace_lat = '" . (float)$birthplace_lat . "',"; |
|
249
|
|
|
$sql .= "birthplace_lng = '" . (float)$birthplace_lng . "',birthplace_country = '" . $birthplace_country . "',politic = '" . $politic . "',"; |
|
250
|
|
|
$sql .= "religion = '" . $religion . "',emailtype = '" . $emailtype . "',screenname_type = '" . $screenname_type . "',"; |
|
251
|
|
|
$sql .= "screenname = '" . $screenname . "',mobile = '" . (float)$mobile . "',phone = '" . (float)$phone . "',adress = '" . $adress . "',"; |
|
252
|
|
|
$sql .= "present_city = '" . $present_city . "',present_lat = '" . (float)$present_lat . "',present_lng = '" . (float)$present_lng . "',"; |
|
253
|
|
|
$sql .= "present_country = '" . $present_country . "',website = '" . $website . "',interests = '" . $interests . "',"; |
|
254
|
|
|
$sql .= "music = '" . $music . "',tvshow = '" . $tvshow . "',movie = '" . $movie . "',"; |
|
255
|
|
|
$sql .= "books = '" . $books . "',aboutme = '" . $aboutme . "',school_type = '" . $school_type . "',"; |
|
256
|
|
|
$sql .= "school = '" . $school . "', schoolstart = '" . $schoolstart . "',schoolstop = '" . $schoolstop . "',"; |
|
257
|
|
|
$sql .= "employer = '" . $jobemployer . "', position = '" . $jobposition . "',jobstart = '" . $jobstart . "',"; |
|
258
|
|
|
$sql .= "jobstop = '" . $jobstop . "', description = '" . $jobdescription . "' "; |
|
259
|
|
|
$sql .= "WHERE userid ='" . (int)$uid . "'"; |
|
260
|
|
|
$result = $xoopsDB->queryF($sql); |
|
261
|
|
|
if (false === $result) { |
|
262
|
|
|
die('SQL error:' . $sql . ''); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
$this->EditAdmins($uid, $realname, $avatar); |
|
266
|
|
|
$img->createAlbum($uid); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
if ('save' === $_POST['function']) { |
|
270
|
|
|
$sql = 'INSERT INTO ' |
|
271
|
|
|
. $xoopsDB->prefix('smallworld_user') |
|
272
|
|
|
. ' (id, userid, regdate, username, userimage, realname, gender, intingender, relationship, partner, searchrelat, birthday, birthplace, birthplace_lat, birthplace_lng, birthplace_country, politic, religion, emailtype, screenname_type, screenname, mobile, phone, adress, present_city, present_lat, present_lng, present_country, website, interests, music, tvshow, movie, books, aboutme, school_type, school, schoolstart, schoolstop, employer, position, jobstart, jobstop, description, friends, followers, admin_flag) '; |
|
273
|
|
|
$sql .= "VALUES ('','" . (int)$uid . "', '" . $regdate . "', '" . $username . "', '" . $avatar . "', '" . $realname . "', '" . $gender . "', '" . $intingender . "', '" . $relationship . "', '" . $partner . "', '" . $searchrelat . "','"; |
|
274
|
|
|
$sql .= $birthday . "', '" . $birthplace . "', '" . (float)$birthplace_lat . "', '" . (float)$birthplace_lng . "', '" . $birthplace_country . "', '" . $politic . "', '" . $religion . "','"; |
|
275
|
|
|
$sql .= $emailtype . "', '" . $screenname_type . "', '" . $screenname . "', '" . (float)$mobile . "', '" . (float)$phone . "', '" . $adress . "', '" . $present_city . "', '" . (float)$present_lat . "','"; |
|
276
|
|
|
$sql .= (float)$present_lng . "', '" . $present_country . "', '" . $website . "', '" . $interests . "', '" . $music . "', '" . $tvshow . "', '" . $movie . "', '" . $books . "', '" . $aboutme . "', '"; |
|
277
|
|
|
$sql .= $school_type . "', '" . $school . "', '" . $schoolstart . "', '" . $schoolstop . "', '" . $jobemployer . "', '" . $jobposition . "', '" . $jobstart . "', '" . $jobstop . "', '" . $jobdescription . "', "; |
|
278
|
|
|
$sql .= "'0', '0', '0')"; |
|
279
|
|
|
$result = $xoopsDB->queryF($sql); |
|
280
|
|
|
if (false === $result) { |
|
281
|
|
|
die('SQL error:' . $sql . ''); |
|
282
|
|
|
} |
|
283
|
|
|
$this->SetAdmins($uid, $username, $realname, $avatar); |
|
284
|
|
|
$img->createAlbum($uid); |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* SetAdmins function |
|
290
|
|
|
* @param int $userID |
|
291
|
|
|
* @param string $username |
|
292
|
|
|
* @param string $realname |
|
293
|
|
|
* @param mixed $avatar |
|
294
|
|
|
* @return void |
|
295
|
|
|
*/ |
|
296
|
|
|
public function SetAdmins($userID, $username, $realname, $avatar) |
|
297
|
|
|
{ |
|
298
|
|
|
global $xoopsDB, $xoopsUser; |
|
299
|
|
|
$ip = $_SERVER['REMOTE_ADDR']; |
|
300
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_admin') . ' (id,userid,username, realname,userimage,ip,complaint,inspect_start, ' . "inspect_stop) VALUES ('', '" . $userID . "', '" . $username . "','" . $realname . "', '" . $avatar . "','" . $ip . "','0','0','0')"; |
|
301
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* EditAdmins function |
|
306
|
|
|
* @param int $userID |
|
307
|
|
|
* @param string $realname |
|
308
|
|
|
* @param mixed $avatar |
|
309
|
|
|
* @return void |
|
310
|
|
|
*/ |
|
311
|
|
|
public function EditAdmins($userID, $realname, $avatar) |
|
312
|
|
|
{ |
|
313
|
|
|
global $xoopsDB; |
|
314
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_admin') . " SET realname = '" . $realname . "', userimage = '" . $avatar . "' WHERE userid = '" . (int)$userID . "'"; |
|
315
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* alreadycomplaint function |
|
320
|
|
|
* - Check if user has already sent complaint |
|
321
|
|
|
* @param string $msg |
|
322
|
|
|
* @param int $by |
|
323
|
|
|
* @param int $against |
|
324
|
|
|
* @return int |
|
325
|
|
|
*/ |
|
326
|
|
|
public function alreadycomplaint($msg, $by, $against) |
|
327
|
|
|
{ |
|
328
|
|
|
global $xoopsDB; |
|
329
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_complaints') . " WHERE byuser_id = '" . (int)$by . "' AND owner = '" . (int)$against . "' AND link = '" . addslashes($msg) . "'"; |
|
330
|
|
|
$result = $xoopsDB->queryF($sql); |
|
331
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
332
|
|
|
if ($i < 1) { |
|
333
|
|
|
$query = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_complaints') . " (complaint_id,link,byuser_id,owner) VALUES ('', '" . addslashes($msg) . "', '" . (int)$by . "', '" . (int)$against . "')"; |
|
334
|
|
|
$result = $xoopsDB->queryF($query); |
|
|
|
|
|
|
335
|
|
|
} else { |
|
336
|
|
|
} |
|
337
|
|
|
return $i; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* updateComplaint function |
|
342
|
|
|
* @param int $userID |
|
343
|
|
|
* @return void |
|
344
|
|
|
*/ |
|
345
|
|
|
public function updateComplaint($userID) |
|
346
|
|
|
{ |
|
347
|
|
|
global $xoopsDB; |
|
348
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_admin') . ' SET complaint = complaint + 1 ' . "WHERE userid = '" . (int)$userID . "'"; |
|
349
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* updateInspection function |
|
354
|
|
|
* @param int $userID |
|
355
|
|
|
* @param int $start |
|
356
|
|
|
* @param int stop |
|
357
|
|
|
* @return void |
|
358
|
|
|
*/ |
|
359
|
|
|
public function updateInspection($userID, $start, $stop) |
|
|
|
|
|
|
360
|
|
|
{ |
|
361
|
|
|
global $xoopsDB; |
|
362
|
|
|
$newstop = $time() + $stop; |
|
|
|
|
|
|
363
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_admin') . " SET inspect_start = '" . $time() . "', instect_stop = '" . $newstop . "' WHERE userid ='" . (int)$userID . "'"; |
|
364
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* handleImageEdit function |
|
369
|
|
|
* @return void |
|
370
|
|
|
*/ |
|
371
|
|
|
public function handleImageEdit() |
|
372
|
|
|
{ |
|
373
|
|
|
global $xoopsDB; |
|
374
|
|
|
for ($i = 0, $iMax = count($_POST['id']); $i < $iMax; ++$i) { |
|
375
|
|
|
$id = (int)$_POST['id'][$i]; |
|
376
|
|
|
$desc = $_POST['imgdesc'][$i]; |
|
377
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_images') . " SET `desc` = '" . addslashes($desc) . "' WHERE `id`='" . $id . "'"; |
|
378
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
379
|
|
|
} |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* updateInspection function |
|
384
|
|
|
* - insert aplication for friendship into db or delete if denied |
|
385
|
|
|
* @param int $status |
|
386
|
|
|
* @param int $friendid |
|
387
|
|
|
* @param int $userid |
|
388
|
|
|
* @return void |
|
389
|
|
|
*/ |
|
390
|
|
|
public function toogleFriendInvite($status, $friendid, $userid) |
|
391
|
|
|
{ |
|
392
|
|
|
global $xoopsDB; |
|
393
|
|
|
if (0 == $status) { |
|
394
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_friends') . " (id,me,you,status,date) VALUES ('', '" . $userid . "', '" . $friendid . "', '1', UNIX_TIMESTAMP())"; |
|
395
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
396
|
|
|
} |
|
397
|
|
View Code Duplication |
if ($status > 0) { |
|
|
|
|
|
|
398
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$friendid . "' AND you = '" . (int)$userid . "'"; |
|
399
|
|
|
$sql2 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$userid . "' AND you = '" . (int)$friendid . "'"; |
|
400
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
401
|
|
|
$result2 = $xoopsDB->queryF($sql2); |
|
|
|
|
|
|
402
|
|
|
|
|
403
|
|
|
// Since friendship is canceled also following is deleted |
|
404
|
|
|
$this->toogleFollow(1, $userid, $friendid); |
|
405
|
|
|
} |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
/** |
|
409
|
|
|
* toogleFollow function |
|
410
|
|
|
* - Insert following to db or delete if requested |
|
411
|
|
|
* @param int $following |
|
412
|
|
|
* @param int $myUid |
|
413
|
|
|
* @param int $friend |
|
414
|
|
|
* @return void |
|
415
|
|
|
*/ |
|
416
|
|
|
public function toogleFollow($following, $myUid, $friend) |
|
417
|
|
|
{ |
|
418
|
|
|
global $xoopsDB; |
|
419
|
|
|
if (0 == $following) { |
|
420
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_followers') . " (id,me,you,status,date) VALUES ('', '" . $myUid . "', '" . $friend . "', '1', UNIX_TIMESTAMP())"; |
|
421
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
422
|
|
|
} |
|
423
|
|
|
if ($following > 0) { |
|
424
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE you = '" . (int)$friend . "'"; |
|
425
|
|
|
$sql .= " AND me = '" . (int)$myUid . "'"; |
|
426
|
|
|
$sql2 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . (int)$friend . "'"; |
|
427
|
|
|
$sql2 .= " AND you = '" . (int)$myUid . "'"; |
|
428
|
|
|
$result2 = $xoopsDB->queryF($sql2); |
|
|
|
|
|
|
429
|
|
|
} |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* SetFriendshitStat function |
|
434
|
|
|
* @param int $stat |
|
435
|
|
|
* @param int $myUid |
|
436
|
|
|
* @param int $friend |
|
437
|
|
|
* @return void |
|
438
|
|
|
*/ |
|
439
|
|
|
public function SetFriendshitStat($stat, $myUid, $friend) |
|
440
|
|
|
{ |
|
441
|
|
|
global $xoopsDB; |
|
442
|
|
|
if (1 == $stat) { |
|
443
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_friends') . " SET status = '2' WHERE `me` = '" . $friend . "' AND `you` = '" . $myUid . "'"; |
|
444
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
445
|
|
|
$query = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_friends') . " (id,me,you,status,date) VALUES ('', '" . $myUid . "', '" . $friend . "', '2', UNIX_TIMESTAMP())"; |
|
446
|
|
|
$result = $xoopsDB->queryF($query); |
|
|
|
|
|
|
447
|
|
|
} |
|
448
|
|
View Code Duplication |
if ($stat < 0) { |
|
|
|
|
|
|
449
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . (int)$friend . "' AND you = '" . (int)$myUid . "'"; |
|
450
|
|
|
$sql2 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE you = '" . (int)$friend . "' AND me = '" . (int)$myUid . "'"; |
|
451
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
452
|
|
|
$result2 = $xoopsDB->queryF($sql2); |
|
|
|
|
|
|
453
|
|
|
} |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
/** |
|
457
|
|
|
* deleteWallMsg function |
|
458
|
|
|
* @param int $id |
|
459
|
|
|
* @param int $smallworld_msg_id |
|
460
|
|
|
* @return true |
|
|
|
|
|
|
461
|
|
|
*/ |
|
462
|
|
|
public function deleteWallMsg($id, $smallworld_msg_id) |
|
|
|
|
|
|
463
|
|
|
{ |
|
464
|
|
|
global $xoopsDB; |
|
465
|
|
|
$query = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_messages') . " WHERE msg_id = '" . $smallworld_msg_id . "'"; |
|
466
|
|
|
$result = $xoopsDB->queryF($query); |
|
|
|
|
|
|
467
|
|
|
$query2 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE msg_id_fk = '" . $smallworld_msg_id . "'"; |
|
468
|
|
|
$result2 = $xoopsDB->queryF($query2); |
|
|
|
|
|
|
469
|
|
|
//delete votes |
|
470
|
|
|
$query3 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE msg_id = '" . $smallworld_msg_id . "'"; |
|
471
|
|
|
$result3 = $xoopsDB->queryF($query3); |
|
|
|
|
|
|
472
|
|
|
return true; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* deleteWallComment function |
|
477
|
|
|
* - Delete Comments |
|
478
|
|
|
* @param int $smallworld_com_id |
|
479
|
|
|
* @return true |
|
|
|
|
|
|
480
|
|
|
*/ |
|
481
|
|
View Code Duplication |
public function deleteWallComment($smallworld_com_id) |
|
|
|
|
|
|
482
|
|
|
{ |
|
483
|
|
|
global $xoopsDB; |
|
484
|
|
|
$query = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE com_id = '" . $smallworld_com_id . "'"; |
|
485
|
|
|
$result = $xoopsDB->queryF($query); |
|
|
|
|
|
|
486
|
|
|
$query2 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE com_id = '" . $smallworld_com_id . "'"; |
|
487
|
|
|
$result2 = $xoopsDB->queryF($query2); |
|
|
|
|
|
|
488
|
|
|
return true; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* CountUsersRates function |
|
493
|
|
|
* - Delete Comments |
|
494
|
|
|
* @param int $userid |
|
495
|
|
|
* @param string $val |
|
496
|
|
|
* @return int |
|
497
|
|
|
*/ |
|
498
|
|
View Code Duplication |
public function CountUsersRates($userid, $val) |
|
|
|
|
|
|
499
|
|
|
{ |
|
500
|
|
|
global $xoopsUser, $xoopsDB; |
|
501
|
|
|
$query = 'Select SUM(' . $val . ') as sum from ' . $xoopsDB->prefix('smallworld_vote') . " where owner = '" . $userid . "'"; |
|
502
|
|
|
$result = $xoopsDB->queryF($query); |
|
503
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
504
|
|
|
$sum = $row['sum']; |
|
505
|
|
|
} |
|
506
|
|
|
if ('' == $sum) { |
|
|
|
|
|
|
507
|
|
|
$sum = '0'; |
|
508
|
|
|
} |
|
509
|
|
|
return $sum; |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
/** |
|
513
|
|
|
* deleteAccount function |
|
514
|
|
|
* - Delete user account and associate rows across tables |
|
515
|
|
|
* @param int $userid |
|
516
|
|
|
* @return string |
|
|
|
|
|
|
517
|
|
|
*/ |
|
518
|
|
View Code Duplication |
public function deleteAccount($userid) |
|
|
|
|
|
|
519
|
|
|
{ |
|
520
|
|
|
global $xoopsDB, $xoopsUser; |
|
521
|
|
|
$user = new \XoopsUser($userid); |
|
522
|
|
|
$username = $user->uname(); |
|
523
|
|
|
$sql01 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_admin') . " WHERE userid = '" . $userid . "'"; |
|
524
|
|
|
$sql02 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE uid_fk = '" . $userid . "'"; |
|
525
|
|
|
$sql03 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'"; |
|
526
|
|
|
$sql04 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_friends') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'"; |
|
527
|
|
|
$sql05 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_images') . " WHERE userid = '" . $userid . "'"; |
|
528
|
|
|
$sql06 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_messages') . " WHERE uid_fk = '" . $userid . "'"; |
|
529
|
|
|
$sql07 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $userid . "'"; |
|
530
|
|
|
$sql08 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE user_id = '" . $userid . "'"; |
|
531
|
|
|
$sql09 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_complaints') . " WHERE owner = '" . $userid . "' OR byuser_id = '" . $userid . "'"; |
|
532
|
|
|
$sql10 = 'DELETE FROM ' . $xoopsDB->prefix('smallworld_settings') . " WHERE userid = '" . $userid . "'"; |
|
533
|
|
|
|
|
534
|
|
|
$result01 = $xoopsDB->queryF($sql01); |
|
|
|
|
|
|
535
|
|
|
$result02 = $xoopsDB->queryF($sql02); |
|
|
|
|
|
|
536
|
|
|
$result03 = $xoopsDB->queryF($sql03); |
|
|
|
|
|
|
537
|
|
|
$result04 = $xoopsDB->queryF($sql04); |
|
|
|
|
|
|
538
|
|
|
$result05 = $xoopsDB->queryF($sql05); |
|
|
|
|
|
|
539
|
|
|
$result06 = $xoopsDB->queryF($sql06); |
|
|
|
|
|
|
540
|
|
|
$result07 = $xoopsDB->queryF($sql07); |
|
|
|
|
|
|
541
|
|
|
$result08 = $xoopsDB->queryF($sql08); |
|
|
|
|
|
|
542
|
|
|
$result09 = $xoopsDB->queryF($sql09); |
|
|
|
|
|
|
543
|
|
|
$result10 = $xoopsDB->queryF($sql10); |
|
|
|
|
|
|
544
|
|
|
// Remove picture dir |
|
545
|
|
|
$dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/'; |
|
546
|
|
|
$this->smallworld_remDir($userid, $dirname, $empty = false); |
|
547
|
|
|
echo $username . _AM_SMALLWORLD_ADMIN_USERDELETEDALERT; |
|
548
|
|
|
} |
|
549
|
|
|
|
|
550
|
|
|
/** |
|
551
|
|
|
* SmallworldDeleteDirectory function |
|
552
|
|
|
* - Delete images from users on delete |
|
553
|
|
|
* @param int $userid |
|
554
|
|
|
* @return true |
|
|
|
|
|
|
555
|
|
|
*/ |
|
556
|
|
View Code Duplication |
public function SmallworldDeleteDirectory($userid) |
|
|
|
|
|
|
557
|
|
|
{ |
|
558
|
|
|
$dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/'; |
|
559
|
|
|
if (is_dir($dirname)) { |
|
560
|
|
|
$dir_handle = opendir($dirname); |
|
561
|
|
|
} |
|
562
|
|
|
if (!$dir_handle) { |
|
|
|
|
|
|
563
|
|
|
return false; |
|
564
|
|
|
} |
|
565
|
|
|
while ($file = readdir($dir_handle)) { |
|
566
|
|
|
if ('.' !== $file && '..' !== $file) { |
|
567
|
|
|
if (!is_dir($dirname . '/' . $file)) { |
|
568
|
|
|
unlink($dirname . '/' . $file); |
|
569
|
|
|
} else { |
|
570
|
|
|
$this->SmallworldDeleteDirectory($dirname . '/' . $file); |
|
571
|
|
|
} |
|
572
|
|
|
} |
|
573
|
|
|
} |
|
574
|
|
|
closedir($dir_handle); |
|
575
|
|
|
rmdir($dirname); |
|
576
|
|
|
return true; |
|
577
|
|
|
} |
|
578
|
|
|
|
|
579
|
|
|
/** |
|
580
|
|
|
* smallworld_remDir function |
|
581
|
|
|
* - Remove user image dir in uploads. |
|
582
|
|
|
* @param int $userid |
|
583
|
|
|
* @param string|bool $directory |
|
584
|
|
|
* @param bool|int $empty |
|
585
|
|
|
* @return true |
|
|
|
|
|
|
586
|
|
|
*/ |
|
587
|
|
View Code Duplication |
public function smallworld_remDir($userid, $directory, $empty = false) |
|
|
|
|
|
|
588
|
|
|
{ |
|
589
|
|
|
if ('' != $userid) { |
|
590
|
|
|
if ('/' === substr($directory, -1)) { |
|
591
|
|
|
$directory = substr($directory, 0, -1); |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
if (!file_exists($directory) || !is_dir($directory)) { |
|
595
|
|
|
return false; |
|
596
|
|
|
} elseif (!is_readable($directory)) { |
|
597
|
|
|
return false; |
|
598
|
|
|
} else { |
|
599
|
|
|
$directoryHandle = opendir($directory); |
|
600
|
|
|
while ($contents = readdir($directoryHandle)) { |
|
601
|
|
|
if ('.' !== $contents && '..' !== $contents) { |
|
602
|
|
|
$path = $directory . '/' . $contents; |
|
603
|
|
|
if (is_dir($path)) { |
|
604
|
|
|
$this->smallworld_remDir($userid, $path); |
|
605
|
|
|
} else { |
|
606
|
|
|
unlink($path); |
|
607
|
|
|
} |
|
608
|
|
|
} |
|
609
|
|
|
} |
|
610
|
|
|
closedir($directoryHandle); |
|
611
|
|
|
if (false === $empty) { |
|
612
|
|
|
if (!rmdir($directory)) { |
|
613
|
|
|
return false; |
|
614
|
|
|
} |
|
615
|
|
|
} |
|
616
|
|
|
return true; |
|
617
|
|
|
} |
|
618
|
|
|
} |
|
619
|
|
|
} |
|
620
|
|
|
|
|
621
|
|
|
/** |
|
622
|
|
|
* Update private settings |
|
623
|
|
|
* @param int id ($userid) |
|
624
|
|
|
* @param string posts (serialized values) |
|
625
|
|
|
* @return void |
|
626
|
|
|
*/ |
|
627
|
|
|
public function saveSettings($id, $posts) |
|
628
|
|
|
{ |
|
629
|
|
|
global $xoopsDB; |
|
630
|
|
|
$sql = 'SELECT value FROM ' . $xoopsDB->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$id . ''; |
|
631
|
|
|
$result = $xoopsDB->queryF($sql); |
|
632
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
633
|
|
|
if ($i > 0) { |
|
634
|
|
|
$sql = 'UPDATE ' . $xoopsDB->prefix('smallworld_settings') . " SET value = '" . $posts . "' WHERE userid = " . (int)$id . ''; |
|
635
|
|
|
} else { |
|
636
|
|
|
$sql = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_settings') . " (id,userid,value) VALUES ('', '" . $id . "', '" . $posts . "')"; |
|
637
|
|
|
} |
|
638
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
639
|
|
|
$this->GetSettings($id); |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
/** |
|
643
|
|
|
* Retrieve private settings |
|
644
|
|
|
* @param int userid |
|
645
|
|
|
* @return serialized|string |
|
|
|
|
|
|
646
|
|
|
*/ |
|
647
|
|
|
public function GetSettings($userid) |
|
648
|
|
|
{ |
|
649
|
|
|
global $xoopsDB; |
|
650
|
|
|
$sql = 'SELECT value FROM ' . $xoopsDB->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$userid . ''; |
|
651
|
|
|
$result = $xoopsDB->queryF($sql); |
|
652
|
|
|
$i = $xoopsDB->getRowsNum($result); |
|
653
|
|
|
if ($i < 1) { |
|
654
|
|
|
$posts = serialize( |
|
655
|
|
|
[ |
|
656
|
|
|
'posts' => 0, |
|
657
|
|
|
'comments' => 0, |
|
658
|
|
|
'notify' => 1, |
|
659
|
|
|
] |
|
660
|
|
|
); |
|
661
|
|
|
$this->saveSettings($userid, $posts); |
|
662
|
|
|
$this->GetSettings($userid); |
|
663
|
|
|
} else { |
|
664
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
|
665
|
|
|
$data = $row['value']; |
|
666
|
|
|
} |
|
667
|
|
|
return json_encode(unserialize(stripslashes($data))); |
|
|
|
|
|
|
668
|
|
|
} |
|
669
|
|
|
} |
|
670
|
|
|
} |
|
671
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.