Monthly Archives: March 2012

Sum Time with Format hh:mm:ss by Using PHP

<?php

/**
 * @author Masino Sinaga, http://www.openscriptsolution.com
 * @copyright October 13, 2009
 */

echo sum_the_time('01:45:22', '17:27:03');  // this will give you a result: 19:12:25

function sum_the_time($time1, $time2) {
  $times = array($time1, $time2);
  $seconds = 0;
  foreach ($times as $time)
  {
    list($hour,$minute,$second) = explode(':', $time);
    $seconds += $hour*3600;
    $seconds += $minute*60;
    $seconds += $second;
  }
  $hours = floor($seconds/3600);
  $seconds -= $hours*3600;
  $minutes  = floor($seconds/60);
  $seconds -= $minutes*60;
  // return "{$hours}:{$minutes}:{$seconds}";
  return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); // Thanks to Patrick
}

?>

How can calculate distance between two place in php with google map?

<?php

$q = “http://maps.googleapis.com/maps/api/distancematrix/json?origins=&#8221;.str_replace(‘ ‘,’+’,$_REQUEST[‘address1’]).”&destinations=”.str_replace(‘ ‘,’+’,$_REQUEST[‘address2’]).”&mode=driving&sensor=false”;

$json = file_get_contents($q);

$details = json_decode($json, TRUE);

//echo “<pre>”; print_r($details); echo “</pre>”;

$tim = explode(‘ ‘,$details[‘rows’][0][‘elements’][0][‘duration’][‘text’]);

//print $tim[0]=60;
switch ($tim[1]):
case ‘day’:
$time = $tim[0]*24*60;
break;
case ‘days’:
$time = $tim[0]*24*60;
break;
case ‘hour’:
$time =  $tim[0]*60;
break;
case ‘hours’:
$time =  $tim[0]*60;
break;
default:
$time = $tim[0];
endswitch;

if($tim[3]==”hours”)
{
$time = $time+($tim[2]*60);
}
if($tim[3]==”mins”)
{
$time = $time+$tim[2];
}

//print ‘<br>ftim=’.$time;

$dis = explode(‘ ‘,$details[‘rows’][0][‘elements’][0][‘distance’][‘text’]);
//print_r($details[‘rows’][0][‘elements’][0][‘distance’][‘text’]);

$distance = str_replace(“,”, “”, $dis[0]) *0.621371192;

?>

body tag code

<script type=”text/javascript”>
var map;
var geocoder, location1, location2;
function initialize()
{
geocoder = new GClientGeocoder();
}
function showmap()
{

var add1='<?php echo $_REQUEST[‘address1′];?>’;

geocoder.getLocations(add1, function (response)
{

if (!response || response.Status.code != 200)
{
alert(“Sorry, we were unable to find the first address”);
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
calculate();
}
});
}

function calculate()
{

var lt=<?php echo $latitude;?>;
var ll=<?php echo $longitude;?>;

if (GBrowserIsCompatible())
{
// create map and add controls
var map = new GMap2(document.getElementById(“map”));
map.addControl(new GLargeMapControl());

// set centre point of map
var centrePoint = new GLatLng(lt, ll);
map.setCenter(centrePoint, 8);

// add a draggable marker
var marker = new GMarker(centrePoint, {draggable: true});
map.addOverlay(marker);

// add a drag listener to the map
GEvent.addListener(marker, “dragend”, function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById(“latitude”).value = point.lat();
document.getElementById(“longitude”).value = point.lng();
});
}

}

function showLocation() {

var add1='<?php echo $_REQUEST[‘address1′];?>’;
var add2='<?php echo $_REQUEST[‘address2′];?>’;

geocoder.getLocations(add1, function (response) {

if (!response || response.Status.code != 200)
{
alert(“Sorry, we were unable to find the first address”);
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(add2, function (response) {
if (!response || response.Status.code != 200)
{
alert(“Sorry, we were unable to find the second address”);
}
else
{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
calculateDistance();
}
});
}
});
}

function calculateDistance()
{
var lt=<?php print $latitude;?>;
var ll=<?php print $longitude; ?>;
var rt=<?php print $latitude1;?>;
var rl=<?php print $longitude1; ?>;
try
{
var glatlng1 = new GLatLng(<?php print $latitude;?>, <?php print $longitude;?>);
var glatlng2 = new GLatLng(<?php print $latitude1;?>, <?php print $longitude1;?>);
var miledistance = glatlng1.distanceFrom(glatlng2, 3959).toFixed(1);
var kmdistance = (miledistance * 1.609344).toFixed(1);
var time=(kmdistance/30).toFixed(2);
var t=time %1;
if (t > .60)
{

var time=((time-t)+1).toFixed(2);
}

/*document.getElementById(‘values’).innerHTML = ‘<strong>Address 1: </strong><br/>’ + ‘<?php //print $_REQUEST[‘address1′]?>’ + ‘<br /><strong>Address 2: </strong><br/>’ + ‘<?php //print $_REQUEST[‘address2′]?>’ + ‘<br /><strong>Distance: </strong><br/>’ + miledistance + ‘ Miles’ + ‘<br />’+kmdistance + ‘ KiloMeters’+'<br /><strong>Travelling Time:</strong><br />’+time+ ‘Hours’;*/
}
catch (error)
{
alert(error);
}
if (GBrowserIsCompatible())
{
// create map and add controls
var map = new GMap2(document.getElementById(“map”));
map.addControl(new GLargeMapControl());

// set centre point of map
var centrePoint = new GLatLng(lt, ll);
map.setCenter(centrePoint, 8);

var centre = new GMarker(new GLatLng(rt, rl));
map.addOverlay(centre, 8);

var points = [new GLatLng(lt, ll),new GLatLng(rt, rl)];
var polyline = new GPolyline(points, ‘#f00’, 6);

map.addOverlay(polyline);

// add a draggable marker
var marker = new GMarker(centrePoint, {draggable: true});
map.addOverlay(marker);

// add a drag listener to the map
GEvent.addListener(marker, “dragend”, function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById(“latitude”).value = point.lat();
document.getElementById(“longitude”).value = point.lng();
});
}

}

