initial: bootstrap from BukidBountyApp base
This commit is contained in:
2541
app/Http/Controllers/Helpers/Legacy/Backup/DB.php
Normal file
2541
app/Http/Controllers/Helpers/Legacy/Backup/DB.php
Normal file
File diff suppressed because it is too large
Load Diff
304
app/Http/Controllers/Helpers/Legacy/Backup/DBEXT/FILESDB.php
Normal file
304
app/Http/Controllers/Helpers/Legacy/Backup/DBEXT/FILESDB.php
Normal file
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
//File Content
|
||||
|
||||
class DB_FILE_CONTENT
|
||||
{
|
||||
|
||||
public $DB = false;
|
||||
public $tablename = 'file_content';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewFileContent($file, $filename = '', $toDB = true)
|
||||
{
|
||||
if (!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
if (!$filename) {
|
||||
$filename = basename($file);
|
||||
}
|
||||
$table = 'file_content';
|
||||
$filecontent = file_get_contents($file);
|
||||
$filehash = hash_file('sha256', $file);
|
||||
$size = filesize($file);
|
||||
$ifexists = DBFunctions($this->tablename, $this->DB)->CheckifUIDorHashKeyExist($filehash, $fieldstoselectarray = ['uid', 'hashkey'])['uid'] ?? false;
|
||||
if ($ifexists) {
|
||||
return $ifexists;
|
||||
}
|
||||
global $DB;
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
|
||||
$data = ['titlename' => $filename, 'hashkey' => $filehash, 'size_in_bytes' => $size];
|
||||
if ($toDB === true) {
|
||||
$data['content'] = $filecontent;
|
||||
} elseif (!$toDB) {
|
||||
$toDB = 'files/';
|
||||
|
||||
} else {
|
||||
if (!is_dir($toDB)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!endsWithSlash($toDB)) {
|
||||
$toDB .= "/";
|
||||
}
|
||||
if ($toDB !== true) {
|
||||
file_put_contents($toDB . $filehash, $filecontent);
|
||||
if (!file_exists($toDB . $filehash) or filesize($toDB . $filehash) !== $size) {
|
||||
return false;
|
||||
}
|
||||
$data['filelocation'] = $toDB;
|
||||
$data['content'] = '';
|
||||
}
|
||||
$newuid = insertintodb($DB, $table, $data);
|
||||
|
||||
return $newuid;
|
||||
}
|
||||
|
||||
function DeleteFileContent($uidorhashkey)
|
||||
{
|
||||
$where = [];
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
if (is_numeric($uidorhashkey)) {
|
||||
$where['uid'] = $uidorhashkey;
|
||||
} else {
|
||||
$where['hashkey'] = $uidorhashkey;
|
||||
}
|
||||
return deletefromdb('file_content', $where);
|
||||
}
|
||||
|
||||
function getFileContentDetails($uidorhashkey, $fieldstoselect = '')
|
||||
{
|
||||
return getDetailsbyUIDorHashkey('file_content', $uidorhashkey, $fieldstoselect);
|
||||
}
|
||||
|
||||
function getFileContentUIDbyHashkey($hashkey)
|
||||
{
|
||||
if (!$hashkey or is_numeric($hashkey)) {
|
||||
return false;
|
||||
}
|
||||
return $this->getFileContentDetails($hashkey, ['uid', 'hashkey'])['uid'] ?? false;
|
||||
}
|
||||
function getFileContentHashkeybyUID($UID)
|
||||
{
|
||||
if (!$UID or !is_numeric($UID)) {
|
||||
return false;
|
||||
}
|
||||
return $this->getFileContentDetails($UID, ['uid', 'hashkey'])['hashkey'] ?? false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_FILE_CONTENT($DB = false)
|
||||
{
|
||||
return new DB_FILE_CONTENT($DB);
|
||||
}
|
||||
|
||||
|
||||
class FILE_CONTENT_QUICKMULTIPLESEARCH
|
||||
{
|
||||
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'file_content';
|
||||
|
||||
private $parentidresults = [];
|
||||
public $DB;
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false, $DB = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata, $DB);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function FILE_CONTENT_QUICKMULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new FILE_CONTENT_QUICKMULTIPLESEARCH($DB);
|
||||
}
|
||||
|
||||
|
||||
class DB_FILE_LIST
|
||||
{
|
||||
|
||||
public $DB = false;
|
||||
public $tablename = 'file_list';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function insertFileListintoDB($contentuid, $filename, $description = '', $tags = '', $categories = '', $added = '', $addedby = '', $hidden = 0)
|
||||
{
|
||||
|
||||
|
||||
if (!$contentuid or !$filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!$addedby) {
|
||||
global $CurrentUserUID;
|
||||
$addedby = $CurrentUserUID;
|
||||
if (!$addedby) {
|
||||
$addedby = CurrentUserUID();
|
||||
}
|
||||
}
|
||||
if (!$added) {
|
||||
$added = serverdatetimesql();
|
||||
}
|
||||
$modified = serverdatetimesql();
|
||||
|
||||
if (!$description) {
|
||||
$description = '';
|
||||
}
|
||||
if (!$tags) {
|
||||
$tags = '';
|
||||
}
|
||||
if (!$categories) {
|
||||
$categories = '';
|
||||
}
|
||||
|
||||
$hash = generatenewhash($this->tablename);
|
||||
$categories = tryjsonencode($categories);
|
||||
|
||||
$datenow = serverdatetimesql();
|
||||
$tags = tryjsonencode($tags);
|
||||
|
||||
|
||||
$data = [
|
||||
'hashkey' => $hash,
|
||||
'contentuid' => $contentuid,
|
||||
'useruid_access_list' => tryjsonencode(''),
|
||||
'filename' => $filename,
|
||||
'description' => $description,
|
||||
'tags' => $tags,
|
||||
'categories' => $categories,
|
||||
'created' => $added,
|
||||
'modified' => $modified,
|
||||
'hidden' => $hidden,
|
||||
'addedby' => $addedby
|
||||
];
|
||||
|
||||
global $DB;
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
$key = insertintodb($DB, 'file_list', $data);
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
|
||||
function getFileListDetails($uidorhashkey, $fieldstoselect = '')
|
||||
{
|
||||
return getDetailsbyUIDorHashkey($this->tablename, $uidorhashkey, $fieldstoselect);
|
||||
}
|
||||
|
||||
|
||||
function getFileListUIDbyHashkey($hashkey)
|
||||
{
|
||||
if (!$hashkey or is_numeric($hashkey)) {
|
||||
return false;
|
||||
}
|
||||
return $this->getFileListDetails($hashkey, ['uid', 'hashkey'])['uid'] ?? false;
|
||||
}
|
||||
|
||||
function getFileListHashkeybyUID($UID)
|
||||
{
|
||||
if (!$UID or !is_numeric($UID)) {
|
||||
return false;
|
||||
}
|
||||
return $this->getFileListDetails($UID, ['uid', 'hashkey'])['hashkey'] ?? false;
|
||||
}
|
||||
|
||||
|
||||
function InsertFileListandFileContentFromFile($filelocation, $filename, $toDBtrueifFalseSateLocationtoSave = false, $description = '', $tags = '', $categories = '', $hidden = 0)
|
||||
{
|
||||
if (!$filelocation and !$filename) {
|
||||
return false;
|
||||
}
|
||||
$contentuid = DB_FILE_CONTENT()->NewFileContent($filelocation, $filename, $toDBtrueifFalseSateLocationtoSave);
|
||||
|
||||
|
||||
$filelistuid = $this->insertFileListintoDB($contentuid, $filename, $description, $tags, $categories, $added = '', $addedby = '', $hidden);
|
||||
|
||||
return $filelistuid;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function DB_FILE_LIST($DB = false)
|
||||
{
|
||||
return new DB_FILE_LIST($DB);
|
||||
}
|
||||
|
||||
|
||||
class FILE_LIST_QUICKMULTIPLESEARCH
|
||||
{
|
||||
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'file_list';
|
||||
|
||||
private $parentidresults = [];
|
||||
public $DB;
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false, $DB = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata, $DB);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function FILE_LIST_QUICKMULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new FILE_CONTENT_QUICKMULTIPLESEARCH($DB);
|
||||
}
|
||||
368
app/Http/Controllers/Helpers/Legacy/Backup/DBEXT/MARKETDB.php
Normal file
368
app/Http/Controllers/Helpers/Legacy/Backup/DBEXT/MARKETDB.php
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
$classMap['STORES'] = 'DB_STORES';
|
||||
$classMap['PRODUCTS'] = 'DB_PRODUCTS';
|
||||
$classMap['PRODUCTS_TRANSACTIONS'] = 'DB_PRODUCTS_TRANSACTIONS';
|
||||
$classMap['POS_TRANSACTIONS'] = 'DB_POS_TRANSACTIONS';
|
||||
$classMap['PRODUCTS_TRANSACTIONS_SESSIONS'] = 'DB_PRODUCTS_TRANSACTIONS_SESSIONS';
|
||||
$classMap['PRODUCTS_HISTORY'] = 'DB_PRODUCTSHISTORY';
|
||||
$classMap['CART'] = 'DB_CART';
|
||||
$classMap['SUPPLIERS'] = 'DB_SUPPLIERS';
|
||||
$classMap['SUPPLIERS'] = 'DB_SUPPLIERS';
|
||||
|
||||
class DB_CART extends DB_USERS
|
||||
{
|
||||
private function USERS()
|
||||
{
|
||||
return new DB_USERS();
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
function getCartContents($uidorhashkey)
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
$DB = $this->DB;
|
||||
$wherearray = [];
|
||||
if (is_numeric($uidorhashkey)) {
|
||||
$wherearray = ['uid' => $uidorhashkey];
|
||||
} else {
|
||||
$wherearray = ['hashkey' => $uidorhashkey];
|
||||
}
|
||||
|
||||
$DBQUERY = $this->USERS()->GetUserDatabyUID($uidorhashkey);
|
||||
if (!$DBQUERY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = tryjsondecode($DBQUERY['cart']) ?? [];
|
||||
return $result;
|
||||
}
|
||||
function getCartContentsAndComputations($uidorhashkey){
|
||||
$cartContents= $this->getCartContents($uidorhashkey);
|
||||
if (!$cartContents){return false;}
|
||||
return $this->getCartDetailsComputations($cartContents);
|
||||
}
|
||||
function getCartDetailsComputations($cartdata)
|
||||
{
|
||||
if (!$cartdata || !is_array($cartdata)) {
|
||||
return false;
|
||||
}
|
||||
$productsClass = new DB_PRODUCTS_QUICK_MULTIPLESEARCH;
|
||||
$storeClass = new DB_STORES_QUICK_MULTIPLESEARCH;
|
||||
$CartDetails = [];
|
||||
$cartproducts = [];
|
||||
|
||||
|
||||
|
||||
|
||||
foreach ($cartdata as $value) {
|
||||
|
||||
$cart_product_hashkey = $value['hashkey'] ?? $value[0];
|
||||
$cart_product_quantity = $value['quantity'] ?? $value[1];
|
||||
$cart_product_added = $value['added'] ?? $value[2];
|
||||
$cart_product_modified = $value['modified'] ?? $value[3];
|
||||
|
||||
$productdata = $productsClass->getDetailsbyUIDorHashkey($cart_product_hashkey) ?? false;
|
||||
if (!$productdata) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$product_active = $productdata['status'] === 'active';
|
||||
$product_available = $productdata['available'] >= $cart_product_quantity;
|
||||
|
||||
$productstore_uid = $productdata['storeuid'];
|
||||
|
||||
$productstore_hash = $storeClass->getHASHfromUID($productstore_uid);
|
||||
|
||||
$productphoto_array = tryjsondecode($productdata['photourl']);
|
||||
if (!is_array($productphoto_array)) {
|
||||
$productphotoarray = [];
|
||||
}
|
||||
$productphotourl = $productphoto_array[0] ?? null;
|
||||
|
||||
$productprice = $productdata['price'];
|
||||
$product_unit = $productdata['unitname'];
|
||||
$product_name = $productdata['name'];
|
||||
if ($cart_product_quantity < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$cartproducts[] = [
|
||||
'hashkey' => $cart_product_hashkey,
|
||||
'quantity' => $cart_product_quantity,
|
||||
'price' => $productprice,
|
||||
'unit' => $product_unit,
|
||||
'name' => $product_name,
|
||||
'photourl' => $productphotourl,
|
||||
'added' => $cart_product_added,
|
||||
'modified' => $cart_product_modified,
|
||||
'store' => $productstore_hash,
|
||||
'active' => $product_active,
|
||||
'available' => $product_available,
|
||||
'subtotal' => $productprice * $cart_product_quantity
|
||||
];
|
||||
}
|
||||
|
||||
$total = array_sum(array_column($cartproducts, 'subtotal'));
|
||||
if ($total < 2) {
|
||||
return false;
|
||||
}
|
||||
$CartDetails['details'] = [
|
||||
'total' => $total,
|
||||
'shipping' => 'Unknown'
|
||||
];
|
||||
$CartDetails['cart'] = $cartproducts;
|
||||
|
||||
return $CartDetails;
|
||||
}
|
||||
function SetCartContents($uidorhashkey, $newcontentsArray)
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
$DB = $this->DB;
|
||||
$newcontentsArray = tryjsonencode($newcontentsArray);
|
||||
$newcontentsArray = ['cart' => $newcontentsArray];
|
||||
$DBNow = DBQUERY()->USERS()->ModifyUser($newcontentsArray, $uidorhashkey);
|
||||
return $DBNow;
|
||||
}
|
||||
function AddCartContentsSingleProduct($uidorhashkey, $producthashkey, $additionalquantity)
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
$exists = DBQUERY()->USERS()->GetUserDatabyUID($uidorhashkey);
|
||||
if (!$exists) {
|
||||
return false;
|
||||
}
|
||||
if (!$producthashkey || is_numeric($producthashkey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$additionalquantity || !is_numeric($additionalquantity)) {
|
||||
return false;
|
||||
}
|
||||
$contents = $this->getCartContents($uidorhashkey);
|
||||
if ($contents) {
|
||||
$producthashkeys = array_column($contents, 0);
|
||||
} else {
|
||||
$contents = [];
|
||||
$producthashkeys = [];
|
||||
}
|
||||
|
||||
$targetkey = array_search($producthashkey, $producthashkeys);
|
||||
if ($targetkey === false) {
|
||||
$contents[] = [$producthashkey, $additionalquantity, serverdatetimesql(), serverdatetimesql()];
|
||||
} else {
|
||||
$content_details = $contents[$targetkey];
|
||||
$currentquantity = $content_details[1];
|
||||
$currentdate_added = $content_details[2];
|
||||
$newdate_modfied = serverdatetimesql();
|
||||
$newquantity = $currentquantity + $additionalquantity;
|
||||
if ($newquantity < 0) {
|
||||
return false;
|
||||
}
|
||||
$contents[$targetkey] = [$producthashkey, $newquantity, $currentdate_added, $newdate_modfied];
|
||||
}
|
||||
|
||||
return $this->SetCartContents($uidorhashkey, $contents);
|
||||
}
|
||||
|
||||
function EmptyCartContents($uidorhashkey)
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
return $this->SetCartContents($uidorhashkey, []);
|
||||
}
|
||||
function DeleteCartContents($uidorhashkey, $producthashkey)
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
if (!$producthashkey || is_numeric($producthashkey)) {
|
||||
return false;
|
||||
}
|
||||
$contents = $this->getCartContents($uidorhashkey);
|
||||
$producthashkeys = array_column($contents, 0);
|
||||
$targetkey = array_search($producthashkey, $producthashkeys);
|
||||
if ($targetkey === false) {
|
||||
unset($contents[$targetkey]);
|
||||
$contents = array_values($contents);
|
||||
}
|
||||
return $this->SetCartContents($uidorhashkey, $contents);
|
||||
}
|
||||
|
||||
function CheckifProductisAllowedtoAddtoCart($producthashkeyoruid, $quantity)
|
||||
{
|
||||
//returns the product details if allowed, false if not
|
||||
$ProductDetails = DB_PRODUCTS()->getDetailsbyUIDorHashkey($producthashkeyoruid);
|
||||
if (!$ProductDetails || $ProductDetails['status'] !== 'active' || $ProductDetails['available'] < 1) {
|
||||
return false;
|
||||
}
|
||||
if ($quantity > $ProductDetails['available']) {
|
||||
return false;
|
||||
}
|
||||
return $ProductDetails;
|
||||
|
||||
}
|
||||
function SetProductQuantityCartContent($uidorhashkey, $producthashkeyoruid, $quantity)
|
||||
{
|
||||
if (!$uidorhashkey || !$producthashkeyoruid || $quantity === null) {
|
||||
return false;
|
||||
}
|
||||
$producthashkeyifAllowed = $this->CheckifProductisAllowedtoAddtoCart($producthashkeyoruid, $quantity)['hashkey'] ?? false;
|
||||
if (!$producthashkeyifAllowed) {
|
||||
return false;
|
||||
}
|
||||
$producthashkeyoruid = $producthashkeyifAllowed;
|
||||
$contents = $this->getCartContents($uidorhashkey);
|
||||
if (!$contents) {
|
||||
$contents = [];
|
||||
}
|
||||
|
||||
$producthashcolumns = array_column($contents, 0);
|
||||
|
||||
$targetkey = array_search($producthashkeyoruid, $producthashcolumns);
|
||||
|
||||
if ($targetkey === false) {
|
||||
$contents[] = [$producthashkeyoruid, $quantity, serverdatetimesql(), serverdatetimesql()];
|
||||
} else {
|
||||
$content_details = $contents[$targetkey];
|
||||
$currentquantity = $content_details[1];
|
||||
$currentdate_added = $content_details[2];
|
||||
$newdate_modfied = serverdatetimesql();
|
||||
$contents[$targetkey] = [$producthashkeyoruid, $quantity, $currentdate_added, $newdate_modfied];
|
||||
}
|
||||
|
||||
|
||||
$updatecontent = $this->SetCartContents($uidorhashkey, $contents);
|
||||
return $updatecontent;
|
||||
|
||||
}
|
||||
function ShowCartStructure()
|
||||
{
|
||||
$structure = ['contenthashkey', 'quantity', 'date_added', 'date_modified'];
|
||||
e($structure);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function CartDB($DB = false)
|
||||
{
|
||||
return new DB_CART($DB);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class MARKET_MAIN
|
||||
{
|
||||
public $DB = false;
|
||||
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
function isNewTransactionAllowed($createdby_details, $createdfor_details, $ownerdetails)
|
||||
{
|
||||
|
||||
if (!$createdby_details || !$createdfor_details || !$ownerdetails) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parentflagAllowed = false;
|
||||
$acct_typeflagAllowed = false;
|
||||
|
||||
$ownerUID = $ownerdetails['uid'] ?? false;
|
||||
if (!$ownerUID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($createdby_details)) {
|
||||
$createdby_type = $createdby_details;
|
||||
} else {
|
||||
$createdby_type = $createdby_details['acct_type'];
|
||||
}
|
||||
|
||||
if (!is_array($createdby_details)) {
|
||||
$createdfor_type = $createdfor_details;
|
||||
} else {
|
||||
$createdfor_type = $createdfor_details['acct_type'];
|
||||
}
|
||||
|
||||
$createdby_Allowed_Types = $createdby_type === 'storeowner' || $createdby_type === 'storemanager' || $createdby_type === 'ult' || $createdby_type === 'superoperator';
|
||||
$createdfor_Allowed_Types = $createdby_type === 'storeowner' || $createdby_type === 'storemanager';
|
||||
$iscreatedbyULT = $createdby_type === 'ult';
|
||||
|
||||
$createdfor_Parent = $createdfor_details['parentuid'];
|
||||
$createdby_Parent = $createdby_details['parentuid'];
|
||||
|
||||
|
||||
|
||||
if ($createdfor_Parent === $ownerUID) {
|
||||
$parentflagAllowed = true;
|
||||
}
|
||||
|
||||
|
||||
if ($createdby_Allowed_Types && $createdfor_Allowed_Types) {
|
||||
$acct_typeflagAllowed = true;
|
||||
}
|
||||
|
||||
|
||||
if ($iscreatedbyULT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if ($acct_typeflagAllowed && $parentflagAllowed) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getCityFromAddress($address)
|
||||
{
|
||||
$citiesfile = file_get_contents('lib/cities.json');
|
||||
$cities = json_decode($citiesfile) ?? false;
|
||||
$cities = array_column($cities, 'name') ?? false;
|
||||
|
||||
if (!$cities) {
|
||||
return false;
|
||||
}
|
||||
foreach ($cities as $city) {
|
||||
if (stripos($address, $city) !== false) {
|
||||
return $city;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function MARKET_MAIN()
|
||||
{
|
||||
return new MARKET_MAIN();
|
||||
}
|
||||
|
||||
|
||||
require_once('MarketDB/products.db.php');
|
||||
require_once('MarketDB/productshistory.db.php');
|
||||
require_once('MarketDB/product_transactions.db.php');
|
||||
require_once('MarketDB/product_transactions_sessions.db.php');
|
||||
require_once('MarketDB/product_transactions_sessions.db.php');
|
||||
require_once('MarketDB/pos_transactions.db.php');
|
||||
require_once('MarketDB/pos_transactions_sessions.db.php');
|
||||
require_once('MarketDB/stores.db.php');
|
||||
require_once('MarketDB/suppliers.db.php');
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
class DB_POS_TRANSACTIONS
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'pos_transactions';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewPOSTransaction()
|
||||
{
|
||||
|
||||
$data = [
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
];
|
||||
|
||||
|
||||
return $this->InsertBasicDBHashCreatedModified($data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class DB_POS_TRANSACTIONS_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'pos_transactions';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_POS_TRANSACTIONS($DB = false)
|
||||
{
|
||||
return new DB_POS_TRANSACTIONS($DB);
|
||||
}
|
||||
|
||||
function DB_POS_TRANSACTIONS_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_POS_TRANSACTIONS_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DB_POS_TRANSACTIONS_SESSIONS
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'pos_transactions_sessions';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewRecord()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class DB_POS_TRANSACTIONS_SESSIONS_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'pos_transactions_sessions';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_POS_TRANSACTIONS_SESSIONS($DB = false)
|
||||
{
|
||||
return new DB_POS_TRANSACTIONS_SESSIONS($DB);
|
||||
}
|
||||
function DB_POS_TRANSACTIONS_SESSIONS_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_POS_TRANSACTIONS_SESSIONS_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DB_PRODUCTS_TRANSACTIONS
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'products_transactions';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewProductTransactions($productuid, $storeuid, $quantity, $transactiontype, $transactionsessionhash = '', $subtype = '', $createdfor = '', $price = '', $owneruid = '', $createdby = '', $name = '', $description = '', $transactiondata = '', $remarks = '')
|
||||
{
|
||||
|
||||
if (!$productuid || !$storeuid || !$transactiontype || !$quantity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $CurrentUserUID;
|
||||
$createdby = $CurrentUserUID;
|
||||
if (!$createdby) {
|
||||
$createdby = CurrentUserUID();
|
||||
}
|
||||
|
||||
if (!$createdfor) {
|
||||
$createdfor = $createdby;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
$AddtoDataifNOTEmpty = function ($varname, $varvalue) use (&$data) {
|
||||
if (!$varname || !$varvalue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($varvalue)) {
|
||||
$varvalue = tryjsonencode($varvalue);
|
||||
}
|
||||
$data[$varname] = $varvalue;
|
||||
};
|
||||
|
||||
$date = serverdatetimesql();
|
||||
$created = $date;
|
||||
$modified = $date;
|
||||
|
||||
if (!$transactionsessionhash) {
|
||||
$transactionsessionhash = DBQUERY()->PRODUCTS_TRANSACTIONS_SESSIONS()->NewProductsTransactionSession($storeuid);
|
||||
} else {
|
||||
if (!DBQUERY()->PRODUCTS_TRANSACTIONS_SESSIONS()->checkifUIDorHashKeyexist($transactionsessionhash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!$transactiondata) {
|
||||
$transactiondata = [];
|
||||
}
|
||||
|
||||
$storeexists = DBQUERY()->STORES()->CheckifUIDorHashKeyExist($storeuid);
|
||||
if (!$storeexists) {
|
||||
return false;
|
||||
}
|
||||
$productexists = DBQUERY()->PRODUCTS()->CheckifUIDorHashKeyExist($productuid);
|
||||
if (!$productexists) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$logs = [$date, 'Created New Product Transaction by useruid(' . $createdby . ') at ' . $modified . ' .'];
|
||||
|
||||
$AddtoDataifNOTEmpty('productuid', $productuid);
|
||||
$AddtoDataifNOTEmpty('storeuid', $storeuid);
|
||||
$AddtoDataifNOTEmpty('quantity', $quantity);
|
||||
$AddtoDataifNOTEmpty('transactiontype', $transactiontype);
|
||||
$AddtoDataifNOTEmpty('transactionsessionhash', $transactionsessionhash);
|
||||
$AddtoDataifNOTEmpty('subtype', $subtype);
|
||||
$AddtoDataifNOTEmpty('createdfor', $createdfor);
|
||||
$AddtoDataifNOTEmpty('price', $price);
|
||||
$AddtoDataifNOTEmpty('owneruid', $owneruid);
|
||||
$AddtoDataifNOTEmpty('createdby', $createdby);
|
||||
$AddtoDataifNOTEmpty('name', $name);
|
||||
$AddtoDataifNOTEmpty('description', $description);
|
||||
$AddtoDataifNOTEmpty('description', $remarks);
|
||||
$AddtoDataifNOTEmpty('transactiondata', $transactiondata);
|
||||
$AddtoDataifNOTEmpty('transactiondata', $logs);
|
||||
$AddtoDataifNOTEmpty('created', $created);
|
||||
$AddtoDataifNOTEmpty('modified', $modified);
|
||||
|
||||
return $this->InsertIntoDB($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getTransactionsSessions()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DB_PRODUCTS_TRANSACTIONS_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'products_transactions';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_PRODUCTS_TRANSACTIONS($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTS_TRANSACTIONS($DB);
|
||||
}
|
||||
|
||||
function DB_PRODUCTS_TRANSACTIONS_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTS_TRANSACTIONS_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DB_PRODUCTS_TRANSACTIONS_SESSIONS
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'products_transactions_sessions';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function NewProductsTransactionSession($storeuid, $status = 'open', $name = '', $description = '', $category = '', $subtype = '', $createdby = '', $createdfor = '', $remarks = '')
|
||||
{
|
||||
if (!$storeuid) {
|
||||
return false;
|
||||
}
|
||||
$store = DB_STORES()->getDetailsbyUIDorHashkey($storeuid);
|
||||
|
||||
if (!$storeuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$store_owneruid = $store['owneruid'];
|
||||
$store_manageruid = $store['manageruid'];
|
||||
|
||||
$date = serverdatetimesql();
|
||||
$created = $date;
|
||||
$modified = $date;
|
||||
|
||||
global $CurrentUserUID;
|
||||
|
||||
if (!$createdby) {
|
||||
$createdby = $CurrentUserUID;
|
||||
}
|
||||
if (!$createdby) {
|
||||
$createdby = CurrentUserUID();
|
||||
}
|
||||
|
||||
if (!$createdfor) {
|
||||
$createdfor = $createdby;
|
||||
}
|
||||
|
||||
$createdby_details = DBQUERY()->USERS()->getDetailsbyUIDorHashkey($createdby);
|
||||
if (!$createdby_details) {
|
||||
return false;
|
||||
}
|
||||
if ($createdby !== $createdfor) {
|
||||
$createdfor_details = DBQUERY()->USERS()->getDetailsbyUIDorHashkey($createdfor);
|
||||
} else {
|
||||
$createdfor_details = $createdby_details;
|
||||
}
|
||||
|
||||
$ownerdetails = DBQUERY()->USERS()->getDetailsbyUIDorHashkey($store_owneruid);
|
||||
if (!$ownerdetails) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!MARKET_MAIN()->isNewTransactionAllowed($createdby_details, $createdfor_details, $ownerdetails)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$logs = [$date, 'Created New Transaction by uid(' . $createdby . ')'];
|
||||
|
||||
$hashkey = $this->GenerateNewHash();
|
||||
$data = [
|
||||
'hashkey' => $hashkey,
|
||||
'created' => $date,
|
||||
'modified' => $date,
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'category' => $category,
|
||||
'subtype' => $subtype,
|
||||
'createdby' => $createdby,
|
||||
'createdfor' => $createdfor,
|
||||
'remarks' => $remarks,
|
||||
'logs' => $logs,
|
||||
'status' => $status
|
||||
];
|
||||
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (!$value) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$data[$key] = tryjsonencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $insert = $this->InsertIntoDB($data);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class DB_PRODUCTS_TRANSACTIONS_SESSIONS_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'products_transactions_sessions';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_PRODUCTS_TRANSACTIONS_SESSIONS($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTS_TRANSACTIONS_SESSIONS($DB);
|
||||
}
|
||||
function DB_PRODUCTS_TRANSACTIONS_SESSIONS_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTS_TRANSACTIONS_SESSIONS_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DB_PRODUCTS
|
||||
{
|
||||
|
||||
public $DB = false;
|
||||
public $tablename = 'products';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function NewWholesaleProduct(
|
||||
$name,
|
||||
$description,
|
||||
$price,
|
||||
$unitname,
|
||||
$storeuid,
|
||||
$available = 0,
|
||||
$photourl = '',
|
||||
$barcode = '',
|
||||
$specs = '',
|
||||
$owneruid = '',
|
||||
$sold = '',
|
||||
$category = '',
|
||||
$subcategory = '',
|
||||
$remarks = '',
|
||||
$status = '',
|
||||
$sku = '',
|
||||
$shortcode = '',
|
||||
$shortname = '',
|
||||
$qrcode = '',
|
||||
$reviews = '',
|
||||
$createdby = '',
|
||||
$rating = '',
|
||||
$createdfor = ''
|
||||
) {
|
||||
if (!$specs) {
|
||||
$specs = [];
|
||||
}
|
||||
$specs[]='wholesale';
|
||||
|
||||
return $this->NewProduct($name,
|
||||
$description,
|
||||
$price,
|
||||
$unitname,
|
||||
$storeuid,
|
||||
$available,
|
||||
$photourl,
|
||||
$barcode,
|
||||
$specs,
|
||||
$owneruid ,
|
||||
$sold,
|
||||
$category,
|
||||
$subcategory,
|
||||
$remarks,
|
||||
$status,
|
||||
$sku,
|
||||
$shortcode,
|
||||
$shortname,
|
||||
$qrcode,
|
||||
$reviews,
|
||||
$createdby,
|
||||
$rating,
|
||||
$createdfor);
|
||||
|
||||
}
|
||||
|
||||
function NewProduct(
|
||||
$name,
|
||||
$description,
|
||||
$price,
|
||||
$unitname,
|
||||
$storeuid,
|
||||
$available = 0,
|
||||
$photourl = '',
|
||||
$barcode = '',
|
||||
$specs = '',
|
||||
$owneruid = '',
|
||||
$sold = '',
|
||||
$category = '',
|
||||
$subcategory = '',
|
||||
$remarks = '',
|
||||
$status = '',
|
||||
$sku = '',
|
||||
$shortcode = '',
|
||||
$shortname = '',
|
||||
$qrcode = '',
|
||||
$reviews = '',
|
||||
$createdby = '',
|
||||
$rating = '',
|
||||
$createdfor = ''
|
||||
) {
|
||||
|
||||
if (!$name || !$description || !$price || !$unitname || !$storeuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$storedata = DBQUERY()->STORES()->CheckifUIDorHashKeyExist($storeuid);
|
||||
|
||||
if (!$storedata) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$data = [];
|
||||
$addtofinalDBVar = function ($varvalue, $varname, $tryjson = false) use (&$data) {
|
||||
if ($varvalue) {
|
||||
if ($tryjson and is_array($varvalue)) {
|
||||
$varvalue = tryjsonencode($varvalue);
|
||||
}
|
||||
$data[$varname] = $varvalue;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
global $CurrentUserUID;
|
||||
|
||||
if (!$createdby) {
|
||||
$createdby = $CurrentUserUID;
|
||||
}
|
||||
|
||||
if (!$createdby) {
|
||||
$createdby = CurrentUserUID();
|
||||
}
|
||||
|
||||
if (!$createdfor) {
|
||||
$createdfor = $createdby;
|
||||
}
|
||||
|
||||
if (!$status) {
|
||||
$status = 'active';
|
||||
} else {
|
||||
$status = strtolower($status);
|
||||
}
|
||||
|
||||
|
||||
$ownerUIDCheckifParent = function ($owneruid, $createdfor, $createdby) {
|
||||
|
||||
$createdby_isParentofOwner = DB_USERS()->isTargetUserAChildofParent($owneruid, $createdby);
|
||||
if ($createdby_isParentofOwner) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$createdfor_isParentofOwner = DB_USERS()->isTargetUserAChildofParent($owneruid, $createdfor);
|
||||
if ($createdfor_isParentofOwner) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$Owner_isParentofCreatedby = DB_USERS()->isTargetUserAChildofParent($createdby, $owneruid);
|
||||
if ($Owner_isParentofCreatedby) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
$createdby_details = DB_USERS()->getDetailsbyUIDorHashkey($createdby);
|
||||
if (!$createdby_details) {
|
||||
return false;
|
||||
}
|
||||
if ($createdby !== $createdfor) {
|
||||
$createdfor_details = DB_USERS()->getDetailsbyUIDorHashkey($createdfor);
|
||||
} else {
|
||||
$createdfor_details = $createdby_details;
|
||||
}
|
||||
|
||||
if (!$createdfor_details) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$createdby_type = $createdby_details['acct_type'];
|
||||
$createdby_uid = $createdby_details['uid'];
|
||||
$createdbyfor_type = $createdfor_details['acct_type'];
|
||||
$createdfor_uid = $createdfor_details['uid'];
|
||||
|
||||
$storeuid_details = $storedata;
|
||||
if (!$storeuid) {
|
||||
return false;
|
||||
}
|
||||
$storeuid = $storeuid_details['uid'];
|
||||
|
||||
$storeuid_owneruid = $storeuid_details['owneruid'];
|
||||
|
||||
|
||||
if (!$owneruid) {
|
||||
$owneruid = $storeuid_owneruid;
|
||||
}
|
||||
|
||||
$createdby_is_StoreOwner = $createdby_type === 'storeowner';
|
||||
$createdby_is_StoreManager = $createdby_type === 'storemanager';
|
||||
$createdfor_is_StoreOwner = $createdbyfor_type === 'storeowner';
|
||||
$createdfor_is_StoreManger = $createdbyfor_type === 'storemanager';
|
||||
$createdby_is_Ult = $createdby_type === 'ult';
|
||||
$createdby_is_Operator = $createdby_type === 'operator';
|
||||
$createdby_is_Admin = $createdby_type === 'admincore';
|
||||
|
||||
|
||||
|
||||
|
||||
if (!$createdby_is_StoreManager && !$createdby_is_StoreOwner && !$createdfor_is_StoreOwner && !$createdfor_is_StoreManger && !$createdby_is_Ult && !$createdby_is_Operator && !$createdby_is_Admin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($owneruid) {
|
||||
$owner_details = DBQUERY()->USERS()->getDetailsbyUIDorHashkey($owneruid);
|
||||
if (!$owner_details) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$ownerUIDCheckifParent($owneruid, $createdfor, $createdby)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$createdby_is_SameUIDAsStoreOwner = $createdby_uid === $storeuid_owneruid;
|
||||
$createdfor_is_SameUIDAsStoreOwner = $createdfor_uid === $storeuid_owneruid;
|
||||
|
||||
$isOwnerofStore = $createdby_is_SameUIDAsStoreOwner || $createdfor_is_SameUIDAsStoreOwner || $createdby_is_Ult;
|
||||
|
||||
|
||||
if (!$isOwnerofStore) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$userdata = DB_USERS()->GetUserDatabyUID($createdby, ['username', 'nickname']);
|
||||
if (!$userdata) {
|
||||
return false;
|
||||
}
|
||||
$username = $userdata['username'] ?? 'unknown';
|
||||
$created = serverdatetimesql();
|
||||
$logs = [serverdatetimesql(), 'Product Created On ' . serverdatetimesql() . ' by useruid(' . $createdby . ')'];
|
||||
$hash = generatenewhash($this->tablename);
|
||||
|
||||
$addtofinalDBVar($name, 'name');
|
||||
$addtofinalDBVar($description, 'description');
|
||||
$addtofinalDBVar($price, 'price');
|
||||
$addtofinalDBVar($unitname, 'unitname');
|
||||
$addtofinalDBVar($storeuid, 'storeuid');
|
||||
$addtofinalDBVar($available, 'available');
|
||||
$addtofinalDBVar($photourl, 'photourl', true);
|
||||
$addtofinalDBVar($barcode, 'barcode');
|
||||
$addtofinalDBVar($specs, 'specs', 1);
|
||||
$addtofinalDBVar($owneruid, 'owneruid');
|
||||
$addtofinalDBVar($sold, 'sold');
|
||||
$addtofinalDBVar($category, 'category');
|
||||
$addtofinalDBVar($subcategory, 'subcategory');
|
||||
$addtofinalDBVar($remarks, 'remarks');
|
||||
$addtofinalDBVar($status, 'status');
|
||||
$addtofinalDBVar($sku, 'sku');
|
||||
$addtofinalDBVar($shortcode, 'shortcode');
|
||||
$addtofinalDBVar($shortname, 'shortname');
|
||||
$addtofinalDBVar($qrcode, 'qrcode');
|
||||
$addtofinalDBVar($rating, 'rating');
|
||||
$addtofinalDBVar($reviews, 'reviews', 1);
|
||||
$addtofinalDBVar($createdby, 'createdby');
|
||||
$addtofinalDBVar($createdfor, 'createdfor');
|
||||
$addtofinalDBVar($logs, 'logs');
|
||||
$addtofinalDBVar($hash, 'hashkey');
|
||||
$addtofinalDBVar($created, 'created');
|
||||
|
||||
|
||||
global $DB;
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
$key = insertintodb($DB, 'products', $data);
|
||||
|
||||
if ($key) {
|
||||
DBQUERY()->PRODUCTS_HISTORY()->NewProductHistory($data);
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
function ShowProductsbyStoreUID($uidorhashkey, $onlyactive = true, $fieldstoselect = [])
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
if (!is_numeric($uidorhashkey)) {
|
||||
$uidorhashkey = DB_STORES()->getUIDfromHashkey($uidorhashkey) ?? false;
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$data = ['storeuid' => $uidorhashkey];
|
||||
|
||||
if ($onlyactive) {
|
||||
$data['status'] = 'active';
|
||||
}
|
||||
|
||||
return $data = $this->ListFromDB($data, [], $fieldstoselect);
|
||||
}
|
||||
|
||||
function getReviewsbyUID($uidorhashkey)
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
$productdetails = $this->getDetailsbyUIDorHashkey($uidorhashkey);
|
||||
if (!$productdetails) {
|
||||
return false;
|
||||
}
|
||||
return $reviews = tryjsondecode($productdetails['reviews']) ?? '';
|
||||
}
|
||||
|
||||
function setReviewsbyUID($uidorhashkey, $reviews)
|
||||
{
|
||||
if (!$uidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
if ($reviews) {
|
||||
$reviews = tryjsonencode($reviews);
|
||||
}
|
||||
return $this->ModifyDBSinglefieldbyUID($uidorhashkey, 'reviews', $reviews);
|
||||
}
|
||||
function addReviewbyUID($uidorhashkey, $useruid, $rating, $content)
|
||||
{
|
||||
if (!$uidorhashkey || !$useruid || !$rating || !$content) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$reviews = $this->getReviewsbyUID($uidorhashkey);
|
||||
if ($reviews === false) {
|
||||
return false;
|
||||
}
|
||||
$lastelement = $reviews[count($reviews) - 1] ?? false;
|
||||
if (!$lastelement) {
|
||||
$count = $lastelement[0] ?? 1;
|
||||
}
|
||||
$createddate = serverdatetimesql();
|
||||
$modifieddate = serverdatetimesql();
|
||||
|
||||
$userdetails = DBQUERY()->USERS()->GetUserDatabyUID($useruid);
|
||||
if (!$userdetails) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$userSUID = $userdetails['uid'];
|
||||
$userHash = $userdetails['hashkey'];
|
||||
|
||||
$reviews[] = [$count, $createddate, $modifieddate, $userHash, $rating, $content];
|
||||
return $this->setReviewsbyUID($uidorhashkey, $reviews);
|
||||
|
||||
}
|
||||
function clearReviewsbyUID($uidorhashkey)
|
||||
{
|
||||
return $this->setReviewsbyUID($uidorhashkey, []);
|
||||
}
|
||||
|
||||
function listProductsbyStatus($status = null, $fieldstoselectarray = '', )
|
||||
{
|
||||
return DBQUERY()->PRODUCTS()->ListFromDB(['status' => strtolower($status)], $likefields = [], $fieldstoselectarray) ?? false;
|
||||
}
|
||||
function listActiveProductsStatus($fieldstoselectarray = '')
|
||||
{
|
||||
return $this->listProductsbyStatus('active', $fieldstoselectarray);
|
||||
}
|
||||
function listProductsbyStatuswithStock($status = null, $fieldstoselectarray = '')
|
||||
{
|
||||
|
||||
$noavailableflag = 0;
|
||||
if ($fieldstoselectarray && !in_array('available', $fieldstoselectarray)) {
|
||||
$noavailableflag = 1;
|
||||
$fieldstoselectarray[] = 'available';
|
||||
}
|
||||
$list = $this->listProductsbyStatus($status, $fieldstoselectarray);
|
||||
if (!$list) {
|
||||
return false;
|
||||
}
|
||||
foreach ($list as $key => $value) {
|
||||
if ($value['available'] < 1) {
|
||||
unset($list[$key]);
|
||||
continue;
|
||||
}
|
||||
if ($noavailableflag) {
|
||||
unset($list[$key]['available']);
|
||||
}
|
||||
|
||||
}
|
||||
$list = array_values($list);
|
||||
return $list;
|
||||
}
|
||||
function listAvailableandActiveProducts($fieldstoselectarray = '')
|
||||
{
|
||||
return $this->listProductsbyStatuswithStock('active', $fieldstoselectarray);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class DB_PRODUCTS_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'products';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function DB_PRODUCTS_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTS_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
|
||||
function DB_PRODUCTS($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTS($DB);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DB_PRODUCTSHISTORY
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'productshistory';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewProductHistory($data)
|
||||
{
|
||||
$required = ['available', 'price', 'name', 'description', 'status', 'storeuid'];
|
||||
return $this->DefaultDBInsert($data, $required);
|
||||
}
|
||||
}
|
||||
|
||||
class DB_PRODUCTSHISTORY_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'productshistory';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_PRODUCTSHISTORY($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTSHISTORY($DB);
|
||||
}
|
||||
function DB_PRODUCTSHISTORY_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_PRODUCTSHISTORY_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DB_STORES
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'stores';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function GenerateStoreCode($category, $num=null, $length = 8, )
|
||||
{
|
||||
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
|
||||
$charactersLength = strlen($characters);
|
||||
$storeCode = '';
|
||||
if(!$num){
|
||||
$num = rand(1,99);
|
||||
}
|
||||
|
||||
// Generate a random alphanumeric string
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$storeCode .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
$categoryPrefix = substr($category, 0, 2);
|
||||
$categorySuffix = substr($category, -2, 2);
|
||||
$cat = $categoryPrefix . $categorySuffix;
|
||||
$storeCode = date('Y') . '-' . $cat . '-' . $num . '-' . $storeCode;
|
||||
return $storeCode;
|
||||
}
|
||||
|
||||
private function generateStoreCodeUnique($storeCodeArray, $category, $num = '', $length = 8)
|
||||
{
|
||||
$storeCodeUnique = false;
|
||||
|
||||
while (!$storeCodeUnique) {
|
||||
$newstorecode = $this->GenerateStoreCode($category, $num, $length = 8);
|
||||
if (!in_array(strtoupper($storeCodeUnique), $storeCodeArray)) {
|
||||
$storeCodeUnique = $newstorecode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $newstorecode;
|
||||
}
|
||||
function generateNewStoreCodefromDB($category, $num = '', $length = 8)
|
||||
{
|
||||
$storecodes = $this->ListFromDB([], [], ['storecode']);
|
||||
if (!$storecodes) {
|
||||
$storecodes = [];
|
||||
}
|
||||
$storecodes = array_column($storecodes, 'storecode');
|
||||
$targetdateYEARMONTH = date('Y') . '-' . date('m');
|
||||
$datecreated = $this->ListbyDateCreated($targetdateYEARMONTH);
|
||||
$newnum = (count($datecreated)) + 1;
|
||||
if (!$num) {
|
||||
$num = $targetdateYEARMONTH . '-' . $newnum;
|
||||
}
|
||||
$uniqueStoreCode = $this->generateStoreCodeUnique($storecodes, $category, $num, $length);
|
||||
return $uniqueStoreCode;
|
||||
}
|
||||
|
||||
function NewStore($name, $description, $owneruid, $manageruid, $storeAddress, $category = '', $subcategory = '', $photourl = '', $storecode = '', $status = 'active', $specs = '', $additionaldata = '', $remarks = '', $createdby = '')
|
||||
{
|
||||
|
||||
if (!$name || !$description || !$owneruid || !$manageruid || !$storeAddress) {
|
||||
return false;
|
||||
}
|
||||
$GetUserDetails = function ($useruid) {
|
||||
if (!$useruid) {
|
||||
return false;
|
||||
}
|
||||
$details = DBQUERY()->USERS()->GetUserDatabyUID($useruid);
|
||||
return $details;
|
||||
};
|
||||
|
||||
$addtoDataifNotEmpty = function ($varname, $varvalue) use (&$data) {
|
||||
if (!$varname || !$varvalue) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($varvalue)) {
|
||||
$varvalue = tryjsonencode($varvalue);
|
||||
}
|
||||
$data[$varname] = $varvalue;
|
||||
};
|
||||
|
||||
global $CurrentUserUID;
|
||||
if (!$createdby) {
|
||||
$createdby = $CurrentUserUID;
|
||||
}
|
||||
if (!$createdby) {
|
||||
$createdby = CurrentUserUID();
|
||||
}
|
||||
|
||||
$createdby_details = DB_USERS()->getDetailsbyUIDorHashkey($createdby) ?? false;
|
||||
if (!$createdby_details) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$owner_details = $GetUserDetails($owneruid);
|
||||
if (!$owner_details) {
|
||||
return false;
|
||||
}
|
||||
$manager_details = $GetUserDetails($manageruid);
|
||||
if (!$manager_details) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!MARKET_MAIN()->isNewTransactionAllowed($createdby_details, $manager_details, $owner_details)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!$storecode) {
|
||||
$storecode = $this->generateNewStoreCodefromDB($category);
|
||||
}
|
||||
|
||||
$datetimenow = serverdatetimesql();
|
||||
$hashkey = $this->GenerateNewHash();
|
||||
$logs = [$datetimenow, 'Created New Store by useruid(' . $createdby . ') at ' . $datetimenow];
|
||||
$data = [
|
||||
'hashkey' => $hashkey,
|
||||
'created' => $datetimenow,
|
||||
'modified' => $datetimenow,
|
||||
'logs' => $logs,
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'owneruid' => $owneruid,
|
||||
'manageruid' => $manageruid,
|
||||
'createdby' => $createdby,
|
||||
'address' => $storeAddress
|
||||
];
|
||||
|
||||
|
||||
$addtoDataifNotEmpty('category', $category);
|
||||
$addtoDataifNotEmpty('subcategory', $subcategory);
|
||||
$addtoDataifNotEmpty('photourl', $photourl);
|
||||
$addtoDataifNotEmpty('storecode', $storecode);
|
||||
$addtoDataifNotEmpty('status', $status);
|
||||
$addtoDataifNotEmpty('specs', $specs);
|
||||
$addtoDataifNotEmpty('additionaldata', $additionaldata);
|
||||
$addtoDataifNotEmpty('remarks', $remarks);
|
||||
|
||||
$insert = $this->InsertIntoDB($data);
|
||||
return $insert;
|
||||
}
|
||||
}
|
||||
|
||||
class DB_STORES_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'stores';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_STORES($DB = false)
|
||||
{
|
||||
return new DB_STORES($DB);
|
||||
}
|
||||
|
||||
function DB_STORES_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_STORES_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
class DB_SUPPLIERS
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'suppliers';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewSupplier()
|
||||
{
|
||||
|
||||
$data = [
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
];
|
||||
|
||||
|
||||
return $this->InsertBasicDBHashCreatedModified($data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class DB_SUPPLIERS_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'suppliers';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_SUPPLIERS($DB = false)
|
||||
{
|
||||
return new DB_SUPPLIERS($DB);
|
||||
}
|
||||
|
||||
function DB_SUPPLIERS_QUICK_MULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new DB_SUPPLIERS_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
<?php
|
||||
|
||||
$classMap['PROPERTIES'] = 'DB_PROPERTIES';
|
||||
$classMap['REFERRALS'] = 'DB_REFERRALS';
|
||||
$classMap['REFERRAL_KEYS'] = 'DB_REFERRAL_KEYS';
|
||||
|
||||
class DB_REFERRALS
|
||||
{
|
||||
|
||||
public $DB = false;
|
||||
public $tablename = 'referrals';
|
||||
public $logs;
|
||||
public $status;
|
||||
use BASICDB;
|
||||
use LOGSDB;
|
||||
use STATUSDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
|
||||
$this->logs = new stdClass();
|
||||
$this->logs->setLogbyUID = [$this, 'setLogbyUID'];
|
||||
$this->logs->deleteFullLogbyUID = [$this, 'deleteFullLogbyUID'];
|
||||
$this->logs->viewLogsbyUID = [$this, 'viewLogsbyUID'];
|
||||
$this->logs->deleteLogbyArrayIndex = [$this, 'deleteLogbyArrayIndex'];
|
||||
$this->logs->AddLog = [$this, 'AddLog'];
|
||||
$this->status = new stdClass();
|
||||
$this->status->UpdateStatus = [$this, 'UpdateStatus'];
|
||||
$this->status->ViewStatus = [$this, 'ViewStatus'];
|
||||
$this->status->SetStatusAsDenied = [$this, 'SetStatusAsDenied'];
|
||||
$this->status->SetStatusAsOngoing = [$this, 'SetStatusAsOngoing'];
|
||||
$this->status->SetStatusAsNULL = [$this, 'SetStatusAsNULL'];
|
||||
$this->status->SetStatusAsNULL = [$this, 'SetStatusAsApproved'];
|
||||
|
||||
}
|
||||
function NewReferral($fullname, $mobile, $landline = '', $facebookurl = '', $email = '', $property_location = '', $target_property = '', $target_viewing_date = '', $firstname = '', $middlename = '', $lastname = '', $referral_key = 0, $remarks = '', $alt_contact_details = '', $status = 0)
|
||||
{
|
||||
|
||||
if (!$fullname || !$mobile) {
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!$referral_key) {
|
||||
$referral_key = CurrentUserUID();
|
||||
}
|
||||
if (!$referral_key) {
|
||||
$referral_key = '';
|
||||
}
|
||||
$target_property = $target_property ?? 0;
|
||||
$hash = $this->GenerateNewHash();
|
||||
|
||||
if (!$alt_contact_details) {
|
||||
$alt_contact_details = '[]';
|
||||
} elseif (is_array($alt_contact_details)) {
|
||||
$alt_contact_details = json_encode($alt_contact_details);
|
||||
}
|
||||
$data = [];
|
||||
|
||||
$ConvertToJSONifPossible = function ($datakey, $dataarraay) use (&$data) {
|
||||
if (!$datakey) {
|
||||
return;
|
||||
}
|
||||
if ($dataarraay) {
|
||||
if (is_array($dataarraay)) {
|
||||
$data[$datakey] = json_encode($dataarraay);
|
||||
} else {
|
||||
$data[$datakey] = $dataarraay;
|
||||
}
|
||||
} else {
|
||||
$data[$datakey] = '[]';
|
||||
}
|
||||
};
|
||||
$ifNotNullAddtoArray = function ($datakey, $dataval) use (&$data) {
|
||||
if (!$dataval) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data[$datakey] = $dataval;
|
||||
};
|
||||
|
||||
// file_put_contents('results.txt', print_r($email, 1) . print_r($landline, 1));
|
||||
|
||||
//fix target_property in DB
|
||||
|
||||
$data = [
|
||||
'hashkey' => $hash,
|
||||
'fullname' => $fullname,
|
||||
'mobile' => $mobile,
|
||||
'referral_key' => $referral_key,
|
||||
'email' => $email ?? '',
|
||||
];
|
||||
|
||||
if ($target_property && !is_numeric($target_property)) {
|
||||
$target_property = DBQUERY($this->DB)->PROPERTIES()->getUIDfromHashkey($target_property) ?? 0;
|
||||
}
|
||||
|
||||
$ifNotNullAddtoArray('referral_key', $referral_key);
|
||||
$ifNotNullAddtoArray('landline', $landline);
|
||||
$ifNotNullAddtoArray('target_property', $target_property);
|
||||
$ifNotNullAddtoArray('property_location', $property_location);
|
||||
|
||||
|
||||
$ifNotNullAddtoArray('facebookurl', $facebookurl);
|
||||
$ifNotNullAddtoArray('firstname', $firstname);
|
||||
$ifNotNullAddtoArray('middlename', $middlename);
|
||||
$ifNotNullAddtoArray('lastname', $lastname);
|
||||
$ifNotNullAddtoArray('remarks', $remarks);
|
||||
$ifNotNullAddtoArray('target_viewing_date', $target_viewing_date);
|
||||
|
||||
|
||||
|
||||
$ConvertToJSONifPossible('alt_contact_details', $alt_contact_details);
|
||||
|
||||
|
||||
|
||||
|
||||
if ($target_viewing_date) {
|
||||
$data['target_viewing_date'] = $target_viewing_date;
|
||||
}
|
||||
return $this->InsertIntoDB($data);
|
||||
|
||||
}
|
||||
|
||||
public function SetStatusAsDenied($uidorhashkey)
|
||||
{
|
||||
return $this->status->UpdateStatus($uidorhashkey, -1);
|
||||
}
|
||||
public function SetStatusAsOngoing($uidorhashkey)
|
||||
{
|
||||
return $this->status->UpdateStatus($uidorhashkey, 1);
|
||||
}
|
||||
public function SetStatusAsNULL($uidorhashkey)
|
||||
{
|
||||
return $this->status->UpdateStatus($uidorhashkey, 0);
|
||||
}
|
||||
public function SetStatusAsApproved($uidorhashkey)
|
||||
{
|
||||
return $this->status->UpdateStatus($uidorhashkey, 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function DB_REFERRALS($DB = false)
|
||||
{
|
||||
return new DB_REFERRALS($DB);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class REFERRALS_QUICKMULTIPLESEARCH
|
||||
{
|
||||
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'referrals';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
public $DB;
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindbyExactFullName($name, $newdata = false)
|
||||
{
|
||||
return $this->Find('fullname', $name, $exact = true, true, $newdata)['name'];
|
||||
}
|
||||
function ListbySimilarNames($name, $newdata = false, $usestrpos = false)
|
||||
{
|
||||
return $this->List('fullname', $name, false, true, $newdata, $usestrpos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function REFERRALS_QUICKMULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new REFERRALS_QUICKMULTIPLESEARCH($DB);
|
||||
}
|
||||
|
||||
|
||||
class DB_PROPERTIES
|
||||
{
|
||||
|
||||
public $DB = false;
|
||||
public $tablename = 'properties';
|
||||
|
||||
use BASICDB;
|
||||
use LOGSDB;
|
||||
use STATUSDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewProperties($name, $description, $location, $photourl, $sqm = '', $rooms = NULL, $bedrooms = '', $kitchen = '', $toilet = '', $floors = '', $specs = '', $category = '', $subcategory = '', $status = 0, $remarks = '', $forbiddenUIDsArray = '', $createdby = '', $price = '')
|
||||
{
|
||||
if (!$name || !$description || !$location || !$photourl) {
|
||||
return false;
|
||||
}
|
||||
if ($forbiddenUIDsArray and is_array($forbiddenUIDsArray)) {
|
||||
$forbiddenUIDsArray = json_encode($forbiddenUIDsArray);
|
||||
}
|
||||
$data = [];
|
||||
|
||||
$ConvertToJSONifPossible = function ($datakey, $dataarraay) use (&$data) {
|
||||
if (!$datakey) {
|
||||
return;
|
||||
}
|
||||
if ($dataarraay) {
|
||||
if (is_array($dataarraay)) {
|
||||
$data[$datakey] = json_encode($dataarraay);
|
||||
} else {
|
||||
$data[$datakey] = $dataarraay;
|
||||
}
|
||||
} else {
|
||||
$data[$datakey] = '[]';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$ifNotNullAddtoArray = function ($datakey, $dataval) use (&$data) {
|
||||
if (!$dataval) {
|
||||
return;
|
||||
}
|
||||
$data[$datakey] = $dataval;
|
||||
};
|
||||
|
||||
$hashkey = $this->GenerateNewHash();
|
||||
|
||||
if (!$createdby) {
|
||||
$createdby = CurrentUserUID();
|
||||
}
|
||||
if ($createdby) {
|
||||
$data['createdby'] = $createdby;
|
||||
}
|
||||
$data['hashkey'] = $hashkey;
|
||||
$data['name'] = $name;
|
||||
$data['description'] = $description;
|
||||
$data['location'] = $location;
|
||||
$ConvertToJSONifPossible('photourl', $photourl);
|
||||
$ifNotNullAddtoArray('sqm', $sqm);
|
||||
$ifNotNullAddtoArray('rooms', $rooms);
|
||||
$ifNotNullAddtoArray('bedrooms', $bedrooms);
|
||||
$ifNotNullAddtoArray('kitchen', $kitchen);
|
||||
$ifNotNullAddtoArray('toilet', $toilet);
|
||||
$ifNotNullAddtoArray('floors', $floors);
|
||||
$ifNotNullAddtoArray('category', $category);
|
||||
$ifNotNullAddtoArray('subcategory', $subcategory);
|
||||
$ifNotNullAddtoArray('price', $price);
|
||||
$ConvertToJSONifPossible('specs', $specs);
|
||||
|
||||
$data['status'] = $status ?? 0;
|
||||
$data['remarks'] = $remarks ?? '';
|
||||
$data['forbiddenuids'] = $forbiddenUIDsArray ?? '';
|
||||
$data['logs'] = '[["' . serverdatetimesql() . '","Created Property"]]';
|
||||
|
||||
$Insert = $this->InsertIntoDB($data);
|
||||
return $Insert;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function DB_PROPERTIES($DB = false)
|
||||
{
|
||||
return new DB_PROPERTIES($DB);
|
||||
}
|
||||
|
||||
class PROPERTIES_QUICKMULTIPLESEARCH
|
||||
{
|
||||
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'properties';
|
||||
|
||||
private $parentidresults = [];
|
||||
public $DB;
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function PROPERTIES_QUICKMULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new PROPERTIES_QUICKMULTIPLESEARCH($DB);
|
||||
}
|
||||
|
||||
class DB_REFERRAL_KEYS
|
||||
{
|
||||
|
||||
public $DB = false;
|
||||
public $tablename = 'referral_keys';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewReferralKey($useruid = '', $propertyuid = 0, $referral_code = 0)
|
||||
{
|
||||
if (!$useruid) {
|
||||
$useruid = CurrentUserUID();
|
||||
}
|
||||
if (!$useruid) {
|
||||
$useruid = '';
|
||||
}
|
||||
if ($useruid and is_numeric($useruid)) {
|
||||
$useruid = DB_USERS($this->DB)->GetUserDatabyUID($useruid)['uid'] ?? '';
|
||||
}
|
||||
$hashkey = $this->GenerateNewHash();
|
||||
$data['hashkey'] = $hashkey;
|
||||
$data['useruid'] = $useruid ?? 0;
|
||||
$data['propertyuid'] = $propertyuid ?? 0;
|
||||
|
||||
|
||||
|
||||
if ($referral_code) {
|
||||
$referral_code_exists = $this->getDetailsbyReferral_Key($referral_code);
|
||||
if ($referral_code_exists) {
|
||||
return false;
|
||||
}
|
||||
$data['referral_code'] = $referral_code;
|
||||
} else {
|
||||
$data['referral_code'] = generateUniqueReferralCode($this->DB, 'referral_code', $this->tablename);
|
||||
}
|
||||
|
||||
$Insert = $this->InsertIntoDB($data);
|
||||
return $Insert;
|
||||
}
|
||||
function getDetailsbyReferral_Key($referral_code, $fieldstoselect = '')
|
||||
{
|
||||
if (!$referral_code) {
|
||||
return false;
|
||||
}
|
||||
$details = $this->ListFromDB(['referral_code' => $referral_code], [], $fieldstoselect);
|
||||
return $details[0] ?? false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function DB_REFERRAL_KEYS($DB = false)
|
||||
{
|
||||
return new DB_REFERRAL_KEYS($DB);
|
||||
}
|
||||
|
||||
class REFERRAL_KEYS_QUICKMULTIPLESEARCH
|
||||
{
|
||||
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'referral_keys';
|
||||
|
||||
private $parentidresults = [];
|
||||
public $DB;
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false, $DB = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata, $DB);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
function GetReferralCodebyUID($uidorhashkey, $newdata = false)
|
||||
{
|
||||
return $this->getValueByUIDorHashkey($uidorhashkey, 'referral_code', $newdata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function REFERRAL_KEYS_QUICKMULTIPLESEARCH($DB = false)
|
||||
{
|
||||
return new REFERRAL_KEYS_QUICKMULTIPLESEARCH($DB);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
class DB_TABLENAME
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'users';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewRecord()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class DB_TABLENAME_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'tablename';
|
||||
|
||||
private $parentidresults = [];
|
||||
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function DB_TABLENAME($DB=false){
|
||||
return new DB_TABLENAME($DB);
|
||||
}
|
||||
function DB_TABLENAME_QUICK_MULTIPLESEARCH($DB=false){
|
||||
return new DB_TABLENAME_QUICK_MULTIPLESEARCH($DB);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
306
app/Http/Controllers/Helpers/Legacy/Backup/DBEXT/USERINFODB.php
Normal file
306
app/Http/Controllers/Helpers/Legacy/Backup/DBEXT/USERINFODB.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
class DB_USERINFO
|
||||
{
|
||||
public $DB = false;
|
||||
public $tablename = 'userinfo';
|
||||
|
||||
use BASICDB;
|
||||
public function __construct($DB = false)
|
||||
{
|
||||
if (!$DB) {
|
||||
$DB = DB();
|
||||
}
|
||||
if (!$DB) {
|
||||
return false;
|
||||
}
|
||||
if ($DB) {
|
||||
$this->DB = $DB;
|
||||
}
|
||||
if (!$this->tablename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function NewUserInfo($targetuserlogin, $fullname = '', $firstname = '', $middlename = '', $lastname = '', $landline = '', $mobile = '', $email = '', $altemail = '', $altlandline = '', $altmobile = '', $credit_card = '', $bankdetails = '[]', $facebookurl = '', $photourl = '[]', $otherdetails = '[]', $addresses = '[]')
|
||||
{
|
||||
if (!$targetuserlogin) {
|
||||
return false;
|
||||
}
|
||||
$usercheck = DBQUERY()->USERS()->getDetailsbyUIDorHashkey($targetuserlogin)['uid'] ?? false;
|
||||
if (!$usercheck) {
|
||||
return false;
|
||||
}
|
||||
$hashkey = $this->GenerateNewHash();
|
||||
if ($bankdetails) {
|
||||
if (is_array($bankdetails)) {
|
||||
$bankdetails = json_encode($bankdetails);
|
||||
}
|
||||
} else {
|
||||
$bankdetails = '[]';
|
||||
}
|
||||
if ($otherdetails) {
|
||||
if (is_array($otherdetails)) {
|
||||
$otherdetails = json_encode($otherdetails);
|
||||
}
|
||||
} else {
|
||||
$otherdetails = '[]';
|
||||
}
|
||||
if ($addresses) {
|
||||
if (is_array($otherdetails)) {
|
||||
$otherdetails = json_encode($otherdetails);
|
||||
}
|
||||
} else {
|
||||
$addresses = '[]';
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'hashkey' => $hashkey,
|
||||
'targetuserlogin' => $targetuserlogin,
|
||||
'fullname' => $fullname,
|
||||
'firstname' => $firstname,
|
||||
'middlename' => $middlename,
|
||||
'lastname' => $lastname,
|
||||
'landline' => $landline,
|
||||
'mobile' => $mobile,
|
||||
'email' => $email,
|
||||
'altemail' => $altemail,
|
||||
'altlandline' => $altlandline,
|
||||
'altmobile' => $altmobile,
|
||||
'credit_card' => $credit_card,
|
||||
'bankdetails' => $bankdetails,
|
||||
'facebookurl' => $facebookurl,
|
||||
'photourl' => $photourl,
|
||||
'otherdetails' => $otherdetails,
|
||||
'addresses' => $addresses
|
||||
|
||||
];
|
||||
$insert = $this->InsertIntoDB($data);
|
||||
return $insert;
|
||||
}
|
||||
function GetbyTargetUserUID($useruidorhashkey, $fieldstoselect = '')
|
||||
{
|
||||
$result = $this->ListbyTargetUserUID($useruidorhashkey, $fieldstoselect);
|
||||
|
||||
return $result[0] ?? [];
|
||||
}
|
||||
function ListbyTargetUserUID($useruidorhashkey, $fieldstoselect = '')
|
||||
{
|
||||
if (!$useruidorhashkey) {
|
||||
return false;
|
||||
}
|
||||
if (!is_numeric($useruidorhashkey)) {
|
||||
$useruidorhashkey = DB_USERS($this->DB)->GetUserUIDbyHashkey($useruidorhashkey) ?? false;
|
||||
}
|
||||
|
||||
if (!$useruidorhashkey || !is_numeric($useruidorhashkey)) {
|
||||
return false;
|
||||
}
|
||||
return $this->ListFromDB(['targetuserlogin' => $useruidorhashkey], [], $fieldstoselect);
|
||||
}
|
||||
|
||||
function ModifybyTargetUserUID($targetuserUID, $data)
|
||||
{
|
||||
if (!$targetuserUID || !$data) {
|
||||
return false;
|
||||
}
|
||||
$wherearray = ['targetuserlogin' => $targetuserUID];
|
||||
return $this->ModifySingleRowwithVerification($data, $wherearray);
|
||||
}
|
||||
function GetAddresses($targetuserUID)
|
||||
{
|
||||
if (!$targetuserUID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$details = $this->GetbyTargetUserUID($targetuserUID);
|
||||
if (!$details) {
|
||||
return false;
|
||||
}
|
||||
$addresses = $details['addresses'] ?? null;
|
||||
if ($addresses) {
|
||||
$addresses = tryjsondecode($addresses, true);
|
||||
}
|
||||
return $addresses;
|
||||
}
|
||||
function GetLastAddress($targetuserUID)
|
||||
{
|
||||
$details = $this->GetAddresses($targetuserUID);
|
||||
if ($details === false) {
|
||||
return false;
|
||||
}
|
||||
if ($details === null) {
|
||||
return null;
|
||||
}
|
||||
$details[count($details) - 1]['key'] = count($details) - 1;
|
||||
return $details[count($details) - 1];
|
||||
}
|
||||
function getDefaultAddress($targetuserUID)
|
||||
{
|
||||
if (!$targetuserUID) {
|
||||
return false;
|
||||
}
|
||||
$details = $this->GetAddresses($targetuserUID);
|
||||
if (!$details) {
|
||||
return false;
|
||||
}
|
||||
if (count($details) === 1) {
|
||||
$details['key'] = 0;
|
||||
return $details[0];
|
||||
}
|
||||
foreach ($details as $key => $value) {
|
||||
if ($value['default']) {
|
||||
$value['key'] = $key;
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function SetAddresses($targetuserUID, $newaddresses)
|
||||
{
|
||||
|
||||
if (!$targetuserUID || !is_numeric($targetuserUID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if (is_array($newaddresses)) {
|
||||
$newaddresses = array_values($newaddresses);
|
||||
$newaddresses = json_encode($newaddresses);
|
||||
}
|
||||
|
||||
$data['addresses'] = $newaddresses;
|
||||
return $this->ModifybyTargetUserUID($targetuserUID, $data);
|
||||
}
|
||||
function AddAddress($targetuserUID, $address, $addressname, $contactname, $contactnumber, $default = false)
|
||||
{
|
||||
if (!$targetuserUID || !$address || !$addressname || !$contactname || !$contactnumber) {
|
||||
return false;
|
||||
}
|
||||
if ($default === 'true') {
|
||||
$default = true;
|
||||
} elseif ($default === 'false') {
|
||||
$default = 0;
|
||||
}
|
||||
|
||||
$data = $this->GetAddresses($targetuserUID);
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$data = [];
|
||||
}
|
||||
if ($default) {
|
||||
foreach ($data as $key => $value) {
|
||||
$data[$key][4] = false;
|
||||
}
|
||||
}
|
||||
$data[] = [$address, $addressname, $contactname, $contactnumber, $default];
|
||||
|
||||
$submit = $this->SetAddresses($targetuserUID, $data);
|
||||
if (!$submit) {
|
||||
return false;
|
||||
}
|
||||
return $this->GetLastAddress($targetuserUID);
|
||||
}
|
||||
function RemoveAddress($targetuserUID, $index)
|
||||
{
|
||||
if (!$targetuserUID || !is_numeric($index)) {
|
||||
return false;
|
||||
}
|
||||
$addressees = $this->GetAddresses($targetuserUID);
|
||||
if ($addressees === false) {
|
||||
return false;
|
||||
}
|
||||
if (!isset($addressees[$index])) {
|
||||
return false;
|
||||
}
|
||||
unset($addressees[$index]);
|
||||
$addressees = array_values($addressees);
|
||||
return $this->SetAddresses($targetuserUID, $addressees);
|
||||
}
|
||||
function ModifyAddressbyIndex($targetuserUID, $index,$name=null,$address=null,$contactname=null,$contactnumber=null,$default=null)
|
||||
{
|
||||
if(!$name && !$address && !$contactname && !$contactnumber && $default===null) {return false;}
|
||||
if (!$targetuserUID || !is_numeric($index)) {
|
||||
return false;
|
||||
}
|
||||
$addressees = $this->GetAddresses($targetuserUID);
|
||||
if ($addressees === false) {
|
||||
return false;
|
||||
}
|
||||
if (!isset($addressees[$index])) {
|
||||
return false;
|
||||
}
|
||||
$dataname= $addressees[$index][1] ?? false;
|
||||
$dataaddress = $addressees[$index][0] ?? false;
|
||||
$datacontactname =$addressees[$index][2] ?? false;
|
||||
$datacontactnumber = $addressees[$index][3] ?? false;
|
||||
$datadefault = $addressees[$index][4] ?? false;
|
||||
|
||||
$finalname = $name ?? $dataname;
|
||||
$finaladdress = $address ?? $dataaddress;
|
||||
$finalcontactname = $contactname ?? $datacontactname;
|
||||
$finaldatacontactnumber =$contactnumber ?? $datacontactnumber;
|
||||
if($default !==null){
|
||||
$finaldefault = $default;
|
||||
}else{
|
||||
$finaldefault= $datadefault;
|
||||
}
|
||||
|
||||
if ($finaldefault) {
|
||||
foreach ($addressees as $key => $value) {
|
||||
$addressees[$key][4] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$addressees[$index]=[$finaladdress,$finalname,$finalcontactname,$finaldatacontactnumber,$finaldefault];
|
||||
$addressees = array_values($addressees);
|
||||
return $this->SetAddresses($targetuserUID, $addressees);
|
||||
}
|
||||
function SetAddressAsDefault($targetuserUID,$index){
|
||||
return $this->ModifyAddressbyIndex($targetuserUID, $index,null,null,null,null,true);
|
||||
}
|
||||
function EmptyAddresses($targetuserUID)
|
||||
{
|
||||
return $this->SetAddresses($targetuserUID, '');
|
||||
}
|
||||
function ShowAddressFormat()
|
||||
{
|
||||
return ['Address', 'Address Name', 'Contact Name', 'Contact Number', 'default'];
|
||||
}
|
||||
}
|
||||
|
||||
function DB_USERINFO($db = false)
|
||||
{
|
||||
return new DB_USERINFO($db);
|
||||
}
|
||||
|
||||
function USERINFO_MULTIPLESEARCH($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
|
||||
return new USERINFO_QUICK_MULTIPLESEARCH($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
class USERINFO_QUICK_MULTIPLESEARCH
|
||||
{
|
||||
use DBClassSearch;
|
||||
public $data;
|
||||
|
||||
public $tablename = 'users';
|
||||
|
||||
private $parentidresults = [];
|
||||
public $DB;
|
||||
|
||||
public function __construct($data = [], $likefields = [], $fieldstoselectarray = '', $orderby = '', $noindex = 0, $whereappend = ' and ', $dateonlyarray = '', $newdata = false)
|
||||
{
|
||||
return $this->initialize($data, $likefields, $fieldstoselectarray, $orderby, $noindex, $whereappend, $dateonlyarray, $newdata);
|
||||
}
|
||||
|
||||
function FindName($uid)
|
||||
{
|
||||
return $this->Find($fieldname = 'uid', $contenttosearch = $uid, $exact = true)[0]['name'];
|
||||
}
|
||||
|
||||
}
|
||||
91
app/Http/Controllers/Helpers/Legacy/Backup/Main.lib.php
Normal file
91
app/Http/Controllers/Helpers/Legacy/Backup/Main.lib.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
$altdb = 'u943309104_bukid';
|
||||
$altuser = 'u943309104_bukidb';
|
||||
$altpass = 'lB&3I=t6';
|
||||
$althost = 'mysql';
|
||||
$root_passDB = 'as73n1^1dhu';
|
||||
|
||||
$defaultAdminAppUser = '777';
|
||||
$defaultAdminAppPassword = 'OmegaPsilon32!';
|
||||
$InitializeDB = false;
|
||||
|
||||
$GLOBALS['defaultAdminAppUser'] = $defaultAdminAppUser;
|
||||
$GLOBALS['defaultAdminAppPassword'] =$defaultAdminAppPassword;
|
||||
|
||||
|
||||
function loadSettings()
|
||||
{
|
||||
$filePath = 'settings/settings.json';
|
||||
if (file_exists($filePath)) {
|
||||
$jsonContent = file_get_contents($filePath);
|
||||
|
||||
$MainSettings = json_decode($jsonContent, true);
|
||||
return $MainSettings;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$MainSettings = loadSettings();
|
||||
|
||||
if (!file_exists('settings/DBInitialized') && $InitializeDB) {
|
||||
RunDBInit();
|
||||
}
|
||||
|
||||
function DB()
|
||||
{
|
||||
global $althost;
|
||||
global $altdb;
|
||||
global $altuser;
|
||||
global $altpass;
|
||||
global $defaultAdminAppUser;
|
||||
global $defaultAdminAppPassword;
|
||||
|
||||
try {
|
||||
$db = opennewdb($altdb, $althost, $altuser, $altpass);
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
try {
|
||||
$db = opennewdb('ta');
|
||||
} catch (Exception $le) {
|
||||
echo 'DB Error';
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
return $db;
|
||||
}
|
||||
|
||||
|
||||
function RunDBInit()
|
||||
{
|
||||
global $althost;
|
||||
global $altdb;
|
||||
global $altuser;
|
||||
global $altpass;
|
||||
$mysqli = new mysqli($althost, $altuser, $altpass, $altdb);
|
||||
echo 'Initializing DB...' . PHP_EOL;
|
||||
if ($mysqli->connect_error) {
|
||||
echo 'Error...' . '<br>';
|
||||
die("Connection failed: " . $mysqli->connect_error);
|
||||
}
|
||||
echo 'Connected to DB...' . '<br>';
|
||||
|
||||
$query = file_get_contents("init/mysql.sql");
|
||||
|
||||
if ($mysqli->multi_query($query)) {
|
||||
do {
|
||||
|
||||
} while ($mysqli->more_results() && $mysqli->next_result());
|
||||
file_put_contents('settings/DBInitialized', 'true');
|
||||
echo "SQL imported successfully.".'<br>' ;
|
||||
} else {
|
||||
echo "Error importing SQL: " . $mysqli->error.'<br>';
|
||||
}
|
||||
}
|
||||
|
||||
require_once('lib.php');
|
||||
require_once('DB.php');
|
||||
require_once('lib/logins.php');
|
||||
1140
app/Http/Controllers/Helpers/Legacy/Backup/index.php
Normal file
1140
app/Http/Controllers/Helpers/Legacy/Backup/index.php
Normal file
File diff suppressed because it is too large
Load Diff
651
app/Http/Controllers/Helpers/Legacy/Backup/logins.php
Normal file
651
app/Http/Controllers/Helpers/Legacy/Backup/logins.php
Normal file
@@ -0,0 +1,651 @@
|
||||
<?php
|
||||
|
||||
|
||||
ini_set('session.cookie_lifetime', 315360000);
|
||||
ini_set('session.gc_maxlifetime', 315360000);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
function generatesessionhash()
|
||||
{
|
||||
$bytes = random_bytes(36);
|
||||
return hash('sha256', bin2hex($bytes));
|
||||
}
|
||||
|
||||
function user_access($usertype)
|
||||
{
|
||||
|
||||
if (strtolower($usertype) === 'ult') {
|
||||
$accesslist = [
|
||||
'all'
|
||||
];
|
||||
} else if (strtolower($usertype) === 'super operator') {
|
||||
$accesslist = [
|
||||
'all',
|
||||
'manage_users',
|
||||
'manage_roles',
|
||||
'manage_permissions'
|
||||
];
|
||||
} else if (strtolower($usertype) === 'operator') {
|
||||
$accesslist = [
|
||||
'view_tickets',
|
||||
'create_tickets',
|
||||
'edit_tickets',
|
||||
'close_tickets',
|
||||
'manage_assigned_tickets'
|
||||
];
|
||||
} else if (strtolower($usertype) === 'coordinator') {
|
||||
$accesslist = [
|
||||
'view_tickets',
|
||||
'create_tickets',
|
||||
'edit_tickets',
|
||||
'close_tickets',
|
||||
'manage_assigned_tickets',
|
||||
'view_reports'
|
||||
];
|
||||
} else if (strtolower($usertype) === 'usher') {
|
||||
$accesslist = [
|
||||
'view_tickets',
|
||||
'create_tickets',
|
||||
'edit_tickets',
|
||||
'close_tickets'
|
||||
];
|
||||
} else if (strtolower($usertype) === 'user') {
|
||||
$accesslist = [
|
||||
'view_tickets',
|
||||
'create_tickets'
|
||||
];
|
||||
} else if (strtolower($usertype) === 'viewer') {
|
||||
$accesslist = [
|
||||
'view_tickets'
|
||||
];
|
||||
} else if (strtolower($usertype) === 'disabler') {
|
||||
$accesslist = [];
|
||||
} else {
|
||||
$accesslist = [];
|
||||
}
|
||||
|
||||
return $accesslist;
|
||||
|
||||
}
|
||||
|
||||
class WhatUserType
|
||||
{
|
||||
public $Usertype;
|
||||
|
||||
public function __construct($usertype = '---currentuser---')
|
||||
{
|
||||
if ($usertype === '---currentuser---') {
|
||||
global $CurrentUserType;
|
||||
$this->Usertype = $CurrentUserType;
|
||||
} else {
|
||||
$this->Usertype = $usertype;
|
||||
}
|
||||
}
|
||||
|
||||
private function ReadAndMatchType($arrayorStringUserTypes, $Targettype)
|
||||
{
|
||||
if (!$arrayorStringUserTypes || empty($arrayorStringUserTypes)) {
|
||||
return false;
|
||||
}
|
||||
$types = $arrayorStringUserTypes;
|
||||
if (!is_array($arrayorStringUserTypes)) {
|
||||
$types = tryjsondecode($arrayorStringUserTypes);
|
||||
}
|
||||
|
||||
if (is_array($types)) {
|
||||
return in_array($Targettype, $types);
|
||||
} else {
|
||||
return $Targettype === $types;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function IsUltimate()
|
||||
{
|
||||
return $this->ReadAndMatchType($this->Usertype, 'ult');
|
||||
}
|
||||
public function IsSuperOperator()
|
||||
{
|
||||
return $this->ReadAndMatchType($this->Usertype, 'super operator');
|
||||
}
|
||||
public function IsOperator()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'operator');
|
||||
}
|
||||
public function IsCoordinator()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'coordinator');
|
||||
}
|
||||
public function IsDisabler()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'disabler');
|
||||
}
|
||||
public function IsAgent()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'agent');
|
||||
}
|
||||
public function IsViewer()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'viewer');
|
||||
}
|
||||
public function IsStoreManager()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'store manager');
|
||||
}
|
||||
public function IsStoreOwner()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'store owner');
|
||||
}
|
||||
public function IsRider()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'rider');
|
||||
}
|
||||
public function IsAdminStaff()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'admin staff');
|
||||
}
|
||||
public function IsTeamLeader()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'team leader');
|
||||
}
|
||||
public function IsAudit()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'audit');
|
||||
}
|
||||
public function IsRegionalDirector()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'regional director');
|
||||
}
|
||||
public function IsRegularUser()
|
||||
{
|
||||
return $this->ReadAndMatchType( $this->Usertype, 'user');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
function WhatUserType($usertype = '---currentuser---')
|
||||
{
|
||||
return new WhatUserType($usertype);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function SendCookieSession($sessionId, $expiration_strtotime = '')
|
||||
{
|
||||
if (!$sessionId) {
|
||||
return false;
|
||||
}
|
||||
if ($expiration_strtotime) {
|
||||
$expiration_strtotime = time() + 720000000;
|
||||
}
|
||||
setcookie('TA_SESSION_COOKIE', $sessionId, [
|
||||
'expires' => $expiration_strtotime, // 30 days
|
||||
'path' => '/',
|
||||
'secure' => true, // Only send over HTTPS
|
||||
'httponly' => false, // Accessible only by the server
|
||||
'samesite' => 'Strict' // CSRF protection
|
||||
]);
|
||||
}
|
||||
|
||||
function getSessionKeyEitherCookieorSession()
|
||||
{
|
||||
if (!isset($_SESSION['TA']['SESSIONKEY']) or !$_SESSION['TA']['SESSIONKEY']) {
|
||||
} else {
|
||||
return $_SESSION['TA']['SESSIONKEY'];
|
||||
}
|
||||
if (isset($_COOKIE["TA_SESSION_COOKIE"]) and $_COOKIE["TA_SESSION_COOKIE"]) {
|
||||
return $_COOKIE["TA_SESSION_COOKIE"];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function DeleteRemoveSessionKeyCookie()
|
||||
{
|
||||
setcookie("TA_SESSION_COOKIE", "", time() - 3600, "/");
|
||||
$_SESSION['TA']['SESSIONKEY'] = '';
|
||||
}
|
||||
|
||||
function UpdateSessionorCookieKey($sessionid, $expiration_strtotime = '')
|
||||
{
|
||||
if (!$sessionid) {
|
||||
return false;
|
||||
}
|
||||
$_SESSION['TA']['SESSIONKEY'] = $sessionid;
|
||||
SendCookieSession($sessionid, $expiration_strtotime);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function loginstatus()
|
||||
{
|
||||
|
||||
if (!getSessionKeyEitherCookieorSession()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$sessiondata = getActiveSessionData(getSessionKeyEitherCookieorSession());
|
||||
if (!$sessiondata) {
|
||||
return false;
|
||||
}
|
||||
$expiry = strtotime($sessiondata['expiry']);
|
||||
$now = strtotime('now');
|
||||
$active = $sessiondata['userdata']['active'];
|
||||
$expired = $now > $expiry;
|
||||
$time_difference = $expiry - $now;
|
||||
$NOT_EXPIRED = !$expired;
|
||||
|
||||
if ($sessiondata and $NOT_EXPIRED and $active) {
|
||||
if ($time_difference < 300) {
|
||||
$newexpiry = $expiry + (5 * 60);
|
||||
$newexpiry = date("Y-m-d H:i:s", $newexpiry);
|
||||
ModifySession($sessiondata['hashkey'], ['expiry' => $newexpiry]);
|
||||
$sessiondata['expiry'] = $newexpiry;
|
||||
}
|
||||
if (YesNoRandom() and false) {//remove false to allow regeneration of id. currently logsuser out immediately
|
||||
$newsessionid = regeneratesessionidANDUpdateSessionVar();
|
||||
if ($newsessionid) {
|
||||
$sessiondata['hashkey'] = $newsessionid;
|
||||
}
|
||||
}
|
||||
UpdateSessionorCookieKey($sessiondata['hashkey'], strtotime($sessiondata['expiry']));
|
||||
return $sessiondata;
|
||||
} else {
|
||||
deleteSession(getSessionKeyEitherCookieorSession());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getRandomNumber($length = 1)
|
||||
{
|
||||
$random_bytes = openssl_random_pseudo_bytes($length);
|
||||
return ord($random_bytes[0]);
|
||||
}
|
||||
function YesNoRandom()
|
||||
{
|
||||
$regenerate_threshold = 50;
|
||||
$random_number = getRandomNumber(1);
|
||||
if ($random_number <= $regenerate_threshold) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function regeneratesessionid($currensessionhash)
|
||||
{
|
||||
if (!$currensessionhash) {
|
||||
return false;
|
||||
}
|
||||
$newhash = generatesessionhash();
|
||||
$data['hashkey'] = $newhash;
|
||||
$modify = ModifySession($currensessionhash, $data);
|
||||
if (!$modify) {
|
||||
return false;
|
||||
}
|
||||
return $newhash;
|
||||
}
|
||||
|
||||
function regeneratesessionidANDUpdateSessionVar()
|
||||
{
|
||||
$sessionnewid = regeneratesessionid(getSessionKeyEitherCookieorSession());
|
||||
if ($sessionnewid) {
|
||||
UpdateSessionorCookieKey($sessionnewid);
|
||||
return $sessionnewid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function tryloginwcookies($SESSION_ID)
|
||||
{
|
||||
$sessiondata = getActiveSessionData($SESSION_ID);
|
||||
if (!$sessiondata) {
|
||||
return false;
|
||||
}
|
||||
//$_SESSION['TA']['SESSIONKEY']
|
||||
|
||||
}
|
||||
function getUserType()
|
||||
{
|
||||
$loginstatus = loginstatus();
|
||||
if (!$loginstatus) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (isset($loginstatus['userdata']['acct_type']) and $loginstatus['userdata']['acct_type']) {
|
||||
return $loginstatus['userdata']['acct_type'];
|
||||
}
|
||||
}
|
||||
|
||||
function IsUserCoordinator()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'coordinator') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function IsUserUltimate()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'ult') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function IsUserOperator()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'operator') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function IsUserSuperOperator()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'super operator') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function IsUserUsher()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'usher') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function IsUserViewer()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'viewer') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function IsUserDisabler()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'disabler') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function IsNormalUser()
|
||||
{
|
||||
if (strtolower(getUserType()) == 'user') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function CurrentUserUID()
|
||||
{
|
||||
$loginstatus = loginstatus()['userdata']['uid'] ?? false;
|
||||
return $loginstatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function loginnow($username, $password, $keep_alive = false)
|
||||
{
|
||||
if (!$username or !$password) {
|
||||
|
||||
return false;
|
||||
}
|
||||
if (loginstatus()) {
|
||||
return loginstatus();
|
||||
}
|
||||
$trylogin = trylogin($username, $password);
|
||||
if (!$trylogin) {
|
||||
|
||||
return false;
|
||||
}
|
||||
$userid = $trylogin['uid'];
|
||||
if ($keep_alive) {
|
||||
$expiry = date("Y-m-d H:i:s", strtotime('+ 10 years'));
|
||||
} else {
|
||||
$expiry = date("Y-m-d H:i:s", strtotime('+ 2 hours'));
|
||||
}
|
||||
$newsessionkey = NewSession($userid, 1, $expiry);
|
||||
|
||||
$_SESSION['TA']['SESSIONKEY'] = $newsessionkey;
|
||||
|
||||
return $newsessionkey;
|
||||
}
|
||||
|
||||
function logoutnow()
|
||||
{
|
||||
deleteAllUserSessions(CurrentUserUID());
|
||||
unset($_SESSION['TA']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function NewSession($userid, $active = 1, $expiry = false)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$user = checkifexists('users', ['uid' => $userid], ['hashkey', 'nickname', 'acct_type', 'mnumber', 'active', 'parentuid', 'targetuids', 'multiple_logins']);
|
||||
if (!$user) {
|
||||
return 'NO USER';
|
||||
}
|
||||
|
||||
if (checkifexists('sessions', ['userid' => $userid, 'active' => 1], $fieldstoselectarray = '')) {
|
||||
if (!$user['multiple_logins']) {
|
||||
deleteAllUserSessions($userid);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$expiry) {
|
||||
$expiry = date("Y-m-d H:i:s", strtotime('+10 years'));
|
||||
}
|
||||
unset($user['password']);
|
||||
unset($user['creation_date']);
|
||||
unset($user['modified_date']);
|
||||
$newhash = generatesessionhash();
|
||||
$data['hashkey'] = $newhash;
|
||||
$data['userid'] = $userid;
|
||||
$data['active'] = $active;
|
||||
$data['expiry'] = $expiry;
|
||||
$data['userdata'] = json_encode($user);
|
||||
|
||||
$usertype = user_access($user['acct_type']);
|
||||
|
||||
$data['accesslist'] = json_encode($usertype);
|
||||
$key = insertintodb(DB(), 'sessions', $data);
|
||||
|
||||
$sessiondata = getSessionData($newhash);
|
||||
if (!$sessiondata) {
|
||||
return false;
|
||||
}
|
||||
$sessionHistory = NewSession_History($userid, $sessiondata, $active, $expiry);
|
||||
|
||||
if (!$sessionHistory) {
|
||||
deleteSession($newhash);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $newhash;
|
||||
}
|
||||
|
||||
function getSessionData($sessionhash)
|
||||
{
|
||||
$sessionhash = checkifexists('sessions', ['hashkey' => $sessionhash]);
|
||||
if ($sessionhash and is_array($sessionhash) and !empty($sessionhash)) {
|
||||
$sessiondata['userdata'] = json_decode($sessionhash['userdata'], 1);
|
||||
$userhashkey = $sessiondata['userdata']['hashkey'];
|
||||
$fieldstoselect = [
|
||||
'uid',
|
||||
'hashkey',
|
||||
'nickname',
|
||||
'acct_type',
|
||||
'mnumber',
|
||||
'active',
|
||||
'parentuid',
|
||||
'targetuids'
|
||||
];
|
||||
$sessionhash['userdata'] = GetUserDatabyUID($userhashkey, $fieldstoselect);
|
||||
$usertype = $sessionhash['userdata']['acct_type'];
|
||||
$sessionhash['accesslist'] = user_access($usertype);
|
||||
return $sessionhash;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getActiveSessionData($sessionhash)
|
||||
{
|
||||
$session = getSessionData($sessionhash);
|
||||
if ($session and $session['active'] === 1) {
|
||||
return $session;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
function deleteSession($sessionhash)
|
||||
{
|
||||
deletefromdb('sessions', ['hashkey' => $sessionhash]);
|
||||
if (checkifexists('sessions', ['hashkey' => $sessionhash], ['hashkey'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function deleteAllUserSessions($userid)
|
||||
{
|
||||
deletefromdb('sessions', ['userid' => $userid]);
|
||||
if (checkifexists('sessions', ['userid' => $userid], ['hashkey'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function FindCurrentSessionForUser($userid)
|
||||
{
|
||||
$search = checkifexists('sessions', ['userid' => $userid, 'active' => 1], ['hashkey']);
|
||||
if ($search and isset($search['hashkey'])) {
|
||||
return $search['hashkey'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function ModifySession($sessionhash, $newdata)
|
||||
{
|
||||
if (!$sessionhash) {
|
||||
return false;
|
||||
}
|
||||
$check = checkifexists('sessions', ['hashkey' => $sessionhash]);
|
||||
if (!$check or empty($check['hashkey'] or !$check['hashkey'])) {
|
||||
return false;
|
||||
}
|
||||
$whereArray = ['hashkey' => $sessionhash];
|
||||
return updatedbsimple(DB(), 'sessions', $newdata, $whereArray);
|
||||
}
|
||||
|
||||
function ExtendSession($sessionhash, $newexpiry = false)
|
||||
{
|
||||
if (!$newexpiry) {
|
||||
$newexpiry = date("Y-m-d H:i:s", strtotime('+3 days'));
|
||||
}
|
||||
return ModifySession($sessionhash, ['expiry' => $newexpiry]);
|
||||
}
|
||||
function ExtendSessionbyUID($UID, $newexpiry = false)
|
||||
{
|
||||
if (!$newexpiry) {
|
||||
$newexpiry = date("Y-m-d H:i:s", strtotime('+3 days'));
|
||||
}
|
||||
$usersession = FindCurrentSessionForUser($UID);
|
||||
return ModifySession($usersession, ['expiry' => $newexpiry]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//SessionHistory
|
||||
|
||||
|
||||
function NewSession_History($userid, $sessiondata, $active = 1, $expiry = false)
|
||||
{
|
||||
|
||||
|
||||
|
||||
$newhash = generatesessionhash();
|
||||
$data['hashkey'] = $newhash;
|
||||
$data['userid'] = $sessiondata['userid'];
|
||||
$data['old_hashkey'] = $sessiondata['hashkey'];
|
||||
$data['active'] = $sessiondata['active'];
|
||||
$data['expiry'] = $sessiondata['expiry'];
|
||||
$data['accesslist'] = $sessiondata['accesslist'];
|
||||
$data['userdata'] = $sessiondata['userdata'];
|
||||
$data['login_time'] = serverdatetimesql();
|
||||
$data['serverdata'] = json_encode($_SERVER);
|
||||
$data['ip_address'] = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
|
||||
$key = insertintodb(DB(), 'session_history', $data);
|
||||
|
||||
if (!$key) {
|
||||
return false;
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
|
||||
function NewLog($log_type, $log_category, $description, $useruid = '')
|
||||
{
|
||||
|
||||
if (!$useruid) {
|
||||
$useruid = CurrentUserUID();
|
||||
}
|
||||
|
||||
$data['log_time'] = serverdatetimesql();
|
||||
$data['log_type'] = $log_type;
|
||||
$data['log_category'] = $log_category;
|
||||
$data['description'] = $description;
|
||||
$data['server_data'] = json_encode($_SERVER);
|
||||
$data['session_data'] = json_encode($_SESSION);
|
||||
$data['useruid'] = $useruid;
|
||||
|
||||
|
||||
$key = insertintodb(DB(), 'logs', $data);
|
||||
|
||||
|
||||
if (!$key) {
|
||||
return false;
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
945
app/Http/Controllers/Helpers/Legacy/LibLegacy.php
Normal file
945
app/Http/Controllers/Helpers/Legacy/LibLegacy.php
Normal file
@@ -0,0 +1,945 @@
|
||||
<?php
|
||||
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Helpers\Permissions;
|
||||
|
||||
use App\Enums\UserTypes;
|
||||
use Hypervel\Http\Request;
|
||||
use App\Models\User;
|
||||
use Hypervel\Support\Facades\Auth;
|
||||
use App\Enums\UserActions;
|
||||
use App\Http\Controllers\Helpers\QueryHelper;
|
||||
use App\Models\Market\Product;
|
||||
use App\Models\Market\Store;
|
||||
use Exception;
|
||||
|
||||
class LibLegacy
|
||||
{
|
||||
|
||||
function endsWithSlash($path)
|
||||
{
|
||||
if (strlen($path) === 0) {
|
||||
return false;
|
||||
}
|
||||
$lastChar = substr($path, -1);
|
||||
return $lastChar === '/' || $lastChar === '\\';
|
||||
}
|
||||
|
||||
function ArraytoHash($array)
|
||||
{
|
||||
if (!is_array($array) || empty($array)) {
|
||||
return false;
|
||||
}
|
||||
$jsonString = json_encode($array);
|
||||
$hash = hash('sha256', $jsonString);
|
||||
return $hash;
|
||||
}
|
||||
|
||||
function SetNoCache()
|
||||
{
|
||||
header('Cache-Control: no-cache');
|
||||
}
|
||||
|
||||
function SetCacheTime($seconds)
|
||||
{
|
||||
if ($seconds) {
|
||||
return false;
|
||||
}
|
||||
header('Cache-Control: max-age=' . $seconds . '');
|
||||
}
|
||||
function SetCacheTimeMinutes($minutes)
|
||||
{
|
||||
if ($minutes) {
|
||||
return false;
|
||||
}
|
||||
$seconds = $minutes * 60;
|
||||
header('Cache-Control: max-age=' . $seconds . '');
|
||||
}
|
||||
|
||||
function SetCache1Year()
|
||||
{
|
||||
header('Cache-Control: max-age=31536000, public');
|
||||
}
|
||||
|
||||
function json_array_echo($array)
|
||||
{
|
||||
jsonheader();
|
||||
echo json_encode($array);
|
||||
}
|
||||
function tryjsondecode($string, $arrayoutput = true)
|
||||
{
|
||||
if (is_array($string)) {
|
||||
return $string;
|
||||
}
|
||||
if (!$string) {
|
||||
return $string;
|
||||
}
|
||||
$json = json_decode($string, $arrayoutput);
|
||||
if ($json === null) {
|
||||
return $string;
|
||||
} else {
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
|
||||
function tryjsonencode($array)
|
||||
{
|
||||
if (!$array) {
|
||||
return json_encode([]);
|
||||
}
|
||||
if (is_array($array)) {
|
||||
$result = json_encode($array);
|
||||
} else {
|
||||
$result = json_encode([$array]);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function filterArrayColumns($array, $columns)
|
||||
{
|
||||
return array_map(function ($item) use ($columns) {
|
||||
return array_intersect_key($item, array_flip($columns));
|
||||
}, $array);
|
||||
}
|
||||
|
||||
function logmaker($filename, $nolog = false)
|
||||
{
|
||||
$main = new class ($filename, $nolog) {
|
||||
public $filename;
|
||||
public $loglistarray = [];
|
||||
|
||||
public function __construct($filename, $nolog)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
if ($nolog) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function add($str)
|
||||
{
|
||||
$this->loglistarray[] = $str;
|
||||
}
|
||||
|
||||
public function done()
|
||||
{
|
||||
file_put_contents($this->filename, implode("\r\n\r\n", $this->loglistarray));
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
file_put_contents($this->filename, implode("\r\n\r\n", $this->loglistarray));
|
||||
}
|
||||
};
|
||||
return $main;
|
||||
}
|
||||
|
||||
function createThumbnail($sourcePath, $destinationPath = null, $thumbWidth = 64, $thumbHeight = 64)
|
||||
{
|
||||
list($width, $height, $type) = getimagesize($sourcePath);
|
||||
$srcImage = null;
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$srcImage = imagecreatefromjpeg($sourcePath);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$srcImage = imagecreatefrompng($sourcePath);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$srcImage = imagecreatefromgif($sourcePath);
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Unsupported image type');
|
||||
}
|
||||
|
||||
$thumbImage = imagecreatetruecolor($thumbWidth, $thumbHeight);
|
||||
|
||||
imagecopyresampled($thumbImage, $srcImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height);
|
||||
|
||||
if (!$destinationPath) {
|
||||
$basepath = dirname($sourcePath);
|
||||
$basenameWithoutExtension = pathinfo($sourcePath, PATHINFO_FILENAME);
|
||||
$extension = pathinfo($sourcePath, PATHINFO_EXTENSION) ?? '';
|
||||
if ($extension) {
|
||||
$extension = '.' + $extension;
|
||||
}
|
||||
$newfilename = $basenameWithoutExtension + '_thumbnail' + $extension;
|
||||
$destinationPath = $basepath + '/' + $newfilename;
|
||||
}
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($thumbImage, $destinationPath);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($thumbImage, $destinationPath);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
imagegif($thumbImage, $destinationPath);
|
||||
break;
|
||||
}
|
||||
|
||||
imagedestroy($srcImage);
|
||||
imagedestroy($thumbImage);
|
||||
}
|
||||
|
||||
|
||||
function trim_ending_hyphen($string)
|
||||
{
|
||||
if (substr($string, -1) === "-") {
|
||||
return substr($string, 0, -1); // Remove the last character (hyphen)
|
||||
} else {
|
||||
return $string; // Return the original string if it doesn't end with a hyphen
|
||||
}
|
||||
}
|
||||
|
||||
function convertStringToSQLDateTime($stringDate)
|
||||
{
|
||||
$timestamp = strtotime($stringDate);
|
||||
$sqlDatetime = date("Y-m-d H:i:s", $timestamp);
|
||||
return $sqlDatetime;
|
||||
}
|
||||
|
||||
|
||||
function comparestringnumberstoarray($string, $comparearray, $inorder = false)
|
||||
{
|
||||
$mainarray = explode('-', $string);
|
||||
$mainarray = array_values($mainarray);
|
||||
|
||||
$lastvaluemainarray = $mainarray[count($mainarray) - 1];
|
||||
if ($lastvaluemainarray === '') {
|
||||
array_pop($mainarray);
|
||||
}
|
||||
|
||||
if (in_array('', $mainarray)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$inorder) {
|
||||
sort($mainarray);
|
||||
sort($comparearray);
|
||||
}
|
||||
|
||||
return $mainarray == $comparearray;
|
||||
}
|
||||
|
||||
|
||||
function refreshpage()
|
||||
{
|
||||
return '<script>location.reload()</script>';
|
||||
}
|
||||
function refreshpagenopost()
|
||||
{
|
||||
|
||||
return '<script>window.location = window.location.href</script>';
|
||||
}
|
||||
function refresh()
|
||||
{
|
||||
header('Location: .');
|
||||
}
|
||||
function jschangetopurl($url)
|
||||
{
|
||||
|
||||
return '<script>top.location = "' . $url . '";</script>';
|
||||
}
|
||||
|
||||
function jschangetopurlnoscripttag($url)
|
||||
{
|
||||
|
||||
return "top.location = '" . $url . "';";
|
||||
}
|
||||
function jsopenmodal($modalname)
|
||||
{
|
||||
return '<script>
|
||||
$(document).ready(function(){
|
||||
$("#' . $modalname . '").modal();
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
function jsonheader()
|
||||
{
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
}
|
||||
|
||||
function simpleredirect($requesturl, $functiontoexecute, $reqtype = '', $fallbackfunction = NULL, $conditiontrue = NULL, $caching = false)
|
||||
{
|
||||
|
||||
// sample url = http://website.com/?u=name/{john}
|
||||
// sample function syntax simpleredirect('name/{}')
|
||||
|
||||
if (file_exists('sim.txt')) {
|
||||
unlink('sim.txt');
|
||||
}
|
||||
$addlog = function ($str) {
|
||||
@file_put_contents('sim.txt', $str . "\r\n", FILE_APPEND);
|
||||
};
|
||||
|
||||
|
||||
|
||||
$urlcheck = geturlparameters($requesturl);
|
||||
|
||||
$addlog('chekingurl=' . getappendedurl() . ' requrl=' . $requesturl);
|
||||
|
||||
if ($urlcheck === FALSE) {
|
||||
$addlog('urlcheck=false');
|
||||
return false;
|
||||
}
|
||||
$addlog('chekingurl success');
|
||||
if ($reqtype == '') {
|
||||
$reqtype = 'get';
|
||||
$addlog('reqtype unknown changing to get');
|
||||
} else {
|
||||
$reqtype = strtolower($reqtype);
|
||||
|
||||
$addlog('reqtype = ' . $reqtype);
|
||||
}
|
||||
|
||||
if ($reqtype !== 'post' and $reqtype !== 'get') {
|
||||
$reqtype = 'get';
|
||||
$addlog('reqtype not post or get changing to get');
|
||||
}
|
||||
|
||||
if (strtolower($reqtype) !== strtolower($_SERVER['REQUEST_METHOD'])) {
|
||||
$addlog('reqtype not the same reqtype = ' . $reqtype . ' requestmethod = ' . $_SERVER['REQUEST_METHOD']);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$GLOBALS['urlparameters'] = $urlcheck;
|
||||
|
||||
if ($conditiontrue !== NULL and !$conditiontrue) {
|
||||
$addlog('condition not true exiting');
|
||||
if ($fallbackfunction) {
|
||||
$fallbackfunction();
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!$caching) {
|
||||
$addlog('removing cache');
|
||||
removecaching();
|
||||
} elseif ($caching) {
|
||||
$addlog('adding cache');
|
||||
if ($caching === true) {
|
||||
SetCache1Year();
|
||||
} elseif (is_numeric($caching)) {
|
||||
SetCacheTimeMinutes($caching);
|
||||
} else {
|
||||
SetCache1Year();
|
||||
}
|
||||
}
|
||||
$addlog('executing function');
|
||||
$functiontoexecute($urlcheck);
|
||||
}
|
||||
|
||||
|
||||
function simpleredirectfile($requesturl, $file, $reqtype = '', $fallbackfunction = NULL, $conditiontrue = NULL, $caching = FALSE)
|
||||
{
|
||||
$filefunct = function () use ($file) {
|
||||
readfile($file);
|
||||
};
|
||||
simpleredirect($requesturl, $filefunct, $reqtype, $fallbackfunction, $conditiontrue, $caching);
|
||||
}
|
||||
|
||||
|
||||
function checkifstringisenclosedinbrackets($string)
|
||||
{
|
||||
// checks if string is enclosed in brackers ex {name}
|
||||
//returns string inside and returns false if there is no bracket
|
||||
if (substr($string, 0, 1) === "{" && substr($string, -1) === "}") {
|
||||
$string = substr($string, 1, -1);
|
||||
} else {
|
||||
$string = false;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function geturlparameters($urlparam)
|
||||
{
|
||||
//urlparam = 'users/'
|
||||
if ($urlparam === '') {
|
||||
$urlparam = [];
|
||||
} else {
|
||||
$urlparam = explode('/', $urlparam);
|
||||
}
|
||||
$url = geturlarray();
|
||||
|
||||
|
||||
if (count($url) !== count($urlparam)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$params = [];
|
||||
foreach ($urlparam as $key => $value) {
|
||||
if ($urlparam[$key] !== $url[$key]) {
|
||||
$enclosed = checkifstringisenclosedinbrackets($value);
|
||||
if ($enclosed) {
|
||||
$params[$enclosed] = $url[$key];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
function getLastDigitSegments($string, $n)
|
||||
{
|
||||
$parts = explode('-', $string);
|
||||
$lastSegments = array_slice($parts, -$n);
|
||||
return implode('-', $lastSegments);
|
||||
}
|
||||
function geturlarray()
|
||||
{
|
||||
$url = getappendedurl();
|
||||
|
||||
if (substr($url, 0, 1) === "/") {
|
||||
$uri = substr($url, 1);
|
||||
} else {
|
||||
$uri = $url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$uri = array_values(array_filter(explode('/', $uri)));
|
||||
unset($uri[0]);
|
||||
$uri = array_values($uri);
|
||||
if (empty($uri)) {
|
||||
return [];
|
||||
}
|
||||
if (substr($uri[0], 0, 1) === "?") {
|
||||
$uri[0] = substr($uri[0], 1);
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
function getappendedurl()
|
||||
{
|
||||
//get appended url sample url https:/google.com/aslkdfj/asdf/asdf
|
||||
//result aslkdfj/asdf/asdf
|
||||
return $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
|
||||
function removecaching()
|
||||
{
|
||||
if (headers_sent()) {
|
||||
return false;
|
||||
}
|
||||
header_remove('ETag');
|
||||
header_remove('Pragma');
|
||||
header_remove('Cache-Control');
|
||||
header_remove('Last-Modified');
|
||||
header_remove('Expires');
|
||||
|
||||
// set header
|
||||
header('Expires: Thu, 1 Jan 1970 00:00:00 GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
}
|
||||
|
||||
|
||||
function is_valid_var($var)
|
||||
{
|
||||
if (!isset($var)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($var) || $var === false || is_null($var)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
function ConvertDatetoMDYYYY($datestring)
|
||||
{
|
||||
//from YYYY-MM-DD to M/D/YYYY
|
||||
if (!$datestring) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$timestamp = strtotime($datestring);
|
||||
$formattedDate = date('n/j/Y', $timestamp);
|
||||
return $formattedDate;
|
||||
}
|
||||
|
||||
function PNGtoJPGNN($filelocation, $newfilelocation)
|
||||
{
|
||||
$new_pic = imagecreatefrompng($filelocation);
|
||||
$w = imagesx($new_pic);
|
||||
$h = imagesy($new_pic);
|
||||
$white = imagecreatetruecolor($w, $h);
|
||||
$bg = imagecolorallocate($white, 255, 255, 255);
|
||||
imagefill($white, 0, 0, $bg);
|
||||
|
||||
imagecopy($white, $new_pic, 0, 0, 0, 0, $w, $h);
|
||||
$success = imagejpeg($white, $newfilelocation);
|
||||
imagedestroy($new_pic);
|
||||
imagedestroy($white);
|
||||
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
||||
function PNGtoJPG($pngFilePath, $jpgFilePath, $maxWidth = false, $maxHeight = false, $quality = 100)
|
||||
{
|
||||
$pngImage = imagecreatefrompng($pngFilePath);
|
||||
if (!$pngImage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$originalWidth = imagesx($pngImage);
|
||||
$originalHeight = imagesy($pngImage);
|
||||
if (!$maxWidth && !$maxHeight) {
|
||||
$maxWidth = $originalWidth;
|
||||
$maxHeight = $originalHeight;
|
||||
}
|
||||
|
||||
$aspectRatio = $originalWidth / $originalHeight;
|
||||
|
||||
if ($maxWidth / $maxHeight > $aspectRatio) {
|
||||
$newWidth = $maxHeight * $aspectRatio;
|
||||
$newHeight = $maxHeight;
|
||||
} else {
|
||||
$newWidth = $maxWidth;
|
||||
$newHeight = $maxWidth / $aspectRatio;
|
||||
}
|
||||
$newWidth = ceil($newWidth);
|
||||
$newHeight = ceil(num: $newHeight);
|
||||
|
||||
$jpgImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
imagecopyresampled($jpgImage, $pngImage, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
|
||||
$success = imagejpeg($jpgImage, $jpgFilePath, $quality);
|
||||
|
||||
imagedestroy($pngImage);
|
||||
imagedestroy($jpgImage);
|
||||
return $success;
|
||||
}
|
||||
|
||||
function PNGtoWebP($pngFilePath, $webpFilePath, $maxWidth = false, $maxHeight = false, $quality = 100)
|
||||
{
|
||||
$pngImage = imagecreatefrompng($pngFilePath);
|
||||
if (!$pngImage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$originalWidth = imagesx($pngImage);
|
||||
$originalHeight = imagesy($pngImage);
|
||||
|
||||
if (!$maxWidth && !$maxHeight) {
|
||||
$maxWidth = $originalWidth;
|
||||
$maxHeight = $originalHeight;
|
||||
}
|
||||
|
||||
$aspectRatio = $originalWidth / $originalHeight;
|
||||
|
||||
if ($maxWidth / $maxHeight > $aspectRatio) {
|
||||
$newWidth = $maxHeight * $aspectRatio;
|
||||
$newHeight = $maxHeight;
|
||||
} else {
|
||||
$newWidth = $maxWidth;
|
||||
$newHeight = $maxWidth / $aspectRatio;
|
||||
}
|
||||
$newWidth = ceil($newWidth);
|
||||
$newHeight = ceil(num: $newHeight);
|
||||
|
||||
$webpImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||
|
||||
imagealphablending($webpImage, false);
|
||||
imagesavealpha($webpImage, true);
|
||||
$transparent = imagecolorallocatealpha($webpImage, 255, 255, 255, 127);
|
||||
imagefilledrectangle($webpImage, 0, 0, $newWidth, $newHeight, $transparent);
|
||||
|
||||
imagecopyresampled($webpImage, $pngImage, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
|
||||
|
||||
$success = imagewebp($webpImage, $webpFilePath, $quality);
|
||||
imagedestroy($pngImage);
|
||||
imagedestroy($webpImage);
|
||||
return $success;
|
||||
}
|
||||
|
||||
function BatchConvertPNG($oldfolder, $newfolder, $newtype = 'webp', $maxWidth = false, $maxHeight = false, $quality = 100)
|
||||
{
|
||||
//filename from old folder to new folder is copied exactly even the extensions are the same.
|
||||
if (!$newtype) {
|
||||
$newtype = 'webp';
|
||||
}
|
||||
$oldfolder = AddSlashtoStrifNolastSlash($oldfolder);
|
||||
$newfolder = AddSlashtoStrifNolastSlash($newfolder);
|
||||
$processIMG = function ($oldfilename) use ($newfolder, $newtype, $maxWidth, $maxHeight, $quality) {
|
||||
if (!file_exists($oldfilename)) {
|
||||
echo $oldfilename . '<br>';
|
||||
return false;
|
||||
}
|
||||
$mimetype = mime_content_type($oldfilename);
|
||||
if (!str_contains($mimetype, 'png')) {
|
||||
return false;
|
||||
}
|
||||
$basefilename = basename($oldfilename);
|
||||
$newjpglocation = $newfolder . $basefilename;
|
||||
|
||||
if (strtolower($newtype) === 'webp') {
|
||||
return PNGtoWebP($oldfilename, $newjpglocation, $maxWidth, $maxHeight, $quality);
|
||||
} elseif (strtolower($newtype) === 'jpg' || strtolower($newtype) === 'jpeg') {
|
||||
return PNGtoJPG($oldfilename, $newjpglocation, $maxWidth, $maxHeight, $quality);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
$dir = scandir($oldfolder);
|
||||
foreach ($dir as $keyy => $file) {
|
||||
if ($file === '..') {
|
||||
unset($dir[$keyy]);
|
||||
continue;
|
||||
}
|
||||
if ($file === '.') {
|
||||
unset($dir[$keyy]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
foreach ($dir as $file) {
|
||||
$oldfilename = $oldfolder . '/' . $file;
|
||||
$processIMG($oldfilename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function AddSlashtoStrifNolastSlash($str)
|
||||
{
|
||||
if (!$str) {
|
||||
return false;
|
||||
}
|
||||
$lastchar = substr($str, -1);
|
||||
if ($lastchar !== '/' && $lastchar !== '\\') {
|
||||
$str .= '/';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
function formatDateTimetoReadable($dateTimeString)
|
||||
{
|
||||
if (empty($dateTimeString)) {
|
||||
return '';
|
||||
}
|
||||
$date = new DateTime($dateTimeString);
|
||||
if (!$date) {
|
||||
return '';
|
||||
}
|
||||
$formattedDate = $date->format('F j, Y');
|
||||
$hours = (int) $date->format('g');
|
||||
$minutes = (int) $date->format('i');
|
||||
$ampm = $date->format('A');
|
||||
$formattedMinutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
|
||||
return strpos($dateTimeString, ' ') !== false
|
||||
? "{$formattedDate} {$hours}:{$formattedMinutes}{$ampm}"
|
||||
: "{$formattedDate}";
|
||||
}
|
||||
|
||||
function generateDatesOLD($daysArray, $months = 1, $sort = true)
|
||||
{
|
||||
if (!$daysArray) {
|
||||
return false;
|
||||
}
|
||||
if (!is_array($daysArray)) {
|
||||
$daysArray = tryjsondecode($daysArray);
|
||||
}
|
||||
if (!is_array($daysArray)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dates = [];
|
||||
|
||||
// Iterate through each day in the array
|
||||
foreach ($daysArray as $day) {
|
||||
list($weekday, $time) = $day;
|
||||
|
||||
$currentDate = new DateTime();
|
||||
$currentDate->modify("next $weekday");
|
||||
|
||||
for ($i = 0; $i < $months; $i++) {
|
||||
// Add the time to the current date
|
||||
$dateWithTime = $currentDate->format('Y-m-d') . ' ' . $time;
|
||||
|
||||
// Add the date to the array
|
||||
$dates[] = $dateWithTime;
|
||||
|
||||
// Move to the next week (incrementing only the week part)
|
||||
$currentDate->modify('+1 week');
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the dates if specified
|
||||
if ($sort) {
|
||||
sort($dates);
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generateDatesNEW($daysArray, $months = 2, $sort = true)
|
||||
{
|
||||
if (!$daysArray) {
|
||||
return false;
|
||||
}
|
||||
if (!is_array($daysArray)) {
|
||||
$daysArray = tryjsondecode($daysArray);
|
||||
}
|
||||
if (!is_array($daysArray)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dates = [];
|
||||
|
||||
// Iterate through each day in the array
|
||||
foreach ($daysArray as $day) {
|
||||
list($weekday, $time) = $day;
|
||||
|
||||
$currentDate = new DateTime();
|
||||
|
||||
// If today is the specified weekday, include it
|
||||
if (strtolower($currentDate->format('D')) === strtolower($weekday)) {
|
||||
$dateWithTime = $currentDate->format('Y-m-d') . ' ' . $time;
|
||||
$dates[] = $dateWithTime;
|
||||
}
|
||||
|
||||
// Move to the next week (incrementing only the week part)
|
||||
$currentDate->modify("next $weekday");
|
||||
|
||||
for ($i = 1; $i < $months; $i++) {
|
||||
// Add the time to the current date
|
||||
$dateWithTime = $currentDate->format('Y-m-d') . ' ' . $time;
|
||||
|
||||
// Add the date to the array
|
||||
$dates[] = $dateWithTime;
|
||||
|
||||
// Move to the next week (incrementing only the week part)
|
||||
$currentDate->modify('+1 week');
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the dates if specified
|
||||
if ($sort) {
|
||||
sort($dates);
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
function generateDates($daysArray, $days = 8, $sort = true)
|
||||
{
|
||||
$dates = generateDatesNEW($daysArray, $months = 4, $sort);
|
||||
unset($dates[0]);
|
||||
return array_splice($dates, 0, $days, []);
|
||||
}
|
||||
|
||||
function GetTotalAmountfromArray($array)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
|
||||
foreach ($array as $amount) {
|
||||
if (is_numeric($amount) && $amount !== '') {
|
||||
$total += $amount;
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
function removecolumnsfrom2Darray($array, $arraycolumnstoremove)
|
||||
{
|
||||
if (!is_array($array) or !is_array($arraycolumnstoremove)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($array as $key => $value) {
|
||||
foreach ($value as $skey => $sval) {
|
||||
if (in_array($skey, $arraycolumnstoremove)) {
|
||||
unset($array[$key][$skey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sqlarray_2dfilter($array, $columnname, string $stringtosearch, $exact = FALSE, $caseinsensitive = false, $simplesearchwith_strpos = false)
|
||||
{
|
||||
if ($columnname === '' or $columnname === null or $columnname === false) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!$array) {
|
||||
return false;
|
||||
}
|
||||
$datatosearch = array_column($array, $columnname);
|
||||
if ($caseinsensitive) {
|
||||
$stringtosearch = strtolower($stringtosearch);
|
||||
foreach ($datatosearch as $key => $value) {
|
||||
$datatosearch[$key] = strtolower($value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($exact) {
|
||||
$keylist = array_keys($datatosearch, $stringtosearch);
|
||||
} else {
|
||||
if ($simplesearchwith_strpos) {
|
||||
$keylist = [];
|
||||
foreach ($datatosearch as $sskey => $ssvalue) {
|
||||
if ($caseinsensitive) {
|
||||
if (stripos($ssvalue, $stringtosearch)) {
|
||||
$keylist[] = $sskey;
|
||||
}
|
||||
} elseif (!$caseinsensitive) {
|
||||
if (strpos($ssvalue, $stringtosearch)) {
|
||||
$keylist[] = $sskey;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$stringtosearch = preg_quote($stringtosearch, '/'); // remove if an error is encountered
|
||||
$keylist = array_keys(preg_grep('/(?i)' . $stringtosearch . '/', $datatosearch));
|
||||
}
|
||||
}
|
||||
$res = [];
|
||||
foreach ($keylist as $value) {
|
||||
$res[] = $array[$value];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function array2d_removeduplicate($array, $columnname, $reorder = FALSE)
|
||||
{
|
||||
$keylist = array_keys(array_unique(array_column($array, $columnname)));
|
||||
$newarray = [];
|
||||
foreach ($keylist as $value) {
|
||||
$newarray[$value] = $array[$value];
|
||||
}
|
||||
if ($reorder) {
|
||||
$newarray = array_values($newarray);
|
||||
}
|
||||
|
||||
return $newarray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches a 2d array using a multiple words that match by separating by space.
|
||||
*
|
||||
* This function takes a 2D array, a column name, and a search string as input.
|
||||
* It separates the search string by space and calls the sqlarray_2dfilter function
|
||||
* multiple times until all words are matched.
|
||||
*
|
||||
* @param array $array The 2D array to search in.
|
||||
* @param string $columnname The name of the column to search in.
|
||||
* @param string $stringtosearch The search string to search for.
|
||||
* @param bool $exact Whether to search for exact matches or not. Defaults to FALSE.
|
||||
* @param bool $caseinsensitive Whether to perform a case-insensitive search or not. Defaults to FALSE.
|
||||
* @param bool $simplesearchwith_strpos Whether to use the strpos function for searching or not. Defaults to FALSE.
|
||||
*
|
||||
* @return array The filtered data array where all words in the search string are present.
|
||||
*/
|
||||
function sqlarray_2dfilter_multiple($array, $columnname, string $stringtosearch, $exact = FALSE, $caseinsensitive = false, $simplesearchwith_strpos = false)
|
||||
{
|
||||
if ($columnname === '' or $columnname === null or $columnname === false) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!$array) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$words = explode(' ', $stringtosearch);
|
||||
$result = $array;
|
||||
|
||||
foreach ($words as $word) {
|
||||
$result = sqlarray_2dfilter($result, $columnname, $word, $exact, $caseinsensitive, $simplesearchwith_strpos);
|
||||
if (empty($result)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function sqlarray_2dfilterContinuos($array, $columnname, $stringarraytosearch, $exact = FALSE, $caseinsensitive = false)
|
||||
{
|
||||
$res = [];
|
||||
foreach ($stringarraytosearch as $key => $value) {
|
||||
$searchresult = sqlarray_2dfilter($array, $columnname, $value, $exact, $caseinsensitive);
|
||||
if (!$searchresult) {
|
||||
continue;
|
||||
}
|
||||
$res = [...$res, ...$searchresult];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
function encryptString($simple_string, $encryption_key)
|
||||
{
|
||||
$ciphering = "AES-128-CTR";
|
||||
$iv_length = openssl_cipher_iv_length($ciphering);
|
||||
$options = 0;
|
||||
$encryption_iv = '1218277893585121';
|
||||
$encryption = openssl_encrypt(
|
||||
$simple_string,
|
||||
$ciphering,
|
||||
$encryption_key,
|
||||
$options,
|
||||
$encryption_iv
|
||||
);
|
||||
return $encryption;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function decryptString($string, $decryption_key)
|
||||
{
|
||||
$ciphering = "AES-128-CTR";
|
||||
$decryption_iv = '1218277893585121';
|
||||
$options = 0;
|
||||
$decryption = openssl_decrypt(
|
||||
$string,
|
||||
$ciphering,
|
||||
$decryption_key,
|
||||
$options,
|
||||
$decryption_iv
|
||||
);
|
||||
return $decryption;
|
||||
}
|
||||
|
||||
function objectToUrlSafeBase64($obj)
|
||||
{
|
||||
$jsonString = json_encode($obj);
|
||||
$base64String = base64_encode($jsonString);
|
||||
$urlSafeBase64 = str_replace(['+', '/', '='], ['-', '_', ''], $base64String);
|
||||
return $urlSafeBase64;
|
||||
}
|
||||
|
||||
function urlSafeBase64ToObject($urlSafeBase64)
|
||||
{
|
||||
$base64String = str_replace(['-', '_'], ['+', '/'], $urlSafeBase64);
|
||||
$padding = strlen($base64String) % 4;
|
||||
if ($padding) {
|
||||
$base64String .= str_repeat('=', 4 - $padding);
|
||||
}
|
||||
$jsonString = base64_decode($base64String);
|
||||
return json_decode($jsonString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user