This is an old revision of the document!


Main Author: Ravindra de Silva Contributors: …

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

shn_location($range,$value=null,$parent=null,$extra_opts=null)
  • $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 “USA” then you can pass the

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[“camps”]=true;

e.g:

require_once $global['approot']."/inc/lib_location.inc";
$extra_opts["camps"]=true;
$range=array("start"=>1,"end"=>4);
shn_location($range,$_SESSION['org']['loc'],null,$extra_opts);

this will create 4 select boxes from level 1 to level 4 remember in the database in field_options ,we define the levels. In addition this will generate a select box to select camps.

if you need only the first 3 levels

$range=array("start"=>1,"end"=>3);

Then once the form is submitted ,there will a POST variable per each level name of the variable will be the level no.

Note: You can display both camps and organizations at the same time with locations. it will be extended to display Inventories as well.

        $extra_opts["camps"]=true;
        $extra_opts["org"]=true;

above code will produce two radio buttons and a set of location select boxes. when you select the “camp” radio button , a select box will appear with the camps. when you select a camp ,through AJAX, location details of the camp(country,city,state,ect) will be retrieved and the location boxes will get populated with those. similar functionality can be seen when you select the “organization” radio button.

Obtain the location selected by user from POST variables

the function to use is

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 return it.

e.g

 
    $loc=shn_location_get_form_submit_loc();
    if($loc==-1){
    	add_error(SHN_ERR_OR_LOCATION_INCOMPLETE);
        $error=true;
    }

Other API functions

shn_location_is_leaf($loc)

Returns true if the location does not have any children

shn_location_get_descendants($loc,&$loc_arr))

Returns an array of descendants of a location

shn_location_level_range_form($name,$label,$sel)

Displays the full range of location levels for the user

shn_get_parents($child,&$loc_arr)

Returns the list of parents of the location. Starting from the location to the parent,grand parent,ect. For each level the name and location id is returned.

 shn_get_level($loc)

Returns the level of the location

 shn_is_last_level($loc)

Returns whether the location is in the last level or not

 shn_get_last_level()

Returns the last location level avaliable

 shn_get_range()

Returns the range of levels avaliable


Navigation
  • Navigate