Tuesday, October 9, 2018

How to download static docx file using php[Solved]

hey Guys, After lot of R&D I found the solution to download docx file using PHP.
Below is the example code.
function downloadDocx(){
$file = 'bikash_university.docx'
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
echo "<h1>Content error</h1><p>The file does not exist!</p>";
}

Friday, September 21, 2018

How to check whether email is read by user using PHP[SOLVED]

Below is the complete code using in php for sending email and read the status if use has opened the mail or not
call the function 
function sendEamil(201, 'bikash ranjan', 'harihar@gmail.com','Harihar','Nayak');
Declared below function to send the email
function sendEamil($id='', $to_name='', $to_address='',$firstName,$lastName){
    $from_name     = 'Bikash ranjan nayak';
    $from_address  = 'nayak.bikash@gmail.com';
    $reply_address  = 'no-reply@gmail.com';    
    $bccEmail    = 'nayak.bikash@yahoo.com';
    $contact_name  = $firstName." ".$lastName;   
    //set hidden url for captured the read mail
    $hiddenUrl      = 'http:127.0.0.1/readmail/readmail.php?type=table&id='.$id;
    
   $maildescription ='<!doctype html>
 <html>
 <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>php technical group</title>
   
 </head>';
  $contentBOdy.= 'Body HTML contents';  
  
  $maildescription.= '<body bgcolor="#ffffff" width="100%" style="margin: 0;" yahoo="yahoo">
    '.$contentBOdy.'
   
    <div style="display:none">
        <img alt="" src="'.$hiddenUrl.'" width="0px" height="0px" />
    </div>
</body>

</html>';
    
// Mail Description ( HTML ) End here
    // Mail Header
    $subject  = "Register form";
    $mime_boundary = "----PHP technical Register form ----".MD5(TIME().$id.TIME());
    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Date:".date('r', $_SERVER['REQUEST_TIME'])."\n";
    $headers .= "Message-ID:<" . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) .$id. "@" . $_SERVER['SERVER_NAME'] . ">\n";
    $headers .= "From:".$from_name."<".$from_address.">\n";
    $headers .= "Bcc:".$bccEmail." \n";
    $headers .= "Reply-To:".$from_name."<".$reply_address.">\n";
    $headers .= "Return-Path:".$from_name."<".$reply_address.">\n";
    $headers .= "X-Mailer: PHP v".phpversion()."\n";
    $headers .= "X-Originating-IP:".$_SERVER['SERVER_ADDR']."\n";
    $headers .= "X-MessageID:".$id."\n";
    $headers .= "X-ListMember:".$to_address."\n";
    $headers .= "Precedence: bulk\n";
    $headers .= "Bounces-To: ".$reply_address."\n";
    $headers .= "List-Unsubscribe: <https://phptechnicalgroups.blogspot.com>\n";
    $headers .= "List-Owner: <mailto:".$from_address.">\n";
    $headers .= "X-Feedback-ID:"."2016:".$id.":event:register\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"$mime_boundary\"\n";
    $setReturnPath = "<webmaster@phptechncalgrop.com>";
    $additional = "-f".$setReturnPath;

    //Create Email Body (HTML)
    $message = "--$mime_boundary\n";
    $message .= "Content-Type: text/html; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= "<html>\n";
    $message .= "<body>\n";
    $message .= $maildescription;
    $message .= "</body>\n";
    $message .= "</html>\n";
    $message .= "--$mime_boundary\n";
    $message .= "Content-Transfer-Encoding: base64\n";
    $mailsent = mail($to_address, $subject, $message, $headers,$additional);
    return ($mailsent)?(true):(false);
  }

Thursday, September 13, 2018

How to read gmail email integration using imap php [Solved]

Hey Every once after a lot of R&D from google, now we could configure the email content read successfully here is the example of how to retrieve the email content.

PHP script email reader.php

