|
1 |
| -<?php |
2 |
| - |
3 |
| -/** |
4 |
| - * actions.php |
5 |
| - * |
6 |
| - * This file handles all server-side responses for Ajax requests. All information is returned in JSON |
7 |
| - * format. |
8 |
| - */ |
9 |
| - |
10 |
| -require_once("../../../../global/library.php"); |
11 |
| - |
12 |
| -use FormTools\Core; |
13 |
| -use FormTools\Modules; |
14 |
| -use FormTools\Settings; |
15 |
| -use FormTools\Themes; |
16 |
| - |
17 |
| -use FormTools\Modules\SystemCheck\Files; |
18 |
| -use FormTools\Modules\SystemCheck\General; |
19 |
| -use FormTools\Modules\SystemCheck\Hooks; |
20 |
| -use FormTools\Modules\SystemCheck\Tables; |
21 |
| -use FormTools\Modules\SystemCheck\Orphans; |
22 |
| - |
23 |
| -Core::init(); |
24 |
| -Core::$user->checkAuth("admin"); |
25 |
| -Modules::initModulePage(); |
26 |
| - |
27 |
| -// the action to take and the ID of the page where it will be displayed (allows for |
28 |
| -// multiple calls on same page to load content in unique areas) |
29 |
| -$request = array_merge($_GET, $_POST); |
30 |
| -$action = $request["action"]; |
31 |
| -$settings = Settings::get(); |
32 |
| -$root_dir = Core::getRootDir(); |
33 |
| - |
34 |
| -switch ($action) { |
35 |
| - |
36 |
| - // Stage 1 of the Table Verification test: returns a list of tables to test for a particular component |
37 |
| - case "get_component_tables": |
38 |
| - $component = $request["component"]; |
39 |
| - |
40 |
| - // N.B. from 2.1.5 onwards, the Core stores its own DB structure |
41 |
| - if ($component == "core") { |
42 |
| - require_once("$root_dir/global/misc/config_core.php"); |
43 |
| - $tables = array_merge(array("FORM TOOLS CORE", "core"), Tables::getComponentTables($STRUCTURE)); |
44 |
| - } else { |
45 |
| - $module_info = Modules::getModule($request["component"]); // $request["component"] is just the module ID |
46 |
| - $module_config = General::getModuleConfigFileContents($module_info["module_folder"]); |
47 |
| - $tables = array_merge(array($module_info["module_name"], $request["component"]), Tables::getComponentTables($module_config["tables"])); |
48 |
| - } |
49 |
| - echo json_encode(array("tables" => $tables)); |
50 |
| - break; |
51 |
| - |
52 |
| - // Stage 2 of the Table Verification test: verifies the table structure |
53 |
| - case "verify_table": |
54 |
| - $component = $request["component"]; |
55 |
| - if ($component == "core") { |
56 |
| - require_once("$root_dir/global/misc/config_core.php"); |
57 |
| - $info = Tables::checkComponentTable($STRUCTURE, $request["table_name"]); |
58 |
| - $info["table_name"] = $request["table_name"]; |
59 |
| - echo json_encode($info); |
60 |
| - } else { |
61 |
| - $module_info = Modules::getModule($request["component"]); // $request["component"] is just the module ID |
62 |
| - $module_config = General::getModuleConfigFileContents($module_info["module_folder"]); |
63 |
| - $info = Tables::checkComponentTable($module_config["tables"], $request["table_name"]); |
64 |
| - $info["table_name"] = $request["table_name"]; |
65 |
| - echo json_encode($info); |
66 |
| - } |
67 |
| - break; |
68 |
| - |
69 |
| - // verifies the hooks for a particular module. This is much simpler than the table test. It just examines each module's hooks |
70 |
| - // in a single step and returns the result |
71 |
| - case "verify_module_hooks": |
72 |
| - $module_id = $request["module_id"]; |
73 |
| - $module_info = Modules::getModule($module_id); |
74 |
| - $module_folder = $module_info["module_folder"]; |
75 |
| - $module_version = $module_info["version"]; |
76 |
| - $result = Hooks::verifyModuleHooks($module_folder); |
77 |
| - |
78 |
| - echo json_encode(array( |
79 |
| - "module_id" => $module_id, |
80 |
| - "module_folder" => $module_folder, |
81 |
| - "module_name" => $module_info["module_name"], |
82 |
| - "result" => $result |
83 |
| - )); |
84 |
| - break; |
85 |
| - |
86 |
| - case "verify_component_files": |
87 |
| - $component = $request["component"]; |
88 |
| - |
89 |
| - $return_info = array("result" => "pass"); |
90 |
| - if ($component == "core") { |
91 |
| - $missing_files = Files::checkCoreFiles(); |
92 |
| - $return_info["component_type"] = "core"; |
93 |
| - $return_info["component_name"] = "Form Tools Core"; |
94 |
| - } |
95 |
| - if (preg_match("/^module_/", $component)) { |
96 |
| - $module_id = preg_replace("/^module_/", "", $component); |
97 |
| - $module_info = Modules::getModule($module_id); |
98 |
| - $missing_files = Files::checkModuleFiles($module_info["module_folder"]); |
99 |
| - $return_info["component_type"] = "module"; |
100 |
| - $return_info["component_name"] = $module_info["module_name"]; |
101 |
| - } |
102 |
| - if (preg_match("/^theme_/", $component)) { |
103 |
| - $theme_id = preg_replace("/^theme_/", "", $component); |
104 |
| - $theme_info = Themes::getTheme($theme_id); |
105 |
| - $missing_files = Files::checkThemeFiles($theme_info["theme_folder"]); |
106 |
| - $return_info["component_type"] = "theme"; |
107 |
| - $return_info["component_name"] = $theme_info["theme_name"]; |
108 |
| - } |
109 |
| - if (!empty($missing_files)) { |
110 |
| - $return_info["result"] = "fail"; |
111 |
| - $return_info["missing_files"] = $missing_files; |
112 |
| - } |
113 |
| - echo json_encode($return_info); |
114 |
| - break; |
115 |
| - |
116 |
| - case "find_table_orphans": |
117 |
| - $remove_orphans = isset($request["remove_orphans"]) ? true : false; |
118 |
| - $results = Orphans::findTableOrphans($request["table_name"], $remove_orphans); |
119 |
| - echo json_encode($results); |
120 |
| - break; |
121 |
| -} |
122 |
| - |
123 |
| - |
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * actions.php |
| 5 | + * |
| 6 | + * This file handles all server-side responses for Ajax requests. All information is returned in JSON |
| 7 | + * format. |
| 8 | + */ |
| 9 | + |
| 10 | +require_once("../../../global/library.php"); |
| 11 | + |
| 12 | +use FormTools\Core; |
| 13 | +use FormTools\Modules; |
| 14 | +use FormTools\Settings; |
| 15 | +use FormTools\Themes; |
| 16 | + |
| 17 | +use FormTools\Modules\SystemCheck\Files; |
| 18 | +use FormTools\Modules\SystemCheck\General; |
| 19 | +use FormTools\Modules\SystemCheck\Hooks; |
| 20 | +use FormTools\Modules\SystemCheck\Tables; |
| 21 | +use FormTools\Modules\SystemCheck\Orphans; |
| 22 | + |
| 23 | +$module = Modules::initModulePage("admin"); |
| 24 | + |
| 25 | +// the action to take and the ID of the page where it will be displayed (allows for |
| 26 | +// multiple calls on same page to load content in unique areas) |
| 27 | +$request = array_merge($_GET, $_POST); |
| 28 | +$action = $request["action"]; |
| 29 | +$settings = Settings::get(); |
| 30 | +$root_dir = Core::getRootDir(); |
| 31 | + |
| 32 | +switch ($action) { |
| 33 | + |
| 34 | + // Stage 1 of the Table Verification test: returns a list of tables to test for a particular component |
| 35 | + case "get_component_tables": |
| 36 | + $component = $request["component"]; |
| 37 | + |
| 38 | + // N.B. from 2.1.5 onwards, the Core stores its own DB structure |
| 39 | + if ($component == "core") { |
| 40 | + require_once("$root_dir/global/misc/config_core.php"); |
| 41 | + $tables = array_merge(array("FORM TOOLS CORE", "core"), Tables::getComponentTables($STRUCTURE)); |
| 42 | + } else { |
| 43 | + $module_info = Modules::getModule($request["component"]); // $request["component"] is just the module ID |
| 44 | + $module_config = General::getModuleConfigFileContents($module_info["module_folder"]); |
| 45 | + $tables = array_merge(array($module_info["module_name"], $request["component"]), Tables::getComponentTables($module_config["tables"])); |
| 46 | + } |
| 47 | + echo json_encode(array("tables" => $tables)); |
| 48 | + break; |
| 49 | + |
| 50 | + // Stage 2 of the Table Verification test: verifies the table structure |
| 51 | + case "verify_table": |
| 52 | + $component = $request["component"]; |
| 53 | + if ($component == "core") { |
| 54 | + require_once("$root_dir/global/misc/config_core.php"); |
| 55 | + $info = Tables::checkComponentTable($STRUCTURE, $request["table_name"]); |
| 56 | + $info["table_name"] = $request["table_name"]; |
| 57 | + echo json_encode($info); |
| 58 | + } else { |
| 59 | + $module_info = Modules::getModule($request["component"]); // $request["component"] is just the module ID |
| 60 | + $module_config = General::getModuleConfigFileContents($module_info["module_folder"]); |
| 61 | + $info = Tables::checkComponentTable($module_config["tables"], $request["table_name"]); |
| 62 | + $info["table_name"] = $request["table_name"]; |
| 63 | + echo json_encode($info); |
| 64 | + } |
| 65 | + break; |
| 66 | + |
| 67 | + // verifies the hooks for a particular module. This is much simpler than the table test. It just examines each module's hooks |
| 68 | + // in a single step and returns the result |
| 69 | + case "verify_module_hooks": |
| 70 | + $module_id = $request["module_id"]; |
| 71 | + $module_info = Modules::getModule($module_id); |
| 72 | + $module_folder = $module_info["module_folder"]; |
| 73 | + $module_version = $module_info["version"]; |
| 74 | + $result = Hooks::verifyModuleHooks($module_folder); |
| 75 | + |
| 76 | + echo json_encode(array( |
| 77 | + "module_id" => $module_id, |
| 78 | + "module_folder" => $module_folder, |
| 79 | + "module_name" => $module_info["module_name"], |
| 80 | + "result" => $result |
| 81 | + )); |
| 82 | + break; |
| 83 | + |
| 84 | + case "verify_component_files": |
| 85 | + $component = $request["component"]; |
| 86 | + |
| 87 | + $return_info = array("result" => "pass"); |
| 88 | + if ($component == "core") { |
| 89 | + $missing_files = Files::checkCoreFiles(); |
| 90 | + $return_info["component_type"] = "core"; |
| 91 | + $return_info["component_name"] = "Form Tools Core"; |
| 92 | + } |
| 93 | + if (preg_match("/^module_/", $component)) { |
| 94 | + $module_id = preg_replace("/^module_/", "", $component); |
| 95 | + $module_info = Modules::getModule($module_id); |
| 96 | + $missing_files = Files::checkModuleFiles($module_info["module_folder"]); |
| 97 | + $return_info["component_type"] = "module"; |
| 98 | + $return_info["component_name"] = $module_info["module_name"]; |
| 99 | + } |
| 100 | + if (preg_match("/^theme_/", $component)) { |
| 101 | + $theme_id = preg_replace("/^theme_/", "", $component); |
| 102 | + $theme_info = Themes::getTheme($theme_id); |
| 103 | + $missing_files = Files::checkThemeFiles($theme_info["theme_folder"]); |
| 104 | + $return_info["component_type"] = "theme"; |
| 105 | + $return_info["component_name"] = $theme_info["theme_name"]; |
| 106 | + } |
| 107 | + if (!empty($missing_files)) { |
| 108 | + $return_info["result"] = "fail"; |
| 109 | + $return_info["missing_files"] = $missing_files; |
| 110 | + } |
| 111 | + echo json_encode($return_info); |
| 112 | + break; |
| 113 | + |
| 114 | + case "find_table_orphans": |
| 115 | + $remove_orphans = isset($request["remove_orphans"]) ? true : false; |
| 116 | + $results = Orphans::findTableOrphans($request["table_name"], $remove_orphans); |
| 117 | + echo json_encode($results); |
| 118 | + break; |
| 119 | +} |
| 120 | + |
| 121 | + |
0 commit comments