      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192:

    <?php

    namespace WPGMZA;

    class Database
    {
        public function __construct()
        {
            global $wpgmza;
            global $wpgmza_version;

            $this->version = get_option('wpgmza_db_version');

            if(version_compare($this->version, $wpgmza_version, '<'))
                $this->install();
        }

        public function install()
        {
            global $wpgmza;
            global $wpgmza_version;

            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

            $this->installMapsTable();
            $this->installMarkerTable();
            $this->installPolygonTable();
            $this->installPolylineTable();
            $this->installCircleTable();
            $this->installRectangleTable();

            update_option('wpgmza_db_version', $wpgmza_version);
        }

        protected function installMapsTable()
        {
            global $WPGMZA_TABLE_NAME_MAPS;

            $sql = "CREATE TABLE `$WPGMZA_TABLE_NAME_MAPS` (
                id int(11) NOT NULL AUTO_INCREMENT,
                map_title varchar(55) NOT NULL,
                map_width varchar(6) NOT NULL,
                map_height varchar(6) NOT NULL,
                map_start_lat varchar(700) NOT NULL,
                map_start_lng varchar(700) NOT NULL,
                map_start_location varchar(700) NOT NULL,
                map_start_zoom INT(10) NOT NULL,
                default_marker varchar(700) NOT NULL,
                type INT(10) NOT NULL,
                alignment INT(10) NOT NULL,
                directions_enabled INT(10) NOT NULL,
                styling_enabled INT(10) NOT NULL,
                styling_json mediumtext NOT NULL,
                active INT(1) NOT NULL,
                kml VARCHAR(700) NOT NULL,
                bicycle INT(10) NOT NULL,
                traffic INT(10) NOT NULL,
                dbox INT(10) NOT NULL,
                dbox_width varchar(10) NOT NULL,
                listmarkers INT(10) NOT NULL,
                listmarkers_advanced INT(10) NOT NULL,
                filterbycat TINYINT(1) NOT NULL,
                ugm_enabled INT(10) NOT NULL,
                ugm_category_enabled TINYINT(1) NOT NULL,
                fusion VARCHAR(100) NOT NULL,
                map_width_type VARCHAR(3) NOT NULL,
                map_height_type VARCHAR(3) NOT NULL,
                mass_marker_support INT(10) NOT NULL,
                ugm_access INT(10) NOT NULL,
                order_markers_by INT(10) NOT NULL,
                order_markers_choice INT(10) NOT NULL,
                show_user_location INT(3) NOT NULL,
                default_to VARCHAR(700) NOT NULL,
                other_settings longtext NOT NULL,
                PRIMARY KEY  (id)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

            dbDelta($sql);
        }

        protected function installMarkerTable()
        {
            global $WPGMZA_TABLE_NAME_MARKERS;

            $sql = "CREATE TABLE `$WPGMZA_TABLE_NAME_MARKERS` (
                id int(11) NOT NULL AUTO_INCREMENT,
                map_id int(11) NOT NULL,
                address varchar(700) NOT NULL,
                description mediumtext NOT NULL,
                pic varchar(700) NOT NULL,
                link varchar(700) NOT NULL,
                icon varchar(700) NOT NULL,
                lat varchar(100) NOT NULL,
                lng varchar(100) NOT NULL,
                anim varchar(3) NOT NULL,
                title varchar(700) NOT NULL,
                infoopen varchar(3) NOT NULL,
                category varchar(500) NOT NULL,
                approved tinyint(1) DEFAULT '1',
                retina tinyint(1) DEFAULT '0',
                type tinyint(1) DEFAULT '0',
                did varchar(500) NOT NULL,
                other_data LONGTEXT NOT NULL,
                latlng POINT,
                integration_source VARCHAR(32) NULL,
                integration_context INT(11) NULL,
                PRIMARY KEY  (id)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

            dbDelta($sql);
        }

        protected function installPolygonTable()
        {
            global $WPGMZA_TABLE_NAME_POLYGONS;

            $sql = "CREATE TABLE `$WPGMZA_TABLE_NAME_POLYGONS` (
                id int(11) NOT NULL AUTO_INCREMENT,
                map_id int(11) NOT NULL,
                polydata LONGTEXT NOT NULL,
                innerpolydata LONGTEXT NOT NULL,
                linecolor VARCHAR(7) NOT NULL,
                lineopacity VARCHAR(7) NOT NULL,
                fillcolor VARCHAR(7) NOT NULL,
                opacity VARCHAR(3) NOT NULL,
                title VARCHAR(250) NOT NULL,
                link VARCHAR(700) NOT NULL,
                ohfillcolor VARCHAR(7) NOT NULL,
                ohlinecolor VARCHAR(7) NOT NULL,
                ohopacity VARCHAR(3) NOT NULL,
                polyname VARCHAR(100) NOT NULL,
                PRIMARY KEY  (id)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

            dbDelta($sql);
        }

        protected function installPolylineTable()
        {
            global $WPGMZA_TABLE_NAME_POLYLINES;

            $sql = "CREATE TABLE `$WPGMZA_TABLE_NAME_POLYLINES` (
                id int(11) NOT NULL AUTO_INCREMENT,
                map_id int(11) NOT NULL,
                polydata LONGTEXT NOT NULL,
                linecolor VARCHAR(7) NOT NULL,
                linethickness VARCHAR(3) NOT NULL,
                opacity VARCHAR(3) NOT NULL,
                polyname VARCHAR(100) NOT NULL,
                PRIMARY KEY  (id)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

            dbDelta($sql);
        }

        protected function installCircleTable()
        {
            global $WPGMZA_TABLE_NAME_CIRCLES;

            $sql = "CREATE TABLE `$WPGMZA_TABLE_NAME_CIRCLES` (
                id int(11) NOT NULL AUTO_INCREMENT,
                map_id int(11) NOT NULL,
                name TEXT,
                center POINT,
                radius FLOAT,
                color VARCHAR(16),
                opacity FLOAT,
                PRIMARY KEY  (id)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

            dbDelta($sql);
        }

        protected function installRectangleTable()
        {
            global $WPGMZA_TABLE_NAME_RECTANGLES;

            $sql = "CREATE TABLE `$WPGMZA_TABLE_NAME_RECTANGLES` (
                id int(11) NOT NULL AUTO_INCREMENT,
                map_id int(11) NOT NULL,
                name TEXT,
                cornerA POINT,
                cornerB POINT,
                color VARCHAR(16),
                opacity FLOAT,
                PRIMARY KEY  (id)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

            dbDelta($sql);
        }
    }