Page 1 of 1

hide the ADD button after one record

Posted: 2018-09-13 10:21
by pasbonte
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

Re: hide the ADD button after one record

Posted: 2018-09-13 11:10
by pbottcher
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();

Re: hide the ADD button after one record

Posted: 2018-09-13 12:12
by pasbonte
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.

Re: hide the ADD button after one record

Posted: 2018-09-14 06:30
by pasbonte
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

Re: hide the ADD button after one record

Posted: 2018-09-14 07:02
by jsetzer
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

Re: hide the ADD button after one record

Posted: 2018-09-14 07:32
by jsetzer
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 5482 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 5482 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 5482 times

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

Regards,
Jan

Re: hide the ADD button after one record

Posted: 2018-09-14 09:18
by pasbonte
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

Re: hide the ADD button after one record

Posted: 2018-09-14 11:26
by jsetzer
  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;
}