From 5bc4f09805223539cd593ccbe7ed49955dd58775 Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 23 May 2009 12:48:50 +0200 Subject: make calendar window working again, fixes #78 Signed-off-by: Andreas Unterkircher --- phpfspot.class.php | 45 +++++++++++++++++++++++++++++++++------------ phpfspot.js | 14 ++++++-------- rpc.php | 6 ++---- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/phpfspot.class.php b/phpfspot.class.php index 1423f98..89f924d 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -2561,6 +2561,11 @@ class PHPFSPOT { print "PEAR Console_Getopt package is missing
\n"; $missing = true; } + @include_once 'Date.php'; + if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) { + print "PEAR Date package is missing
\n"; + $missing = true; + } @include_once $this->cfg->smarty_path .'/libs/Smarty.class.php'; if(isset($php_errormsg) && preg_match('/Failed opening.*for inclusion/i', $php_errormsg)) { print "Smarty template engine can not be found in ". $this->cfg->smarty_path ."/libs/Smarty.class.php
\n"; @@ -2665,11 +2670,22 @@ class PHPFSPOT { * @param integer $month * @param integer $day */ - public function get_calendar_matrix($year = 0, $month = 0, $day = 0) + public function get_calendar_matrix($userdate) { - if (!isset($year)) $year = date('Y'); - if (!isset($month)) $month = date('m'); - if (!isset($day)) $day = date('d'); + if(($userdate = strtotime($userdate)) === false) { + $year = date('Y'); + $month = date('m'); + $day = date('d'); + } + else { + $date = new Date(); + $date->setDate($userdate); + + $year = $date->getYear(); + $month = $date->getMonth(); + $day = $date->getDay(); + } + $rows = 1; $cols = 1; $matrix = Array(); @@ -2678,27 +2694,26 @@ class PHPFSPOT { require_once CALENDAR_ROOT.'Day.php'; // Build the month - $month = new Calendar_Month_Weekdays($year,$month); + $month_cal = new Calendar_Month_Weekdays($year,$month); // Create links - $prevStamp = $month->prevMonth(true); + $prevStamp = $month_cal->prevMonth(true); $prev = "javascript:setMonth(". date('Y',$prevStamp) .", ". date('n',$prevStamp) .", ". date('j',$prevStamp) .");"; - $nextStamp = $month->nextMonth(true); + $nextStamp = $month_cal->nextMonth(true); $next = "javascript:setMonth(". date('Y',$nextStamp) .", ". date('n',$nextStamp) .", ". date('j',$nextStamp) .");"; $selectedDays = array ( new Calendar_Day($year,$month,$day), - new Calendar_Day($year,12,25), ); // Build the days in the month - $month->build($selectedDays); + $month_cal->build($selectedDays); - $this->tmpl->assign('current_month', date('F Y',$month->getTimeStamp())); + $this->tmpl->assign('current_month', date('F Y',$month_cal->getTimeStamp())); $this->tmpl->assign('prev_month', $prev); $this->tmpl->assign('next_month', $next); - while ( $day = $month->fetch() ) { + while ( $day = $month_cal->fetch() ) { if(!isset($matrix[$rows])) $matrix[$rows] = Array(); @@ -2706,7 +2721,13 @@ class PHPFSPOT { $string = ""; $dayStamp = $day->thisDay(true); - $link = "javascript:setCalendarDate(". date('Y',$dayStamp) .", ". date('n',$dayStamp).", ". date('j',$dayStamp) .");"; + $link = "javascript:setCalendarDate('" + . date('Y',$dayStamp) + . "-" + . date('m',$dayStamp) + . "-" + . date('d',$dayStamp) + ."');"; // isFirst() to find start of week if ( $day->isFirst() ) diff --git a/phpfspot.js b/phpfspot.js index 54395e2..f705e88 100644 --- a/phpfspot.js +++ b/phpfspot.js @@ -535,8 +535,8 @@ function hidePhotoDetails(mode) function showCalendar(date_box, click_obj) { var calendar = document.getElementById('calendar'); - var year = document.getElementById(date_box+'year').value; - var month = document.getElementById(date_box+'month').value; + var userdate = document.getElementById('date_' + date_box).value; + if(date_box == 'from') { var xpos = document.getElementById('frompic').offsetLeft; var ypos = document.getElementById('frompic').offsetTop; @@ -553,7 +553,7 @@ function showCalendar(date_box, click_obj) if(calendar.style.visibility == "" || calendar.style.visibility == 'hidden') { calendar.style.visibility = 'visible'; calendar.innerHTML = "Loading..."; - calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path +'/rpc.php?action=get_calendar_matrix&year=' + year + '&month=' + month)); + calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path +'/rpc.php?action=get_calendar_matrix&date=' + userdate)); calendar_shown = 1; } else { @@ -581,18 +581,16 @@ function setMonth(year, month, day) { var calendar = document.getElementById('calendar'); calendar.innerHTML = "Loading..."; - calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_calendar_matrix&year='+ year +'&month='+ month +'&day='+ day)); + calendar.innerHTML = HTML_AJAX.grab(encodeURI(web_path + '/rpc.php?action=get_calendar_matrix&date='+ year +'-'+ month +'-'+ day)); } /** * get the user-selected date from the calendar and * put it into the date-search boxes */ -function setCalendarDate(year, month, day) +function setCalendarDate(userdate) { - document.getElementById(calendar_mode+'year').value = year; - document.getElementById(calendar_mode+'month').value = month; - document.getElementById(calendar_mode+'day').value = day; + document.getElementById('date_'+calendar_mode).value = userdate; hideCalendar(); } // setCalendarDate() diff --git a/rpc.php b/rpc.php index 17af073..748fd25 100644 --- a/rpc.php +++ b/rpc.php @@ -152,10 +152,8 @@ class PHPFSPOT_RPC { break; case 'get_calendar_matrix': - if((is_numeric($_GET['year']) || !isset($_GET['year'])) && - (is_numeric($_GET['month']) || !isset($_GET['month'])) && - (is_numeric($_GET['day']) || !isset($_GET['day']))) { - $phpfspot->get_calendar_matrix($_GET['year'], $_GET['month'], $_GET['day']); + if(isset($_GET['date']) && is_string($_GET['date'])) { + $phpfspot->get_calendar_matrix($_GET['date']); } break; -- cgit v1.2.3-18-g5258