New Profiles
4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 18, 2009 (RSS)
By KCMedia - August 17, 2009 - edited: August 17, 2009
I have a website that shows up a list of 30 staff members that are sorted in alphabetic order, now the client wants to be able to mark new staff members with a some kind of NEW flashing image to let people know that they are new and after 1 month it will go away.
How can i go about this there is a code view from CMS below.
What would i need to do in CMS Builder to get this to work.
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
require_once "cmsAdmin/lib/viewer_functions.php";
list($ladiesRecords, $ladiesMetaData) = getRecords(array(
'tableName' => 'ladies',
'perPage' => '10',
));
?>
<!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>
<!-- INSTRUCTIONS -->
<div class="instructions">
<b>Sample List Viewer - Instructions:</b>
<ol>
<?php ?>
<li><b>Remove any fields you don't want displayed.</b> (Most list pages only have title and link fields.)</li>
<li>Rearrange remaining fields to suit your needs.</li>
<li>Copy and paste code into previously designed page (or add design to this page).</li>
</ol>
</div>
<!-- /INSTRUCTIONS -->
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Ladies - List Page Viewer</h1>
<?php foreach ($ladiesRecords as $record): ?>
Record Number: <?php echo $record['num'] ?><br/>
Name: <?php echo $record['name'] ?><br/>
Age: <?php echo $record['age'] ?><br/>
Description: <?php echo $record['description'] ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>
<!-- STEP 2a: Display Uploads for field 'photo' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
<?php foreach ($record['photo'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>
<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->
<hr/>
<?php endforeach; ?>
<?php if ($ladiesMetaData['invalidPageNum']): ?>
Results page '<?php echo $ladiesMetaData['page']?>' not found, <a href="<?php echo $ladiesMetaData['firstPageLink'] ?>">start over >></a>.<br/><br/>
<?php elseif (!$ladiesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->
<?php if ($ladiesMetaData['prevPage']): ?>
<a href="<?php echo $ladiesMetaData['prevPageLink'] ?>"><< prev</a>
<?php else: ?>
<< prev
<?php endif ?>
- page <?php echo $ladiesMetaData['page'] ?> of <?php echo $ladiesMetaData['totalPages'] ?> -
<?php if ($ladiesMetaData['nextPage']): ?>
<a href="<?php echo $ladiesMetaData['nextPageLink'] ?>">next >></a>
<?php else: ?>
next >>
<?php endif ?>
<!-- /STEP3: Display Page Links -->
</body>
</html>
Craig
KC Media Solutions
www.kcmedia.biz
Re: [kcmedia] New Profiles
By Chris - August 18, 2009
If your records are created at the same time as staff members are hired, there's a really easy solution: you can have PHP check the "createdDate" of the record and display some HTML if the record was created in the past 30 days:
<?php if (strtotime(date('Y-m-d'))-strtotime($record['createdDate']) < 60*60*24*30): ?>
<span style="color:red;font-weight:bold;text-decoration:blink;">NEW</span>
<?php endif; ?>
If you can't rely on the createdDate, a simple alternative would involve adding a new date field "hiredDate". You could use a checkbox field, but you'd need to manually update it. Or you could combine the two: a checkbox which decides which date should be used to determine how new the staff member is.
I hope this helps you! Please let us know if you have any more questions or comments.
Chris
Re: [chris] New Profiles
By KCMedia - August 18, 2009
Thanks for that.
it worked great but the problem is how can i sort the listings at the moment they are sorted by alpha but i want it so that new ones go to the top above the alpha and then the not new ones below it.
Craig
KC Media Solutions
www.kcmedia.biz
Re: [kcmedia] New Profiles
By Chris - August 18, 2009 - edited: August 18, 2009
No problem. :)
For the next issue, add this code to the top of the page in STEP 1 (after the getRecord(...); call, but before ?>)
foreach ( array_keys( $ladiesRecords ) as $key ) {
$record =& $ladiesRecords[$key];
$record['recordIsNew'] = (strtotime(date('Y-m-d'))-strtotime($record['createdDate']) < 60*60*24*30);
}
function customSort($a, $b) {
// if both records are new or not new, sort alphabetically by name
if ( $a['recordIsNew'] == $b['recordIsNew'] ) { return strcmp($a['name'], $b['name']); }
// otherwise, sort new records to the top
if ( $a['recordIsNew'] ) { return -1; }
if ( $b['recordIsNew'] ) { return 1; }
}
usort($ladiesRecords, 'customSort');
Please let us know how it goes.
Chris