Your IP : 216.73.216.26


Current Path : /home2/wtmwscom/public_html/
Upload File :
Current File : /home2/wtmwscom/public_html/function_lib.php

<?php
$master_income_type_array = array(1 => 'Referral Income', 2 => 'Binary Pair Income', 3 => 'Binary Matching Income', 4 => 'Task Income', 5 => 'Income on Income', 6 => 'Lead Income', 7 => 'Daily Growth Income', 8 => 'Withdrawal', 9 => 'Pin Generation', 10 => 'Fund Transfer', 11=>'level Income');

$master_is_paid_register = true;
/* generate a member id */

function generateId() {
    //$id1 = "";
    $id = rand(1, 9);
    for ($i = 1; $i <= 7; $i++) {
        $id = $id . rand(0, 9);
    }
    //$id =  $id1.  rand(1000000, 9999);

    return $id;
}

/* create a unique user id */

function createId() {
    $id = generateId();
    //global $dbInstance;
    $result = mysqli_query($GLOBALS['connection'],"select uid from user where uid= '" . $id . "'");
    if (mysqlI_num_rows($result)) {
        createId();
    } else {
        return $id;
    }
}

/* mysql_real_escape_string and trim */

function tres($text) {
    return trim(mysqli_real_escape_string($GLOBALS['connection'],$text));
}

/* HEADER LOCATION */

function redirect($location) {
    echo '<script>window.location.href="' . $location . '";</script>';
}

/* Set msg */

function setMessage($message, $type) {
    $_SESSION['SetMessage'] = '<div class="alert alert-dismissible fade in show ' . $type . '"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>' . $message . '</div>';
}

/* get msg */

function getMessage() {
    $GetMessage = @$_SESSION['SetMessage'];
    unset($_SESSION['SetMessage']);
    return $GetMessage;
}

/* get top level id */

function get_top_level_id($uid) {
    $level = array();
    $result = mysqli_query($GLOBALS['connection'],"select placement_id from user where uid = '$uid'");
    if (mysqlI_num_rows($result) != 0) {
        $i = 0;
        while ($row = mysqli_fetch_object($result)) {
            $level[$i][] = $row->placement_id;
        }
        while (TRUE) {
            foreach ($level[$i] as $value) {
                $result = mysqli_query($GLOBALS['connection'],"select placement_id from user where uid = '$value'");
                //if(mysqlI_num_rows($result) != 0){
                while ($row = mysqli_fetch_object($result)) {
                    $level[$i + 1][] = $row->placement_id;
                }
                //}
            }
            if (($level[$i + 1][0] == 100)) {
                break;
            }
            /* elseif(count($level[$i+1]) != 0){
              $i++;
              continue;
              } */ else {
                //return $level;
                //break;
                $i++;
            }
        }
    }
    //else{
    return $level;
    //}
}
function otp_authenticate($redirect_page){
    return; // simply disable otp
    if(!isset($_SESSION['adminid'])) {
        if((!isset($_SESSION['otp_auth']) || $_SESSION['otp_auth'] == FALSE)){
            $_SESSION['otp_redirect'] = $redirect_page;
            redirect("otp.php");
            die;
        }
    }
}
/* get placement_id */

function get_placement_id($child_ids, $placement_id) {
    foreach ($child_ids as $key => $value) {
        foreach ($value as $key => $value2) {
            if ($value2 == $placement_id) {
                $new_placement_id = $value2;
            }
        }
    }
    return $new_placement_id;
}

function close_business_income($date) {
    //$query = "select distinct uid from commission where iaid in ( select iaid from invest_amount where date < $date and status = 0)";
    $query = "select * from commission where date > $date and status = 0"; //die($query);
    $result = mysqli_query($GLOBALS['connection'],$query);
    $uid_array = array();
    while ($row = mysqli_fetch_object($result)) {
        $uid = $row->uid;
        mysqli_query($GLOBALS['connection'],"update user set balance = balance + $row->amount where uid = '$uid' ");
        $uid_array[] = $uid;
    }
    $status_commission = implode("' , '", $uid_array);
    mysqli_query($GLOBALS['connection'],"update commission set status = 1 where uid in ('$status_commission') ");
}

