Help with Author settings

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 9, 2011   (RSS)

Re: [nmsinc] Help with Author settings

By Jason - November 8, 2011

Hi,

What you can do is use a custom SQL string to populate your list box.

Try this,
When creating your list, for List Options select "Get options from MySQL Query (advanced)".

Here is an example of a query that will use "num" as the option value and "title'' as the option label from a section called "news". It will restrict options to only those created by the user currently logged in:

SELECT num, title
FROM `<?php echo $TABLE_PREFIX ?>news`
WHERE createdByUserNum = '<?php echo $CURRENT_USER['num'];?>'


Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [nmsinc] Help with Author settings

By nmsinc - November 8, 2011

Thanks Jason; however, I also have users with "Author and View" and "Editor" rights, will this code set prevent them from seeing all records?
nmsinc

Re: [nmsinc] Help with Author settings

By Jason - November 9, 2011

Hi,

Yes, that would stop editors from seeing everything.

Here is another approach. You can use PHP if statements to dynamically alter your sql query

NOTE: this example assumes that you are giving the user a permission level for ALL sections, not apply permissions one section at a time.

Try this:

<?php
$accessLevel = @$CURRENT_USER['accessList']['all']['accessLevel'];

$where = "";

if ($accessLevel == 6 || $accessLevel == 7) {
$where = "WHERE createdByUserNum = '".$CURRENT_USER['num']."'";
}

?>


SELECT num, title
FROM `<?php echo $TABLE_PREFIX ?>news`
<?php echo $where; ?>


If the logged in user is set to author or author & viewer, they will only see records they created as options. Otherwise, they'll see everything.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Help with Author settings

By nmsinc - November 9, 2011

Thanks Jason,

This worked perfect!
nmsinc