get_current_user() returns the OWNER of the php script - now we use posix functions...
[phpfspot.git] / phpfspot.class.php
index 31a39529776df42465141c2e718b2f8fa3a13fae..579054d6ebd70a18caba3abd46612723c6e5474f 100644 (file)
@@ -23,6 +23,12 @@ class PHPFSPOT {
       $this->cfg = new PHPFSPOT_CFG;
 
       $this->db  = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
       $this->cfg = new PHPFSPOT_CFG;
 
       $this->db  = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
+      
+      if(!is_writeable(dirname($this->cfg->phpfspot_db))) {
+         print dirname($this->cfg->phpfspot_db) .": directory is not writeable!";
+         exit(1);
+      }
+         
       $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
       $this->check_config_table();
 
       $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
       $this->check_config_table();
 
@@ -54,21 +60,35 @@ 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('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('from'));
-      $this->tmpl->assign('to_date', $this->get_calendar('to'));
+
+      $_SESSION['start_action'] = $_GET['mode'];
 
       switch($_GET['mode']) {
          case 'showpi':
             if(isset($_GET['tags'])) {
                $_SESSION['selected_tags'] = split(',', $_GET['tags']);
             }
 
       switch($_GET['mode']) {
          case 'showpi':
             if(isset($_GET['tags'])) {
                $_SESSION['selected_tags'] = split(',', $_GET['tags']);
             }
+            if(isset($_GET['from_date'])) {
+               $_SESSION['from_date'] = $_GET['from_date'];
+            }
+            if(isset($_GET['to_date'])) {
+               $_SESSION['to_date'] = $_GET['to_date'];
+            }
             break;
          case 'showp':
             if(isset($_GET['tags'])) {
                $_SESSION['selected_tags'] = split(',', $_GET['tags']);
             break;
          case 'showp':
             if(isset($_GET['tags'])) {
                $_SESSION['selected_tags'] = split(',', $_GET['tags']);
+               $_SESSION['start_action'] = 'showp';
             }
             if(isset($_GET['id'])) {
                $_SESSION['current_photo'] = $_GET['id'];
             }
             if(isset($_GET['id'])) {
                $_SESSION['current_photo'] = $_GET['id'];
+               $_SESSION['start_action'] = 'showp';
+            }
+            if(isset($_GET['from_date'])) {
+               $_SESSION['from_date'] = $_GET['from_date'];
+            }
+            if(isset($_GET['to_date'])) {
+               $_SESSION['to_date'] = $_GET['to_date'];
             }
             break;
          case 'export':
             }
             break;
          case 'export':
@@ -78,6 +98,8 @@ class PHPFSPOT {
 
       }
 
 
       }
 
+      $this->tmpl->assign('from_date', $this->get_calendar('from'));
+      $this->tmpl->assign('to_date', $this->get_calendar('to'));
       $this->tmpl->assign('content_page', 'welcome.tpl');
       $this->tmpl->show("index.tpl");
 
       $this->tmpl->assign('content_page', 'welcome.tpl');
       $this->tmpl->show("index.tpl");
 
@@ -177,7 +199,7 @@ class PHPFSPOT {
       }
 
       if(!is_readable($orig_path)) {
       }
 
       if(!is_readable($orig_path)) {
-         $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
+         $this->_warning("Photo ". $orig_path ." is not readable for user ". $this->getuid() ."<br />\n");
       }
 
       /* If the thumbnail doesn't exist yet, try to create it */
       }
 
       /* If the thumbnail doesn't exist yet, try to create it */
@@ -204,6 +226,9 @@ class PHPFSPOT {
       if($current_tags != "") {
          $extern_link.= "&tags=". $current_tags;
       }
       if($current_tags != "") {
          $extern_link.= "&tags=". $current_tags;
       }
+      if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
+         $extern_link.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date'];
+      }
 
       $this->tmpl->assign('extern_link', $extern_link);
 
 
       $this->tmpl->assign('extern_link', $extern_link);
 
@@ -319,6 +344,9 @@ class PHPFSPOT {
 
    public function addTag($tag)
    {
 
    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();
 
       if(!isset($_SESSION['selected_tags']))
          $_SESSION['selected_tags'] = Array();
 
@@ -644,6 +672,9 @@ class PHPFSPOT {
       if($current_tags != "") {
          $extern_link.= "&tags=". $current_tags;
       }
       if($current_tags != "") {
          $extern_link.= "&tags=". $current_tags;
       }
+      if(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
+         $extern_link.= "&from_date=". $_SESSION['from_date'] ."&to_date=". $_SESSION['to_date'];
+      }
 
       $export_link = "index.php?mode=export";
 
 
       $export_link = "index.php?mode=export";
 
@@ -860,7 +891,7 @@ class PHPFSPOT {
       }
 
       if(!is_readable($full_path)) {
       }
 
       if(!is_readable($full_path)) {
-         $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
+         $this->_warning("File ". $full_path ." is not readable for ". $this->getuid() ."\n");
          return;
       }
 
          return;
       }
 
@@ -1124,9 +1155,13 @@ class PHPFSPOT {
 
    private function get_calendar($mode)
    {
 
    private function get_calendar($mode)
    {
-      $output = "<input type=\"text\" size=\"3\" id=\"". $mode ."year\" value=\"". date("Y") ."\" />\n";
-      $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."month\" value=\"". date("m") ."\" />\n";
-      $output.= "<input type=\"text\" size=\"1\" id=\"". $mode ."day\" value=\"". date("d") ."\" />\n";
+      $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 ."\" />\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";
       return $output;
 
    } // get_calendar()
       return $output;
 
    } // get_calendar()
@@ -1223,6 +1258,9 @@ class PHPFSPOT {
          if($current_tags != "") {
             $orig_url.= "&tags=". $current_tags;
          } 
          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;
 
 
          $thumb_url = $protocol ."://". $server_name . $this->cfg->web_path ."phpfspot_img.php?idx=". $picture ."&width=". $this->cfg->thumb_width;
 
@@ -1262,6 +1300,37 @@ class PHPFSPOT {
       }
    } // getCurrentPhoto()
 
       }
    } // getCurrentPhoto()
 
+   public function whatToDo()
+   {
+      if(isset($_SESSION['selected_tags']) && !empty($_SESSION['selected_tags'])) {
+         return "showpi_tags";
+      }
+      elseif(isset($_SESSION['from_date']) && isset($_SESSION['to_date'])) {
+         return "showpi_date";
+      }
+      elseif(isset($_SESSION['current_photo'])) {
+         return "show_photo";
+      }
+      elseif(isset($_SESSION['start_action']) && $_SESSION['start_action'] == 'showpi') {
+         return "showpi";
+      }
+
+      return "nothing special";
+
+   } // whatToDo()
+
+   private function getuid()
+   {
+      if($uid = posix_getuid()) {
+         if($user = posix_getpwuid($uid)) {
+            return $user['name'];
+         }
+      }
+   
+      return 'n/a';
+   
+   } // getuid()
+
 }
 
 ?>
 }
 
 ?>