/
core_class.php
executable file
·99 lines (85 loc) · 2.34 KB
/
core_class.php
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
<?php
class Core {
// Function to validate the post data
function validate_post($data)
{
// Counter variable
$counter = 0;
// Validate the hostname
if(isset($data['hostname']) AND !empty($data['hostname'])) {
$counter++;
}
// Validate the username
if(isset($data['username']) AND !empty($data['username'])) {
$counter++;
}
// Validate the password
if(isset($data['password']) AND !empty($data['password'])) {
// pass
}
// Validate the database
if(isset($data['database']) AND !empty($data['database'])) {
$counter++;
}
// Validate the Kayako API Key
if(isset($data['kayakoapi']) AND !empty($data['kayakoapi'])){
//None
}
// Validate the Swift URL
if(isset($data['swifturl']) AND !empty($data['swifturl'])){
//None
}
// Validate the Kayako Secret Key
if(isset($data['kayakosecretkey']) AND !empty($data['kayakosecretkey'])){
//None
}
// Validate the Offline Administrator Username
if(isset($data['offlineadminname']) AND !empty($data['offlineadminname'])){
$counter++;
}
// Validate the Offline Administrator Password
if(isset($data['offlineadminpassword']) AND !empty($data['offlineadminpassword'])){
$counter++;
}
// Check if all the required fields have been entered
if($counter == 5) {
return true;
}
else {
return false;
}
}
// Function to show an error
function show_message($type,$message) {
return $message;
}
// Function to write the config file
function write_config($data) {
// Config path
$template_path = 'config/database.php';
$output_path = '../application/config/database.php';
// Open the file
$database_file = file_get_contents($template_path);
$new = str_replace("%HOSTNAME%",$data['hostname'],$database_file);
$new = str_replace("%USERNAME%",$data['username'],$new);
$new = str_replace("%PASSWORD%",$data['password'],$new);
$new = str_replace("%DATABASE%",$data['database'],$new);
$new = str_replace('$config[\'firstrun\'] = FALSE;', '$config[\'firstrun\'] = TRUE;', $new);
// Write the new database.php file
$handle = fopen($output_path,'w+');
// Chmod the file, in case the user forgot
@chmod($output_path,0777);
// Verify file permissions
if(is_writable($output_path)) {
// Write the file
if(fwrite($handle,$new)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
?>