forked from victorstanciu/dbv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_rev.php
88 lines (73 loc) · 2.23 KB
/
add_rev.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* @package: Multi-db upgrade
* @date: Dec 2013
* @author: Chris Fortune - http://cfortune.kics.bc.ca/
*/
session_start();
if($_POST['add_rev'] == 'add_rev')
{
$revision_id = $_POST['revision_id'];
$revision_num = $_POST['revision_num'];
$sql = $_POST['sql'];
$db = $_POST['db'];
if( $revision_id != '' && $revision_num != '')
{
if( !is_dir('data/revisions/'.$db.'/'.$revision_id) )
mkdir('data/revisions/'.$db.'/'.$revision_id);
if( !file_exists('data/revisions/'.$db.'/'.$revision_id.'/'.$revision_num) )
{
$my_file = $revision_num.'.sql';
$handle = fopen('data/revisions/'.$db.'/'.$revision_id.'/'.$my_file, 'w') or die('Cannot open file: '.'data/revisions/'.$db.'/'.$revision_id.'/'.$my_file);
if( $sql != '' )
fwrite($handle, $sql);
$_SESSION['act'] = 'Reviosn created successfully#success';
}
else
$_SESSION['act'] = 'Revisio number is already exists#error';
}
else
$_SESSION['act'] = 'Revision ID and Revision number should not be empty.#error';
echo '<script>window.location.href="index.php?db='.$db.'"</script>';
}
else if($_REQUEST['act'] == 'delfile')
{
$db = $_REQUEST['db'];
$dir_file= $_REQUEST['val'];
$del_file = unlink('data/revisions/'.$db.'/'.$dir_file);
if($del_file)
$_SESSION['act'] = 'File deleted successfully#success';
else
$_SESSION['act'] = 'File could not deleted#error';
echo '<script>window.location.href="index.php?db='.$db.'"</script>';
}
else if($_REQUEST['act'] == 'delfolder')
{
$db = $_REQUEST['db'];
$folder = $_REQUEST['val'];
$del_folder = rrmdir('data/revisions/'.$db.'/'.$folder);
if($del_folder)
$_SESSION['act'] = 'Folder could not deleted#error';
else
$_SESSION['act'] = 'Folder deleted successfully#success';
echo '<script>window.location.href="index.php?db='.$db.'"</script>';
}
else
echo '<script>window.location.href="index.php?db='.$db.'"</script>';
function rrmdir($dir)
{
if (is_dir($dir))
{
$objects = scandir($dir);
foreach ($objects as $object)
{
if ($object != "." && $object != "..")
{
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
?>