| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/asap_sites/securepayasap.com/php/ |
Upload File : |
<?php
/**
* /lib/mysql.php
*
* This file contains the MySQL class for connecting and querying the database
*
* @copyright 2016-2021 Synergy Pro Marketing
* @author Aaron Campbell <aaron@synergymentoring.com>
* @license None, All Rights Reserved
* @package Layout
* @filesource
*/
//Heavily modified by Jeremy Johnson to get it working with mysqli because mysql is no longer supported by php 7+
/**
* MySQL is a database connection class for connecting and querying a MySQL database
*
* Example usage:
* $db->query("SELECT * FROM table WHERE field = 1");
*
* @package MySQL
* @author Aaron Campbell <aaron@synergymentoring.com>
* @version $Revision: 1.3 $
* @access public
*/
$db = new MySQL('db.syndbs.com', 'lc2user', 'SYN57CRUZ', 'asap');
class MySQL {
var $lastRecords;
var $lastQuery;
var $lastError;
var $lastID;
var $insert_id;
var $dbh;
/**
* returns the database connection as a standard PHP object
*
* @param string $host The database host address
* @param string $user The database username
* @param string $pass The database password
* @param string $db The name of the database to connect to
*/
function __construct(
$host = null,
$user = null,
$pass = null,
$db = null
) {
$this->connected = false;
if(!empty($db)) {
$this->conn_handle = mysqli_connect($host, $user, $pass, $db);
} else {
$this->conn_handle = mysqli_connect($host, $user, $pass);
}
if ($this->conn_handle) {
$this->connected = true;
$this->dbh = $this->conn_handle;
}
}
/** returns true if databse connects and false if does not */
function is_connected () {
return $this->connected;
}
/**
* returns a queries results as an array
*
* @param string $query_str A standard MySQL query string
*
* @return array On select queries will return an array of records, otherwise will return an empty array
*/
function query ($query_str, $is_assoc=true) {
$this->lastQuery = $query_str;
$records = Array();
if ($this->connected == true) {
$result = mysqli_query($this->conn_handle, $query_str);
$mysqlError = mysqli_error($this->conn_handle);
if (mysqli_errno($this->conn_handle) > 0 && empty($this->lastError)) {
$file_call_stack = debug_backtrace();
$file_call_stack = print_r($file_call_stack, true);
$result = mysqli_query($this->conn_handle,"INSERT INTO lc2systems.db_errors
SET
description = '" . mysqli_real_escape_string($this->conn_handle,$mysqlError) . "',
ip_address = '" . mysqli_real_escape_string($this->conn_handle,$_SERVER['REMOTE_ADDR']) . "',
request_uri = '" . mysqli_real_escape_string($this->conn_handle,$_SERVER['REQUEST_URI']) . "',
filename = '" . mysqli_real_escape_string($this->conn_handle,$_SERVER['SCRIPT_FILENAME']) . "',
HOST = '" . mysqli_real_escape_string($this->conn_handle,$_SERVER['HTTP_HOST']) . "',
site_code = '" . mysqli_real_escape_string($this->conn_handle,$_SESSION['site_code']) . "',
reseller_id = '" . mysqli_real_escape_string($this->conn_handle,$_SESSION['user']) . "',
lead_id = '" . mysqli_real_escape_string($this->conn_handle,$_SESSION['lead']) . "',
version = '" . mysqli_real_escape_string($this->conn_handle,$_SESSION['version']) . "',
call_trace = '" . mysqli_real_escape_string($this->conn_handle,$file_call_stack) . "'
");
}
$this->lastError = $mysqlError;
if ( ! is_bool($result)) {
if($is_assoc) {
while ($rec = mysqli_fetch_assoc($result)) {
$records[] = $rec;
}
} else {
while ($rec = mysqli_fetch_array($result)) {
$records[] = $rec;
}
}
} else {
return $result;
}
$this->lastRecords = $records;
}
$this->last_insert_id();
return $records;
}
function get_results($query) {
$arr = $this->query($query);
$return = array();
if(!empty($arr)) {
foreach($arr as $k=>$v) {
$return[] = (object) $v;
}
}
return $return;
}
function clean($value) {
return mysqli_real_escape_string($this->conn_handle,$value);
}
function affected_rows() {
return mysqli_affected_rows($this->conn_handle);
}
function escape($value) {
return mysqli_real_escape_string($this->conn_handle,$value);
}
/**
* Adds a note to the site note table
*
* @param string $site_code the site for which a note is being saved
* @param array $session_data the standard $_SESSION array
* @param string $note the note content to be saved
* @param array $note_data the note information to be saved
*
* @return int $id if success returns false if failed
*/
function addNote ($site_code, $session_data, $note, $note_data) {
/*
* Example
* --------------------------------------------------------------
$noteData = array(
"client_id"=>$user,
"note_type"=>"client",
"username"=>"aaron",
"first_name"=>"aaron",
"last_name"=>"campbell",
"client_type"=>"client"
);
$note = "Hello World<hr>";
$noteId = $db->addNote($siteCode, $_SESSION, $note, $noteData);
-----------------------------------------------------------------
*/
$site_code = mysqli_real_escape_string($this->conn_handle,$site_code);
$timeclock_id = $session_data['timeclock_id'];
$timeclock_id = ($timeclock_id * 1);
$note = mysqli_real_escape_string($this->conn_handle,$note);
$client_id = $note_data['client_id'];
$client_id = ($client_id * 1);
$note_type = $note_data['note_type'];
$note_type = mysqli_real_escape_string($this->conn_handle,$note_type);
$note_username = $note_data['username'];
$note_username = mysqli_real_escape_string($this->conn_handle,$note_username);
$note_first_name = $note_data['first_name'];
$note_first_name = mysqli_real_escape_string($this->conn_handle,$note_first_name);
$note_last_name = $note_data['last_name'];
$note_last_name = mysqli_real_escape_string($this->conn_handle,$note_last_name);
$client_type = $note_data['client_type'];
$client_type = mysqli_real_escape_string($this->conn_handle,$client_type);
$location = $note_data['location'];
$location = mysqli_real_escape_string($this->conn_handle,$location);
if ( ! empty($site_code)) {
if ($site_code == "surfcrm") {
$site_database = "surfcrm.notes";
} else {
$site_database = "lc2{$site_code}_lc.notes";
}
$query = "
INSERT INTO {$site_database}
SET
site_code = '$site_code',
timeclock_id = '$timeclock_id',
client_id = '$client_id',
client_type = '$client_type',
username = '$note_username',
first_name = '$note_first_name',
last_name = '$note_last_name',
type = '$note_type',
note = '$note',
location = '" . $_SERVER['REQUEST_URI'] . "',
ip_address = '" . $_SERVER['REMOTE_ADDR'] . "'
";
$query = trim($query);
$result = mysqli_query($query);
$id = mysqli_insert_id($this->connHandle);
$id = ($id * 1);
if ($id > 0) {
return $id;
} else {
return false;
}
}
}
/**
* returns true when a query is run with no errors
*
* @return boolean Will return true when query is valid and false if the query is not valid
*/
function valid () {
return ($this->connected && mysqli_errno($this->conn_handle) == 0);
}
/**
* @return integer The error code for MySQL
*
* For codes and descriptions see: https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
* @see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
*/
function errno () {
if ($this->connected) {
return mysqli_errno($this->conn_handle);
} else {
return null;
}
}
/**
* @return string The error description
*/
function error () {
if ($this->connected) {
$mysqlError = mysqli_error($this->conn_handle);
$this->lastError = $mysqlError;
return $mysqlError;
} else {
return "";
}
}
/**
* @return mixed[] Will return the last inserted record's primary key value
*/
function last_insert_id () {
$id = mysqli_insert_id($this->conn_handle);
$this->lastID = $id;
$this->insert_id = $id;
if ($id == 0) {
return null;
} else {
return $id;
}
}
/**
* @return mixed[] Will return the last inserted record's primary key value
*/
function lastInsertId () {
$id = mysqli_insert_id($this->conn_handle);
$this->lastID = $id;
if ($id == 0) {
return null;
} else {
return $id;
}
}
function prettyJSON($json)
{
$result = '';
$level = 0;
$in_quotes = false;
$in_escape = false;
$ends_line_level = NULL;
$json_length = strlen( $json );
for( $i = 0; $i < $json_length; $i++ ) {
$char = $json[$i];
$new_line_level = NULL;
$post = "";
if( $ends_line_level !== NULL ) {
$new_line_level = $ends_line_level;
$ends_line_level = NULL;
}
if ( $in_escape ) {
$in_escape = false;
} else if( $char === '"' ) {
$in_quotes = !$in_quotes;
} else if( ! $in_quotes ) {
switch( $char ) {
case '}': case ']':
$level--;
$ends_line_level = NULL;
$new_line_level = $level;
break;
case '{': case '[':
$level++;
case ',':
$ends_line_level = $level;
break;
case ':':
$post = " ";
break;
case " ": case "\t": case "\n": case "\r":
$char = "";
$ends_line_level = $new_line_level;
$new_line_level = NULL;
break;
}
} else if ( $char === '\\' ) {
$in_escape = true;
}
if( $new_line_level !== NULL ) {
$result .= "\n".str_repeat( "\t", $new_line_level );
}
$result .= $char.$post;
}
return $result;
}
function debug ($return_string='0') {
$result = '<pre class="left">';
$result .= $this->lastQuery;
$result .= '<hr>';
$result .= $this->prettyJSON(json_encode($this->lastRecords));
$result .= '<hr>';
$result .= $this->lastError;
$result .= '<hr>';
$result .= $this->lastID;
$result .= '</pre>';
if(empty($return_string)) {
echo $result;
} else {
return $result;
}
}
/**
* @var object The connection handle
* @access private
*/
public $conn_handle;
/**
* @var boolean The connection status
* @access private
*/
public $connected;
}
;
/**
* returns a mysqli_real_escape_string cleaned string
*
* @param mixed[] $value The value to be cleaned
*
* @return string Will return a cleaned string that is safe to insert into the database
*/
if(!function_exists('clean')) {
function clean ($value) {
global $db;
return mysqli_real_escape_string($db->conn_handle,$value);
}
}
if(!function_exists('mysql_real_escape_string')) {
function mysql_real_escape_string ($value) {
global $db;
return mysqli_real_escape_string($db->conn_handle,$value);
}
}
if(!function_exists('mysql_insert_id')) {
function mysql_insert_id ($value) {
global $db;
return $db->last_insert_id();
}
}