| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
// executes the SQL found in a module install.sql or uninstall.sql |
|---|
| 4 |
function runModuleSQL($moddir,$type){ |
|---|
| 5 |
global $db; |
|---|
| 6 |
if (is_file("modules/{$moddir}/{$type}.sql")) { |
|---|
| 7 |
|
|---|
| 8 |
$fd = fopen("modules/{$moddir}/{$type}.sql","r"); |
|---|
| 9 |
while (!feof($fd)) { |
|---|
| 10 |
$data .= fread($fd, 1024); |
|---|
| 11 |
} |
|---|
| 12 |
fclose($fd); |
|---|
| 13 |
|
|---|
| 14 |
preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP).*);\s*\n/Us", $data, $matches); |
|---|
| 15 |
|
|---|
| 16 |
foreach ($matches[1] as $sql) { |
|---|
| 17 |
$result = $db->query($sql); |
|---|
| 18 |
if(DB::IsError($result)) { |
|---|
| 19 |
return false; |
|---|
| 20 |
} |
|---|
| 21 |
} |
|---|
| 22 |
return true; |
|---|
| 23 |
} |
|---|
| 24 |
return true; |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
function installModule($modname,$modversion) { |
|---|
| 28 |
global $db; |
|---|
| 29 |
$sql = "INSERT INTO modules (modulename, version) values ('{$modname}','{$modversion}')"; |
|---|
| 30 |
$results = $db->query($sql); |
|---|
| 31 |
if(DB::IsError($results)) { |
|---|
| 32 |
die($results->getMessage()); |
|---|
| 33 |
} |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
function uninstallModule($modname) { |
|---|
| 37 |
global $db; |
|---|
| 38 |
$sql = "DELETE FROM modules WHERE modulename = '{$modname}'"; |
|---|
| 39 |
$results = $db->query($sql); |
|---|
| 40 |
if(DB::IsError($results)) { |
|---|
| 41 |
die($results->getMessage()); |
|---|
| 42 |
} |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
function enableModule($modname) { |
|---|
| 46 |
global $db; |
|---|
| 47 |
$sql = "UPDATE modules SET enabled = 1 WHERE modulename = '{$modname}'"; |
|---|
| 48 |
$results = $db->query($sql); |
|---|
| 49 |
if(DB::IsError($results)) { |
|---|
| 50 |
die($results->getMessage()); |
|---|
| 51 |
} |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
function disableModule($modname) { |
|---|
| 55 |
global $db; |
|---|
| 56 |
$sql = "UPDATE modules SET enabled = 0 WHERE modulename = '{$modname}'"; |
|---|
| 57 |
$results = $db->query($sql); |
|---|
| 58 |
if(DB::IsError($results)) { |
|---|
| 59 |
die($results->getMessage()); |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
if (isset($_POST['submit'])) { |
|---|
| 64 |
switch ($_POST['modaction']) { |
|---|
| 65 |
case "install": |
|---|
| 66 |
if (runModuleSQL($_POST['modname'],$_POST['modaction'])) |
|---|
| 67 |
installModule($_POST['modname'],$_POST['modversion']); |
|---|
| 68 |
else |
|---|
| 69 |
echo "<div class=\"error\">"._("Module install script failed to run")."</div>"; |
|---|
| 70 |
break; |
|---|
| 71 |
case "uninstall": |
|---|
| 72 |
if (runModuleSQL($_POST['modname'],$_POST['modaction'])) |
|---|
| 73 |
uninstallModule($_POST['modname']); |
|---|
| 74 |
else |
|---|
| 75 |
echo "<div class=\"error\">"._("Module uninstall script failed to run")."</div>"; |
|---|
| 76 |
break; |
|---|
| 77 |
case "enable": |
|---|
| 78 |
enableModule($_POST['modname']); |
|---|
| 79 |
echo "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."'</script>"; |
|---|
| 80 |
break; |
|---|
| 81 |
case "disable": |
|---|
| 82 |
disableModule($_POST['modname']); |
|---|
| 83 |
echo "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."'</script>"; |
|---|
| 84 |
break; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
?> |
|---|
| 88 |
|
|---|
| 89 |
<h2>Module Administration</h2> |
|---|
| 90 |
|
|---|
| 91 |
<table border="1" width="100%"> |
|---|
| 92 |
<th>Module</th><th>Version</th><th>Status</th><th>Action</th> |
|---|
| 93 |
<?php |
|---|
| 94 |
foreach(find_allmodules() as $key => $mod) { |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
if ($mod['status'] == 0) { |
|---|
| 98 |
$status = _("Not Installed"); |
|---|
| 99 |
|
|---|
| 100 |
$action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 101 |
$action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 102 |
$action .= "<input type=\"hidden\" name=\"modversion\" value=\"{$mod['version']}\">"; |
|---|
| 103 |
$action .= "<input type=\"hidden\" name=\"modaction\" value=\"install\">"; |
|---|
| 104 |
$action .= "<input type=\"submit\" name=\"submit\" value=\""._("Install")."\">"; |
|---|
| 105 |
$action .= "</form>"; |
|---|
| 106 |
} else if($mod['status'] == 1){ |
|---|
| 107 |
$status = _("Disabled"); |
|---|
| 108 |
|
|---|
| 109 |
$action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 110 |
$action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 111 |
$action .= "<input type=\"hidden\" name=\"modaction\" value=\"enable\">"; |
|---|
| 112 |
$action .= "<input type=\"submit\" name=\"submit\" value=\""._("Enable")."\">"; |
|---|
| 113 |
$action .= "</form>"; |
|---|
| 114 |
|
|---|
| 115 |
$action .= "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 116 |
$action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 117 |
$action .= "<input type=\"hidden\" name=\"modaction\" value=\"uninstall\">"; |
|---|
| 118 |
$action .= "<input type=\"submit\" name=\"submit\" value=\""._("Uninstall")."\">"; |
|---|
| 119 |
$action .= "</form>"; |
|---|
| 120 |
|
|---|
| 121 |
} else if($mod['status'] == 2){ |
|---|
| 122 |
$status = _("Enabled"); |
|---|
| 123 |
|
|---|
| 124 |
$action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 125 |
$action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 126 |
$action .= "<input type=\"hidden\" name=\"modaction\" value=\"disable\">"; |
|---|
| 127 |
$action .= "<input type=\"submit\" name=\"submit\" value=\""._("Disable")."\">"; |
|---|
| 128 |
$action .= "</form>"; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
echo "<tr>"; |
|---|
| 132 |
echo "<td>"; |
|---|
| 133 |
echo $mod['displayName']; |
|---|
| 134 |
echo "</td>"; |
|---|
| 135 |
echo "<td>"; |
|---|
| 136 |
echo $mod['version']; |
|---|
| 137 |
echo "</td>"; |
|---|
| 138 |
echo "<td>"; |
|---|
| 139 |
echo $status; |
|---|
| 140 |
echo "</td>"; |
|---|
| 141 |
echo "<td>"; |
|---|
| 142 |
echo $action; |
|---|
| 143 |
echo "</td>"; |
|---|
| 144 |
echo "</tr>"; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
?> |
|---|
| 148 |
|
|---|
| 149 |
</table> |
|---|
| 150 |
|
|---|