/mods/_core/file_manager/delete.php

https://github.com/harriswong/ATutor · PHP · 185 lines · 138 code · 27 blank · 20 comment · 22 complexity · 15f9eefafe55f90196247871b79fd402 MD5 · raw file

  1. <?php
  2. /****************************************************************/
  3. /* ATutor */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or*/
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /****************************************************************/
  13. define('AT_INCLUDE_PATH', '../../../include/');
  14. require(AT_INCLUDE_PATH.'vitals.inc.php');
  15. require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
  16. global $db;
  17. if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
  18. authenticate(AT_PRIV_CONTENT);
  19. }
  20. $current_path = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
  21. $popup = $_REQUEST['popup'];
  22. $framed = $_REQUEST['framed'];
  23. if (isset($_POST['submit_no'])) {
  24. $msg->addFeedback('CANCELLED');
  25. header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
  26. exit;
  27. }
  28. if (isset($_POST['submit_yes'])) {
  29. /* delete files and directories */
  30. /* delete the file */
  31. $pathext = $_POST['pathext'];
  32. if (isset($_POST['listoffiles'])) {
  33. $checkbox = explode(',',$_POST['listoffiles']);
  34. $count = count($checkbox);
  35. $result=true;
  36. for ($i=0; $i<$count; $i++) {
  37. $filename=$checkbox[$i];
  38. if (course_realpath($current_path . $pathext . $filename) == FALSE) {
  39. $msg->addError('FILE_NOT_DELETED');
  40. $result=false;
  41. break;
  42. } else if (!(@unlink($current_path.$pathext.$filename))) {
  43. $msg->addError('FILE_NOT_DELETED');
  44. $result=false;
  45. break;
  46. }
  47. }
  48. if ($result)
  49. {
  50. // delete according definition of primary resources and alternatives for adapted content
  51. $filename = '../'.$pathext.$filename;
  52. // 1. delete secondary resources types
  53. $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources_types
  54. WHERE secondary_resource_id in (SELECT secondary_resource_id
  55. FROM ".TABLE_PREFIX."secondary_resources
  56. WHERE secondary_resource = '".$filename."'
  57. OR primary_resource_id in (SELECT primary_resource_id
  58. FROM ".TABLE_PREFIX."primary_resources
  59. WHERE resource='".$filename."'))";
  60. $result = mysql_query($sql, $db);
  61. // 2. delete secondary resources
  62. $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources
  63. WHERE secondary_resource = '".$filename."'
  64. OR primary_resource_id in (SELECT primary_resource_id
  65. FROM ".TABLE_PREFIX."primary_resources
  66. WHERE resource='".$filename."')";
  67. $result = mysql_query($sql, $db);
  68. // 3. delete primary resources types
  69. $sql = "DELETE FROM ".TABLE_PREFIX."primary_resources_types
  70. WHERE primary_resource_id in (SELECT primary_resource_id
  71. FROM ".TABLE_PREFIX."primary_resources
  72. WHERE resource = '".$filename."')";
  73. $result = mysql_query($sql, $db);
  74. // 4. delete primary resources
  75. $sql = "DELETE FROM ".TABLE_PREFIX."primary_resources
  76. WHERE resource = '".$filename."'";
  77. $result = mysql_query($sql, $db);
  78. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  79. }
  80. }
  81. /* delete directory */
  82. if (isset($_POST['listofdirs'])) {
  83. $checkbox = explode(',',$_POST['listofdirs']);
  84. $count = count($checkbox);
  85. $result=true;
  86. for ($i=0; $i<$count; $i++) {
  87. $filename=$checkbox[$i];
  88. if (strpos($filename, '..') !== false) {
  89. $msg->addError('UNKNOWN');
  90. $result=false;
  91. header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
  92. exit;
  93. } else if (!is_dir($current_path.$pathext.$filename)) {
  94. $msg->addError(array('DIR_NOT_DELETED',$filename));
  95. $result=false;
  96. header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
  97. exit;
  98. } else if (!($result = clr_dir($current_path.$pathext.$filename))) {
  99. $msg->addError('DIR_NO_PERMISSION');
  100. $result=false;
  101. header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
  102. exit;
  103. }
  104. }
  105. if ($result)
  106. $msg->addFeedback('DIR_DELETED');
  107. }
  108. header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'cp='.$_POST['cp'].SEP.'cid='.$_POST['cid'].SEP.'pid='.$_POST['pid'].SEP.'a_type='.$_POST['a_type']);
  109. exit;
  110. }
  111. require(AT_INCLUDE_PATH.'header.inc.php');
  112. // find the files and directories to be deleted
  113. $total_list = explode(',', $_GET['list']);
  114. $pathext = $_GET['pathext'];
  115. $popup = $_GET['popup'];
  116. $framed = $_GET['framed'];
  117. $cp = $_GET['cp'];
  118. $cid = $_GET['cid'];
  119. $pid = $_GET['pid'];
  120. $a_type = $_GET['a_type'];
  121. $count = count($total_list);
  122. $countd = 0;
  123. $countf = 0;
  124. foreach ($total_list as $list_item) {
  125. if (is_dir($current_path.$pathext.$list_item)) {
  126. $_dirs[$countd] = $list_item;
  127. $countd++;
  128. } else {
  129. $_files[$countf] = $list_item;
  130. $countf++;
  131. }
  132. }
  133. $hidden_vars['pathext'] = $pathext;
  134. $hidden_vars['popup'] = $popup;
  135. $hidden_vars['framed'] = $framed;
  136. $hidden_vars['cp'] = $cp;
  137. $hidden_vars['cid'] = $cid;
  138. $hidden_vars['pid'] = $pid;
  139. $hidden_vars['a_type'] = $a_type;
  140. if (isset($_files)) {
  141. $list_of_files = implode(',', $_files);
  142. $hidden_vars['listoffiles'] = $list_of_files;
  143. foreach ($_files as $file) {
  144. $file_list_to_print .= '<li>'.$file.'</li>';
  145. }
  146. $msg->addConfirm(array('FILE_DELETE', $file_list_to_print), $hidden_vars);
  147. }
  148. if (isset($_dirs)) {
  149. $list_of_dirs = implode(',', $_dirs);
  150. $hidden_vars['listofdirs'] = $list_of_dirs;
  151. foreach ($_dirs as $dir) {
  152. $dir_list_to_print .= '<li>'.$dir.'</li>';
  153. }
  154. $msg->addConfirm(array('DIR_DELETE',$dir_list_to_print), $hidden_vars);
  155. }
  156. $msg->printConfirm();
  157. require(AT_INCLUDE_PATH.'footer.inc.php');
  158. ?>