Gino Gmaps  1.0.1
Modulo di gestione di mappe interattive per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.gmapsService.php
Vai alla documentazione di questo file.
1 <?php
31 class gmapsService extends propertyObject {
32 
33  private static $_tbl_service = 'gmaps_service';
34 
36 
40  private $_img_width = 200;
41 
45  private $_thumb_width = 80;
46 
55  function __construct($id, $instance) {
56 
57  $this->_controller = $instance;
58  $this->_tbl_data = self::$_tbl_service;
59  parent::__construct($id);
60 
61  $this->_extension_media = array('jpg', 'jpeg', 'png');
62  $this->_prefix_img = 'img_';
63  $this->_prefix_thumb = 'thumb_';
64  $this->_data_www = CONTENT_WWW.'/gmaps/'.$this->_controller->instanceName().'/service';
65  $this->_data_dir = CONTENT_DIR.OS.'gmaps'.OS.$this->_controller->instanceName().OS.'service';
66 
67  $this->_model_label = $this->id ? $this->name : '';
68  }
69 
77  public function setInstance($value) {
78 
79  if($this->_p['instance']!=$value && !in_array('instance', $this->_chgP)) $this->_chgP[] = 'instance';
80  $this->_p['instance'] = $value;
81  return true;
82 
83  }
84 
93  public static function deleteInstance($instance) {
94 
95  $db = db::instance();
96  $query = "DELETE FROM ".self::$_tbl_service." WHERE instance='$instance'";
97  $res = $db->actionquery($query);
98 
99  return $res;
100 
101  }
102 
115  public static function get($instance, $opts=null) {
116 
117  $where = "instance='".$instance."'".(isset($opts['where']) ? " AND ".$opts['where'] : '');
118  $order = isset($opts['order']) ? $opts['order'] : 'name';
119  $limit = isset($opts['limit']) ? "LIMIT ".$opts['limit'] : '';
120 
121  $res = array();
122 
123  $db = db::instance();
124  $query = "SELECT id FROM ".self::$_tbl_service." WHERE $where ORDER BY $order $limit";
125  $a = $db->selectquery($query);
126  foreach($a as $b) {
127  $res[] = $b['id'];
128  }
129 
130  return $res;
131 
132  }
133 
145  public static function getForSelect($instance, $opts=null) {
146 
147  $where = "instance='".$instance."'".(isset($opts['where']) ? " AND ".$opts['where'] : '');
148  $order = isset($opts['order']) ? $opts['order'] : 'name';
149 
150  $res = array();
151 
152  $db = db::instance();
153  $query = "SELECT id, name FROM ".self::$_tbl_service." WHERE $where ORDER BY $order";
154  $a = $db->selectquery($query);
155  foreach($a as $b) {
156  $res[$b['id']] = htmlChars($b['name']);
157  }
158 
159  return $res;
160 
161  }
162 
170  public function form($redirect) {
171 
172  if(isset($_POST['submit'])) {
173  $gform = new Form('form_service', 'post', false, array('verifyToken'=>true));
174  $gform->save('dataform');
175  $req_error = $gform->arequired();
176  if(!$req_error) {
177  $this->name = cleanVar($_POST, 'name', 'string', '');
178  $this->description = cleanVar($_POST, 'description', '');
179  $this->updateDbData();
180 
181  $old_icon = cleanVar($_POST, 'old_icon', 'string', '');
182 
183  $res = $gform->manageFile('icon', $old_icon, true, $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('prefix_file'=>$this->_prefix_img, 'prefix_thumb'=>$this->_prefix_thumb, 'width'=>$this->_img_width, 'thumb_width'=>$this->_thumb_width));
184 
185  header("Location: ".$redirect);
186  exit();
187  }
188  else {
189  error::errorMessage(array('error'=>1), $_SERVER['QUERY_STRING']);
190  exit();
191  }
192  }
193 
194  if($this->id) {
195  $title = _("Modifica servizio");
196  $submit = _("modifica");
197  }
198  else {
199  $title = _("Nuovo servizio");
200  $submit= _("inserisci");
201  }
202  $htmlsection = new htmlSection(array('class'=>'admin', 'headerTag'=>'header', 'headerLabel'=>$title));
203 
204  $gform = new Form('form_service', 'post', true, array('trnsl_table'=>$this->_tbl_data, 'trnsl_id'=>$this->id));
205  $gform->load('dataform');
206  $buffer = $gform->form('', true, 'name', array('generateToken'=>true));
207  $buffer .= $gform->hidden('id', $this->id);
208 
209  $buffer .= $gform->cinput('name', 'text', $gform->retvar('name', htmlInput($this->name)), _("Nome"), array('required'=>true, 'maxlength'=>200, 'size'=>40, 'trnsl'=>true, 'field'=>'name'));
210  $buffer .= $gform->ctextarea('description', $gform->retvar('description', htmlInput($this->description)), _("Descrizione"), array('cols'=>40, 'rows'=>4, 'trnsl'=>true, 'field'=>'description'));
211 
212  $buffer .= $gform->cfile('icon', $this->icon, _("Icona"), array("extensions"=>$this->_extension_media, "del_check"=>true, "preview"=>true, "previewSrc"=>$this->_data_www.'/'.$this->_prefix_img.$this->icon));
213  $buffer .= $gform->cinput('submit', 'submit', $submit, '', array('classField'=>'submit'));
214 
215  $buffer .= $gform->cform();
216 
217  $htmlsection->content = $buffer;
218 
219  return $htmlsection->render();
220  }
221 
229  public function delete() {
230 
231  $points = gmapsPoint::getByService($this->id);
232 
233  if(count($points)) {
234  return 'points';
235  }
236  else {
237  if($this->icon) {
238  @unlink($this->_data_dir.OS.$this->_prefix_img.$this->icon);
239  @unlink($this->_data_dir.OS.$this->_prefix_thumb.$this->icon);
240  }
241 
242  return $this->deleteDbData();
243  }
244 
245  }
246 
247 }
248 
249 ?>