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)
By Mikey - April 27, 2013 - edited: September 15, 2013
I need some help... I'm trying to display specific field data - based on a business' paid advertising level. Presently there are four levels, but more could be added in the further, or possible some could be removed or renamed. Therefore - this needs to be flexible and able to display content based on the selected field labels for "paid_ads" that belongs to the perspective business and what they have paid for.
There are three section that will be displayed based on the level of the paid_ads:
1st Levels of Paid Ads: Premium Business & Business Spot Light
2nd Levels of Paid Ads: Business & Business Basics
3rd Level no paid ads: = the <?php else: ?>
The problem I'm having is I can't figure out how to display content based on the "paid_ads" level that the business has paid for.
I have the "business_directoryRecords" set up as a multi list, with a pull down list field for "paid_ads", which I'll select the level of advertising the business has paid for and thereby display specific data on their details page - based on the level of advertising they have paid for.
Below is some raw code showing what I'm trying to achieve with if statements. Any help on getting this working would be much appreciated!!
Zick
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsBuilder/lib/viewer_functions.php';
$dirsToCheck = array('/home/www/host/00.00.000.00/httpdocs/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load record from 'business_directory'
list($business_directoryRecords, $business_directoryMetaData) = getRecords(array(
'tableName' => 'business_directory',
//'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$business_directoryRecord = @$business_directoryRecords[0]; // get first record
if (!$business_directoryRecord) { dieWith404("Record not found!"); } // show error message if no record found
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>
<h1>Business Directory - Detail Page Viewer</h1>
Record Number: <?php echo htmlencode($business_directoryRecord['num']) ?><br/>
Paid Advertising (values): <?php echo $business_directoryRecord['paid_ads'] ?><br/>
Paid Advertising (labels): <?php echo join(', ', $business_directoryRecord['paid_ads:labels']); ?><br/>
1st Levels of Paid Ads: Premium Business & Business Spot Light (note these may change, therefore - this can't be hardcoded into the if statement)
2nd Levels of Paid Ads: Business & Business Basics (note these may change, therefore - this can't be hardcoded into the if statement)
3rd Level no paid ads: = the <?php else: ?>
(1st Levels of Paid Ads: Premium Business & Business Spot Light)
<?php if ($business_directoryRecord['paid_ads:labels'] == 'paid_ads:labels' || $business_directoryRecord['paid_ads:labels'] == 'paid_ads:labels'): ?>
Business Name: <?php echo htmlencode($business_directoryRecord['title']) ?><br/>
First Name: <?php echo htmlencode($business_directoryRecord['first_name']) ?><br/>
Last Name: <?php echo htmlencode($business_directoryRecord['last_name']) ?><br/>
Business Title: <?php echo htmlencode($business_directoryRecord['business_title']) ?><br/>
Summary: <?php echo htmlencode($business_directoryRecord['summary']) ?><br/>
Content: <?php echo $business_directoryRecord['content']; ?><br/>
Testimonial: <?php echo $business_directoryRecord['testimonial']; ?><br/>
<hr/>
Phone: <?php echo htmlencode($business_directoryRecord['phone']) ?><br/>
Ext: <?php echo htmlencode($business_directoryRecord['ext']) ?><br/>
Toll Free: <?php echo htmlencode($business_directoryRecord['toll_free']) ?><br/>
Fax: <?php echo htmlencode($business_directoryRecord['fax']) ?><br/>
Mobile Phone: <?php echo htmlencode($business_directoryRecord['mobile_phone']) ?><br/>
Email: <?php echo htmlencode($business_directoryRecord['email']) ?><br/>
<hr/>
Address: <?php echo htmlencode($business_directoryRecord['address']) ?><br/>
Address 2: <?php echo htmlencode($business_directoryRecord['address_2']) ?><br/>
City: <?php echo htmlencode($business_directoryRecord['city']) ?><br/>
State: <?php echo $business_directoryRecord['state:label'] ?><br/>
Zip Code: <?php echo htmlencode($business_directoryRecord['zip']) ?><br/>
<hr/>
Google+: <?php echo htmlencode($business_directoryRecord['google_plus_web_address']) ?><br/>
Facebook: <?php echo htmlencode($business_directoryRecord['facebook_web_address']) ?><br/>
Twitter: <?php echo htmlencode($business_directoryRecord['twitter_web_address']) ?><br/>
Youtube: <?php echo htmlencode($business_directoryRecord['youtube_web_address']) ?><br/>
LinkedIn: <?php echo htmlencode($business_directoryRecord['linkedin_web_address']) ?><br/>
<hr/>
Right Content Title: <?php echo htmlencode($business_directoryRecord['right_content_title']) ?><br/>
Right Content: <?php echo $business_directoryRecord['right_content']; ?><br/>
_link : <a href="<?php echo $business_directoryRecord['_link'] ?>"><?php echo $business_directoryRecord['_link'] ?></a><br/>
<?php foreach ($business_directoryRecord['business_logo'] as $index => $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<?php endforeach ?>
<hr/>
<?php foreach ($business_directoryRecord['documents'] as $index => $upload): ?>
Documents: <a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['filename'] ?></a>
<?php endforeach ?>
<hr/>
<a href="<?php echo $business_directoryMetaData['_listPage'] ?>"><< Back to list page</a>
<a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a>
(2nd Levels of Paid Ads: Business & Business Basics)
<?php elseif ($business_directoryRecord['paid_ads:labels'] == 'paid_ads:labels' || $business_directoryRecord['paid_ads:labels'] == 'paid_ads:labels'): ?>
Business Name: <?php echo htmlencode($business_directoryRecord['title']) ?><br/>
First Name: <?php echo htmlencode($business_directoryRecord['first_name']) ?><br/>
Last Name: <?php echo htmlencode($business_directoryRecord['last_name']) ?><br/>
Business Title: <?php echo htmlencode($business_directoryRecord['business_title']) ?><br/>
Summary: <?php echo htmlencode($business_directoryRecord['summary']) ?><br/>
Testimonial: <?php echo $business_directoryRecord['testimonial']; ?><br/>
<hr/>
Phone: <?php echo htmlencode($business_directoryRecord['phone']) ?><br/>
Ext: <?php echo htmlencode($business_directoryRecord['ext']) ?><br/>
Toll Free: <?php echo htmlencode($business_directoryRecord['toll_free']) ?><br/>
Fax: <?php echo htmlencode($business_directoryRecord['fax']) ?><br/>
Mobile Phone: <?php echo htmlencode($business_directoryRecord['mobile_phone']) ?><br/>
Email: <?php echo htmlencode($business_directoryRecord['email']) ?><br/>
<hr/>
Address: <?php echo htmlencode($business_directoryRecord['address']) ?><br/>
Address 2: <?php echo htmlencode($business_directoryRecord['address_2']) ?><br/>
City: <?php echo htmlencode($business_directoryRecord['city']) ?><br/>
State: <?php echo $business_directoryRecord['state:label'] ?><br/>
Zip Code: <?php echo htmlencode($business_directoryRecord['zip']) ?><br/>
<hr/>
Right Content Title: <?php echo htmlencode($business_directoryRecord['right_content_title']) ?><br/>
Right Content: <?php echo $business_directoryRecord['right_content']; ?><br/>
_link : <a href="<?php echo $business_directoryRecord['_link'] ?>"><?php echo $business_directoryRecord['_link'] ?></a><br/>
<?php foreach ($business_directoryRecord['business_logo'] as $index => $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<?php endforeach ?>
<hr/>
<a href="<?php echo $business_directoryMetaData['_listPage'] ?>"><< Back to list page</a>
(3rd Level no paid ads)
<?php else: ?>
Business Name: <?php echo htmlencode($business_directoryRecord['title']) ?><br/>
First Name: <?php echo htmlencode($business_directoryRecord['first_name']) ?><br/>
Last Name: <?php echo htmlencode($business_directoryRecord['last_name']) ?><br/>
Business Title: <?php echo htmlencode($business_directoryRecord['business_title']) ?><br/>
Summary: <?php echo htmlencode($business_directoryRecord['summary']) ?><br/>
Testimonial: <?php echo $business_directoryRecord['testimonial']; ?><br/>
<hr/>
Phone: <?php echo htmlencode($business_directoryRecord['phone']) ?><br/>
Ext: <?php echo htmlencode($business_directoryRecord['ext']) ?><br/>
Toll Free: <?php echo htmlencode($business_directoryRecord['toll_free']) ?><br/>
Fax: <?php echo htmlencode($business_directoryRecord['fax']) ?><br/>
Mobile Phone: <?php echo htmlencode($business_directoryRecord['mobile_phone']) ?><br/>
<hr/>
Address: <?php echo htmlencode($business_directoryRecord['address']) ?><br/>
Address 2: <?php echo htmlencode($business_directoryRecord['address_2']) ?><br/>
City: <?php echo htmlencode($business_directoryRecord['city']) ?><br/>
State: <?php echo $business_directoryRecord['state:label'] ?><br/>
Zip Code: <?php echo htmlencode($business_directoryRecord['zip']) ?><br/>
<hr/>
_link : <a href="<?php echo $business_directoryRecord['_link'] ?>"><?php echo $business_directoryRecord['_link'] ?></a><br/>
<hr/>
<a href="<?php echo $business_directoryMetaData['_listPage'] ?>"><< Back to list page</a>
<?php endif; ?>
</body>
</html>
By gkornbluth - April 29, 2013
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
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By gregThomas - April 29, 2013
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
PHP Programmer - interactivetools.com