true:open, enable - false:closed, disable private $category; // Id of the associated category private $title; private $lat; private $lon; private $zoom; private $data_changed; // Used to know if data were changed private $category_changed; // Used to know if category was changed /***********************************************************************/ /* Methods *************************************************************/ function getMaps() { $query = ' SELECT id FROM '.PSLI_MAPS_TABLE.' ORDER BY title;'; $result = pwg_query($query); $maps = array(); while ($row = pwg_db_fetch_assoc($result)) { $maps[] = new Psli_Map($row['id']); } return $maps; } function assignData ($template, $lat_name, $lon_name, $zoom_name, $title_name, $id_name) { $template->assign( array( $lat_name => $this->lat, $lon_name => $this->lon, $zoom_name => $this->zoom, $title_name => $this->title, $id_name => $this->id ) ); } function generateMapsList($template, $block) { $i = 0; $query = ' SELECT id, title FROM '.PSLI_MAPS_TABLE.' ORDER BY title;'; $result = pwg_query($query); $maps = array(); $maps_selecteds = array(); if (! $this->status) $maps_selecteds[0] = l10n('No selected map'); while ($row = pwg_db_fetch_assoc($result)) { $i ++; if ($row['id'] == $this->id) { $maps_selecteds[$row['id']] = $row['title']; } else { $maps[$row['id']] = $row['title']; } } $template->assign($block.'_selected', $maps_selecteds); $template->assign($block, $maps); return $i; } function delete() { if ($this->status == true) { $query = 'DELETE FROM '.PSLI_ENTITIES_MAPS_TABLE.' WHERE id_map = '.$this->id.';'; pwg_query($query); $query = 'DELETE FROM '.PSLI_MAPS_TABLE.' WHERE id = '.$this->id.';'; pwg_query($query); $this->status = false; return true; } else return false; } function create() { if ($this->status == false) { $query = ' INSERT INTO '.PSLI_MAPS_TABLE.' (lat, lon, zoom, title) VALUES (0, 0, 2, "'.l10n("New Map").'");'; pwg_query($query); $this->id = pwg_db_insert_id(); $this->category = 0; $this->lat = 0; $this->lon = 0; $this->zoom = 2; $this->title = l10n("New Map"); $this->status = true; $this->category_changed = false; $this->data_changed = false; return true; } else return false; } function open($open) { $query = ' SELECT id, id_category, lat, lon, zoom, title FROM '.PSLI_MAPS_TABLE.' WHERE id = '.$open.';'; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { $row = pwg_db_fetch_assoc($result); $this->id = $row['id']; $this->category = $row['id_category']; $this->lat = $row['lat']; $this->lon = $row['lon']; $this->zoom = $row['zoom']; $this->title = $row['title']; $this->status = true; $this->category_changed = false; $this->data_changed = false; return true; } else return false; } function save() { if (($this->status == true) && ($this->data_changed == true)) { $query = ' UPDATE '.PSLI_MAPS_TABLE.' SET lat = '.$this->lat.', lon = '.$this->lon.', title = "'.addslashes($this->title).'", zoom = '.$this->zoom.' WHERE id = '.$this->id.';'; pwg_query($query); $this->data_changed = false; } if (($this->status == true) && ($this->category_changed == true)) { $query = ' UPDATE '.PSLI_MAPS_TABLE.' SET id_category = '.$this->category.' WHERE id = '.$this->id.';'; pwg_query($query); $this->category_changed = false; } } /***********************************************************************/ /* Setters ************************************************************/ function setCategory($value) { if (($this->status == true) && ($value != $this->category)) { $this->category = $value; $this->category_changed = true; } } function setTitle($value) { if (($this->status == true) && ($value != $this->title)) { $this->title = $value; $this->data_changed = true; } } function setLatitude($value) { if (($this->status == true) && ($value != $this->lat)) { $this->lat = $value; $this->data_changed = true; } } function setLongitude($value) { if (($this->status == true) && ($value != $this->lon)) { $this->lon = $value; $this->data_changed = true; } } function setZoom($value) { if (($this->status == true) && ($value != $this->zoom)) { $this->zoom = $value; $this->data_changed = true; } } /***********************************************************************/ /* Getters ************************************************************/ function getCategory() { return $this->category; } function getTitle() { return $this->title; } function getLatitude() { return $this->lat; } function getLongitude() { return $this->lon; } function getZoom() { return $this->zoom; } function getId() { return $this->id; } function isOpened() { return $this->status; } /***********************************************************************/ /* Constructor *********************************************************/ function __construct ($value = 0) { $this->category = 0; $this->lat = 0; $this->lon = 0; $this->zoom = 2; $this->title = l10n("New Map"); $this->status = false; $this->category_changed = false; $this->data_changed = false; if ($value != 0) $this->open($value); } } ?>