Tuesday, December 1, 2020

Google Map API Implementation In (Web View and PDF) PHP

Web View Map Sample Code:

<head>

    <title>Report</title>

    <style type="text/css">

      /* Set the size of the div element that contains the map */

      #map1 {

        height: 100%;

        /* The height is 400 pixels */

        width: 100%;

        /* The width is the width of the web page */

      }

    </style>

    <script>

    var latitude = '.$fi_location_lat.'; // php variable value assigning to javascript vaiable

    var longitude = '.$fi_location_lng.'; // php variable value assigning to javascript vaiable

       // Initialize and add the map

      function initMap1() {

        // The map, centered at area

        const map1 = new google.maps.Map(document.getElementById("map1"), {

          zoom: 13,

          center: { lat: latitude, lng: longitude},

        });

        // The marker, positioned at area

        const marker = new google.maps.Marker({

          position: { lat: latitude, lng: longitude},

          map: map1,

        });

      }

    </script>

    <!-- This key is not a valid key and it should be created using google account -->

<script src="https://maps.googleapis.com/maps/api/js?key=ERAIcdszaS7Euddsdsadasd34xdF&callback=initMap1&libraries=&v=weekly"defer>

</script>

</head>

<body>

<div id="map1"></div>

<!-- This is Map display div --> </body></html>


Web View and Image Format Sample Code:

This format map view is especially, used for pdf report writing:

<div class="img-box">

<img src="https://maps.googleapis.com/maps/api/staticmap?center='.$fi_location_lat.','.$fi_location_lng.'&zoom=15&scale=1&size=700x450&maptype=roadmap&format=jpeg&visual_refresh=true&markers=color:red|'.$fi_location_lat.','.$fi_location_lng.'&key=ERAIcdszaS7Euddsdsadasd34xdF">

</div>

Tuesday, October 20, 2020

If API end point is not working in postman or browser please try the below technical methods

Method 1: Check the postman cache and try in new tab.

Method 2: type CTRL+R enter cmd then type ping domainname.com (without http and www) and enter, check if any response is coming.

Method 3: type CTRL+R enter cmd then type

Method 4: type CTRL+R enter drivers then goto this path(C:\Windows\System32\drivers\etc\hosts) and enter edit the host file & add and save it. below line with IP. ie. destination server domain or IP details.

after that try in postman or browser it will work accordingly.

Example.

100.00.00.100 domain.name.com

Monday, October 19, 2020

How To Switch Between Multiple PHP Versions In Ubuntu

 Switch from higher version to lower version

Step 1: login to the server and convert as you as ROOT User

Step 2: Disabling the PHP 7.2 version

root@ip-100-00-00-000:~# sudo a2dismod php7.2 // no space between php7.2

Module php7.2 disabled.

To activate the new configuration, you need to run:

  service apache2 restart

Step 3: service apache2 restart

Step 4: Enabling the PHP 7.0 version:

root@ip-100-00-00-000:~# sudo a2enmod php7.0

Considering conflict php5 for php7.0:

Enabling module php7.0.

To activate the new configuration, you need to run:

  service apache2 restart

Step 5: service apache2 restart.


For this mysql restart is not required

Just keep in mind if mysql or phpmyadmin is not working just restart the mysql 

MYSQL Restart: sudo service apache2 restart


php.ini file location:

/etc/php/7.0/apache2

Thursday, October 8, 2020

From Array to Comma Separated String Values

public function get_branch_details_post(){

     $abm_id = trim($this->post('abm_id'));     

          $branches = $this->branch_model->get_branches($abm_id);

          $branch_list ='';

          if(is_array($branches) && count($branches)>0){

             $i=0;

            foreach ($branches as $row) { 

                if($row['branch_name']!='')

                $branch_list .= $row['branch_name'].','; 

                $i++;

            }

            echo $final_branches = rtrim($branch_list,',');         

          }  

  }

  Output: Abohar, ADIMALY 

Office official mail sending formats

Hi Abc,
Good Morning

Tried reaching you at your mobile however unable to get through.
Sibi from company name this side, I'm supposed to do testing of below mentioned mobile app in trail mail so could you please share me the fresh link of IOS app and other necessary details to initiate the same. Also, if possible, please schedule a call for walkthrough in the second half too.

