How to hide records by Group or user?
How to hide records by Group or user?
What would be the easiest way to hide specific records by either user or group?
For example, if a record has field1=blue I want user X to be able to view
but
if a record has field1= anything other than blue, I DO NOT want user X to be able to view.
How is this done?
For example, if a record has field1=blue I want user X to be able to view
but
if a record has field1= anything other than blue, I DO NOT want user X to be able to view.
How is this done?
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
go to your tablename.php inside hooks folder and look for the tablename_dv function, add this (change group ID to your admin group ID #) :
Code: Select all
if(isset($_REQUEST['dvprint_x'])) return;
ob_start(); ?>
<script>
<?php if ($memberInfo['group ID'] == '2' ){?>
$j(function(){
$j('#field1').parents('.form-group').show();
});
<?php }else{; ?>
$j(function(){
$j('#name').parents('.form-group').hide();
});
<?php }; ?>
</script>
<?php
$form_code = ob_get_contents();
ob_end_clean();
$html .= $form_code;
Re: How to hide records by Group or user?
Wouldn't this just show the records to the admin group and hide it for everyone else? Also, where do I put the field value that I want to trigger hide or show?
Let me be more specific as to my requirements. We have a table that tracks warranty information by vendor. The table contains records for many vendors, but we only want each vendor to see their own records. For this example, lets say the field name = vendor. And let's say we have two vendors:
Honda
Toyota
So this would be the rough table:
Table = warranty
Record ID = 123
Vendor = Toyota
Description = blah blah blah
Table = warranty
Record ID = 124
Vendor = Honda
Description = blahx blahx blahx
When someone from Honda logs in and goes to table = warranty we only want them to see records that have field Vendor = Honda. They would NOT see records with field Vendor = Toyota
Can you use those specific examples in the code above?
Let me be more specific as to my requirements. We have a table that tracks warranty information by vendor. The table contains records for many vendors, but we only want each vendor to see their own records. For this example, lets say the field name = vendor. And let's say we have two vendors:
Honda
Toyota
So this would be the rough table:
Table = warranty
Record ID = 123
Vendor = Toyota
Description = blah blah blah
Table = warranty
Record ID = 124
Vendor = Honda
Description = blahx blahx blahx
When someone from Honda logs in and goes to table = warranty we only want them to see records that have field Vendor = Honda. They would NOT see records with field Vendor = Toyota
Can you use those specific examples in the code above?
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
look at this post:mgoetze wrote: ↑2020-01-30 01:31Wouldn't this just show the records to the admin group and hide it for everyone else? Also, where do I put the field value that I want to trigger hide or show?
Let me be more specific as to my requirements. We have a table that tracks warranty information by vendor. The table contains records for many vendors, but we only want each vendor to see their own records. For this example, lets say the field name = vendor. And let's say we have two vendors:
Honda
Toyota
So this would be the rough table:
Table = warranty
Record ID = 123
Vendor = Toyota
Description = blah blah blah
Table = warranty
Record ID = 124
Vendor = Honda
Description = blahx blahx blahx
When someone from Honda logs in and goes to table = warranty we only want them to see records that have field Vendor = Honda. They would NOT see records with field Vendor = Toyota
Can you use those specific examples in the code above?
viewtopic.php?f=4&t=3308
Re: How to hide records by Group or user?
@D Oliviera,
That post is for hiding and locking fields, we need to be able to hide/show rows (records). I'm not a php/jscript coder so I would not know how to manipulate their code to make it record based instead of fields. I don't think this is overly complicated and I know it involve hooks, but I simply have no clue how or where to enter the code.
Any help would be greatly appreciated.
That post is for hiding and locking fields, we need to be able to hide/show rows (records). I'm not a php/jscript coder so I would not know how to manipulate their code to make it record based instead of fields. I don't think this is overly complicated and I know it involve hooks, but I simply have no clue how or where to enter the code.
Any help would be greatly appreciated.
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
hmm.. there are a couple ways to go about that.. create groups named honda, toyota, etc.. configure warranty table to let its users view only records by group(admin area->groups->permissions), then in the after insert and after update functions inside hooks/warranty.php add this code:mgoetze wrote: ↑2020-01-30 16:11@D Oliviera,
That post is for hiding and locking fields, we need to be able to hide/show rows (records). I'm not a php/jscript coder so I would not know how to manipulate their code to make it record based instead of fields. I don't think this is overly complicated and I know it involve hooks, but I simply have no clue how or where to enter the code.
Any help would be greatly appreciated.
Code: Select all
if( $data['vendor'] == 'HONDA'){ /* look in your phpmyadmin the id group for honda, in this case im assuming its '1' also replace 'primary_key_warranty' for your primary key field */
sql("UPDATE `membership_userrecords` SET `groupID` = '1' WHERE `pkValue` = '{$data['primary_key_warranty']}'", $eo);
}else if( $data['vendor'] == 'TOYOTA'){
sql("UPDATE `membership_userrecords` SET `groupID` = '2' WHERE `pkValue` = '{$data['primary_key_warranty']}'", $eo);
}
Re: How to hide records by Group or user?
This makes sense, but I have one question about the code. We have about 10 different groups that access the warranty table. We only want group = Honda to see records where field vendor = honda. I believe the first part of your "if statement" above will accomplish that. BUT , we want the other 9 groups to be able to view all records, so I don't think the "else if" statement above will work. Basically I dont know how to close the If statement above if there is no else if. I hope this makes sense
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
replace code in after insert and after update to this:mgoetze wrote: ↑2020-01-30 19:54This makes sense, but I have one question about the code. We have about 10 different groups that access the warranty table. We only want group = Honda to see records where field vendor = honda. I believe the first part of your "if statement" above will accomplish that. BUT , we want the other 9 groups to be able to view all records, so I don't think the "else if" statement above will work. Basically I dont know how to close the If statement above if there is no else if. I hope this makes sense
Code: Select all
if( $data['vendor'] == 'HONDA'){ /* look in your phpmyadmin the id group for honda, in this case im assuming its '1' also replace 'primary_key_warranty' for your primary key field */
sql("UPDATE `membership_userrecords` SET `groupID` = '1' WHERE `pkValue` = '{$data['primary_key_warranty']}'", $eo);
}else{
}
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
correcting myself... small mistakeD Oliveira wrote: ↑2020-01-30 20:46replace code in after insert and after update to this:mgoetze wrote: ↑2020-01-30 19:54This makes sense, but I have one question about the code. We have about 10 different groups that access the warranty table. We only want group = Honda to see records where field vendor = honda. I believe the first part of your "if statement" above will accomplish that. BUT , we want the other 9 groups to be able to view all records, so I don't think the "else if" statement above will work. Basically I dont know how to close the If statement above if there is no else if. I hope this makes sense
Code: Select all
if( $data['vendor'] == 'HONDA'){ /* look in your phpmyadmin the id group for honda, in this case im assuming its '1' also replace 'primary_key_warranty' for your primary key field */ sql("UPDATE `membership_userrecords` SET `groupID` = '1' WHERE `pkValue` = '{$data['primary_key_warranty']}'", $eo); }else{ }
Code: Select all
sql("UPDATE `membership_userrecords` SET `groupID` = '1', `tableName` = 'warranty' WHERE `pkValue` = '{$data['primary_key_warranty']}'", $eo);
Re: How to hide records by Group or user?
I used the code above as a template but when the user logs it says they do not have any permission to view any pages. I tried changing the permission of the group to All for view, edit, and delete, but that didnt help. Somehow the code below locks anyone in group ID 21 from viewing the damaged_defective_us table. Then I logged in as admin and I tried entering a record inside the damaged_defective_us table, and after I did that the database record did not change the group id to 21, so that is likely another issue. Here is my exact code.
Code: Select all
function damaged_defective_us_after_insert($data, $memberInfo, &$args) {
return TRUE;
if( $data['vendor_code'] == '1'){
sql("UPDATE `membership_userrecords` SET `groupID` = '21', `tableName` = 'damaged_defective_us' WHERE `pkValue` = '{$data['id']}'", $eo);
}
}
function damaged_defective_us_before_update(&$data, $memberInfo, &$args) {
return TRUE;
}
function damaged_defective_us_after_update($data, $memberInfo, &$args) {
return TRUE;
if( $data['vendor_code'] == '1'){
sql("UPDATE `membership_userrecords` SET `groupID` = '21', `tableName` = 'damaged_defective_us' WHERE `pkValue` = '{$data['id']}'", $eo);
}
}
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
try this:mgoetze wrote: ↑2020-01-31 22:44I used the code above as a template but when the user logs it says they do not have any permission to view any pages. I tried changing the permission of the group to All for view, edit, and delete, but that didnt help. Somehow the code below locks anyone in group ID 21 from viewing the damaged_defective_us table. Then I logged in as admin and I tried entering a record inside the damaged_defective_us table, and after I did that the database record did not change the group id to 21, so that is likely another issue. Here is my exact code.
Code: Select all
function damaged_defective_us_after_insert($data, $memberInfo, &$args) { return TRUE; if( $data['vendor_code'] == '1'){ sql("UPDATE `membership_userrecords` SET `groupID` = '21', `tableName` = 'damaged_defective_us' WHERE `pkValue` = '{$data['id']}'", $eo); } } function damaged_defective_us_before_update(&$data, $memberInfo, &$args) { return TRUE; } function damaged_defective_us_after_update($data, $memberInfo, &$args) { return TRUE; if( $data['vendor_code'] == '1'){ sql("UPDATE `membership_userrecords` SET `groupID` = '21', `tableName` = 'damaged_defective_us' WHERE `pkValue` = '{$data['id']}'", $eo); } }
Code: Select all
function damaged_defective_us_after_insert($data, $memberInfo, &$args) {
if( $data['vendor_code'] == '1'){
sql("UPDATE `membership_userrecords` SET `groupID` = '21' WHERE `pkValue` = '{$data['id']}' AND `tableName` = 'damaged_defective_us'", $eo);
}
return TRUE;
}
function damaged_defective_us_before_update(&$data, $memberInfo, &$args) {
return TRUE;
}
function damaged_defective_us_after_update($data, $memberInfo, &$args) {
if( $data['vendor_code'] == '1'){
sql("UPDATE `membership_userrecords` SET `groupID` = '21' WHERE `pkValue` = '{$data['id']}' AND `tableName` = 'damaged_defective_us'", $eo);
}
return TRUE;
}
Re: How to hide records by Group or user?
Same results. Group 21 cannot view any records and the Group ID does not change when posting.
Re: How to hide records by Group or user?
The core issue that remains is that the owner of the record is not changing to Group 21 when the record is created or updated. My guess is there is something wrong with the pkvalue code string.
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
"id" is correct. I can confirm that the code above is NOT changing the owner of the records after insert or update. Not sure why, but I can tell through Phpmyadmin that the group owner does not change.
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
the above code worked for me, you're gonna have to hire a developer and give them access to your server for a specific diagnosis
Re: How to hide records by Group or user?
ok, thank you for your help.
- D Oliveira
- AppGini Super Hero
- Posts: 347
- Joined: 2018-03-04 09:30
- Location: David
Re: How to hide records by Group or user?
last try...
Code: Select all
function damaged_defective_us_after_insert($data, $memberInfo, &$args) {
?>
<script>
if($j('#vendor_code').val() == '1'){
<?php
sql("UPDATE `membership_userrecords` SET `groupID` = '21' WHERE `pkValue` = '{$data['id']}' AND `tableName` = 'damaged_defective_us'", $eo);
?>
}
</script>
<?php
return TRUE;
}
function damaged_defective_us_before_update(&$data, $memberInfo, &$args) {
return TRUE;
}
function damaged_defective_us_after_update($data, $memberInfo, &$args) {
?>
<script>
if($j('#vendor_code').val() == '1'){
<?php
sql("UPDATE `membership_userrecords` SET `groupID` = '21' WHERE `pkValue` = '{$data['id']}' AND `tableName` = 'damaged_defective_us'", $eo);
?>
}
</script>
<?php
return TRUE;
}
Re: How to hide records by Group or user?
I appreciate you continuing to try and help me on this but the code above is still not working. It simply does not change the record owner after post or update. I don't know enough about PHP to give you further feedback. I am going to reach out to a developer and see if they can shed some light on the issue. Thank you again, I really appreciate the effort.
Mark
Mark