Skip to content

Instantly share code, notes, and snippets.

@pcdinh
Created July 30, 2009 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcdinh/158655 to your computer and use it in GitHub Desktop.
Save pcdinh/158655 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php include 'fragment/head_main.tpl.php'; ?>
<body>
<!-- Loading panel -->
<!-- End loading panel -->
<div class="wrapper">
<?php include 'fragment/header.tpl.php'; ?>
<div id="main">
<div class="body1">
<div class="breadcrumb"><span class="none">Your are here: </span><a href="index.php">Home</a><span class="sep">&#8250;</span>Search</div>
<?php include 'fragment/search_form.tpl.php'; ?>
<?php if (true === $this->_searchAction): ?>
<div class="searchResult clearfix">
<?php if (null !== $this->_error): ?>
<div><?php echo $this->_error; ?></div>
<?php endif; ?>
<?php if (0 === count($this->_rs)): ?>
<div>We did not find any results for <strong><?php echo htmlentities($_GET['q']) ?></strong></div>
<?php else: ?>
<table id="ver-zebra" summary="Matching Files">
<colgroup>
<col class="vzebra-odd" />
<col class="vzebra-even" />
<col class="vzebra-odd" />
</colgroup>
<thead>
<tr>
<th scope="col" id="vzebra-comedy">File</th>
<th scope="col" id="vzebra-adventure">Company</th>
<th scope="col" id="vzebra-action">Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->_rs['data'] as $entry): ?>
<tr>
<td><a href="download.php?id=<?php echo $entry['doc_id']; ?>"><?php echo $entry['name'] ?></a></td>
<td><?php echo $entry['company_name'].' ('.$entry['wvb_number'].')' ?></td>
<td><?php echo date('M d, Y', strtotime($entry['filedate'])) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="paginator"><?php echo paginate('search.php?q='.RequestUtils::getGet('q').'&keyword_type='.RequestUtils::getGet('keyword_type'), $this->_totalRows, $this->_currentPage, $this->_itemPerPage); ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="body2"></div>
</div>
<?php include 'fragment/footer.tpl.php'; ?>
</div>
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).bind('ready', function() {
var option = {
'anchorSelector' : '#bigSearch .tab a',
'containerSelector' : '#bigSearch .tab'
};
var searchTabs = new ifile.SearchTabs();
var keywordType = <?php echo RequestUtils::getGetForJs('keyword_type', 'wvb_number'); ?>;
searchTabs.init(keywordType, option);
searchTabs.listenOnClick(option);
});
/* ]]> */
</script>
</body>
</html>
<?php
/**
* A set of methods to manipulate files.
*
* @author pcdinh
* @since June 18, 2009
* @version $Id: SearchController.php 407 2009-07-22 04:51:07Z hanhnt83 $
*/
class SearchController
{
/**
* Indicates if user submitted a search keyword.
*
* @var bool
*/
private $_searchAction = false;
/**
* Error message generated when accessing database service.
*
* @var string
*/
private $_error;
/**
* Matching list of files.
*
* @var array
*/
private $_rs;
/**
* Number of items to be rendered per page.
*
* @var int
*/
private $_itemPerPage = 20;
/**
* Current page.
*
* @var int
*/
private $_currentPage = 1;
/**
* Total rows found.
*
* @var int
*/
private $_totalRows = 0;
/**
* Constructs an object of <code>SearchController</code>.
*/
public function __construct()
{
}
/**
* Renders search page template output.
*
* @return string
*/
public function execute()
{
if (true === $this->isSearchAction())
{
$this->_searchAction = true;
}
try
{
$keyword = urldecode(RequestUtils::getGet('q'));
$this->_doSearch($keyword);
}
catch (Exception $e)
{
$this->_error = $e->getMessage();
}
return include_once 'template/search.tpl.php';
}
/**
* Does search action and returns matches.
*
* @param string $keyword
*/
protected function _doSearch($keyword)
{
include_once 'lib/ifile/service/SearchService.php';
$searcher = new SearchService(getConfig('dbdoc'));
// Normalize the user parameter "page"
if (false === isset($_GET['page']) || false === ctype_digit($_GET['page']))
{
$_GET['page'] = '1';
}
$this->_currentPage = $_GET['page'];
switch (RequestUtils::getGet('keyword_type'))
{
case 'doc_type':
$this->_rs = $searcher->findByDocType($keyword, $_GET['page'], $this->_itemPerPage);
break;
case 'file_name':
$this->_rs = $searcher->findByFileName($keyword, $_GET['page'], $this->_itemPerPage);
break;
case 'report_period':
$this->_rs = $searcher->findByReportPeriod($keyword, $_GET['page'], $this->_itemPerPage);
break;
default: // wvb_number
$this->_rs = $searcher->findByWVBNumber($keyword, $_GET['page'], $this->_itemPerPage);
break;
}
$this->_totalRows = $this->_rs['total_rows'];
}
/**
* Checks if user submitted a search keyword.
*
* @return bool
*/
public function isSearchAction()
{
return isset($_GET['q']);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment