commit 3d3b31ae303f4a44c7b1d19e169fbead2ad6dc5d
Author: Jocelyn Delande <jocelyn at delalande dot fr>
Date:   Tue Dec 10 00:41:03 2013 +0100

    Moved some treatements to functions for better understanding.

diff --git a/addParams.php b/addParams.php
index 974d5b1..592a102 100644
--- a/addParams.php
+++ b/addParams.php
@@ -1,17 +1,8 @@
 <?php
 require_once('class/site_point.class.php');
-?>
 
-<!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"/>
-   <link rel="stylesheet" media="screen" href="css/base.css" />
-   <title>Positionnerment dun panoramique</title>
-
-<?php
    // tableau de vérification de conformité
- $params = array('title' => array('name' => 'titre',
+$params = array('title' => array('name' => 'titre',
 				  'pattern' => '^.{1,50}$',
 				  'required' => true),
 		 'latitude' => array('name' => 'latitude',
@@ -31,8 +22,41 @@ require_once('class/site_point.class.php');
 		 'loop' => array('name' => 'image_loop',
 				 'type' => 'boolean',
 				 'required' => false),
-		 'dir' => array('required' => true),
 		 'panorama' => array('required' => true));
+
+
+class FormValidationError extends Exception {}
+
+function ini_value($k, $v, $params_format) {
+  /** According to the $params global reference table, format the value for
+  storing in an ini file and returns it.
+  */
+  if (isset($params_format[$k]['type']) && $params_format[$k]['type'] == 'numeric') {
+	$ini_val = $v;
+  } else if (isset($params_format[$k]['type']) && $params_format[$k]['type'] == 'boolean') {
+	$ini_val = $v ? "true" : "false";
+  } else { //string
+	$ini_val = "\"$v\"";
+  }
+  return $ini_val;
+}
+
+function is_ini_key($k, $params_format) {
+  /** Do we need to store that information in the params ini file ?
+  */
+  return isset($params_format[$k]['name']);
+}
+
+function ini_key($k, $params_format) {
+  /** For a given form key, returns the key for ini file
+  */
+  if (isset($params_format[$k]['name'])) {
+    return $params_format[$k]['name'];
+  } else {
+    throw (new FormValidationError('"'.$k.'" is an unknown key.'));
+  }
+}
+
 $wrong = array();
 $values = array();
 // vérification de la conformité
@@ -48,33 +72,36 @@ foreach($params as $param => $check) {
     $wrong[$param] = '<em>$tst</em> est un paramètre manquant';
   }
 }
+?>
+<!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"/>
+   <link rel="stylesheet" media="screen" href="css/base.css" />
+   <title>Positionnerment dun panoramique</title>
 
-
+<?php
 if (count($wrong) == 0) {
-	$pano = site_point::get($values['panorama']);
+  $pano = site_point::get($values['panorama']);
 
   // On vérifie qu'on a bien créée un nouveau fichier .params et on écrit dedans.
-	echo '<p>Les valeurs suivantes sont utilisées.</p>'."\n";
-	echo "<dl>\n";
-	foreach ($values as $k => $v) {
-		if (isset($params[$k]['name'])) {
-			$nm = $params[$k]['name'];
-			if (isset($params[$k]['type']) && $params[$k]['type'] == 'numeric') {
-				$vf = $v;
-			} else if (isset($params[$k]['type']) && $params[$k]['type'] == 'boolean') {
-				$vf = $v ? "true" : "false";
-			} else {
-				$vf = "\"$v\"";
-			}
-			$pano->set_param($nm, $vf);
-			printf("<dt>%s</dt>\n<dd>%s</dd>\n", $nm, $vf);
-		}
-	}
-	$pano->save_params();
+  echo '<p>Les valeurs suivantes sont utilisées.</p>'."\n";
+  echo "<dl>\n";
 
-	echo "</dl>\n";
-	echo '<p class="succes">Paramétrage terminé.</p>'."\n";
-  printf('<a href="%s">Retour au panorama</a></p>'."\n", $panorama->get_url());
+  foreach ($values as $k => $v) {
+    if (is_ini_key($k, $params)) {
+      $storable_key = ini_key($k, $params);
+      $storable_val = ini_value($k, $v, $params);
+
+	  $pano->set_param($storable_key, $storable_val);
+	  printf("<dt>%s</dt>\n<dd>%s</dd>\n", $storable_key, $storable_val);
+    }
+  }
+  $pano->save_params();
+
+  echo "</dl>\n";
+  echo '<p class="succes">Paramétrage terminé.</p>'."\n";
+  printf('<a href="%s">Retour au panorama</a></p>'."\n", $pano->get_url());
 
 
  } else {
diff --git a/html/form_param.html b/html/form_param.html
index 972994a..96b778e 100644
--- a/html/form_param.html
+++ b/html/form_param.html
@@ -1,7 +1,7 @@
 <div id="addParams">
   <label id="paramFormShow">Paramétrer le panorama</label>
 </div>
-     <form action="addParams.php?param_dir=%s&amp;param_panorama=%s" id="form_param" method="post">
+     <form action="addParams.php?param_panorama=%s" id="form_param" method="post">
   <fieldset id="adding"><legend id="paramFormHide">Paramétrage du panorama</legend>
     <label title="Au moins 4 caractères">Titre :
       <input type="text" pattern="^.{1,40}$" name="param_title" placeholder="%s"
diff --git a/panorama.php b/panorama.php
index bd15699..12a8973 100644
--- a/panorama.php
+++ b/panorama.php
@@ -142,7 +142,7 @@
      } elseif ($params == false ) {
      	$dir   = $_GET['dir'];
         $name  = $_GET['panorama'];
-        printf($form_param, $dir, $name, $name);
+        printf($form_param, $name, $name);
      }
      echo '<p id="info"></p>'."\n";
 
