Projet

Général

Profil

Révision 3d3b31ae

Ajouté par Jocelyn Delande il y a plus de 10 ans

Moved some treatements to functions for better understanding.

Voir les différences:

addParams.php
1 1
<?php
2 2
require_once('class/site_point.class.php');
3
?>
4 3

  
5
<!DOCTYPE html>
6
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
7
<head>
8
   <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
9
   <link rel="stylesheet" media="screen" href="css/base.css" />
10
   <title>Positionnerment dun panoramique</title>
11

  
12
<?php
13 4
   // tableau de vérification de conformité
14
 $params = array('title' => array('name' => 'titre',
5
$params = array('title' => array('name' => 'titre',
15 6
				  'pattern' => '^.{1,50}$',
16 7
				  'required' => true),
17 8
		 'latitude' => array('name' => 'latitude',
......
31 22
		 'loop' => array('name' => 'image_loop',
32 23
				 'type' => 'boolean',
33 24
				 'required' => false),
34
		 'dir' => array('required' => true),
35 25
		 'panorama' => array('required' => true));
26

  
27

  
28
class FormValidationError extends Exception {}
29

  
30
function ini_value($k, $v, $params_format) {
31
  /** According to the $params global reference table, format the value for
32
  storing in an ini file and returns it.
33
  */
34
  if (isset($params_format[$k]['type']) && $params_format[$k]['type'] == 'numeric') {
35
	$ini_val = $v;
36
  } else if (isset($params_format[$k]['type']) && $params_format[$k]['type'] == 'boolean') {
37
	$ini_val = $v ? "true" : "false";
38
  } else { //string
39
	$ini_val = "\"$v\"";
40
  }
41
  return $ini_val;
42
}
43

  
44
function is_ini_key($k, $params_format) {
45
  /** Do we need to store that information in the params ini file ?
46
  */
47
  return isset($params_format[$k]['name']);
48
}
49

  
50
function ini_key($k, $params_format) {
51
  /** For a given form key, returns the key for ini file
52
  */
53
  if (isset($params_format[$k]['name'])) {
54
    return $params_format[$k]['name'];
55
  } else {
56
    throw (new FormValidationError('"'.$k.'" is an unknown key.'));
57
  }
58
}
59

  
36 60
$wrong = array();
37 61
$values = array();
38 62
// vérification de la conformité
......
48 72
    $wrong[$param] = '<em>$tst</em> est un paramètre manquant';
49 73
  }
50 74
}
75
?>
76
<!DOCTYPE html>
77
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
78
<head>
79
   <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
80
   <link rel="stylesheet" media="screen" href="css/base.css" />
81
   <title>Positionnerment dun panoramique</title>
51 82

  
52

  
83
<?php
53 84
if (count($wrong) == 0) {
54
	$pano = site_point::get($values['panorama']);
85
  $pano = site_point::get($values['panorama']);
55 86

  
56 87
  // On vérifie qu'on a bien créée un nouveau fichier .params et on écrit dedans.
57
	echo '<p>Les valeurs suivantes sont utilisées.</p>'."\n";
58
	echo "<dl>\n";
59
	foreach ($values as $k => $v) {
60
		if (isset($params[$k]['name'])) {
61
			$nm = $params[$k]['name'];
62
			if (isset($params[$k]['type']) && $params[$k]['type'] == 'numeric') {
63
				$vf = $v;
64
			} else if (isset($params[$k]['type']) && $params[$k]['type'] == 'boolean') {
65
				$vf = $v ? "true" : "false";
66
			} else {
67
				$vf = "\"$v\"";
68
			}
69
			$pano->set_param($nm, $vf);
70
			printf("<dt>%s</dt>\n<dd>%s</dd>\n", $nm, $vf);
71
		}
72
	}
73
	$pano->save_params();
88
  echo '<p>Les valeurs suivantes sont utilisées.</p>'."\n";
89
  echo "<dl>\n";
74 90

  
75
	echo "</dl>\n";
76
	echo '<p class="succes">Paramétrage terminé.</p>'."\n";
77
  printf('<a href="%s">Retour au panorama</a></p>'."\n", $panorama->get_url());
91
  foreach ($values as $k => $v) {
92
    if (is_ini_key($k, $params)) {
93
      $storable_key = ini_key($k, $params);
94
      $storable_val = ini_value($k, $v, $params);
95

  
96
	  $pano->set_param($storable_key, $storable_val);
97
	  printf("<dt>%s</dt>\n<dd>%s</dd>\n", $storable_key, $storable_val);
98
    }
99
  }
100
  $pano->save_params();
101

  
102
  echo "</dl>\n";
103
  echo '<p class="succes">Paramétrage terminé.</p>'."\n";
104
  printf('<a href="%s">Retour au panorama</a></p>'."\n", $pano->get_url());
78 105

  
79 106

  
80 107
 } else {
html/form_param.html
1 1
<div id="addParams">
2 2
  <label id="paramFormShow">Paramétrer le panorama</label>
3 3
</div>
4
     <form action="addParams.php?param_dir=%s&amp;param_panorama=%s" id="form_param" method="post">
4
     <form action="addParams.php?param_panorama=%s" id="form_param" method="post">
5 5
  <fieldset id="adding"><legend id="paramFormHide">Paramétrage du panorama</legend>
6 6
    <label title="Au moins 4 caractères">Titre :
7 7
      <input type="text" pattern="^.{1,40}$" name="param_title" placeholder="%s"
panorama.php
142 142
     } elseif ($params == false ) {
143 143
     	$dir   = $_GET['dir'];
144 144
        $name  = $_GET['panorama'];
145
        printf($form_param, $dir, $name, $name);
145
        printf($form_param, $name, $name);
146 146
     }
147 147
     echo '<p id="info"></p>'."\n";
148 148

  

Formats disponibles : Unified diff