Code Generator > List Page: see only the records created by the user

14 posts by 3 authors in: Forums > CMS Builder
Last Post: June 24, 2023   (RSS)

By andreasml - June 11, 2023

Hi

I have created the List page of a section with the code generator tool and made all the additions described in the Website Membership plugin so that each user should log in to have access to this page. And this works fine. So when a user logs in with his username/password he/she has access to this specific section list page. However, he/she has access to the full set of records and not only to those records he/she has created. This is something I want to avoid as each user should have access only to his/her records. 

Can you give me some hints on how to carry on? (Just to remind that each user can have one of three different distinct types of access to records - own, hospital, all-). 

And an extra question. As this List page will contain a very large number of records, how could I add a search tool (either at the beginning of the page or on a different page) to filter the retrieved records according to some criteria?

Kind regards, 

Andreas Lazaris

By Deborah - June 12, 2023

Hi, Andreas.

I've not tried this myself, but the last post on the following forum thread might help.
https://www.interactivetools.com/forum/forum-posts.php?postNum=2245779#post2245779

Looks like basically this might do it:

'where' => mysql_escapef('createdByUserNum = ?', $CURRENT_USER['num']),

~ Deborah

By andreasml - June 12, 2023

Hi Deborah 

Thank you for your reply. 

It seems it works. 

  // load records from 'aortic_aneurysm_disease'
  list($aortic_aneurysm_diseaseRecords, $aortic_aneurysm_diseaseMetaData) = getRecords(array(
    'tableName'   => 'aortic_aneurysm_disease',
    'perPage'     => '10',
    'loadUploads' => false,
    'allowSearch' => true,
    'where' => mysql_escapef('createdByUserNum = ?', $CURRENT_USER['num']),
  ));

What about a search query to search within the file?

Kind regards, 

Andreas

By Deborah - June 13, 2023

Glad that worked for you, Andreas.

Depending on what you have in mind for search, one of these methods might work.

1) There's a variety of search methods in the CMS Builder documentation here:
https://www.interactivetools.com/docs/cmsbuilder/viewer_search.php

2) To search multiple tables on one page, you can try MultiSearch.php referred to in this forum post:
https://www.interactivetools.com/forum/forum-posts.php?postNum=2246137#post2246137
There's a download link to MultiSearch.php at the bottom of the second post.

Hope that helps!
~ Deborah

By andreasml - June 14, 2023

Thanks, Deborah

Unfortunately, I have not been able to manage it as I expected. I am thinking of adding some PHP code inside this list-page (already filtered to contain only records created by the logged in user) that will allow users to search within it using various criteria. Is there some code available?

Regards, 

Andreas

By Deborah - June 14, 2023

Andreas, I'm sorry to say I don't know of any pre-existing code.

Perhaps someone else reading this might have ideas or you could contact Interactive Tools consulting.

~ Deborah

By Dave - June 19, 2023

Andreas, 

There's some examples here for creating search fields: https://www.interactivetools.com/docs/cmsbuilder/viewer_search.php

What fields do you want to search on and what do you want it to look like? 

Dave Edis - Senior Developer
interactivetools.com

By andreasml - June 20, 2023

Hi Dave

Is there any available PHP code to make a simple search within my section list-page?

Regards, 

Andreas

By andreasml - June 20, 2023

Hi Dave

Is there any available PHP code to make a simple search within my section list-page?

Regards, 

Andreas