@xyz
As discussed, kindly share the mobile app and other required details readily available at the moment .

Wednesday, October 7, 2020

Sunday, October 4, 2020

Thursday, October 1, 2020

From Last Month To Current Month Get or Set Any Date Dynamically In PHP & Get Date Difference(How Many Days)

$date1 = date("Y-m-d", strtotime("first day of last month"));

echo $datestart = date('Y-m-d', strtotime("+4 days", strtotime($date1))); // date start 

$date2 = date("Y-m-d", strtotime("first day of this month"));

echo $dateend = date('Y-m-d', strtotime("+4 days", strtotime($date2))); // date end

Output:

2020-09-05

2020-10-05

**************************************************************************************

$from_date = date("Y-m-d", strtotime('2020-09-05'));

$today_date = date('2020-10-01'); //date('Y-m-d');

$date1 = new DateTime($from_date);

$date2 = new DateTime($today_date);

$diff = $date1->diff($date2);

echo $diff->days;

Output: 26

**************************************************************************************

Write PHP code and execute PHP script with online editor

Click here http://www.writephponline.com

Tuesday, September 22, 2020

Developer Time Saving Works & Websites

Method 1: Case Converter is a simple free online tool that converts any text to either lower case, upper case, proper or sentence case.

Example:

Simply copy and paste your text into the text area above and click on the buttons at the bottom to convert it to one of the different cases, including:

“Upper Case” WHICH CONVERTS ALL THE LETTER INTO CAPITALS LIKE THIS.

“Lower Case” which converts all the letters into small letters like this.

“Proper Case” Which Converts The Text So Every Word Has Its First Letter Capitalised Like This

“Sentence Case”. This capitalises the first letter of each sentence, and converts the rest of the text to lower case. So the first letter after every full stop is automatically converted into a capital letter. Click here https://caseconverter.com
or
Click here https://www.mefancy.com/textchange/letter-case-converter.php

Method 2: Replace spaces with underscores

Click here https://www.mefancy.com/textchange/replace-space-underscore.php

QR Code Generator & More
Click here https://www.mefancy.com/fun/qr-code-generator.php
Click here https://www.mefancy.com/fun/
Click here https://www.mefancy.com/html/ultra-html-table-generator.php
Click here https://www.mefancy.com/textchange/text-diff-compare.php
Click here https://www.mefancy.com/addremove/remove-duplicate-word.php
Click here https://www.mefancy.com/html/
Count Characters, Words, Sentences, Lines
Click here https://www.mefancy.com/textchange/count-text.php
Click here https://www.mefancy.com/textchange/capitalize-sentences.php

Add Prefix and/or Suffix (Each Line):
Setp1:
Click here https://www.mefancy.com/addremove/add-prefix-suffix.php


Step2:
Click here https://www.mefancy.com/textchange/merge-text.php


Generate the Email HTML Link Code:

Example: <a href="mailto:test@gmail.com?subject=Mail Subject&body=Body of the Email">Each Click Mail Will Send</a>


Method 3:
Free Comma Separating Tool:
Click here https://delim.co

Method 4:
Simply paste in your serialized string, click "Unserialize", and we'll display your unserialized text in an easy-to-read format.
Click here https://www.unserialize.com

Method 5:
Split Strings by Delimiter
Click here https://www.browserling.com/tools/text-split
or 
Click here https://dostring.com/split-string-online

Method 6:
Live JSON Generator
Click here http://www.objgen.com/json

Friday, September 18, 2020

Simple Mail Send Function In PHP

 <?php

$to  = 'test@gmail.com';

$subject = 'Demo mail subject'

$message = 'Body of the smessage';

mail($to, $subject, $message);

//Or we can send directly like below 

mail('test@gmail.com', 'Demo mail subject', 'Body of the smessage');

//You can check in spam or inbox in mail

?>

Thursday, September 17, 2020

From one server to another server curl call through cron job and debugging methods

After logged in server setting the cron log:

Tab1:

ubuntu@ip-123-00-00-00:~$ sudo -i

root@ip-123-00-00-00:~# crontab -e

