-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.php
More file actions
211 lines (177 loc) · 5.16 KB
/
report.php
File metadata and controls
211 lines (177 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
/**
*
* @package phpBB Gallery
* @copyright (c) 2014 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbgallery\core;
class report
{
const UNREPORTED = 0;
const OPEN = 1;
const LOCKED = 2;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var string */
protected $table_images;
/** @var string */
protected $table_reports;
public function __construct(\phpbb\db\driver\driver_interface $db, $image_table, $report_table)
{
$this->db = $db;
$this->table_images = $image_table;
$this->table_reports = $report_table;
}
/**
* Report an image
*
* @param int $album_id
* @param int $image_id
* @param int $reporter_id User ID of the reporting user
* @param string $report_message Additional report reason
* @return int ID of the report entry
*/
public function add($album_id, $image_id, $report_message, $user_id)
{
$data = array(
'report_album_id' => (int) $album_id,
'report_image_id' => (int) $image_id,
'reporter_id' => (int) $user_id,
'report_note' => $report_message,
'report_time' => time(),
'report_status' => self::OPEN,
);
$sql = 'INSERT INTO ' . $this->table_reports . ' ' . $this->db->sql_build_array('INSERT', $data);
$this->db->sql_query($sql);
$report_id = (int) $this->db->sql_nextid();
$sql = 'UPDATE ' . $this->table_images . '
SET image_reported = ' . $report_id . '
WHERE image_id = ' . (int) $data['report_image_id'];
$this->db->sql_query($sql);
return $report_id;
}
/**
* Change status of a report
*
* @param mixed $report_ids Array or integer with report_id.
* @param int $user_id If not set, it uses the currents user_id
*/
static public function change_status($new_status, $report_ids, $user_id = false)
{
global $db, $user;
$sql_ary = array(
'report_manager' => (int) (($user_id) ? $user_id : $user->data['user_id']),
'report_status' => $new_status,
);
$report_ids = self::cast_mixed_int2array($report_ids);
$sql = 'UPDATE ' . GALLERY_REPORTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
WHERE ' . $db->sql_in_set('report_id', $report_ids);
$db->sql_query($sql);
if ($new_status == self::LOCKED)
{
$sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
SET image_reported = ' . self::UNREPORTED . '
WHERE ' . $db->sql_in_set('image_reported', $report_ids);
$db->sql_query($sql);
}
else
{
$sql = 'SELECT report_image_id, report_id
FROM ' . GALLERY_REPORTS_TABLE . '
WHERE report_status = ' . self::OPEN . '
AND ' . $db->sql_in_set('report_id', $report_ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
SET image_reported = ' . (int) $row['report_id'] . '
WHERE image_id = ' . (int) $row['report_image_id'];
$db->sql_query($sql);
}
$db->sql_freeresult($result);
}
}
/**
* Move an image from one album to another
*
* @param mixed $image_ids Array or integer with image_id.
*/
static public function move_images($image_ids, $move_to)
{
global $db;
$image_ids = self::cast_mixed_int2array($image_ids);
$sql = 'UPDATE ' . GALLERY_REPORTS_TABLE . '
SET report_album_id = ' . (int) $move_to . '
WHERE ' . $db->sql_in_set('report_image_id', $image_ids);
$db->sql_query($sql);
}
/**
* Move the content from one album to another
*
* @param mixed $image_ids Array or integer with image_id.
*/
static public function move_album_content($move_from, $move_to)
{
global $db;
$sql = 'UPDATE ' . GALLERY_REPORTS_TABLE . '
SET report_album_id = ' . (int) $move_to . '
WHERE report_album_id = ' . (int) $move_from;
$db->sql_query($sql);
}
/**
* Delete reports for given report_ids
*
* @param mixed $report_ids Array or integer with report_id.
*/
static public function delete($report_ids)
{
global $db;
$report_ids = self::cast_mixed_int2array($report_ids);
$sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . '
WHERE ' . $db->sql_in_set('report_id', $report_ids);
$result = $db->sql_query($sql);
$sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . '
SET image_reported = ' . self::UNREPORTED . '
WHERE ' . $db->sql_in_set('image_reported', $report_ids);
$db->sql_query($sql);
}
/**
* Delete reports for given image_ids
*
* @param mixed $image_ids Array or integer with image_id.
*/
static public function delete_images($image_ids)
{
global $db;
$image_ids = self::cast_mixed_int2array($image_ids);
$sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . '
WHERE ' . $db->sql_in_set('report_image_id', $image_ids);
$result = $db->sql_query($sql);
}
/**
* Delete reports for given album_ids
*
* @param mixed $album_ids Array or integer with album_id.
*/
static public function delete_albums($album_ids)
{
global $db;
$album_ids = self::cast_mixed_int2array($album_ids);
$sql = 'DELETE FROM ' . GALLERY_REPORTS_TABLE . '
WHERE ' . $db->sql_in_set('report_album_id', $album_ids);
$result = $db->sql_query($sql);
}
static public function cast_mixed_int2array($ids)
{
if (is_array($ids))
{
return array_map('intval', $ids);
}
else
{
return array((int) $ids);
}
}
}