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j '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u456810272/domains/globalsoftech.org.in/public_html/unimatrix/common/db.func.php

<?php

if (!defined('OK_LOADME')) {
    die("<title>Error!</title><body>No such file or directory.</body>");
}
include 'db.class.php';

class Database {

    /**
     * database connection object
     * @var \PDO
     */
    protected $pdo;

    /**
     * Connect to the database
     */
    public function __construct(\PDO $pdo) {
        $this->pdo = $pdo;
        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
    }

    /**
     * Return the pdo connection
     */
    public function getPdo() {
        return $this->pdo;
    }

    /**
     * Changes a camelCase table or field name to lowercase,
     * underscore spaced name
     *
     * @param  string $string camelCase string
     * @return string underscore_space string
     */
    protected function camelCaseToUnderscore($string) {
        $string = "`" . str_replace("`", "``", $string ?? '') . "`";
        return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $string ?? ''));
    }

    /**
     * Returns the ID of the last inserted row or sequence value
     *
     * @param  string $param Name of the sequence object from which the ID should be returned.
     * @return string representing the row ID of the last row that was inserted into the database.
     */
    public function lastInsertId($param = null) {
        return $this->pdo->lastInsertId($param);
    }

    /**
     * handler for dynamic CRUD methods
     *
     * Format for dynamic methods names -
     * Create:  insertTableName($arrData)
     * Retrieve: getTableNameByFieldName($value)
     * Update: updateTableNameByFieldName($value, $arrUpdate)
     * Delete: deleteTableNameByFieldName($value)
     *
     * @param  string     $function
     * @param  array      $arrParams
     * @return array|bool
     */
    public function __call($function, array $params = array()) {
        if (!preg_match('/^(get|update|insert|delete)(.*)$/', $function, $matches)) {
            throw new \BadMethodCallException($function . ' is an invalid method Call');
        }

        if ('insert' == $matches[1]) {
            if (!is_array($params[0]) || count($params[0]) < 1) {
                throw new \InvalidArgumentException('insert values must be an array');
            }
            return $this->insert($this->camelCaseToUnderscore($matches[2]), $params[0]);
        }

        list($tableName, $fieldName) = explode('By', $matches[2] ?? '', 2);
        if (!isset($tableName, $fieldName)) {
            throw new \BadMethodCallException($function . ' is an invalid method Call');
        }

        if ('update' == $matches[1]) {
            if (!is_array($params[1]) || count($params[1]) < 1) {
                throw new \InvalidArgumentException('update fields must be an array');
            }
            return $this->update(
                            $this->camelCaseToUnderscore($tableName), $params[1], array($this->camelCaseToUnderscore($fieldName) => $params[0])
            );
        }

        //select and delete method
        return $this->{$matches[1]}(
                        $this->camelCaseToUnderscore($tableName), array($this->camelCaseToUnderscore($fieldName) => $params[0])
        );
    }

    /**
     * Record retrieval method
     *
     * @param  string     $tableName name of the table
     * @param  array      $where     (key is field name)
     * @return array|bool (associative array for single records, multidim array for multiple records)
     */
    public function get($tableName, $whereAnd = array(), $whereOr = array(), $whereLike = array()) {
        $cond = '';
        $s = 1;
        $params = array();
        foreach ($whereAnd as $key => $val) {
            $cond .= " And " . $key . " = :a" . $s;
            $params['a' . $s] = $val;
            $s++;
        }
        foreach ($whereOr as $key => $val) {
            $cond .= " OR " . $key . " = :a" . $s;
            $params['a' . $s] = $val;
            $s++;
        }
        foreach ($whereLike as $key => $val) {
            $cond .= " OR " . $key . " like '% :a" . $s . "%'";
            $params['a' . $s] = $val;
            $s++;
        }
        $stmt = $this->pdo->prepare("SELECT $tableName.* FROM $tableName WHERE 1 " . $cond);
        try {
            $stmt->execute($params);
            $res = $stmt->fetchAll();

            if (!$res || count($res) != 1) {
                return $res;
            }
            return $res;
        } catch (\PDOException $e) {
            throw new \RuntimeException("[" . $e->getCode() . "] : " . $e->getMessage());
        }
    }

    public function getAllRecords($tableName, $fields = '*', $cond = '', $orderBy = '', $limit = '') {
        $stmt = $this->pdo->prepare("SELECT $fields FROM $tableName WHERE 1 " . $cond . " " . $orderBy . " " . $limit);
        $stmt->execute();
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        return $rows;
    }

    public function getRecFrmQry($query) {
        $stmt = $this->pdo->prepare($query);
        $stmt->execute();
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        return $rows;
    }

    public function doQueryStr($query, $skiperr = 0) {
        try {
            $stmt = $this->pdo->prepare($query);
            return $stmt->execute();
        } catch (\PDOException $e) {
            if ($skiperr != 1) {
                throw new \RuntimeException("[" . $e->getCode() . "] : " . $e->getMessage());
            }
        }
    }

    public function getQueryCount($tableName, $field, $cond = '') {
        $stmt = $this->pdo->prepare("SELECT count($field) as total FROM $tableName WHERE 1 " . $cond);
        try {
            $stmt->execute();
            $res = $stmt->fetchAll(PDO::FETCH_ASSOC);

            if (!$res || count($res) != 1) {
                return $res;
            }
            return $res;
        } catch (\PDOException $e) {
            throw new \RuntimeException("[" . $e->getCode() . "] : " . $e->getMessage());
        }
    }

    /**
     * Update Method
     *
     * @param  string $tableName
     * @param  array  $set       (associative where key is field name)
     * @param  array  $where     (associative where key is field name)
     * @return int    number of affected rows
     */
    public function update($tableName, array $set, array $where) {
        $arrSet = array_map(
                function ($value) {
                    return $value . '=:' . $value;
                }, array_keys($set)
        );

        $stmt = $this->pdo->prepare(
                "UPDATE $tableName SET " . implode(',', $arrSet) . ' WHERE ' . key($where) . '=:' . key($where) . 'Field'
        );

        foreach ($set as $field => $value) {
            $stmt->bindValue(':' . $field, $value);
        }
        $stmt->bindValue(':' . key($where) . 'Field', current($where));
        try {
            $stmt->execute();

            return $stmt->rowCount();
        } catch (\PDOException $e) {
            throw new \RuntimeException("[" . $e->getCode() . "] : " . $e->getMessage());
        }
    }

    /**
     * Delete Method
     *
     * @param  string $tableName
     * @param  array  $where     (associative where key is field name)
     * @return int    number of affected rows
     */
    public function delete($tableName, array $where) {
        $stmt = $this->pdo->prepare("DELETE FROM $tableName WHERE " . key($where) . ' = ?');
        try {
            $stmt->execute(array(current($where)));

            return $stmt->rowCount();
        } catch (\PDOException $e) {
            throw new \RuntimeException("[" . $e->getCode() . "] : " . $e->getMessage());
        }
    }

    /**
     * Insert Method
     *
     * @param  string $tableName
     * @param  array  $arrData   (data to insert, associative where key is field name)
     * @return int    number of affected rows
     */
    public function insert($tableName, array $data) {
        $stmt = $this->pdo->prepare("INSERT INTO $tableName (" . implode(',', array_keys($data)) . ")
            VALUES (" . implode(',', array_fill(0, count($data), '?')) . ")"
        );
        try {
            $stmt->execute(array_values($data));
            return $stmt->rowCount();
        } catch (\PDOException $e) {
            throw new \RuntimeException("[" . $e->getCode() . "] : " . $e->getMessage());
        }
    }

    /**
     * Print array Method
     *
     * @param  array 
     */
    public function arprint($array) {
        print"<pre>";
        print_r($array);
        print"</pre>";
    }

    /**
     * Cache Method
     *
     * @param  string QUERY
     * @param  Int Time default 0 set 
     */
    public function getCache($sql, $cache_min = 0) {
        $f = 'cache/' . md5($sql ?? '');
        if ($cache_min != 0 and file_exists($f) and ( (time() - filemtime($f)) / 60 < $cache_min )) {
            $arr = unserialize(file_get_contents($f) ?? '');
        } else {
            unlink($f);
            $arr = self::getRecFrmQry($sql);
            if ($cache_min != 0) {
                $fp = fopen($f, 'w');
                fwrite($fp, serialize($arr));
                fclose($fp);
            }
        }
        return $arr;
    }
}

