Upload markdown files and organize them in a tree structure
⚠️ Warning: This action cannot be undone!
controllers/productCatController.php (883 lines)
productcat
-- Get complete category hierarchy with parent names
SELECT
productcat.productCatId,
productcat.productCatName,
productcat.productCatDescription,
productcat.productCatParent,
productcat.inMenu,
productcat.stopNegativeSale,
productcat.discounttype,
productcat.selldiscount,
productcat.buydiscount,
productcat.conditions,
productcat.isOptic,
productcat.productCatDate,
productcat.userId,
productcat.obygyInvestigationCatId,
productcat.opticServices,
productcat.webApiId,
productcat.productCatImage,
productcat.buytotal,
productcat.buyhalf,
productcat.buypart,
productcat.buypricereal,
productcat.price4,
productcat.price5,
productcat.price6,
productcat.price7,
productcat.price8,
productcat.price9,
productcat.price10,
productcat.price11,
productcat.price12,
productcat.price13,
parent.productCatName as parentName
FROM productcat
LEFT JOIN productcat as parent ON productcat.productCatParent = parent.productCatId
WHERE productcat.conditions = 0
ORDER BY productcat.productCatParent ASC, productcat.productCatId ASC;
-- Get all available units for category associations
SELECT
unitid,
unitname,
unitvalue,
conditions
FROM unit
WHERE conditions = 0
ORDER BY unitid ASC;
-- Get program settings for display configuration
SELECT * FROM programsettings WHERE programsettingsid = 1;
API Endpoint: GET /api/v1/product-categories/management
Business Logic:
-- Check for existing "Investigations" category (OBGY medical integration)
SELECT
productCatId,
productCatName,
productCatParent,
conditions
FROM productcat
WHERE productCatName = 'Investigations039;
AND conditions = 0;
-- Insert new product category with all fields
INSERT INTO productcat (
productCatName,
productCatDescription,
productCatParent,
inMenu,
stopNegativeSale,
discounttype,
selldiscount,
buydiscount,
conditions,
isOptic,
productCatDate,
userId,
obygyInvestigationCatId,
opticServices,
webApiId,
buytotal,
buyhalf,
buypart,
buypricereal,
price4,
price5,
price6,
price7,
price8,
price9,
price10,
price11,
price12,
price13,
productCatImage
) VALUES (
'Electronics039;, -- productCatName
'Electronic products category039;, -- productCatDescription
0, -- productCatParent (0 for root category)
1, -- inMenu (1=show in menu, 0=hidden)
1, -- stopNegativeSale (1=prevent, 0=allow)
1, -- discounttype
10.50, -- selldiscount (percentage)
5.00, -- buydiscount (percentage)
0, -- conditions (0=active, 1=deleted)
0, -- isOptic (0=normal, 1=optical)
CURDATE(), -- productCatDate
1, -- userId (current user ID)
0, -- obygyInvestigationCatId
'service1,service2039;, -- opticServices (comma-separated)
123, -- webApiId
1, -- buytotal (permission flag)
1, -- buyhalf (permission flag)
1, -- buypart (permission flag)
1, -- buypricereal (permission flag)
1, -- price4 (price level 4 permission)
1, -- price5 (price level 5 permission)
0, -- price6 (price level 6 permission)
0, -- price7 (price level 7 permission)
0, -- price8 (price level 8 permission)
0, -- price9 (price level 9 permission)
0, -- price10 (price level 10 permission)
0, -- price11 (price level 11 permission)
0, -- price12 (price level 12 permission)
0, -- price13 (price level 13 permission)
'category_image.jpg039; -- productCatImage (filename)
);
-- Get the newly inserted category ID
SELECT LAST_INSERT_ID() as newCategoryId;
-- Associate selected units with the new category
INSERT INTO productcatunit (productCatId, unitId) VALUES (LAST_INSERT_ID(), 1);
INSERT INTO productcatunit (productCatId, unitId) VALUES (LAST_INSERT_ID(), 2);
INSERT INTO productcatunit (productCatId, unitId) VALUES (LAST_INSERT_ID(), 3);
-- Alternative: For OBGY medical categories, create "Investigations" parent if not exists
INSERT IGNORE INTO productcat (
productCatName,
productCatDescription,
productCatParent,
conditions,
productCatDate,
userId,
inMenu,
stopNegativeSale,
discounttype,
selldiscount,
buydiscount,
isOptic,
buytotal,
buyhalf,
buypart,
buypricereal,
price4, price5, price6, price7, price8, price9, price10, price11, price12, price13
) VALUES (
'Investigations039;,
'Medical Investigations039;,
0,
0,
CURDATE(),
1,
1, 0, 0, 0.00, 0.00, 0,
0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
);
API Endpoint: POST /api/v1/product-categories
Request Body Structure:
{
"productCatName": "Electronics",
"productCatDescription": "Electronic products category",
"parent": 0,
"inMenu": 1,
"stopNegativeSale": 1,
"discounttype": 1,
"selldiscount": 10.5,
"buydiscount": 5.0,
"buytotal": 1,
"buyhalf": 1,
"buypart": 1,
"buypricereal": 1,
"price4": 1,
"price5": 1,
"price6": 0,
"price7": 0,
"price8": 0,
"price9": 0,
"price10": 0,
"price11": 0,
"price12": 0,
"price13": 0,
"units": [1, 2, 3],
"opticServices": ["service1", "service2"],
"webApiId": 123
}
Business Logic:
// Line 184-193 in productCatController.php
">elseif ($do == "add2") {
">$flag = $_GET['flag039;];
try {
add(); // Same function as regular add
header("location:?do=sucess");
} ">catch (Exception $e) {
header("location:?do=error");
}
}
API Endpoint: POST /controllers/productCatController.php?do=add2
Business Logic: Same as add() but with different response handling
---
// Line 194-201 in productCatController.php
">elseif ($do == "add2SimpleReturn") {
try {
$id = add();
">echo $id; // Return category ID directly
} ">catch (Exception $e) {
echo -1; // Return error indicator
}
}
API Endpoint: POST /controllers/productCatController.php?do=add2SimpleReturn
Response: Category ID or -1 for error
Business Logic: AJAX-optimized category creation for dynamic forms
---
// Line 202-211 in productCatController.php
">elseif ($do == "addCat") {
try {
">$catName = $_POST['catName039;];
">$id = addCatByNameOnly($catName); // Function at line 844
">echo $id;
} ">catch (Exception $e) {
echo -1;
}
}
addCatByNameOnly() function:
// Line 844+ in productCatController.php
">function addCatByNameOnly($catName) {
global $productCat, $productCatDAO, $today;
$productCat->productCatName = $catName;
$productCat->productCatDescription = $catName;
$productCat->productCatParent = 0;
$productCat->conditions = 0;
$productCat->productCatDate = $today;
$productCat->userId = $_SESSION['userid039;];
// Set all other fields to defaults
return $productCatDAO->insert($productCat);
}
SQL Operations:
-- Insert simple category
INSERT INTO productcat (
productCatName, productCatDescription, productCatParent,
conditions, productCatDate, userId
) VALUES (?, ?, 0, 0, ?, ?)
API Endpoint: POST /controllers/productCatController.php?do=addCat
Request Body: {"catName": "New Category"}
---
// Line 212-230 in productCatController.php
">elseif ($do == "show") {
show(); // Function at line 536
$smarty->display("productCatview/show.html");
}
show() function:
// Line 536-545 in productCatController.php
function show() {
global $productCatDAO, $smarty;
">$allData = $productCatDAO->queryByConditions(0);
$smarty->assign("allData", $allData);
$allParents = getProductCatParents();
$smarty->assign("allParents", $allParents);
}
SQL Operations:
-- Get all active categories
SELECT * FROM productcat WHERE conditions = 0 ORDER BY productCatId DESC
-- Get category hierarchy
SELECT productcat.*, parent.productCatName as parentName
FROM productcat
LEFT JOIN productcat as parent ON productcat.productCatParent = parent.productCatId
WHERE productcat.conditions = 0
ORDER BY productcat.productCatParent, productcat.productCatId
API Endpoint: GET /controllers/productCatController.php?do=show
---
// Line 231-240 in productCatController.php
">elseif ($do == "executeOperation") {
try {
executeOperation(); // Function at line 556
show();
$smarty->display("productCatview/show.html");
} ">catch (Exception $e) {
$smarty->display("error.html");
}
}
executeOperation() function:
// Line 556-603 in productCatController.php
function executeOperation() {
global $productCatDAO;
$operation = $_POST['operation039;];
$categories = $_POST['categories039;]; // Array of category IDs
switch ($operation) {
case 'delete039;:
foreach ($categories as $catId) {
$category = $productCatDAO->load($catId);
$category->conditions = 1; // Soft delete
$productCatDAO->update($category);
}
break;
case 'restore039;:
foreach ($categories as $catId) {
$category = $productCatDAO->load($catId);
$category->conditions = 0; // Restore
$productCatDAO->update($category);
}
break;
}
}
SQL Operations:
-- Load category for bulk operation
SELECT * FROM productcat WHERE productCatId = ?
-- Bulk soft delete
UPDATE productcat SET conditions = 1 WHERE productCatId IN (?, ?, ?)
-- Bulk restore
UPDATE productcat SET conditions = 0 WHERE productCatId IN (?, ?, ?)
API Endpoint: POST /controllers/productCatController.php?do=executeOperation
Request Body:
{
"operation": "delete",
"categories": [1, 2, 3]
}
---
// Line 241-247 in productCatController.php
">elseif ($do == "returndelete") {
try {
$note = returndelete(); // Function at line 651
">if ($note != "success") {
$smarty->assign('msgnote039;, $note);
$smarty->display("notes.html");
} else {
header("location:?do=sucess");
}
} ">catch (Exception $e) {
header("location:?do=error");
}
}
returndelete() function:
// Line 651-662 in productCatController.php
function returndelete() {
global $productCatDAO;
$productCatid = $_GET["id"];
$category = $productCatDAO->load($productCatid);
">if ($category) {
$category->conditions = 0; // Restore category
$productCatDAO->update($category);
return "success";
}
return "Category not found";
}
SQL Operations:
-- Load category
SELECT * FROM productcat WHERE productCatId = ?
-- Restore category
UPDATE productcat SET conditions = 0 WHERE productCatId = ?
API Endpoint: GET /controllers/productCatController.php?do=returndelete&id={id}
---
// Line 248-263 in productCatController.php
">elseif ($do == "tempdelete") {
try {
">$note = tempdelete($_GET["id"]); // Function at line 604
">if ($note != "success") {
$smarty->assign('msgnote039;, $note);
$smarty->display("notes.html");
} else {
header("location:?do=sucess");
}
} ">catch (Exception $e) {
header("location:?do=error");
}
}
tempdelete() function:
// Line 604-650 in productCatController.php
">function tempdelete($productCatid) {
global $productCatDAO, $ProductEX;
// Check if category has products
$products = $ProductEX->queryByProductCatId($productCatid);
">if (count($products) > 0) {
return "Cannot delete category with products";
}
// Check if category has child categories
$children = $productCatDAO->queryByParent($productCatid);
">if (count($children) > 0) {
return "Cannot delete category with subcategories";
}
$category = $productCatDAO->load($productCatid);
">if ($category) {
$category->conditions = 1; // Soft delete
$productCatDAO->update($category);
return "success";
}
return "Category not found";
}
SQL Operations:
-- Check for products in category
SELECT * FROM product WHERE productCatId = ? AND conditions = 0
-- Check for child categories
SELECT * FROM productcat WHERE productCatParent = ? AND conditions = 0
-- Load category
SELECT * FROM productcat WHERE productCatId = ?
-- Soft delete category
UPDATE productcat SET conditions = 1 WHERE productCatId = ?
API Endpoint: GET /controllers/productCatController.php?do=tempdelete&id={id}
---
// Line 264-282 in productCatController.php
">elseif ($do == "deleteFinaly") {
try {
">$data = deleteFinaly($_GET["id"]); // Function at line 804
">if ($data != -1) {
header("location:?do=sucess");
} else {
header("location:?do=error");
}
} ">catch (Exception $e) {
header("location:?do=error");
}
}
deleteFinaly() function:
// Line 804-843 in productCatController.php
">function deleteFinaly($productCatid) {
global $productCatDAO, $ProductEX, $catUnitDAO;
// Check dependencies
$products = $ProductEX->queryByProductCatId($productCatid);
">if (count($products) > 0) {
return -1; // Cannot delete - has products
}
$children = $productCatDAO->queryByParent($productCatid);
">if (count($children) > 0) {
return -1; // Cannot delete - has children
}
// Delete category-unit associations
$catUnitDAO->deleteByProductCatId($productCatid);
// Delete category image if exists
$category = $productCatDAO->load($productCatid);
">if ($category && $category->productCatImage) {
unlink("../upload/category/" . $category->productCatImage);
}
// Permanently delete category
$productCatDAO->delete($productCatid);
return 1;
}
SQL Operations:
-- Check for products
SELECT * FROM product WHERE productCatId = ? AND conditions = 0
-- Check for child categories
SELECT * FROM productcat WHERE productCatParent = ? AND conditions = 0
-- Delete category-unit associations
DELETE FROM productcatunit WHERE productCatId = ?
-- Load category for image deletion
SELECT * FROM productcat WHERE productCatId = ?
-- Permanently delete category
DELETE FROM productcat WHERE productCatId = ?
API Endpoint: GET /controllers/productCatController.php?do=deleteFinaly&id={id}
---
// Line 283-298 in productCatController.php
">elseif ($do == "editprint") {
$loadData = edit(); // Function at line 663
$smarty->assign("loadData", $loadData);
$allParents = getProductCatParents();
$smarty->assign("allParents", $allParents);
$unitsData = getUnits();
$smarty->assign("unitsData", $unitsData);
$smarty->assign("customPrint", 1);
$smarty->display("productCatview/editprint.html");
}
API Endpoint: GET /controllers/productCatController.php?do=editprint&id={id}
---
// Line 299-336 in productCatController.php
">elseif ($do == "edit") {
$loadData = edit(); // Function at line 663
$smarty->assign("loadData", $loadData);
$allParents = getProductCatParents();
$smarty->assign("allParents", $allParents);
$unitsData = getUnits();
$smarty->assign("unitsData", $unitsData);
$catUnits = getProductCatUnits($loadData->productCatId);
$smarty->assign("catUnits", $catUnits);
$smarty->display("productCatview/edit.html");
}
edit() function:
// Line 663-673 in productCatController.php
function edit() {
global $productCatDAO;
$productCatId = $_GET["id"];
return $productCatDAO->load($productCatId);
}
SQL Operations:
-- Load category for editing
SELECT * FROM productcat WHERE productCatId = ?
-- Get category hierarchy for parent selection
SELECT productcat.*, parent.productCatName as parentName
FROM productcat
LEFT JOIN productcat as parent ON productcat.productCatParent = parent.productCatId
WHERE productcat.conditions = 0
-- Get available units
SELECT * FROM unit WHERE conditions = 0
-- Get current category-unit associations
SELECT productcatunit.*, unit.unitname
FROM productcatunit
JOIN unit ON productcatunit.unitId = unit.unitid
WHERE productcatunit.productCatId = ?
API Endpoint: GET /controllers/productCatController.php?do=edit&id={id}
---
// Line 337-353 in productCatController.php
">elseif ($do == "update") {
try {
update(); // Function at line 674
header("location:?do=sucess");
} ">catch (Exception $e) {
header("location:?do=error");
}
}
update() function (Line 674-803): Similar to add() but updates existing category with same comprehensive feature set including:
-- Load existing category
SELECT * FROM productcat WHERE productCatId = ?
-- Update category
UPDATE productcat SET
productCatName = ?, productCatDescription = ?, productCatParent = ?,
inMenu = ?, stopNegativeSale = ?, discounttype = ?, selldiscount = ?,
buydiscount = ?, buytotal = ?, buyhalf = ?, buypart = ?, buypricereal = ?,
price4 = ?, price5 = ?, price6 = ?, price7 = ?, price8 = ?, price9 = ?,
price10 = ?, price11 = ?, price12 = ?, price13 = ?, opticServices = ?,
productCatImage = ?, conditions = ?
WHERE productCatId = ?
-- Delete existing unit associations
DELETE FROM productcatunit WHERE productCatId = ?
-- Insert new unit associations
INSERT INTO productcatunit (productCatId, unitId) VALUES (?, ?)
API Endpoint: PUT /controllers/productCatController.php?do=update
---
// Line 354-356 in productCatController.php
">elseif ($do == "sucess") {
$smarty->display("succes.html");
}
API Endpoint: GET /controllers/productCatController.php?do=sucess
---
// Line 357-359 in productCatController.php
">elseif ($do == "error") {
$smarty->display("error.html");
}
API Endpoint: GET /controllers/productCatController.php?do=error
---
CREATE TABLE productcat (
productCatId INT PRIMARY KEY AUTO_INCREMENT,
productCatName VARCHAR(255) NOT NULL,
productCatDescription TEXT,
productCatParent INT DEFAULT 0, -- Parent category ID
inMenu TINYINT DEFAULT 1, -- Show in menu (0/1)
stopNegativeSale TINYINT DEFAULT 0, -- Prevent negative sales (0/1)
discounttype TINYINT DEFAULT 0, -- Discount type
selldiscount DECIMAL(5,2) DEFAULT 0, -- Sale discount percentage
buydiscount DECIMAL(5,2) DEFAULT 0, -- Purchase discount percentage
conditions TINYINT DEFAULT 0, -- 0=Active, 1=Deleted
isOptic TINYINT DEFAULT 0, -- Optical category flag
productCatDate DATE, -- Creation date
userId INT, -- Creator user ID
obygyInvestigationCatId INT, -- OBGY medical category ID
opticServices TEXT, -- Comma-separated optical services
webApiId INT, -- External API ID
productCatImage VARCHAR(255), -- Category logo/image
-- Purchase permissions by price level
buytotal TINYINT DEFAULT 0,
buyhalf TINYINT DEFAULT 0,
buypart TINYINT DEFAULT 0,
buypricereal TINYINT DEFAULT 0,
-- 13 different price levels
price4 TINYINT DEFAULT 0,
price5 TINYINT DEFAULT 0,
price6 TINYINT DEFAULT 0,
price7 TINYINT DEFAULT 0,
price8 TINYINT DEFAULT 0,
price9 TINYINT DEFAULT 0,
price10 TINYINT DEFAULT 0,
price11 TINYINT DEFAULT 0,
price12 TINYINT DEFAULT 0,
price13 TINYINT DEFAULT 0
);
CREATE TABLE productcatunit (
id INT PRIMARY KEY AUTO_INCREMENT,
productCatId INT, -- Reference to productcat
unitId INT, -- Reference to unit
FOREIGN KEY (productCatId) REFERENCES productcat(productCatId),
FOREIGN KEY (unitId) REFERENCES unit(unitid)
);