Create list from uploads field in combo viewer

9 posts by 2 authors in: Forums > CMS Builder
Last Post: March 24, 2016   (RSS)

By mattbcd - March 7, 2016

Hi

In a combo list viewer I'm trying to create a list which links directly to the upload for each record rather than to the detail page for each. See http://bathresidents.org.uk/minutesTest.php

Each upload is a pdf, so I just need the user to be able to click one of the archived links at the bottom and load that pdf rather than have to click through to another page in order to download it. 

Is this possible?  The only field I could specify for the list in the code generator was 'title', so ideally I'd like to be able to specify 'upload' instead.

Thanks

Matt Harpham

By Damon - March 7, 2016

Hi Matt,

Yes, linking to the PDFs directly can work.

Could you reply with the minutesTest.php template attached so I can look at the code and make suggestions?

Cheers,
Damon Edis - interactivetools.com

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

By mattbcd - March 7, 2016

Sure.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cms/lib/viewer_functions.php';
  $dirsToCheck = array('/content/sites2/b/a/bathresidents.org.uk/web/','','../','../../','../../../');
  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 detail record from 'priorities'
  list($prioritiesRecords, $prioritiesMetaData) = getRecords(array(
    'tableName'   => 'priorities',
    'where'       => whereRecordNumberInUrl(1), // If no record # is specified then latest record is shown
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $detailRecord = @$prioritiesRecords[0]; // get first record
  if (!$detailRecord) { dieWith404("Record not found!"); } // show error message if no record found

  // load list records from 'priorities'
  list($prioritiesRecords, $prioritiesMetaData) = getRecords(array(
    'tableName'   => 'priorities',
    'loadUploads' => false,
    'allowSearch' => false,
  ));

  // load detail record from 'minutes'
  list($minutesRecords, $minutesMetaData) = getRecords(array(
    'tableName'   => 'minutes',
    'where'       => whereRecordNumberInUrl(1), // If no record # is specified then latest record is shown
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $detailRecord = @$minutesRecords[0]; // get first record
  if (!$detailRecord) { dieWith404("Record not found!"); } // show error message if no record found

  // load list records from 'minutes'
  list($minutesRecords, $minutesMetaData) = getRecords(array(
    'tableName'   => 'minutes',
    'limit'       => '10',
    'loadUploads' => false,
    'allowSearch' => false,
  ));

?>
<!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"><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Federation of Bath Residents' Associations - <?php echo htmlencode($detailRecord['title']) ?></title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="meta" -->
<meta http-equiv="description" name="description" content="<?php echo htmlencode($detailRecord['title']) ?>" />
<!-- InstanceEndEditable -->
<link href="styles_scr.css" media="screen" rel="stylesheet" type="text/css" />
<link href="styles/styles_pr.css" media="print" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="images/icon.ico" type="image/vnd.microsoft.icon">
<link rel="icon" href="images/icon.ico" type="image/vnd.microsoft.icon">

<script language="JavaScript" type="text/JavaScript" src="scripts.js"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>
<div id="wrapper">
<div id="maintop">
<div id="maintopnav">
<div id="maintopnavrow">
<div id="navitem"><a href="minutes.php">Meeting Minutes</a></div>
<div id="navitem"><a href="members.php">Members</a></div>
<div id="navitem"><a href="index.php">Home</a></div>
</div><br />
<div id="maintopnavrow">
<div id="navitem"><a href="papers.php">FoBRA papers</a></div>
<div id="navitem"><a href="chairmansReport.php">Chairman's Report</a></div>
</div><br />
<div id="maintopnavrow">
<div id="navitem"><a href="contact.php">Contact Us</a></div>
<div id="navitem"><a href="links.php">Links</a></div>
<div id="navitem"><a href="joining.php">Joining FoBRA</a></div>

</div>
</div>
</div>
<div id="printheader"><img src="images/print_header.gif" /></div>
<div id="structure">
<div id="priorities">
<div id="priHead"><img src="images/sidenavHeader.png" width="135" height="45" alt="FoBRA Priorities"/></div>
<div id="priContent">
<?php foreach ($prioritiesRecords as $listRecord): ?>
    <?php $isSelected = ($listRecord['num'] == $detailRecord['num']); ?>
    <?php if ($isSelected) { print "<b>"; } ?>
    <a href="<?php echo htmlencode($listRecord['_link']) ?>"><?php echo htmlencode($listRecord['title']) ?></a><br/>
    <?php if ($isSelected) { print "</b>"; } ?>
    <?php endforeach ?></div>
</div>

<!-- InstanceBeginEditable name="main" -->
<div id="maincontent" style="background-image: url(/images/bgs/<?php echo htmlencode($detailRecord['bgimage']) ?>); margin-right: 0px; z-index: 10;">
<h1>Meeting Minutes</h1>
<p>All meeting minutes are in PDF format. Click the links to view.</p>
    <div id="archive">Latest Meeting</div>
<h2>
    <?php foreach ($detailRecord['pdf'] as $index => $upload): ?>
    <a href="<?php echo $upload['urlPath'] ?>"><?php echo htmlencode($detailRecord['title']) ?></a>
    <?php endforeach ?><br />
<?php if ($detailRecord['pdf2']): ?>
<?php foreach ($detailRecord['pdf2'] as $index => $upload): ?>
    <a href="<?php echo $upload['urlPath'] ?>"><?php echo htmlencode($detailRecord['title']) ?></a>
    <?php endforeach ?>
    <?php endif ?>
    </h2>    
    
<div id="archive">More Meeting Minutes</div>
<p class="smallbold">
    <?php foreach ($minutesRecords as $listRecord): ?>
      <a href="<?php echo htmlencode($listRecord['_link']) ?>"><?php echo htmlencode($listRecord['title']) ?></a><br/>
    <?php endforeach ?>
      </p>      
    <?php if (!$minutesRecords): ?>
      No records were found!<br/><br/>
    <?php endif ?>

      <br style="clear:both;">
  </div>  
  <!-- InstanceEndEditable -->

</div>
</div>
<div id="footer"><img src="images/footer.png" alt="Promoting residents' interests in bath" width="850" height="80" border="0" /></div>
</body>
<!-- InstanceEnd --></html>

Then, just to show what the uploads look like in a detail viewer:

        <!-- Upload Fields: extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
        PDF:
        <blockquote>
        <?php foreach ($record['pdf'] as $index => $upload): ?>
          Upload Url: <?php echo $upload['urlPath'] ?><br/>
<br/>
          Download Link: <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/><br/>

          Image Tags:<br/>
          <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
          info1 (Title) : <?php echo htmlencode($upload['info1']) ?><br/><br/>
          Extension: <?php echo $upload['extension'] ?><br/>
          isImage: <?php if ($upload['isImage']): ?>Yes<?php else: ?>No<?php endif ?><br/>
          hasThumbnail: <?php if ($upload['hasThumbnail']): ?>Yes<?php else: ?>No<?php endif ?><br/>
          <hr/>
        <?php endforeach ?>
        </blockquote>

        <!-- Upload Fields: extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
        PDF2:
        <blockquote>
        <?php foreach ($record['pdf2'] as $index => $upload): ?>
          Upload Url: <?php echo $upload['urlPath'] ?><br/>
<br/>
          Download Link: <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/><br/>
          Image Tags:<br/>
          <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<br/>
          Extension: <?php echo $upload['extension'] ?><br/>
          isImage: <?php if ($upload['isImage']): ?>Yes<?php else: ?>No<?php endif ?><br/>
          hasThumbnail: <?php if ($upload['hasThumbnail']): ?>Yes<?php else: ?>No<?php endif ?><br/>
          <hr/>

        <?php endforeach ?>
        </blockquote>


Thanks Damon!

By Damon - March 8, 2016

Hi Matt,

Just reviewing your code. For the PDF links you want in the More Meeting Minutes part of the page, which upload field is it? pdf or pdf2?

I see that in the Latest Meeting part of the page you have both pdf and pdf2 upload fields so you could have both linked to one after another?

Let me know.

Cheers,
Damon Edis - interactivetools.com

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

By mattbcd - March 8, 2016

Hi Damon

Ideally it's both, but only if the 2nd pdf exists. 

Matt

By Damon - March 8, 2016

OK, that makes sense but what does that look like?

Does the title display twice if there is a upload for pdf and an upload for pdf2?

Cheers,
Damon Edis - interactivetools.com

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

By mattbcd - March 8, 2016 - edited: March 8, 2016

Ah, good question. Maybe append (2) to the title name of the 2nd pdf.

Matt

By Damon - March 9, 2016

Hi Matt,

Here are some code updates for the More Meeting Minutes part of the page:

<div id="archive">More Meeting Minutes</div>
<p class="smallbold">
    <?php foreach ($minutesRecords as $listRecord): ?>

       <?php foreach ($listRecord['pdf'] as $index => $upload): ?>
         <a href="<?php echo $upload['urlPath'] ?>"><?php echo htmlencode($listRecord['title']) ?></a><br/>
       <?php endforeach; ?>

       <?php foreach ($listRecord['pdf2'] as $index => $upload): ?>
         <a href="<?php echo $upload['urlPath'] ?>"><?php echo htmlencode($listRecord['title']) ?> (2)</a><br/>
        <?php endforeach; ?>

    <?php endforeach ?>
</p>     

Also, at the top of the page code around line 40, make sure that you have uploads set to load and display:

// load list records from 'minutes'

  list($minutesRecords, $minutesMetaData) = getRecords(array(
    'tableName'   => 'minutes',
    'limit'       => '10',
    'loadUploads' => true,
    'allowSearch' => false,

  ));


Let me know if this works as expected.

Cheers,
Damon Edis - interactivetools.com

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