/* get child level with uid */

function get_child_ids($uid) {
    $level = array(array($uid));
    $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$uid'");
    if (mysqlI_num_rows($result) != 0) {
        $i = 1;
        while ($row = mysqli_fetch_object($result)) {
            $level[$i][] = $row->uid;
        }
        while (TRUE) {
            foreach ($level[$i] as $value) {
                $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$value'");
                //if(mysqlI_num_rows($result) != 0){
                while ($row = mysqli_fetch_object($result)) {
                    $level[$i + 1][] = $row->uid;
                }
                //}
            }
            // if($i==4){break;}
            if (!empty($level[$i + 1])) {
                $i++;
                continue;
            } else {
                //return $level;
                break;
            }
        }
    }
    //else{
    return $level;
    //}
}

/* get child level */

function get_child_ids_1($uid) {
    $level = array();
    $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$uid'");
    if (mysqlI_num_rows($result) != 0) {
        $i = 1;
        while ($row = mysqli_fetch_object($result)) {
            $level[$i][] = $row->uid;
        }
        while (TRUE) {
            foreach ($level[$i] as $value) {
                $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$value'");
                //if(mysqlI_num_rows($result) != 0){
                while ($row = mysqli_fetch_object($result)) {
                    $level[$i + 1][] = $row->uid;
                }
                //}
            }
            // if($i==4){break;}
            if (!empty($level[$i + 1])) {
                $i++;
                continue;
            } else {
                //return $level;
                break;
            }
        }
    }
    //else{
    return $level;
    //}
}

function get_child_levels($child_ids) {
    $child_level = array();
    foreach ($child_ids as $key => $value) {
        foreach ($value as $key => $value2) {
            $child_level[] = $value2;
        }
    }
    return $child_level;
}

function get_commission_ids($child_ids, $uid) {
    $commission_level = array();
    foreach ($child_ids as $key => $value) {
        foreach ($value as $key => $value2) {
            $result = mysqli_query($GLOBALS['connection'],"select uid from commission_done where uid = '$uid' AND cid='" . $value2 . "'");
            if (mysqlI_num_rows($result) == 0) {

                $commission_level[] = $value2;
            }
        }
    }
    return $commission_level;
}

function calculate_commission_ids($left_commission_ids, $right_commission_ids, $uid) {

    $n_of_i_left = count($left_commission_ids);
    $n_of_i_right = count($right_commission_ids);

    if ($n_of_i_left <= $n_of_i_right) {
        $j = $n_of_i_left;
    } elseif ($n_of_i_left > $n_of_i_right) {
        $j = $n_of_i_right;
    }

    $i = 0;
    while ($i <= $j) {
        if (isset($left_commission_ids[$i])) {
            $uid1 = $left_commission_ids[$i];

            if (isset($right_commission_ids[$i])) {
                $uid2 = $right_commission_ids[$i];
                $return = mysqli_query($GLOBALS['connection'],"SELECT * FROM `commission` WHERE `for1`='" . $left_commission_ids . "' AND `for2`='" . $right_commission_ids . "' AND `uid`='" . $uid . "'");
                if (mysqlI_num_rows($return) > 0) {
                    // continue;
                }
                mysqli_query($GLOBALS['connection'],"INSERT INTO commission (uid, amount, date,for1,for2) VALUES ('$uid', 500, '" . date('Y-m-d H:i:s') . "','" . $left_commission_ids . "','" . $right_commission_ids . "')");
                mysqli_query($GLOBALS['connection'],"UPDATE `user` SET `balance`=`balance`+500 WHERE `uid`='" . $uid . "'");
                mysqli_query($GLOBALS['connection'],"INSERT INTO commission_done (uid, cid, date) VALUES ('$uid', '" . $uid1 . "', '" . date('Y-m-d H:i:s') . "')");
                mysqli_query($GLOBALS['connection'],"INSERT INTO commission_done (uid, cid, date) VALUES ('$uid', '" . $uid2 . "', '" . date('Y-m-d H:i:s') . "')");
            }
        }
        $i++;
    }
}

