Display specific data using if statements on detail page viewer

3 posts by 3 authors in: Forums > CMS Builder
Last Post: April 29, 2013   (RSS)

Hi Zick

I don't know if this will help, but for a site that had multiple levels of access, I set up a multi-value check box list field in user accounts which listed the available access levels, and checked the box(es) corresponding to the user's level(s) of access. (you could pull these values from another table to make it more dynamic)

Then in the viewer, to restrict access to only the checked levels, I used.

<?php if (strpos($CURRENT_USER['allowedFolders'], 'your_check_box_value')): ?>

Here's another version of the same approach that I used to restrict access...

 <?php if (@$CURRENT_USER): ?><p align="center" class="heading-text-bold-pal">Here's a list of all the Records you've created.</p>
       
        <p align="center" class="heading-text"> Welcome <?php echo mysql_escape($CURRENT_USER['first_name']); ?> <?php echo
mysql_escape($CURRENT_USER['last_name']); ?>, <?php if (@$CURRENT_USER): ?>
  <?php if (@$CURRENT_USER && @$CURRENT_USER['allowedFolders'] == "entry_level" ): ?>
        Entry Level subscriber.
        <?php elseif (@$CURRENT_USER && @$CURRENT_USER['allowedFolders'] == "silver" ): ?>
        Silver Level subscriber.
        <?php elseif (@$CURRENT_USER && @$CURRENT_USER['allowedFolders'] == "gold" ): ?>
       Gold Level subscriber.
        <?php else : ?>
        Platinum Level subscriber.
        <?php endif ?>

And I restricted access to only those records authored by the current user with:

 <?php if ($record['createdByUserNum']== @$CURRENT_USER['num']): ?>

Hope that gives you some ideas.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Zick, 

Here is an example of how I would create this system using my blog section. My category drop down list field contains the following options:

News
Features
Updates

I've attached a screen shot so you can see how it's set up. 

Then if I wanted to display certain data based on the value that had been selected from the category field I would use something like this:

  // load record from 'blog'
  list($blogRecords, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'where'       => "`num` = '23'",
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $blogRecord = @$blogRecords[0]; // get first record
  if (!$blogRecord) { dieWith404("Record not found!"); } // show error message if no record found
?>

  <?php if($blogRecord['category'] == 'News'): ?>
    <p><?php echo 'This is the news category'; ?></p>
  <?php elseif($blogRecord['category'] == 'Features'): ?>
    <p><?php echo 'This is the Features category'; ?></p>
  <?php elseif($blogRecord['category'] == 'Updates'): ?>
    <p><?php echo 'This is the Updates Category'; ?></p>
  <?php else: ?>
    <p>No Category selected!</p>
  <?php endif; ?>

This is example code, so you'll have to make a few changes to get it working with your site.

So the list field is called category, and it stores the name of the value that was selected from the drop down. Then I used an if statement to loop through each possible category type and display custom data based on if that category has been selected. 

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

example_005.png 21K