/**
* Find function for Notes
* @param array $query The query to search for -- ["ip" => "127.0.0.1", "nick" => "bob", "account" => "bob", "id" => "lol]
- * @return array|NULL Returns an array of objects (notes)
+ * @return array Returns an array of objects (notes)
*/
- public static function find(array $query) : array|NULL
+ public static function find(array $query) : array
{
global $config;
read_config_db();
if (!isset($config['notes']))
- return NULL;
+ return [];
$notes = [];
foreach ($query as $key => $value)
- {
- foreach (get_config("notes") as $nkey => $nvalue)
+ {
+ foreach ($config['notes'] as $nkey => $nvalue) // $nkey = "ip" "nick" "account", $nvalue = array
{
- if ($value != $nvalue)
- continue;
-
- $note = (object)[];
- $note->id = $nkey;
- $note->type = $key;
- $note->data - $value;
- $note->note = $nvalue;
- $notes[] = $note;
+ foreach ($nvalue as $k => $n) // $k = "127.0.0.1", "bob", "bobsaccount", $n = array of notes [id => note]
+ {
+ if ($value != $k)
+ continue;
+ $note = [];
+ $note["type"] = $nkey;
+ $note["data"] = $k;
+ $note["notes"] = $n;
+ $notes[$key] = $note;
+ }
}
}
- return !empty($notes) ? $notes : NULL;
+ return !empty($notes) ? $notes : [];
}
/**
function generate_html_whois($user)
{
global $rpc;
+
+ $notes = Notes::find(["nick" => $user->name, "ip" => $user->ip, "account" => $user->account ?? NULL]);
+ $numnotes = [
+ "ip" => isset($notes['ip']['notes']) ? count($notes["ip"]['notes']) : [],
+ "nick" => isset($notes['ip']['notes']) ? count($notes["nick"]['notes'] ?? []) : [],
+ "account" => isset($notes['ip']['notes']) ? count($notes['account']['notes'] ?? []) : [],
+ ];
+
?>
<table class="table-sm table-responsive caption-top table-hover">
top:25px;
right: 25px;
background-color:lightgrey;
- font-size:small;
- "
+ font-size:small;"
>Reputation <span class="badge badge-danger" style="font-size:small;"><?php echo $user->user->reputation; ?></span>
</span>
<tbody>
<tr>
<th>Nick</th>
<td colspan="2"><code><?php echo htmlspecialchars($user->name); ?></code></td>
+ <td colspan="2"><button id="nicknotes" class="btn btn-sm btn-secondary fa-solid fa-sticky-note text-nowrap"> <?php echo $numnotes['nick']?></div></button></td>
</tr><tr>
<th>User ID (UID)</th>
<td colspan="2"><code><?php echo htmlspecialchars($user->id); ?></code></td>
<?php } ?>
<a href="<?php echo htmlspecialchars(get_config("base_url")."tools/ip-whois.php?ip=$user->ip"); ?>"><button class="btn-sm btn-primary">WHOIS IP</button></a>
</td>
+ <td><button id="ipnotes" class="btn btn-sm btn-secondary fa-solid fa-sticky-note text-nowrap"> <?php echo $numnotes['ip']?></button></td>
</tr><tr>
<th>Ident</th>
<td colspan="2"><code><?php echo htmlspecialchars($user->user->username); ?></code></td>
<tr>
<th>Logged in as</th>
<td colspan="2"><code><?php echo (isset($user->user->account)) ? "<a href=\"".get_config("base_url")."users/?account=".htmlspecialchars($user->user->account)."\">".htmlspecialchars($user->user->account)."</a>" : ""; ?></code></td>
+ <td><button id="account_notes" class="btn btn-sm btn-secondary fa-solid fa-sticky-note text-nowrap"> <?php echo $numnotes['account']?></button></td>
</tr>
<tr>
<th style="background-color: blanchedalmond;border-radius:5px";>Security Groups</th>