This topic is locked
[SOLVED]

 Hiding tabs revisited

8/28/2015 7:35:33 PM
PHPRunner General questions
greggk author

Hello,

I have a project where the edit page has 3 tabs. I want to display only 1 tab based on the user groupID, ie purchasing,warehouse,accounting

From reading on the forums I found a lot of help on hiding the tabs.



var tab = "Purchasing1",

myTabs = pageObj.tabs['tabGroup_'+tab],

tabIndex = 1, // 0 means first tab, 1 means second tab etc

tabToHide = myTabs.item( tabIndex ),

siblingTab;

tabToHide.get("boundingBox").hide();
tabToHide.hide();
if ( tabToHide.get('selection') ) {

siblingTab = tabToHide.next() || tabToHide.previous()



if ( siblingTab && siblingTab.get('visible') ) {

myTabs.selectChild( siblingTab.get("index") );

} else {

tabToHide.set('selection', 0);

}

}



Since it consists of 3 tabs, I did this 3 times, and indeed I hid the tabs.

Now, when it comes to display a tab on condition, that's where I'm stuck

I found this little code on the forums that is supposed to show my customtab.



// before display event

if( $_SESSION["UserName"] == accounting){

echo "<script language=\"Javascript\"> var DisplayCustomTab = 1; </script>";

} else {

echo "<script language=\"Javascript\"> var DisplayCustomTab = 0; </script>";

}



I have tried it a few different ways, hiding two tabs, displaying 1, The displaycustomtab doesn't seem to work.

In my mind it was easier to hide all the tabs, and unhide the tab based on the condition.

Maybe I'm over thinking stuff.

Any thoughts is appreciated.

greggk author 9/2/2015

Ok, so I got a little bit further on this.

I was able to hide, unhide and highlight tabs based on the UserName. Which is great, but some how I need to be able to pull the GroupID from the ugmembers table. I think that's been my problem, it's trying to pull the GroupID from the users table, but since I'm using the Dynamic permission, the GroupID on the user table is empty, and the GroupID on the ugmembers has the correct GroupID I need.

Could someone point me into the right direction as to how I can pull that information to this edit page?

Thanks.

C
chuckbower 9/3/2015



Ok, so I got a little bit further on this.

I was able to hide, unhide and highlight tabs based on the UserName. Which is great, but some how I need to be able to pull the GroupID from the ugmembers table. I think that's been my problem, it's trying to pull the GroupID from the users table, but since I'm using the Dynamic permission, the GroupID on the user table is empty, and the GroupID on the ugmembers has the correct GroupID I need.

Could someone point me into the right direction as to how I can pull that information to this edit page?

Thanks.


Gregg, if I understand your question correctly, I think you need to use CustomQuery to go to table ugsmembers searching by user id and pull the associated group id. However, I think the new dynamic permissions allow you to code a user into multiple groups, right? So if you search by user id, you may return more than 1 row, hence, more than 1 group.
Now with dynamic permissions, some of our early assumptions where we coded some of our own permissions or other app logic based upon the group id in the user table is no longer valid and has to be rewritten if you choose to go the dynamic permissions route.

greggk author 9/4/2015

I was able to finally do this.

What I did is, I had to retain the GroupID value from login.



$_SESSION["GroupID"] = $data["GroupID"];



Then I had to use that GroupID. I added a snippet in the edit page



echo "<script>

window.group = '" . $_SESSION["GroupID"]. "';

</script>";



Then I was finally able to use that in a javascript onload event.

so, in my case:



if (group=='1')

{

//---- begin show tab purchasing ----

var tab = "Purchasing1",

myTabs = pageObj.tabs['tabGroup_'+tab];

myTabs.selectChild(0);

//---- end show tab ----

}


It took a lot of reading, trial and errors, but that part is complete.

Thanks for the response, I decided to post my findings just in case someone has similar issues in the future.

Sergey Kornilov admin 9/4/2015

If you use Dynamic Permissions $_SESSION["GroupID"] gives you current user group name.
As a general rule of thumb you can use print_r($_SESSION); added somewhere to event like AfterAppInit to investigate session variables.
Here is the sample output below.

Array

(

[myqsladdress] => 127.0.0.1

[fromFacebook] =>

[UserRights] => Array

(

[Guest] => Array

(

[.Groups] => Array

(

[0] => -3

)
)
[ttt] => Array

(

[carsadmin_cars] => ADESPIM

[carsbcolor] => ADESPIM

[carscar] => ADESPIM

[carscars] => ADESPIM

[carsform] => ADESPIM

[carslogotypes] => ADESPIM

[carsmake] => ADESPIM

[carsmodels] => ADESPIM

[carsmore_photo] => ADESPIM

[carspictures] => ADESPIM

[carsusers] => ADESPIM

[.IsAdmin] => 1

[.Groups] => Array

(

[0] => -1

[1] => 1

)
)
)
[LastReadRights] => 1441404613

[login_count_captcha] => 1

[UserID] => ttt

[UserName] => ttt

[GroupID] => ttt

[AccessLevel] => User

[MyURL] => /menu.php

)