here is the complete PHP script 
<?php 
set_time_limit(3000); 
   /* connect to gmail with your credentials */
   $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
   $username = 'Bikash@bikash.com'; 
   $password = 'XXXXX#';
   /* try to connect */
   $inbox = imap_open($hostname,$username,$password);
   /* get all new emails. If set to 'ALL' instead 
    * of 'NEW' retrieves all the emails, but can be 
    * resource intensive, so the following variable, 
    * $max_emails, puts the limit on the number of emails downloaded. 
    */
   //$emails = imap_search($inbox,'ALL');
    $date = date ( "d M Y", strToTime ( "-1 days" ) );
             $emails = imap_search($inbox,'FROM "no-reply@tableau.com" SINCE "'.$date.'"');
   /* useful only if the above search is set to 'ALL' */
   $max_emails = 5;
   /* if any emails found, iterate through each email */
   if($emails) {
                                $count = 1;
    /* put the newest emails on top */
    rsort($emails);
    /* for every email... */
    $ArrayMessage = array();
    foreach($emails as $email_number) {
     //get information specific to this email
     $overviewData = imap_fetch_overview($inbox,$email_number,0);
     //echo '<pre>'; print_r($overviewData);
     if(count($overviewData>0)){
                         $object                      = new stdClass();
    $object->msgno               = trim($overviewData[0]->msgno);
    $object->uid                 = trim($overviewData[0]->uid);
    $object->from                = trim($overviewData[0]->from);
    $object->to                  = trim($overviewData[0]->to);
    $object->subject             = $overviewData[0]->subject;
    $object->message_id          = $overviewData[0]->message_id;
    $object->size                = $overviewData[0]->size;
    $object->recent              = $overviewData[0]->recent;
    $object->flagged             = $overviewData[0]->flagged;
    $object->answered            = $overviewData[0]->answered;
    $object->deleted             = $overviewData[0]->deleted;
    $object->seen                = $overviewData[0]->seen;
    $object->draft               = $overviewData[0]->draft;
    $object->udate               = $overviewData[0]->udate;
//do store your database as per required
}}}
//Hope it will help you!
?>

Wednesday, August 22, 2018

How to send custom email using Joomla[Solved]

Hey Guys,

below is the example custom function for sending email using in joomla function
------------------------------------------------------------------
public function sendRegistrationEmail($sender='', $replyTo='', $replyFromName='', $recipient='', $bcc='', $messageSubject='', $messageBody=''){
$mailer = & JFactory::getMailer();
$mailer->setSubject($messageSubject);
$mailer->Encoding = 'base64';
$mailer->setSender($sender);
$mailer->addRecipient($recipient);
$mailer->addReplyTo($replyTo, $replyFromName);
$mailer->isHTML(true);
$mailer->setBody($messageBody);
$mailer->addBCC($bcc);
$mailsent = & $mailer->Send();
$send = ($mailsent)?(true):(false);
return $send;
}

Monday, August 13, 2018

How to set google GA event category wise?

Please follow the below the example for GA event function used in javascript function.


function call in below example for dynamic Event function .


 setGa('Category Name',' level name');
-----------------------------------------------------------


function setGa(catName,value){
var currentPage = jQuery("#page").val(); 
    var blogType = jQuery('#selectType option:selected').val();
var ajaxHitUrl = window.location.protocol + '//' + window.location.hostname + '/';
if(gaMainURL=='blog'){
var gAUrl = ajaxHitUrl+'datacenter/blog?blogType='+blogType+'&shc_page='+shc_page+'&page='+currentPage;
}else{
var gAUrl = ajaxHitUrl+'datacenter/social-hub/podcast?blogType='+blogType+'&shc_page=1&page='+currentPage;
}

ga('send','event',catName,value.toString(),gAUrl.toString());
ga('set', 'page', gAUrl.toString());
ga('send', 'pageview');

}

Thursday, August 2, 2018

How to create tag in GIT and push to repository?commands

Hi All,

Please find  below  GIT complete commands for developer that can help in  you git command line. I have worked on <buildersqa>  repository branch it configure by IT team and you can clone and pull your branch.


Run below command to proceed

git config --global user.bikash "Bikash ranajn nayak"
git config --global user.nayakr.bikash@gmail.com

git clone git+ssh://bikash@127.0.0.1/home/repository/buildersqa

Step 1 -> Take Checkout git from buildersqa
        git checkout buildersqa

Step2-> Pull the branch from buildersqa
        git pull origin buildersqa

Step3 -> Create won branch
        git checkout -b features/bika_taskName_date

ADD YOU PATCHES your new created branch

Step4-> Commit your branch
       git commit -am "add your comment for "

Step5-> Again checkout to buildersqa
       git checkout buildersqa

Step6-> Again take pull from buildersqa
       git pull origin buildersqa

Step7-> merge your branch to  buildersqa
      git merge –no-commit features/bika_taskName_date

Step8->Commit your branch buildersqa
      git commit -am "add your comment for "

