-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
147 lines (128 loc) · 3.81 KB
/
index.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Project list</title>
<LINK href='main.css' type=text/css rel=stylesheet>
<script>
function confirm_prompt( text,url ) {
if (confirm( text )) {
window.location = url ;
}
}
</script>
</head>
<body>
<h2>Projects</h2>
<?php
include_once("image2video.php");
#$project_id=$_POST['project_id'];
$basedir=dirname(__FILE__);
$main_upload_dir="$basedir/uploads/";
$main_upload_url="./uploads";
$bin_dir="$basedir/bin";
$errors= array();
$messages= array();
$today = date("F j, Y, g:i a");
$dt = date("U");
if( $_GET['new'] ) {
echo "<h3>Add new project</h3>
<form action='index.php' method='post' multipart='' enctype='multipart/form-data'>
<table>
<tr>
<td><input type='text' name='project_name' value='New project $today' size=50></td>
<td><input type='submit' name='save' id='save' value='Save'> </td>
</tr>
</table>
<input type='hidden' name='add' id='add' value='1'>
</form>
</body>
</html>
";
exit(0);
}
if( $_POST['add'] ) {
$project=array();
$project_id=$dt.sha1( $_POST['project_name'].$today );
$project_name=$_POST['project_name'];
$project['project_name']=$project_name;
$project['project_id']=$project_id;
$project['main_upload_dir']=$main_upload_dir;
if( ! mkdir( "$main_upload_dir/$project_id", 0777, true) )
{
echo "<h2><font color=red>Error! Cannot make the directory $main_upload_dir/$project_id</font></h2>";
exit (0);
}
$myfile = fopen("$main_upload_dir/$project_id/project.txt", "w") ;
if( !$myfile )
{
"<h2><font color=red>Error! Unable to save file $main_upload_dir/$project_id/project.txt</font></h2>";
exit(0);
}
fwrite($myfile, json_encode ( $project ) );
fclose($myfile);
echo "<h3>Project '$project_name' created</h3>
<form action='upload_images.php' method='post' multipart='' enctype='multipart/form-data'>
<table>
<tr>
<td><input type='submit' name='save' id='save' value='Add images to project'> </td>
</tr>
</table>
<input type='hidden' name='project_id' value='$project_id'>
</form>
</body>
</html>
";
// renew the fonts list
$command="find /usr/share/fonts/truetype/ |grep ttf\$ >$main_upload_dir/fonts.txt 2>/dev/null";
#$command="convert -list font | awk '/Font:/ {print $2}' >$basedir/fonts.txt 2>/dev/null";
exec ( $command );
exit(0);
}
if( $_GET['del'] && $_GET['project_id'] ) {
$project_id=$_GET['project_id'];
if( file_exists( "$main_upload_dir/$project_id/project.txt") ) {
exec( "rm -rf $main_upload_dir/$project_id" );
echo "<h2><font color=green>Project with id '$project_id' removed</font></h2>";
} else{
echo "<h2><font color=red>Error! Cannot remove the project '$project_id'</font></h2>";
}
}
echo '
<table>
<tr>
<td bgcolor=#FDF2FF><a href="index.php?new=1">Add new project</a></td>
<td></td>
<td></td>
</tr>
';
$Dirs=scandir( $main_upload_dir , SCANDIR_SORT_DESCENDING );
/* echo '<pre>';
echo var_dump($Dirs );
echo '</pre>';
echo '<pre>';
echo var_dump($dir );
echo '</pre>';
*/
foreach( $Dirs as $dir ) {
if( file_exists( "$main_upload_dir/$dir/project.txt") ) {
$string = file_get_contents("$main_upload_dir/$dir/project.txt");
$project = json_decode($string, true);
$project_name=$project['project_name'];
$project_id=$project['project_id'];
echo " <tr>
<td><a href='edit_effect.php?project_id=$project_id'>$project_name</a></td>
<td>[ <a href='clone_project.php?old_project_id=$project_id'> Clone this project</a> ]</td>
<td>[ <a href='' onclick=\"confirm_prompt( 'Are you sure to remove this project?','?del=1&project_id=$project_id'); return false;\">Remove this project</a> ]</td>
</tr>\n";
}
}
echo '
</form>
</table>
</body>
</html>
';
?>
</body>
</html>