Thursday, July 21, 2011

EIGHT LESSONS: Google map on popup window

EIGHT LESSONS: Google map on popup window

Google map on popup window


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Find latitude and longitude with Google Maps</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=Goolge api"
      type="text/javascript"></script>
<script type="text/javascript">
 function load() {
   if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        var center = new GLatLng(48.89364,2.33739);
        map.setCenter(center, 15);
   geocoder = new GClientGeocoder();
        var marker = new GMarker(center, {draggable: true});
        map.addOverlay(marker);
//alert(center.lat().toFixed(5));
        document.formx.latitude.value = center.lat().toFixed(5);
        document.formx.langitude.value = center.lng().toFixed(5);
 GEvent.addListener(marker, "dragend", function() {
       var point = marker.getPoint();
     map.panTo(point);
       document.formx.latitude.value = point.lat().toFixed(5);
       document.formx.langitude.value = point.lng().toFixed(5);
   });
 GEvent.addListener(map, "moveend", function() {
 map.clearOverlays();
    var center = map.getCenter();
 var marker = new GMarker(center, {draggable: true});
 map.addOverlay(marker);
 document.formx.latitude.value = center.lat().toFixed(5);
  document.formx.langitude.value = center.lng().toFixed(5);
GEvent.addListener(marker, "dragend", function() {
      var point =marker.getPoint();
    map.panTo(point);
      document.formx.latitude.value = point.lat().toFixed(5);
    document.formx.langitude.value = point.lng().toFixed(5);


        });

        });

      }
    }

  function showAddress(address) {
  var map = new GMap2(document.getElementById("map"));
       map.addControl(new GSmallMapControl());
       map.addControl(new GMapTypeControl());
       if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
 document.formx.latitude.value = point.lat().toFixed(5);
  document.formx.langitude.value = point.lng().toFixed(5);

map.clearOverlays()
map.setCenter(point, 14);
   var marker = new GMarker(point, {draggable: true});
map.addOverlay(marker);

GEvent.addListener(marker, "dragend", function() {
      var pt = marker.getPoint();
    map.panTo(pt);
      document.formx.latitude.value = pt.lat().toFixed(5);
    document.formx.langitude.value= pt.lng().toFixed(5);
 });
GEvent.addListener(map, "moveend", function() {
 map.clearOverlays();
    var center = map.getCenter();
 var marker = new GMarker(center, {draggable: true});
 map.addOverlay(marker);
 document.formx.latitude.value = center.lat().toFixed(5);
  document.formx.langitude.value= center.lng().toFixed(5);
   
GEvent.addListener(marker, "dragend", function() {
     var pt = marker.getPoint();
   map.panTo(pt);
    document.formx.latitude.value = pt.lat().toFixed(5);
  document.formx.langitude.value = pt.lng().toFixed(5);

        });

        });

            }
          }
        );
      }
    }
    </script>
<style type="text/css">
.popup_table tr td{
border:1px solid #ccc;
background-color:#fff;
}</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>

$(document).ready(function() {

//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();

//Get the A tag
var id = $(this).attr('href');

//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});

//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
      //Set the popup window to center
$(id).css('top',  winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);

//transition effect
$(id).fadeIn(2000);

$(window).resize(function(){
location.reload();
});
load();
});

//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();

$('#mask').hide();
$('.window').hide();
});

//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});

});

</script>
<style>


#mask {
  position:absolute;
  left:0;
  top:0;
  z-index:9000;

  display:none;
}

#boxes .window {
  position:absolute;
  left:0;
  top:0;
  width:500px;
  height:300px;
  display:none;
  z-index:9999;
  padding:20px;
}

