This topic is locked
[SOLVED]

 delete button on view page and security things

4/8/2015 8:10:43 AM
PHPRunner General questions
Hackepeter author

Hi Folks,
there are 3 tasks to complete and I´m stuck in scripting it.

  1. I want to have a button on the view page for deleting the current record. --> I managed this - is working so far
  2. after the record was deleted the same page should show the next record. --> how to code this?
  3. The button should only work if the usergroup (dynamic permissions) is allowed to delete records --> no idea how to solve this
    Is anyone out there who can help me?
    Thanks Peter

Sergey Kornilov admin 4/10/2015

This is possible and some coding will be required.
2. After you delete the record you need to execute a SQL query that will get an ID of the next record. For instance if id of deleted record is $id your SQL query will be

select id from mytable where id>$id order by id


If you need to take into account sort order on the list page or advanced security settings like 'Users can see and edit their own records only' - that will be much more complicated.
You also need to handle a case when last record was deleted and there is no next record.
3. In regards to hiding the button if no delete permissions exist.
You need to wrap this button in your template code i.e.

{BEGIN mybutton} ... {END mybutton}
Now in BeforeDisplay event of the page in question you need to retrieve current user permissions and show/hide button based on that.

$perm = GetUserPermissions("mytable");

if(strpos($perm, "D")) {

$xt->assign("mybutton", true);

} else {

$xt->assign("mybutton", true);

}