PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/installer/cleanUp.php

https://bitbucket.org/wildanm/orangehrm
PHP | 106 lines | 60 code | 27 blank | 19 comment | 15 complexity | ecdd6119831e1a1a7a4991fc6fb8e328 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, AGPL-3.0, BSD-3-Clause, AGPL-1.0, GPL-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
  4. * all the essential functionalities required for any enterprise.
  5. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
  6. *
  7. * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program;
  16. * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA
  18. *
  19. */
  20. // Cleaning up
  21. function connectDB() {
  22. if(!@mysql_connect($_SESSION['dbInfo']['dbHostName'].':'.$_SESSION['dbInfo']['dbHostPort'], $_SESSION['dbInfo']['dbUserName'], $_SESSION['dbInfo']['dbPassword'])) {
  23. $_SESSION['error'] = 'Database Connection Error!';
  24. return false;
  25. }
  26. return true;
  27. }
  28. function cleanUp() {
  29. if ($_SESSION['cMethod'] == 'new' || $_SESSION['dbCreateMethod'] == 'new') {
  30. if (!connectDB()) {
  31. return false;
  32. }
  33. if (isset($_SESSION['dbInfo']['dbOHRMUserName'])) {
  34. $query = dropUser();
  35. }
  36. $query[0] = dropDB();
  37. $sucExec = $query;
  38. $overall = true;
  39. for ($i=0; $i < count($query); $i++) {
  40. $sucExec[$i] = mysql_query($query[$i]);
  41. if (!$sucExec[$i]) {
  42. $overall = false;
  43. }
  44. }
  45. if (!$overall) {
  46. connectDB();
  47. for ($i=0; $i < count($query); $i++) {
  48. if (!$sucExec[$i]) {
  49. $sucExec[$i] = mysql_query($query[$i]);
  50. }
  51. if (!$sucExec[$i]) {
  52. $overall = false;
  53. }
  54. }
  55. }
  56. }
  57. $sucExec[] = delConf();
  58. return $sucExec;
  59. }
  60. function dropDB() {
  61. $query = "DROP DATABASE ". $_SESSION['dbInfo']['dbName'];
  62. return $query;
  63. }
  64. function dropUser() {
  65. $tables = array('`user`', '`db`', '`tables_priv`', '`columns_priv`');
  66. foreach ($tables as $table) {
  67. $query[] = "DELETE FROM $table WHERE `User` = '".$_SESSION['dbInfo']['dbOHRMUserName']."' AND (`Host` = 'localhost' OR `Host` = '%')";
  68. }
  69. return $query;
  70. }
  71. function delConf() {
  72. $filename = ROOT_PATH . '/lib/confs/Conf.php';
  73. return @unlink($filename);
  74. }
  75. $_SESSION['cleanProgress'] = cleanUp();
  76. if (isset($_SESSION['UNISTALL']) && $_SESSION['cleanProgress']) {
  77. unset($_SESSION['UNISTALL']);
  78. }
  79. ?>