getModule(); $module = Vtiger_Module::getInstance($moduleName); echo '
'; if (!$module) { echo '

' . vtranslate('Invalid module') . '

'; echo '
'; } else { echo '

' . $module->label . '

'; echo '
'; // Uninstall module $module->delete(); // Clean & Clear $this->cleanDatabase($moduleName); $this->cleanFolder($moduleName); $this->cleanLanguage($moduleName); echo "Module was uninstalled."; } echo '
'; echo 'Back to ' . vtranslate('ModuleManager') . ''; echo '
'; } /** * @param $moduleName */ function cleanDatabase($moduleName) { global $adb; // vtiger_finreportscf table echo "  - Delete vtiger_finreportscf table."; $result = $adb->pquery("DROP TABLE vtiger_finreportscf"); echo ($result) ? " - DONE" : " - ERROR"; echo '
'; // vtiger_finreports table echo "  - Delete vtiger_finreports table."; $result = $adb->pquery("DROP TABLE vtiger_finreports"); echo ($result) ? " - DONE" : " - ERROR"; echo '
'; } /** * @param $moduleName */ function cleanFolder($moduleName) { echo "  - Remove " . $moduleName . " template folder"; $result = $this->removeFolder('layouts/v7/modules/' . $moduleName); echo ($result) ? " - DONE" : " - ERROR"; echo '
'; echo "  - Remove " . $moduleName . " module folder"; $result = $this->removeFolder('modules/' . $moduleName); echo ($result) ? " - DONE" : " - ERROR"; echo '
'; } /** * @param $path * @return bool */ function removeFolder($path) { if (!isFileAccessible($path) || !is_dir($path)) { return false; } if (!is_writeable($path)) { chmod($path, 0777); } $handle = opendir($path); while ($tmp = readdir($handle)) { if ($tmp == '..' || $tmp == '.') { continue; } $tmpPath = $path . DS . $tmp; if (is_file($tmpPath)) { if (!is_writeable($tmpPath)) { chmod($tmpPath, 0666); } unlink($tmpPath); } else if (is_dir($tmpPath)) { if (!is_writeable($tmpPath)) { chmod($tmpPath, 0777); } $this->removeFolder($tmpPath); } } closedir($handle); rmdir($path); return !is_dir($path); } /** * @param $moduleName */ function cleanLanguage($moduleName) { $files = glob("languages/*/{$moduleName}.php"); // get all file names foreach ($files as $file) { // iterate files if (is_file($file)) { unlink($file); // delete file } } } /** * @link http://stackoverflow.com/questions/7288029/php-delete-directory-that-is-not-empty * @param $dir */ function rmdir_recursive($dir) { foreach (scandir($dir) as $file) { if ('.' === $file || '..' === $file) continue; $tmpFile = "$dir/$file"; if (is_dir($tmpFile)) $this->rmdir_recursive($tmpFile); else unlink($tmpFile); } rmdir($dir); } }