Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/php/
Upload File :
Current File : /var/www/cesa.co.za/php/inc_db.php

<?php
include_once("inc_php7.php");

$vatperc = 15;

$fifiten5VatDate = new DateTime("2025-05-01 00:00:00");

if ($fifiten5VatDate->getTimestamp() >= time()) {
    // VAT is still 15%
    $vatperc = 15;
}

$incvat = (100 + $vatperc) / 100;

include_once($_SERVER['DOCUMENT_ROOT'] . "/cfg/config.php");

// echo 'EW_CONN_HOST: ' . EW_CONN_HOST . '<br>';
// echo 'EW_CONN_USER: ' . EW_CONN_USER . '<br>';
// echo 'EW_CONN_PASS: ' . EW_CONN_PASS . '<br>';
// echo 'EW_CONN_DB: ' . EW_CONN_DB . '<br>';
// echo 'WP_HOST: ' . WP_HOST . '<br>';
// echo 'WPDB_USER: ' . WPDB_USER . '<br>';
// echo 'WPDB_PASS: ' . WPDB_PASS . '<br>';
// echo 'WPDB_DB: ' . WPDB_DB . '<br>';
// echo 'MAILDB_USER: ' . MAILDB_USER . '<br>';
// echo 'MAILDB_PASS: ' . MAILDB_PASS . '<br>';
// exit;

$loghost = EW_CONN_HOST;
$logid = EW_CONN_USER;
$logpwd = EW_CONN_PASS;
$dbname = EW_CONN_DB;

$host = $loghost;
$user = $logid;
$password = $logpwd;
$db = $dbname;

$conni = mysqli_connect($loghost, $logid, $logpwd, $dbname);

$conn = mysql_connect($loghost, $logid, $logpwd);
mysql_select_db($dbname);

extract($_REQUEST);

if (!function_exists("LogUserActivity")) {

    function LogUserActivity($sActivity)
    {
        global $conn;

        $sql = "INSERT INTO user_activity (ContactsID, FirstName, Surname, DateAccessed, Activity, FormParams)
	VALUES (" . $_SESSION["CID"] . ", '" . mysql_real_escape_string($_SESSION["firstname"]) . "', '" . mysql_real_escape_string($_SESSION["lastname"]) . "',
	NOW(), '" . mysql_real_escape_string($sActivity) . "', '" . print_r($_POST, true) . "')";

        mysql_query($sql);
    }
}

//this function drives the two above and generates a mailto link. if label isn't set, it just re-obfuscates the email address and uses that as the label
//obfuscate takes a string and replaces most characters with the hexidecimal ordinal equivalent. Note: return string is almost certainly much longer than the original email address

if (!function_exists("obfuscate")) {

    function obfuscate($email)
    {
        $i = 0;
        $obfuscated = "";
        while ($i < strlen($email)) {
            if (rand(0, 2)) {
                $obfuscated .= '%' . dechex(ord($email[$i]));
            } else {
                $obfuscated .= $email[$i];
            }
            $i++;
        }
        return $obfuscated;
    }
}

if (!function_exists("obfuscate_numeric")) {

    //obfuscate_numeric takes a string and replaces the characters with html entity eqivalents. You have to do this if you want to obfuscate the label and have it display normally, or if you just want to obfuscate the "mailto" tag. Note: return string is almost certainly much longer than the plaintext string
    function obfuscate_numeric($plaintext)
    {
        $i = 0;
        $obfuscated = "";
        while ($i < strlen($plaintext)) {
            if (rand(0, 2)) {
                $obfuscated .= '&#' . ord($plaintext[$i]);
            } else {
                $obfuscated .= $plaintext[$i];
            }
            $i++;
        }
        return $obfuscated;
    }
}
if (!function_exists("generate_obfuscated_mailto")) {

    function generate_obfuscated_mailto($email, $label = "")
    {
        if (empty($label))
            $label = $email;
        return sprintf(
            "<a href='%s:%s'>%s</a>",
            obfuscate_numeric('mailto'),
            obfuscate($email),
            obfuscate_numeric($label)
        );
    }
}

