commit 137a4cfc6a39359c792b0766c1d9f35398f89dc4
Author: Jocelyn Delande <jocelyn at delalande dot fr>
Date:   Mon Dec 23 21:57:24 2013 +0100

    does the same upload job, bet refactored the form and receive action for future

diff --git a/class/FormValidator.class.php b/class/FormValidator.class.php
index dffc1bd..38a05b5 100644
--- a/class/FormValidator.class.php
+++ b/class/FormValidator.class.php
@@ -40,12 +40,14 @@ class FormValidator {
 						$sanitized_f = $request[$fieldname];
 					}
 				} else {
-					$val = $request[$fieldname];
-					try {
-						$sanitized_f = $this->validate_field($validator, $val);
-					} catch (FieldValidationError $e) {
-						$err = $e->getMessage();
-						break;
+					if (isset($request[$fieldname]) and $request[$fieldname]) {
+						$val = $request[$fieldname];
+						try {
+							$sanitized_f = $this->validate_field($validator, $val);
+						} catch (FieldValidationError $e) {
+							$err = $e->getMessage();
+							break;
+						}
 					}
 				}
 			}
@@ -92,7 +94,7 @@ FormValidator::register(
   'numeric',
   function ($v) {
 	  $sanitized = floatval($v);
-    if ($sanitized === false) {
+	  if (($sanitized === false) || (!is_numeric($v))) {
 	  	throw new FieldValidationError('n\'est pas une valeur numérique');
 	  } else {
 		  return $sanitized;
diff --git a/envoyer.php b/envoyer.php
index fb316b1..d18799c 100644
--- a/envoyer.php
+++ b/envoyer.php
@@ -33,7 +33,7 @@
 			<ul>
 			  <li><input type="file" name="files[]" id="file" multiple="multiple"/></li>
 
-			  <li><input type="checkbox" name="loop">Panorama bouclant
+			  <li><input type="checkbox" name="loop" value="true">Panorama bouclant
 			  (360°)</li>
 			</ul>
 		<p class="help">
diff --git a/uploadReceive.php b/uploadReceive.php
index 31cf728..ab26a89 100644
--- a/uploadReceive.php
+++ b/uploadReceive.php
@@ -1,38 +1,95 @@
-<!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>Transfert de panoramique</title>
-</head>
-<body>
 <?php
  
-$dest_dir ='upload';
+require_once('class/FormValidator.class.php');
+require_once('constants.inc.php');
+
+class UploadReceiveError extends Exception {}
+
+
+////////////////////// actions //////////////////////////////////////////
 
-if (! is_dir($dest_dir)) {
-    if (! mkdir($dest_dir)) {
-        $message = 'Dossier "'.$dest_dir.'" non inscriptible ou inexistant.';
+function handle_upload() {
+  if (! is_dir(UPLOAD_PATH)) {
+    if (! mkdir(UPLOAD_PATH)) {
+      throw new UploadReceiveError(
+        'Dossier "'.UPLOAD_PATH.'" non inscriptible ou inexistant.');
     }
-}
+  }
+  foreach ($_FILES['files']['name'] as $i => $file) {
+    $file_err = $_FILES['files']['error'][$i];
+    $file_tmp = $_FILES['files']['tmp_name'][$i];
+    $file_finalpath = UPLOAD_PATH.'/'.basename($file);
 
-if(!empty($_POST) && !empty($_FILES)) {
-  foreach (array_keys($_FILES['files']['name']) as $i) {
-    if(!empty($_FILES['files']['name'][$i])) {
-      if(isset($_FILES['files']['error'][$i]) && UPLOAD_ERR_OK === $_FILES['files']['error'][$i]) {
-	move_uploaded_file($_FILES['files']['tmp_name'][$i],$dest_dir.'/'.basename($_FILES['files']['name'][$i]));
-	printf("<h2>transfert de %s réalisé</h2>\n", $_FILES['files']['name'][$i]);
+    if(!empty($file)) {
+      if(isset($file) && UPLOAD_ERR_OK === $file_err) {
+	      move_uploaded_file($file_tmp, $file_finalpath);
+        return sprintf("transfert de %s réalisé",  $file);
       } else {
-	$message = 'Une erreur interne a empêché l\'upload de l\'image : '. $_FILES['files']['error'][$i];
+        throw new UploadReceiveError(
+          'Une erreur interne a empêché l\'envoi de l\'image :'. $file_err);
       }
     } else {
-      $message = 'Veuillez passer par le formulaire svp !';
+      throw new UploadReceiveError(
+        'Veuillez passer par le formulaire svp !');
     }
   }
-  if (isset($message)) {
-    echo "<h2>$message</h2>\n";
+}
+
+////////////////////// main //////////////////////////////////////////
+
+$fields_spec = array('lat'         => array('required', 'numeric', 'positive'),
+                     'lon'         => array('numeric', 'positive'),
+                     'alt'  => array('numeric'),
+);
+
+$validator = new FormValidator($fields_spec);
+$upload_success = false;
+
+////// STEP 1 : UPLOAD ////////
+
+if ($validator->validate($_REQUEST)) {
+  try {
+    $message = handle_upload();
+    $upload_success = true;
+  } catch (UploadReceiveError $e) {
+    $message = $e->getMessage();
+  }
+} else {
+  $message = 'paramètres invalides';
+}
+
+////// STEP 2 : PARAMETERS ////////
+
+$params_success = false;
+
+if ($upload_success) {
+  //pass
+}
+
+
+?>
+
+<!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>Transfert de panoramique</title>
+</head>
+<body>
+<?php
+if (isset($message)) {
+  echo "<h2>$message</h2>\n";
+  if ($validator->errors()) {
+    foreach($validator->errors() as $key => $error) {
+      printf('<p>"%s" : %s</p>', $_REQUEST[$key], $error);
+    }
+
+  } else {
+?>
+    <p>Pour acceder à la liste des images transférées afin de convertir en panorama <a href="creerPano.php">cliquer ici</a></p>
+<?php 
   }
 }
 ?>
-<p>Pour acceder à la liste des images transférées afin de convertir en panorama <a href="creerPano.php">cliquer ici</a></p>
 </body>
 </html>
