Gino Gmaps  1.0.1
Modulo di gestione di mappe interattive per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.gmapsMarker.php
Vai alla documentazione di questo file.
1 <?php
31 class gmapsMarker extends propertyObject {
32 
33  private static $_tbl_marker = 'gmaps_marker';
34 
36 
45  function __construct($id, $instance) {
46 
47  $this->_controller = $instance;
48  $this->_tbl_data = self::$_tbl_marker;
49  parent::__construct($id);
50 
51  $this->_extension_media = array('png');
52  $this->_data_www = CONTENT_WWW.'/gmaps/'.$this->_controller->instanceName().'/marker';
53  $this->_data_dir = CONTENT_DIR.OS.'gmaps'.OS.$this->_controller->instanceName().OS.'marker';
54  }
55 
63  public function setInstance($value) {
64 
65  if($this->_p['instance']!=$value && !in_array('instance', $this->_chgP)) $this->_chgP[] = 'instance';
66  $this->_p['instance'] = $value;
67  return true;
68 
69  }
70 
79  public static function deleteInstance($instance) {
80 
81  $db = db::instance();
82  $query = "DELETE FROM ".self::$_tbl_marker." WHERE instance='$instance'";
83  $res = $db->actionquery($query);
84 
85  return $res;
86 
87  }
88 
101  public static function get($instance, $opts=null) {
102 
103  $where = "instance='".$instance."'".(isset($opts['where']) ? " AND ".$opts['where'] : '');
104  $order = isset($opts['order']) ? $opts['order'] : 'label';
105  $limit = isset($opts['limit']) ? "LIMIT ".$opts['limit'] : '';
106 
107  $res = array();
108 
109  $db = db::instance();
110  $query = "SELECT id FROM ".self::$_tbl_marker." WHERE $where ORDER BY $order $limit";
111  $a = $db->selectquery($query);
112  foreach($a as $b) {
113  $res[] = $b['id'];
114  }
115 
116  return $res;
117 
118  }
119 
131  public static function getForSelect($instance, $opts=null) {
132 
133  $where = "instance='".$instance."'".(isset($opts['where']) ? " AND ".$opts['where'] : '');
134  $order = isset($opts['order']) ? $opts['order'] : 'label';
135 
136  $res = array();
137 
138  $db = db::instance();
139  $query = "SELECT id, label FROM ".self::$_tbl_marker." WHERE $where ORDER BY $order";
140  $a = $db->selectquery($query);
141  foreach($a as $b) {
142  $res[$b['id']] = htmlChars($b['label']);
143  }
144 
145  return $res;
146 
147  }
148 
156  public function form($redirect) {
157 
158  if(isset($_POST['submit'])) {
159  $gform = new Form('form_marker', 'post', false, array('verifyToken'=>true));
160  $gform->save('dataform');
161  $req_error = $gform->arequired();
162  if(!$req_error) {
163  $this->label = cleanVar($_POST, 'label', 'string', '');
164  $this->description = cleanVar($_POST, 'description', 'string', '');
165  $this->updateDbData();
166 
167  $old_icon = cleanVar($_POST, 'old_icon', 'string', '');
168  $old_shadow = cleanVar($_POST, 'old_shadow', 'string', '');
169 
170  $res = $gform->manageFile('icon', $old_icon, false, $this->_extension_media, $this->_data_dir.OS, preg_replace("#action=insert#", 'action=modify&id='.$this->id, $_SERVER['QUERY_STRING']), $this->_tbl_data, 'icon', 'id', $this->id, array());
171  $res = $gform->manageFile('shadow', $old_shadow, false, $this->_extension_media, $this->_data_dir.OS, preg_replace("#action=insert#", 'action=modify&id='.$this->id, $_SERVER['QUERY_STRING']), $this->_tbl_data, 'shadow', 'id', $this->id, array());
172 
173  header("Location: ".$redirect);
174  exit();
175  }
176  else {
177  error::errorMessage(array('error'=>1), $_SERVER['QUERY_STRING']);
178  exit();
179  }
180  }
181 
182  if($this->id) {
183  $title = _("Modifica marker");
184  $submit = _("modifica");
185  }
186  else {
187  $title = _("Nuovo marker");
188  $submit= _("inserisci");
189  }
190  $htmlsection = new htmlSection(array('class'=>'admin', 'headerTag'=>'header', 'headerLabel'=>$title));
191 
192  $gform = new Form('form_marker', 'post', true, array('trnsl_table'=>$this->_tbl_data, 'trnsl_id'=>$this->id));
193  $gform->load('dataform');
194  $buffer = $gform->form('', true, 'label', array('generateToken'=>true));
195  $buffer .= $gform->hidden('id', $this->id);
196 
197  $buffer .= $gform->cinput('label', 'text', $gform->retvar('label', htmlInput($this->label)), _("Etichetta"), array('required'=>true, 'maxlength'=>200, 'size'=>40, 'trnsl'=>true, 'field'=>'label'));
198 
199  $buffer .= $gform->cfile('icon', $this->icon, _("Icona"), array("extensions"=>$this->_extension_media, "del_check"=>true, "preview"=>true, "previewSrc"=>$this->_data_www.'/'.$this->icon));
200  $buffer .= $gform->cfile('shadow', $this->shadow, _("Ombra"), array("extensions"=>$this->_extension_media, "del_check"=>true, "preview"=>true, "previewSrc"=>$this->_data_www.'/'.$this->shadow));
201  $buffer .= $gform->cinput('submit', 'submit', $submit, '', array('classField'=>'submit'));
202 
203  $buffer .= $gform->cform();
204 
205  $htmlsection->content = $buffer;
206 
207  return $htmlsection->render();
208  }
209 
216  public function iconUrl() {
217 
218  return $this->icon ? $this->_data_www.'/'.$this->icon : null;
219 
220  }
221 
228  public function shadowUrl() {
229 
230  return $this->shadow ? $this->_data_www.'/'.$this->shadow : null;
231 
232  }
233 
241  public function delete() {
242 
243  $points = gmapsPoint::getByMarker($this->id);
244 
245  if(count($points)) {
246  return 'points';
247  }
248  else {
249  if($this->icon) {
250  @unlink($this->_data_dir.OS.$this->icon);
251  }
252  if($this->shadow) {
253  @unlink($this->_data_dir.OS.$this->shadow);
254  }
255 
256  return $this->deleteDbData();
257  }
258 
259  }
260 
261 }
262 
263 ?>