summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpfspot.class.php118
-rw-r--r--phpfspot.js43
-rw-r--r--rpc.php12
-rw-r--r--stylesheet.css2
-rw-r--r--templates/photo_index.tpl23
-rw-r--r--templates/search.tpl9
-rw-r--r--templates/single_photo.tpl2
7 files changed, 111 insertions, 98 deletions
diff --git a/phpfspot.class.php b/phpfspot.class.php
index 0113fe6..f71a0db 100644
--- a/phpfspot.class.php
+++ b/phpfspot.class.php
@@ -457,9 +457,6 @@ class PHPFSPOT {
*/
public function addTag($tag)
{
- // if the result of a date search are displayed, reset them
- $this->resetDateSearch();
-
if(!isset($_SESSION['selected_tags']))
$_SESSION['selected_tags'] = Array();
@@ -550,18 +547,33 @@ class PHPFSPOT {
{
$matched_photos = Array();
+ if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
+ $from_date = strtotime($_SESSION['from_date']);
+ $to_date = strtotime($_SESSION['to_date']);
+ $additional_where_cond = "
+ p.time>='". $from_date ."'
+ AND
+ p.time<='". $to_date ."'
+ ";
+ }
+
/* return a search result */
if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') {
- $result = $this->db->db_query("
+ $query_str = "
SELECT DISTINCT photo_id
FROM photo_tags pt
INNER JOIN photos p
ON p.id=pt.photo_id
INNER JOIN tags t
ON pt.tag_id=t.id
- WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'
- ORDER BY p.time ASC
- ");
+ WHERE t.name LIKE '%". $_SESSION['searchfor'] ."%'";
+
+ if(isset($additional_where_cond))
+ $query_str.= "AND ". $additional_where_cond ." ";
+ $query_str.= "
+ ORDER BY p.time ASC
+ ";
+ $result = $this->db->db_query($query_str);
while($row = $this->db->db_fetch_object($result)) {
array_push($matched_photos, $row['photo_id']);
}
@@ -576,14 +588,19 @@ class PHPFSPOT {
$selected = substr($selected, 0, strlen($selected)-1);
if($_SESSION['tag_condition'] == 'or') {
- $result = $this->db->db_query("
+ $query_str = "
SELECT DISTINCT photo_id
FROM photo_tags pt
INNER JOIN photos p
ON p.id=pt.photo_id
WHERE pt.tag_id IN (". $selected .")
+ ";
+ if(isset($additional_where_cond))
+ $query_str.= "AND ". $additional_where_cond ." ";
+
+ $query_str.= "
ORDER BY p.time ASC
- ");
+ ";
}
elseif($_SESSION['tag_condition'] == 'and') {
@@ -619,43 +636,30 @@ class PHPFSPOT {
AND pt". ($i+1) .".tag_id=". $_SESSION['selected_tags'][$i] ."
";
}
- $result = $this->db->db_query($query_str);
+ if(isset($additional_where_cond))
+ $query_str.= "AND ". $additional_where_cond;
}
+ $result = $this->db->db_query($query_str);
while($row = $this->db->db_fetch_object($result)) {
array_push($matched_photos, $row['photo_id']);
}
return $matched_photos;
}
- if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
- $from_date = strtotime($_SESSION['from_date']);
- $to_date = strtotime($_SESSION['to_date']);
- $result = $this->db->db_query("
- SELECT DISTINCT photo_id
- FROM photo_tags pt
- INNER JOIN photos p
- ON p.id=pt.photo_id
- WHERE
- time>='". $from_date ."'
- AND
- time<='". $to_date ."'
- ORDER BY p.time ASC
- ");
- while($row = $this->db->db_fetch_object($result)) {
- array_push($matched_photos, $row['photo_id']);
- }
- return $matched_photos;
- }
-
/* return all available photos */
- $result = $this->db->db_query("
+ $query_str = "
SELECT DISTINCT photo_id
FROM photo_tags pt
INNER JOIN photos p
ON p.id=pt.photo_id
+ ";
+ if(isset($additional_where_cond))
+ $query_str.= "WHERE ". $additional_where_cond ." ";
+ $query_str.= "
ORDER BY p.time ASC
- ");
+ ";
+ $result = $this->db->db_query($query_str);
while($row = $this->db->db_fetch_object($result)) {
array_push($matched_photos, $row['photo_id']);
}
@@ -1172,39 +1176,29 @@ class PHPFSPOT {
} // setTagCondition()
/**
- * invoke tag search
+ * invoke tag & date search
*
* this function will return all matching tags and store
- * them in the session variable selected_tags.
+ * them in the session variable selected_tags. furthermore
+ * it also handles the date search.
* getPhotoSelection() will then only return the matching
* photos.
*/
- public function startTagSearch($searchfor)
+ public function startSearch($searchfor, $from, $to)
{
$_SESSION['searchfor'] = $searchfor;
- $_SESSION['selected_tags'] = Array();
-
- foreach($this->avail_tags as $tag) {
- if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
- array_push($_SESSION['selected_tags'], $tag);
- }
-
- $this->resetDateSearch();
-
- } // startTagSearch()
-
- /**
- * invoke date search
- *
- * this function in fact does nothing then only setting
- * the from- and to-date in the users session variables.
- * the result is generated by getPhotoSelection().
- */
- public function startDateSearch($from, $to)
- {
$_SESSION['from_date'] = $from;
$_SESSION['to_date'] = $to;
- }
+
+ if($searchfor != "") {
+ /* new search, reset the current selected tags */
+ $_SESSION['selected_tags'] = Array();
+ foreach($this->avail_tags as $tag) {
+ if(preg_match('/'. $searchfor .'/i', $this->tags[$tag]))
+ array_push($_SESSION['selected_tags'], $tag);
+ }
+ }
+ } // startSearch()
/**
* rotate image
@@ -1406,9 +1400,15 @@ class PHPFSPOT {
$month = $_SESSION[$mode .'_date'] ? date("m", strtotime($_SESSION[$mode .'_date'])) : date("m");
$day = $_SESSION[$mode .'_date'] ? date("d", strtotime($_SESSION[$mode .'_date'])) : date("d");
- $output = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\" />\n";
- $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". $month ."\" />\n";
- $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". $day ."\" />\n";
+ $output = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". $year ."\"";
+ if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
+ $output.= " />\n";
+ $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". $month ."\"";
+ if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
+ $output.= " />\n";
+ $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". $day ."\"";
+ if(!isset($_SESSION[$mode .'_date'])) $output.= " disabled=\"disabled\"";
+ $output.= " />\n";
return $output;
} // get_calendar()
diff --git a/phpfspot.js b/phpfspot.js
index 58e48de..5aac788 100644
--- a/phpfspot.js
+++ b/phpfspot.js
@@ -90,16 +90,10 @@ function setCheckedValue(condition, value) {
}
}
-function startTagSearch(searchfor)
+function startSearch()
{
- HTML_AJAX.grab(encodeURI('rpc.php?action=tag_search&for=' + searchfor));
- refreshAvailableTags();
- refreshSelectedTags();
- showPhotoIndex();
-}
+ var searchfor = document.getElementsByName('searchfor')[0].value
-function startDateSearch()
-{
from_year = document.getElementById('fromyear').value;
from_month = document.getElementById('frommonth').value;
from_day = document.getElementById('fromday').value;
@@ -109,10 +103,39 @@ function startDateSearch()
to_day = document.getElementById('today').value;
to = to_year +"-"+ to_month +"-"+ to_day;
- HTML_AJAX.grab(encodeURI('rpc.php?action=date_search&from='+ from +'&to='+ to));
+ var request = 'rpc.php?action=search';
- refreshPhotoIndex();
+ if(searchfor != "") {
+ request = request + '&for=' + searchfor;
+ }
+ if(document.getElementsByName('consider_date')[0].checked == true) {
+ request = request + '&from='+ from +'&to='+ to;
+ }
+
+ HTML_AJAX.grab(encodeURI(request));
+
+ refreshAvailableTags();
+ refreshSelectedTags();
+ showPhotoIndex();
+
+}
+
+function datesearch()
+{
+ var mode = true;
+
+ if(document.getElementsByName('consider_date')[0].checked == true) {
+ mode = false;
+ }
+
+ document.getElementById('fromyear').disabled = mode;
+ document.getElementById('frommonth').disabled = mode;
+ document.getElementById('fromday').disabled = mode;
+ document.getElementById('toyear').disabled = mode;
+ document.getElementById('tomonth').disabled = mode;
+ document.getElementById('today').disabled = mode;
+
}
function setViewMode(mode)
diff --git a/rpc.php b/rpc.php
index 2e30459..5d9bb37 100644
--- a/rpc.php
+++ b/rpc.php
@@ -90,17 +90,9 @@ class PHPFSPOT_RPC {
$fspot->showCredits();
break;
- case 'tag_search':
+ case 'search':
- $fspot->resetDateSearch();
- $fspot->startTagSearch($_GET['for']);
- break;
-
- case 'date_search':
-
- $fspot->resetTagSearch();
- $fspot->resetTags();
- $fspot->startDateSearch($_GET['from'], $_GET['to']);
+ $fspot->startSearch($_GET['for'], $_GET['from'], $_GET['to']);
break;
case 'get_export':
diff --git a/stylesheet.css b/stylesheet.css
index fe2b2ef..610e7aa 100644
--- a/stylesheet.css
+++ b/stylesheet.css
@@ -65,7 +65,7 @@ td.index_header {
white-space: nowrap;
}
-td.photo_name {
+td.content_title {
background-color: #eeeeee;
padding: 10px;
vertical-align: middle;
diff --git a/templates/photo_index.tpl b/templates/photo_index.tpl
index 2b4c827..f9c651d 100644
--- a/templates/photo_index.tpl
+++ b/templates/photo_index.tpl
@@ -4,33 +4,30 @@
<td colspan="3">
<table style="width: 100%;">
<tr>
- <td class="index_header">
+ <td class="content_title">
<b>Photo Index</b>
{if $searchfor }
{if $count == 1}
- {$count} image is the result for your search about "{$searchfor}"
+ {$count} image is the result for your search about "{$searchfor}".
{else}
- {$count} images are the result for your search about "{$searchfor}"
- {/if}
- {elseif $from_date }
- {if $count == 1}
- {$count} image is the result for your search between {$from_date} to {$to_date}
- {else}
- {$count} images are the result for your search between {$from_date} to {$to_date}
+ {$count} images are the result for your search about "{$searchfor}".
{/if}
{elseif $tag_result}
{if $count == 1}
- {$count} image has been found for the selected tags
+ {$count} image has been found for the selected tags.
{else}
- {$count} images have been found for the selected tags
+ {$count} images have been found for the selected tags.
{/if}
{else}
{if $count == 1}
- {$count} image has been found
+ {$count} image has been found.
{else}
- {$count} images have been found
+ {$count} images have been found.
{/if}
{/if}
+ {if $from_date && $to_date }
+ Results are limited to a date between {$from_date} to {$to_date}.
+ {/if}
</td>
<td class="index_header" style="text-align: right">
{if $extern_link }
diff --git a/templates/search.tpl b/templates/search.tpl
index f0f8c0d..c87d29e 100644
--- a/templates/search.tpl
+++ b/templates/search.tpl
@@ -7,7 +7,7 @@
<tr>
<td class="searchfor">
<table>
- <form action="" onsubmit="startTagSearch(document.getElementsByName('searchfor')[0].value); return false;">
+ <form action="" onsubmit="startSearch(); return false;">
<tr>
<td>Tag:</td>
<td>
@@ -17,12 +17,13 @@
<input type="image" src="resources/doit.png" alt="Tag-Search" />
</td>
</tr>
- </form>
- <form action="" onsubmit="startDateSearch(); return false;">
<tr>
<td>Date:</td>
- <td>{$from_date} <a href="javascript:showCalendar('from');"><img src="resources/date.png" id="frompic"/></a></td>
+ <td><input type="checkbox" name="consider_date" value="Y" onclick="datesearch();">consider date-search
+ </tr>
+ <tr>
<td>&nbsp;</td>
+ <td>{$from_date} <a href="javascript:showCalendar('from');"><img src="resources/date.png" id="frompic"/></a></td>
</tr>
<tr>
<td>&nbsp;</td>
diff --git a/templates/single_photo.tpl b/templates/single_photo.tpl
index 5275843..8dfd433 100644
--- a/templates/single_photo.tpl
+++ b/templates/single_photo.tpl
@@ -1,7 +1,7 @@
<!-- Single photo -->
<table>
<tr>
- <td class="photo_name" style="text-align: left;">
+ <td class="content_title" style="text-align: left;">
<b>Photo {$image_name}</b><br />
&nbsp;{$description}<br />
</td>