]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Add ability to remove channel bans/invites/exepts
authorValerie Pond <redacted>
Fri, 17 Feb 2023 23:56:43 +0000 (23:56 +0000)
committerValerie Pond <redacted>
Fri, 17 Feb 2023 23:56:43 +0000 (23:56 +0000)
channels/details.php
misc/channel-lookup-misc.php

index 488af56060c4e33eb33ad9cf4524c0a595239ccb..6f87ca5e475967df40a198e0bf0e8327e92876aa 100644 (file)
@@ -25,22 +25,17 @@ if (isset($_GET['chan']))
        }
 }
 $topicset = false;
+$del_ex = false;
+$del_inv = false;
+$del_ban = false;
+$checkboxes = [];
 if (isset($_POST))
 {
        if (isset($_POST['update_topic']) && isset($_POST['set_topic']))
        {
                if (isset($channelObj))
                {
-                       if (isset($channelObj->topic)) // if the set topic is different
-                       {
-                               if (strcmp($channelObj->topic,$_POST['set_topic']))
-                               {
-                                       $user = (function_exists('unreal_get_current_user') && $u = unreal_get_current_user()) ? $u->username : NULL;
-                                       $topicset = $rpc->channel()->set_topic($channelObj->name, $_POST['set_topic'], $user);
-                                       $channelObj->topic = $_POST['set_topic'];
-                               }
-                       }
-                       else
+                       if (!isset($channelObj->topic) || strcmp($channelObj->topic,$_POST['set_topic'])) // if the set topic is different
                        {
                                $user = (function_exists('unreal_get_current_user') && $u = unreal_get_current_user()) ? $u->username : NULL;
                                $topicset = $rpc->channel()->set_topic($channelObj->name, $_POST['set_topic'], $user);
@@ -48,6 +43,29 @@ if (isset($_POST))
                        }
                }
        }
+       $checkboxes = (isset($_POST['ban_checkboxes'])) ? $_POST['ban_checkboxes'] : [];
+       if (isset($_POST['delete_sel_ex']))
+       {
+               foreach($_POST['ce_checkboxes'] as $c)
+                       $checkboxes[] = $c;
+               $del_ex = true;
+               chlkup_autoload_modal("excepts_modal");
+       }
+       else if (isset($_POST['delete_sel_inv']))
+       {
+               foreach($_POST['ci_checkboxes'] as $c)
+                       $checkboxes[] = $c;
+               $del_inv = true;
+               chlkup_autoload_modal("invites_modal");
+       }
+       else if (isset($_POST['delete_sel_ban']))
+       {
+               foreach($_POST['cb_checkboxes'] as $c)
+                       $checkboxes[] = $c;
+               $del_ban = true;
+               chlkup_autoload_modal("bans_modal");
+       }
+
 }
 
 ?>
@@ -56,8 +74,8 @@ if (isset($_POST))
 <br>
 <form method="get" action="details.php">
 <div class="container-xxl">
-       <div class="input-group short-form-control">
-               <input  class="short-form-control" id="chan" name="chan" type="text" value="<?php echo $channame; ?>">
+       <div class="input-group">
+               <input  class="form-control" id="chan" name="chan" type="text" value="<?php echo $channame; ?>">
                <div class="input-group-append">
                        <button type="submit" class="btn btn-primary">Go</button>
                </div>
@@ -70,13 +88,12 @@ if (isset($_POST))
 
 <br>
 <h3>
-       Topic:<br></h3><h4>
+       Topic:<br></h3>
        <form method="post" action="details.php?chan=<?php echo urlencode($channelObj->name); ?>">
-       <div class="input-group short-form-control">
-       <input maxlength="360" type="text" class="short-form-control" name="set_topic" value="<?php echo (isset($channelObj->topic)) ? htmlspecialchars($channelObj->topic) : ""; ?>">
+       <div class="input-group">
+       <input maxlength="360" type="text" class="input-group form-control" name="set_topic" value="<?php echo (isset($channelObj->topic)) ? htmlspecialchars($channelObj->topic) : ""; ?>">
        <div class="input-group-append"><button type="submit" name="update_topic" value="true" class="btn btn-info">Update Topic</button></div></div>
        </form>