function get_top_level_id_6($uid, $arr = array()) {
    $result = mysqli_query($GLOBALS['connection'],"select placement_id from user where uid = '$uid'");
    if (count($arr) == 6) {
        return $arr;
    } elseif ($uid == 100) {
        return $arr;
    }
    if (mysqlI_num_rows($result) > 0) {
        $data = mysql_fetch_array($result);
        $arr[count($arr)] = $data[0];
        return get_top_level_id_6($data[0], $arr);
    } else {
        return $arr;
    }
}

function get_top_level_id_10($uid, $arr = array()) {
    $result = mysqli_query($GLOBALS['connection'],"select placement_id from user where uid = '$uid'");
    if (count($arr) == 10) {
        return $arr;
    } elseif ($uid == 100) {
        return $arr;
    }
    if (mysqlI_num_rows($result) > 0) {
        $data = mysql_fetch_array($result);
        $arr[count($arr)] = $data[0];
        return get_top_level_id_10($data[0], $arr);
    } else {
        return $arr;
    }
}

function calculate_commission($level_ids, $uid) {

    if (isset($level_ids[0])) {
        //echo $level_ids[0]."<br>";
        mysqli_query($GLOBALS['connection'],"INSERT INTO commission (uid, from_id, amount, date) VALUES ('$level_ids[0]', '$uid', 10, '" . date('Y-m-d H:i:s') . "')");
    }
    if (isset($level_ids[1])) {
        //echo $level_ids[1]."<br>";
        mysqli_query($GLOBALS['connection'],"INSERT INTO commission (uid, from_id, amount, date) VALUES ('$level_ids[1]', '$uid', 5, '" . date('Y-m-d H:i:s') . "')");
    }
    if (isset($level_ids[2])) {
        //echo $level_ids[2]."<br>";
        mysqli_query($GLOBALS['connection'],"INSERT INTO commission (uid, from_id, amount, date) VALUES ('$level_ids[2]', '$uid', 5, '" . date('Y-m-d H:i:s') . "')");
    }
    if (isset($level_ids[3])) {
        //echo $level_ids[3]."<br>";
        mysqli_query($GLOBALS['connection'],"INSERT INTO commission (uid, from_id, amount, date) VALUES ('$level_ids[3]', '$uid', 5, '" . date('Y-m-d H:i:s') . "')");
    }
    if (isset($level_ids[4])) {
        //echo $level_ids[4]."<br>";
        mysqli_query($GLOBALS['connection'],"INSERT INTO commission (uid, from_id, amount, date) VALUES ('$level_ids[4]', '$uid', 5, '" . date('Y-m-d H:i:s') . "')");
    }
    if (isset($level_ids[5])) {
        //echo $level_ids[5]."<br>";
        mysqli_query($GLOBALS['connection'],"INSERT INTO commission (uid, from_id, amount, date) VALUES ('$level_ids[5]', '$uid', 15, '" . date('Y-m-d H:i:s') . "')");
    }
}

function get_receiver_ids($amount, $request_id) {
    $receiver_ids = array();
    //$result = mysqli_query($GLOBALS['connection'],"SELECT recid, balance FROM request_amount WHERE balance>0 AND uid!='".$uid."' AND lock_status=0 ORDER BY type DESC, datetime ASC");
    $result = mysqli_query($GLOBALS['connection'],"SELECT recid, balance FROM request_amount WHERE  recid IN ($request_id) ORDER BY type DESC, datetime ASC");
    $total_amount = 0;
    while ($row = mysqli_fetch_object($result)) {
        $receiver_ids[] = $row->recid;
        $total_amount = $total_amount + $row->balance;
        if ($total_amount >= $amount) {
            break;
        }
    }
    return $receiver_ids;
}

