Archive for March, 2012

jQuery UI Datepicker Add Days (check-in,check-out,no. of nights)

by on Tuesday, March 6th, 2012

<div class="cus-select" style="width:90px;">
<input type="text" name="check_in[<?=$_GET['i']?>]" class="custom-sel-box check_in checkin_out"
style="width:90px;" onchange="getDetail('<?=$_GET['i']?>')" >
</div>
<div class="cus-select" style="width:90px; margin-left: 14px;">
<input type="text" name="check_out[<?=$_GET['i']?>]" class="custom-sel-box check_out checkin_out"
style="width:90px;" onchange="getDetail('<?=$_GET['i']?>')" >
</div>


<div class="cus-select" style="width:90px; margin-left: 14px;">
<select name="nights[<?=$_GET['i']?>]" class="custom-sel-box nights" style="width:90px;"
onchange="getDetail('<?=$_GET['i']?>')" >
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>        
</select>
</div>

$( ".checkin_out" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy',
minDate: new Date(),
onSelect:function(v,d){
total_night = parseInt($( ".cust_multi_form_inner<?=$_GET['i']?> .nights" ).val());
check_in = $( ".cust_multi_form_inner<?=$_GET['i']?> .check_in" ).val();
check_out = $( ".cust_multi_form_inner<?=$_GET['i']?> .check_out" ).val();
cal_cls = $(this).attr('class').split(' ')[1];

if(cal_cls=='check_in'){
start = $.datepicker.parseDate('dd-mm-yy', v);
start.setDate(start.getDate()+total_night);
$('.cust_multi_form_inner<?=$_GET['i']?> .check_out').val($.datepicker.formatDate('dd-mm-yy', start));
getDetail('<?=$_GET['i']?>');
}
if(cal_cls=='check_out'){
end = $.datepicker.parseDate('dd-mm-yy', v);
start = $.datepicker.parseDate('dd-mm-yy', check_in);
no_of_nights = (end-start)/(1000*60*60*24);
$('.cust_multi_form_inner<?=$_GET['i']?> .nights').val(no_of_nights);
getDetail('<?=$_GET['i']?>');
}
}
});

$('.nights').change(function(){
total_night = parseInt($(this).val());
start = $.datepicker.parseDate('dd-mm-yy', $('.cust_multi_form_inner<?=$_GET['i']?> .check_in').val());
start.setDate(start.getDate()+total_night);
$( ".cust_multi_form_inner<?=$_GET['i']?> .check_out" ).val($.datepicker.formatDate('dd-mm-yy', start));
getDetail('<?=$_GET['i']?>');
});

Sending multiple files in email using PHP

by on Thursday, March 1st, 2012

<?php

// array with filenames to be sent as attachment
$files = array("emi_pdf/Self_Employee_1330438553.pdf",
"emi_pdf/Self_Employee_1330439327.pdf","emi_pdf/Self_Employee_1330438611.pdf");

// email fields: to, from, subject, and so on
$to = "abc.kumar@gmail.com"; 
$from = "me@domain.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";

$headers = "From: $from";

// boundary 
$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

// headers for attachment 
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

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

// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . 
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . 
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}

// send

$ok = @mail($to, $subject, $message, $headers); 
if ($ok) { 
echo "<p>mail sent to $to!</p>"; 
} else { 
echo "<p>mail could not be sent!</p>"; 
} 

?>