Forums

Restrict view to certain fields based on their data

marcinwolejko 11 Jun, 2013
Hi,
I was wondering if this is possible with Chronoconnectivity.

I have several people filling in the data through CF which is accessible later in CC. The data concerns various services for our clients.

Now, my boss asked me if I could set it up so that various clients could see the data related to services provided for them.

For instance - we've got company X that we provide service for. My people fill in the form, input the company name X and remaining data. What we are trying to achieve is to be able to somehow filter the data so that company X sees their services, and not company's Y or Z.

Is there anyway this could be done, guys? For instance, if field client=X then user (company X) can see the details in the CC table, etc.
Thanks in advance for your reply Bob or Max 🙂
GreyHead 11 Jun, 2013
Hi marcinwolejko,

Yes that's possible with a bit of coding. You have to be able to identify what company a user comes from by some method or other. You can do this with User Groups (in Joomla! 2.5+) or using some table linked to their User ID.

Then you add code to the listing WHERE box that looks up the user's company and adds a matching clause to the listing WHERE e.g. where `company_name` = '$users_company'

The difficult bit is in working out how to reliably match up the user's ids, companies and the data company.

Bob
marcinwolejko 12 Jun, 2013
Hi, Bob - thanks for that.
I did as you suggested.
I preassumed that the user name should correspond with the client name (in my case that filed/ table column is called 'zleceniodawca' in my CC/CF table jos_epiczerwiec2013)

I've added the following line:
<?PHP  $user = JFactory::getUser(); ?>
`zleceniodawca` = '$cf_user_id'

in the Where sql line of CC.

However, it does not seem to work. The listing remains empty. (I am logged in as a client of course)

Here's the snippet from the debugger:
Array
(
    [Approx_Memory_Usage] => 1094336
    [Approx_Time] => 0.027427911758423
    [check_permissions] => Array
        (
            [list] => 1
            [search] => 0
            [toolbar] => 0
        )

    [SQL] => Array
        (
            [0] => SELECT * FROM `jos_epiczerwiec2013` WHERE `zleceniodawca` = '$cf_user_id' ORDER BY `cf_id` LIMIT 0,100
        )

    [data] => Array
        (
        )

)
GreyHead 12 Jun, 2013
Hi marcinwoljeko,

A couple of problems, the id variable is wrong and it needs to be inside the <?php ?> tags. Please try:
<?php
$user = JFactory::getUser();
echo " `zleceniodawca` = '{$user->id}' ";
?>

Bob
marcinwolejko 12 Jun, 2013
Bob,
thank you. That was great and quick support !

I've altered the code you've given me and it worked.
<?php
$user = JFactory::getUser();
echo " `zleceniodawca` = '{$user->name}' ";
?>


I'm buying you a beer right now 😀 so enjoy!
Crap, it's paypal only. I need to set up an account. Will buy you a nice cold one buddy, for sure. Just will take some time a little bit :?
GreyHead 12 Jun, 2013
Hi marcinwolejko,

Sorry about mixing up the id and username :-(

And thank for the beer :-)

Bob


Bob
This topic is locked and no more replies can be posted.