Saturday, 10 March 2012

How to validate multiple checkbox?

var adfa=0;
var chk=document.getElementById("tbl");//table id
for(var i=0;i < chk.rows.length;i++)
{
var inputs = chk.rows[i].getElementsByTagName('input');
if(inputs[0].checked==true)
{
adfa=1;
}
}
if(adfa==1)
{
//alert("true");
if(val=='delete'){
var ans=confirm('Are you sure want to delete?');
if(ans)
document.forms[id].submit();
}
}else
{
alert("No entry was selected to be deleted");
}

Saturday, 3 March 2012

PHP mail with attachment

<?php

//Set Email Subject
$subject = $_POST['sub'];
$message_email=$_POST['message'];
$message_email.='<br><br><br>'.$data;

//define the from \ reply to headers
$headers = "From: darshakkumarshah@mkics.in\r\nReply-To: darshakkumarshah@mkics.in";

//create a unique boundary string to delimit different parts of the email (plain text, html, file attachment)
$random_hash = md5(date('r', time()));

//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks for sending
$attachment = chunk_split(base64_encode(file_get_contents($file_nm)));

//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"
."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"
."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";

//Insert the plain text message.
$message .= strip_tags($data);
$message .= "\r\n\r\n--PHP-alt-$random_hash\r\n"
."Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";

//Insert the html message.
$message .= $message_email;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";

//include attachment
if(isset($_POST['checkbox']))
{
$message .= "--PHP-mixed-$random_hash\r\n"
."Content-Type: application/pdf; name=".$file_nm."\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";
}

//send the email
$mail = mail( $to, $subject , $message, $headers );

?>

Tuesday, 31 January 2012

Dynamic add and remove Textbox with numeric validation using javascript

<script type='text/javascript'>
// Numeric validations
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}

// remove dynamic textbox
function rem(inval)
{
$("#my"+inval+"Div").remove();
}
// add dynamic textbox
// --------------------------------------------------------
// Author : Daxa
// Website : http://www.beyondmart.com/
// modify by : darshakkkumar shah
// modify data :31 jan 2012
// --------------------------------------------------------

var inival=0; // Initialise starting element number

// Call this function to add textbox
function addTextBox()
{
var newArea = add_New_Element();
var htcontents = "<td valign='top'><input type='text' name='quan[]' style='text-align:right' onkeypress='return numbersonly(event)' /></td><td><textarea rows='1' name='desc[]' cols='48'/></textarea></td><td valign='top'><input type='text' name='price[]' style='text-align:right' onkeypress='return numbersonly(event)'/></td><td style='width:50px;padding='0' valign='top'>&nbsp;</td><td valign='top'><span style='cursor:pointer;' onclick='rem("+inival+");'><img src='img/delete.png'></span></td><br/>";
document.getElementById(newArea).innerHTML = htcontents; // You can any other elements in place of 'htcontents'
}


function add_New_Element() {
inival=inival+1; // Increment element number by 1
var ni = document.getElementById('area');
var newdiv = document.createElement('tr'); // Create dynamic element
var divIdName = 'my'+inival+'Div';
newdiv.setAttribute('id',divIdName);
ni.appendChild(newdiv);
return divIdName;
}

</script>

Monday, 21 November 2011

Read the csv file and insert in mysql in php

<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{

$cmpname='';
$uplpath=".";
$fname=$_FILES['upload']['name'];

move_uploaded_file($_FILES['upload']['tmp_name'],$uplpath."/".$fname);
$handle=fopen($uplpath."/".$fname,"r");
if($handle)
{
while(!feof($handle))
{
$str=fgets($handle,4096);
$arr=explode(',',$str);
$cnt = count($arr);
$cmp=$cmpname;
if($cnt>1)
{
$nm=$arr[0];
$mail=$arr[1];

echo $q="insert into test(name,email) values('$nm','$mail')";
$r=mysql_query($q) or die(mysql_error());
header("Location:result.php?suc=1");
}
}
}
else
{
$m=1;
}



}
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data">
<p>
<input type="file" name="upload" id="fileField" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
</body>
</html>

Wednesday, 2 November 2011

How to hide folder without using any software?

cls
@ECHO OFF
title Folder Lock
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Lock goto MDLOCKER
:CONFIRM
echo Are you sure u want to Lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Lock "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to Unlock folder
set/p "pass=>"
if NOT %pass%==enter your password here  goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Lock
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Lock
echo Lock created successfully
goto End
:End

 

///

and then save it in .bat file and then run.

If you are run this file then if folder not exist there then automatically make .

Friday, 14 October 2011

Convert Varchar to Date Format in mysql

SELECT *  FROM `tMembers` where str_to_date(sBirthDay,"%m/%d/%Y") between str_to_date('12/15/1985',"%m/%d/%Y") and str_to_date('09/22/1987',"%m/%d/%Y")

Wednesday, 7 September 2011

Youtube API(Upload video to our website)

First, download Zend Framework......

<?php

//debug
#error_reporting(E_ALL);

//include Zend Gdata Libs
require_once("Zend/Gdata/ClientLogin.php");
require_once("Zend/Gdata/HttpClient.php");
require_once("Zend/Gdata/YouTube.php");
require_once("Zend/Gdata/App/MediaFileSource.php");
require_once("Zend/Gdata/App/HttpException.php");
require_once('Zend/Uri/Http.php');

//yt account info
$yt_user = ' '; //youtube username or gmail account
$yt_pw = '  '; //account password
$yt_source = 'jh'; //name of application (can be anything)

//video path
$video_url = '1.mov';

//yt dev key
$yt_api_key = 'AI39s...'; //your youtube developer key

//login in to YT
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_user,
$password = $yt_pw,
$service = 'youtube',
$client = null,
$source = $yt_source, // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);

$yt = new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key);

$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource($video_url);
$filesource->setContentType('video/quicktime'); //make sure to set the proper content type.
$filesource->setSlug('1.mov');

$myVideoEntry->setMediaSource($filesource);

$myVideoEntry->setVideoTitle('name');
$myVideoEntry->setVideoDescription('desc');
// Note that category must be a valid YouTube category !
$myVideoEntry->setVideoCategory('Comedy');

// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');

// Upload URI for the currently authenticated user
$uploadUrl = "http://uploads.gdata.youtube.com/feeds/users/$yt_user/uploads";
// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if availableor just a regular Zend_Gdata_App_Exception

try {
$newEntry = $yt->insertEntry($myVideoEntry,
$uploadUrl,
'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}

//this outputs a ton of garbage. not sure what to do with it yet.

/*echo "
" . var_dump($newEntry) . "

";
echo "

";*/

$state = $newEntry->getVideoState();

if ($state) {
ehco 'Upload status for video ID ' . $newEntry->getVideoId() . ' is ' .
$state->getName() . ' - ' . $state->getText() . "\n";

} else {
echo "Not able to retrieve the video status information yet. " .
"Please try again later.\n";

}

?>