+ /**
+ * output calendard input fields
+ */
+ private function get_calendar($mode)
+ {
+ $year = $_SESSION[$mode .'_date'] ? date("Y", strtotime($_SESSION[$mode .'_date'])) : date("Y");
+ $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 ."\"";
+ 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()
+
+ /**
+ * output calendar matrix
+ */
+ 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';
+
+ // Build the month
+ $month = new Calendar_Month_Weekdays($year,$month);
+
+ // Create links
+ $prevStamp = $month->prevMonth(true);
+ $prev = "javascript:setMonth(". date('Y',$prevStamp) .", ". date('n',$prevStamp) .", ". date('j',$prevStamp) .");";
+ $nextStamp = $month->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);
+
+ $this->tmpl->assign('current_month', date('F Y',$month->getTimeStamp()));
+ $this->tmpl->assign('prev_month', $prev);
+ $this->tmpl->assign('next_month', $next);
+
+ while ( $day = $month->fetch() ) {
+
+ if(!isset($matrix[$rows]))
+ $matrix[$rows] = Array();
+
+ $string = "";
+
+ $dayStamp = $day->thisDay(true);
+ $link = "javascript:setCalendarDate(". date('Y',$dayStamp) .", ". date('n',$dayStamp).", ". date('j',$dayStamp) .");";
+
+ // isFirst() to find start of week
+ if ( $day->isFirst() )
+ $string.= "<tr>\n";
+
+ if ( $day->isSelected() ) {
+ $string.= "<td class=\"selected\">".$day->thisDay()."</td>\n";
+ } else if ( $day->isEmpty() ) {
+ $string.= "<td> </td>\n";
+ } else {
+ $string.= "<td><a class=\"calendar\" href=\"".$link."\">".$day->thisDay()."</a></td>\n";
+ }
+
+ // isLast() to find end of week
+ if ( $day->isLast() )
+ $string.= "</tr>\n";
+
+ $matrix[$rows][$cols] = $string;
+
+ $cols++;
+
+ if($cols > 7) {
+ $cols = 1;
+ $rows++;
+ }
+ }
+
+ $this->tmpl->assign('matrix', $matrix);
+ $this->tmpl->assign('rows', $rows);
+ $this->tmpl->show("calendar.tpl");
+
+ } // get_calendar_matrix()
+
+ /**
+ * output export page
+ */
+ public function getExport($mode)
+ {
+ $pictures = $this->getPhotoSelection();
+ $current_tags = $this->getCurrentTags();
+
+ if(!isset($_SERVER['HTTPS'])) $protocol = "http";
+ else $protocol = "https";
+
+ $server_name = $_SERVER['SERVER_NAME'];
+
+ foreach($pictures as $picture) {
+
+ $orig_url = $protocol ."://". $server_name . $this->cfg->web_path ."index.php?mode=showp&id=". $picture;
+ if($current_tags != "") {
+ $orig_url.= "&tags=". $current_tags;
+ }
+ if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
+ $orig_url.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date'];
+ }
+
+ $thumb_url = $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width;
+
+ switch($mode) {
+
+ case 'HTML':
+ // <a href="%pictureurl%"><img src="%thumbnailurl%" ></a>
+ print htmlspecialchars("<a href=\"". $orig_url ."\"><img src=\"". $thumb_url ."\" /></a>") ."<br />\n";
+ break;
+
+ case 'MoinMoin':
+ // [%pictureurl% %thumbnailurl%]
+ print htmlspecialchars(" * [".$orig_url." ".$thumb_url."&fake=1.jpg]") ."<br />\n";
+ break;
+ }
+
+ }
+
+ } // getExport()
+
+ /**
+ * return all selected tags as one string
+ */
+ private function getCurrentTags()
+ {
+ $current_tags = "";
+ if($_SESSION['selected_tags'] != "") {
+ foreach($_SESSION['selected_tags'] as $tag)
+ $current_tags.= $tag .",";
+ $current_tags = substr($current_tags, 0, strlen($current_tags)-1);
+ }
+ return $current_tags;
+
+ } // getCurrentTags()
+
+ /**
+ * return the current photo
+ */
+ public function getCurrentPhoto()
+ {
+ if(isset($_SESSION['current_photo'])) {
+ print $_SESSION['current_photo'];
+ }
+ } // getCurrentPhoto()
+
+ /**
+ * tells the client browser what to do
+ *
+ * this function is getting called via AJAX by the
+ * client browsers. it will tell them what they have
+ * to do next. This is necessary for directly jumping
+ * into photo index or single photo view when the are
+ * requested with specific URLs
+ */
+ public function whatToDo()
+ {
+ if(isset($_SESSION['current_photo']) && $_SESSION['start_action'] == 'showp') {
+ return "show_photo";
+ }
+ elseif((isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) ||
+ (isset($_SESSION['from_date']) && isset($_SESSION['to_date']))) {
+ return "showpi";
+ }
+ elseif(isset($_SESSION['start_action']) && $_SESSION['start_action'] == 'showpi') {
+ return "showpi";
+ }
+
+ return "nothing special";
+
+ } // whatToDo()
+
+ /**
+ * return the current process-user
+ */
+ private function getuid()
+ {
+ if($uid = posix_getuid()) {
+ if($user = posix_getpwuid($uid)) {
+ return $user['name'];
+ }
+ }
+
+ return 'n/a';
+
+ } // getuid()
+
+ /**
+ * returns a select-dropdown box to select photo index sort parameters
+ */
+ private function get_sort_field()
+ {
+ $output = "<select name=\"sort_order\">";
+ foreach(array('date_asc', 'date_desc', 'name_asc', 'name_desc') as $sort_order) {
+ $output.= "<option value=\"". $sort_order ."\"";
+ if($sort_order == $_SESSION['sort_order']) {
+ $output.= " selected=\"selected\"";
+ }
+ $output.= ">". $sort_order ."</option>";
+ }
+ $output.= "</select>";
+ return $output;
+
+ } // get_sort_field()
+
+ /**
+ * returns the currently selected sort order
+ */
+ private function get_sort_order()
+ {
+ switch($_SESSION['sort_order']) {
+ case 'date_asc':
+ return " ORDER BY p.time ASC";
+ break;
+ case 'date_desc':
+ return " ORDER BY p.time DESC";
+ break;
+ case 'name_asc':
+ return " ORDER BY p.name ASC";
+ break;
+ case 'name_desc':
+ return " ORDER BY p.name DESC";
+ break;
+ }
+
+ } // get_sort_order()
+
+ public function getNextSlideShowImage()
+ {
+ $all_photos = $this->getPhotoSelection();
+
+ if(!isset($_SESSION['slideshow_img']) || $_SESSION['slideshow_img'] == count($all_photos)-1)
+ $_SESSION['slideshow_img'] = 0;
+ else
+ $_SESSION['slideshow_img']++;
+
+ $server_name = $_SERVER['SERVER_NAME'];
+ if(!isset($_SERVER['HTTPS'])) $protocol = "http";
+ else $protocol = "https";
+
+ return $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $all_photos[$_SESSION['slideshow_img']] ."&width=". $this->cfg->photo_width;
+
+ } // getNextSlideShowImage()
+
+ public function resetSlideShow()
+ {
+ if(isset($_SESSION['slideshow_img']))
+ unset($_SESSION['slideshow_img']);
+ } // resetSlideShow()