<?php
defined('BASEPATH') or exit('No direct script access allowed');
// ENABLE ERROR DISPLAY BY DEFAULT (MANDATORY)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Debug logging
log_activity('Module: Starting installation...');
try {
// Create permissions (use register_staff_capabilities in main file, not here)
log_activity('Module: Creating options...');
// Create basic options only
add_option('module_setting_1', 'default_value');
add_option('module_setting_2', 'default_value');
// Create custom fields with error handling
$CI = &get_instance();
if (!class_exists('Custom_fields_model')) {
$CI->load->model('custom_fields_model');
}
// Create custom fields with try-catch
try {
$field_data = [
'fieldto' => 'tasks',
'name' => 'Field Name',
'type' => 'checkbox',
'required' => 0,
'active' => 1,
'show_on_pdf' => 0,
'show_on_ticket_form' => 0,
'visible_to_client' => 0,
'disalow_client_to_edit' => 1,
'bs_column' => 6
];
$field_id = $CI->custom_fields_model->add($field_data);
if ($field_id) {
update_option('module_field_id', $field_id);
log_activity('Module: Custom field created successfully');
}
} catch (Exception $e) {
log_activity('Module: Warning - Custom field creation failed: ' . $e->getMessage());
// Don't fail installation, just log warning
}
log_activity('Module: Installation completed successfully');
} catch (Exception $e) {
// Display detailed error in browser
log_activity('Module: Installation FAILED - ' . $e->getMessage());
error_log('Module Installation Error: ' . $e->getMessage());
echo '<div style="background: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; padding: 15px; margin: 10px; border-radius: 4px;">';
echo '<h3>Module Installation Error</h3>';
echo '<p><strong>Error:</strong> ' . htmlspecialchars($e->getMessage()) . '</p>';
echo '<p><strong>File:</strong> ' . htmlspecialchars($e->getFile()) . '</p>';
echo '<p><strong>Line:</strong> ' . htmlspecialchars($e->getLine()) . '</p>';
echo '<p><strong>Stack Trace:</strong></p>';
echo '<pre>' . htmlspecialchars($e->getTraceAsString()) . '</pre>';
echo '</div>';
throw $e;
}