Thursday, February 1, 2024

Select and Insert value from dropdown multiple, write and insert multiple values

 Hello. 

Today I want to show you how to select values from dropdown, Write or insert values from dropdown and save to database and manage it.




DB table name : maternal_disease

fields: mdid, cid, shortname, status, display, createdby, createdate, updatedby, updatedate

main php file code : 

<div class="col-sm-4">
                                        <input type="hidden" name="jobskillarray" id="jobskillarray" value="">
                                        <p id="jobskillmsg"></p>
                                        <div id="servicesList2" class="servicesList2"> </div>
                                        <input type="text" name="tag_name2" id="tag_name2" placeholder="Required Skills" list="skilllist2">
                                         
                                        <button type="button" class="btn btn-primary" id="addSkillBtn2">Add This Disease</button>
                                        <datalist id="skilllist2">
                                          <?php foreach ($maternalDiseaseList as $tag) { ?>
                                               <option ><?php echo $tag['shortname'] ?></option>
                                          <?php } ?>
                                        </datalist>
                                        
                                    </div>
<script type="text/javascript">
        $(document).ready(function() {
        var quotations = [];
        var quotations_id = [];
        $('#addSkillBtn2').click(function(e) {
          //debugger;
          var len = quotations_id.length;
          $("#jobskillmsg").html('');
          if (len < 15)
          {
              let tag_name2 = $('#tag_name2').val();
              let tagname2 = tag_name2.slice(0, 100);
              $("#skillMsg").html('');
              console.log(quotations);
              //console.log(quotations_id);
              //debugger
              var data = {};
              if ( tagname2.length >= 2 ){
                //if ($.inArray(tagname2, quotations) == 0) { 
                if ($.inArray(tagname2, quotations) >= 0) { 
                    console.log(quotations);
                } 
                else {
                  //console.log(quotations);
                  //console.log(quotations_id);
                  //debugger;
                  $.ajax({
                        url: 'ajax.php',
                        type: 'POST',
                        dataType: 'json',
                        data: {set_maternal_disease: tagname2},
                        //processData: false,
                        //contentType: false,
                        beforeSend: function(){
                              $('#mydiv').show();
                            },
                        success: function(response) {
                          $('#mydiv').hide();
                          //console.log(quotations);
                          //console.log(quotations_id);
                          //debugger;
                            if (response.message == 'success') {
                               var itemname = response.data.name;
                                var itemid = response.data.id;
                                    //console.log('Value Not exists');
                                    quotations.push(itemname);
                                    quotations_id.push(itemid);
                                    var item = document.createElement("p");
                                    var skillli = '<span class="skillable" data-value="'+response.data.id+'" data-name="'+response.data.name+'" id="js_'+response.data.id+'" ><label for="">'+response.data.name+'</label><i title="delete this skill" id="icon-minus2" class="red right icon-minus-sign"> x </i></span>';
                                    item.innerHTML = skillli;
                                    document.getElementsByClassName("servicesList2")[0].append(item);
                                    $('#tag_name2').val('');
                                  //console.log(quotations);console.log(quotations_id);
                                  $('#jobskillarray').val(quotations_id);
                               
                            } else if (response.message == 'duplicate') {
                              // setTimeout(function() {
                              //     $("#skillMsgDuplicate").hide('blind', {}, 500)
                              // }, 5000);
                               $("#skillMsg").html("<div class='col-md-12'><div class='alert alert-warning'><strong>Sorry! </strong> Duplicate skill cannot be added. </div> </div>");
                            } else if (response.message == 'limit') {
                              // setTimeout(function() {
                              //     $("#skillMsgLimit").hide('blind', {}, 500)
                              // }, 5000);
                              $("#skillMsg").html("<div class='col-md-12'><div class='alert alert-danger'><strong>Sorry! </strong> Maximum 5 skills are allowed. </div> </div>");
                            } else {
                              alert('Error! Try again or refresh page.');
                            }
                        },
                        error: function() {
                          $('#mydiv').hide();
                            alert('Error occurred while adding the skill.');
                        }
                  });
                  return false; 
                  } //end if check value exist
              }
          } 
          else
          { 
            $("#jobskillmsg").html("<div class='col-md-12'><div class='alert alert-danger'><strong>Sorry! </strong> Maximum 15 Disease are allowed. </div> </div>");
          }
          console.log(quotations);
          console.log(quotations_id);
        });
        //end skill to post ajax
        //remove jobpost skill by modal
        $(document).on('click','#icon-minus2',
        function() 
        {
          var y = quotations_id;
          //if (confirm("Are you sure?")) {
            var $list =  $("#servicesList");
            listValue = $(this).parent().data('value');
            listName = $(this).parent().data('name');
            //alert(listValue);
            if (listValue !== '') {
              $("p span#js_"+listValue).remove();
              quotations_id = jQuery.grep(quotations_id, function(value) {
                        return value != listValue;
                      });
              $('#jobskillarray').val(quotations_id);
              quotations = jQuery.grep(quotations, function(value) {
                        return value != listName;
                      });
              //console.log(quotations_id);
              //console.log(quotations);
            }
              
          //}         
        });
        //end
        });
    </script>


ajax.php

//display maternal disease
if(isset($_POST['set_maternal_disease'])){
    $id_edit = string_sanitize(trim($_POST['set_maternal_disease']));
    
    $userid = $_SESSION['userid'];
    $cid = $_SESSION['cid'];
    $createddate = date("Y-m-d H:i:s");
    $disease = mb_substr($id_edit, 0, 100);
    $sql = "SELECT shortname, mdid FROM `maternal_disease` WHERE `shortname` = '".$disease."' AND `cid` = '".$cid."' AND `status` = '1' AND `display` = '1' ";
    $myquery = mysqli_query($db_conx, $sql);
    if(mysqli_num_rows($myquery) == 1)
    {
        $row = mysqli_fetch_assoc($myquery);
        $mdid = $row['mdid'];
        $shortname = $row['shortname'];
    } elseif (mysqli_num_rows($myquery) == 0) {
        //insert data
        $sql = "INSERT INTO `maternal_disease` (`cid`, `shortname`, `createdby`, `createddate`) VALUES ('".$cid."', '".$disease."', '".$userid."', '".$createddate."')";
        $insertDisease = mysqli_query($db_conx, $sql);
        if ($insertDisease === TRUE){
            $mdid = mysqli_insert_id($db_conx);
            $shortname = $disease;
        }
    } else {
    }
    $responseData = [
                    'message' => 'success',
                    'data' => ['name'=> $shortname, 
                                'id' => $mdid
                                ],
                ];
    echo json_encode($responseData);
}

Monday, January 29, 2024

God mode in windows system and its details

Hello.

Today I am going to show you GOD Mode in windows operating system. 

What Is the "God Mode" Folder in Windows and How Do I Enable It?

Here are the categories of tools you'll find in God Mode:

  • Administrative Tools
  • AutoPlay
  • Backup and Restore
  • Color Management
  • Credential Manager
  • Date and Time
  • Devices and Printers
  • Ease of Access Center
  • File Explorer Options
  • File History
  • Fonts
  • Indexing Options
  • Infrared
  • Internet Options
  • Keyboard
  • Mouse
  • Network and Sharing Center
  • Pen and Touch
  • Phone and Modem
  • Power Options
  • Programs and Features
  • Region
  • RemoteApp and Desktop Connections
  • Security and Maintenance
  • Sound
  • Speech Recognition
  • Storage Spaces
  • Sync Center
  • System
  • Tablet PC Settings
  • Taskbar and Navigation
  • Troubleshooting
  • User Accounts
  • Windows Defender Firewall
  • Windows Mobility Center
  • Work Folders

Windows 10 God Mode clearly displays the control panel settings in a list and simplifies the access via a central desktop shortcut. We explain how to activate Windows God Mode and what you can achieve with it.




  1. Create a new folder on your desktop. To do this, right-click an empty area of the desktop, hover over New, and then choose Folder.
  2. Name the folder GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}. If you've already created it with a different name, right-click the folder and choose Rename to change it.
  3. Once you hit Enter after changing the name, that name will disappear, and the icon should change into a Control Panel icon.
  4. You can now open the folder to access all the settings inside. You'll find settings for everything from AutoPlay, user accounts, disk optimization, and so on. There are a total of 201 items, but that could vary depending on what version of Windows you're running.
  5. Because it's a standard folder, you can also easily copy settings shortcuts directly onto your desktop for even quicker access. Simply drag and drop the setting you want, and it'll be accessible directly on the desktop.
Note:
You want to access the God Mode only once and without a desktop shortcut? Then just press the shortcut “Windows + R”, type shell:::{ED7BA470-8E54-465E-825C-99712043E01C} in the Run dialog and press “Enter” to bring up the God Mode menu.


Saturday, January 13, 2024

How to data scrap from other website

 Hello.

Today I am going to explain how to scrap data from other website. 

Web scraping requires careful consideration and adherence to ethical and legal standards. Before proceeding, ensure that you have the right to access and scrape the content, according to the website's terms of service.



Suppose we have one website and we want to copy some of its div data.


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scraping Example</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>
<div id="output"></div>
<script>
$(document).ready(function() {
// Set the URL of the target website
var url = 'https://www.portotheme.com/wordpress/porto_landing/';
// Make an AJAX request to fetch the HTML content
$.get(url, function(data) {
// Create a jQuery object from the HTML data
var $html = $(data);
// Use jQuery to select the desired div
var $targetDiv = $html.find('.row.sample-item-list.sample-item-list-loaded.sort-destination');
// Process each item within the div
$targetDiv.find('div.col-sm-6.col-lg-4.col-xxl-3').each(function() {
// Extract data for each item
var title = $(this).find('h3').text();
var link = $(this).find('a').attr('href');
// Get the inline style of the span.sample-item element
var inlineStyle = $(this).find('span.sample-item').attr('style') || '';
// Retrieve data-oi value
var dataOiValue = $(this).find('.sample-item').data('oi');
var fileName = dataOiValue.split('/').pop();
// Display the data in the output div
$('#output').append('<p>Title: ' + title + ', Link: ' + link + ' , filename:'+fileName+'</p>');
});
});
});
</script>
</body>
</html>

Saturday, December 2, 2023

Wordpress theme add css js files right method

Hello

Today I am going to explain how to add css and js files in functions.php in wordpress theme. I was face so much issues when add css and js files. Theme is not display properly as in html view. I saw that I made mistake in include js files. My way is not right. So here I saw you the correct way.

All files are in "assets" folder.

functions.php

function load_stylesheets(){

$theme_version = wp_get_theme()->get( 'Version' );

wp_enqueue_style('bootstrap', get_template_directory_uri().'/assets/vendors/bootstrap/css/bootstrap.min.css', array(), $theme_version, false);

wp_enqueue_style('fontawesome', get_template_directory_uri().'/assets/vendors/fontawesome/css/all.min.css', array(), $theme_version, false);

wp_enqueue_style('tinyslider', get_template_directory_uri().'/assets/vendors/tiny-slider/dist/tiny-slider.css', array(), $theme_version, false);

wp_enqueue_style('owlcarousel1', get_template_directory_uri().'/assets/vendors/owl-carousel/owl.carousel.min.css', array(), $theme_version, false);

wp_enqueue_style('owlcarousel2', get_template_directory_uri().'/assets/vendors/owl-carousel/owl.theme.default.min.css', array(), $theme_version, false);

wp_enqueue_style('animate', get_template_directory_uri().'/assets/vendors/animate/animate.min.css', array(), $theme_version, false);

wp_enqueue_style('iconstyle', get_template_directory_uri().'/assets/vendors/paroti-icons/style.css', array(), $theme_version, false);

wp_enqueue_style('magnific', get_template_directory_uri().'/assets/vendors/jquery-magnific-popup/jquery.magnific-popup.css', array(), $theme_version, false);

wp_enqueue_style('youtube', get_template_directory_uri().'/assets/vendors/youtube-popup/youtube-popup.css', array(), $theme_version, false);

wp_enqueue_style('pstyle', get_template_directory_uri().'/assets/css/paroti.css', array(), $theme_version, false);

wp_enqueue_style('customcss', get_template_directory_uri().'/assets/css/custom.css', array(), $theme_version, false);


//js files

wp_register_script('jquery',get_template_directory_uri().'/assets/vendors/jquery/jquery-3.6.1.min.js',array('jquery'), $theme_version, true);

wp_enqueue_script('jquery');


wp_register_script('bootstrap',get_template_directory_uri().'/assets/vendors/bootstrap/js/bootstrap.bundle.min.js',array('jquery'), $theme_version, true);

wp_enqueue_script('bootstrap');


wp_register_script('tinislider',get_template_directory_uri().'/assets/vendors/tiny-slider/dist/min/tiny-slider.js',array('jquery'), $theme_version, true);

wp_enqueue_script('tinislider');


wp_register_script('validatefile',get_template_directory_uri().'/assets/vendors/jquery-validation/jquery.validate.min.js',array('jquery'), $theme_version, true);

wp_enqueue_script('validatefile');


wp_register_script('wowjs',get_template_directory_uri().'/assets/vendors/wow/wow.js',array('jquery'), $theme_version, true);

wp_enqueue_script('wowjs');


wp_register_script('ajaxchimp',get_template_directory_uri().'/assets/vendors/jquery-ajaxchimp/jquery.ajaxchimp.min.js',array('jquery'), $theme_version, true);

wp_enqueue_script('ajaxchimp');


wp_register_script('jqueryappear',get_template_directory_uri().'/assets/vendors/jquery-appear/jquery.appear.min.js',array('jquery'), $theme_version, true);

wp_enqueue_script('jqueryappear');


wp_register_script('carrousalmin',get_template_directory_uri().'/assets/vendors/owl-carousel/owl.carousel.min.js',array('jquery'), $theme_version, true);

wp_enqueue_script('carrousalmin');


wp_register_script('magnificpopup',get_template_directory_uri().'/assets/vendors/jquery-magnific-popup/jquery.magnific-popup.min.js',array('jquery'), $theme_version, true);

wp_enqueue_script('magnificpopup');


wp_register_script('youtubejquery',get_template_directory_uri().'/assets/vendors/youtube-popup/youtube-popup.jquery.js',array('jquery'), $theme_version, true);

wp_enqueue_script('youtubejquery');


wp_register_script('mainjsfile',get_template_directory_uri().'/assets/js/paroti.js',array('jquery'), $theme_version, true);

wp_enqueue_script('mainjsfile');


wp_register_script('customjs',get_template_directory_uri().'/assets/js/customjs.js',array('jquery'), $theme_version, true);

wp_enqueue_script('customjs');

}

add_action('wp_enqueue_scripts','load_stylesheets');

Thursday, August 24, 2023

Sorting numbers without using inbuilt function

 $result = ['9','2','5','4','3','7'];

for ($i = 0; $i < count($result) - 1; $i++) {

  for ($j = $i + 1; $j < count($result); $j++) {

    if ($result[$i] > $result[$j]) {

      $temp = $result[$i];

      $result[$i] = $result[$j];

      $result[$j] = $temp;

    }

  }

}


echo "<pre>";print_r($result);echo "</pre>";

OUTPUT:

Array
(
    [0] => 2
    [1] => 3
    [2] => 4
    [3] => 5
    [4] => 7
    [5] => 9
)

Encrypt and decrypt password method with key

 Hello Today I saw you how to encrypt and decrypt password.

core PHP:

define ("SECRETKEY", "MyApplicationResult");
function encryptedPassword($password){
return openssl_encrypt($password, "AES-128-ECB", SECRETKEY);
}
function decryptedPassword($password){
return openssl_decrypt($password, "AES-128-ECB", SECRETKEY);
}


CodeIgniter 4:

 public function encrypt_pass($simple_string){
       
        // Store the cipher method
        $ciphering = "AES-128-CTR";
        // Use OpenSSl Encryption method
        $iv_length = openssl_cipher_iv_length($ciphering);
        $options = 0;
        // Non-NULL Initialization Vector for encryption
        $encryption_iv = '1234567891011121';
        // Store the encryption key
        $encryption_key = "MySecretKey";
        return $encryption = openssl_encrypt($simple_string, $ciphering, $encryption_key, $options, $encryption_iv);
     }

    public function decrypt_pass($encryption){
        // Store the cipher method
        $ciphering = "AES-128-CTR";
        // Use OpenSSl Encryption method
        $iv_length = openssl_cipher_iv_length($ciphering);
        $options = 0;
        // Non-NULL Initialization Vector for encryption
        $decryption_iv = '1234567891011121';
        // Store the encryption key
        //$decryption_key = $this->websitekey;
        $decryption_key = "MySecretKey";
        return $decryption=openssl_decrypt ($encryption, $ciphering, $decryption_key, $options, $decryption_iv);
    }

