function do_delete() { global $delete, $conn, $modul; if ($delete) { preg_match("/(.*)_(.*)/i", $modul, $alter_modul); if (isset($alter_modul[2])) { if ($alter_modul[2] == 'fields') { $sql = "SELECT title, c_default FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE id='" . $delete . "' "; $result = db_mysql_query($sql, $conn); $arr = db_mysql_fetch_array($result); if ($arr['c_default'] == '1') { unset($delete); } else { $sql = "ALTER TABLE " . $_SESSION['TABLE_PREFIX'] . $alter_modul[1] . " \n\t\t\t\t\t\t\t\t\tDROP COLUMN " . $arr['title'] . " "; db_mysql_query($sql, $conn); } } if ($alter_modul[2] == 'tree') { $data = array(); $sql = "SELECT id, title, id_parent, sort_order FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE c_active = '1' ORDER BY sort_order ASC "; $result = db_mysql_query($sql, $conn); while ($arr = db_mysql_fetch_array($result)) { $data[$arr['id']] = $arr; } delete_tree($alter_modul[1], build_tree($data, $delete), $delete); $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $alter_modul[1] . " WHERE id_tree = '" . $delete . "' "; db_mysql_query($sql, $conn); } } if (isset($delete)) { $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE id = '" . $delete . "' "; db_mysql_query($sql, $conn); } } }
function delete_tree($dir) { /** * gets all the files and directories from the given directory (excluding hidden files) and loops over them deleting them. * checks if the file '000.txt' file is present which is the first file in the main directory. * prevents the action as a fail safe if it finds it. * deletes the directory itself after deleting the contents. * * @since 1.0 * * @caller delete_doc * @ingroup delete doc * * @param string $dir is the directory to be trashed. * * @return null * * @var array $files is all the directory's files' and directories */ $files = array_diff(scandir($dir), array('.', '..')); $isInSubDir = false; foreach ($files as $file) { if ($file === 'subfile.txt') { $isInSubDir = true; } } if ($isInSubDir) { foreach ($files as $file) { is_dir("{$dir}/{$file}") ? delete_tree("{$dir}/{$file}") : unlink("{$dir}/{$file}"); } rmdir($dir); } }
function delete_tree($table, $data, $i = 1, $id_parent = NULL) { global $conn; foreach ($data as $key => $value) { $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $table . " WHERE id_tree = '" . $value['id'] . "' "; db_mysql_query($sql, $conn); $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $table . "_tree WHERE id = '" . $value['id'] . "' "; db_mysql_query($sql, $conn); if ($value['id_parent'] == $id_parent) { $i = 1; } if (isset($value['children'])) { delete_tree($table, $value['children'], $i + 1, $value['id_parent']); } } }