]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - Classes/class-notes.php
Add start of Notes functionality
[irc/unrealircd/unrealircd-webpanel.git] / Classes / class-notes.php
1 <?php
2
3 /* Make notes against nicks, IPs and account names. */
4
5 class Notes { // OKAY CLASS GET YOUR NOTEPAD OUT
6 /**
7 * Find function for Notes
8 * @param array $query The query to search for -- ["ip" => "127.0.0.1", "nick" => "bob", "account" => "bob", "id" => "lol]
9 * @return array|NULL Returns an array of objects (notes)
10 */
11 public static function find(array $query) : array|NULL
12 {
13 global $config;
14 read_config_db();
15 if (!isset($config['notes']))
16 return NULL;
17
18 $notes = [];
19 foreach ($query as $key => $value)
20 {
21 foreach (get_config("notes") as $nkey => $nvalue)
22 {
23 if ($value != $nvalue)
24 continue;
25
26 $note = (object)[];
27 $note->id = $nkey;
28 $note->type = $key;
29 $note->data - $value;
30 $note->note = $nvalue;
31 $notes[] = $note;
32 }
33 }
34 return !empty($notes) ? $notes : NULL;
35 }
36
37 /**
38 * Add a note to one or more peices of data
39 * @param array ["ip" => "127.0.0.1"]
40 * @param string $note "This is a note"
41 * @return void
42 */
43 public static function add(array $params, string $note)
44 {
45 global $config;
46 read_config_db();
47 foreach ($params as $key => $value)
48 {
49 $id = md5(random_bytes(20)); // note ID (for linking)
50 $config['notes'][$key][$value][$id] = $note;
51 }
52 write_config(); // write db
53 }
54
55 public static function delete_by_id(string $id)
56 {
57 global $config;
58 read_config_db();
59 if (!isset($config['notes']))
60 return NULL;
61
62 foreach ($config['notes'] as $nkey => $nvalue)
63 foreach ($nvalue as $key => $value)
64 if ($value == $id)
65 {
66 unset($config['notes'][$nkey][$key]);
67 break;
68 }
69
70 write_config('notes');
71 }
72 }