70 $this->_controller = $instance;
71 $this->_tbl_data = self::$_tbl_polygon;
72 parent::__construct($id);
74 $this->_points = array();
75 $this->_points_id = array();
76 $query =
"SELECT point_id FROM ".self::$_tbl_polygon_point.
" WHERE polygon_id='".$this->
id.
"'";
77 $a = $this->_db->selectquery($query);
80 $this->_points[] =
new gmapsPoint($b[
'point_id'], $this->_controller);
81 $this->_points_id[] = $b[
'point_id'];
85 $this->_ctgs_id = array();
86 $this->_ctgs = array();
87 $query =
"SELECT ctg_id FROM ".self::$_tbl_polygon_polygon_ctg.
" WHERE polygon_id='".$this->
id.
"'";
88 $a = $this->_db->selectquery($query);
92 $this->_ctgs_id[] = $b[
'ctg_id'];
106 if($this->_p[
'instance']!=$value && !in_array(
'instance', $this->_chgP)) $this->_chgP[] =
'instance';
107 $this->_p[
'instance'] = $value;
122 $db = db::instance();
125 $query =
"DELETE FROM ".self::$_tbl_polygon_point.
" WHERE polygon_id IN (SELECT id FROM ".self::$_tbl_polygon.
" WHERE instance='$instance')";
126 $res = $db->actionquery($query);
129 $query =
"DELETE FROM ".self::$_tbl_polygon_polygon_ctg.
" WHERE polygon_id IN (SELECT id FROM ".self::$_tbl_polygon.
" WHERE instance='$instance')";
130 $res = $res && $db->actionquery($query);
133 $query =
"DELETE FROM ".self::$_tbl_map_polygon.
" WHERE polygon_id IN (SELECT id FROM ".self::$_tbl_polygon.
" WHERE instance='$instance')";
134 $res = $res && $db->actionquery($query);
137 $query =
"DELETE FROM ".self::$_tbl_polygon.
" WHERE instance='$instance'";
138 $res = $res && $db->actionquery($query);
156 public static function get($instance, $opts=null) {
158 $where =
"instance='".$instance.
"'".((isset($opts[
'where']) && $opts[
'where']) ?
" AND ".$opts[
'where'] :
'');
159 $order = isset($opts[
'order']) ? $opts[
'order'] :
'label';
160 $limit = isset($opts[
'limit']) ?
"LIMIT ".$opts[
'limit'] :
'';
164 $db = db::instance();
165 $query =
"SELECT id FROM ".self::$_tbl_polygon.
" WHERE $where ORDER BY $order $limit";
166 $a = $db->selectquery($query);
187 $db = db::instance();
188 $query =
"SELECT polygon_id FROM ".self::$_tbl_polygon_polygon_ctg.
" WHERE ctg_id='$ctg_id'";
189 $a = $db->selectquery($query);
191 $res[] = $b[
'polygon_id'];
243 if(!is_array($point_ids)) $points = array($point_ids);
246 foreach($point_ids as $pid) {
247 $values[] =
"('".$this->id.
"', '".$pid.
"')";
250 $db = db::instance();
251 $query =
"INSERT INTO ".self::$_tbl_polygon_point.
" (polygon_id, point_id) VALUES ".implode(
',', $values).
";";
253 return $db->actionquery($query);
265 if(!is_array($point_ids)) $points = array($point_ids);
268 foreach($point_ids as $pid) {
269 $values[] =
"point_id='".$pid.
"'";
272 $db = db::instance();
273 $query =
"DELETE FROM ".self::$_tbl_polygon_point.
" WHERE polygon_id='".$this->
id.
"' AND (".implode(
" OR ", $values).
")";
275 return $db->actionquery($query);
285 public function form($redirect) {
287 if(isset($_POST[
'submit'])) {
288 $gform =
new Form(
'form_polygon',
'post',
false, array(
'verifyToken'=>
true));
289 $gform->save(
'dataform');
290 $req_error = $gform->arequired();
292 $ctgs_id = cleanVar($_POST,
'ctg',
'array',
'');
293 $this->label = cleanVar($_POST,
'label',
'string',
'');
294 $this->lat = cleanVar($_POST,
'lat',
'string',
'');
295 $this->lng = cleanVar($_POST,
'lng',
'string',
'');
296 $this->description = cleanVarEditor($_POST,
'description',
'');
297 $this->color = cleanVar($_POST,
'color',
'string',
'');
298 $this->width = cleanVar($_POST,
'width',
'int',
'');
299 $this->updateDbData();
301 header(
"Location: ".$redirect);
305 if(!($_POST[
'lat'] && $_POST[
'lng'])) {
306 exit(error::errorMessage(array(
'error'=>_(
"Rappresentare l'area sulla mappa seguendo le istruzioni.")), $_SERVER[
'QUERY_STRING']));
308 exit(error::errorMessage(array(
'error'=>1), $_SERVER[
'QUERY_STRING']));
312 $registry = registry::instance();
313 $registry->addJs(
"http://maps.googleapis.com/maps/api/js?key=AIzaSyArAE-uBvCZTRaf_eaFn4umUdESmoUvoxM&sensor=true");
314 $registry->addJs(
"http://ajs.otto.to.it/sources/0.1/ajs/ajs.js");
317 $title = _(
"Modifica area");
318 $submit = _(
"modifica");
321 $title = _(
"Nuova area");
322 $submit= _(
"inserisci");
324 $htmlsection =
new htmlSection(array(
'class'=>
'admin',
'headerTag'=>
'header',
'headerLabel'=>$title));
326 $gform =
new Form(
'form_polygon',
'post',
true, array(
'trnsl_table'=>$this->_tbl_data,
'trnsl_id'=>$this->
id));
327 $gform->load(
'dataform');
328 $required =
"label,ctg,lat,lng";
329 $buffer = $gform->form(
'',
false, $required, array(
'generateToken'=>
true));
330 $buffer .= $gform->hidden(
'id', $this->
id);
332 $buffer .= $gform->hidden(
'lat', $this->lat, array(
'id'=>
'lat'));
333 $buffer .= $gform->hidden(
'lng', $this->lng, array(
'id'=>
'lng'));
335 $buffer .= $gform->multipleCheckbox(
'ctg[]', $gform->retvar(
'ctg', $this->_ctgs_id),
gmapsPolygonCtg::getForSelect($this->instance), _(
"Categorie"), array(
'required'=>
true));
336 $buffer .= $gform->cinput(
'label',
'text', $gform->retvar(
'label', htmlInput($this->label)), _(
"Etichetta"), array(
'required'=>
true,
'maxlength'=>200,
'size'=>40,
'trnsl'=>
true,
'field'=>
'label'));
337 $buffer .= $gform->cell($this->
formMap());
338 $buffer .= $gform->fcktextarea(
'description', $gform->retvar(
'description', htmlInputEditor($this->description)), _(
"Descrizione"), array(
'fck_toolbar'=>
"Default",
'trnsl'=>
true,
'field'=>
'description'));
339 $buffer .= $gform->cinput(
'color',
'text', $gform->retvar(
'color', htmlInput($this->color)), array(_(
"Colore"), _(
"codice esadecimale, es. #ff0000")), array(
'required'=>
true,
'maxlength'=>7,
'size'=>7,
'pattern'=>
'^#[0-9abcdefABCDEF]{6}$',
'hint'=>_(
"Inserire il colore in esadecimale")));
340 $buffer .= $gform->cinput(
'width',
'text', $gform->retvar(
'width', htmlInput($this->width)), array(_(
"Spessore tracciato"), _(
"in px")), array(
'required'=>
true,
'maxlength'=>2,
'size'=>2,
'pattern'=>
'^[0-9]*$',
'hint'=>_(
"Inserire un numero intero")));
341 $buffer .= $gform->cinput(
'submit',
'submit', $submit,
'', array(
'classField'=>
'submit'));
343 $buffer .= $gform->cform();
345 $htmlsection->content = $buffer;
347 return $htmlsection->render();
359 $buffer =
"<p>Per geolocalizzare l'area utilizzare lo strumento mappa qui sotto. Seguire la seguente procedura:</p>";
361 $buffer .=
"<li>"._(
"Premere il pulsante 'polygon'").
"</li>";
362 $buffer .=
"<li>"._(
"Cliccare nel punto desiderato sulla mappa per settare ogni punto del percorso. Se si dispone di un indirizzo si può utilizzare il campo di testo, scrivere l'indirizzo e poi premere 'draw'. E' possibile modificare direttamente l'area agendo sui controlli.").
"</li>";
363 $buffer .=
"<li>"._(
"Quando l'area tracciata corrisponde a quella desiderato permere il pulsante 'export map'.").
"</li>";
365 $buffer .=
"<div id=\"map_canvas\" style=\"width:100%; height: 300px;\"></div>";
367 $buffer .=
"<script>";
368 $buffer .=
"ajs.use(['ajs.maps.gmapdraw'], function() {
370 fillFields = function(data) {
373 for(var i = 0, tot = data.polygon[0].length; i < tot; i++) {
374 lat.push(data.polygon[0][i].lat);
375 lng.push(data.polygon[0][i].lng);
377 $('lat').set('value', lat.join(','));
378 $('lng').set('value', lng.join(','));
379 alert('".jsVar(_(
"L'area è stata settata correttamente, prosegui con la compilazione del form")).
"');
382 mymap = new ajs.maps.gmapdraw.map('map_canvas', {
384 export_map_callback: fillFields,
385 tools: {'polygon': { options: { max_items_allowed: 1 }}},
390 if($('lat').value && $('lng').value) {
392 var lat = $('lat').value.split(',');
393 var lng = $('lng').value.split(',');
396 for(var i = 0, tot = lat.length; i < tot; i++) {
397 parr.push({lat: lat[i], lng: lng[i]});
400 var data = {polygon: [parr]};
401 mymap.importMap(data);
402 mymap.gmap().setCenter(new google.maps.LatLng(lat[(Math.round(lat.length/2))], lng[(Math.round(lng.length/2))]));
407 $buffer .=
"</script>";
422 $db = db::instance();
423 $query =
"DELETE FROM ".self::$_tbl_polygon_polygon_ctg.
" WHERE polygon_id='".$this->
id.
"'";
424 $res = $db->actionquery($query);
427 foreach($ctgs_id as $ctg_id) {
428 $values[] =
"('".$this->id.
"', '".$ctg_id.
"')";
430 $query =
"INSERT INTO ".self::$_tbl_polygon_polygon_ctg.
" (polygon_id, ctg_id) VALUES ".implode(
',', $values).
";";
431 $res = $db->actionquery($query);
447 $buffer =
"var polygon_path_".$this->id.
" = new google.maps.MVCArray();";
448 $lats = explode(
',', $this->lat);
449 $lngs = explode(
',', $this->lng);
450 for($i=0; $i<count($lats); $i++) {
453 $buffer .=
"polygon_path_".$this->id.
".push(new google.maps.LatLng($lat, $lng));";
454 $buffer .= $bounds.
".extend(new google.maps.LatLng($lat, $lng));";
456 $buffer .=
" var polygon_".$this->id.
" = new google.maps.Polygon({path: polygon_path_".$this->
id.
", map:$map});";
458 foreach($this->_points as $point) {
459 $buffer .= $point->gmapCode($map, $bounds);
475 $db = db::instance();
479 $categories = array();
480 foreach($this->_ctgs as $ctg) {
481 $categories[] = jsVar($ctg->ml(
'name'));
486 label: '".jsVar($this->ml(
'label')).
"',
487 categories: '".implode(
', ', $categories).
"',
488 description: '".jsVar(cutHtmlText(HtmlChars($this->ml(
'description')), 120,
'...',
false,
false,
false, null)).
"',
489 lat: '".jsVar($this->lat).
"',
490 lng: '".jsVar($this->lng).
"',
491 color: '".$this->color.
"',
492 width: '".$this->width.
"'
496 $info_url = HOME_FILE.
'?pt['.$this->_controller->instanceName().
'-infowindow]&polygon_id='.$this->
id.
'&map_id='.$map_id;
498 $buffer .=
"new GmapPolygon($fields, [".implode(
',', $this->_ctgs_id).
"], $map_obj, '$info_url');";
511 public function delete() {
513 $db = db::instance();
516 $query =
"DELETE FROM ".self::$_tbl_polygon_polygon_ctg.
" WHERE polygon_id='".$this->
id.
"'";
517 $res = $db->actionquery($query);
520 $query =
"DELETE FROM ".self::$_tbl_map_polygon.
" WHERE polygon_id='".$this->
id.
"'";
521 $res = $res && $db->actionquery($query);
524 $query =
"DELETE FROM ".self::$_tbl_polygon_point.
" WHERE polygon_id='".$this->
id.
"'";
525 $res = $res && $db->actionquery($query);
527 $res = $res && $this->deleteDbData();