Projet

Général

Profil

Paste
Télécharger (3,16 ko) Statistiques
| Branche: | Révision:

root / addParams.php @ 5119cb9e

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

    
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
<?php
12
   // tableau de vérification de conformité
13
 $params = array('title' => array('name' => 'titre',
14
                                  'pattern' => '^.{1,50}$',
15
                                  'required' => true),
16
                 'latitude' => array('name' => 'latitude',
17
                                     'type' => 'numeric',
18
                                     'min' => -180,
19
                                     'max' => 180,
20
                                     'required' => true),
21
                 'longitude' => array('name' => 'longitude',
22
                                     'type' => 'numeric',
23
                                      'min' => -180,
24
                                      'max' => 180,
25
                                      'required' => true),
26
                 'altitude' => array('name' => 'altitude',
27
                                     'type' => 'numeric',
28
                                     'min' => -400,
29
                                     'required' => true),
30
                 'loop' => array('name' => 'image_loop',
31
                                 'type' => 'boolean',
32
                                 'required' => false),
33
                 'dir' => array('required' => true),
34
                 'panorama' => array('required' => true));
35
$wrong = array();
36
$values = array();
37
// vérification de la conformité
38
foreach($params as $param => $check) {
39
  if (isset($_REQUEST['param_'.$param])) {
40
    $tst = $_REQUEST['param_'.$param];
41
    if ((isset($check['min']) || isset($check['max'])) && ! is_numeric($tst)) $wrong[$param] = "<em>$tst</em> ne correspond pas à une valeur numérique";
42
    else if (isset($check['min']) && $tst < $check['min']) $wrong[$param] = "<em>$tst</em> trop bas";
43
    else if (isset($check['max']) && $tst > $check['max']) $wrong[$param] = "<em>$tst</em> trop haut";
44
    else if (isset($check['pattern']) && preg_match('/'.preg_quote($check['pattern']).'/', $tst)) $wrong[$param] = "<em>$tst</em> non conforme";
45
    else $values[$param] = $tst;
46
  } else if (isset($check['required']) && $check['required']) {
47
    $wrong[$param] = '<em>$tst</em> est un paramètre manquant';
48
  }
49
}
50

    
51
if (isset($values['panorama'])) {
52
  $back_url = sprintf('panorama.php?panorama=%s', $values['panorama']);
53
  if (isset($values['dir'])) $back_url .= '&amp;dir='. $values['dir'];
54
} else {
55
  $back_url = '.';
56
}
57

    
58
if (count($wrong) == 0) {
59
        $pano = site_point::get($values['panorama']);
60

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

    
80
        echo "</dl>\n";
81
        echo '<p class="succes">Paramétrage terminé.</p>'."\n";
82
 } else {
83
        echo '<p class="error">Les valeurs suivantes sont incorrectes.</p>'."\n";
84
        echo "<dl>\n";
85
        foreach ($wrong as $k => $v) {
86
                printf("<dt>%s</dt>\n<dd>%s</dd>\n", $k, $v);
87
        }
88
        echo "</dl>\n";
89
}
90
printf('<a href="%s">Retour au panorama</a></p>'."\n", $back_url);
91

    
92
?>
93
</html>