77 $this->_controller = $instance;
79 $this->_tbl_data = self::$_tbl_map;
80 parent::__construct($id);
81 $this->_points = array();
82 $this->_points_id = array();
83 $this->_polylines = array();
84 $this->_polylines_id = array();
85 $this->_polygons = array();
86 $this->_polygons_id = array();
87 $query =
"SELECT point_id FROM ".self::$_tbl_map_point.
" WHERE map_id='".$this->
id.
"'";
88 $a = $this->_db->selectquery($query);
91 $this->_points[] =
new gmapsPoint($b[
'point_id'], $this->_controller);
92 $this->_points_id[] = $b[
'point_id'];
95 $query =
"SELECT polyline_id FROM ".self::$_tbl_map_polyline.
" WHERE map_id='".$this->
id.
"'";
96 $a = $this->_db->selectquery($query);
99 $this->_polylines[] =
new gmapsPolyline($b[
'polyline_id'], $this->_controller);
100 $this->_polylines_id[] = $b[
'polyline_id'];
103 $query =
"SELECT polygon_id FROM ".self::$_tbl_map_polygon.
" WHERE map_id='".$this->
id.
"'";
104 $a = $this->_db->selectquery($query);
107 $this->_polygons[] =
new gmapsPolygon($b[
'polygon_id'], $this->_controller);
108 $this->_polygons_id[] = $b[
'polygon_id'];
122 if($this->_p[
'instance']!=$value && !in_array(
'instance', $this->_chgP)) $this->_chgP[] =
'instance';
123 $this->_p[
'instance'] = $value;
138 $db = db::instance();
139 $query =
"DELETE FROM ".self::$_tbl_map.
" WHERE instance='$instance'";
140 $res = $db->actionquery($query);
228 if(!is_array($point_ids)) $points = array($point_ids);
231 foreach($point_ids as $pid) {
232 $values[] =
"('".$this->id.
"', '".$pid.
"')";
235 $db = db::instance();
236 $query =
"INSERT INTO ".self::$_tbl_map_point.
" (map_id, point_id) VALUES ".implode(
',', $values).
";";
238 return $db->actionquery($query);
250 if(!is_array($polyline_ids)) $points = array($polyline_ids);
253 foreach($polyline_ids as $pid) {
254 $values[] =
"('".$this->id.
"', '".$pid.
"')";
257 $db = db::instance();
258 $query =
"INSERT INTO ".self::$_tbl_map_polyline.
" (map_id, polyline_id) VALUES ".implode(
',', $values).
";";
260 return $db->actionquery($query);
272 if(!is_array($polygon_ids)) $points = array($polygon_ids);
275 foreach($polygon_ids as $pid) {
276 $values[] =
"('".$this->id.
"', '".$pid.
"')";
279 $db = db::instance();
280 $query =
"INSERT INTO ".self::$_tbl_map_polygon.
" (map_id, polygon_id) VALUES ".implode(
',', $values).
";";
282 return $db->actionquery($query);
295 if(!is_array($point_ids)) $points = array($point_ids);
298 foreach($point_ids as $pid) {
299 $values[] =
"point_id='".$pid.
"'";
302 $db = db::instance();
303 $query =
"DELETE FROM ".self::$_tbl_map_point.
" WHERE map_id='".$this->
id.
"' AND (".implode(
" OR ", $values).
")";
305 return $db->actionquery($query);
317 if(!is_array($polyline_ids)) $points = array($polyline_ids);
320 foreach($polyline_ids as $pid) {
321 $values[] =
"polyline_id='".$pid.
"'";
324 $db = db::instance();
325 $query =
"DELETE FROM ".self::$_tbl_map_polyline.
" WHERE map_id='".$this->
id.
"' AND (".implode(
" OR ", $values).
")";
327 return $db->actionquery($query);
339 if(!is_array($polygon_ids)) $points = array($polygon_ids);
342 foreach($polygon_ids as $pid) {
343 $values[] =
"polygon_id='".$pid.
"'";
346 $db = db::instance();
347 $query =
"DELETE FROM ".self::$_tbl_map_polygon.
" WHERE map_id='".$this->
id.
"' AND (".implode(
" OR ", $values).
")";
349 return $db->actionquery($query);
365 public static function get($instance, $opts=null) {
367 $where =
"instance='".$instance.
"'".((isset($opts[
'where']) && $opts[
'where']) ?
" AND ".$opts[
'where'] :
'');
368 $order = isset($opts[
'order']) ? $opts[
'order'] :
'name';
369 $limit = isset($opts[
'limit']) ?
"LIMIT ".$opts[
'limit'] :
'';
373 $db = db::instance();
374 $query =
"SELECT id FROM ".self::$_tbl_map.
" WHERE $where ORDER BY $order $limit";
375 $a = $db->selectquery($query);
391 public function form($redirect) {
393 if(isset($_POST[
'submit'])) {
394 $gform =
new Form(
'form_map',
'post',
false, array(
'verifyToken'=>
true));
395 $gform->save(
'dataform');
396 $req_error = $gform->arequired();
398 $this->name = cleanVar($_POST,
'name',
'string',
'');
399 $this->description = cleanVarEditor($_POST,
'description',
'');
400 $this->width = cleanVar($_POST,
'width',
'string',
'');
401 $this->height = cleanVar($_POST,
'height',
'string',
'');
402 $this->updateDbData();
403 header(
"Location: ".$redirect);
407 exit(error::errorMessage(array(
'error'=>1), $_SERVER[
'QUERY_STRING']));
412 $title = _(
"Modifica mappa");
413 $submit = _(
"modifica");
416 $title = _(
"Nuova mappa");
417 $submit= _(
"inserisci");
419 $htmlsection =
new htmlSection(array(
'class'=>
'admin',
'headerTag'=>
'header',
'headerLabel'=>$title));
421 $gform =
new Form(
'form_map',
'post',
true, array(
'trnsl_table'=>$this->_tbl_data,
'trnsl_id'=>$this->
id));
422 $gform->load(
'dataform');
423 $required =
"name,width,height";
424 $buffer = $gform->form(
'',
false, $required, array(
'generateToken'=>
true));
425 $buffer .= $gform->hidden(
'id', $this->
id);
427 $buffer .= $gform->cinput(
'name',
'text', $gform->retvar(
'name', htmlInput($this->name)), _(
"Nome"), array(
'required'=>
true,
'maxlength'=>200,
'size'=>40,
'trnsl'=>
true,
'field'=>
'name'));
428 $buffer .= $gform->fcktextarea(
'description', $gform->retvar(
'description', htmlInputEditor($this->description)), _(
"Descrizione"), array(
'fck_toolbar'=>
"Default",
'trnsl'=>
true,
'field'=>
'description'));
429 $buffer .= $gform->cinput(
'width',
'text', $gform->retvar(
'width', htmlInput($this->width)), array(_(
"Larghezza"), _(
"in px o percentuale<br />es: 500px, 98%")), array(
'required'=>
true,
'maxlength'=>32,
'size'=>6));
430 $buffer .= $gform->cinput(
'height',
'text', $gform->retvar(
'height', htmlInput($this->height)), array(_(
"Altezza"), _(
"in px o percentuale<br />es: 500px, 98%")), array(
'required'=>
true,
'maxlength'=>32,
'size'=>6));
431 $buffer .= $gform->cinput(
'submit',
'submit', $submit,
'', array(
'classField'=>
'submit'));
433 $buffer .= $gform->cform();
435 $htmlsection->content = $buffer;
437 return $htmlsection->render();
448 public function delete() {
450 $db = db::instance();
453 $query =
"DELETE FROM ".self::$_tbl_map_point.
" WHERE map_id='".$this->
id.
"'";
454 $res = $db->actionquery($query);
457 $query =
"DELETE FROM ".self::$_tbl_map_polyline.
" WHERE map_id='".$this->
id.
"'";
458 $res = $db->actionquery($query);
460 return $this->deleteDbData();