-</h4>
 <?php 
 if ($topicset)
        Message::Success("The topic for $channelObj->name has been updated to be: \"".htmlspecialchars($channelObj->topic)."\"");
@@ -102,6 +119,7 @@ if ($topicset)
                        </button>
                </div>
                <div class="modal-body">
+                       <?php if ($del_ban) do_delete_chanban($channelObj, $checkboxes); ?>
                        <form method="post">
                        <?php generate_chanbans_table($channelObj); ?>          
                        </form>
@@ -120,6 +138,7 @@ if ($topicset)
                        </button>
                </div>
                <div class="modal-body">
+                       <?php if ($del_inv) do_delete_invite($channelObj, $checkboxes); ?>
                        <form method="post">
                        <?php generate_chaninvites_table($channelObj); ?>               
                        </form>
@@ -139,6 +158,7 @@ if ($topicset)
                        </button>
                </div>
                <div class="modal-body">
+                       <?php if ($del_ex) do_delete_chanex($channelObj, $checkboxes); ?>
                        <form method="post">
                        <?php generate_chanexcepts_table($channelObj); ?>               
                        </form>
index ecca808b5bfb740357b46381982db8596b16a168..b55cbd866c7756d2c4cda3534e843b4dfd540061 100644 (file)
 
 function generate_chanbans_table($channel)
 {
-    ?>
-    <form method="post"><p>
-    <button class="btn btn-info btn-sm" type="submit" name="delete_sel_ban">Delete</button>
-    </p>
-    <table class="table table-responsive table-hover">
-    <thead class="table-info">
-        <th><input type="checkbox" label='selectall' onClick="toggle_checkbox(this)" /></th>
-        <th>Name</th>
-        <th>Set by</th>
-        <th>Set at</th>
-        <th></th>
-    </thead>
-    <tbody>
-        <?php
-        foreach ($channel->bans as $ban) {
-            echo "<tr>";
-            echo "<td scope=\"row\"><input type=\"checkbox\" value='$ban->name' name=\"checkboxes[]\"></td>";
-            echo "<td><code>".htmlspecialchars($ban->name)."</code></td>";
-            $set_by = htmlspecialchars($ban->set_by);
-            echo "<td>$set_by</td>";
-            $set_at = $ban->set_at;
-            echo "<td>$set_at</td>";
-            echo "<td></td>";
-            echo "</tr>";
-        }
-
-        ?>
-    </tbody>
-    </table>
-    </form>
-    <?php
+       global $rpc;
+       $channel = $rpc->channel()->get($channel->name);
+       ?>
+       <form method="post"><p>
+       <button class="btn btn-info btn-sm" type="submit" name="delete_sel_ban">Delete</button>
+       </p>
+       <table class="table table-responsive table-hover">
+       <thead class="table-info">
+               <th><input type="checkbox" label='selectall' onClick="toggle_chanbans(this)" /></th>
+               <th>Name</th>
+               <th>Set by</th>
+               <th>Set at</th>
+               <th></th>
+       </thead>
+       <tbody>
+               <?php
+               foreach ($channel->bans as $ban) {
+                       echo "<tr>";
+                       echo "<td scope=\"row\"><input type=\"checkbox\" value='$ban->name' name=\"cb_checkboxes[]\"></td>";
+                       echo "<td><code>".htmlspecialchars($ban->name)."</code></td>";
+                       $set_by = htmlspecialchars($ban->set_by);
+                       echo "<td>$set_by</td>";
+                       $set_at = $ban->set_at;
+                       echo "<td>$set_at</td>";
+                       echo "<td></td>";
+                       echo "</tr>";
+               }
+
+               ?>
+       </tbody>
+       </table>
+       </form>
+       <?php
 }
 function generate_chaninvites_table($channel)
 {
-    ?>
-    <form method="post"><p>
-    <button class="btn btn-info btn-sm" type="submit" name="delete_sel_inv">Delete</button>
-    </p>
-    <table class="table table-responsive table-hover">
-    <thead class="table-info">
-        <th><input type="checkbox" label='selectall' onClick="toggle_checkbox(this)" /></th>
-        <th>Name</th>
-        <th>Set by</th>
-        <th>Set at</th>
-        <th></th>
-    </thead>
-    <tbody>
-        <?php
-        foreach ($channel->invite_exceptions as $inv) {
-            echo "<tr>";
-            echo "<td scope=\"row\"><input type=\"checkbox\" value='$inv->name' name=\"checkboxes[]\"></td>";
-            echo "<td><code>".htmlspecialchars($inv->name)."</code></td>";
-            $set_by = htmlspecialchars($inv->set_by);
-            echo "<td>$set_by</td>";
-            $set_at = $inv->set_at;
-            echo "<td>$set_at</td>";
-            echo "<td></td>";
-            echo "</tr>";
-        }
-
-        ?>
-    </tbody>
-    </table>
-    </form>
-    <?php
+       global $rpc;
+       $channel = $rpc->channel()->get($channel->name);
+       ?>
+       <form method="post"><p>
+       <button class="btn btn-info btn-sm" type="submit" name="delete_sel_inv">Delete</button>
+       </p>
+       <table class="table table-responsive table-hover">
+       <thead class="table-info">
+               <th><input type="checkbox" label='selectall' onClick="toggle_chaninvs(this)" /></th>
+               <th>Name</th>
+               <th>Set by</th>
+               <th>Set at</th>
+               <th></th>
+       </thead>
+       <tbody>
+               <?php
+               foreach ($channel->invite_exceptions as $inv) {
+                       echo "<tr>";
+                       echo "<td scope=\"row\"><input type=\"checkbox\" value='$inv->name' name=\"ci_checkboxes[]\"></td>";
+                       echo "<td><code>".htmlspecialchars($inv->name)."</code></td>";
+                       $set_by = htmlspecialchars($inv->set_by);
+                       echo "<td>$set_by</td>";
+                       $set_at = $inv->set_at;
+                       echo "<td>$set_at</td>";
+                       echo "<td></td>";
+                       echo "</tr>";
+               }
+
+               ?>
+       </tbody>
+       </table>
+       </form>
+       <?php
 }
 
 
 function generate_chanexcepts_table($channel)
 {
-    ?>
-    <form method="post"><p>
-    <button class="btn btn-info btn-sm" type="submit" name="delete_sel_ex">Delete</button>
-    </p>
-    <table class="table table-responsive table-hover">
-    <thead class="table-info">
-        <th><input type="checkbox" label='selectall' onClick="toggle_checkbox(this)" /></th>
-        <th>Name</th>
-        <th>Set by</th>
-        <th>Set at</th>
-        <th></th>
-    </thead>
-    <tbody>
-        <?php
-        foreach ($channel->ban_exemptions as $ex) {
-            echo "<tr>";
-            echo "<td scope=\"row\"><input type=\"checkbox\" value='$ex->name' name=\"checkboxes[]\"></td>";
-            echo "<td><code>".htmlspecialchars($ex->name)."</code></td>";
-            $set_by = htmlspecialchars($ex->set_by);
-            echo "<td>$set_by</td>";
-            $set_at = $ex->set_at;
-            echo "<td>$set_at</td>";
-            echo "<td></td>";
-            echo "</tr>";
-        }
-
-        ?>
-    </tbody>
-    </table>
-    </form>
-    <?php
-}
+       global $rpc;
+       $channel = $rpc->channel()->get($channel->name);
+       ?>
+       <form method="post"><p>
+       <button class="btn btn-info btn-sm" type="submit" name="delete_sel_ex">Delete</button>
+       </p>
+       <table class="table table-responsive table-hover">
+       <thead class="table-info">
+               <th><input type="checkbox" label='selectall' onClick="toggle_chanexs(this)" /></th>
+               <th>Name</th>
+               <th>Set by</th>
+               <th>Set at</th>
+               <th></th>
+       </thead>
+       <tbody>
+               <?php
+               foreach ($channel->ban_exemptions as $ex) {
+                       echo "<tr>";
+                       echo "<td scope=\"row\"><input type=\"checkbox\" value='$ex->name' name=\"ce_checkboxes[]\"></td>";
+                       echo "<td><code>".htmlspecialchars($ex->name)."</code></td>";
+                       $set_by = htmlspecialchars($ex->set_by);
+                       echo "<td>$set_by</td>";
+                       $set_at = $ex->set_at;
+                       echo "<td>$set_at</td>";
+                       echo "<td></td>";
+                       echo "</tr>";
+               }
 
