|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DBStaticNote { |
|
4
|
|
|
|
|
5
|
|
|
public static function db_note_list_delete($where) { |
|
6
|
|
|
classSupernova::$gc->db->doDeleteDeprecated(TABLE_NOTES, $where); |
|
|
|
|
|
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
public static function db_note_get_id_and_owner($note_id_edit) { |
|
10
|
|
|
return classSupernova::$db->doSelectFetch("SELECT `id`, `owner` FROM {{notes}} WHERE `id` = {$note_id_edit} LIMIT 1 FOR UPDATE"); |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @param $user_id |
|
15
|
|
|
* @param bool $sticky |
|
16
|
|
|
* |
|
17
|
|
|
* @return array|bool|mysqli_result|null |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function db_note_list_by_owner($user_id, $sticky = false) { |
|
20
|
|
|
$sticky = $sticky ? ' AND `sticky` = 1' : ''; |
|
21
|
|
|
$extra_sort = $sticky ? ' `galaxy` ASC, `system` ASC, `planet` ASC, `planet_type` ASC,' : ''; |
|
22
|
|
|
$notes_query = classSupernova::$db->doSelect("SELECT * FROM `{{notes}}` WHERE `owner` = {$user_id} {$sticky} ORDER BY `priority` DESC, {$extra_sort} `time` DESC"); |
|
23
|
|
|
|
|
24
|
|
|
return $notes_query; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param $note_priority |
|
29
|
|
|
* @param $note_title |
|
30
|
|
|
* @param $note_text |
|
31
|
|
|
* @param $note_galaxy |
|
32
|
|
|
* @param $note_system |
|
33
|
|
|
* @param $note_planet |
|
34
|
|
|
* @param $note_planet_type |
|
35
|
|
|
* @param $note_sticky |
|
36
|
|
|
* @param $note_id_edit |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function db_note_update_by_id($note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky, $note_id_edit) { |
|
39
|
|
|
classSupernova::$db->doUpdate("UPDATE {{notes}} SET `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}', |
|
40
|
|
|
`galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky} |
|
41
|
|
|
WHERE `id` = {$note_id_edit} LIMIT 1;"); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param $user |
|
46
|
|
|
* @param $note_priority |
|
47
|
|
|
* @param $note_title |
|
48
|
|
|
* @param $note_text |
|
49
|
|
|
* @param $note_galaxy |
|
50
|
|
|
* @param $note_system |
|
51
|
|
|
* @param $note_planet |
|
52
|
|
|
* @param $note_planet_type |
|
53
|
|
|
* @param $note_sticky |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function db_note_insert($user, $note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky) { |
|
56
|
|
|
classSupernova::$db->doInsert("INSERT INTO {{notes}} SET `owner` = {$user['id']}, `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}', |
|
57
|
|
|
`galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky};"); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param $user |
|
63
|
|
|
* |
|
64
|
|
|
* @return array|bool|mysqli_result|null |
|
65
|
|
|
*/ |
|
66
|
|
|
public static function db_note_list_select_by_owner_and_planet($user) { |
|
67
|
|
|
$query = classSupernova::$db->doSelect("SELECT * FROM {{notes}} WHERE `owner` = {$user['id']} AND `galaxy` <> 0 AND `system` <> 0 AND `planet` <> 0 ORDER BY `priority` DESC, `galaxy`, `system`, `planet`, `planet_type`;"); |
|
68
|
|
|
|
|
69
|
|
|
return $query; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param array $user |
|
74
|
|
|
* @param int $note_id_edit |
|
75
|
|
|
* |
|
76
|
|
|
* @throws Exception |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function processDelete($user, $note_id_edit) { |
|
79
|
|
|
$not = ''; |
|
80
|
|
|
$query_where = ''; |
|
81
|
|
|
switch (sys_get_param_str('note_delete_range')) { |
|
82
|
|
|
case 'all': |
|
83
|
|
|
break; |
|
84
|
|
|
|
|
85
|
|
|
case 'marked_not': |
|
86
|
|
|
$not = 'NOT'; |
|
87
|
|
|
case 'marked': |
|
88
|
|
|
if (!is_array($notes_marked = sys_get_param('note'))) { |
|
89
|
|
|
throw new Exception('note_err_none_selected', ERR_WARNING); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$notes_marked_filtered = array(); |
|
93
|
|
|
foreach ($notes_marked as $note_id => $note_select) { |
|
94
|
|
|
if ($note_select == 'on' && $note_id = idval($note_id)) { |
|
95
|
|
|
$notes_marked_filtered[] = $note_id; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if (empty($notes_marked_filtered)) { |
|
100
|
|
|
throw new Exception('note_err_none_selected', ERR_WARNING); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$notes_marked_filtered = implode(',', $notes_marked_filtered); |
|
104
|
|
|
$query_where = "AND `id` {$not} IN ({$notes_marked_filtered})"; |
|
105
|
|
|
break; |
|
106
|
|
|
|
|
107
|
|
|
default: |
|
108
|
|
|
throw new Exception('note_warn_no_range', ERR_WARNING); |
|
109
|
|
|
break; |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
sn_db_transaction_start(); |
|
113
|
|
|
$where['owner'] = $user['id']; |
|
|
|
|
|
|
114
|
|
|
$where[] = $query_where; |
|
115
|
|
|
DBStaticNote::db_note_list_delete($where); |
|
116
|
|
|
sn_db_transaction_commit(); |
|
117
|
|
|
|
|
118
|
|
|
throw new Exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: