I am using "After table initialized" instead of creating tons of separate views for multiple reasons including maintainability, logic stays relatively constant and relationships. However, when I use something like(and it is a tad more complicated the way I wrote the logic but this is the gist of it):
//if user in client role
if($_SESSION["roleprefix"]=='01')
{
$query->replaceWhere("id=".$_SESSION["client_id"]);
}
// if user is in service-client role
if($_SESSION["roleprefix"]=='02')
{
$query->addWhere("service_client_id=".$_SESSION["service_client_id"]);
}
// if user is admin
if($_SESSION["roleprefix"]=='00')
{
$query->replaceWhere("");
}
The logic works great until I pull up a table that uses this table as a drop-down as an add/edit as relationship. Here is the error:
Error type 256
Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) and (id = 1)' at line 3
URL localhost/client_branch_list.php?
Error file \output\connections\MySQLiConnection.php
Error line 142
SQL query SELECT [removed for verbosity] FROM client
WHERE ((id= )) and (id = 1)
So just to give it short: AfterTableInit() logic works fine on all 'client' table functions, however when I go to the client_branch_list page - it errors out every time because the dropdown for client under client_branch is relating back to the client table obviously and appears to be adding an extra (id=) and (id=1)[this is from the session variables I store at successful login]. When I code from scratch I usually can fix things like this in 15-30 minutes because I know where all the query data is at, however I am not sure what is causing this conflict and if I can figure it out, I can finish up this application view logic and have a pretty snappy application with over 7 types of roles all login and getting the view permissions of exactly what I need them to see and edit and nothing more.