Location: PHPKode > scripts > googlemapsForWP > googlemapsforp/data/mapdata.php
<?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('googlemapsForWPDB')){
/**
 * googlemapsForWP maps
 * The class provides access to
 */
	 class googlemapsForWPDB {
            function __construct(){}
/**
 *
 * @global connection $wpdb 
 */
              function install(){
                global $wpdb;
                     $line=$wpdb->query("CREATE TABLE IF NOT EXISTS wp_googlemapsForWP(
                        `id` int(11) AUTO_INCREMENT NOT NULL,
                        `mapname` varchar( 25 ) NOT NULL DEFAULT 'Cardiff',
                        `mapdescription` varchar( 300 )DEFAULT 'map',
                        `zoom` text NOT NULL,
                        `size` text NOT NULL,
                        `type` varchar(10) DEFAULT 'roadmap',
                        `format` varchar(7) DEFAULT 'png24',
                        `sensor` varchar (5) DEFAULT 'false',
                        PRIMARY KEY ( `id` )) ENGINE=InnoDB");
                     if($line===false){
                         $this->uninstall();
                         throw new Exception("The plugin could not be installed due to an error creating tables");
                     }
                     $line= $wpdb->query("CREATE TABLE IF NOT EXISTS wp_googlemapsForWP_flags(
                        `id` int(11) AUTO_INCREMENT NOT NULL,
                        `latitude` varchar(10) DEFAULT '51.477222',
                        `longitude` varchar(10) DEFAULT '0',
                        `last_update` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                        `map` int(11) NOT NULL,
                        `type` varchar (20) NOT NULL DEFAULT 'center',
                        `size` varchar (20) NOT NULL DEFAULT 'small',
                        `colour` varchar (10) NOT NULL DEFAULT 'red',
                        `note` varchar (500),
                        PRIMARY KEY ( `id` )) ENGINE=InnoDB; ");
                     if($line===false){
                         $this->uninstall();
                         throw new Exception("The plugin could not be installed due to an error creating tables");
                     }
            }
/**
 *
 * @global connection $wpdb 
 */
            function uninstall(){
                global $wpdb;
                $wpdb->query("DROP TABLE IF EXISTS wp_googlemapsForWP;");
                $wpdb->query("DROP TABLE IF EXISTS wp_googlemapsForWP_flags;");
            }
/**
 * 
 */
            function updateTables(){}
            function installed(){
                global $wpdb;
                $wpdb->flush;
                $installed=$wpdb->query("SELECT `mapname` FROM wp_googlemapsForWP;");
                if($installed===false ){ return false;}
                return true;
            }
/**
 *
 * @global connection $wpdb
 * @param array $args
 * @return array
 */
            function addMap($args){
                //error checking needed on insert retrun
                global $wpdb;
                foreach($args as $key => $value){
                    $args[$key]=$value;
                }
                $size=$args['sizewidth']."x".$args['sizeheight'];
                $wpdb->insert('wp_googlemapsForWP',array('mapname'=>$args['mapname'],'mapdescription'=>$args['mapdescription'],'zoom'=>$args['zoom'],'size'=>$size,'type'=>$args['type'],'format'=>$args['format'],'sensor'=>$args['sensor']));
                $mapnumber=$wpdb->insert_id;
                $wpdb->insert('wp_googlemapsForWP_flags',array('longitude' => $args['longitude'],'latitude'=>$args['latitude'],'map'=>$mapnumber,'type'=>'center'));
                return $mapnumber;
            }
/**
 *
 * @global connection $wpdb
 * @param <type> $id 
 */
            function deleteMap($id){
                global $wpdb;
                $wpdb->query("DELETE FROM wp_googlemapsForWP_flags WHERE map = ".$id.";");
                $wpdb->query("DELETE FROM wp_googlemapsForWP WHERE id = ".$id.";");
            }
/**
 *
 * @global connection $wpdb
 * @param <type> $mapnumber
 * @param <type> $long
 * @param <type> $lat
 * @param <type> $size
 * @param <type> $colour
 * @param <type> $note 
 */
            function addFlag($args){
                //$map, $long, $lat, $size, $colour, $note
                global $wpdb;
                $wpdb->insert('wp_googlemapsForWP_flags',$args);
                return $wpdb->insert_id;
            }
/**
 *
 * @global connection $wpdb
 * @param <type> $mapid
 * @return <type> 
 */
            function getFlags($mapid){
                global $wpdb;
                $flags=$wpdb->get_results("SELECT * FROM wp_googlemapsForWP_flags WHERE map = ".$mapid." AND type='flag';",ARRAY_A);
                return $flags;
            }
/**
 *
 * @global connection $wpdb
 * @param <type> $id 
 */
            function deleteFlag($id){
               global $wpdb;
                $wpdb->query("DELETE FROM wp_googlemapsForWP_flags WHERE id = ".$id.";");
            }
/**
 *
 * @global connection $wpdb
 * @param <type> $id
 * @return <type> 
 */
            function getMap($id){
                global $wpdb;
                $map=$wpdb->get_results("SELECT mapname,mapdescription,zoom,a.size,a.type,format,sensor,latitude,longitude
                        FROM `wp_googlemapsForWP` a LEFT JOIN `wp_googlemapsForWP_flags` b
                        ON a.id = b.map AND b.type = 'center'
                        WHERE a.id = ".$id.";",ARRAY_A);
                return $map;
            }
/**
 *
 * @global connection $wpdb
 * @return <type> 
 */
            function getMapList(){
                global $wpdb;
                $maplist=$wpdb->get_results("SELECT id,mapname FROM wp_googlemapsForWP;",ARRAY_A);
                return $maplist;//array('name1','name2');
            }
         }
}
?>
Return current item: googlemapsForWP