Manipulating datastore data after loading

by on December 26th, 2012

var restaurantsStore = this.getStore();
var avg_rating;
restaurantsStore.clearFilter();
if ( restaurantsStore !== undefined )
{
restaurantsStore.load({
callback: function(records, operation, success) {
var proxy = restaurantsStore.getProxy(),
message = proxy.getReader().rawData.message;

if( success === false ){
Ext.Msg.alert('Operation Failed', message);
}
else{
var vendor = records[0].get('vendor');
Ext.getCmp('poweredByContainer').setVendor( vendor );

if( vendor === 'O' ){
for ( var index = 0; index < records.length; index++)
{
var phone = records[index].get('phone');
var recordR = restaurantsStore.getAt(index);
Ext.Ajax.request({
modelInstance: recordR,
url: 'restaurants/call_yelp_api/'+phone,
success: function(response, context){
var text = Ext.decode(response.responseText);
if( text.businesses[0] !== undefined )
avg_rating = text.businesses[0].avg_rating;
context.modelInstance.set('overall_rating', (avg_rating/5)*100);

},
failure: function(response){
var textF = response.responseText;
}
});

}
}

}
},
params: params,
scope: this
});

How can i Do Checkbox state maintain In Paging Grid

by on December 7th, 2012

Ques: http://www.sencha.com/forum/showthread.php?99255-How-can-i-Do-Checkbox-state-maintain-In-Paging-Grid

Ans: http://www.sencha.com/forum/showthread.php?61282-Ext.ux.grid.RowSelectionPaging&highlight=pagingselection

install mongodb on redhat centos or fedora linux

by on November 29th, 2012

install mongo on linux/ubuntu:
1. sudo apt-get install mongodb
2. sudo pecl install mongo
3. echo “extension=mongo.so” >> /etc/php5/apache2/php.ini
4. restart apache
5. restart mongodb ( sudo service mongodb restart/start )
install on centos centos 6.3

1. http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/
2. Install php-pecl-mongo rpm package: yum install php-pecl-mongo
3. echo “extension=mongo.so” >> /etc/php.ini
4. service httpd restart
5. restart mongodb ( sudo service mongod restart/start )

set allowBlank dynamically in extjs

by on November 8th, 2012

myField.allowBlank = true;

myField.validateValue(myField.getValue()); //force update

Convert array to object and object to array in PHP

by on November 1st, 2012

convert array to object PHP

$obj = json_decode (json_encode ($var), FALSE);
where $var is an array.

convert object to array PHP

$arr = json_decode( json_encode($var), true);
where $var is an object

 

How to use native php function in cakephp

by on October 23rd, 2012

//your core php code

function __autoload($name) {
require_once($name . ‘.php’);
}

//in cakephp you can use like this

function my_autoloader($name) {
require_once($name . ‘.php’);
}
spl_autoload_register(‘my_autoloader’);

Extjs 4 How to create Password field ?

by on June 29th, 2012

var yourField = new Ext.form.TextField({
fieldLabel: ‘pass’,
inputType: ‘password’    //this is important .. you have to change text to password
});

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

by on 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 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>"; 
} 

?>

Generate a PDF and send as attachment in Email

by on February 29th, 2012

One way:

<?php

// download fpdf class (http://fpdf.org)
require("/fpd/fpdf.php");

// fpdf object
$pdf = new FPDF();

// generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/)
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(40,10, "this is a pdf example");

// email stuff (change data below)
$to = "target@domain.com";
$from = "me@domain.com";
$subject = "send email with pdf attachment";
$message = "<p>Please see the attachment.</p>";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "example.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

// main header (multipart mandatory)
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;

// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";

// send message
mail($to, $subject, "", $headers);

?>

Second way:

<?php

$pdf_name = str_replace(" ", "_", $employee_type).'_'.time();

$query_emi_form = "insert query";
$resultset_emi_queryform = mysql_query($query_emi_form);
$last_id = mysql_insert_id();
$saved = "Query Form Submitted Successfully";
$result1=mysql_query("select * from tbl where id=".$last_id);
$data = '<div align="center"><table width="500" border="1"><tr>
<th scope="col" width="240">&nbsp;Field Name</th>
<th scope="col" width="240">&nbsp;Value</th>
</tr>';
while($row=mysql_fetch_field($result1)){
$f[] = $row;
}
$rows = mysql_fetch_assoc($result1);
for($i=0;$i<count($f);$i++){
$fname = ucfirst(str_replace("_", " ", $f[$i]->name));
$fname_original = $f[$i]->name;
$ff[]=$rows;
$data .="<tr><td>$fname</td><td>$rows[$fname_original]</td></tr>";
}
$data .="</table></div>";
$stringData = '<html><body>'.$data.'</body></html>';

//use this http://www.macronimous.com/resources/Converting_HTML2PDF_using_PHP.asp
require('html2pdf_sample/html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();

$pdf->WriteHTML($stringData);
$pdf->Output("emi_pdf/".$pdf_name.".pdf");

if($emi_query_id){
$result2="select * from tbl_queries where query_id=".$emi_query_id;
$resultset_result = mysql_query($result2);

$resultset = mysql_fetch_array($resultset_result);

$query_no = $resultset['query_no'];

$message = '<html><body>';
$message .='Dear Sir/Mam,<br><br>';
$message .='Greetings from !!!<br><br><br>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Query No:</strong> </td><td>" .$query_no. "</td></tr>";
$message .= "</table>";
$message .='Sincerely,<br><br>';
$message .='Name<br>';
$message .= "</body></html>";

$to = 'email@gmail.com';
$from = "noreply@domainname.com";
$subject = "QUERY NO.-".$query_no;

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = $pdf_name.".pdf";
$fileatt ="emi_pdf/".$filename;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$attachment = chunk_split(base64_encode($data));

// main header (multipart mandatory)
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;

// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
@mail($to, $subject, $message, $headers);
}

?>
Inline
Inline