Back in 2008 (ancient history...) Dave Edis announced that as of version 1.13 (more ancient history...) a multi search function had been added to CMSB and he offered some example implementation.
I thought that it would be great if I could including upload info fields in the multisearch results.
With a lot of help from Daniel Loewe, a senior programmer at Interactive Tools, I was able to reach my goal.
Here's the code for both the MultiSearch page (called multisearch.php) and the Image Viewer page (called test.php) (no styling):
<?php $libraryPath = 'cmsAdmin/lib/viewer_functions.php'; $dirsToCheck = array('/your_server_path/','','../','../../','../../../'); foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }} if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
$searchOptions = array(); $searchOptions['keywords'] = @$FORM['q']; $searchOptions['perPage'] = "100"; $searchOptions['debugSql'] = "0";
$searchTables = array(); $searchTables['family_stories'] = array( 'viewerUrl' => 'story_detail.php', 'titleField' => 'title', 'summaryField' => 'sub_title', 'searchFields' => array('title','sub_title','story'), );
$searchTables['faq'] = array( 'viewerUrl' => 'faqdetail.php', 'titleField' => 'question', 'summaryField' => 'category', 'searchFields' => array('category','question','answer'), );
$searchTables['uploads'] = array( 'viewerUrl' => 'test.php', 'titleField' => 'filePath', 'summaryField' => 'thumbFilePath', 'searchFields' => array('filePath', 'info1','info2', 'info3', 'info4', 'info5'), );
list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions); ?> <!-- /STEP1: Load Record List --> <?php echo "<?xml version='1.0'?>\n"; ?> <!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; font-size: 12px; } </style> </head> <body> <h1>Search Viewer</h1> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>" > <input type="text" name="q" value="<?php echo htmlspecialchars(@$FORM['q']); ?>" size="50"> <input type="submit" name="" value="Search">
<table border=0 cellpadding=2 cellspacing=0 width=100%> <tr> <td bgcolor="#EEEEEE"><font size=2 class="maintext">Search results for <b><?php echo htmlspecialchars(@$FORM['q']); ?></b></font> - <font size=2 class="maintext">This page shows results <b><?php echo htmlspecialchars(@$searchDetails['pageResultsStart']); ?></b> to <b><?php echo htmlspecialchars(@$searchDetails['pageResultsEnd']); ?></b> out of <b><?php echo htmlspecialchars(@$searchDetails['totalRecords']); ?></b> found.</font></td> </tr> </table>
<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") --> <?php if ($searchDetails['prevPage']): ?> <a href="<?php echo $searchDetails['prevPageLink'] ?>"><< previous page</a> <?php else: ?> << prev <?php endif ?> - page <?php echo $searchDetails['page'] ?> of <?php echo $searchDetails['totalPages'] ?> - <?php if ($searchDetails['nextPage']): ?> <a href="<?php echo $searchDetails['nextPageLink'] ?>">next page >></a> <?php else: ?> next >> <?php endif ?> <!-- /STEP3: Display Page Links -->
<!-- show errors --> <?php if ($searchDetails['invalidPageNum']): ?> Results page '<?php echo $searchDetails['page']?>' not found, <a href="<?php echo $searchDetails['firstPageLink'] ?>">start over >></a>. <?php elseif ($searchOptions['keywords'] && $searchDetails['noRecordsFound']): ?> No records matched search query!
<?php elseif ($searchOptions['keywords'] == ""): ?> Enter a keyword to search.
<?php endif ?>
<!-- STEP2: Display Record List --> <hr /> <?php foreach ($searchRows as $record): ?> <a href="<?php echo $record['_link'] ?>"><?php echo $record['_title'] ?></a> <?php if ($record['_summary']): ?> <?php echo $record['_summary'] ?> <?php else: ?> No description is available for this page. <?php endif ?> <a href="<?php echo $record['_link'] ?>" style="color: #008000"><?php echo $record['_link'] ?></a> <hr/> <?php endforeach ?> <!-- /STEP2: Display Record List -->
</form> </body> </html>
And for the Image Viewer called test.php (no styling)
<?php $libraryPath = 'cmsAdmin/lib/viewer_functions.php'; $dirsToCheck = array('/your_server_path/','','../','../../','../../../'); foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }} if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
list($uploadsRecords, $uploadsMetaData) = getRecords(array( 'tableName' => 'uploads', 'where' => whereRecordNumberInUrl(0), 'loadUploads' => true, 'allowSearch' => false, 'limit' => '1', )); $uploadsRecord = @$uploadsRecords[0]; // get first record
?>
<a href='/multisearch.php'><span class=" navigation_font" style="font-size:24px;">< < BACK TO SEARCH PAGE</span></a>
<div > <img src="http://your_site.com/cmsAdmin/uploads/<?php echo $uploadsRecord['filePath'] ?>"/> <?PHP $uploadsRecord['info1'] = preg_replace("/[\"]/", "''", $uploadsRecord['info1'] ); ?> <?PHP $uploadsRecord['info2'] = preg_replace("/[\"]/", "''", $uploadsRecord['info2'] ); ?> <?PHP $uploadsRecord['info3'] = preg_replace("/[\"]/", "''", $uploadsRecord['info3'] ); ?> <?PHP $uploadsRecord['info4'] = preg_replace("/[\"]/", "''", $uploadsRecord['info4'] ); ?> <?PHP $uploadsRecord['info5'] = preg_replace("/[\"]/", "''", $uploadsRecord['info5'] ); ?> <div align='center' style='font-size:1.4em; vertical-align:top; text-align:left;' class='text_font' ><?php echo($uploadsRecord['info1']) ?> <?php echo($uploadsRecord['info2']) ?> <?php echo($uploadsRecord['info3']) ?> <?php echo($uploadsRecord['info4']) ?> <?php echo($uploadsRecord['info4']) ?></div> The first CMS Builder reference book is now available on-line!
|