Check or uncheck multiple checkbox at a time in javascript

function checkUncheckAllCheckbox()
{
f=document.frmName
if(f.mainCheckBox.checked)
{
f.checkBoxName.checked=true;
for(i=0;i<f.checkBoxName.length;i++)
f.checkBoxName[i].checked=true;
}
else if(!f.mainCheckBox.checked)
{
f.checkBoxName.checked=false;
for(i=0;i<f.checkBoxName.length;i++)
f.checkBoxName[i].checked=false;
}
}

How to configure the symfony project directory

Your symfony project derectory is “/var/www/html/sf_sandbox” so in the browser you can acess this by this URL : “http://localhost/sf_sandbox/web/frontend.php/”

So if you want to map the symfony project directoy to your web root directory ie i mean to say you just want to acess it my using the URL :”http://localhost/” then you have to add the below line in the httpd.conf file and then restart your apache server.After that you can directly acess the symfony project from localhost url.

<VirtualHost *:80>
ServerName http://localhost/
DocumentRoot “/var/www/html/sf_sandbox/web”
DirectoryIndex index.php
<Directory “/var/www/html/sf_sandbox/web”>
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

Rest of the things will be handled by symfony itself.

How to redirect domain to other directory on the same domain

Open the .htaccess file of your root directory
of your project and add the following line.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^http://someDomainName.com [NC]
RewriteCond %{HTTP_HOST} !^http://www.someDomainName.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI} !^/someOtherDirectory/
RewriteRule ^(.*)$ /someOtherDirectory/$1

Then restart your apache

Usage :
Suppose your project is placed in some other directory
other than the default web directory then you can redirect
your request to that directory for example

Your actual project URL is
"http://someDomaiName/someDirectory/fileName"
and you want that your URL should resemble like
"http://someDomaiName/fileName"
then the above .htaccess rule will do the same.

integrate window media player in your website

<html>
<head></head>
<body leftmargin=”0″ topmargin=”0″>
<table cellpadding=”0″ cellspacing=”0″ border=”0″>
<tr height=”350″><td align=”center”>
<table cellpadding=”0″ cellspacing=”0″ border=1 bordercolor=”black”>
<tr>
<td valign=”top”>
<OBJECT ID=”MediaPlayer” WIDTH=”320″ HEIGHT=”290″ CLASSID=”CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95″ STANDBY=”Loading Windows Media Player components…” TYPE=”application/x-oleobject”>
<PARAM NAME=”URL” VALUE=’http://localhost/vinod/meeting_with_the_boss.wmv’ />
<param name=”AudioStream” value=”0″ />
<param name=”AutoSize” value=”1″ />
<param name=”AutoStart” value=”-1″ />
<param name=”AnimationAtStart” value=”1″ />
<param name=”AllowScan” value=”-1″ />
<param name=”AllowChangeDisplaySize” value=”-1″ />
<param name=”AutoRewind” value=”0″ />
<param name=”Balance” value=”0″ />
<param name=”BufferingTime” value=”1″ />
<param name=”ClickToPlay” value=”1″ />
<param name=”CursorType” value=”0″ />
<param name=”CurrentPosition” value=”-1″ />
<param name=”CurrentMarker” value=”0″ />
<param name=”DisplayBackColor” value=”0″ />
<param name=”DisplayForeColor” value=”16777215″ />
<param name=”DisplayMode” value=”0″ />
<param name=”DisplaySize” value=”4″ />
<param name=”Enabled” value=”1″ />
<param name=”EnableContextMenu” value=”1″ />
<param name=”EnableFullScreenControls” value=”1″ />
<param name=”EnableTracker” value=”0″ />
<param name=”Filename” VALUE=’http://localhost/vinod/meeting_with_the_boss.wmv’><param name=”Mute” value=”0″ />
<param name=”PlayCount” value=”1″ />
<param name=”PreviewMode” value=”1″ />
<param name=”SelectionStart” value=”-1″ />
<param name=”SelectionEnd” value=”-1″ />
<param name=”SendKeyboardEvents” value=”0″ />
<param name=”SendMouseClickEvents” value=”0″ />
<param name=”SendMouseMoveEvents” value=”0″ />
<param name=”SendPlayStateChangeEvents” value=”-1″ />
<param name=”ShowCaptioning” value=”0″ />
<param name=”ShowAudioControls” value=”1″ />
<param name=”ShowDisplay” value=”0″ />
<param name=”ShowGotoBar” value=”0″ />
<param name=”ShowPositionControls” value=”0″ />
<param name=”ShowTracker” value=”1″ />
<param name=”VideoBorderWidth” value=”0″ />
<param name=”VideoBorderColor” value=”0″ />
<param name=”VideoBorder3D” value=”0″ />
<param name=”Volume” value=”-1″ />
<param name=”WindowlessVideo” value=”0″ />
<param name=”ShowStatusBar” value=”1″ />
<PARAM name=”ShowControls” VALUE=”1″ />
<PARAM name=”ShowControls” VALUE=”true” />
<param name=”ShowStatusBar” value=”true” />
<PARAM name=”ShowDisplay” VALUE=”false” />
<EMBED TYPE=”application/x-mplayer2″ SRC=’http://localhost/vinod/meeting_with_the_boss.wmv’ NAME=”MediaPlayer” WIDTH=”320″ HEIGHT=”290″ ShowControls=”1″ ShowStatusBar=”1″ ShowDisplay=”0″ autostart=”1″> </EMBED></OBJECT>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