function get_receiver_ids_new($amount, $request_id, $donor_refer_id) {
    $receiver_ids = array();
    //$result = mysqli_query($GLOBALS['connection'],"SELECT recid, balance FROM request_amount WHERE balance>0 AND uid!='".$uid."' AND lock_status=0 ORDER BY type DESC, datetime ASC");
    $result = mysqli_query($GLOBALS['connection'],"SELECT recid, uid, balance FROM request_amount WHERE  recid IN ($request_id) ORDER BY type DESC, datetime ASC");
    $total_amount = 0;
    while ($row = mysqli_fetch_object($result)) {
        // get receiver refer id
        $receiver_refer_id = mysqli_fetch_object(mysqli_query($GLOBALS['connection'],"SELECT refer_id FROM user WHERE uid='" . $row->uid . "'"))->refer_id;
        // if donor refer id and receiver refer id is not same then add request id else do not add
        if ($donor_refer_id != $receiver_refer_id) {
            $receiver_ids[] = $row->recid;
            $total_amount = $total_amount + $row->balance;
            if ($total_amount >= $amount) {
                break;
            }
        }
    }
    return $receiver_ids;
}

function get_all_commit_ids() {
    $all_commit_ids = array();
    $result = mysqli_query($GLOBALS['connection'],"SELECT commit_id FROM commit WHERE confirm_status=1");
    while ($row = mysqli_fetch_object($result)) {
        $all_commit_ids[] = $row->commit_id;
    }
    return $all_commit_ids;
}

function get_referral_commit_ids() {
    $referral_commit_ids = array();
    $result = mysqli_query($GLOBALS['connection'],"SELECT commit_id FROM referral_income");
    while ($row = mysqli_fetch_object($result)) {
        $referral_commit_ids[] = $row->commit_id;
    }
    return $referral_commit_ids;
}

function array_remove_by_value($commit_ids, $value) {
    return array_values(array_diff($commit_ids, array($value)));
}

function get_commit_ids($all_commit_ids, $referral_commit_ids) {
    $commit_ids = $all_commit_ids;
    foreach ($referral_commit_ids as $key => $value) {
        $commit_ids = array_remove_by_value($commit_ids, $value);
    }
    return $commit_ids;
}

function get_receiver_commit_ids($commit_id) {
    $receiver_commit_ids = array();
    $result = mysqli_query($GLOBALS['connection'],"SELECT r_commit_id FROM help WHERE commit_id='" . $commit_id . "'");
    while ($row = mysqli_fetch_object($result)) {
        $receiver_commit_ids[] = $row->r_commit_id;
    }
    return $receiver_commit_ids;
}

function get_child_uids($uid) {
    $child_uids = array();
    $result = mysqli_query($GLOBALS['connection'],"SELECT uid FROM user WHERE placement_id='$uid'");
    if (mysqlI_num_rows($result) >= 10) {
        while ($row = mysqli_fetch_object($result)) {
            $child_uids[] = $row->uid;
        }
    }
    return $child_uids;
}

function get_commit_uids($child_uids) {
    $commit_uids = array();
    foreach ($child_uids as $key => $value) {
        $result = mysqli_query($GLOBALS['connection'],"SELECT DISTINCT uid FROM commit WHERE confirm_status=1 AND uid='$value'");
        if (mysqlI_num_rows($result)) {
            while ($row = mysqli_fetch_object($result)) {
                $commit_uids[] = $row->uid;
            }
        }
    }
    return $commit_uids;
}

function get_commit_uids_10($commit_uids) {
    $commit_uids_10 = array();
    foreach ($commit_uids as $key => $value) {
        $commit_uids_10[] = $value;
        if (count($commit_uids_10) == 10) {
            break;
        }
    }
    return $commit_uids_10;
}

function get_commit_uids_100($commit_uids) {
    $commit_uids_100 = array();
    foreach ($commit_uids as $key => $value) {
        $commit_uids_100[] = $value;
        if (count($commit_uids_100) == 100) {
            break;
        }
    }
    return $commit_uids_100;
}

function get_commit_uids_1000($commit_uids) {
    $commit_uids_1000 = array();
    foreach ($commit_uids as $key => $value) {
        $commit_uids_1000[] = $value;
        if (count($commit_uids_1000) == 1000) {
            break;
        }
    }
    return $commit_uids_1000;
}

function get_terminal_id($placement_id, $position) {
    do {
        $result = mysqli_query($GLOBALS['connection'],"SELECT uid FROM user WHERE placement_id='$placement_id' AND position='$position'");
        $row = mysqli_fetch_object($result);
        if (mysqlI_num_rows($result) == 1) {
            $placement_id = $row->uid;
            continue;
        } else {
            break;
        }
    } while (TRUE);
    return $placement_id;
}