crontab: installing new crontab

root@ip-172-31-18-45:~# php /var/www/html/mf_lms_web_live/index.php sfdccron after_lead_status_update_sending_lead_details_to_sfdc >> /home/ubuntu/cron_log

After hitting this above url open one more window like below for output

Checking cron log file in server, setting the cron log:


Tab2:

ubuntu@ip-123-00-00-00:~$

ubuntu@ip-123-00-00-00:~$ sudo -i

root@ip-123-00-00-00:~# cd /var

root@ip-123-00-00-00:/var#  tail -f /home/ubuntu/cron_log 

(OR) ubuntu@ip-123-00-00-00:~$ tail -f /home/ubuntu/cron_log  press enter button below are the output

Cron Already RunningCron Already RunningCron Already RunningCron Already Running


Tab3:

Through curl, we are executing or to run the cron

 root@ip-123-00-00-00:~# curl http://mf-stage.ibbtrade.com/sfdccron/after_lead_status_update_sending_lead_details_to_sfdc

Wednesday, September 2, 2020

MYSQL strict mode issue resolved but each and every time server restart need to run the below commands

 If you set globals in MySQL:

SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';

SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';

This will not set it PERMANENTLY, and it will revert after every restart.

So you should set this in your config file (e.g. /etc/mysql/my.cnf in the [mysqld] section), so that the changes remain in effect after MySQL restart:

Config File: /etc/mysql/my.cnf

MYSQL Restart: sudo service apache2 restart

Tuesday, September 1, 2020

