<?php
/**
* Documents the file following
* @package googlemapsForWP
* @author webcat
*/
//#################################################################
if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
die('You are not allowed to call this page directly.');
}
//#################################################################
if (!class_exists('googlemapsForWPMaps')) {
/**
* googlemapsForWP maps
* Maps database data to map classes
*/
class googlemapsForWPMaps {
protected $DB;
protected $status;
function __construct() {
$url = googlemapsForWP::pluginDir(). DIRECTORY_SEPARATOR;
$data = $url . 'data' . DIRECTORY_SEPARATOR;
$bus = $url . 'business' . DIRECTORY_SEPARATOR;
try {
if (!file_exists($data . 'mapdata.php') || !file_exists($data . 'googlemapsForWPvalidation.php') || !file_exists($bus . 'googlemapsForWPMap.php')) {
throw new Exception('Cannot find the required files');
} else {
require($data . 'mapdata.php');
require($bus . 'googlemapsForWPMap.php');
require($data . 'googlemapsForWPvalidation.php');
}
} catch (Exception $e) {
echo("A required file could not be accessed on your server. Please contact your server admin");
}
$this->DB = new googlemapsForWPDB();
$this->status = "Success";
}
/**
* Check install
*
*/
function installed(){
if($this->DB->installed()==true){
return true;
}
return false;
}
/**
*
* @return array of rows from map table, associateive
*/
function getMaps() {
return $this->DB->getMapList();
}
/**
*
* @param int $id
* @return array of flags from flags table
*/
function getFlags($id) {
return $this->DB->getFlags($id);
}
/**
*
* @param int $id
* @return googleMapsForWPMap
*/
function getMap($id) {
$mapdata = $this->DB->getMap($id);
$sizes = explode('x', $mapdata[0]['size']);
$maparray = array('mapname' => $mapdata[0]['mapname'], 'mapdescription' => $mapdata[0]['mapdescription'], 'longitude' => $mapdata[0]['longitude'], 'latitude' => $mapdata[0]['latitude'], 'zoom' => $mapdata[0]['zoom'], 'sizewidth' => $sizes[0], 'sizeheight' => $sizes[1], 'type' => $mapdata[0]['a.type'], 'format' => $mapdata[0]['format'], 'sensor' => $mapdata[0]['sensor']);
$map = new googleMapsForWPMap($id, $maparray);
$map->addFlags($this->DB->getFlags($id));
return $map;
}
/**
*
* @return <type>
*/
function getStatus() {
return $this->status;
}
/**
*
* @param <type> $id
*/
function deleteMap($id) {
$this->DB->deleteMap($id);
}
/**
*
* @param <type> $id
*/
function deleteFlag($id) {
$this->DB->deleteFlag($id);
}
/**
*
* @param string $map
* @param string $long
* @param string $lat
* @param string $size
* @param string $colour
* @param string $note
*/
function addFlag($args) {
//'longitude' => ,'latitude'=>,'map'=>,'type'=>'flag','size'=>,'colour'=>,'note'=>
$check = new googleMapsForWPDataFlagCheck();
if ($check->checkFlag($args)) {
if ($this->DB->addFlag($args) > 0) {
$check = null;
return true;
} else {
$this->status = ": " . $check->getErrors() . "<br />Could not add flag.";
$check = null;
return false;
}
} else {
$this->status = ": " . $check->getErrors() . "<br />Could not add flag.";
$check = null;
return false;
}
return true;
}
/**
*
* @param <type> $args
* @return googleMapsForWPMap
*/
function addMap($args) {
//$mapname,$description,$longitude,$latitude,$zoom,$sizewidth,$sizeheight,$type,$format
$check = new googleMapsForWPDataMapCheck();
if ($check->checkMap($args)) {
$mapid = $this->DB->addMap($args);
if ($mapid >= 1) {
$check = null;
return new googleMapsForWPMap($mapid, $args);
} else {
$this->status = ": " . $check->getErrors() . "<br />Could not add map.";
$check = null;
return false;
}
} else {
$this->status = ": " . $check->getErrors() . "<br />Could not add map.";
$check = null;
return false;
}
}
}
}
?>