2 Field authentication

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Schind
User
Posts: 7

2 Field authentication

Post by Schind »

So i can get each user to see their own fields. but what i would like to do is assign those fields to a supplier ID and when the supplier logs in they can see those fields assigned to them. the catch is the users must still see their own fields.

what i basically have set up is an application Table. these applications are assigned to users to contact clients, once the data is filled in an administrator can then assign the application to a supplier to fill the order. i have set up a field supplierID but i cant get the fields to display by userID and Supplier ID,

ie display all fields where userID is equal to current userID And supplierID is equal to current Supplier ID

Thanks in advance Ryan


kirondedshem
User
Posts: 642

Post by kirondedshem »

you should post how you are applying the filters so other can work from there.
display all fields where userID is equal to current userID And supplierID is equal to current Supplier ID
I dont know if you mean you are hiding certain columns from the list pages, so I'll give an example of hiding certain records from a list page
So i can get each user to see their own fields. but what i would like to do is assign those fields to a supplier ID and when the supplier logs in they can see those fields assigned to >them. the catch is the users must still see their own fields.
What I undertand by this is when a user logs in he should see his records and when a supplier logs in he should also see his reords. Hence "display all fields where userID is equal to current userID And supplierID is equal to current Supplier ID" becomes "display all fields where userID is equal to current userID OR supplierID is equal to current Supplier ID"
NOTE: I think the condition should have an OR instead of an AND, since every user might not neccessarily be a supplier.
IMPORTNAT:since suppliers have to log in, they should have user accounts a well, so you should write a fucntion in global code to get you the supplier_id of a currenlty logged in user, depending on how a supplier is created in relation to user accounts
BUT Ideally, you should put the code in record_selecting.

NOTE:record_Selecting applys all filters added using AND operator so you must formulate your condition all at once, eg go to all table which need filtering
-select a table-> got to Recordset_Selecting and do something like
function Recordset_Selecting(&$filter) {
//get curren tuser id(am using phpmaker fucntion)
$current_user_id = CurrentUserID();
//get current supplier id of logged in user (assuming you have this defined in global code)
$current_supplier_id = CurrentSupplierID();
//show all records where userID is equal to current userID OR supplierID is equal to current Supplier ID
ew_AddFilter($filter, " (userID = '$current_user_id' OR supplierID = '$current_supplier_id' ) "); // Add your own filter expression
}

Just change this to mactch your structure


Schind
User
Posts: 7

Post by Schind »

Thanks for the advice, i will try this and post my results.

an outline of what im trying to get the system to do:

A lead with basic details of a prospective client is loaded onto the system into its own table and the "lead" now gets a customer ID. That customer ID is assigned to a sales agent so that they can follow up and verify the details and verify if the customer is interested in the product. if the customer responds yes to the product an application form is then filled out also a new table with the customer id coming from the lead table. Once the application has been filled out the administrator of the system reviews the application and then assigns a Supplier to whom the order will be filled. the Suppliers would need to access the application form to pull details,documents uploaded etc. and this is where i start getting lost, the Supplier needs the application assigned to his User ID however the sales agent still needs it assigned to his userID so as to keep track of the Sale and the progress, (Each Application has a Status Field). i have not defined anything in the global settings as i was not sure where this code would come up. i am a bit of a Noob with the syntax of the code but i understand what i want it to say and do.

Would i be able to apply the same Principle in changing what menu ITEMS are displayed in a drop down. ie Sales agent only sees certain status update options to select where as dealers see a different set of status options?


kirondedshem
User
Posts: 642

Post by kirondedshem »

Would i be able to apply the same Principle in changing what menu ITEMS are displayed in a drop down. ie Sales agent only sees certain status update options to select where as >dealers see a different set of status options?

If you mean to hide or show some menu items depending on who is logged in, then enable dynamic user level permissions(read about it in advanced security), this can help you create specific user levels and assign then specific permissions to add,edit,list,view specific tables, hence the menu will automatically hide those they dont have permissions for.

As for what you have explained you want to achieve, as long as you stick to the good database principals and set up each entity separate but allow it to extend it can be achived.
***********NOTE: Just look at this structure and see how to adjust what you have**********************
************For example if i was to go about it**********
the Supplier needs the application assigned to his User ID however the sales agent still needs it assigned to his userID so as to keep track of the Sale and the progress, (Each >Application has a Status Field).

1.create a table for customer
2.create a table for sales agents
3.create a table for supplier

  1. NOTE: since all the above people can log into the system. each of the above tables should have alink to a specifc user account. ie
    CREATE TABLE sales_agent, cutomer, supplier(
    ------------------
    user_account_id int(11), (linking to the user_account table)
    -----------------
    );

NOTE:You can also create different userlevels for each groups such that you can limit what each of them accesses

With this you can even have the same user account being a customer, a sales agent and a supplier at the same time

  1. Create global fucntions to give you customer, sales agent and supplier ids of each logged in user. eg in global fucnitons write.
    //NOTE:these return the respective id or return null if user is not one of those people
    function GetMyCustomerID()
    {
    $current_user_id = CurrentUserID();
    return ew_ExecuteScalar("select id from customer where user_account_id = '".$current_user_id."'");
    }

function GetMySalesAgentID()
{
$current_user_id = CurrentUserID();
return ew_ExecuteScalar("select id from sales_agent where user_account_id = '".$current_user_id."'");
}

function GetMySupplierID()
{
$current_user_id = CurrentUserID();
return ew_ExecuteScalar("select id from supplier where user_account_id = '".$current_user_id."'");
}

