Hiding some fields from groups in view.php

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
4thstar
Posts: 16
Joined: 2014-06-26 15:39

Hiding some fields from groups in view.php

Post by 4thstar » 2014-07-12 12:56

Hello.
I found several entries in the forum, but thought i would post this as it helps me remember what i did, so far it looks to work for me just fine.

I wanted to hide some fields from groups, for example i had a text area that states if a listing has been activated by admin, i also wanted to add notes and not have these visible to the client when they viewed the ??????_view.php page..

i am new with php but after trying many ways, this looks to be the best for me :) and my limited understanding lol

The idea is this...
My table is called "listings"
I wanted to use the default template generated by AppGini for Admin users.
I then wanted to create an alternative view for other groups that had hidden fields in their view.
My groups are as follows:

1 = anonymous
2 = Admins
3 = Members

Step 1:
copy /templates/listings_templateDV.html 3 times and rename to create.....

/templates/1listings_templateDV.html
/templates/2listings_templateDV.html
/templates/3listings_templateDV.html

Step 2:
add this to the bootstrap.css file

Code: Select all

.hideb {
  display: none !important;
  margin-bottom: 15px;
}
Step 3
Open listings_dml.php
Find

Code: Select all

// open the detail view template
Under this find ..

Code: Select all

	if($dvprint){
		$templateCode = @file_get_contents('./templates/listings_templateDVP.html');
	}else{
		$templateCode = @file_get_contents('./templates/listings_templateDV.html');
	}
and Replace with ...

Code: Select all

	// open the detail view template
$memberInfo = getMemberInfo();
$template = $memberInfo['groupID'];
if ($template == 2){

//So If the user is admin, then continue as normal and display original template
	if($dvprint){
		$templateCode = @file_get_contents('./templates/listings_templateDVP.html');
	}else{
		$templateCode = @file_get_contents('./templates/listings_templateDV.html');
}
}
else {
// If the user is not admin then get the group number and prepend the template name with the group number
//If the group id = 3 then the below will load the template called 	./templates/3listings_templateDV.html
	if($dvprint){
		$templateCode = @file_get_contents('./templates/'.$template.'listings_templateDVP.html');
	}else{
		$templateCode = @file_get_contents('./templates/'.$template.'listings_templateDV.html');
}	
}
	
Step 4:
then open up the members template ( /templates/3listings_templateDV.html )

find the field you want to hide

Code: Select all

<div class="form-group">
and change to

Code: Select all

<div class="hideb">
I hope this helps :)
it seems to work :)
Cheers
Carl

4thstar
Posts: 16
Joined: 2014-06-26 15:39

Re: Hiding some fields from groups in view.php

Post by 4thstar » 2014-07-12 14:08

An alternative way i am looking at is to use the Hooks file ( hooks/listings.php ) << where "listings" is my table...

I will need to keep an eye on the templates if i change a style/type of field as the details in the html change, however this also seems to be a better way as there are far less file edits...

Code: Select all

	function listings_dv($selectedID, $memberInfo, &$html, &$args){

$groupID = $memberInfo['groupID'];
if ($groupID != 2)
{
$dofind = '<div class="form-group">
					<label for="listing_approved"'; //Heres the html that we need to find before the standard template is shown
$doreplacewith = '<div class="hideb">
					<label for="listing_approved"'; //Here is what we need to change the above code to....
$html = str_replace($dofind, $doreplacewith, $html)	;
}

	}
Cheers
Carl

JEngels
Posts: 17
Joined: 2014-03-10 14:16
Location: Germany

Re: Hiding some fields from groups in view.php

Post by JEngels » 2014-09-30 08:26

Hi Carl,

having nearly the same subject I tried the solution by Alan
http://forums.appgini.com/phpbb/viewtop ... ields#p126

In his version no need to modify the css.
Meanwhile coding even is a little bit less than in 2013.
Here's what to do:

1. Copy yourtable_templateDV.html and rename it (maybe yourtable_templateDV_grp1.html)

2. In that new file yourtable_templateDV_grp1.html delete all fields you won't be seen by members of that special group.

3. Change some code in yourtable_dml.php to split view-processing depending on logged in membergroup.


// code for template based detail view forms
// open the detail view template

if($dvprint){
$templateCode = @file_get_contents('./templates/yourtable_templateDVP.html');
}elseif(getLoggedGroupID() == 4){ // 4 = replace with your desired group
$templateCode = @file_get_contents('./templates/yourtable_templateDV_grp1.html');
}else{
$templateCode = @file_get_contents('./templates/yourtable_templateDV.html');
}

The only disadvantage of that method is not to forget to uncheck and prevent yourtable_dml.php from upload when recompiling the project.

And that are important questions:
Is there a solution of that topic only touching hook-file(s)?
Or even better: does Achmad plan to implement functionality in coming updates?

Have success!
Koepi

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Hiding some fields from groups in view.php

Post by AhmedBR » 2022-07-26 23:47

This method still works. 22.14

I just keep a copy of the dml file in hooks folder, in case I need to regenerate the app.
Since the fields I want for the second view will never change.
In case you will not change this particular table, just set the file READ ONLY in windows, this way even if you forget to skip it during regeneration, it will not be overwritten.

for the elseif I use getLoggedMemeberID instead of group, as the restriction is for specific users.

Happy coding :D
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Hiding some fields from groups in view.php

Post by AhmedBR » 2022-07-26 23:58

By the way I do not hide the field, I delete its reference and make sure it is not visible from table view (you can do this from Appgini itself).

Happy coding.
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Hiding some fields from groups in view.php

Post by AhmedBR » 2022-07-27 10:46

You can also use this article to hide columns in table view:
https://bigprof.com/blog/appgini/how-to ... ser-group/
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

Post Reply