Private Message Checkbox - Help (1.3.5)

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
270
Points
18
Age
29
Location
Tennessee
Mysidian Dollar
13,272
So I'm needing help with my private message checkbox that's replaced the img url thingy. This is my class_messagetablehelper.php file
protected function getDeleteLink($param){
$path = Registry::get("path");
$deletebox = new Comment("<form action='../../messages' method='post'>
<input type='checkbox' class='checkbox' name='checkdelete' value='Delete'>
<input id='input' class='button' type='submit' value='DELETE'>
</form>
<style>
input.checkbox {
position: relative;
top: 15px;
}
input#input {
position: relative;
left: 0px;
bottom: -15px;
background-color: red;
font-weight: bold;
width: 80px;
}
</style>
<script>
var checkboxes=document.getElementsByClassName('checkbox');
for(let i=0;i<checkboxes.length;i++){
checkboxes.onclick=function(){
if (checkboxes.checked) {
checkboxes.style.outlineColor = 'red';
checkboxes.style.outlineStyle = 'solid';
} else {
checkboxes.style.outlineColor = 'none';
checkboxes.style.outlineStyle = 'none';
}
};
}
</script>");
return $deletebox;
}


and this is my messageview.php (I'm using 1.3.5)
if($mysidia->input->post("checkdelete")){

$mysidia->db->delete("messages");

}

and it functions and all, but it deletes all the private messages in database instead of ones selected. I'm not a PHP/Java coder, I literally research and piece together and this is as far as I can get... I got it functioning, but can't get the messages to recognize checked pms and delete appropriately.
 

HIddenPanda

Premium Member
Premium Member
Joined
Jul 15, 2010
Messages
60
Points
8
Mysidian Dollar
3,648
So first, $mysidia-db->delete() deletes whole tables, not rows in a table. Second, where in messageview.php did you put those lines? It doesn't look like any logic is/should be being done in that file. The logic you're looking for appears to be the delete() function in messages.php in the root directory. That's where you'd want to sanitize your inputs and delete the messages.
1673896265910.png
 

Kesstryl

Member
Member
Joined
Feb 22, 2012
Messages
142
Points
18
Mysidian Dollar
11,053
So first, $mysidia-db->delete() deletes whole tables, not rows in a table. Second, where in messageview.php did you put those lines? It doesn't look like any logic is/should be being done in that file. The logic you're looking for appears to be the delete() function in messages.php in the root directory. That's where you'd want to sanitize your inputs and delete the messages.
View attachment 502
Without documentation about which classes and functions do what, people who are not expert programmers are going to be so lost trying to customize Mysidia
 

HIddenPanda

Premium Member
Premium Member
Joined
Jul 15, 2010
Messages
60
Points
8
Mysidian Dollar
3,648
Without documentation about which classes and functions do what, people who are not expert programmers are going to be so lost trying to customize Mysidia
Totally correct. I'm no expert, but I would also say it doesn't help that the templating engine seems needlessly convoluted and page components seem to get added to pages in various different files/stages of the request.
 

HIddenPanda

Premium Member
Premium Member
Joined
Jul 15, 2010
Messages
60
Points
8
Mysidian Dollar
3,648
1. Change the line:
PHP:
<input type='checkbox' class='checkbox' name='checkdelete' value='Delete'>
to
PHP:
<input type='checkbox' class='checkbox' name='checkdelete[]' value='$param'>

2. Change the following in messages.php:
PHP:
public function delete(){
        $mysidia = Registry::get("mysidia");
        try{
            $this->message = new PrivateMessage($mysidia->input->get("id"));
            if($this->message->touser != $mysidia->user->username) {
                $this->setFlags("nopermission_title", "nopermission");
                return;
            }
            $this->message->remove();
        }
        catch(MessageNotfoundException $pne){
            $this->setFlags("nonexist_title", "nonexist");
        }   
    }

to
PHP:
public function delete(){
        $mysidia = Registry::get("mysidia");
        try{
            $msgs = $mysidia->input->get("checkdelete")
            foreach($msgs as $msg)
            {
                $this->message = new PrivateMessage($msg);
                if($this->message->touser != $mysidia->user->username) {
                    $this->setFlags("nopermission_title", "nopermission");
                    return;
                }
                $this->message->remove();
            }
        }
        catch(MessageNotfoundException $pne){
            $this->setFlags("nonexist_title", "nonexist");
        }   
    }

I haven't tested this, but it should work. Let me know how it goes
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,214
Messages
32,630
Members
1,577
Latest member
pudgiehedgie
BETA

Latest Threads

Latest Posts

Top