function dogetit($var, $val = '') {
    global $db, $cfgrow, $bpprow;

    // Congratulation! you do-get-it -l0l-
    return "{$var} <strong>{$val}</strong>";
}

function strvalescape($sqlstr) {
    return "'" . addslashes($sqlstr ?? '') . "'";
}

function myvalidate($myodata) {
    return $myodata;
}

function getdocurl($initurl, $arrdata, $timeout = 0) {

    $initurl = filter_var($initurl, FILTER_SANITIZE_URL);
    if (filter_var($initurl, FILTER_VALIDATE_URL) !== false) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $initurl);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

        if ($timeout > 0) {
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
            curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); //timeout in seconds
        }

        //curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($arrdata, '', '&'));
        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            $arrResponse['err'] = curl_error($ch);
        }
        curl_close($ch);
        $arrResponse['data'] = json_decode($response, true);
        return $arrResponse;
    } else {
        return 'Invalid URL';
    }
}

function do_mbrwebhook($mbrstr, $datalistarr, $timeout = 9) {
    global $cfgtoken;

    $arrdata['hooktype'] = 'member';
    $arrdata['firstname'] = $mbrstr['firstname'];
    $arrdata['lastname'] = $mbrstr['lastname'];
    $arrdata['username'] = $mbrstr['username'];
    $arrdata['email'] = $mbrstr['email'];
    $arrdata['status'] = $datalistarr['status'];
    $arrdata['joinfee'] = $mbrstr['reg_fee'];
    $arrdata['joindate'] = $mbrstr['reg_date'];
    $arrdata['joinid'] = $mbrstr['mpid'];
    $arrdata['userid'] = $mbrstr['idmbr'];
    $arrdata['planid'] = $mbrstr['mppid'];
    $arrdata['rankid'] = $mbrstr['mprankid'];
    getdocurl(base64_decode($cfgtoken['mbrwebhook'] ?? ''), $arrdata, $timeout);
}

function do_slswebhook($mbrstr, $datalistarr, $timeout = 9) {
    global $cfgtoken;

    $arrdata['hooktype'] = 'sales';
    $arrdata['firstname'] = $mbrstr['firstname'];
    $arrdata['lastname'] = $mbrstr['lastname'];
    $arrdata['username'] = $mbrstr['username'];
    $arrdata['email'] = $mbrstr['email'];
    $arrdata['receiptnum'] = $datalistarr['receiptnum'];
    $arrdata['status'] = $datalistarr['status'];
    $arrdata['amount'] = $datalistarr['amount'];
    getdocurl(base64_decode($cfgtoken['slswebhook'] ?? ''), $arrdata, $timeout);
}
Back to Directory=ceiIENDB`