Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
dev:location_handler [2007/05/02 19:01] fran typos, formatting |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | Main Author: [[http:// | ||
- | |||
- | ====== Location Library ====== | ||
- | |||
- | ===== Generate Location Boxes ===== | ||
- | |||
- | This allows you to create a set of select boxes with AJAX capability. | ||
- | all you need to do is include the libray and call the API function. For AJAX to function | ||
- | javascript needs to be enabled at the client side. | ||
- | |||
- | The function to use is | ||
- | |||
- | <code php> | ||
- | shn_location($range, | ||
- | </ | ||
- | |||
- | * $range is the range of location levels you want to display | ||
- | i.e Though levels from Country to City exists ,you might want to display only | ||
- | Country to State | ||
- | * if you want to pre-select a location ,then pass a value. If you pass a city then | ||
- | the State and Country will also be populated. | ||
- | * If you want to show only the locations of the Country " | ||
- | location id of USA as $parent. | ||
- | * In $extra_opts you can specify whether you want to display location unknown check box | ||
- | and whether you want to display camps, organizations alongside the locations. | ||
- | for example if you want to show camps, then pass $extra_opts[" | ||
- | |||
- | |||
- | |||
- | e.g: | ||
- | <code php> | ||
- | require_once $global[' | ||
- | $extra_opts[" | ||
- | $range=array(" | ||
- | shn_location($range, | ||
- | </ | ||
- | |||
- | this will create 4 select boxes from level 1 to level 4 | ||
- | remember in the database in field_options, | ||
- | In addition this will generate a select box to select camps. | ||
- | |||
- | if you need only the first 3 levels | ||
- | <code php> | ||
- | $range=array(" | ||
- | </ | ||
- | |||
- | Then once the form is submitted ,there will a POST variable for each level. | ||
- | Name of the variable will be the level number. | ||
- | |||
- | Note: You can display both camps and organizations at the same time with locations. | ||
- | It will be extended to display Inventories as well. | ||
- | |||
- | <code php> | ||
- | $extra_opts[" | ||
- | $extra_opts[" | ||
- | </ | ||
- | |||
- | Above code will produce two radio buttons and a set of location select | ||
- | boxes. | ||
- | When you select the " | ||
- | the camps. | ||
- | When you select a camp, through AJAX, location details of the | ||
- | camp (country, | ||
- | will get populated with those. | ||
- | Similar functionality can be seen when you select the " | ||
- | radio button. | ||
- | |||
- | ===== Obtain the location selected by user from POST variables ===== | ||
- | |||
- | the function to use is | ||
- | |||
- | <code php> | ||
- | shn_location_get_form_submit_loc(); | ||
- | </ | ||
- | |||
- | This function will start from the lowest level of the select boxes (say city) and goes up | ||
- | the select boxes till it finds a location selected and returns it. | ||
- | |||
- | e.g | ||
- | <code php> | ||
- | |||
- | $loc=shn_location_get_form_submit_loc(); | ||
- | if($loc==-1){ | ||
- | add_error(SHN_ERR_OR_LOCATION_INCOMPLETE); | ||
- | $error=true; | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | ====== Other API functions ====== | ||
- | <code php> | ||
- | shn_location_is_leaf($loc) | ||
- | </ | ||
- | |||
- | Returns true if the location does not have any children. | ||
- | |||
- | <code php> | ||
- | shn_location_get_descendants($loc,& | ||
- | </ | ||
- | |||
- | Returns an array of descendants of a location. | ||
- | |||
- | <code php> | ||
- | shn_location_level_range_form($name, | ||
- | </ | ||
- | |||
- | Displays the full range of location levels for the user. | ||
- | |||
- | <code php> | ||
- | shn_get_parents($child,& | ||
- | </ | ||
- | |||
- | | ||
- | the parent, grand parent,ect. For each level the name and location id is returned. | ||
- | |||
- | <code php> | ||
- | | ||
- | </ | ||
- | |||
- | Returns the level of the location. | ||
- | |||
- | <code php> | ||
- | | ||
- | </ | ||
- | |||
- | Returns whether the location is in the last level or not. | ||
- | |||
- | <code php> | ||
- | | ||
- | </ | ||
- | |||
- | Returns the last location level available. | ||
- | |||
- | <code php> | ||
- | | ||
- | </ | ||
- | |||
- | Returns the range of levels available. | ||