Configure bitbucket access from old user url (https://olduser@bitbucket.org) to new user url (https://newuser@bitbucket.org)

 From bitbucket  to server if another user url already configured('https://olduser@bitbucket.org) and password asking or if not working to configure our own current user bit buket url('https://newuser@bitbucket.org) please follow the below methods:

Goto project repository:

step1:  root@ip-100-00-00-100:~# cd /var/www/html/mf_external_api/

step2:  cd .git (Example: root@ip-100-00-00-100:~# cd /var/www/html/mf_external_api# cd .git)

step3:  ls

step4:  vi config (Ex: root@ip-100-00-00-100:/var/www/html/mf_external_api/.git# vi config)

step5:  press "i" for  edit

step6:  change the "url https://newuser@bitbucket.org"

step7: press "esc" button

step8: press ":wq" used for save and write.

step9: root@ip-172-31-12-217:/var/www/html/mf_external_api/.git# cd ..

step10: then normal steps like bitbucket to server:

        git fetch

password

git stash

git rebase origin/master

git stash pop

Thursday, August 20, 2020

To upload file or video from local to server and from server to local download

 Goto pem file location and

open terminal or git bash with current path

Method1: If you want upload all videos from the directory(*):

scp -i abc-projectname.pem ../r2w-app-videos/* ubuntu@00.000.000.00:/var/www/html/r2w-app-videos

Method2: If any specific video upload:

scp -i abc-xyz.pem ../abc-app-videos/abc-intro-video-english.mp4 ubuntu@00.000.000.00:/var/www/html/abc-app-videos

OR

Method3: Specific drive(F) based approach

Here I mentioned full path location for pem file and video file:

scp -i /f/mfpem/xyz-test.pem /f/abc-app-videos/abc-intro-video-english.mp4 ubuntu@10.000.000.00:/var/www/html/abc-app-videos

Method 4:  Linux

Local to server upload:
scp -i /home/krishna/pems/abc-xyz.pem  MF_Production_android_app_13_06_2019.apk   ubuntu@10.100.00.00:/var/www/html/mf_lms_api/android_app

Server to local download:

scp -i /home/krishna/pems/xyz-project.pem ubuntu@10.00.000.000:/var/www/html/test_apis/public/interface/O8k4Ysdfdf99/field_convertor.json /home/krishna/Downloads


Monday, April 20, 2020

In MYSQL - Restore the data from backup manually like INSERT IGNORE followed by the command

The presence of a unique index in a table normally causes an error to occur if you insert a record into the table that duplicates an existing record in the column or columns that define the index.

Use the INSERT IGNORE command rather than the INSERT command. If a record doesn't duplicate an existing record, then MySQL inserts it as usual. If the record is a duplicate, then the IGNORE keyword tells MySQL to discard it silently without generating an error.

The following example does not error out and at the same time it will not insert duplicate records as well.

mysql> INSERT IGNORE INTO person_tbl (last_name, first_name)
   -> VALUES( 'Jay', 'Thomas');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT IGNORE INTO person_tbl (last_name, first_name)
   -> VALUES( 'Jay', 'Thomas');
Query OK, 0 rows affected (0.00 sec)
Use the REPLACE command rather than the INSERT command. If the record is new, it is inserted just as with INSERT. If it is a duplicate, the new record replaces the old one.

mysql> REPLACE INTO person_tbl (last_name, first_name)
   -> VALUES( 'Ajay', 'Kumar');
Query OK, 1 row affected (0.00 sec)

mysql> REPLACE INTO person_tbl (last_name, first_name)
   -> VALUES( 'Ajay', 'Kumar');
Query OK, 2 rows affected (0.00 sec)
The INSERT IGNORE and REPLACE commands should be chosen as per the duplicate-handling behavior you want to effect. The INSERT IGNORE command keeps the first set of the duplicated records and discards the remaining. The REPLACE command keeps the last set of duplicates and erases out any earlier ones.

Another way to enforce uniqueness is to add a UNIQUE index rather than a PRIMARY KEY to a table.

CREATE TABLE person_tbl (
   first_name CHAR(20) NOT NULL,
   last_name CHAR(20) NOT NULL,
   sex CHAR(10)
   UNIQUE (last_name, first_name)
);
Counting and Identifying Duplicates
Following is the query to count duplicate records with first_name and last_name in a table.

mysql> SELECT COUNT(*) as repetitions, last_name, first_name
   -> FROM person_tbl
   -> GROUP BY last_name, first_name
   -> HAVING repetitions > 1;
This query will return a list of all the duplicate records in the person_tbl table. In general, to identify sets of values that are duplicated, follow the steps given below.

Determine which columns contain the values that may be duplicated.

List those columns in the column selection list, along with the COUNT(*).

List the columns in the GROUP BY clause as well.

Add a HAVING clause that eliminates the unique values by requiring the group counts to be greater than one.

Eliminating Duplicates from a Query Result
You can use the DISTINCT command along with the SELECT statement to find out unique records available in a table.

mysql> SELECT DISTINCT last_name, first_name
   -> FROM person_tbl
   -> ORDER BY last_name;
An alternative to the DISTINCT command is to add a GROUP BY clause that names the columns you are selecting. This has the effect of removing duplicates and selecting only the unique combinations of values in the specified columns.

mysql> SELECT last_name, first_name
   -> FROM person_tbl
   -> GROUP BY (last_name, first_name);
Removing Duplicates Using Table Replacement
If you have duplicate records in a table and you want to remove all the duplicate records from that table, then follow the procedure given below.

mysql> CREATE TABLE tmp SELECT last_name, first_name, sex
   -> FROM person_tbl;
   -> GROUP BY (last_name, first_name);

mysql> DROP TABLE person_tbl;
mysql> ALTER TABLE tmp RENAME TO person_tbl;
An easy way of removing duplicate records from a table is to add an INDEX or a PRIMARY KEY to that table. Even if this table is already available, you can use this technique to remove the duplicate records and you will be safe in future as well.

mysql> ALTER IGNORE TABLE person_tbl
   -> ADD PRIMARY KEY (last_name, first_name);

To avoid sub query use HAVING same query will get total count and take that count and apply with HAVING like WHERE condition

SELECT
  ul.id,
  ul.device_type,
  ul.device_token,
  COUNT(cl.lead_id) AS total_leads
FROM
  custom_leads AS cl
LEFT JOIN
  user_login AS ul ON ul.id = cl.lead_cre_user_id
WHERE
  cl.lead_from = 'dealer-app' AND ul.user_type = '21' AND ul.user_category = 'Dealer' AND ul.sub_type = 'Org'
GROUP BY
  cl.lead_cre_user_id
HAVING
  total_leads >= 10 AND total_leads <= 35