Projet

Général

Profil

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

root / addParams.php @ fb66982c

1
<!DOCTYPE html>
2
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
3
<head>
4
   <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
5
   <link rel="stylesheet" media="screen" href="css/base.css" />
6
   <title>Positionnerment dun panoramique</title>
7
<?php
8
   // tableau de vérification de conformité
9
 $params = array('title' => array('name' => 'titre', 
10
                                  'pattern' => '^.{1,50}$',
11
                                  'required' => true),
12
                 'latitude' => array('name' => 'latitude', 
13
                                     'type' => 'numeric',
14
                                     'min' => -180,
15
                                     'max' => 180,
16
                                     'required' => true),
17
                 'longitude' => array('name' => 'longitude', 
18
                                     'type' => 'numeric',
19
                                      'min' => -180,
20
                                      'max' => 180,
21
                                      'required' => true),
22
                 'altitude' => array('name' => 'altitude', 
23
                                     'type' => 'numeric',
24
                                     'min' => -400,
25
                                     'required' => true),
26
                 'loop' => array('name' => 'image_loop', 
27
                                 'type' => 'boolean',
28
                                 'required' => false),
29
                 'dir' => array('required' => true),
30
                 'panorama' => array('required' => true));
31
$wrong = array();
32
$values = array();
33
// vérification de la conformité
34
foreach($params as $param => $check) {
35
  if (isset($_REQUEST['param_'.$param])) {
36
    $tst = $_REQUEST['param_'.$param];
37
    if ((isset($check['min']) || isset($check['max'])) && ! is_numeric($tst)) $wrong[$param] = "<em>$tst</em> ne correspond pas à une valeur numérique";
38
    else if (isset($check['min']) && $tst < $check['min']) $wrong[$param] = "<em>$tst</em> trop bas";
39
    else if (isset($check['max']) && $tst > $check['max']) $wrong[$param] = "<em>$tst</em> trop haut";
40
    else if (isset($check['pattern']) && preg_match('/'.preg_quote($check['pattern']).'/', $tst)) $wrong[$param] = "<em>$tst</em> non conforme";
41
    else $values[$param] = $tst;
42
  } else if (isset($check['required']) && $check['required']) {
43
    $wrong[$param] = '<em>$tst</em> est un paramètre manquant';
44
  }
45
}
46

    
47
if (isset($values['panorama'])) {
48
  $back_url = sprintf('panorama.php?panorama=%s', $values['panorama']);
49
  if (isset($values['dir'])) $back_url .= '&amp;dir='. $values['dir'];
50
} else {
51
  $back_url = '.';
52
}
53

    
54
if (count($wrong) == 0) {
55
  // On recherche le dossier correspondant au panorama en question
56
  $dir_file = "./".$values['dir']."/".$values['panorama'];
57
  $dir_open = opendir($dir_file);
58
  while (false !== ($file = readdir($dir_open))) {
59
    // Si on trouve bien des tuiles
60
    if (preg_match('/(.*)_[0-9]+_[0-9]+_[0-9]+\.jpg$/', $file, $reg)) {
61
      $prefix = $reg[1];
62
      $new_param_file = $prefix.".params";
63
      break;   // On sort à la première tuile trouvée
64
    }
65
  }
66
  closedir($dir_open);
67
  
68
  // On vérifie qu'on a bien créée un nouveau fichier .params et on écrit dedans.
69
  if(isset($new_param_file)){
70
    $fid = fopen($dir_file."/".$new_param_file,'a+');
71
    echo '<p>Les valeurs suivantes sont utilisées.</p>'."\n";
72
    echo "<dl>\n";
73
    foreach ($values as $k => $v) {
74
      echo "$k -$v<br/>\n";
75
      if (isset($params[$k]['name'])) {
76
        $nm = $params[$k]['name'];
77
        if (isset($params[$k]['type']) && $params[$k]['type'] == 'numeric') {
78
          $vf = $v;
79
        } else if (isset($params[$k]['type']) && $params[$k]['type'] == 'boolean') {
80
          $vf = $v ? "true" : "false"; 
81
        } else {
82
          $vf = "\"$v\"";
83
        }
84
        fputs($fid, "$nm = $vf\n");
85
        printf("<dt>%s</dt>\n<dd>%s</dd>\n", $nm, $vf);
86
      }
87
    }
88
    echo "</dl>\n";
89
    fclose($fid);
90
    echo '<p class="succes">Paramétrage terminé.</p>'."\n";
91
  } else {
92
    printf("<p class=\"error\">impossible d'écrire dans le fichier '%s'</p>\n", $dir_file);
93
  }
94
 } else {
95
  echo '<p class="error">Les valeurs suivantes sont incorrectes.</p>'."\n";
96
  echo "<dl>\n";
97
  foreach ($wrong as $k => $v) {
98
    printf("<dt>%s</dt>\n<dd>%s</dd>\n", $k, $v);
99
  }
100
  echo "</dl>\n";
101
}
102
printf('<a href="%s">Retour au panorama</a></p>'."\n", $back_url);
103

    
104
?>
105
</html>