class GHMS_Install {
public static function install() {
self::create_tables();
self::seed_initial_data();
}
private static function create_tables() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$tables = [
"CREATE TABLE {$wpdb->prefix}ghms_agricultural_cycles (
id int(11) NOT NULL AUTO_INCREMENT,
sub_id int(11) DEFAULT NULL,
line_id int(11) DEFAULT NULL,
flower_type_id int(11) DEFAULT NULL,
start_date date DEFAULT NULL,
expected_date date DEFAULT NULL,
harvest_date date DEFAULT NULL,
status enum('planned','active','completed','aborted') DEFAULT 'planned',
PRIMARY KEY (id),
KEY sub_id (sub_id),
KEY line_id (line_id),
KEY flower_type_id (flower_type_id)
) $charset_collate;",
// Add all other tables from your SQL dump
];
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
foreach ($tables as $table) {
dbDelta($table);
}
}
}class GHMS_Tasks {
public function __construct() {
add_action('ghms_daily_maintenance', array($this, 'check_scheduled_tasks'));
add_action('init', array($this, 'schedule_events'));
}
public function schedule_events() {
if (!wp_next_scheduled('ghms_daily_maintenance')) {
wp_schedule_event(time(), 'daily', 'ghms_daily_maintenance');
}
}
public function check_scheduled_tasks() {
$today = current_time('Y-m-d');
$due_tasks = GHMS_Database::get_instance()->get_tasks_due_on($today);
foreach ($due_tasks as $task) {
$this->send_task_reminder($task);
}
}
private function send_task_reminder($task) {
$employee = GHMS_Database::get_instance()->get_employee($task->assigned_to);
$user = get_user_by('id', $employee->user_id);
if ($user) {
$subject = sprintf(__('Reminder: %s task due today', 'ghms'), $task->task_type);
$message = sprintf(
__('Hello %s, you have a %s task scheduled for today. Details: %s', 'ghms'),
$user->display_name,
$task->task_type,
$task->notes
);
wp_mail($user->user_email, $subject, $message);
}
}
}class GHMS_WooCommerce {
public function __construct() {
add_action('save_post_product', array($this, 'sync_product_with_ghms'), 10, 3);
add_action('woocommerce_order_status_changed', array($this, 'handle_order_status_change'), 10, 3);
}
public function sync_product_with_ghms($post_id, $post, $update) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if ($post->post_type != 'product') return;
$product = wc_get_product($post_id);
$flower_type_id = get_post_meta($post_id, '_ghms_flower_type_id', true);
if ($flower_type_id) {
// Update existing flower type
GHMS_Database::get_instance()->update_flower_type($flower_type_id, [
'name' => $product->get_name(),
'wc_product_id' => $post_id,
'wc_last_sync' => current_time('mysql')
]);
} else {
// Create new flower type
$flower_type_id = GHMS_Database::get_instance()->insert_flower_type([
'wc_product_id' => $post_id,
'name' => $product->get_name(),
'wc_last_sync' => current_time('mysql')
]);
update_post_meta($post_id, '_ghms_flower_type_id', $flower_type_id);
}
}
public function handle_order_status_change($order_id, $old_status, $new_status) {
if ($new_status == 'completed') {
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item) {
$product_id = $item->get_product_id();
$flower_type_id = get_post_meta($product_id, '_ghms_flower_type_id', true);
if ($flower_type_id) {
GHMS_Database::get_instance()->record_sale([
'flower_type_id' => $flower_type_id,
'wc_order_id' => $order_id,
'sold_quantity' => $item->get_quantity(),
'sale_date' => current_time('mysql')
]);
}
}
}
}
}
Warning: Cannot modify header information - headers already sent by (output started at /home4/umifydmy/public_html/wp-content/plugins/007/includes/class-ghms-install.php:1) in /home4/umifydmy/public_html/wp-includes/pluggable.php on line 1450
Warning: Cannot modify header information - headers already sent by (output started at /home4/umifydmy/public_html/wp-content/plugins/007/includes/class-ghms-install.php:1) in /home4/umifydmy/public_html/wp-includes/pluggable.php on line 1453