Monday, January 4, 2010

Tab Menu in Javascript

Implement customize tab menu in single floor and multi floor in any language using javascript




<style type="text/css">
  .tabHold{background-color:#bbb9b5; width:400px; height:26px; margin-left:18px; margin-top:9px; float:left;}


.tabHold_1{background-color:#bbb9b5; width:400px; height:26px; margin-left:18px; margin-top:6px; float:left;}
  
  .tabmenu{width:100px; height:21px; text-align:center; font-family:Arial; font-size:13px; padding-top:3px; color:#FFFFFF; text-decoration:none; float:left; cursor:pointer;}
  .tabmenu:hover{ background-color:#FFFFFF; width:100px; height:21px; text-align:center; padding-top:3px; font-family:Arial; font-size:13px; color:#000000; text-decoration:none; float:left;}
  .tabContent{
  color:#000000;
  width:450px;
  height:100px;
  float:left;
  display:none;
  border:#CCCCCC solid 2px;

  }
  .DefaulttabContent{
  color:#000000;
  width:450px;
  height:100px;
  float:left;
  display:block;
  border:#CCCCCC solid 2px;
  }
  </style>


<script language="javascript">
  function init(){

  document.getElementById('tabmenu1').style.background='#FFFFFF';
  document.getElementById('tabmenu1').style.color='#000000';
  document.getElementById('tab1').style.display='block';


  }
  function onClickShow(TabNo,totTab){

 
  var i=1;
  for(i=1;i<=totTab;i++){
  if(i==TabNo){
  document.getElementById('tabmenu'+TabNo).style.background='#FFFFFF';
  document.getElementById('tabmenu'+TabNo).style.color='#000000';
  document.getElementById('tab'+TabNo).style.display='block';


}else{
  document.getElementById('tabmenu'+i).style.background='#bbb9b5';
  document.getElementById('tabmenu'+i).style.color='#FFFFFF';
  document.getElementById('tab'+i).style.display='none';


}


}
  
  
  }
  window.onload(init());


  </script>
  </head>
  <body>
  <div style="width:450px; float:left; border:#000000 solid 2px;">
  <div align="left" class="tabHold">
  <span class="tabmenu" onclick="onClickShow('1','8')" id="tabmenu1">Tab1</span>
  <span class="tabmenu" onclick="onClickShow('2','8')" id="tabmenu2">Tab2</span>
  <span class="tabmenu" onclick="onClickShow('3','8')" id="tabmenu3">Tab3</span>
  <span class="tabmenu" onclick="onClickShow('4','8')" id="tabmenu4">Tab4</span>
  </div>
  <div align="left" class="tabHold_1">
  <span class="tabmenu" onclick="onClickShow('5','8')" id="tabmenu5">Tab5</span>
  <span class="tabmenu" onclick="onClickShow('6','8')" id="tabmenu6">Tab6</span>
  <span class="tabmenu" onclick="onClickShow('7','8')" id="tabmenu7">Tab7</span>
  <span class="tabmenu" onclick="onClickShow('8','8')" id="tabmenu8">Tab8</span>
  </div>


<div class="DefaulttabContent" id="tab1">Text in Default Tab</div>
  <div class="tabContent" id="tab2">Text in Tab2</div>
  <div class="tabContent" id="tab3">Text in Tab3</div>
  <div class="tabContent" id="tab4">Text in Tab4</div>
  <div class="tabContent" id="tab5">Text in Tab5</div>
  <div class="tabContent" id="tab6">Text in Tab6</div>
  <div class="tabContent" id="tab7">Text in Tab7</div>
  <div class="tabContent" id="tab8">Text in Tab8</div>


</div>


Default page load :




Click on other tab :

Friday, December 25, 2009

Dayanmic Pagination in PHP

Creating dyanamic pagination for any site or section of site with Display page rang of display page no of all pages in PHP.

Creating Following Pagination format

Example :-




 $strPosition=$_REQUEST['startPostion']; //Record Start Position

  if(isset($strPosition) && $strPosition>=1){
  $start=$strPosition;

  }else{
  $start=0;
  }
  $display=15; //No. of record dispaly onl single page or one Page

  $rsCount; //No. of record fetch from recordset (database table)


$pages=ceil($rsCount/$display); //Calculate pages will display or get from database table



<div align="left" style="width:500px; border:#666666 solid 1px; display:block;">


<!-- Display Previous Page Button(Link) -->


<div align="left" style="float:left">
  <?php


  
  // echo $currentPage;
  if($pages>1){

  $currentPage=($start/$display)+1; //Current Page No. on which page is have

  $stPageNo=$currentPage-4; //Set Start Page no for page range

  $endPageNo=(($currentPage+5)<$pages)? $currentPage+5 : $pages;    //Set End Page No for page range

  if($currentPage>=1){

  echo '<a href="'.$_SERVER["PHP_SELF"].'?startPostion='.($start-$display).'">
  <span style="color:#FF9933; font-family:Arial, Helvetica, sans-serif; font-size:14px">Previous Page</span>
  </a>';
  }
  }
  ?>
  </div>

Ex:-




  <!-- List of Page No in Block Format-->


<div align="left" style="float:left; padding-left:5px;">
  <?php
  for($i=$stPageNo;$i<=$endPageNo;$i++){
  if($i>0){
  if($i==$currentPage){
  echo'<span title="Current Page">'.$i.'</span>';
  }else{
  echo '<a title="page '.$i.'" href="'.$_SERVER['PHP_SELF'].'?startPostion='.($display*($i-1)).'" class="no-underline">
  <span style="color:#FF9933; font-family:Arial, Helvetica, sans-serif; font-size:14px; display:block; border:#CCCCCC solid 1px; width:15px; text-align:center;">'.$i.'&nbsp;'.'</span></a>';
  }

  }
  }
  ?>
  </div>

Ex:-




 <!-- Display Next Page Button(Link) -->



<div align="left" style="float:right">
  <?php
  if($pages>1){
  if($currentPage!=$pages){

  echo '<a href="'.$_SERVER["PHP_SELF"].'?startPostion='.($start+$display).'"><span style="color:#FF9933; font-family:Arial, Helvetica, sans-serif; font-size:14px">Next Page</span></a>';

  }
  }
  ?>
  </div>

Ex:-


  </div>


Out Put:-





Wednesday, December 23, 2009

Send Mail With Attachment in php

 If u want to send a email using php mail function with attachment a zip or any file following code will help u to send it.

$fileatt = ""; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = ""; // Filename that will be used for the file as the attachment



$to = 'youraddress@example.com';                          //define the receiver of the email 

$subject = 'Test email with attachment';                   //define the subject of the email 

$random_hash = md5(date('r', time()));                 //create a boundary string. It must be unique use md5 function for it.


$random_hash = md5(date('r', time()));                 //create a boundary string. It must be unique use md5 function for it.
$mime_boundary = "==Multipart_Boundary_x{$random_hash}x";
$headers = "From: support@campus100.com\r\nReply-To: support@campus100.com";   //define the headers we want passed. Note that they are separated with \r\n

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";   //add boundary string and mime type specification
//$headers .= "Content-type: text/html\r\n";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks

$file = fopen($destination,'rb');
$data = fread($file,filesize($destination));
fclose($file);
$data = chunk_split(base64_encode($data));
//define the body of the message.

//ob_start();         //Turn on output buffering
$fileatt_type=$_FILES['attachFile']['type'];

$textTosend='.nl2br($body).';

$textTosend .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$textTosend . "\n\n";



$textTosend .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data. "\n\n" .
"--{$mime_boundary}\n";
unset($data);
unset($file);
unset($destination);
unset($fileatt_type);
unset($fileatt_name);

if(mail( $to, $subject, $message, $headers ) ){

echo "Mail sent" ;

}else{
   echo "Mail send Fail";
}

?>




Monday, December 21, 2009

change picture each time web page loads

Image can change on web page, you know...like showing different christmas pictures when web page loads on a users computer. I want them to see a different picture each time in php page.


$file=array();

$file[0]="file1.gif";
$file[1]="file2.gif";
$file[2]="file3.gif";
$file[3]="file4.gif";
$file[4]="file5.gif";
$file[5]="file6.gif";
$file[6]="file7.gif";
$file[7]="file8.gif";

$fileno=rand(0,7);

$filename=$file[$fileno];

echo '<img src="$filename" >';

?>

Saturday, December 19, 2009

Spelling Checking in php

Spelling Check in php. Pass checking string to function and get result in from of any error.

function checkSpell($input)
{
    $word=new COM("word.application") or die("Cannot create Word object");
    $word->Visible=false;
    $word->WindowState=2;
    $word->DisplayAlerts=false;
    $doc=$word->Documents->Add();
    $doc->Content=$input;
    $doc->CheckSpelling();
    $result= $doc->SpellingErrors->Count;
    if($result!=0)
    {
        echo "Input text contains misspelled words.\n\n";
        for($i=1; $i <= $result; $i++)
        {      
            echo "Original Word: " .$doc->SpellingErrors[$i]->Text."\n";
            $list=$doc->SpellingErrors[$i]->GetSpellingSuggestions();
            echo "Suggestions: ";
            for($j=1; $j <= $list->Count; $j++)
            {
                $correct=$list->Item($j);
                echo $correct->Name.",";
            }
            echo "\n\n";
        }
    }
    else
    {
        echo "No spelling mistakes found.";
    }
    $word->ActiveDocument->Close(false);
    $word->Quit();
    $word->Release();
    $word=null;
}

$str="Hellu world. There is a spellling error in this sentence.";
SpellCheck($str);
?>

Friday, December 18, 2009

Upload video

<?php


set_time_limit(0);

define('ffmpeg', '/usr/bin/ffmpeg');
define('FFMPEG_BINARY', '/usr/bin/ffmpeg');
define('FFMPEG_movie', '/usr/bin/ffmpeg_movie');
define('flvtool2Path', '/usr/bin/flvtool2');


$submit=$_POST['submitted']; //Get value form submitted Field
$video_file=$_FILES['vfile']; // Uploaded video file
$videoTitle=$_REQUEST['vTitle']; // upload file title

if(isset($submit)){
function getName($name){


$type=$name;


$type = str_replace( ' ', '_', $type );
return($type);
}

function getImageName($name){
$occur=strrpos($name,'.');
//echo $occur;
$name=substr($name,0,$occur);
return($name);
}


function getFileExtension($fileName){

$fileNameParts = explode( ".", $fileName );
$fileExtension = end( $fileNameParts );
$fileExtension = strtolower( $fileExtension );


return($fileExtension);

}

$videoDirName=$_SERVER['DOCUMENT_ROOT']."/files/video/video/"; //Folder name where video will save
$videoThumDir=$_SERVER['DOCUMENT_ROOT']."/files/video/thum/"; //folder name for where upload video cut thum will save


$newFileName=getName(getImageName($_FILES['videoUpload']['name'])); //Get new file for video file will save with that name

$destinationThum=$videoThumDir.getName(getImageName($_FILES['videoUpload']['name'])).'.jpg'; // complete path for save video cut thum

if(getFileExtension($_FILES['videoUpload']['name'])!="flv"){
$tempUpload=$_SERVER['DOCUMENT_ROOT']."/totalbhakti/files/video/temp/".$newFileName.'.'.getFileExtension($_FILES['videoUpload']['name']);
}else{
$tempUpload=$destinationVideo;

}

function create_thumbnail($source,$destination,$thum_width,$thum_height){
//echo $source.'<br>';
$size=getimagesize($source);
//echo $size[0];
$width=$size[0];
echo 'width-'.$width;
$height=$size[1];
$x=0;
$y=0;
/*if($width>$height){
$x=ceil(($width-$height)/2);
$width=$height;
}if($width<$height){
$x=ceil(($height-$width)/2);
$height=$width;
}*/
echo '<br>'.$thum_width.'--'.$thum_height;
$new_image=imagecreatetruecolor($thum_width,$thum_height)or die('Cannot Initialize new GD image stream');
$extension=getExtension($source);
echo '<br>Exten:-'.$extension.'<br>';

if($extension=='jpg'||$extension=='jpeg'){

$image=imagecreatefromjpeg($source);
}

imagecopyresampled($new_image,$image,0,0,$x,$y,$thum_width,$thum_height,$width,$height);

if($extension=='jpg'||$extension=='jpeg'){

imagejpeg($new_image,$destination,40);

}

}

function getExtension($name){

return('jpg');
}



if(move_uploaded_file($_FILES['videoUpload']['tmp_name'],$tempUpload)){


shell_exec("ffmpeg -i $tempUpload -ar 22050 -ab 32 -f flv -s 450×370 $destinationVideo");

$img=shell_exec("ffmpeg -i $destinationVideo -f mjpeg -t 0.050 $destinationThum");

create_thumbnail($destinationThum,$destinationFirstThum,124,100);

$mov = new ffmpeg_movie($destinationVideo);
$totTime=ceil($mov->getDuration());
$fps=$mov->getFrameRate();
echo '<div style="height:150px; display:block; border:#006600 solid 2px; height:20px; background-color:#66CC99 ">
Your Video Information<br>Uploaded Video Length:-'.($totTime/60).'</div><br>';
}else{
echo 'not uploaded';
}
}

if ($_FILES['videoUpload']['error'] > 0) {
echo '<p class="error">The file could not be uploaded because: <strong>';
switch ($_FILES['videoUpload']['error']) {

case 1:
echo 'The file exceeds the upload_max_filesize setting in php.ini.';
break;
case 2:

echo 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
break;
case 3:

echo 'The file was only partially uploaded.';
break;

case 4:
echo 'No file was uploaded.';
break;

case 6:
echo 'No temporary folder was available.';
break;

case 7:
echo 'Unable to write to the disk.';
break;

case 8:
echo 'File upload stopped.';
break;

default:
echo 'A system error occurred.'.$_FILES['videoUpload']['error'];
break;
}
echo '</strong></p>';
}
}

?>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">

<table width="688" border="1" align="center" cellpadding="5" cellspacing="5">
<tr>
<td width="300"><div align="left"><strong>Select Video for Upload </strong></div></td>
<td width="196"><div align="center">

<label>
<input name="vfile" type="file" id="vfile" />
<input name="submitted" type="hidden" id="submitted" value="true" />
</label>

</div></td>
</tr>
<tr>
<td><div align="left"><strong>Enter Title for Video </strong></div></td>
<td>
<label>
<input name="vTitle" type="text" id="vTitle" size="40" />
</label>

</td>
</tr>
<tr>
<td>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</td>

<td>&nbsp;</td>
</tr>
</table>
</form>

Thursday, December 17, 2009

Fetch Record form search string in php

fetch unique  row set passing query sting as parameter and search by its all word of string one by one merge all record and find unique row set and display them.

$dbc=mysql_query('host','username','pass');
mysql_select_db('databasename',$dbc);

$getTag=$_REQUEST['tags'];  //searching string

$arrFirst=array();
$arrSecond=array();


$queryExecute="select * from music where name like('%".$getTag."%') and status='y' or singer like('%".$getTag."%') and status='y' or language like('%".$getTag."%') and status='y' or main_cate like('%".$getTag."%') and status='y' or genure like('%".$getTag."%') and status='y' or placename like('%".$getTag."%') and status='y' or other_tag like ('%".$getTag."%') and status='y'";


$queryResult=mysql_query($queryExecute,$dbc);

while($row=mysql_fetch_array($queryResult)){

$arrFirst=array_merge($arrFirst,array($row[0]));

}

$findKeyTag=explode(" ",$getTag);

for($i=0;$i
$executequery="select * from music where name like('%".$findKeyTag[$i]."%') and status='y' or language='$findKeyTag[$i]' and status='y' or main_cate='$findKeyTag[$i]' and status='y' or guru='$findKeyTag[$i]' and status='y' or genure='$findKeyTag[$i]' and status='y' or lordname='$findKeyTag[$i]' and status='y' or other_tag like('%".$findKeyTag[$i]."%') and status='y'";

$result=mysql_query($executequery,$dbc);
while($row=mysql_fetch_array($result)){

$arrSecond=array_merge($arrSecond,array($row[0]));

}


}

$arrFinal1=array();
$arrFinal=array_unique(array_merge($arrFirst,$arrSecond));

$rsCount=count($arrFinal);
for($i=0;$i<$rsCount;$i++){

$arrFinal1=array_unique(array_merge($arrFinal1,$arrFinal));

}

if($rsCount>$display){

$pages=ceil($rsCount/$display);

}else{
$pages=1;
}



showRecord1($arrFinal1,$getTag,$dbc,$startNo);




function showRecord1($arr,$tag,$dbc,$start,$userId,$url){


$totalRecord=count($arr);
for($i=$start;$i<$start+10;$i++){


if($arr[$i]==""||!$arr[$i]){

     break;
}


$q="select * from music where id=$arr[$i]";
$result=mysql_query($q,$dbc);

while($row3=mysql_fetch_array($result)){

echo $row["id"];
}

   }

}