Removed:
trunk/schoorbs-misc/templates/search-results.tpl
Modified:
trunk/schoorbs-includes/database/entry.class.php
trunk/schoorbs-includes/global.functions.php
trunk/schoorbs-includes/session-plugins/session_http.php
trunk/schoorbs-misc/themes/contented6/search.tpl.php
trunk/search.php
Log:
Finished Search interface
Modified: trunk/schoorbs-includes/database/entry.class.php
==============================================================================
--- trunk/schoorbs-includes/database/entry.class.php (original)
+++ trunk/schoorbs-includes/database/entry.class.php Sun Oct 26 02:16:55
2008
@@ -31,8 +31,7 @@
* @param $nEndTime int
* @return array
*/
- public function getBetween($oRoom, $nStartTime, $nEndTime)
- {
+ public function getBetween($oRoom, $nStartTime, $nEndTime) {
$aEntries = array();
$oDB = SchoorbsDB::getInstance();
// Example query:
@@ -59,8 +58,7 @@
* @return Entry
* @author Uwe L. Korn <uw...@xhochy.org>
*/
- public static function getById($nId)
- {
+ public static function getById($nId) {
$oDB = SchoorbsDB::getInstance();
// Example Query:
// SELECT * FROM schoorbs_entry WHERE id = 5
@@ -84,8 +82,7 @@
* @return Entry
* @author Uwe L. Korn <uw...@xhochy.org>
*/
- public static function fetchEntry($oResult)
- {
+ public static function fetchEntry($oResult) {
$oEntry = new Entry();
$oEntry->nId = $oResult->getInt('id');
$oEntry->oRoom = Room::getById($oResult->getInt('room_id'));
@@ -104,6 +101,64 @@
$oEntry->nTimestamp = intval($oResult->getTimestamp('timestamp', 'U'));
return $oEntry;
+ }
+
+ /**
+ * Search in all text-based columns for an occurence of $sText
+ *
+ * @author Uwe L. Korn <uw...@xhochy.org>
+ * @param $sText string The string we are searching for
+ * @return Array
+ */
+ public static function simpleSearch($sText) {
+ $oDB = SchoorbsDB::getInstance();
+
+ // Example query:
+ // SELECT * FROM entry WHERE name LIKE '%test%' OR
+ // description LIKE '%test%' OR created_by LIKE '%test%'
+ $oStatement = $oDB->getConnection()->prepareStatement('SELECT * FROM '
+ .$oDB->getTableName('entry').' WHERE name LIKE ? OR '
+ .' description LIKE ? OR create_by LIKE ?');
+
+ // Add % for searching to things likes $sText.'sss' too
+ $oStatement->setString(1, '%'.$sText.'%');
+ $oStatement->setString(2, '%'.$sText.'%');
+ $oStatement->setString(3, '%'.$sText.'%');
+
+ $aEntries = array();
+ $oResult = $oStatement->executeQuery();
+ while ($oResult->next()) {
+ $aEntries[] = self::fetchEntry($oResult);
+ }
+ return $aEntries;
+ }
+
+ public static function advancedSearch($sText, $sCreatedBy, $oRoom,
$sType) {
+ $oDB = SchoorbsDB::getInstance();
+
+ // Example query:
+ // SELECT * FROM entry WHERE name LIKE '%test%' OR
+ // description LIKE '%test%' OR created_by LIKE '%test%'
+ $sQuery = 'SELECT * FROM '.$oDB->getTableName('entry')
+ .' WHERE (name LIKE ? OR description LIKE ?) AND '
+ .' create_by LIKE ? AND type LIKE ?';
+ if ($oRoom != null) $sQuery.= ' AND room_id = ?';
+ $oStatement = $oDB->getConnection()->prepareStatement($sQuery);
+
+ // Add % for searching to things likes $sText.'sss' too
+ $oStatement->setString(1, '%'.$sText.'%');
+ $oStatement->setString(2, '%'.$sText.'%');
+ $oStatement->setString(3, '%'.$sCreatedBy.'%');
+ $oStatement->setString(4, '%'.$sType.'%');
+ if ($oRoom != null) $oStatement->setInt(5, $oRoom->getId());
+
+
+ $aEntries = array();
+ $oResult = $oStatement->executeQuery();
+ while ($oResult->next()) {
+ $aEntries[] = self::fetchEntry($oResult);
+ }
+ return $aEntries;
}
/**
Modified: trunk/schoorbs-includes/global.functions.php
==============================================================================
--- trunk/schoorbs-includes/global.functions.php (original)
+++ trunk/schoorbs-includes/global.functions.php Sun Oct 26 02:16:55 2008
@@ -74,35 +74,6 @@
}
/**
- *
- * @param int $mod_time
- * @return array
- */
-function period_date_string($t, $mod_time=0)
-{
- global $periods;
-
- $time = getdate($t);
- $p_num = $time['minutes'] + $mod_time;
- if( $p_num < 0 ) $p_num = 0;
- if( $p_num >= count($periods) - 1 ) $p_num = count($periods ) - 1;
- // I have made the separater a ',' as a '-' leads to an ambiguious
- // display in report.php when showing end times.
- return array($p_num, $periods[$p_num] . utf8_strftime(', %A %d %B %Y',
$t));
-}
-
-function time_date_string($t)
-{
- global $twentyfourhour_format;
-
- if ($twentyfourhour_format)
- return utf8_strftime("%H:%M:%S - %A %d %B %Y",$t);
- else
- return utf8_strftime("%I:%M:%S%p - %A %d %B %Y",$t);
-}
-
-
-/**
* If crossing dst determine if you need to make a modification
* of 3600 seconds (1 hour) in either direction.
*
Modified: trunk/schoorbs-includes/session-plugins/session_http.php
==============================================================================
--- trunk/schoorbs-includes/session-plugins/session_http.php (original)
+++ trunk/schoorbs-includes/session-plugins/session_http.php Sun Oct 26
02:16:55 2008
@@ -19,10 +19,12 @@
{
global $auth;
+ // @codeCoverageIgnoreStart
if(!defined('SCHOORBS_NOGUI')) {
- header("WWW-Authenticate: Basic realm=\"$auth[realm]\"");
+ header("WWW-Authenticate: Basic realm=\"$auth[realm]\"");
header("HTTP/1.0 401 Unauthorized");
}
+ // @codeCoverageIgnoreEnd
}
function getAuthPassword()
Modified: trunk/schoorbs-misc/themes/contented6/search.tpl.php
==============================================================================
--- trunk/schoorbs-misc/themes/contented6/search.tpl.php (original)
+++ trunk/schoorbs-misc/themes/contented6/search.tpl.php Sun Oct 26
02:16:55 2008
@@ -59,3 +59,29 @@
</form>
</div>
</div>
+
+
+<?php if (count($result) > 0) { ?>
+ <h3>Search results:</h3>
+ <ul>
+ <?php foreach($result as $oEntry) { ?>
+ <li>
+ <a href="view-entry.php?id=<?php echo $oEntry->getId(); ?>">
+ <?php echo $oEntry->getName(); ?>
+ </a>
+ (<?php echo date('d', $oEntry->getStartTime()).' '
+ .Lang::_(date('F', $oEntry->getStartTime())).' '
+ .date('Y H:i', $oEntry->getStartTime()); ?>
+ -
+ <?php echo date('d', $oEntry->getEndTime()).' '
+ .Lang::_(date('F', $oEntry->getEndTime())).' '
+ .date('Y H:i', $oEntry->getEndTime()); ?>)
+ <p>
+ <?php $aOut = str_split($oEntry->getDescription(), 100); echo
ht($aOut[0]); ?>
+ <a href="view-entry.php?id=<?php echo
$oEntry->getId(); ?>">...</a>
+ <br /><em><?php echo Lang::_('Booked by'); ?> <strong><?php echo
ht($oEntry->getCreateBy()); ?></strong></em>
+ </p>
+ </li>
+ <?php } ?>
+ </ul>
+<?php } ?>
Modified: trunk/search.php
==============================================================================
--- trunk/search.php (original)
+++ trunk/search.php Sun Oct 26 02:16:55 2008
@@ -20,10 +20,6 @@
/** The template system */
require_once 'schoorbs-includes/schoorbstpl.class.php';
-
-/** The database wrapper */
-require_once "schoorbs-includes/database/$dbsys.php";
-
## Main ##
// Get all booking types
@@ -34,61 +30,25 @@
}
}
-SchoorbsTPL::populateVar('types', $aTypes);
-SchoorbsTPL::renderPage('search');
-
+$aResult = array();
if (isset($_REQUEST['searchtype'])) {
- unset($hResult);
-
+
if ($_REQUEST['searchtype'] == 'simple') {
- $sText = sql_escape_arg(unslashes($_REQUEST['search-for']));
- $hResult = sql_query(sprintf(
- 'SELECT id, start_time, end_time, name, description FROM %s WHERE '
- .'name LIKE \'%%%s%%\' OR description LIKE \'%%%s%%\' OR create_by '
- .'LIKE \'%%%s%%\'',
- $tbl_entry, $sText, $sText, $sText
- ));
+ $sText = unslashes($_REQUEST['search-for']);
+ $aResult = Entry::simpleSearch($sText);
} elseif ($_REQUEST['searchtype'] == 'advanced') {
- $sText = sql_escape_arg(unslashes($_REQUEST['description']));
- $sCreateBy = sql_escape_arg(unslashes($_REQUEST['create_by']));
- $sQuery = sprintf(
- 'SELECT id, start_time, end_time, name, description FROM %s WHERE '
- .'(name LIKE \'%%%s%%\' OR description LIKE \'%%%s%%\') AND create_by '
- .'LIKE \'%%%s%%\'',
- $tbl_entry, $sText, $sText, $sCreateBy
- );
- $sType = sql_escape_arg(unslashes($_REQUEST['type']));
- if ($sType != '-ignore-') {
- $sQuery.= ' AND type = \''.$sType.'\'';
- }
- $nRoom = intval(input_Room());
- if ($nRoom != -1) {
- $sQuery.= ' AND room_id = '.$nRoom;
+ $sText = unslashes($_REQUEST['description']);
+ $sCreateBy = unslashes($_REQUEST['create_by']);
+ $oRoom = Room::getById(input_Room());
+ $sType = unslashes($_REQUEST['type']);
+ if ($sType == '-ignore-') {
+ $sType = '';
}
- $hResult = sql_query($sQuery);
- }
-
- if (isset($hResult)) {
- $aBookings = array();
- for ($i = 0; ($row = sql_row($hResult, $i)); $i++) {
- if ($enable_periods) {
- list( , $start_date) = period_date_string($row[1]);
- list( , $end_date) = period_date_string($row[2], -1);
- } else {
- $start_date = time_date_string($row[1]);
- $end_date = time_date_string($row[2]);
- }
-
- $aBookings[] = array(
- 'id' => $row[0],
- 'start_time' => $start_date,
- 'end_time' => $end_date,
- 'name' => $row[3],
- 'description' => $row[4]
- );
- }
-
- $smarty->assign('bookings', $aBookings);
- $smarty->display('search-results.tpl');
+ $aResult = Entry::advancedSearch($sText, $sCreateBy, $oRoom,
+ $sType);
}
}
+
+SchoorbsTPL::populateVar('result', $aResult);
+SchoorbsTPL::populateVar('types', $aTypes);
+SchoorbsTPL::renderPage('search');