function get_count_child_ids($uidp, $position) {
    $count = 0;

    if ($position == 'L') {
        $uid = mysqli_fetch_object(mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$uidp' and position='L'"))->uid;
    } elseif ($position == 'R') {
        $uid = mysqli_fetch_object(mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$uidp' and position='R'"))->uid;
    }

    if (!empty($uid)) {
        $level = array(array($uid));
        $count++;
//echo "select uid from user where placement_id = $uid";
        $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$uid'");
        if (mysqlI_num_rows($result) != 0) {
            $i = 1;
            while ($row = mysqli_fetch_object($result)) {
                $level[$i][] = $row->uid;
                $count++;
            }
            while (TRUE) {
                foreach ($level[$i] as $value) {
                    $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$value'");
                    //if(mysqlI_num_rows($result) != 0){

                    while ($row = mysqli_fetch_object($result)) {
                        $level[$i + 1][] = $row->uid;
                        $count++;
                    }
                    //}
                }
                // if($i==4){break;}
                if (!empty($level[$i + 1])) {
                    $i++;
                    continue;
                } else {
                    //return $level;
                    break;
                }
            }
        }
    }
    //else{
    return $count;
    //}
}

function get_child_ids_2($uid, $position) {
    $level = array();
    $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$uid' AND position='$position'");
    if (mysqlI_num_rows($result) != 0) {
        $i = 1;
        while ($row = mysqli_fetch_object($result)) {
            $level[$i][] = $row->uid;
        }
        while (TRUE) {
            foreach ($level[$i] as $value) {
                $result = mysqli_query($GLOBALS['connection'],"select uid from user where placement_id = '$value'");
                //if(mysqlI_num_rows($result) != 0){

                while ($row = mysqli_fetch_object($result)) {
                    $level[$i + 1][] = $row->uid;
                }
                //}
            }
            // if($i==4){break;}
            if (!empty($level[$i + 1])) {
                $i++;
                continue;
            } else {
                //return $level;
                break;
            }
        }
    }
    //else{
    return $level;
    //}
}

function get_commitment($child_ids) {
    $amount = 0;
    foreach ($child_ids as $key => $value) {
        $result = mysqli_query($GLOBALS['connection'],"SELECT SUM(amount) as amount FROM commit WHERE uid = '$value'");
        if (mysqlI_num_rows($result)) {
            $row = mysqli_fetch_object($result);
            $amount = $amount + $row->amount;
        }
    }
    return $amount;
}

function get_commitment_today($child_ids) {
    $amount = 0;
    $date = date('Y-m-d');
    foreach ($child_ids as $key => $value) {
        $result = mysqli_query($GLOBALS['connection'],"SELECT SUM(amount) as amount FROM commit WHERE uid = '$value' AND datetime LIKE '%$date%'");
        if (mysqlI_num_rows($result)) {
            $row = mysqli_fetch_object($result);
            $amount = $amount + $row->amount;
        }
    }
    return $amount;
}

function get_transacts($child_ids) {
    $amount = 0;
    foreach ($child_ids as $key => $value) {
        $result = mysqli_query($GLOBALS['connection'],"SELECT SUM(amount) as amount FROM commit WHERE uid = '$value' AND confirm_status=1");
        if (mysqlI_num_rows($result)) {
            $row = mysqli_fetch_object($result);
            $amount = $amount + $row->amount;
        }
    }
    return $amount;
}

function send_sms($mobile, $message) {

    if (!empty($mobile) && !empty($message)) {
        $username = 'fastmoneyflow';
        $password = 'Indoreoffice@123';
        $senderid = 'FastMo';
        $url = "http://mysmsshop.in/http-api.php";
        $param = "username=$username&password=$password&senderid=$senderid&route=1&number=$mobile&message=$message";
       // die($url."?".$param);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
        curl_setopt($ch, CURLOPT_POST, 1);
        //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        // close cURL resource, and free up system resources
        curl_close($ch);
        //echo $result;
    }
}

//function send_sms($mobile, $message) {
//    /*
//    if (!empty($mobile) && !empty($message)) {
//        $uname = 'wtmitluser';
//        $pass = 'anoopoffice123';
//        $senderid = 'flexyc';
//        $url = "http://trans.smsmantra.in/api/v3/sendsms/plain";
//        //$param = "uname=$uname&pass=$pass&send=$senderid&dest=91$mobile&msg=$message";
//        //die($url."?".$param);
//        $ch = curl_init();
//        curl_setopt($ch, CURLOPT_URL, $url);
//        curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$uname&password=$pass&sender=$senderid&GSM=91$mobile&SMSText=$message");
//        curl_setopt($ch, CURLOPT_POST, 1);
//        //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//        curl_exec($ch);
//        // close cURL resource, and free up system resources
//        curl_close($ch);
//        //echo $result;
//    }
//     * 
//     */
//}

function get_user($uid) {
    $name = mysqli_fetch_object(mysqli_query($GLOBALS['connection'],"SELECT login_id, name FROM user WHERE uid='$uid'"))->name;
    return $name;
}

function get_user_detail($uid) {
    $user_detail = mysqli_fetch_object(mysqli_query($GLOBALS['connection'],"SELECT * FROM user WHERE uid='$uid'"));
    return $user_detail;
}

/////////////////// 15 dec 2015 by jay begin ///////////////////
function get_commission_uid5($uid) {
    if ($uid == 100)
        return array();
    $id_array = array();
    $i = 1;
    do {
        $manager_id = mysqli_fetch_object(mysqli_query($GLOBALS['connection'],"select manager_id from user where uid = '$uid' "))->manager_id;
        $id_array[] = $manager_id;
        $uid = $manager_id;
        $i++;
        //if($refer_id == 100 || $i == 5) break;
    } while (($i <= 5) && ($manager_id != 100));
    return $id_array;
}

function set_commission_1d($level, $amount, $commit_id) {
    foreach ($level as $key => $uid) {

        if ($uid != 0) { // if user id exist
            
            switch ($key) {
                case 0: $percentage = 0.05;
                    break;
                case 1: $percentage = 0.03;
                    break;
                case 2: $percentage = 0.01;
                    break;
                case 3: $percentage = 0.005;
                    break;
                case 4: $percentage = 0.001;
                    break;

                default: $percentage = 0;
                    break;
            }
            //$commision_amount = $key == 0 ? ($amount * 0.05) : ($amount * 0.02); // 5% for 1st level and next 4 level 2%
            $commision_amount = $percentage * $amount;
             mysqli_query($GLOBALS['connection'],"UPDATE `manager_income` SET `confirm_status` = '1' WHERE `commit_id` = '$commit_id' AND `uid` = '$uid' ");
            mysqli_query($GLOBALS['connection'],"UPDATE user SET manager_wallet = manager_wallet + '$commision_amount' WHERE uid='" . $uid . "'");
        }
    }

    //}
}

function close_business_income_1($date) {
    //$query = "select distinct uid from commision where iaid in ( select iaid from invest_amount where date < $date and status = 0)";
    $query = "select * from commision where date > $date and status = 0"; //die($query);
    $result = mysqli_query($GLOBALS['connection'],$query);
    $uid_array = array();
    while ($row = mysqli_fetch_object($result)) {
        $uid = $row->uid;
        //$balance = mysqli_fetch_object(mysqli_query($GLOBALS['connection'],"select sum(amount) from commision where uid = '$uid'"));
        mysqli_query($GLOBALS['connection'],"update user set balance = balance + $row->amount where uid = '$uid' ");
        $uid_array[] = $uid;
    }
    $status_commision = implode("' , '", $uid_array);
    mysqli_query($GLOBALS['connection'],"update commision set status = 1 where uid in ('$status_commision') ");

    mysqli_query($GLOBALS['connection'],"update invest_amount set status = 1 where date > $date and status =0 ");
}

function send_sms_email_link($donor_user_id, $reciever_user_id, $amount) {

    //written by Ritu Sharma at 23/12/2015

    $mobile_result = mysqli_query($GLOBALS['connection'],"SELECT uid, login_id, name, mobile, email FROM user WHERE uid IN($donor_user_id,$reciever_user_id) ");
    while ($mobile_row = mysqli_fetch_object($mobile_result)) {
        if ($mobile_row->uid == $donor_user_id) {
            $donor_name = $mobile_row->name;
            $donor_mobile = $mobile_row->mobile;
            $donor_login_id = $mobile_row->login_id;
            $donor_email_id = $mobile_row->email;
        } else if ($mobile_row->uid == $reciever_user_id) {
            $reciever_name = $mobile_row->name;
            $reciever_mobile = $mobile_row->mobile;
            $reciever_login_id = $mobile_row->login_id;
            $reciever_email_id = $mobile_row->email;
        }
    }
    $donor_messsage = "Dear $donor_name ($donor_login_id), you have to help $amount to $reciever_name ($reciever_login_id, Mo. $reciever_mobile";
    $donor_email_message = "Dear $donor_name <br/> you have to help $amount to $reciever_name ($reciever_login_id)";
    send_sms($donor_mobile, $donor_messsage);
//    $headers = 'MIME-Version: 1.0' . "\r\n";
//    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//    $headers .= "From: info@flexyclub.net";
//    mail($donor_email_id, "Flexyclub.net give help details", $donor_email_message, $headers);
    send_phpmailer_mail($donor_email_id, "Flexyclub.net give help details", $donor_email_message);

    $reciever_message = " Congratulation!!! $reciever_name ($reciever_login_id), you will recieve help of $amount from $donor_name($donor_login_id), Mo. $donor_mobile ";
    $reciever_email_message = " Congratulation!!!! $reciever_name <br/> you will recieve help of $amount from $donor_name($donor_login_id) ";
    send_sms($reciever_mobile, $reciever_message);
    //mail($reciever_email_id, "Flexyclub.net receive help details", $reciever_email_message, $headers);
    send_phpmailer_mail($reciever_email_id, "Flexyclub.net receive help details", $reciever_email_message);
}

/////////////////// 15 dec 2015 by jay end ///////////////////

function send_phpmailer_mail($to, $subject, $message){
    
    $mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'helpndiahelp.biz';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'mail@helpndiahelp.biz';                 // SMTP username
$mail->Password = 'indoreoffice@123';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                    // TCP port to connect to

$mail->setFrom('mail@helpndiahelp.biz', ' Wtm WebShop');
//$mail->addAddress('ritu@wtmit.com', 'Ritu Sahrma');     // Add a recipient
$mail->addAddress($to);               // Name is optional
$mail->addReplyTo('mail@helpndiahelp.biz', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $subject;
$mail->Body    = $message;
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    return FALSE;
    //echo 'Message could not be sent.';
    //echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    return TRUE;
    //echo 'Message has been sent';
}
}
function converCurrency($from_Currency,$to_Currency,$amount){
 /*$url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to"; 
 $request = curl_init(); 
 $timeOut = 0; 
 curl_setopt ($request, CURLOPT_URL, $url); 
 curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1); 
 //curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); 
 curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut); 
 $response = curl_exec($request); 
 curl_close($request); 
 //return $response;
 $regularExpression     = '#\<span class=bld\>(.+?)\<\/span\>#s';
    preg_match($regularExpression, $response, $finalData);
    return $finalData[0];
  * */
  
    $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
  $get = explode("<span class=bld>",$get);
  $get = explode("</span>",$get[1]);  
  $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
  return $converted_amount;
 }
 
 
 function get_top_referral_id_n($uid, $level_no, $arr = array()) {
    
    if ($level_no != -1 && count($arr) == $level_no) {
        return $arr;
    } else if ($uid == 100) {
        return $arr;
    }
    //echo " select placement_id from user where uid = '$uid' <br/>";
    $result = mysqli_query($GLOBALS['connection'], "select refer_id from user where uid = '$uid'");
    if (mysqli_num_rows($result) > 0) {
        $data = mysqli_fetch_array($result);
        $arr[count($arr)] = $data[0];
        return get_top_referral_id_n($data[0], $level_no, $arr);
    } else {
        return $arr;
    }
}
?>