hide the ADD button after one record

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

hide the ADD button after one record

Post by pasbonte » 2018-09-13 10:21

Hello
I want to allow a user to subscribe to become a member (with or without approval) and then add a record in a table BUT only one.
He creates his register name, first name ... and then we fill the other fields throughout the year (so we have to hide the ADD button)
Is it possible ?
thank you

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: hide the ADD button after one record

Post by pbottcher » 2018-09-13 11:10

Hi,

yes it is possible, you can use the hook to check if you have already one entry in your table (if the user can only view his records), or query the db to see if a record exists, and if it the case, hide the "add" button.

To hide the add button (in the table view) you can use

Code: Select all

$j('#addNew').hide();
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: hide the ADD button after one record

Post by pasbonte » 2018-09-13 12:12

Thank you for the idea,
I have this code to see if the member has filed a registration:

Code: Select all

// We count in the membership_userrecords table the row (s) where the memberID field is equal to 1.
$ sql = mysql_query ('SELECT COUNT (*) AS memberID FROM membership_userrecords WHERE memberID =? SelectedID = # ID #);
$ data = mysql_fetch_array ($ sql);
 
// If there is a line
if (($ data ['memberID'] == '1'))
{
// remove the ADD button
J $ ( '# addNew') hide ().
}
The SELECT COUNT (*) AS memberID FROM membership_userrecords WHERE memberID =? SelectedID = # ID # works in SQL, but where exactly?

In the HOOK of my table but I do not see too much.

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: hide the ADD button after one record

Post by pasbonte » 2018-09-14 06:30

pasbonte wrote:
2018-09-13 12:12
Thank you for the idea,
I have this code to see if the member has filed a registration:

Code: Select all

// We count in the membership_userrecords table the row (s) where the memberID field is equal to 1.
$ sql = mysql_query ('SELECT COUNT (*) AS memberID FROM membership_userrecords WHERE memberID =? SelectedID = # ID #);
$ data = mysql_fetch_array ($ sql);
 
// If there is a line
if (($ data ['memberID'] == '1'))
{
// remove the ADD button
J $ ( '# addNew') hide ().
}
The SELECT COUNT (*) AS memberID FROM membership_userrecords WHERE memberID =? SelectedID = # ID # works in SQL, but where exactly?

In the HOOK of my table but I do not see too much.
Hello
I really block, I searched and tried but I do not see.
thanks for the help

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: hide the ADD button after one record

Post by jsetzer » 2018-09-14 07:02

Hiding the add button on client side only can be hacked in almost any modern browser.

Just in case you need a safer method, you should check if you can solve it using AppGini's "special permissions for user" feature - not from within the admin-area, but by code:

As far as I can see in incCommon.php, AppGini reads the group-permissions first and overwrites them by user-permissions if available. So my idea is the following:

On after insert in TABLENAME create a record in membership_userpermissions-table with...
  • memberID = '<MEMBERNAME>'
  • tableName = '<TABLENAME>'
  • allowInsert = 0 // insert disabled
  • allowView = 1 // view own records only
  • allowEdit = 1 // edit own records only
  • allowDelete = 1 // delete own records only

Code: Select all

INSERT INTO `membership_userpermissions` (`memberID`, `tableName`, `allowInsert`, `allowView`, `allowEdit`, `allowDelete`)
VALUES ('MEMBERNAME', 'TABLENAME', '0', '1', '1', '1');
The existance of this record should disallow another insert in this table by this user.

On after delete remove that record by code. The group-permissions will be used and insert will be possible again.

Hope this helps!

Kind Regards,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: hide the ADD button after one record

Post by jsetzer » 2018-09-14 07:32

I have just tested this and it should work:

I have inserted a record in membership_userpermissions-table with allowInsert = 0:

chrome_2018-09-14_09-17-42.png
chrome_2018-09-14_09-17-42.png (59.44 KiB) Viewed 4158 times

Afterwards the Add-Button is gone:

chrome_2018-09-14_09-21-03.png
chrome_2018-09-14_09-21-03.png (11.02 KiB) Viewed 4158 times


After removing the record from membership_userpermissions-table the Add-button is back again:

2018-09-14_09-22-00.png
2018-09-14_09-22-00.png (6.23 KiB) Viewed 4158 times

It also works on homepage (if you allow adding records from homepage).

Regards,
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Re: hide the ADD button after one record

Post by pasbonte » 2018-09-14 09:18

Bonjour Jan
Merci !

Your idea is original and I think it is good!

I insert this code into the file matable.php in the HOOK folder.

Code: Select all

function ORIENTATION_3_after_insert ($ data, $ memberInfo, & $ args) {
INSERT INTO `membership_userpermissions` (` memberID`, `tableName`,` allowInsert`, `allowView`,` allowEdit`, `allowDelete`);
VALUES ('MEMBERNAME', 'TABLENAME', '0', '1', '1', '1');
return TRUE;
}
but that does not work ...
the page displays an error

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: hide the ADD button after one record

Post by jsetzer » 2018-09-14 11:26

  1. Don't mix up SQL code and PHP code.
  2. If your table name is "ORIENTATION_3" (without the quotes) you'll have to edit the file ./hooks/ORIENTATION_3.php
  3. You'll have to replace MEMBERNAME and TABLENAME by current values
  4. When copying and pasting code, please make sure blanks (space-characters) are in the right place
Try this in ./hooks/ORIENTATION_3.php:

Code: Select all

function ORIENTATION_3_after_insert($data, $memberInfo, &$args){
    $table = "ORIENTATION_3";
    $sql = "INSERT INTO `membership_userpermissions`(`memberID`, `tableName`, `allowInsert`, `allowView`, `allowEdit`, `allowDelete`) VALUES ('" . $memberInfo['username'] . "', '" . $table . "', '0', '1', '1', '1')";
    sql($sql, $eo);
    return $eo == null;
}
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply