📄 mdb-function.php

Size: 4,702 bytes
Path: /home/islandholiday/public_html/admin/panel/OLD/mdb-function.php
Modified: 2020-10-02 05:04:58
<?php


//======================calculate age from dob===================//
//$date2= date('Y-m-d', strtotime("+6 months", strtotime($row['appDate'])));

function GetAge($dob){
    $dob =strtotime($dob);
    $dateNow =strtotime(date("Y-m-d"));

    $age= 0;
     while($dateNow>$dob = strtotime('+1 year',$dob)){
        ++$age;
     }

     return array($age);
}


//======================calculate amount donated in percentage===================//
function CalculateRrate($cat,$appID,$conn){
    

    $s = $conn->query("SELECT * FROM application a,donnation d,".$cat." f,beneficiary b where a.appID=".$appID." and d.appID=a.appID and f.benID =b.benID");

    $sr = mysqli_fetch_array($s);
    if($sr['amountDonated']>0){
       $a =($sr['amount']-$sr['amountDonated']);
       $b = (100)-(($a*100)/$sr['amount']); 
    }else{
        $b=0;
    }
    
     return array(round($b,2));
}


//=============================Insert into database =======================//

//with field columns
function InsertRowQField($table,$values,$conn){

    // retrieve the keys of the array (column titles)
    $data_values = array_keys($values);

    
    
    // build the query
    $sql = "INSERT INTO ".$table."
    (`".implode('`,`', $data_values)."`)
    VALUES('".implode("','", $values)."')";

    // run and return the query result resource
    $sql1=mysqli_query($conn,$sql);
    $id=mysqli_insert_id($conn);
    return array($sql1,$id);

    
}






//no field columns
function InsertRowQ($table2,$values2,$conn){

        
    // build the query
    $sqlQ = "INSERT INTO ".$table2." VALUES('".implode("','", $values2)."')";

    // run and return the query result resource
    $sql2=mysqli_query($conn,$sqlQ);
    $id2=mysqli_insert_id($conn);
    
    return array($sql2,$id2);
}





//=========================update query=========================//
function updateDb($table4,$values4,$whereSQL4,$conn){

    

    // build the query
    $sqlU = "UPDATE ".$table4." SET ";
    // loop and build the column //
    $sets = array();
    foreach($values4 as $column => $value)
    {
         $sets[] = "`".$column."` = '".$value."'";
    }
    $sqlU .= implode(', ', $sets);

    // append the where statement
    $sqlU .= $whereSQL4;

    // run and return the query result
    return mysqli_query($conn,$sqlU);

}

function deleteDb($table,$whereSQL,$conn){
    $sqlD="DELETE FROM ".$table.' '. $whereSQL;

    // run and return the query result
    return mysqli_query($conn,$sqlD);


}

//========================ENCRYPT URL=====================================//
function encrypt($data){
    $salt='Kuntai];nteChapandee'; //random characters 
    $ecrypt_1=($data).$salt; //add the salt to your url



    $base64 = urlencode(base64_encode($ecrypt_1)); //now encryp the url that is salted

    return $base64;

}




function decrypt($data){
    $base64Dec = base64_decode($data);
    $saltdec=explode('K', $base64Dec);
    $encrypt_2 =($saltdec[0]);

    return $encrypt_2;
}




function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijkl*^mnopqrstuvwxyzABCDEFGH5753$IJKLMNOPQRSTUVWXYZMaembeMabich^!!!@iKimonsta836":><<*H^%$$DC451mkdkghiud3ty6752i78tgd78kJVFRZTTYUoi8y767fcTY';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}


//=============url dencrypt


function urlDencrypt($conn,$data) {

        $a=mysqli_escape_string($conn,$data);
        $b=filter_var($a, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
         $c=base64_decode($b);

    
    return $c;
}

//=================steralize user input

function cleanInput($conn,$data){
    $ab=mysqli_escape_string($conn,$data);
        $cd=filter_var($ab, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
        return $cd;
}


//=================block user====

function BlockUser($conn,$data){
    $uid=decrypt($data);
    $id=mysqli_escape_string($conn,$uid);
        $uid=filter_var($id, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
        $query="UPDATE userlogin SET status = '0' WHERE Uid = '$uid'";

        return mysqli_query($conn,$query);


}

//=================block user====

function UnBlockUser($conn,$data){
    $uid=decrypt($data);
    $id=mysqli_escape_string($conn,$uid);
        $uid=filter_var($id, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
        $query="UPDATE userlogin SET status = '1' WHERE Uid = '$uid'";

        return mysqli_query($conn,$query);


}



?>