content = new View("admin_tagsmap.html"); // Generate a form for Google Maps Settings. $view->content->googlemaps_form = $this->_get_googlemaps_form(); // Generate a list of tags to display. $query = ORM::factory("tag"); $view->content->tags = $query->orderby("name", "ASC")->find_all(); // Display the page. print $view; } public function edit_gps($tag_id) { // Generate a new admin page to edit the tag specified by $tag_id. $view = new Admin_View("admin.html"); $view->content = new View("admin_tagsmap_edit.html"); $view->content->tagsmapedit_form = $this->_get_tagsgpsedit_form($tag_id); print $view; } public function delete_gps($tag_id) { // Delete the GSP data associated with a tag. // Delete the record. ORM::factory("tags_gps") ->where("tag_id", $tag_id) ->delete_all(); // Redirect back to the main screen and display a "success" message. message::success(t("Your Settings Have Been Saved.")); url::redirect("admin/tagsmap"); } private function _get_tagsgpsedit_form($tag_id) { // Make a new Form. $form = new Forge("admin/tagsmap/savegps", "", "post", array("id" => "gTagsMapAdminForm")); // Add a few input boxes for GPS and Description $tagsgps_group = $form->group("TagsMapGPS"); $tagsgps_group->hidden("tag_id")->value($tag_id); // Check and see if this ID already has GPS data. $existingGPS = ORM::factory("tags_gps") ->where("tag_id", $tag_id) ->find_all(); if (count($existingGPS) == 0) { $tagsgps_group->input("gps_latitude")->label(t("Latitude"))->value(); $tagsgps_group->input("gps_longitude")->label(t("Longitude"))->value(); $tagsgps_group->textarea("gps_description")->label(t("Description"))->value(); } else { $tagsgps_group->input("gps_latitude")->label(t("Latitude"))->value($existingGPS[0]->latitude); $tagsgps_group->input("gps_longitude")->label(t("Longitude"))->value($existingGPS[0]->longitude); $tagsgps_group->textarea("gps_description")->label(t("Description"))->value($existingGPS[0]->description); } // Add a save button to the form. $tagsgps_group->submit("SaveGPS")->value(t("Save")); // Return the newly generated form. return $form; } public function savegps() { // Save the GPS coordinates to the database. // Prevent Cross Site Request Forgery access::verify_csrf(); // Figure out the values of the text boxes $str_tagid = Input::instance()->post("tag_id"); $str_latitude = Input::instance()->post("gps_latitude"); $str_longitude = Input::instance()->post("gps_longitude"); $str_description = Input::instance()->post("gps_description"); // Save to database. // Check and see if this ID already has GPS data. $existingGPS = ORM::factory("tags_gps") ->where("tag_id", $str_tagid) ->find_all(); if (count($existingGPS) == 0) { $newgps = ORM::factory("tags_gps"); $newgps->tag_id = $str_tagid; $newgps->latitude = $str_latitude; $newgps->longitude = $str_longitude; $newgps->description = $str_description; $newgps->save(); } else { $updatedGPS = ORM::factory("tags_gps", $existingGPS[0]->id); $updatedGPS->tag_id = $str_tagid; $updatedGPS->latitude = $str_latitude; $updatedGPS->longitude = $str_longitude; $updatedGPS->description = $str_description; $updatedGPS->save(); } // Redirect back to the main screen and display a "success" message. message::success(t("Your Settings Have Been Saved.")); url::redirect("admin/tagsmap"); } private function _get_googlemaps_form() { // Make a new Form. $form = new Forge("admin/tagsmap/savemapprefs", "", "post", array("id" => "gTagsMapAdminForm")); // Input box for the Maps API Key $googlemap_group = $form->group("GoogleMapsKey"); $googlemap_group->input("google_api_key") ->label(t("Google Maps API Key")) ->value(module::get_var("tagsmap", "googlemap_api_key")); // Input boxes for the Maps starting location and zoom. $startingmap_group = $form->group("GoogleMapsPos"); $startingmap_group->input("google_starting_latitude") ->label(t("Starting Latitude")) ->value(module::get_var("tagsmap", "googlemap_latitude")); $startingmap_group->input("google_starting_longitude") ->label(t("Starting Longitude")) ->value(module::get_var("tagsmap", "googlemap_longitude")); $startingmap_group->input("google_default_zoom") ->label(t("Default Zoom Level")) ->value(module::get_var("tagsmap", "googlemap_zoom")); $startingmap_group->input("google_default_type") ->label(t("Default Map Type") . " (G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP, G_PHYSICAL_MAP, G_SATELLITE_3D_MAP)") ->value(module::get_var("tagsmap", "googlemap_type")); // Add a save button to the form. $form->submit("SaveSettings")->value(t("Save")); // Return the newly generated form. return $form; } public function savemapprefs() { // Prevent Cross Site Request Forgery access::verify_csrf(); // Figure out the values of the text boxes $str_googlekey = Input::instance()->post("google_api_key"); $str_googlelatitude = Input::instance()->post("google_starting_latitude"); $str_googlelongitude = Input::instance()->post("google_starting_longitude"); $str_googlezoom = Input::instance()->post("google_default_zoom"); $str_googlemaptype = Input::instance()->post("google_default_type"); // Save Settings. module::set_var("tagsmap", "googlemap_api_key", $str_googlekey); module::set_var("tagsmap", "googlemap_latitude", $str_googlelatitude); module::set_var("tagsmap", "googlemap_longitude", $str_googlelongitude); module::set_var("tagsmap", "googlemap_zoom", $str_googlezoom); module::set_var("tagsmap", "googlemap_type", $str_googlemaptype); message::success(t("Your Settings Have Been Saved.")); // Redirect back to the TagsMap admin page. url::redirect("admin/tagsmap"); } }