NOTE:now you can call thses functions anywhere to use them as well as check if a logged in user is a supplier or if he is a customer etc etc.

  1. IMPORTANT:WHEN ADDING leads or applications, DO NOT ASSIGN then to a user_id directly.
    INSTEAD:ensure that the leads tabe and applications table have fields to hold specific attachements to respective customer, sales_agent, supplier, forexample the table would look something like
    CREATE TABLE leads, applications(
    -------------------------------------
    customer_id int(11) this links to your customer table to show which customer this belongs to
    sales_agent_id int(11) this links to your sales_agent table to show which sales agent this belongs to
    supplier_id int(11) this links to your supplier table to show which supplier this belongs to
    -------------------------------------

);

NOTE: just ensure to update these fileds whenever you assign something to a specific customer, sales_agent and supplier, whenever this happnes, or update them when this cahnges.

  1. We such a structure,a ll am left with is to filter out the leads or applications list to show only those belongint to a given customer, supplier or sales_Agent. which I can easily do in record_slecting depending on how many types of users can access that list.

For example assuming that customer,sales_Agent and supplier both access the ame list page to see applications I would filter it like this.

function Recordset_Selecting(&$filter) {
//get current informtion based on logged in user
$current_customer_id = GetMyCustomerID();
$current_supplier_id = GetMySupplierID();
$current_sales_agent_id = GetMySalesAgentID();

//ASSUMING THIS table has all the three fields indicated previously
//show all records for this customer, or this supplier or this sales agent
ew_AddFilter($filter, " (customer_id = '$current_customer_id' OR supplier_id = '$current_supplier_id' OR sales_agent_id = '$current_sales_agent_id' ) "); // Add your own filter expression
}

HINT: database structure is very important so whenever you are making a given tables try to think ahead into what your ultimate goal is so you can know if you need to extend it or add some sort of foreign keys and think about all the other entities that are likely to use and it will be affected etc etc


Schind
User
Posts: 7

Post by Schind »

Hi Thanks i reworked the process or structure should i say to have an Assigned to which passes the application around to who ever needs it with a field that is selected for who the sales person is.

My next hurdle is to create a button that only displays if the previous drop down menu has a certain answer "Completed". then that button needs to insert all the fields from table leads into table applications and then remove it from the leads table.

Any more pearls of wisdom as to where to start. I'm completely in the dark with how to create the button.

And once again thank you so so much for all your advice and guidance.


kirondedshem
User
Posts: 642

Post by kirondedshem »

My next hurdle is to create a button that only displays if the previous drop down menu has a certain answer "Completed". then that button needs to insert all the fields from table leads into table applications and then remove it from the leads table.

You can make use of phpmaker "custom action" (raed about it in custom menu). But basically If you are on the leads table it can help add a list option(similar to the edit/view buttons for each record), it can help you add your own button which when clicked can submit a record then you put your code in custom_action event of list page to handle what action you want to perform on that record.

HINT: it can even be used like the multi delete where you can submit multiple lead records to be processed at once.

Am Following the example in help menu

  1. go to leads table ->ListOptions_Rendered() and put
    function ListOptions_Rendered() {
    //CREATE An action named, process_lead
    //check a condition before you draw it for each record
    //use $this->field_name->CurrentValue to access the value of the field you want to check with
    //if condition is true then draw this button for this record
    $this->ListOptions->Items["new"]->Body = "<a href=\"#\" onclick=\"return ew_SubmitAction(event, {action: 'process_lead', method: 'postback', msg: 'Add star?', key: " . $this->KeyToJson() . "});\">Process Thisr</a>";

    }

  2. got leads table->Row_CustomAction, this is where you process the leads from to do whatever you want and put

function Row_CustomAction($action, $row) {
//check th action to process by
if ($action == "process_lead") { // Check action name
//access whetver value of that row by using $row["filed_name"]
$id = $row["id"];
//write sql queries to do what you want here
$this->setSuccessMessage("I have processed lead of id=$id");
return TRUE; // Success
}
}

HINT:look at the example for a more original approach


Schind
User
Posts: 7

Post by Schind »

OK if i follow the instructions nothing displays anywhere so what i have done is edit the actual page "editlead.php" which was generated by php maker.

what i have done is create a pop up php page that i want to execute the script to add the data to the applications table. i can easily make the page pop up but I'm not sure what the variables are that php mkaer is making the fields in the form. when i try calling them in my page i get blanks loading in my data base.


kirondedshem
User
Posts: 642

Post by kirondedshem »

what i have done is edit the actual page "editlead.php"
Avoid editing pages that might be automatically regenerated, if you have to then create a custom file and put your code there
HINT:The approach am giving you is a much more cleaner way of doing it, it also makes sense from the user's perspective as well, so try it again
Ive added a few lines at the top, paste this code for your list page and tell me if it does not show

function ListOptions_Rendered() {
//CREATE An action named, process_lead
//check a condition before you draw it for each record
//use $this->field_name->CurrentValue to access the value of the field you want to check with
//if condition is true then draw this button for this record
$opt = &$this->ListOptions->Add("custom_action");//create the list option first
$opt->Header = "Receipts";//add a header for this column
$this->ListOptions->Items["custom_action""]->Body = "<a href=\"#\" onclick=\"return ew_SubmitAction(event, {action: 'process_lead', method: 'postback', msg: 'Add star?', key: " . $this->KeyToJson() . "});\">Process Thisr</a>";

}

NOTE:This will work by deafult, unless you have a custom list template body, in which case you have to add an extra column and put {{{list_option custom_action}}}.
NOTE:You should see an extra button next to any of the records in that list page. After this then put your implimentation in Row_CustomAction($action, $row)


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi all,

is it possibile to do 2 field authentication (google authenticator or MFA Microsoft Azure).

Many thanks,
Andrea.


Post Reply