Projet

Général

Profil

Révision ffa856dc

Ajouté par Jocelyn Delande il y a presque 11 ans

added params generation to upload

Voir les différences:

class/FormValidator.class.php
112 112
	  }
113 113
  }
114 114
);
115
// Intended to validate checkbox which takes NULL for unchecked
116
FormValidator::register(
117
  'boolean',
118
  function ($v) {
119
	  if ($v == NULL) {
120
		  return false;
121
	  } else {
122
		  return true;
123
	  }
124
  }
125
);
115 126

  
116 127
?>
class/site_point.class.php
1 1
<?php
2 2
require_once(dirname(__FILE__).'/../constants.inc.php');
3 3
require_once(dirname(__FILE__).'/utils.class.php');
4

  
4
utils::init();
5 5
//
6 6
class PanoramaFormatException extends Exception {
7 7
	/** If the files organization is not correct for a panorama, we can't let it go...
......
206 206
	  return new site_point($pano_dir);
207 207
  }
208 208

  
209
  public static function create($filepath) {
210
	  /** creates a new panorama, given its name, from an uploaded file.
211
	   */
212
	  $name = utils::strip_extension(basename($filepath));
213
	  $pano_dir = PANORAMA_PATH.'/'.$name;
214
	  $pano = new site_point($pano_dir);
215
	  if (!mkdir($pano->tiles_path())) {
216
		  return false;
217
	  } else {
218
		  return $pano;
219
	  }
220
  }
209 221

  
210 222
  public function to_geoJSON() {
211 223
	  $prm = $this->get_params();
......
229 241

  
230 242
  public static function get_all($only_with_params=false) {
231 243
	  /**
232
	   * @param $only_with_params : filters out the panoramas which are not parametrized
244
	   * @param $only_with_params : filters out the panoramas which
245
	   *        are not parametrized
233 246
	   */
234 247
	  $panos = array_diff(scandir(PANORAMA_PATH), array('..', '.'));
235 248
	  $pano_instances = array();
uploadReceive.php
1 1
<?php
2 2
 
3 3
require_once('class/FormValidator.class.php');
4
require_once('class/site_point.class.php');
4 5
require_once('constants.inc.php');
5 6

  
6 7
class UploadReceiveError extends Exception {}
......
23 24
    if(!empty($file)) {
24 25
      if(isset($file) && UPLOAD_ERR_OK === $file_err) {
25 26
	      move_uploaded_file($file_tmp, $file_finalpath);
26
        return sprintf("transfert de %s réalisé",  $file);
27
        return $file_finalpath;
27 28
      } else {
28 29
        throw new UploadReceiveError(
29 30
          'Une erreur interne a empêché l\'envoi de l\'image :'. $file_err);
......
35 36
  }
36 37
}
37 38

  
39
function existant_and_set($list, $keys) {
40
  /** For HTTP data : keys of $keys are set within $list and they are not empty
41
  * or false nor empty
42
  */
43
  foreach($keys as $key) {
44
    if (!isset($list[$key]) || !$list[$key]) {
45
      return false;
46
    }
47
  }
48
  return true;
49
}
50

  
38 51
////////////////////// main //////////////////////////////////////////
39 52

  
40
$fields_spec = array('lat'         => array('required', 'numeric', 'positive'),
53
$fields_spec = array('lat'         => array('numeric', 'positive'),
41 54
                     'lon'         => array('numeric', 'positive'),
42
                     'alt'  => array('numeric'),
55
                     'alt'  => array('numeric', 'positive'),
56
                     'loop'  => array('boolean'),
43 57
);
44 58

  
45 59
$validator = new FormValidator($fields_spec);
46
$upload_success = false;
47 60

  
48 61
////// STEP 1 : UPLOAD ////////
49 62

  
63
$upload_success = false;
64
$uploaded_filepath = '';
65

  
50 66
if ($validator->validate($_REQUEST)) {
51 67
  try {
52
    $message = handle_upload();
68
    $uploaded_filepath = handle_upload();
53 69
    $upload_success = true;
70
    $message = sprintf("transfert de %s réalisé", basename($uploaded_filepath));
54 71
  } catch (UploadReceiveError $e) {
55 72
    $message = $e->getMessage();
56 73
  }
......
63 80
$params_success = false;
64 81

  
65 82
if ($upload_success) {
66
  //pass
83
  $vals = $validator->sane_values();
84
  // There is no point setting a part of the parameters only ; check that all
85
  // are present.  
86
  if (existant_and_set($vals, array('lat', 'alt', 'lon'))) {
87
    try {
88
      $panorama = site_point::create($uploaded_filepath);
89
      $panorama->set_param('titre', 'Sans nom 1');//FIXME
90
      $panorama->set_param('latitude',  $vals['lat']);
91
      $panorama->set_param('longitude', $vals['lon']);
92
      $panorama->set_param('altitude',  $vals['alt']);
93
      $panorama->set_param('image_loop', $vals['loop']);
94
      $panorama->save_params();
95
      $params_success = true;
96
    } catch (Exception $e) {
97
      $message = 'erreur à la création du panorama : '.$e->getMessage();
98
    }
99
  }
67 100
}
68 101

  
69 102

  

Formats disponibles : Unified diff