if (!function_exists("RemoveXSS")) {

    function RemoveXSS($val)
    {
        // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
        // this prevents some character re-spacing such as <java\0script>
        // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
        $val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);

        // straight replacements, the user should never need these since they're normal characters
        // this prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&#X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
        $search = 'abcdefghijklmnopqrstuvwxyz';
        $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $search .= '1234567890!@#$%^&*()';
        $search .= '~`";:?+/={}[]-_|\'\\';
        for ($i = 0; $i < strlen($search); $i++) {
            // ;? matches the ;, which is optional
            // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
            // &#x0040 @ search for the hex values
            $val = preg_replace('/(&#[xX]0{0,8}' . dechex(ord($search[$i])) . ';?)/i', $search[$i], $val); // with a ;
            // &#00064 @ 0{0,7} matches '0' zero to seven times
            $val = preg_replace('/(&#0{0,8}' . ord($search[$i]) . ';?)/', $search[$i], $val); // with a ;
        }

        // now the only remaining whitespace attacks are \t, \n, and \r
        $ra1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
        $ra2 = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
        $ra = array_merge($ra1, $ra2);

        $found = true; // keep replacing as long as the previous round replaced something
        while ($found == true) {
            $val_before = $val;
            for ($i = 0; $i < sizeof($ra); $i++) {
                $pattern = '/';
                for ($j = 0; $j < strlen($ra[$i]); $j++) {
                    if ($j > 0) {
                        $pattern .= '(';
                        $pattern .= '(&#[xX]0{0,8}([9ab]);)';
                        $pattern .= '|';
                        $pattern .= '|(&#0{0,8}([9|10|13]);)';
                        $pattern .= ')*';
                    }
                    $pattern .= $ra[$i][$j];
                }
                $pattern .= '/i';
                $replacement = substr($ra[$i], 0, 2) . '<x>' . substr($ra[$i], 2); // add in <> to nerf the tag
                $val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
                if ($val_before == $val) {
                    // no replacements were made, so exit the loop
                    $found = false;
                }
            }
        }
        return $val;
    }
}

if (!function_exists("sanitize")) {

    function sanitize(&$input)
    {
        foreach ($input as $key => $value) {
            $input[$key] = RemoveXSS($value);
        }
    }
}

if (!function_exists("systemerror")) {

    function systemerror($errortype, $problem, $pageoccurred, $resolution)
    {
        $title = "$errortype error";
?>
        <html>

        <head>
            <title><?php echo $errortype ?></title>

        </head>

        <body>
            <!-- Start Page Content Here -->

            <table width="700" cellpadding="10" border="0" cellspacing="0">
                <tr>
                    <td valign="top">
                        <div class="outline">
                            <h3><?php echo $errortype ?></h3>
                            <p>
                                An error has occured</b>:
                            </p>
                            <p>
                                "<?php echo $problem ?>"
                            </p>
                            <p>
                                <?php echo $resolution ?>
                            </p>
                            <p>
                                If you are still having trouble and you are sure this is a valid problem please email <a href="mailto:julia@xe.co.za">julia@xe.co.za</a> with a full description of what you were trying to do and be sure to copy the information on this page.
                            </p>
                        </div>
                    </td>
                </tr>
            </table>

            <!-- End Page Content Here -->
        </body>

        </html>
<?php
        die();
    }
}

if (!function_exists("zadate")) {

    function zadate()
    {

        $zadate = gmdate("d F Y", time() + 7200);
        return $zadate;
    }
}

/* * ******************************************************
 * To check if a certain field has been filled out.	*
 * usage: checkIt(variable, question number)		*
 * ****************************************************** */
if (!function_exists("checkIt")) {

    function checkIt($what, $question)
    {
        if ($what == '' || strlen($what) < 1) {
            return false;
        } else {
            return true;
        } //end if else
    }

    //end function
}

/* * *********************************************
 * Function to see if a email address can exist *
 * usage: $bool = checkEmail($email_address)    *
 * ********************************************* */
if (!function_exists("checkEmail")) {

    function checkEmail($email)
    {
        if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) || !eregi("^.+\@(\[?)[-a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$", $email)) {
            return false;
        } else {
            list($user, $domain) = explode(`@`, $email);
            if ((!eregi("^[a-zA-Z0-9\.\-]+$", $user)) || (!eregi("^[a-zA-Z0-9\.\-]+$", $domain))) {
                return false;
            } else {
                return true;
            } //end if else
        } //end if else
    }

    //end function
}

/* * **************************************
 * Function checks to see if there  	*
 * are any numbers in a string.      	*
 * If there are, return true, else  	*
 * return false.                    	*
 * Usage: if(checkForNumbers(string))	*
 * ************************************** */
if (!function_exists("checkForNumbers")) {

    function checkForNumbers($string)
    {
        if (ereg("[0-9]", $string) == 0) {
            return false;
        } else {
            return true;
        } //end if else
    }

    //end function
}

if (!function_exists("log_query")) {

    function log_query() {}
}

if (!function_exists("reCaptcha")) {

    function reCaptcha($sResponse)
    {
        // Key: 6LcoIWUrAAAAAKBLHpjS7GyroBey9G6yhilbpyNa
        // Secret: 6LcoIWUrAAAAANW5m_GMWA9WbBcvOzJkVCO5memV
        $url = 'https://www.google.com/recaptcha/api/siteverify';
        $fields = array(
            'secret' => '6LcoIWUrAAAAANW5m_GMWA9WbBcvOzJkVCO5memV',
            'response' => $sResponse
        );

        //url-ify the data for the POST
        $fields_string = "";
        foreach ($fields as $key => $value) {
            $fields_string .= $key . '=' . $value . '&';
        }
        rtrim($fields_string, '&');

        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

        //execute post
        $result = curl_exec($ch);

        //close connection
        curl_close($ch);
        $resultObj = json_decode($result, true);
        return $resultObj["success"];
    }
}