Step9->Create tag version of your branch
      git tag -a bika_v2.0_9April2018 -m "Version 2.0"

Step10->push you tag to buildersqa
       git push origin <tagname>

Step11->Push you branch to buildersqa
       git push origin buildersqa

Finally your code patches available in your tag version on remote server, only you need to provide your tag name to  IT team for pull on  buildersqa server .

Please let in comment if any doubt or any question on this.

Tuesday, July 24, 2018

How to encode Base64 in jvascript and decode in PHP?[solved]

Create a custom function in java script Base64 and decode in PHP in below example.

Javascript.js
------------------------
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}}
-------------------------------------------------------------------------------
send the data through the ajax
-------------------------------------------
var serializedData = 'sending ajax request';

var strData= serializedData.toString();

jQuery.ajax({
url : BaseUrl+'&task=ajaxProductSearch',
type: 'POST',
data: {encriptData:strData},
-------------------------------------------------------------

response.php PHP get value and decode
//GET THE REQUEST FROM AJAX

$postData    = JRequest::getVar('data');

//DECODE BASE64 IN PHP
$postDataBase64Decode  = base64_decode($postData);

Tuesday, July 10, 2018

How to split with delimiter and retrieve the left and right side value?

Hey Guys

We have stored the value of course Name and chapter name in ChapterName  column  

Value stored like : " JAVA : Polymorphism  "

We need to retrieve CourseName :  JAVA and ChapterName : Polymorphism

Below is the SQL select query to retrieve .

SELECT   
SUBSTRING_INDEX(SUBSTRING_INDEX(ChapterName, ' ', 1), ' ', -1) AS CourseName,
    
REPLACE(TRIM(SUBSTR(ChapterName, LOCATE(':', ChapterName)) ),':','') AS ChapterName
FROM Courses where `id`=1;

Friday, May 4, 2018

How change the URL clicking on jquery event?[SOLVED]


Below is the solution for adding URL using jquery event


$("#eventid").click(function() {
window.history.pushState({},'data',baseUrl+'?igq='+keyword+'&program='+program+'&type='+type+'&cat='+encodeURIComponent(CategoriesSelectedData)+'&page='+page); 


}

Friday, March 16, 2018

How to jvalidate the array type input box using jquery[SOLVED]


Hey guy ,

After lot of R&D I have updated the core library for dynamic validation input box for below updated and example , it might be help you for validation.

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>

jQuery(function() {

jQuery("#winner_register").validate({
  errorElement: 'small',
  focusInvalid: true,
  invalidHandler: function(form, validator){
   if (!validator.numberOfInvalids())
   return;
   jQuery('html, body').animate({
   scrollTop: jQuery(validator.errorList[0].element).offset().top-300
   }, 100);
  },
  rules: {
   
   'ftk_email[]': {
    required: true,
    email: true,
   }
   
  },
  messages: {
   
   'ftk_email[]': {
    required: "Please enter FTK Email.",
    email: "Please enter a valid FTK Email.",
   }
   
  },
  submitHandler: function(form) {
   customvalidation();
   jQuery('#ajax_check_send').text('Submitting...');
   form.submit();
   jQuery('#ajax_check_send').text('');
   // avoid to execute the actual submit of the form.
  }
 });

});
<form method="post" name="winner_register" id="winner_register" action="" class="form-validate" autocomplete="off" novalidate="novalidate">
<input type="text" class="required form-control" name="ftk_email[]" id="ftk_email_1" value="" title="Please enter FTK Email.">
<small class="error" generated="true" for="ftk_email_1" style="display:none"></small>
<input type="text" class="required form-control" name="ftk_email[]" id="ftk_email_2" value="" title="Please enter FTK Email.">
<small class="error" generated="true" for="ftk_email_2" style="display:none"></small>
 <input type="submit" name="compAdd" value="Submit" title="Submit" id="submitButton" class="create_btn btn-intel btn">
</form>
updated the below code on jquery validate library
jquery.validate.js
checkForm: function() {
    this.prepareForm();
    for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) {
        if (this.findByName(elements[i].name).length != undefined && this.findByName(elements[i].name).length > 1) {
            for (var cnt = 0; cnt < this.findByName(elements[i].name).length; cnt++) {
                this.check(this.findByName(elements[i].name)[cnt]);
            }
        } else {
            this.check(elements[i]);
        }
    }
    return this.valid();
}