2021-03-31 20:02:45 +02:00
< ? php
ini_set ( 'display_errors' , 1 );
ini_set ( 'display_startup_errors' , 1 );
error_reporting ( E_ALL );
$root = realpath ( $_SERVER [ 'DOCUMENT_ROOT' ]);
require ( $root . " /database/credentials.php " );
// Connect the database
try {
$db = new PDO ( " mysql:host= $host ;dbname= $database ;charset=utf8 " ,
$user ,
$password ,
array ( PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION
));
} catch ( Exception $e ){
die ( " Error : " . $e -> getMessage ());
}
if ( isset ( $_POST [ 'search' ]))
{
if ( isset ( $_POST [ 'query' ]))
{
$q = $_POST [ 'query' ];
// Search in `authors` table
$req = $db -> prepare ( 'SELECT id FROM `authors` WHERE firstname=:q OR lastname=:q OR username=:q OR website=:q' );
$req -> execute ( array (
" q " => $q
));
$result_author = $req -> fetchAll ();
if ( empty ( $result_author ))
{
$req = $db -> prepare ( 'SELECT * FROM `records` WHERE (recordist_name LIKE "%:q%" OR file_name LIKE "%:q%" OR species LIKE "%:q%" OR subspecies LIKE "%:q%" OR sound_type LIKE "%:q%" OR date=:q OR remarks LIKE "%:q%")' );
$req -> execute ( array (
" q " => $q
));
$result = $req -> fetchAll ();
// print_r($result);
} else
{
foreach ( $result_author as $row ) {
$author_id = $row [ 'id' ];
$req = $db -> prepare ( 'SELECT * FROM `records` WHERE author_id=:author_id' );
$req -> execute ( array (
" author_id " => $author_id
));
$result = $req -> fetchAll ();
}
}
// print_r($result);
}
} else
{
// header('Location: /');
}
if ( empty ( $result ))
{
// header('Location: /');
} else
{
?>
<! DOCTYPE html >
< html lang = " en " >
< head >
< meta charset = " UTF-8 " >
< meta http - equiv = " X-UA-Compatible " content = " IE=edge " >
< meta name = " viewport " content = " width=device-width, initial-scale=1.0 " >
< title > Explore | Chiro - Canto </ title >
< link rel = " stylesheet " type = " text/css " href = " /styles/style.css " >
</ head >
2021-04-01 08:57:34 +02:00
< ? php
2021-04-16 19:14:52 +02:00
include ( " $root /analytics/owa.php " );
2021-04-01 08:57:34 +02:00
include ( " $root /analytics/matomo.php " );
?>
2021-03-31 20:02:45 +02:00
< body >
< ? php include ( " $root /menu.php " ); ?>
< ? php include ( " $root /header.php " ); ?>
< section >
< h3 > Explore </ h3 >
< h4 > Search Results </ h4 >
< ? php
if ( empty ( $result )) {
echo " No result for this query, please try again. \n " ;
} else {
?>
< table >
< thead >
< tr >
< th > File name </ th >
< th > Author </ th >
< th > License </ th >
< th > Date </ th >
</ tr >
</ thead >
< tbody >
< ? php
foreach ( $result as $row ) {
?>
< tr >
< td >< a href = " /explore/spectrograms?record=<?= $row['id'] ?> " >< ? = $row [ 'file_name' ] ?> </a></td>
< td >< ? = $row [ 'recordist_name' ] ?> </td>
< td >< ? = $row [ 'license' ] ?> </td>
< td >< ? = $row [ 'date' ] ?> <?=$row['time']?></td>
</ tr >
< ? php
}
?>
</ tbody >
</ table >
< ? php
}
?>
</ section >
< ? php include ( " $root /footer.php " ); ?>
</ body >
< script src = " /scripts/script.js " ></ script >
</ html >
< ? php
}