How to hide records by Group or user?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
mgoetze
Posts: 23
Joined: 2014-12-02 06:59

How to hide records by Group or user?

Post by mgoetze » 2020-01-30 00:56

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?

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-01-30 01:12

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;


mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-01-30 01:31

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?

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-01-30 06:17

mgoetze wrote:
2020-01-30 01:31
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?
look at this post:

viewtopic.php?f=4&t=3308

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 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.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-01-30 18:55

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.
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:

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);

}

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-01-30 19:54

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

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-01-30 20:46

mgoetze wrote:
2020-01-30 19:54
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
replace code in after insert and after update to this:

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{


}

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-01-31 06:16

D Oliveira wrote:
2020-01-30 20:46
mgoetze wrote:
2020-01-30 19:54
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
replace code in after insert and after update to this:

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{


}
correcting myself... small mistake

Code: Select all

sql("UPDATE `membership_userrecords` SET `groupID` = '1', `tableName` = 'warranty'  WHERE `pkValue` = '{$data['primary_key_warranty']}'", $eo);

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-01-31 22:44

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);	
		}
	}

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-02-01 02:13

mgoetze wrote:
2020-01-31 22:44
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);	
		}
	}
try this:

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;
	}

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-02-01 03:44

Same results. Group 21 cannot view any records and the Group ID does not change when posting.

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-02-01 17:41

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.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-02-01 21:29

mgoetze wrote:
2020-02-01 17:41
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.
it is case sensitive, can you try changing 'id' to 'ID' ?

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-02-02 21:13

"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.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-02-03 17:33

mgoetze wrote:
2020-02-02 21:13
"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.
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

mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-02-03 17:40

ok, thank you for your help.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to hide records by Group or user?

Post by D Oliveira » 2020-02-03 19:52

mgoetze wrote:
2020-02-03 17:40
ok, thank you for your help.

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;
	}


mgoetze
Posts: 23
Joined: 2014-12-02 06:59

Re: How to hide records by Group or user?

Post by mgoetze » 2020-02-04 16:58

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

Post Reply