-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
382 lines (340 loc) · 18.8 KB
/
install.php
File metadata and controls
382 lines (340 loc) · 18.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/**
* Auburn CMS Installation Script
* This script will create the database and all required tables
*/
// Define installation mode to prevent redirects
define('INSTALLATION_MODE', true);
// Clean up any existing database configuration to ensure fresh install
if (file_exists('config/database.php')) {
// Show warning about existing configuration
$existing_config = true;
} else {
$existing_config = false;
}
echo "<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Auburn CMS Installation</title>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css' rel='stylesheet'>
<style>
.form-section { margin-bottom: 2rem; }
.alert { margin-bottom: 1rem; }
</style>
</head>
<body>
<div class='container mt-5'>
<div class='row justify-content-center'>
<div class='col-md-10'>
<div class='card'>
<div class='card-header'>
<h3 class='mb-0'>Auburn CMS Installation</h3>
</div>
<div class='card-body'>";
if (isset($_POST['install'])) {
// Get database configuration from form
$DB_HOST = trim($_POST['db_host']);
$DB_USER = trim($_POST['db_user']);
$DB_PASSWORD = trim($_POST['db_password']);
$DB_NAME = trim($_POST['db_name']);
// Validate required fields
if (empty($DB_HOST) || empty($DB_USER) || empty($DB_NAME)) {
echo "<div class='alert alert-danger'>Error: Please fill in all required database fields.</div>";
} else {
try {
// Test connection to MySQL server (without database)
$conn = new mysqli($DB_HOST, $DB_USER, $DB_PASSWORD);
if ($conn->connect_error) {
throw new Exception("Connection failed: " . $conn->connect_error);
}
echo "<div class='alert alert-info'>Connected to MySQL server successfully!</div>";
// Create database
$sql = "CREATE DATABASE IF NOT EXISTS `$DB_NAME` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
if ($conn->query($sql) === TRUE) {
echo "<div class='alert alert-success'>Database '$DB_NAME' created successfully!</div>";
} else {
throw new Exception("Error creating database: " . $conn->error);
}
// Select the database
$conn->select_db($DB_NAME);
// Create configuration file
$config_content = "<?php
/**
* Auburn CMS Database Configuration
* This file is automatically generated during installation
* Do not edit this file manually - use the admin panel instead
*/
// Database Configuration Constants
define('DB_HOST', '" . addslashes($DB_HOST) . "');
define('DB_NAME', '" . addslashes($DB_NAME) . "');
define('DB_USER', '" . addslashes($DB_USER) . "');
define('DB_PASS', '" . addslashes($DB_PASSWORD) . "');
define('DB_CHARSET', 'utf8mb4');
// PDO Connection String
define('DBINFO', 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME);
define('DBUSER', DB_USER);
define('DBPASS', DB_PASS);
// Connection verification flag
define('DB_CONFIGURED', true);
?>";
// Write configuration file
if (file_put_contents('config/database.php', $config_content) !== false) {
echo "<div class='alert alert-success'>Database configuration file created successfully!</div>";
} else {
throw new Exception("Error writing database configuration file. Please check file permissions.");
}
// Create users table
$users_table = "CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'auto incrementing user_id of each user, unique index',
`user_first_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'user_first_name,not unique',
`user_last_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'user_last_name,not unique',
`user_name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'user''s name, unique',
`user_password_hash` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'user''s password in salted and hashed format',
`user_email` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'user''s email, unique',
`user_address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'user_address,not unique',
`user_address2` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'user_address2,not unique',
`user_city` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'user_city,not unique',
`user_state` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'user_state,not unique',
`user_zip_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'user_zip_code,not unique',
`user_birthday` date NOT NULL COMMENT 'user_birthday,not unique',
`user_role` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'user_role,not unique',
`user_date_created` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'user''s date and time created',
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name` (`user_name`),
UNIQUE KEY `user_email` (`user_email`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='user data'";
if ($conn->query($users_table) === TRUE) {
echo "<div class='alert alert-success'>Users table created successfully!</div>";
} else {
throw new Exception("Error creating users table: " . $conn->error);
}
// Create posts table
$posts_table = "CREATE TABLE IF NOT EXISTS `posts` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`posts_title` varchar(255) NOT NULL,
`posts_url` varchar(255) NOT NULL,
`posts_content` text NOT NULL,
`posts_thumbnail` varchar(255) NOT NULL,
`posts_tags` varchar(255) NOT NULL,
`date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4";
if ($conn->query($posts_table) === TRUE) {
echo "<div class='alert alert-success'>Posts table created successfully!</div>";
} else {
throw new Exception("Error creating posts table: " . $conn->error);
}
// Create notifications table
$notifications_table = "CREATE TABLE IF NOT EXISTS `notifications` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
`type` text NOT NULL,
`message` text NOT NULL,
`status` text NOT NULL,
`level` text NOT NULL COMMENT 'رتبة المستخدم',
`date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if ($conn->query($notifications_table) === TRUE) {
echo "<div class='alert alert-success'>Notifications table created successfully!</div>";
} else {
throw new Exception("Error creating notifications table: " . $conn->error);
}
// Create settings table
$settings_table = "CREATE TABLE IF NOT EXISTS `settings` (
`website_id` int(11) NOT NULL AUTO_INCREMENT,
`website_title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_meta` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_favicon` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_login_icon` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_language` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_user_language` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_admin_user` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_admin_password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_timezone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_header` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL,
`website_modified_date` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`website_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='settings data'";
if ($conn->query($settings_table) === TRUE) {
echo "<div class='alert alert-success'>Settings table created successfully!</div>";
// Insert default settings
$default_settings = "INSERT INTO `settings` (
`website_title`, `website_meta`, `website_favicon`, `website_login_icon`,
`website_language`, `website_user_language`, `website_admin_user`,
`website_admin_password`, `website_timezone`, `website_header`
) VALUES (
'Auburn CMS',
'Auburn Content Management System',
'admin/files/favicon.ico',
'admin/files/logo.svg',
'ar',
'ar',
'admin',
'admin123',
'Asia/Riyadh',
'Auburn CMS - إدارة المحتوى'
)";
if ($conn->query($default_settings) === TRUE) {
echo "<div class='alert alert-success'>Default settings inserted successfully!</div>";
} else {
echo "<div class='alert alert-warning'>Note: Could not insert default settings: " . $conn->error . "</div>";
}
} else {
throw new Exception("Error creating settings table: " . $conn->error);
}
// Create upload files table
$upload_table = "CREATE TABLE IF NOT EXISTS `uploadmultiplefiles` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'auto incrementing file_id of each file, unique index',
`filename` varchar(255) NOT NULL COMMENT 'file name without the extensions',
`imgdir` varchar(255) NOT NULL COMMENT 'location where the file is stored',
`UploadTimestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'the time where the file was uploaded to the system',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4";
if ($conn->query($upload_table) === TRUE) {
echo "<div class='alert alert-success'>Upload files table created successfully!</div>";
} else {
throw new Exception("Error creating upload files table: " . $conn->error);
}
// Create download history table
$download_table = "CREATE TABLE IF NOT EXISTS `downloadhistory` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`jobNumber` varchar(11) NOT NULL,
`dateAndTime` datetime NOT NULL,
`fileName` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if ($conn->query($download_table) === TRUE) {
echo "<div class='alert alert-success'>Download history table created successfully!</div>";
} else {
throw new Exception("Error creating download history table: " . $conn->error);
}
// Create branch table
$branch_table = "CREATE TABLE IF NOT EXISTS `add_a_new_branch` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`JobNumber` text NOT NULL,
`BranchNumber` text NOT NULL,
`Neighborhood` text NOT NULL,
`Region` text NOT NULL,
`TimeStamp` datetime NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if ($conn->query($branch_table) === TRUE) {
echo "<div class='alert alert-success'>Branch table created successfully!</div>";
} else {
throw new Exception("Error creating branch table: " . $conn->error);
}
echo "<div class='alert alert-success'><strong>Installation completed successfully!</strong></div>";
echo "<div class='alert alert-info'>
<h5>Installation Summary:</h5>
<ul>
<li>✅ Database '<strong>$DB_NAME</strong>' created</li>
<li>✅ All required tables created</li>
<li>✅ Database configuration saved to <code>config/database.php</code></li>
<li>✅ All existing configuration files will now use the centralized config</li>
</ul>
<h5>Next Steps:</h5>
<ol>
<li>Go to <a href='index.php' class='btn btn-primary btn-sm'>index.php</a> to start using the system</li>
<li>Register a new user account to begin</li>
<li>The system is now configured and ready to use!</li>
</ol>
</div>";
$conn->close();
} catch (Exception $e) {
echo "<div class='alert alert-danger'>Error: " . $e->getMessage() . "</div>";
echo "<div class='alert alert-info'>Please check your database credentials and try again.</div>";
}
}
} else {
echo "<form method='post' class='needs-validation' novalidate>
<div class='form-section'>
<h5 class='mb-3'>Database Configuration</h5>";
// Show warning if existing configuration found
if ($existing_config) {
echo "<div class='alert alert-warning'>
<strong>⚠️ Existing Configuration Detected!</strong><br>
A database configuration file already exists. This installation will overwrite the existing configuration.
If you have a working system, you might want to backup your data first.
</div>";
}
echo "<div class='alert alert-info'>
<i class='bi bi-info-circle'></i>
<strong>Before you begin:</strong> Make sure your MySQL server is running and you have the necessary credentials.
</div>
<div class='row'>
<div class='col-md-6 mb-3'>
<label for='db_host' class='form-label'>Database Host *</label>
<input type='text' class='form-control' id='db_host' name='db_host'
value='localhost:3307' placeholder='localhost or localhost:3306' required>
<div class='form-text'>Usually 'localhost' or 'localhost:3306'. Include port if different.</div>
<div class='invalid-feedback'>Please provide a valid database host.</div>
</div>
<div class='col-md-6 mb-3'>
<label for='db_name' class='form-label'>Database Name *</label>
<input type='text' class='form-control' id='db_name' name='db_name'
value='auburn_cms' placeholder='auburn_cms' required>
<div class='form-text'>The database name (will be created if it doesn't exist).</div>
<div class='invalid-feedback'>Please provide a database name.</div>
</div>
</div>
<div class='row'>
<div class='col-md-6 mb-3'>
<label for='db_user' class='form-label'>Database Username *</label>
<input type='text' class='form-control' id='db_user' name='db_user'
value='root' placeholder='root' required>
<div class='form-text'>MySQL username with create database privileges.</div>
<div class='invalid-feedback'>Please provide a database username.</div>
</div>
<div class='col-md-6 mb-3'>
<label for='db_password' class='form-label'>Database Password</label>
<input type='password' class='form-control' id='db_password' name='db_password'
placeholder='Enter database password'>
<div class='form-text'>MySQL password (leave empty if no password).</div>
</div>
</div>
<div class='alert alert-warning'>
<h6>⚠️ What this installation will do:</h6>
<ul class='mb-0'>
<li>Create the database (if it doesn't exist)</li>
<li>Create all required tables for Auburn CMS</li>
<li>Generate a centralized configuration file at <code>config/database.php</code></li>
<li>Set up default admin credentials (admin/admin123)</li>
</ul>
</div>
</div>
<div class='d-grid'>
<button type='submit' name='install' class='btn btn-primary btn-lg'>
🚀 Install Auburn CMS
</button>
</div>
</form>
<script>
// Bootstrap form validation
(function() {
'use strict';
window.addEventListener('load', function() {
var forms = document.getElementsByClassName('needs-validation');
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>";
}
echo " </div>
</div>
</div>
</div>
</div>
</body>
</html>";
?>