Download Mail - convert _incoming_mailRecords fields within php header

5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: July 12, 2011   (RSS)

By Zicky - July 9, 2011

I'd like to figure out a way to convert the fields of the _incoming_mailRecords in load records to sync up with some other records I'm using a page that I'm pulling multiple records into with an array. Is it possible to achieve the following and does any one have any suggestions how to do this?



<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'abc/abc/viewer_functions.php';
$dirsToCheck = array('/var/www/vhosts/abc.com/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 records
list($_incoming_mailRecords, $_incoming_mailMetaData) = getRecords(array(
'tableName' => '_incoming_mail',
));
Is it possible to
convert subject to title
convert text and html to summary
convert attachments to media
?>
<!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>Incoming Mail - List Page Viewer</h1>
<?php foreach ($_incoming_mailRecords as $record): ?> so _incoming_mailRecords look like this in red?
Subject: <?php echo $record['subject'] ?><br/> becomes <?php echo $record['title'] ?>
Message Text: <?php echo $record['text'] ?><br/> becomes <?php echo $record['summary'] ?>
Message HTML: <?php echo $record['html'] ?><br/> becomes <?php echo $record['summary'] ?>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>


<!-- STEP 2a: Display Uploads for field 'attachments' (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['attachments'] as $upload): ?> becomes <?php foreach ($record['media'] 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 (!$_incoming_mailRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->

</body>
</html>

Re: [zick] Download Mail - convert _incoming_mailRecords fields within php header

By robin - July 11, 2011

Hey zick,

So you just need the variable names changed? Something like this might be helpful:

// load records
list($_incoming_mailRecords, $_incoming_mailMetaData) = getRecords(array(
'tableName' => '_incoming_mail',
));

foreach($_incoming_mailRecords as &$record) {
$record['title'] = $record['subject'];
$record['summary'] = $record['text'];
$record['media'] = $record['attachments'];
}
unset($record);


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [zick] Download Mail - convert _incoming_mailRecords fields within php header

By robin - July 12, 2011

Hey Zick,

To do a straight combine this will work:
$record['summary'] = $record['text'] . $record['html'];

If you just want one or the other depending on which one is filled, this will help out:
$record['summary'] = coalesce($record['text'], $record['html']);
That is giving text the priority if they are both filled, swap the variables if you want html to have priority.


Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Download Mail - convert _incoming_mailRecords fields within php header

By Zicky - July 12, 2011

Thanks for the two solutions Robin!!!!
I've got them plugged into my site.
I really appreciate the help.
Zick