You can view the live application here

Calculate no of years,month,days,hours,minutes and seconds past since given date

function getYMDHMSPastFromTwoDate($startTimeStamp,$endTimeStamp)
{
$years = ”;
$Month = ”;
$Days = ”;
$Hrs = ”;
$Mins = ”;
$totalSecs = ”;
$timePastArr = array();
$date1 = $startTimeStamp;
$date2 = $endTimeStamp;
if($date1 > $date2)
{
$dateDiff = intval($date1 – $date2);
}
else
{
$dateDiff = intval($date2 – $date1);
}

$totalYears = $dateDiff/(365*24*60*60);
$years = floor($totalYears);
$timeRemaining = ($dateDiff – ($years*365*24*60*60));
$totalMonth = $timeRemaining/(30*24*60*60);
$Month = floor($totalMonth);
$timeRemaining = $timeRemaining – $Month*30*24*60*60;
$totalDays = $timeRemaining/(24*60*60);
$Days = floor($totalDays);
$timeRemaining = $timeRemaining-$Days*60*60*24;
$totalHrs = $timeRemaining/(60*60);
$Hrs = floor($totalHrs);
$timeRemaining = $timeRemaining-$Hrs*60*60;
$totalMins = $timeRemaining/60;
$Mins = floor($totalMins);
$timeRemaining = $timeRemaining-$Mins*60;
$totalSecs = floor($timeRemaining);

return $timePastArr = array(‘year’=>$years,’month’=>$Month,’days’=>$Days,’hours’=>$Hrs,’minutes’=>$Mins,’seconds’=>$totalSecs);

}

Show tooltip on mouseover

Step 1: Copy this css style code into your header tage right before the end of header tag

<style type=”text/css”>

#dhtmltooltip{
position: absolute;
border: 1px solid red;
width: 150px;
padding: 2px;
background-color: lightyellow;
visibility: hidden;
z-index: 100;
filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=115);
}

</style>

Step 2 :Copy the following code into page with your body html tags

<div id=”dhtmltooltip”></div>

<script type=”text/javascript”>

/***********************************************
* Freejavascriptkit.com
* Visit http://www.freejavascriptkit.com for more free Javascripts source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all[“dhtmltooltip”] : document.getElementById? document.getElementById(“dhtmltooltip”) : “”

function ietruebody(){
return (document.compatMode && document.compatMode!=”BackCompat”)? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!=”undefined”) tipobj.style.width=thewidth+”px”
if (typeof thecolor!=”undefined” && thecolor!=””) tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn’t enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it’s width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+”px” : window.pageXOffset+e.clientX-tipobj.offsetWidth+”px”
else if (curX<leftedge)
tipobj.style.left=”5px”
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+”px”

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+”px” : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+”px”
else
tipobj.style.top=curY+offsetypoint+”px”
tipobj.style.visibility=”visible”
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility=”hidden”
tipobj.style.left=”-1000px”
tipobj.style.backgroundColor=”
tipobj.style.width=”
}
}

document.onmousemove=positiontip

</script>

Step 3: Add the following code to your link or page element which needs a tool tip

onMouseover=”ddrivetip(‘Free javascripts from www.freejavascriptkit.com’,’lightgreen’, 300)”;
onMouseout=”hideddrivetip()”

Note : You can refer more detail on “http://www.freejavascriptkit.com/free_javascripts/tooltip_hint/dhtml_mouseover_tooltip.html”

unicode issue in Perl CGI

When some special character(or other language data) is displayed as ‘? ? ? ? ?’ in browser, then you have to make the following change.

1.In your table set the collation of the field that is to be displayed as “Binary”.

If this does not work then you can try the below option in your cgi script

2. Set the meta-type in your templates file as

“<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />”.

If the above two does not work,then try the third option.

3.

use Encode qw(encode decode);

my $text = decode (‘utf8’, $value_to_be_decoded);