Tuesday, August 22, 2023

Get Browser name, version and operating system name in php

Hello.

Recently I want to know about user's details. SO I use these code for geting browser name, version and operating system name.

Output: 
Browser Name: Google Chrome
Browser Version: 116.0.0.0
Operating System: Windows 10

Code:

$userAgent = $_SERVER['HTTP_USER_AGENT'];

function getBrowserVersion($userAgent, $browserName) {
    $pattern = "";
    switch ($browserName) {
        case "Internet Explorer":
            $pattern = '/MSIE|Trident\/.*rv:([\d\.]+)/';
            break;
        case "Mozilla Firefox":
            $pattern = '/Firefox\/([\d\.]+)/';
            break;
        case "Microsoft Edge":
            $pattern = '/Edge\/([\d\.]+)/';
            break;
        case "Google Chrome":
            $pattern = '/Chrome\/([\d\.]+)/';
            break;
        case "Apple Safari":
            $pattern = '/Version\/([\d\.]+)/';
            break;
        case "Opera":
            $pattern = '/Opera\/([\d\.]+)/';
            break;
    }

    if (preg_match($pattern, $userAgent, $matches)) {
        return $matches[1];
    }

    return "Unknown";
}

function getBrowserInfo($userAgent) {
    if (preg_match('/MSIE|Trident/i', $userAgent)) {
        return "Internet Explorer";
    } elseif (preg_match('/Firefox/i', $userAgent)) {
        return "Mozilla Firefox";
    } elseif (preg_match('/Edge/i', $userAgent)) {
        return "Microsoft Edge";
    } elseif (preg_match('/Chrome/i', $userAgent)) {
        return "Google Chrome";
    } elseif (preg_match('/Safari/i', $userAgent)) {
        return "Apple Safari";
    } elseif (preg_match('/Opera/i', $userAgent)) {
        return "Opera";
    }

    return "Unknown";
}

function getOperatingSystem($userAgent) {
    $os = "Unknown";

    if (preg_match('/Windows NT 10/i', $userAgent)) {
        $os = "Windows 10";
    } elseif (preg_match('/Windows NT 6.3/i', $userAgent)) {
        $os = "Windows 8.1";
    } elseif (preg_match('/Windows NT 6.2/i', $userAgent)) {
        $os = "Windows 8";
    } elseif (preg_match('/Windows NT 6.1/i', $userAgent)) {
        $os = "Windows 7";
    } elseif (preg_match('/Windows NT 6.0/i', $userAgent)) {
        $os = "Windows Vista";
    } elseif (preg_match('/Windows NT 5.1/i', $userAgent) || preg_match('/Windows XP/i', $userAgent)) {
        $os = "Windows XP";
    } elseif (preg_match('/Windows NT 5.0/i', $userAgent)) {
        $os = "Windows 2000";
    } elseif (preg_match('/Windows NT 4.0/i', $userAgent)) {
        $os = "Windows NT 4.0";
    } elseif (preg_match('/Macintosh|Mac OS X/i', $userAgent)) {
        $os = "Mac OS X";
    } elseif (preg_match('/Linux/i', $userAgent)) {
        $os = "Linux";
    } elseif (preg_match('/Unix/i', $userAgent)) {
        $os = "Unix";
    } elseif (preg_match('/Ubuntu/i', $userAgent)) {
        $os = "Ubuntu";
    }

    return $os;
}
$operatingSystem = getOperatingSystem($userAgent);

$browserName = getBrowserInfo($userAgent);
$browserVersion = getBrowserVersion($userAgent, $browserName);

echo "Browser Name: " . $browserName . "<br>";
echo "Browser Version: " . $browserVersion;

echo "<br>Operating System: " . $operatingSystem;