commit a1063f687155fd8440c79de3943b6af9935db401
Author: Jocelyn Delande <jocelyn at delalande dot fr>
Date:   Wed Dec 25 15:51:27 2013 +0100

    The one-step upload now handles as well the tiles generation and stops on generation errors if needed

diff --git a/class/TilesGenerator.php b/class/TilesGenerator.php
index 5baae58..1e4bfe1 100644
--- a/class/TilesGenerator.php
+++ b/class/TilesGenerator.php
@@ -29,13 +29,9 @@ class TilesGenerator {
 			}
 		} else {
       if (file_exists($pano_path)) {
-         $pano_files = scandir($pano_path);
-        foreach($pano_files as $filename) {
-          if (preg_match('/.*\.jpg/', $filename)) {
-			      $err = sprintf("\"%s\" contient déjà un découpage de panorama.",
-                           $pano_path);
-            break;
-          }
+        if ($this->panorama->has_tiles()) {
+			    $err = sprintf("\"%s\" contient déjà un découpage de panorama.",
+                         $pano_path);
         }
 		  } else {
 			  mkdir($pano_path);
diff --git a/class/site_point.class.php b/class/site_point.class.php
index 239a67b..8aef257 100644
--- a/class/site_point.class.php
+++ b/class/site_point.class.php
@@ -96,6 +96,19 @@ class site_point {
 	                $p['altitude'], $p['titre']));
   }
 
+  public function has_tiles(){
+	  if (file_exists($this->tiles_path())) {
+         $pano_files = scandir($this->tiles_path());
+        foreach($pano_files as $filename) {
+          if (preg_match('/.*\.jpg/', $filename)) {
+	          return true;
+          }
+        }
+      } else {
+	      return false;
+      }
+  }
+
   public function get_name() {
     return basename($this->base_dir);
   }
@@ -151,6 +164,28 @@ class site_point {
     return array($d, $cap*180/M_PI, $e*180/M_PI);   // les résultats sont en degrés
   }
 
+  public function get_generate_url($source_file) {
+	  /**
+	   * @param $source_file : the name of the source file within the upload dir.
+	   */
+	  return sprintf('genererPano.php?wizard=1&name='.$source_file);
+  }
+
+  public function src_path(){
+	  /** @returns the basename of the src image, or false if it's no longer available
+	   */
+	  $extensions = array('jpg', 'tif', 'png', 'bmp', 'jpeg', 'pnm',
+	                      'JPG', 'TIF', 'PNG', 'BMP', 'JPEG', 'PNM');
+
+	  foreach ($extensions as $ext) {
+		  $tried_name = sprintf('%s/%s.%s', UPLOAD_PATH, $this->get_name(),$ext);
+		  if (file_exists($tried_name)) {
+			  return $tried_name;
+		  }
+	  }
+	  return false;
+  }
+
   public function get_url($cap=false, $ele=false) {
 	  $o = sprintf('panorama.php?dir=%s&panorama=%s',
 	                  PANORAMA_FOLDER, $this->get_name());
@@ -160,6 +195,17 @@ class site_point {
 	  return $o;
   }
 
+  public function get_map_url($cap=0) {
+	  $encoded_title = base64_encode($this->get_name());
+	  $script_name = 'show_capline.php';
+	  $lat = $this->get_params()['latitude'];
+	  $lon = $this->get_params()['longitude'];
+
+	  $o = sprintf('%s?title=%s&cap=%s&org_lat=%.5f&org_lon=%.5f&dist=120000',
+	               $script_name, $encoded_title, $cap, $lat, $lon);
+	  return $o;
+  }
+
   public function set_reference($ref_point, $x, $y) {
 	  /**
 	   * Registers (for saving) the position of a reference point within a
diff --git a/class/utils.class.php b/class/utils.class.php
index 833d140..8b0dde8 100644
--- a/class/utils.class.php
+++ b/class/utils.class.php
@@ -84,6 +84,11 @@ abstract class utils {
     }
   }
 
+  public static function relative_redirect($extra) {
+    $host  = $_SERVER['HTTP_HOST'];
+    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
+    header("Location: http://$host$uri/$extra");
+  }
 }
 
 ?>
diff --git a/genererPano.php b/genererPano.php
index 81a7fdd..a17a599 100644
--- a/genererPano.php
+++ b/genererPano.php
@@ -38,6 +38,11 @@ if (isset($_GET['name'])) {
     print("<p>Pour acceder à la liste des panoramas <a href=\".\">cliquer ici</a></p>\n") ;
 
 
+    // Redirect in js to sumary page
+    if ($_GET['wizard']) {
+      printf('<script>window.location=\'panoInfo.php?name=%s\'</script>\n', $pano_name);
+    }
+
   } catch (TilesGeneratorRightsException $e) {
     printf("<p class=\"error\">%s</p>\n", $e->getMessage());
   } catch (TilesGeneratorScriptException $e) {
diff --git a/panoInfo.php b/panoInfo.php
new file mode 100644
index 0000000..862d7e2
--- /dev/null
+++ b/panoInfo.php
@@ -0,0 +1,70 @@
+<?php
+require_once 'class/site_point.class.php';
+
+
+$pano = site_point::get($_GET['name']);
+
+if ($pano->has_params()) {
+  $params = $pano->get_params();
+  $title = $params['titre'];
+  $lat = $params['latitude'];
+  $lon = $params['longitude'];
+} else {
+  $title = $__GET['name'];
+}
+
+
+$has_tiles = $pano->has_tiles();//TODO
+$has_params = $pano->has_params();
+$src_path = $pano->src_path();
+ ?>
+
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+  <head>
+    <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
+    <title>Liste des panoramas</title>
+    <link rel="stylesheet" media="screen" href="css/base.css"/>
+  </head>
+  <body>
+    <header>
+      <h1><img src="images/tetaneutral.svg" alt="tetaneutral.net"/></h1>
+    </header>
+    <section id="main">
+      <h2><?php echo $title ?></h2>
+      <ul id="pano-list">
+        <li>
+          <?php if ($has_tiles) { ?>
+          <a href="<?php echo $pano->get_url();?>">Visualiser</a>
+          (généré)
+          <?php } else { ?>
+          Tuiles non générées 
+            <?php if ($src_path) {?>
+              <a href="<?php echo $pano->get_generate_url(basename($src_path))?>">Générer</a>
+            <?php } else  {?>
+              (la source n'est plus disponible)
+            <?php } ?>
+          <?php } ?>
+        </li>
+        <li>
+          <?php if ($has_params) { ?>
+          <a href="<?php echo $pano->get_map_url();?>">Voir sur la carte</a>
+          (<?php printf('%.5f,%.5f', $lat, $lon) ?>)
+          <?php } else { ?>
+          Non paramétré
+            <?php if ($has_tiles) {?>
+              <a href="<?php echo $pano->get_url();?>">Paramétrer</a>
+            <?php } ?>
+          <?php } ?>
+        </li>
+      </ul>
+    </section>
+    <footer class="validators"><samp>
+      page validée par
+      <a href="http://validator.w3.org/check?uri=referer"><img src="images/valid_xhtml.svg"
+							       alt="Valid XHTML" title="xHTML validé !"/></a>
+      <a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="images/valid_css.svg"
+								      alt="CSS validé !" title="CSS validé !"/></a>
+    </samp></footer>
+  </body>
+</html>
diff --git a/uploadReceive.php b/uploadReceive.php
index caab3cc..fa9fc45 100644
--- a/uploadReceive.php
+++ b/uploadReceive.php
@@ -103,6 +103,14 @@ if ($upload_success) {
 }
 
 
+////// STEP 3 : TILES ////////
+
+// We do it in a redirection
+
+if ($upload_success) {
+  utils::relative_redirect(
+    $panorama->get_generate_url(basename($uploaded_filepath)));
+}
 ?>
 
 <!DOCTYPE html>
