Saturday, December 31, 2016

Fetch record order by date, even date column as varchar or text.

function get_followupleads($executive_id) {
    $query = "SELECT le.lead_id,le.bname,le.bcontact,le.sname,le.scontact,le.veh_reg_no,le.case_category,le.follow_up_date_time,rto.city as rto_location
              FROM  `rto_tb_leads` as le
              LEFT JOIN rto_office as rto ON rto.id = le.rto_location
              WHERE follow_up_date_time IS NOT NULL AND lead_cre_user_id = $executive_id
              ORDER BY STR_TO_DATE( follow_up_date_time,  '%d-%m-%Y' )";
              $result = $this->db->query($query);
    $details = $result->result_array();
    //echo $this->db->last_query();     
    if( is_array($details) && count($details) > 0 ) {
            return $details;
         }
         return false;
    }

Monday, December 5, 2016

Firebase Cloud Messaging (FCM) PUSH Notification Documentation (Android)

Example:1

<?php // Dynamic
    date_default_timezone_set("Asia/Kolkata");
    function save_and_send_push_notification(){

        define('FIREBASE_API_KEY', 'AIzaSyDf-uPyTgxcxckH2JLE6lO0XmygxWmjFpS7BU0'); // this api key created from fcm account panel
                $title = trim($this->input->post('title'));
                $message = trim($this->input->post('message'));
                $type = trim($this->input->post('type')); // 'All', 'Multiple'
                $user_ids = trim($this->input->post('user_ids')); // this is an array type


                    $payload = array();
                    $payload['team'] = 'India';
                    $payload['score'] = '5.6';
                    $global = 'global';
                    $to = '/topics/' . $global;
                   
                    $res = array();
                    $res['data']['title']           = $title;
                    $res['data']['is_background']   = false;
                    $res['data']['message']         = $message;
                    $res['data']['image']           = 'http://images.carandbike.com/car-images/big/bmw/1-series/bmw-1-series.jpg';
                    $res['data']['payload']         = $payload;
                    $res['data']['timestamp']       = date('Y-m-d H:i:s');

                if($type == 'All'){
                        $global = 'global'; // Topic name provided by android developer
                        $to = '/topics/' . $global;
                        $fields = array('to'=>$to,'data'=>$res);

                }else{
                          $to = array("ffe3mf5m454","df68dfrbb5","fgfhf9fg9gfg"); // device tokens
                          $fields = array('registration_ids'=>$to,'data'=>$res);

                }

        $url = 'https://fcm.googleapis.com/fcm/send';
        $headers = array(
                        'Authorization: key=' .FIREBASE_API_KEY,
                        'Content-Type: application/json'
                        );
        //Open connection
        $ch = curl_init();
        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_PROXY, '10.166.105.54:3128'); if curl not working in live server add this line
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
        //Execute post
        $result = curl_exec($ch);
        if ($result === FALSE)
            die('Curl failed: ' .curl_error($ch));
        //Close connection
        echo $result;
        curl_close($ch);
        // finally if the notification sent. insert these information into one table like=> title,message,image,type and user_ids
}
?>
Example:2
    <?php  Static:
    date_default_timezone_set("Asia/Kolkata");
    // old start
      //define('FIREBASE_API_KEY', 'AIzaSyDf-uPxxcxyTgkH2JccczxLE6lO0XmygxWmjFpS7BU0');
      // $to = 'f7paTxPtMNI:APA91bG5FsRdwdB-W-CmKUDg-5mRgqVEvZ4XEycpel4my0ttR6jEw4ZvtqKD_jROxxcxcz3vkKqV-JPr1ablXjHowY9bQOyAP-sM_kK_zpVdbJuQ-bfO4hG9QyFWjf_193xZuxcxc5IZDtChU6SiF';
   
        // new start
        define('FIREBASE_API_KEY', 'AIzaSyB0J97UiXxcxzcuNNsf9fLRxcHGu4WQ3_Oam3wFgI');
       $to = 'eIE-xNAybZU:APA91bGkrLxceE1mFPfkN9vkBtTuQgmE3LASXAN47HDwCkZfiyFziJ1Ae8GYV8FpRXjsYcT5-vC5AGF0pbxavhIL_j8gxyheKlBqnRxxzcX3CSHD0gvkvfzSH2xcxzcxR8iJDYwGb2ZBVjoeCPLfRs8R';
        $payload = array();
        $payload['team'] = 'India';
        $payload['score'] = '5.6';
            $global = 'global';
      // $to = '/topics/' . $global;
       
        $res = array();
        $res['data']['title']           = 'IBB Trade Offers';
        $res['data']['is_background']   = false;
        $res['data']['message']         = '25 % offers on 1 year used cars';
        $res['data']['image']           = 'http://images.carandbike.com/car-images/big/bmw/1-series/bmw-1-series.jpg';
        $res['data']['payload']         = $payload;
        $res['data']['timestamp']       = date('Y-m-d H:i:s');
                $fields = array(
                        'to'    => $to,
                        'data'  => $res,
                        );

        $url = 'https://fcm.googleapis.com/fcm/send';
        $headers = array(
                        'Authorization: key=' .FIREBASE_API_KEY,
                        'Content-Type: application/json'
                        );
        //Open connection
        $ch = curl_init();
        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_PROXY, '10.166.105.54:3128'); if curl not working in live server add this line
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
        //Execute post
        $result = curl_exec($ch);
        if ($result === FALSE)
            die('Curl failed: ' .curl_error($ch));

       //var_dump($result);die;
        //Close connection
        //echo "<pre>"; print_r($fields);
        echo "<pre>"; print_r(json_decode($result));
        echo $result;
        curl_close($ch);
        return $result;
?>

Server Side Validation in Codeigniter and Core PHP

// for server side validation to check all parameters are empty or not, if one parameter value is empty it return false start
        foreach ($this->input->post() as $key => $val){
                $inputArr[$key] = $val;
                unset($inputArr['referid']);
       
        }
    /*foreach ($_POST as $key => $val){ // for core php
                $inputArr[$key] = $val;
        }*/

        foreach($inputArr as $key1 => $value){
            if(empty($value))
            {  
                $response = array( 'status' => 'FALSE', 'message' => 'Some parameters are missing values');
                $this->set_response($response);
                die;
            }
  
        }
        // for server side validation end

**************************** END************************************

**************************** START**********************************
Using jQuery can set the session:
Using Jquery can set the session --> sessionStorage.setItem("rf_possesion",possesion);
get the session name --> sessionStorage.getItem("rf_possesion");
**************************** END************************************

**************************** START**********************************
POSTMAN form submit capture the form post data in controller:
$data = json_decode(file_get_contents("php://input"));

and print the data like this:

echo $data->username;
**************************** END************************************