+}
+
+function get_chmode_group(string $mode) : int
+{
+ foreach(IRCList::$uplink as $i => $grp)
+ if (strstr($grp,$mode))
+ return $i + 1;
+
+ return 0; // invalid
+}
+
+/**
+ * Force loading of a particular modal by name
+ */
+function chlkup_autoload_modal($name)
+{
+ ?>
+ <script>
+ $(document).ready(function () {
+ $("#<?php echo $name; ?>").modal("show");
+ });
+ </script>
+ <?php
+}
+
+/**
+ * Returns an array of parametered modes and their params
+ */
+function sort_paramed_modes($modes, $params) : array
+{
+ $m = [];
+ for ($i=0; isset($modes[$i]) && $mode = $modes[$i]; $i++)
+ {
+ $group = get_chmode_group($mode);
+ if ($group != 2 && $group != 3)
+ continue;
+ $p = split($params);
+ $m[$mode] = $p[0];
+ $p[0] = NULL;
+ $params = glue($p);
+ }
+ return $m;
+}
+
+function _do_chan_item_delete($chan, string $type, array $list, array &$errors) : bool
+{
+ global $rpc;
+ $n = "";
+ $str = "";
+
+ if ($type == "invite")
+ $char = "I";
+ elseif ($type == "ban")
+ $char = "b";
+ elseif ($type == "except")
+ $char = "e";
+ else
+ return false;
+
+ foreach($list as $l)
+ {
+ // check if the string needs therapy
+ if ((strlen($n) + 1) + (strlen($str) + strlen($l)) > 150)
+ {
+ // send what we've got already and prepare for the next lot
+ if (!$rpc->channel()->set_mode($chan->name, htmlspecialchars("-$n"), htmlspecialchars($str)))
+ $errors[] = $rpc->error . " ($rpc->errno)";
+
+ // prepare for the next set
+ $n = "";
+ $str = "";
+ }
+ $n .= $char;
+ $str .= " ".$l;
+ }
+ // if multiple, this will be the last one so we return here
+ if ($rpc->channel()->set_mode($chan->name, htmlspecialchars("-$n"), htmlspecialchars($str)))
+ {
+ if (!empty($errors))
+ Message::Fail("One or more errors occurred:", $errors);
+ Message::Success("Deleted successfully");
+ return true;
+ }
+ $errors[] = $rpc->error . " ($rpc->errno)";
+ Message::Fail("An error occurred:", $errors);
+ return false;
+}
+
+function do_delete_invite($chan, $list)
+{
+ $errs = [];
+ _do_chan_item_delete($chan, "invite", $list, $errs);
+}
+
+function do_delete_chanban($chan, $list)
+{
+ $errs = [];
+ _do_chan_item_delete($chan, "ban", $list, $errs);
+}
+
+function do_delete_chanex($chan, $list)
+{
+ $errs = [];
+ _do_chan_item_delete($chan, "except", $list, $errs);
+}
+
+
+
+/**
+ * Sort the channels user list:
+ */
+function sort_user_list($list) : array
+{
+ if (empty($list))
+ return $list;
+
+ $new = [];
+ foreach($list as $k => $user)
+ {
+ if (!property_exists($user,"level"))
+ {
+ $new["rest"][] = $user;
+ $list[$k] = NULL;
+ }
+ else if (strstr($user->level,"Y"))
+ {
+ $new["Y"][] = $user;
+ $list[$k] = NULL;
+ }
+ else if (strstr($user->level,"q"))
+ {
+ $new["q"][] = $user;
+ $list[$k] = NULL;
+ }
+ else if (strstr($user->level,"a"))
+ {
+ $new["a"][] = $user;
+ $list[$k] = NULL;
+ }
+ else if (strstr($user->level,"o"))
+ {
+ $new["o"][] = $user;
+ $list[$k] = NULL;
+ }
+ else if (strstr($user->level,"h"))
+ {
+ $new["h"][] = $user;
+ $list[$k] = NULL;
+ }
+ else if (strstr($user->level,"v"))
+ {
+ $new["v"][] = $user;
+ $list[$k] = NULL;
+ }
+
+ }
+
+ unset($list);
+ $list = [];
+ if (isset($new["q"]))
+ foreach($new["q"] as $u)
+ $list[] = $u;
+
+ if (isset($new["a"]))
+ foreach($new["a"] as $u)
+ $list[] = $u;
+
+ if (isset($new["o"]))
+ foreach($new["o"] as $u)
+ $list[] = $u;
+
+ if (isset($new["h"]))
+ foreach($new["h"] as $u)
+ $list[] = $u;
+
+ if (isset($new["v"]))
+ foreach($new["v"] as $u)
+ $list[] = $u;
+
+ if (isset($new["rest"]))
+ foreach($new["rest"] as $u)
+ $list[] = $u;
+
+ return $list;