</script>
<script>initialize();</script>
<script>

window.onload = function load() {

showmap();
showLocation();
}

//]]>
</script>

in div

<p>Estimated distance <strong><?php print ceil($distance)?> miles</strong>, estimated time <strong><?php print ceil($time);?> minutes</strong>.</p>

div code

<div align=”center” id=”map” style=”width: 642px; height: 350px”></div>

How can apply custom menu with different css?

Go to dashboard ->appearance->menus
now click on Screen Options right top corner and check on CSS Classes.
When create a menu than add a css class for individual menu.

add a php code in your header.php

<nav id=”access” role=”navigation”>
<?php wp_nav_menu( array( ‘menu’ => ‘custom_menu’ ) ); ?>
</nav>

and apply a css style.css
#access li.home {background:url(“images/green.jpg”) no-repeat 0 1px transparent;width:116px; height:37; text-align:center; vertical-align:middle;}
#access li.about {background:url(“images/blue.png”) no-repeat 0 1px transparent;width:107px; height:37; text-align:center; vertical-align:middle;}
#access li.project {background:url(“images/orange.png”) no-repeat 0 1px transparent;width:105px; height:37; text-align:center; vertical-align:middle;}
#access li.contact {background:url(“images/red.png”) no-repeat 0 1px transparent;width:105px; height:37; text-align:center; vertical-align:middle;}

#access {
clear: both;
display: block;
float: right;
margin: 0;

}
#access ul {
font-family:Arial; font-size: 10pt;
list-style: none;
margin: 0 0 0 -0.8125em;

padding-left: 0;
}
#access li {
float: left;
position: relative;
font-family:Arial; font-size: 10pt;
}
#access a {
color: #FFF;
display: block;
line-height: 37px;
padding:0;
text-decoration: none;
}

#access ul ul {
display: none;
float: left;
margin: 0;
position: absolute;
top: 37px;
left: 0;
width: auto;
z-index: 99999;
}
#access ul ul ul {
left: 100%;
top: 0;
}
#access ul ul li.aboutul{
background: #00A9C8;
width:125px;
}

#access ul ul li.projectli{
background: #F5BB01;
width:120px;
}
#access ul ul li.contactli{
background: #F54E00;
width:110px;
}

#access ul ul a{

color: #444;
font-family:Arial; font-size: 9pt;
font-weight: normal;
height: auto;
line-height: 15px;
padding: 5px 0 10px 0;

}
#access li:hover > a,
#access ul ul :hover > a,
#access a:focus {
color: #000000;
}
#access li:hover > a,
#access a:focus {
color: #000000;
}
#access ul li:hover > ul {
display: block;
}
#access .current-menu-item > a,
#access .current-menu-ancestor > a,
#access .current_page_item > a,
#access .current_page_ancestor > a {
font-weight: bold;
}

.assistive-text {
position: absolute !important;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
}
#access a.assistive-text:active,
#access a.assistive-text:focus {
background: #eee;
border-bottom: 1px solid #ddd;
color: #1982d1;
clip: auto !important;
font-size: 12px;
position: absolute;
text-decoration: underline;
top: 0;
left: 7.6%;
}

How can use multiple select option with insert table joomla

$post = JRequest::get( ‘request’ );

// declare varible for insert table
$option_id= JRequest::getVar(‘option_id’, array(), ‘post’, ‘array’);
if (is_array( $barring_id)) {
$post[‘option_id’] = implode( “,”, $option_id);
}

$db =& JFactory::getDBO();
$query = ‘SELECT * FROM #__test_option’;
$db->setQuery( $query );
$list[] = JHTML::_(‘select.option’, ‘0’, JText::_( ‘Select Type’ ), ‘option_id’, ‘type’ );
$list2 = array_merge( $barringlist,$db->loadObjectList() );
$lists[‘id’] = JHTML::_(‘select.genericlist’, $list2, ‘option_id[]’, ‘class=”inputbox” multiple=”multiple” ‘,’option_id’, ‘type’, explode(‘,’, $data->option_id ));

use explode so that when edit form than it display selected option.