+               ?>
+       </tbody>
+       </table>
+       </form>
+       <?php
+}
 
+/**
+ *  Generate the user list of a channel
+ * 
+ * Why is it called chan occupants? o.o
+ * For the code, to avoid mixups
+ * It's called "User List" on the website
+ * @param mixed $channel
+ * @return void
+ */
 function generate_chan_occupants_table($channel)
 {
-    ?>
-    <form method="post"><p>
-    
-    </p>
-    <table class="table table-responsive table-hover">
-    <thead class="table-info">
-        <th><input type="checkbox" label='selectall' onClick="toggle_checkbox(this)" /></th>
-        <th>Name</th>
-        <th>Status</th>
-        <th>Actions</th>
-        <th></th>
-    </thead>
-    <tbody>
-        <?php
-        foreach ($channel->members as $member) {
-            echo "<tr>";
-            echo "<td scope=\"row\"><input type=\"checkbox\" value='$member->id' name=\"checkboxes[]\"></td>";
-            echo "<td><a href=\"".BASE_URL."users/details.php?nick=$member->id\">".htmlspecialchars($member->name)."</a></td>";
-            echo "<td>Status</td>";
-            echo "<td>Op</td>";
-            echo "<td>Deop</td>";
-            echo "</tr>";
-        }
-
-        ?>
-    </tbody>
-    </table>
-    </form>
-
-    <?php
+       ?>
+       <form method="post"><p>
+       
+       </p>
+       <table class="table table-responsive table-hover">
+       <thead class="table-info">
+               <th><input type="checkbox" label='selectall' onClick="toggle_checkbox(this)" /></th>
+               <th>Name</th>
+               <th>Status</th>
+               <th>Actions</th>
+               <th></th>
+       </thead>
+       <tbody>
+               <?php
+               foreach ($channel->members as $member) {
+                       echo "<tr>";
+                       echo "<td scope=\"row\"><input type=\"checkbox\" value='$member->id' name=\"checkboxes[]\"></td>";
+                       echo "<td><a href=\"".BASE_URL."users/details.php?nick=$member->id\">".htmlspecialchars($member->name)."</a></td>";
+                       echo "<td>Status</td>";
+                       echo "<td>Op</td>";
+                       echo "<td>Deop</td>";
+                       echo "</tr>";
+               }
+
+               ?>
+       </tbody>
+       </table>
+       </form>
+
+       <?php
+}
+
+function chlkup_autoload_modal($name)
+{
+       ?>
+               <script>
+                       $(document).ready(function () {
+                               $("#<?php echo $name; ?>").modal("show");
+                       });
+               </script>
+       <?php
+}
+
+
+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)
+       {
+               $n .= $char;
+               $str .= " ".$l;
+       }
+       if ($rpc->channel()->set_mode($chan->name, "-$n", $str))
+       {
+               Message::Success("Deleted successfully");
+               return true;
+       }
+       $errors[] = $rpc->error . " ($rpc->errno)";
+               Message::Fail("An error occurred: $rpc->error");
+       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);
 }
\ No newline at end of file