119 $this->_controller = $instance;
121 $this->_tbl_data = self::$_tbl_point;
122 parent::__construct($id);
124 $this->_ctgs_id = array();
125 $this->_ctgs = array();
126 $query =
"SELECT ctg_id FROM ".self::$_tbl_point_point_ctg.
" WHERE point_id='".$this->
id.
"'";
127 $a = $this->_db->selectquery($query);
130 $this->_ctgs[] =
new gmapsPointCtg($b[
'ctg_id'], $this->_controller);
131 $this->_ctgs_id[] = $b[
'ctg_id'];
135 $this->_services_id = array();
136 $this->_services = array();
137 $query =
"SELECT service_id FROM ".self::$_tbl_point_service.
" WHERE point_id='".$this->
id.
"'";
138 $a = $this->_db->selectquery($query);
141 $this->_services[] =
new gmapsService($b[
'service_id'], $this->_controller);
142 $this->_services_id[] = $b[
'service_id'];
146 $this->_images = array();
147 $query =
"SELECT id FROM ".self::$_tbl_point_image.
" WHERE point_id='".$this->
id.
"'";
148 $a = $this->_db->selectquery($query);
151 $this->_images[] =
new gmapsImage($b[
'id'], $this->_controller);
155 $this->_videos = array();
156 $query =
"SELECT id FROM ".self::$_tbl_point_video.
" WHERE point_id='".$this->
id.
"'";
157 $a = $this->_db->selectquery($query);
160 $this->_videos[] =
new gmapsVideo($b[
'id'], $this->_controller);
164 $this->_events = array();
165 $query =
"SELECT id FROM ".self::$_tbl_point_event.
" WHERE point_id='".$this->
id.
"'";
166 $a = $this->_db->selectquery($query);
169 $this->_events[] =
new gmapsEvent($b[
'id'], $this->_controller);
173 $this->_attachments = array();
174 $query =
"SELECT id FROM ".self::$_tbl_point_attachment.
" WHERE point_id='".$this->
id.
"'";
175 $a = $this->_db->selectquery($query);
178 $this->_attachments[] =
new gmapsAttachment($b[
'id'], $this->_controller);
182 $this->_collections = array();
183 $query =
"SELECT id FROM ".self::$_tbl_point_collection.
" WHERE point_id='".$this->
id.
"'";
184 $a = $this->_db->selectquery($query);
187 $this->_collections[] =
new gmapsCollection($b[
'id'], $this->_controller);
201 if($this->_p[
'instance']!=$value && !in_array(
'instance', $this->_chgP)) $this->_chgP[] =
'instance';
202 $this->_p[
'instance'] = $value;
217 $db = db::instance();
220 $query =
"DELETE FROM ".self::$_tbl_point_point_ctg.
" WHERE point_id IN (SELECT id FROM ".self::$_tbl_point.
" WHERE instance='$instance')";
221 $res = $db->actionquery($query);
224 $query =
"DELETE FROM ".self::$_tbl_point_service.
" WHERE point_id IN (SELECT id FROM ".self::$_tbl_point.
" WHERE instance='$instance')";
225 $res = $res && $db->actionquery($query);
228 $query =
"DELETE FROM ".self::$_tbl_point_image.
" WHERE point_id IN (SELECT id FROM ".self::$_tbl_point.
" WHERE instance='$instance')";
229 $res = $res && $db->actionquery($query);
232 $query =
"DELETE FROM ".self::$_tbl_point_video.
" WHERE point_id IN (SELECT id FROM ".self::$_tbl_point.
" WHERE instance='$instance')";
233 $res = $res && $db->actionquery($query);
236 $query =
"DELETE FROM ".self::$_tbl_point_event.
" WHERE point_id IN (SELECT id FROM ".self::$_tbl_point.
" WHERE instance='$instance')";
237 $res = $res && $db->actionquery($query);
240 $query =
"DELETE FROM ".self::$_tbl_point_attachment.
" WHERE point_id IN (SELECT id FROM ".self::$_tbl_point.
" WHERE instance='$instance')";
241 $res = $res && $db->actionquery($query);
244 $query =
"DELETE FROM ".self::$_tbl_map_point.
" WHERE point_id IN (SELECT id FROM ".self::$_tbl_point.
" WHERE instance='$instance')";
245 $res = $res && $db->actionquery($query);
248 $query =
"DELETE FROM ".self::$_tbl_point.
" WHERE instance='$instance'";
249 $res = $res && $db->actionquery($query);
352 public static function get($instance, $opts=null) {
354 $where =
"instance='".$instance.
"'".((isset($opts[
'where']) && $opts[
'where']) ?
" AND ".$opts[
'where'] :
'');
355 $ctg = gOpt(
'ctg', $opts, null);
357 $where .=
" AND id IN (SELECT point_id FROM ".self::$_tbl_point_point_ctg.
" WHERE ctg_id='".$ctg.
"')";
359 $order = isset($opts[
'order']) ? $opts[
'order'] :
'label';
360 $limit = isset($opts[
'limit']) ?
"LIMIT ".$opts[
'limit'] :
'';
364 $db = db::instance();
365 $query =
"SELECT id FROM ".self::$_tbl_point.
" WHERE $where ORDER BY $order $limit";
366 $a = $db->selectquery($query);
387 $db = db::instance();
388 $query =
"SELECT point_id FROM ".self::$_tbl_point.
" WHERE marker='$marker_id'";
389 $a = $db->selectquery($query);
391 $res[] = $b[
'point_id'];
411 $db = db::instance();
412 $query =
"SELECT point_id FROM ".self::$_tbl_point_service.
" WHERE service='$service_id'";
413 $a = $db->selectquery($query);
415 $res[] = $b[
'point_id'];
434 $db = db::instance();
435 $query =
"SELECT point_id FROM ".self::$_tbl_point_point_ctg.
" WHERE ctg_id='$ctg_id'";
436 $a = $db->selectquery($query);
438 $res[] = $b[
'point_id'];
452 public function form($redirect) {
454 if(isset($_POST[
'submit'])) {
455 $gform =
new Form(
'form_point',
'post',
false, array(
'verifyToken'=>
true));
456 $gform->save(
'dataform');
457 $req_error = $gform->arequired();
460 $this->insert_date = date(
'Y-m-d H:i:s');
462 $this->last_edit_date = date(
'Y-m-d H:i:s');
463 $ctgs_id = cleanVar($_POST,
'ctg',
'array',
'');
464 $services_id = cleanVar($_POST,
'service',
'array',
'');
465 $this->label = cleanVar($_POST,
'label',
'string',
'');
466 $this->address = cleanVar($_POST,
'address',
'string',
'');
467 $this->cap = cleanVar($_POST,
'cap',
'string',
'');
468 $this->city = cleanVar($_POST,
'city',
'string',
'');
469 $this->nation = cleanVar($_POST,
'nation',
'int',
'');
470 $this->lat = cleanVar($_POST,
'lat',
'string',
'');
471 $this->lng = cleanVar($_POST,
'lng',
'string',
'');
472 $this->marker = cleanVar($_POST,
'marker',
'int',
'');
473 $this->description = cleanVarEditor($_POST,
'description',
'');
474 $this->information = cleanVarEditor($_POST,
'information',
'');
475 $this->phone = cleanVar($_POST,
'phone',
'string',
'');
476 $this->email = cleanVar($_POST,
'email',
'string',
'');
477 $this->web = cleanVar($_POST,
'web',
'string',
'');
478 $this->opening_hours = cleanVar($_POST,
'web',
'opening_hours',
'');
479 $this->updating = cleanVar($_POST,
'web',
'updating',
'');
480 $this->updating_email = cleanVar($_POST,
'web',
'updating_email',
'');
481 if($this->updating && !$this->updating_email) {
482 exit(error::errorMessage(array(
'error'=>_(
"Inserire anche una email per l'invio del codice di aggiornamento")), $_SERVER[
'QUERY_STRING']));
484 $this->updateDbData();
487 header(
"Location: ".$redirect);
491 if(!($_POST[
'lat'] && $_POST[
'lng'])) {
492 exit(error::errorMessage(array(
'error'=>_(
"Rappresentare il punto sulla mappa seguendo le istruzioni.")), $_SERVER[
'QUERY_STRING']));
494 exit(error::errorMessage(array(
'error'=>1), $_SERVER[
'QUERY_STRING']));
498 $registry = registry::instance();
499 $registry->addJs(
"http://maps.googleapis.com/maps/api/js?key=AIzaSyArAE-uBvCZTRaf_eaFn4umUdESmoUvoxM&sensor=true");
500 $registry->addJs(
"http://ajs.otto.to.it/sources/0.1/ajs/ajs.js");
503 $title = _(
"Modifica punto di interesse");
504 $submit = _(
"modifica");
507 $title = _(
"Nuovo punto di interesse");
508 $submit= _(
"inserisci");
510 $htmlsection =
new htmlSection(array(
'class'=>
'admin',
'headerTag'=>
'header',
'headerLabel'=>$title));
512 $gform =
new Form(
'form_point',
'post',
true, array(
'trnsl_table'=>$this->_tbl_data,
'trnsl_id'=>$this->
id));
513 $gform->load(
'dataform');
514 $required =
"label,lat,lng,ctg,cap,city,address,nation";
515 $buffer = $gform->form(
'',
false, $required, array(
'generateToken'=>
true));
516 $buffer .= $gform->hidden(
'id', $this->
id);
518 $buffer .= $gform->hidden(
'lat', $this->lat, array(
'id'=>
'lat'));
519 $buffer .= $gform->hidden(
'lng', $this->lng, array(
'id'=>
'lng'));
521 $buffer .= $gform->multipleCheckbox(
'ctg[]', $gform->retvar(
'ctg', $this->_ctgs_id),
gmapsPointCtg::getForSelect($this->instance), _(
"Categorie"), array(
'required'=>
true));
522 $buffer .= $gform->multipleCheckbox(
'service[]', $gform->retvar(
'service', $this->_services_id),
gmapsService::getForSelect($this->instance), _(
"Servizi"), array(
'required'=>
false));
523 $buffer .= $gform->cinput(
'label',
'text', $gform->retvar(
'label', htmlInput($this->label)), _(
"Etichetta"), array(
'required'=>
true,
'maxlength'=>200,
'size'=>40,
'trnsl'=>
true,
'field'=>
'label'));
524 $buffer .= $gform->cinput(
'address',
'text', $gform->retvar(
'address', htmlInput($this->address)), _(
"Indirizzo"), array(
'required'=>
true,
'maxlength'=>200,
'size'=>40,
'trnsl'=>
false));
525 $buffer .= $gform->cinput(
'cap',
'text', $gform->retvar(
'cap', htmlInput($this->cap)), _(
"Cap"), array(
'required'=>
true,
'maxlength'=>16,
'size'=>5,
'trnsl'=>
false));
526 $buffer .= $gform->cinput(
'city',
'text', $gform->retvar(
'city', htmlInput($this->city)), _(
"Città"), array(
'required'=>
true,
'maxlength'=>200,
'size'=>40,
'trnsl'=>
true,
'field'=>
'city'));
527 $query =
"SELECT id, ".$_SESSION[
'lngDft'].
" FROM nation ORDER BY ".$_SESSION[
'lngDft'].
" ASC";
528 $buffer .= $gform->cselect(
'nation', $gform->retvar(
'nation', htmlInput($this->nation)), $query, _(
"Nazione"), array(
"required"=>
true));
529 $buffer .= $gform->cselect(
'marker', $gform->retvar(
'marker', htmlInput($this->marker)),
gmapsMarker::getForSelect($this->instance), array(_(
"Marker"), _(
"lasciare vuoto se si intende visualizzare il marker di default di google")), array(
"required"=>
false));
530 $buffer .= $gform->cell($this->
formMap());
531 $buffer .= $gform->fcktextarea(
'description', $gform->retvar(
'description', htmlInputEditor($this->description)), _(
"Descrizione"), array(
'fck_toolbar'=>
"Default",
'trnsl'=>
true,
'field'=>
'description'));
532 $buffer .= $gform->fcktextarea(
'information', $gform->retvar(
'information', htmlInputEditor($this->information)), _(
"Informazioni"), array(
'fck_toolbar'=>
"Default",
'trnsl'=>
true,
'field'=>
'information'));
534 $buffer .= $gform->cinput(
'phone',
'text', $gform->retvar(
'phone', htmlInput($this->phone)), _(
"Telefono"), array(
'required'=>
false,
'maxlength'=>16,
'size'=>8,
'trnsl'=>
false));
535 $buffer .= $gform->cinput(
'email',
'text', $gform->retvar(
'email', htmlInput($this->email)), _(
"Email"), array(
'required'=>
false,
'maxlength'=>64,
'size'=>20,
'trnsl'=>
false));
536 $buffer .= $gform->cinput(
'web',
'text', $gform->retvar(
'web', htmlInput($this->web)), _(
"Web"), array(
'required'=>
false,
'maxlength'=>200,
'size'=>40,
'trnsl'=>
false));
537 $buffer .= $gform->ctextarea(
'opening_hours', $gform->retvar(
'opening_hours', htmlInput($this->opening_hours)), _(
"Orari di apertura"), array(
'required'=>
false,
'cols'=>60,
'rows'=>4,
'trnsl'=>
true,
'field'=>
'opening_hours'));
539 $buffer .= $gform->cradio(
'updating', $gform->retvar(
'updating', htmlInput($this->updating)), array(
'0'=>_(
'no'), 1=>_(
'si')), 0, _(
"Aggiornamento"), array(
'required'=>
true));
540 $buffer .= $gform->cinput(
'updating_email',
'text', $gform->retvar(
'updating_email', htmlInput($this->updating_email)), _(
"Email codice aggiornamento"), array(
'required'=>
false,
'maxlength'=>64,
'size'=>20,
'trnsl'=>
false));
541 $buffer .= $gform->cinput(
'submit',
'submit', $submit,
'', array(
'classField'=>
'submit'));
543 $buffer .= $gform->cform();
545 $htmlsection->content = $buffer;
547 return $htmlsection->render();
559 $buffer =
"<p>Per geolocalizzare il punto di interesse utilizzare lo strumento mappa qui sotto. Seguire la seguente procedura:</p>";
561 $buffer .=
"<li>"._(
"Premere il pulsante 'point'").
"</li>";
562 $buffer .=
"<li>"._(
"Cliccare nel punto desiderato sulla mappa per settare il punto. Una volta comparso il marker è possibile affinare la posizione spostandolo. Se si dispone di un indirizzo si può utilizzare il campo di testo, scrivere l'indirizzo e poi premere 'draw'. Anche in questo caso è poi possibile affinare la posizione in un secondo momento.").
"</li>";
563 $buffer .=
"<li>"._(
"Quando il marker si trova nella posizione desiderata permere il pulsante 'export map'.").
"</li>";
565 $buffer .=
"<div id=\"map_canvas\" style=\"width:100%; height: 300px;\"></div>";
567 $buffer .=
"<script>";
568 $buffer .=
"ajs.use(['ajs.maps.gmapdraw'], function() {
570 fillFields = function(data) {
571 $('lat').set('value', data.point[0].lat.round(10));
572 $('lng').set('value', data.point[0].lng.round(10));
573 alert('".jsVar(_(
"Il punto è stato settato correttamente, prosegui con la compilazione del form")).
"');
576 mymap = new ajs.maps.gmapdraw.map('map_canvas', {
578 export_map_callback: fillFields,
579 tools: {'point': { options: { max_items_allowed: 1 }}},
584 if($('lat').value && $('lng').value) {
585 var data = {point: [{lat: $('lat').value, lng:$('lng').value}]};
586 mymap.importMap(data);
587 mymap.gmap().setCenter(new google.maps.LatLng($('lat').value, $('lng').value));
592 $buffer .=
"</script>";
608 $buffer =
"var marker_".$this->id.
" = new google.maps.Marker({
609 position: new google.maps.LatLng(".$this->lat.
", ".$this->lng.
"),
612 $buffer .= $bounds.
".extend(new google.maps.LatLng(".$this->lat.
", ".$this->lng.
"));";
614 $marker =
new gmapsMarker($this->marker, $this->_controller);
615 $buffer .=
"marker_".$this->id.
".setIcon(new google.maps.MarkerImage('".$marker->iconUrl().
"'));";
616 if($marker->shadow) {
617 $buffer .=
"marker_".$this->id.
".setShadow(new google.maps.MarkerImage('".$marker->shadowUrl().
"'));";
635 public function jsObject($map_obj, $polylines, $polygons, $map_id) {
637 $db = db::instance();
638 $nation = $db->getFieldFromId(
'nation', $_SESSION[
'lng'],
'id', $this->nation);
641 $marker =
new gmapsMarker($this->marker, $this->_controller);
642 $marker_icon = $marker->iconUrl();
643 $marker_shadow = $marker->shadowUrl();
647 $marker_shadow = null;
650 $categories = array();
651 foreach($this->_ctgs as $ctg) {
652 $categories[] = jsVar($ctg->ml(
'name'));
656 foreach($this->_services as $s) {
657 $services[] = jsVar($s->ml(
'name'));
662 label: '".jsVar($this->ml(
'label')).
"',
663 categories: '".implode(
', ', $categories).
"',
664 services: '".implode(
', ', $services).
"',
665 description: '".jsVar(cutHtmlText(HtmlChars($this->ml(
'description')), 120,
'...',
false,
false,
false, null)).
"',
666 address: '".jsVar($this->ml(
'address')).
"',
667 cap: '".jsVar($this->cap).
"',
668 city: '".jsVar($this->ml(
'city')).
"',
669 nation: '".jsVar($nation).
"',
670 lat: '".jsVar($this->lat).
"',
671 lng: '".jsVar($this->lng).
"',
672 icon: ".($marker_icon ?
"'$marker_icon'" :
"null").
",
673 shadow: ".($marker_shadow ?
"'$marker_shadow'" :
"null").
"
676 $info_url = HOME_FILE.
'?pt['.$this->_controller->instanceName().
'-infowindow]&point_id='.$this->
id.
'&map_id='.$map_id;
678 return "new GmapPoint($fields, [".implode(
',', $this->_ctgs_id).
"], [".implode(
',', $polylines).
"], [".implode(
',', $polygons).
"], $map_obj, '$info_url');";
691 $db = db::instance();
692 $query =
"DELETE FROM ".self::$_tbl_point_point_ctg.
" WHERE point_id='".$this->
id.
"'";
693 $res = $db->actionquery($query);
696 foreach($ctgs_id as $ctg_id) {
697 $values[] =
"('".$this->id.
"', '".$ctg_id.
"')";
699 $query =
"INSERT INTO ".self::$_tbl_point_point_ctg.
" (point_id, ctg_id) VALUES ".implode(
',', $values).
";";
700 $res = $db->actionquery($query);
715 $db = db::instance();
716 $query =
"DELETE FROM ".self::$_tbl_point_service.
" WHERE point_id='".$this->
id.
"'";
717 $res = $db->actionquery($query);
720 foreach($services_id as $service_id) {
721 $values[] =
"('".$this->id.
"', '".$service_id.
"')";
723 $query =
"INSERT INTO ".self::$_tbl_point_service.
" (point_id, service_id) VALUES ".implode(
',', $values).
";";
724 $res = $db->actionquery($query);
737 public function delete() {
739 $db = db::instance();
742 $query =
"DELETE FROM ".self::$_tbl_point_point_ctg.
" WHERE point_id='".$this->
id.
"'";
743 $res = $db->actionquery($query);
746 $query =
"DELETE FROM ".self::$_tbl_map_point.
" WHERE point_id='".$this->
id.
"'";
747 $res = $db->actionquery($query);
750 $query =
"DELETE FROM ".self::$_tbl_point_service.
" WHERE point_id='".$this->
id.
"'";
751 $res = $db->actionquery($query);
754 foreach($this->_images as $image) {
759 foreach($this->_videos as $video) {
764 foreach($this->_events as $event) {
769 foreach($this->_attachments as $attachment) {
770 $attachment->delete();
774 foreach($this->_collections as $collection) {
775 $collection->delete();
778 return $this->deleteDbData();