#boxes #dialog {
  width:500px;
  height:350px;
  padding:10px;
  background-color:#ffffff;
}
</style>
<script type="text/javascript">
function show_points(){

var lat=document.formx.latitude.value;
var lng=document.formx.langitude.value;

document.getElementById("lati").value=lat;
document.getElementById("lang").value=lng;
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<ul>
  <li><a href="#dialog" name="modal" id="showMap">Simple Window Modal</a></li>
</ul>
<table>
  <tr>
    <td><input type="text" name="lat" id="lati" value="" /></td>
    <td><input type="text" name="lang" id="lang" value="" /></td>
  </tr>
</table>
<div id="boxes">
  <div id="dialog" class="window"> Simple Modal Window | <a href="#"class="close"/>Close it</a>
    <form name="formx" action="#" onsubmit="showAddress(this.address.value); return false">
      <table width="50%" border="0" cellspacing="0" cellpadding="5" style="border:1px solid #eddfaf; background-color:#F9F4E2;">
        <tr>
          <td><table width="100%" cellpadding="3" cellspacing="0"  bgcolor="#eddfaf">
              <tr>
                <td><input type="text" size="50" name="address" value="3 cit&eacute; Nollez Paris France" /></td>
                <td><input type="submit" value="Search!" /></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td><table  width="420" cellpadding="2" cellspacing="0"  bgcolor="#eddfaf">
              <tr>
                <td colspan="2"></td>
              </tr>
              <tr>
                <td align="center"><b>Latitude</b></td>
                <td align="center"><b>Longitude</b></td>
              </tr>
              <tr>
                <td><input type="text" name="latitude" id="lat" /></td>
                <td><input type="text" name="langitude" id="lng" /></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td><div align="center" id="map" style="width: 480px; height: 200px"><br/>
            </div>
            <a href="#" onclick="show_points();">Like it</a> </td>
        </tr>
      </table>
    </form>
  </div>
</div>
</body>
</html>

OUTPUT:









Simple Modal Window | Close it
Latitude Longitude


Like it


EIGHT LESSONS: Import CSV Data into Mysql

EIGHT LESSONS: Import CSV Data into Mysql

Import CSV Data into Mysql

Here We are converting CSV data into Mysql.
example: we have name,email,phone now we are importing .csv data into mysql
below is the code for this
<?
   if(isset($_POST['submit']))
    {

         $fname = $_FILES['sel_file']['name'];
     
         $chk_ext = explode(".",$fname);
     
         if(strtolower($chk_ext[1]) == "csv")
         {
     
             $filename = $_FILES['sel_file']['tmp_name'];
             $handle = fopen($filename, "r");
     
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
             {
                $sql = "INSERT into user(name,email,phone) values('$data[0]','$data[1]','$data[2]')";
echo $sql;
               // mysql_query($sql) or die(mysql_error());
             }exit;
     
             fclose($handle);
             echo "Successfully Imported";
         }
         else
         {
             echo "Invalid File";
         }
    }
?>
    <form action='' method='post' enctype="multipart/form-data">

        Import File : <input type='file' name='sel_file' size='20'>
        <input type='submit' name='submit' value='submit'>

    </form>
OUTPUT:


Import File :


How To Convert Excel sheet into CSV

We can convert with out using any code.

This method is the most easiest and in fact doesn’t require any tool at all.
 Just head over to Google Docs and login with your Google account.

1.Click New and select Spreadsheet.
This will open a new window where you will find the spreadsheet.

2.Now click File and then select Import.
You can import the following format, .xls, .xlsx, .ods, .csv, and .txt. Click choose file and select the Excel Spreadsheet you want to convert. Once importing is done, hit Open Now link.

Tuesday, July 19, 2011

Clean variable using PHP

<?
function clean($value) {

       // If magic quotes not turned on add slashes.
       if(!get_magic_quotes_gpc())

       // Adds the slashes.
       { $value = addslashes($value); }

       // Strip any tags from the value.
       $value = strip_tags($value);

       // Return the value out of the function.
       return $value;

}
$sample = "<a href='test.php'><strong>test</strong></a>";
$sample = clean($sample);
echo $sample;
?>
Out Put: test

Block censored words using php

does this string contain any ****** ****** ****** ****** ******
<?
// Array containing profane words
$arrProfanities = array('these', 'are', 'the', 'words', 'I', 'want', 'to', 'filter');

// String containing content you want to filter for profane words
$strContent = 'does this string contain any words I want to filter';

// This will replace all the words from the array that are matched in the string with [censored]
$strContent = str_replace($arrProfanities, '******', $strContent);
echo $strContent;
// Output would be:
// $strContent = 'does this string contain any [censored] [censored] [censored] [censored] [censored]?';
?>

Add Multiple Images with Captions

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Upload Multiple images with Captions</title>
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">

(function (a) {
  a.fn.relCopy = function (f) {
    var b = jQuery.extend({
      excludeSelector: ".exclude",
      emptySelector: ".empty",
      copyClass: "copy",
      append: "",
      clearInputs: true,
      limit: 0
    }, f);
    b.limit = parseInt(b.limit);
    this.each(function () {
      a(this).click(function () {
        var e = a(this).attr("rel"),
            d = a(e).length;
        if (b.limit != 0 && d >= b.limit) return false;
        var c = a(e + ":first"),
            g = a(c).parent();
        c = a(c).clone(true).addClass(b.copyClass + d).append(b.append);
        b.excludeSelector && a(c).find(b.excludeSelector).remove();
        b.emptySelector && a(c).find(b.emptySelector).empty();
        if (a(c).attr("id")) {
          var h = a(c).attr("id") + (d + 1);
          a(c).attr("id", h)
        }
        a(c).find("[id]").each(function () {
          var i = a(this).attr("id") + (d + 1);
          a(this).attr("id", i)
        });
        b.clearInputs && a(c).find(":input").each(function () {
          switch (a(this).attr("type")) {
          case "button":
            break;
          case "reset":
            break;
          case "submit":
            break;
          case "checkbox":
            a(this).attr("checked", "");
            break;
          default:
            a(this).val("")
          }
        });
        a(g).find(e + ":last").after(c);
        return false
      })
    });
    return this
  }
})(jQuery);

</script>
<script type="text/javascript">
$(function(){
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remove</a>';

$('a.add').relCopy({ append: removeLink});
});
</script>
</head>

<body>
<form method="post" action="clonesubmit.php">
<p class="clone"> <input type="text" name="hobby[]" class='input'/>
<input name="images[]" type="file"/>
</p>
<p><a href="#" class="add" rel=".clone">Add More</a></p>
<input type="submit" value=" Submit " />
</form>
</body>
</html>

Download reCopy.js

OUTPUT:








Add More