folder_delete.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. require_once ("./header.php");
  3. logged_in_only ();
  4. $noconfirm = set_get_noconfirm ();
  5. # the root folder cannot be deleted
  6. if ($folderid == "" || $folderid == 0){
  7. message ("No Folder selected");
  8. }
  9. else if (!$settings['confirm_delete'] || $noconfirm) {
  10. # lets do the deletion if the confirm variable is set to FALSE or after confirmation
  11. require_once (ABSOLUTE_PATH . "folders.php");
  12. $tree = new folder;
  13. $tree->get_children ($folderid);
  14. # we need $parent_folders for javascript code below.
  15. $parent_folders = $tree->get_path_to_root ($folderid);
  16. if (count ($parent_folders) > 1) {
  17. $parent_folder = $parent_folders[1];
  18. }
  19. else {
  20. $parent_folder = 0;
  21. }
  22. array_push ($tree->get_children, $folderid);
  23. $folders = implode (",", $tree->get_children);
  24. # first delete all subfolders
  25. $query = sprintf ("DELETE FROM folder WHERE childof IN (%s) AND user='%s'",
  26. $mysql->escape ($folders),
  27. $mysql->escape ($username));
  28. if (!$mysql->query ($query)) {
  29. message ($mysql->error);
  30. }
  31. # of course, we want to delete all bookmarks as well
  32. $query = sprintf ("DELETE FROM bookmark WHERE childof IN (%s) AND user='%s'",
  33. $mysql->escape ($folders),
  34. $mysql->escape ($username));
  35. if (!$mysql->query ($query)) {
  36. message ($mysql->error);
  37. }
  38. # now delete the folder itself
  39. $query = sprintf ("DELETE FROM folder WHERE id=%d AND user='%s'",
  40. $mysql->escape ($folderid),
  41. $mysql->escape ($username));
  42. if (!$mysql->query ($query)) {
  43. message ($mysql->error);
  44. }
  45. ?>
  46. <script language="JavaScript">
  47. <!--
  48. function reloadparentwindow() {
  49. var path = window.opener.document.URL;
  50. searchstring = /(folderid=[0-9]*)/gi;
  51. result = searchstring.test(path);
  52. if(result == false) {
  53. urlparams = window.opener.location.search;
  54. if (urlparams == "") {
  55. result = path + "?folderid=<?php echo $parent_folder; ?>";
  56. }
  57. else {
  58. result = path + "&folderid=<?php echo $parent_folder; ?>";
  59. }
  60. }
  61. else {
  62. result = path.replace (searchstring,"folderid=<?php echo $parent_folder; ?>");
  63. }
  64. window.opener.location = result;
  65. window.close();
  66. }
  67. reloadparentwindow();
  68. //-->
  69. </script>
  70. <?php
  71. }
  72. else {
  73. # if there was no confirmation, as to _really_ delete the whole stuff
  74. # print the verification form
  75. $query = sprintf ("SELECT name, public FROM folder WHERE id=%d AND user='%s' AND deleted!='1'",
  76. $mysql->escape ($folderid),
  77. $mysql->escape ($username));
  78. if ($mysql->query ($query)) {
  79. if (mysqli_num_rows ($mysql->result) == 0){
  80. message ("Folder does not exist");
  81. }
  82. $row = mysqli_fetch_object ($mysql->result);
  83. ?>
  84. <h2 class="title">Delete this Folder?</h2>
  85. <p><?php echo $row->public ? $folder_opened_public : $folder_opened; echo " " . $row->name; ?></p>
  86. <form action="<?php echo $_SERVER['SCRIPT_NAME'] . "?folderid=" . $folderid . "&amp;noconfirm=1";?>" method="POST" name="fdelete">
  87. <input type="submit" value=" OK ">
  88. <input type="button" value=" Cancel " onClick="self.close()">
  89. </form>
  90. <?php
  91. }
  92. else {
  93. message ($mysql->error);
  94. }
  95. }
  96. require_once (ABSOLUTE_PATH . "footer.php");
  97. ?>