From 4a0b6f6114f19cebd796b3b1c6e5253edc3267c3 Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 14 Jul 2007 12:06:42 +0000 Subject: [PATCH 1/1] issue24, first trial of date search is now included git-svn-id: file:///var/lib/svn/phpfspot/trunk@198 fa6a889d-dae6-447d-9e79-4ba9a3039384 --- phpfspot.class.php | 163 ++++++++++++++++++++++++++++++++--------- phpfspot.js | 71 ++++++++++++++++-- rpc.php | 13 ++++ stylesheet.css | 28 +++++++ templates/calendar.tpl | 28 +++++++ templates/index.tpl | 2 +- templates/search.tpl | 7 ++ 7 files changed, 271 insertions(+), 41 deletions(-) create mode 100644 templates/calendar.tpl diff --git a/phpfspot.class.php b/phpfspot.class.php index 8fe0f77..31a3952 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -54,8 +54,8 @@ class PHPFSPOT { $this->tmpl->assign('searchfor', $_SESSION['searchfor']); $this->tmpl->assign('page_title', $this->cfg->page_title); $this->tmpl->assign('current_condition', $_SESSION['tag_condition']); - $this->tmpl->assign('from_date', $this->get_calendar()); - $this->tmpl->assign('to_date', $this->get_calendar()); + $this->tmpl->assign('from_date', $this->get_calendar('from')); + $this->tmpl->assign('to_date', $this->get_calendar('to')); switch($_GET['mode']) { case 'showpi': @@ -339,25 +339,37 @@ class PHPFSPOT { public function resetTags() { - unset($_SESSION['selected_tags']); + if(isset($_SESSION['selected_tags'])) + unset($_SESSION['selected_tags']); } // resetTags() public function resetPhotoView() { - unset($_SESSION['current_photo']); + if(isset($_SESSION['current_photo'])) + unset($_SESSION['current_photo']); } // resetPhotoView(); public function resetTagSearch() { - unset($_SESSION['searchfor']); + if(isset($_SESSION['searchfor'])) + unset($_SESSION['searchfor']); } // resetTagSearch() + public function resetDateSearch() + { + if(isset($_SESSION['from_date'])) + unset($_SESSION['from_date']); + if(isset($_SESSION['to_date'])) + unset($_SESSION['to_date']); + + } // resetDateSearch(); + public function getPhotoSelection() { - $tagged_photos = Array(); + $matched_photos = Array(); /* return a search result */ if(isset($_SESSION['searchfor']) && $_SESSION['searchfor'] != '') { @@ -372,9 +384,9 @@ class PHPFSPOT { ORDER BY p.time ASC "); while($row = $this->db->db_fetch_object($result)) { - array_push($tagged_photos, $row['photo_id']); + array_push($matched_photos, $row['photo_id']); } - return $tagged_photos; + return $matched_photos; } /* return according the selected tags */ @@ -432,11 +444,31 @@ class PHPFSPOT { } while($row = $this->db->db_fetch_object($result)) { - array_push($tagged_photos, $row['photo_id']); + array_push($matched_photos, $row['photo_id']); } - return $tagged_photos; + 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(" SELECT DISTINCT photo_id @@ -446,9 +478,9 @@ class PHPFSPOT { ORDER BY p.time ASC "); while($row = $this->db->db_fetch_object($result)) { - array_push($tagged_photos, $row['photo_id']); + array_push($matched_photos, $row['photo_id']); } - return $tagged_photos; + return $matched_photos; } // getPhotoSelection() @@ -908,8 +940,16 @@ class PHPFSPOT { array_push($_SESSION['selected_tags'], $tag); } + $this->resetDateSearch(); + } // startTagSearch() + public function startDateSearch($from, $to) + { + $_SESSION['from_date'] = $from; + $_SESSION['to_date'] = $to; + } + private function rotateImage($img, $degrees) { if(function_exists("imagerotate")) @@ -1082,37 +1122,90 @@ class PHPFSPOT { } // _warning() - private function get_calendar() + private function get_calendar($mode) { -// require_once CALENDAR_ROOT.'Year.php'; -// require_once CALENDAR_ROOT.'Month.php'; -// require_once CALENDAR_ROOT.'Day.php'; + $output = "\n"; + $output.= "\n"; + $output.= "\n"; + return $output; -// $Year = new Calendar_Year(); -// $Month = new Calendar_Month(); -// $Day = new Calendar_Day(); + } // get_calendar() - $output = "\n"; + public function get_calendar_matrix($year = 0, $month = 0, $day = 0) + { + if (!isset($year)) $year = date('Y'); + if (!isset($month)) $month = date('m'); + if (!isset($day)) $day = date('d'); + $rows = 1; + $cols = 1; + $matrix = Array(); + + require_once CALENDAR_ROOT.'Month/Weekdays.php'; + require_once CALENDAR_ROOT.'Day.php'; - $output.= "\n"; - $output.= "\n"; - return $output; + $this->tmpl->assign('matrix', $matrix); + $this->tmpl->assign('rows', $rows); + $this->tmpl->show("calendar.tpl"); - } // get_calendar() + } // get_calendar_matrix() public function getExport($mode) { diff --git a/phpfspot.js b/phpfspot.js index be15455..40d6761 100644 --- a/phpfspot.js +++ b/phpfspot.js @@ -20,10 +20,6 @@ function Tags(mode, id) // del the tag from users session HTML_AJAX.grab(encodeURI('rpc.php?action=deltag&id=' + id)); } - else if(mode == "reset") { - HTML_AJAX.grab(encodeURI('rpc.php?action=reset')); - clearSearch(); - } else if(mode == "condition") { setCheckedValue(id, id.value); HTML_AJAX.grab(encodeURI('rpc.php?action=tagcondition&mode=' + id.value)); @@ -107,7 +103,25 @@ function startTagSearch(searchfor) refreshAvailableTags(); refreshSelectedTags(); showPhotoIndex(); +} + +function startDateSearch() +{ + from_year = document.getElementById('fromyear').value; + from_month = document.getElementById('frommonth').value; + from_day = document.getElementById('fromday').value; + from = from_year +"-"+ from_month +"-"+ from_day; + to_year = document.getElementById('toyear').value; + to_month = document.getElementById('tomonth').value; + 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)); + + refreshAvailableTags(); + refreshSelectedTags(); + refreshPhotoIndex(); + refreshPhotoIndex(); } function setViewMode(mode) @@ -159,7 +173,54 @@ function getPhotoToShow() return photo_to_show; } +function showCalendar(date_box, click_obj) +{ + var calendar = document.getElementById('calendar'); + if(date_box == 'from') { + var xpos = document.getElementById('frompic').offsetLeft; + var ypos = document.getElementById('frompic').offsetTop; + calendar_mode = 'from'; + } + if(date_box == 'to') { + var xpos = document.getElementById('topic').offsetLeft; + var ypos = document.getElementById('topic').offsetTop; + calendar_mode = 'to'; + } + calendar.style.left = xpos + 60 + 'px'; + calendar.style.top = ypos + 80 + 'px'; + + if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') { + calendar.style.visibility = 'visible'; + calendar.innerHTML = "Loading..."; + calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix')); + calendar_shown = 1; + } + else { + calendar.style.visibility = 'hidden'; + calendar_shown = 0; + } +} +function setMonth(year, month, day) +{ + var calendar = document.getElementById('calendar'); + calendar.innerHTML = "Loading..."; + calendar.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day)); +} -var startup = 1; +function setCalendarDate(year, month, day) +{ + document.getElementById(calendar_mode+'year').value = year; + document.getElementById(calendar_mode+'month').value = month; + document.getElementById(calendar_mode+'day').value = day; +} + +function resetAll() +{ + HTML_AJAX.grab(encodeURI('rpc.php?action=reset')); + clearSearch(); +} +var startup = 1; +var calendar_shown = 0; +var calendar_mode = ''; diff --git a/rpc.php b/rpc.php index 49d1930..891f395 100644 --- a/rpc.php +++ b/rpc.php @@ -70,6 +70,7 @@ class PHPFSPOT_RPC { $fspot->resetTagSearch(); $fspot->resetTags(); + $fspot->resetDateSearch(); $fspot->resetPhotoView(); break; @@ -91,9 +92,17 @@ class PHPFSPOT_RPC { case 'tag_search': + $fspot->resetDateSearch(); $fspot->startTagSearch($_GET['for']); break; + case 'date_search': + + $fspot->resetTagSearch(); + $fspot->resetTags(); + $fspot->startDateSearch($_GET['from'], $_GET['to']); + break; + case 'get_export': $fspot->getExport($_GET['mode']); @@ -103,6 +112,10 @@ class PHPFSPOT_RPC { $fspot->getCurrentPhoto(); break; + case 'get_calendar_matrix': + $fspot->get_calendar_matrix($_GET['year'], $_GET['month'], $_GET['day']); + break; + } } // process_ajax_request(); diff --git a/stylesheet.css b/stylesheet.css index 8d12b95..20c1974 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -95,6 +95,10 @@ a.thumblink { font-size: 12px; } +a.calendar { + font-size: 10px; +} + a.thumblink:hover { color: #4761ab; } @@ -134,3 +138,27 @@ td.thumb { clip: auto; overflow: auto; } + +table.calendar tr td { + border: solid 1px #ffffff; + padding: 1px; + text-align: center; + font-size: 10px; +} + +.prevMonth { + font-size: 10px; + text-align: left; +} +.nextMonth { + font-size: 10px; + text-align: right; +} +#calendar { + position: absolute; + width: 140px; + height: 200px; + background-color: #000000; + visibility: hidden; + z-index: 1000; +} diff --git a/templates/calendar.tpl b/templates/calendar.tpl new file mode 100644 index 0000000..1f52732 --- /dev/null +++ b/templates/calendar.tpl @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + {section name="row" loop=$rows step=1} + {section name="col" loop=8 step=1} + {if $matrix[row][col] } + {$matrix[row][col]} + {/if} + {/section} + {/section} + +
<< + {$current_month} + >>
MTWTFSS
+ diff --git a/templates/index.tpl b/templates/index.tpl index 5ff9b0e..4366679 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -12,7 +12,7 @@ photo index - + reset tags diff --git a/templates/search.tpl b/templates/search.tpl index 092006e..51c1877 100644 --- a/templates/search.tpl +++ b/templates/search.tpl @@ -10,6 +10,13 @@ Tag: +
+ Date:
+ {$from_date}

+ {$to_date}
+ +
+
-- 2.25.1