| 5 | | if (isset($_POST['submit'])) { // if form has been submitted |
|---|
| 6 | | switch ($_POST['modaction']) { |
|---|
| 7 | | case "install": |
|---|
| 8 | | if (runModuleSQL($_POST['modname'],$_POST['modaction'])) |
|---|
| 9 | | installModule($_POST['modname'],$_POST['modversion']); |
|---|
| 10 | | else |
|---|
| 11 | | echo "<div class=\"error\">"._("Module install script failed to run")."</div>"; |
|---|
| 12 | | break; |
|---|
| 13 | | case "uninstall": |
|---|
| 14 | | if (runModuleSQL($_POST['modname'],$_POST['modaction'])) |
|---|
| 15 | | uninstallModule($_POST['modname']); |
|---|
| 16 | | else |
|---|
| 17 | | echo "<div class=\"error\">"._("Module uninstall script failed to run")."</div>"; |
|---|
| 18 | | |
|---|
| 19 | | break; |
|---|
| 20 | | case "enable": |
|---|
| 21 | | enableModule($_POST['modname']); |
|---|
| 22 | | //echo "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&foo=1'</script>"; |
|---|
| 23 | | echo "<script language='Javascript'>window.location.reload()</script>\n"; |
|---|
| 24 | | break; |
|---|
| 25 | | case "disable": |
|---|
| 26 | | disableModule($_POST['modname']); |
|---|
| 27 | | //echo "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&foo=2'</script>"; |
|---|
| 28 | | echo "<script language='Javascript'>window.location.reload()</script>\n"; |
|---|
| 29 | | break; |
|---|
| 30 | | case "delete": |
|---|
| 31 | | deleteModule($_POST['modname']); |
|---|
| 32 | | break; |
|---|
| 33 | | case "download": |
|---|
| 34 | | fetchModule($_POST['rawname']); |
|---|
| 35 | | break; |
|---|
| 36 | | case "upgrade": |
|---|
| 37 | | upgradeModule($_POST['modname']); |
|---|
| 38 | | break; |
|---|
| 39 | | case "rmmod": |
|---|
| 40 | | rmModule($_POST['modname']); |
|---|
| 41 | | break; |
|---|
| | 5 | $installed = find_allmodules(); |
|---|
| | 6 | |
|---|
| | 7 | function pageReload(){ |
|---|
| | 8 | return ""; |
|---|
| | 9 | //return "<script language=\"Javascript\">document.location='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&foo=".rand()."'</script>"; |
|---|
| | 10 | } |
|---|
| | 11 | |
|---|
| | 12 | if (isset($_POST['submit']) && is_array($_POST['modules'])) { // if form has been submitted |
|---|
| | 13 | foreach ($_POST['modules'] as $module) { |
|---|
| | 14 | switch ($_POST['modaction']) { |
|---|
| | 15 | case "install": |
|---|
| | 16 | if (runModuleSQL($module,'install')) |
|---|
| | 17 | installModule($module,$_POST[$module.'_version']); |
|---|
| | 18 | else |
|---|
| | 19 | echo "<div class=\"error\">"._("Module install script failed to run")."</div>"; |
|---|
| | 20 | break; |
|---|
| | 21 | case "uninstall": |
|---|
| | 22 | if (runModuleSQL($module,'uninstall')) |
|---|
| | 23 | uninstallModule($module); |
|---|
| | 24 | else |
|---|
| | 25 | echo "<div class=\"error\">"._("Module uninstall script failed to run")."</div>"; |
|---|
| | 26 | break; |
|---|
| | 27 | case "enable": |
|---|
| | 28 | enableModule($module); |
|---|
| | 29 | echo pageReload(); |
|---|
| | 30 | break; |
|---|
| | 31 | case "disable": |
|---|
| | 32 | disableModule($module); |
|---|
| | 33 | echo pageReload(); |
|---|
| | 34 | break; |
|---|
| | 35 | case "delete": |
|---|
| | 36 | deleteModule($module); |
|---|
| | 37 | rmModule($module); |
|---|
| | 38 | break; |
|---|
| | 39 | case "download": |
|---|
| | 40 | fetchModule($module); |
|---|
| | 41 | break; |
|---|
| | 42 | case "upgrade": |
|---|
| | 43 | upgradeModule($module); |
|---|
| | 44 | break; |
|---|
| | 45 | case "installenable": // install and enable a module |
|---|
| | 46 | $boolInstall = true; |
|---|
| | 47 | // only run install if it's not installed |
|---|
| | 48 | if ($installed[$module]['status'] == 0) { |
|---|
| | 49 | // set to false on failed install |
|---|
| | 50 | $boolInstall = runModuleSQL($module,'install'); |
|---|
| | 51 | if ($boolInstall) { |
|---|
| | 52 | installModule($module,$_POST[$module.'_version']); |
|---|
| | 53 | enableModule($module); |
|---|
| | 54 | echo pageReload(); |
|---|
| | 55 | } else { |
|---|
| | 56 | echo "<div class=\"error\">{$module}: "._("Module install script failed to run")."</div>"; |
|---|
| | 57 | } |
|---|
| | 58 | } else { // it's already installed, so just enable it |
|---|
| | 59 | enableModule($module); |
|---|
| | 60 | echo pageReload(); |
|---|
| | 61 | } |
|---|
| | 62 | break; |
|---|
| | 63 | case "downloadinstall": // download, install and enable |
|---|
| | 64 | fetchModule($module); |
|---|
| | 65 | if (runModuleSQL($module,'install')) |
|---|
| | 66 | installModule($module,$_POST[$module.'_version']); |
|---|
| | 67 | else |
|---|
| | 68 | echo "<div class=\"error\">"._("Module install script failed to run")."</div>"; |
|---|
| | 69 | enableModule($module); |
|---|
| | 70 | break; |
|---|
| | 71 | case "downloadupdate": //download and update |
|---|
| | 72 | fetchModule($module); |
|---|
| | 73 | upgradeModule($module); |
|---|
| | 74 | break; |
|---|
| | 75 | case "uninstalldelete": //uninstall and delete |
|---|
| | 76 | if (runModuleSQL($module,'uninstall')) |
|---|
| | 77 | uninstallModule($module); |
|---|
| | 78 | else |
|---|
| | 79 | echo "<div class=\"error\">"._("Module uninstall script failed to run")."</div>"; |
|---|
| | 80 | deleteModule($module); |
|---|
| | 81 | rmModule($module); |
|---|
| | 82 | break; |
|---|
| | 83 | } |
|---|
| 157 | | } |
|---|
| 158 | | |
|---|
| 159 | | $this->html .= $this->tableHtml($online[$arrkey],$status,$action); |
|---|
| 160 | | } |
|---|
| 161 | | |
|---|
| 162 | | } else { //local modules |
|---|
| 163 | | |
|---|
| 164 | | $installed = $this->sortModules($installed); |
|---|
| 165 | | if (isset($installed) && is_array($installed)) { |
|---|
| 166 | | foreach($installed as $key => $mod) { |
|---|
| 167 | | //dynamicatlly create a form based on status |
|---|
| 168 | | if ($mod['status'] == 0) { |
|---|
| 169 | | $status = _("Not Installed"); |
|---|
| 170 | | //install form |
|---|
| 171 | | $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 172 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 173 | | $action .= "<input type=\"hidden\" name=\"modversion\" value=\"{$mod['version']}\">"; |
|---|
| 174 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"install\">"; |
|---|
| 175 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Install")."\">"; |
|---|
| 176 | | $action .= "</form>"; |
|---|
| 177 | | $action .= "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 178 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 179 | | $action .= "<input type=\"hidden\" name=\"modversion\" value=\"{$mod['version']}\">"; |
|---|
| 180 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"rmmod\">"; |
|---|
| 181 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Remove")."\">"; |
|---|
| 182 | | $action .= "</form>"; |
|---|
| 183 | | } else if($mod['status'] == 1){ |
|---|
| 184 | | $status = _("Disabled"); |
|---|
| 185 | | //enable form |
|---|
| 186 | | $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 187 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 188 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"enable\">"; |
|---|
| 189 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Enable")."\">"; |
|---|
| 190 | | $action .= "</form>"; |
|---|
| 191 | | //uninstall form |
|---|
| 192 | | $action .= "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 193 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 194 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"uninstall\">"; |
|---|
| 195 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Uninstall")."\">"; |
|---|
| 196 | | $action .= "</form>"; |
|---|
| 197 | | |
|---|
| 198 | | } else if($mod['status'] == 2){ |
|---|
| 199 | | $status = _("Enabled"); |
|---|
| 200 | | //disable form |
|---|
| 201 | | $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 202 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 203 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"disable\">"; |
|---|
| 204 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Disable")."\">"; |
|---|
| 205 | | $action .= "</form>"; |
|---|
| 206 | | } else if($mod['status'] == 3){ |
|---|
| 207 | | $status = _("Enabled (needs update)"); |
|---|
| 208 | | //disable form |
|---|
| 209 | | $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 210 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 211 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"disable\">"; |
|---|
| 212 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Disable")."\">"; |
|---|
| 213 | | $action .= "</form>"; |
|---|
| 214 | | //upgrade form |
|---|
| 215 | | $action .= "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 216 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 217 | | $action .= "<input type=\"hidden\" name=\"modversion\" value=\"{$mod['version']}\">"; |
|---|
| 218 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"upgrade\">"; |
|---|
| 219 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Update")."\">"; |
|---|
| 220 | | $action .= "</form>"; |
|---|
| 221 | | } else if($mod['status'] == -1){ |
|---|
| 222 | | $status = _("Broken"); |
|---|
| 223 | | //disable form |
|---|
| 224 | | $action = "<form method=\"POST\" action=\"{$_SERVER['REQUEST_URI']}\" style=display:inline>"; |
|---|
| 225 | | $action .= "<input type=\"hidden\" name=\"modname\" value=\"{$key}\">"; |
|---|
| 226 | | $action .= "<input type=\"hidden\" name=\"modaction\" value=\"delete\">"; |
|---|
| 227 | | $action .= "<input type=\"submit\" name=\"submit\" value=\""._("Delete")."\">"; |
|---|
| 228 | | $action .= "</form>"; |
|---|
| 229 | | } |
|---|
| 230 | | $this->html .= $this->tableHtml($mod,$status,$action); |
|---|
| 231 | | } |
|---|
| 232 | | } |
|---|
| 233 | | } |
|---|
| | 206 | // build the table |
|---|
| | 207 | $this->html .= $this->formStart(_("Available Module Updates (online)")); |
|---|
| | 208 | $this->html .= $rows; |
|---|
| | 209 | $this->html .= $this->formEnd($mod['status']); |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | /* |
|---|
| | 213 | * Online Modules |
|---|
| | 214 | */ |
|---|
| | 215 | if(is_array($modsOnlineOnly)) { |
|---|
| | 216 | $rows = ""; |
|---|
| | 217 | foreach($modsOnlineOnly as $mod) { |
|---|
| | 218 | $color = "white"; |
|---|
| | 219 | $rows .= $this->tableHtml($mod,$color); |
|---|
| | 220 | } |
|---|
| | 221 | $this->options = " |
|---|
| | 222 | <select name=\"modaction\"> |
|---|
| | 223 | <option value=\"downloadinstall\">"._("Download and Install selected")." |
|---|
| | 224 | <option value=\"download\">"._("Download selected")." |
|---|
| | 225 | </select> |
|---|
| | 226 | <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> |
|---|
| | 227 | "; |
|---|
| | 228 | // build the table |
|---|
| | 229 | $this->html .= $this->formStart(_("Modules Available (online)")); |
|---|
| | 230 | $this->html .= $rows; |
|---|
| | 231 | $this->html .= $this->formEnd($mod['status']); |
|---|
| | 232 | } |
|---|
| | 233 | |
|---|
| | 234 | } |
|---|
| | 235 | |
|---|
| | 236 | $installed = $this->sortModules($installed); |
|---|
| | 237 | if (isset($installed) && is_array($installed)) { |
|---|
| | 238 | foreach($installed as $mod) { |
|---|
| | 239 | //create seperate arrays based on module status |
|---|
| | 240 | if ($mod['status'] == 0) { |
|---|
| | 241 | $modsNotinstalled[] = $mod; |
|---|
| | 242 | } else if($mod['status'] == 1){ |
|---|
| | 243 | $modsDisabled[] = $mod; |
|---|
| | 244 | } else if($mod['status'] == 2){ |
|---|
| | 245 | $modsEnabled[] = $mod; |
|---|
| | 246 | } else if($mod['status'] == 3){ |
|---|
| | 247 | $modsUpdate[] = $mod; |
|---|
| | 248 | } else if($mod['status'] == -1){ |
|---|
| | 249 | $modsBroken[] = $mod; |
|---|
| | 250 | } |
|---|
| | 251 | |
|---|
| | 252 | //$this->html .= $this->tableHtml($mod,$status,$color); |
|---|
| | 253 | } |
|---|
| | 254 | |
|---|
| | 255 | // draw a form and list for each module status |
|---|
| | 256 | /* |
|---|
| | 257 | * Modules Needing Update |
|---|
| | 258 | */ |
|---|
| | 259 | if(is_array($modsUpdate)) { |
|---|
| | 260 | $rows = ""; |
|---|
| | 261 | foreach($modsUpdate as $mod) { |
|---|
| | 262 | $color = "#CCFF00"; |
|---|
| | 263 | $rows .= $this->tableHtml($mod,$color); |
|---|
| | 264 | } |
|---|
| | 265 | $this->options = " |
|---|
| | 266 | <select name=\"modaction\"> |
|---|
| | 267 | <option value=\"upgrade\">"._("Upgrade Selected")." |
|---|
| | 268 | </select> |
|---|
| | 269 | <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> |
|---|
| | 270 | "; |
|---|
| | 271 | // build the table |
|---|
| | 272 | $this->html .= $this->formStart(_("Enabled Modules Requiring Upgrade")); |
|---|
| | 273 | $this->html .= $rows; |
|---|
| | 274 | $this->html .= $this->formEnd($mod['status']); |
|---|
| | 275 | } |
|---|
| | 276 | |
|---|
| | 277 | /* |
|---|
| | 278 | * Enabled Modules |
|---|
| | 279 | */ |
|---|
| | 280 | if(is_array($modsEnabled)) { |
|---|
| | 281 | $rows = ""; |
|---|
| | 282 | foreach($modsEnabled as $mod) { |
|---|
| | 283 | $color = "white"; |
|---|
| | 284 | $rows .= $this->tableHtml($mod,$color); |
|---|
| | 285 | } |
|---|
| | 286 | $this->options = " |
|---|
| | 287 | <select name=\"modaction\"> |
|---|
| | 288 | <option value=\"disable\">"._("Disable Selected")." |
|---|
| | 289 | <option value=\"uninstall\">"._("Uninstall Selected")." |
|---|
| | 290 | <option value=\"uninstalldelete\">"._("Uninstall and Delete Selected")." |
|---|
| | 291 | </select> |
|---|
| | 292 | <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> |
|---|
| | 293 | "; |
|---|
| | 294 | // build the table |
|---|
| | 295 | $this->html .= $this->formStart(_("Enabled Modules")); |
|---|
| | 296 | $this->html .= $rows; |
|---|
| | 297 | $this->html .= $this->formEnd($mod['status']); |
|---|
| | 298 | } |
|---|
| | 299 | |
|---|
| | 300 | /* |
|---|
| | 301 | * Disabled Modules |
|---|
| | 302 | */ |
|---|
| | 303 | if(is_array($modsDisabled)) { |
|---|
| | 304 | $rows = ""; |
|---|
| | 305 | foreach($modsDisabled as $mod) { |
|---|
| | 306 | $color = "white"; |
|---|
| | 307 | $rows .= $this->tableHtml($mod,$color); |
|---|
| | 308 | } |
|---|
| | 309 | $this->options = " |
|---|
| | 310 | <select name=\"modaction\"> |
|---|
| | 311 | <option value=\"enable\">"._("Enable Selected")." |
|---|
| | 312 | <option value=\"uninstall\">"._("Uninstall Selected")." |
|---|
| | 313 | <option value=\"uninstalldelete\">"._("Uninstall and Delete Selected")." |
|---|
| | 314 | </select> |
|---|
| | 315 | <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> |
|---|
| | 316 | "; |
|---|
| | 317 | // build the table |
|---|
| | 318 | $this->html .= $this->formStart(_("Disabled Modules")); |
|---|
| | 319 | $this->html .= $rows; |
|---|
| | 320 | $this->html .= $this->formEnd($mod['status']); |
|---|
| | 321 | } |
|---|
| | 322 | |
|---|
| | 323 | /* |
|---|
| | 324 | * Local Modules Not Installed |
|---|
| | 325 | */ |
|---|
| | 326 | if(is_array($modsNotinstalled)) { |
|---|
| | 327 | $rows = ""; |
|---|
| | 328 | foreach($modsNotinstalled as $mod) { |
|---|
| | 329 | $color = "white"; |
|---|
| | 330 | $rows .= $this->tableHtml($mod,$color); |
|---|
| | 331 | } |
|---|
| | 332 | $this->options = " |
|---|
| | 333 | <select name=\"modaction\"> |
|---|
| | 334 | <option value=\"installenable\">"._("Enable Selected")." |
|---|
| | 335 | <option value=\"delete\">"._("Delete Selected")." |
|---|
| | 336 | </select> |
|---|
| | 337 | <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> |
|---|
| | 338 | "; |
|---|
| | 339 | // build the table |
|---|
| | 340 | $this->html .= $this->formStart(_("Not Installed Local Modules")); |
|---|
| | 341 | $this->html .= $rows; |
|---|
| | 342 | $this->html .= $this->formEnd($mod['status']); |
|---|
| | 343 | } |
|---|
| | 344 | |
|---|
| | 345 | if(is_array($modsBroken)) { |
|---|
| | 346 | $rows = ""; |
|---|
| | 347 | foreach($modsBroken as $mod) { |
|---|
| | 348 | $color = "#FFFFFF"; |
|---|
| | 349 | $rows .= $this->tableHtml($mod,$color); |
|---|
| | 350 | } |
|---|
| | 351 | $this->options = " |
|---|
| | 352 | <select name=\"modac |
|---|
| | 353 | <option value=\"delete\">"._("Delete Selected")." |
|---|
| | 354 | </select> |
|---|
| | 355 | <input type=\"submit\" name=\"submit\" value=\""._("Submit")."\"> |
|---|
| | 356 | "; |
|---|
| | 357 | // build the table |
|---|
| | 358 | $this->html .= $this->formStart(_('Broken')); |
|---|
| | 359 | $this->html .= $rows; |
|---|
| | 360 | $this->html .= $this->formEnd($mod['status']); |
|---|
| | 361 | } |
|---|
| | 362 | |
|---|
| | 363 | } |
|---|
| | 364 | |
|---|