public static function create_new($searchedFor, $parentID = 0, $addGoogleMapLocationsObjectOrItsID = false)
 {
     $obj = new GoogleMapSearchRecord();
     $obj->SearchedFor = $searchedFor;
     $obj->ParentID = $parentID;
     if (!$addGoogleMapLocationsObjectOrItsID) {
         //do nothing
     } elseif ($addGoogleMapLocationsObjectOrItsID === true || ($addGoogleMapLocationsObjectOrItsID = 1)) {
         //create object
         $location = new GoogleMapLocationsObject();
         $location->Address = $searchedFor;
         $location->Manual = false;
         $location->write();
         $obj->GoogleMapLocationsObjectID = $location->ID;
     } else {
         $obj->GoogleMapLocationsObjectID = $addGoogleMapLocationsObjectOrItsID;
     }
     $obj->write();
     return $obj;
 }
 function createnewbusinesslistingfrompoint($request)
 {
     if (!isset($_GET["address"])) {
         $addressArray = array();
         $address = '';
     } else {
         $addressArray = unserialize($_GET["address"]);
         $address = $addressArray["address"];
     }
     if (!isset($_GET["name"])) {
         $name = '';
     } else {
         $name = Convert::raw2xml($_GET["name"]);
     }
     if (!isset($_GET["parent"])) {
         $parent = 0;
     } else {
         $parent = intval($_GET["parent"]);
     }
     if ($member = Member::currentMember()) {
         if ($name) {
             if ($parent && ($parentPage = DataObject::get_by_id("SiteTree", $parent))) {
                 if ($address && count($addressArray)) {
                     $allowedParents = BusinessPage::get_can_be_child_off();
                     if (is_array($allowedParents) && in_array($parentPage->ClassName, $allowedParents)) {
                         $extension = '';
                         if (Versioned::current_stage() == "Live") {
                             $extension = "_Live";
                         }
                         $page = DataObject::get_one("BusinessPage", "ParentID = " . $parentPage->ID . " AND SiteTree{$extension}.Title = '" . Convert::raw2sql($name) . "'");
                         if ($page) {
                             //do nothing
                         } else {
                             $page = new BusinessPage();
                             $page->Title = $name;
                             $page->MenuTitle = $name;
                             $page->MetaTitle = $name;
                             $page->Email = $member->Email;
                             $page->ParentID = $parentPage->ID;
                             $page->writeToStage('Stage');
                             $page->publish('Stage', 'Live');
                             $page->flushCache();
                             $page->Members()->add($member);
                             $member->addToGroupByCode(BusinessPage::get_member_group_code());
                         }
                         $point = new GoogleMapLocationsObject();
                         $point->addDataFromArray($addressArray);
                         $point->ParentID = $page->ID;
                         $point->write();
                         Director::redirect($page->Link());
                         return;
                     } else {
                         Director::redirect($this->linkWithExtras(array("address" => $address, "name" => $name, "error" => "Could not find correct parent page type ")));
                         return;
                     }
                 } else {
                     Director::redirect($this->linkWithExtras(array("address" => $address, "name" => $name, "error" => "Could not find address page.")));
                     return;
                 }
             } else {
                 Director::redirect($this->linkWithExtras(array("address" => $address, "name" => $name, "error" => "Could not find parent page.")));
                 return;
             }
         }
         Director::redirect($this->linkWithExtras(array("address" => $address, "name" => $name, "error" => "Could not find listing name.")));
         return;
     } else {
         Security::permissionFailure($this, "You must have an account and be logged in to create new a new listing.");
     }
 }
 public function updatemexml()
 {
     //we use request here, because the data comes from javascript!
     if ($this->owner->canEdit()) {
         if (isset($_REQUEST["x"]) && isset($_REQUEST["y"]) && isset($_REQUEST["i"]) && isset($_REQUEST["a"])) {
             $lng = floatval($_REQUEST["x"]);
             $lat = floatval($_REQUEST["y"]);
             $id = intval($_REQUEST["i"]);
             $action = $_REQUEST["a"];
             if ($lng && $lat) {
                 if (0 == $id && "add" == $action) {
                     $point = new GoogleMapLocationsObject();
                     $point->ParentID = $this->owner->ID;
                     $point->Latitude = $lat;
                     $point->Longitude = $lng;
                     $point->write();
                     return $point->ID;
                 } elseif ($id > 0 && "move" == $action) {
                     $point = GoogleMapLocationsObject::get()->byID($id);
                     if ($point) {
                         if ($point->ParentID == $this->owner->ID) {
                             $point->Latitude = $lat;
                             $point->Longitude = $lng;
                             $point->Address = "";
                             $point->FullAddress = "";
                             $point->write();
                             return "location updated";
                         } else {
                             return "you dont have permission to update that location";
                         }
                     } else {
                         return "could not find location";
                     }
                 } elseif ($id && "remove" == $action) {
                     $point = GoogleMapLocationsObject::get()->byID($id);
                     if ($point) {
                         if ($point->ParentID == $this->owner->ID) {
                             $point->delete();
                             $point = null;
                             return "location deleted";
                         } else {
                             return "you dont have permission to delete that location";
                         }
                     } else {
                         return "could not find location.";
                     }
                 }
             } else {
                 return "point not defined.";
             }
         } else {
             return "not enough information was provided.";
         }
     }
     return "point could NOT be updated.";
 }