|
|
1 |
<?PHP
|
|
|
2 |
|
|
|
3 |
if($member_db[1] != 1){ msg("error", "Access Denied", "You don't have permission for this section"); }
|
|
|
4 |
$success = FALSE;
|
|
|
5 |
// ********************************************************************************
|
|
|
6 |
// Archive
|
|
|
7 |
// ********************************************************************************
|
|
|
8 |
if($action == "archive")
|
|
|
9 |
{
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
// ***************************
|
|
|
13 |
// Un-Archive
|
|
|
14 |
// ***************************
|
|
|
15 |
if($subaction == "unarchive" and $aid != "" and isset($aid)){
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
if(!$handle = opendir("$cutepath/data/archives")){ die("<center>Unable to open directory $cutepath/data/archive</center>"); }
|
|
|
19 |
while (false !== ($file = readdir($handle)))
|
|
|
20 |
{
|
|
|
21 |
if ($file == "$aid.news.arch")
|
|
|
22 |
{
|
|
|
23 |
$newsfile = fopen("$cutepath/data/news.txt", 'a');
|
|
|
24 |
$newsarch = file("$cutepath/data/archives/$file");
|
|
|
25 |
foreach ($newsarch as $newsline)
|
|
|
26 |
{
|
|
|
27 |
fwrite($newsfile,$newsline);
|
|
|
28 |
}
|
|
|
29 |
fclose($newsfile);
|
|
|
30 |
unlink("$cutepath/data/archives/$file");
|
|
|
31 |
}
|
|
|
32 |
elseif ($file == "$aid.comments.arch")
|
|
|
33 |
{
|
|
|
34 |
$commfile = fopen("$cutepath/data/comments.txt", 'a');
|
|
|
35 |
$commarch = file("$cutepath/data/archives/$file");
|
|
|
36 |
foreach ($commarch as $commline)
|
|
|
37 |
{
|
|
|
38 |
fwrite($commfile,$commline);
|
|
|
39 |
}
|
|
|
40 |
fclose($commfile);
|
|
|
41 |
unlink("$cutepath/data/archives/$file");
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
closedir($handle);
|
|
|
45 |
|
|
|
46 |
}//end Un-Archive function
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
echoheader("archives", "Archives");
|
|
|
50 |
|
|
|
51 |
echo<<<HTML
|
|
|
52 |
|
|
|
53 |
<script language="javascript">
|
|
|
54 |
function confirmdelete(id,news){
|
|
|
55 |
var agree=confirm("Do you really want to permanently delete this archive ?\\nAll ("+news+") news and comments in it will be deleted.");
|
|
|
56 |
if (agree)
|
|
|
57 |
document.location="$PHP_SELF?mod=tools&action=dodeletearchive&archive="+id;
|
|
|
58 |
}
|
|
|
59 |
</script>
|
|
|
60 |
<form method=post action="$PHP_SELF"><table border=0 cellpading=0 cellspacing=0 width="645" >
|
|
|
61 |
<td width=321 height="33">
|
|
|
62 |
<b>Send news to archive</b>
|
|
|
63 |
<table border=0 cellpading=0 cellspacing=0 width=300 class="panel" cellpadding="10" >
|
|
|
64 |
<tr>
|
|
|
65 |
<td width=304 height="25">
|
|
|
66 |
<p align="center">
|
|
|
67 |
<input type=submit value="Proceed with archiving ...">
|
|
|
68 |
</tr>
|
|
|
69 |
|
|
|
70 |
</table>
|
|
|
71 |
<input type=hidden name=action value=doarchive>
|
|
|
72 |
<input type=hidden name=mod value=tools>
|
|
|
73 |
</form>
|
|
|
74 |
|
|
|
75 |
<td width=320 height="33" align="center">
|
|
|
76 |
<!-- HELP -->
|
|
|
77 |
|
|
|
78 |
<table height="25" cellspacing="0" cellpadding="0">
|
|
|
79 |
<tr>
|
|
|
80 |
<td width="25" align=middle><img border="0" src="skins/images/help_small.gif"></td>
|
|
|
81 |
<td > <a onClick="javascript:Help('archives')" href="#">Explaining archives and<br>
|
|
|
82 |
Their usage</a></td>
|
|
|
83 |
</tr>
|
|
|
84 |
</table>
|
|
|
85 |
|
|
|
86 |
<tr>
|
|
|
87 |
<td width=654 colspan="2" height="11">
|
|
|
88 |
<img height=20 border=0 src="skins/images/blank.gif" width=1>
|
|
|
89 |
<br> </tr>
|
|
|
90 |
<tr>
|
|
|
91 |
<td width=654 colspan=2 height=14>
|
|
|
92 |
<b>Available archives</b>
|
|
|
93 |
</tr>
|
|
|
94 |
<tr>
|
|
|
95 |
|
|
|
96 |
<td width=654 colspan=2 height=1>
|
|
|
97 |
<table width=641 height=100% cellspacing=0 cellpadding=0>
|
|
|
98 |
<tr>
|
|
|
99 |
<td width=8 bgcolor=#F7F6F4> </td>
|
|
|
100 |
<td width=160 bgcolor=#F7F6F4><u>archivation date</u></td>
|
|
|
101 |
<td width=222 bgcolor=#F7F6F4><u>duration</u></td>
|
|
|
102 |
<td width=81 bgcolor=#F7F6F4><u>news</u></td>
|
|
|
103 |
<td width=110 bgcolor=#F7F6F4><u><!--action--></u></td>
|
|
|
104 |
|
|
|
105 |
</tr>
|
|
|
106 |
HTML;
|
|
|
107 |
|
|
|
108 |
if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archives "); }
|
|
|
109 |
while (false !== ($file = readdir($handle)))
|
|
|
110 |
{
|
|
|
111 |
if($file != "." and $file != ".." and !is_dir("./data/archives/$file") and eregi("news.arch", $file))
|
|
|
112 |
{
|
|
|
113 |
|
|
|
114 |
$file_arr = explode(".", $file);
|
|
|
115 |
$id = $file_arr[0];
|
|
|
116 |
|
|
|
117 |
$news_lines = file("./data/archives/$file");
|
|
|
118 |
$creation_date = date("d F Y",$file_arr[0]);
|
|
|
119 |
$count = count($news_lines);
|
|
|
120 |
$last = $count-1;
|
|
|
121 |
$first_news_arr = explode("|", $news_lines[$last]);
|
|
|
122 |
$last_news_arr = explode("|", $news_lines[0]);
|
|
|
123 |
|
|
|
124 |
$first_timestamp = $first_news_arr[0];
|
|
|
125 |
$last_timestamp = $last_news_arr[0];
|
|
|
126 |
|
|
|
127 |
$duration = (date("d M Y",$first_timestamp) ." - ". date("d M Y",$last_timestamp) );
|
|
|
128 |
echo "
|
|
|
129 |
<tr>
|
|
|
130 |
<td ></td>
|
|
|
131 |
<td >$creation_date</td>
|
|
|
132 |
<td >$duration</td>
|
|
|
133 |
<td >$count</td>
|
|
|
134 |
<td ><a title='Edit the news in this archive' href=\"$PHP_SELF?mod=editnews&action=list&source=$id\">[edit]</a> <a title='restore news from this archive to active news' href=\"$PHP_SELF?mod=tools&action=archive&subaction=unarchive&aid=$id\">[unarchive]</a> <a title='Delete this archive' onClick=\"javascript:confirmdelete('$id', '$count');\" href=\"#\">[delete]</a></td>
|
|
|
135 |
</tr>
|
|
|
136 |
";
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
closedir($handle);
|
|
|
140 |
|
|
|
141 |
if($count == 0){
|
|
|
142 |
echo"<tr><td align=center colspan=6><br>There are no archives</td></tr>";
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
echo<<<HTML
|
|
|
146 |
</table>
|
|
|
147 |
</table>
|
|
|
148 |
HTML;
|
|
|
149 |
|
|
|
150 |
echofooter();
|
|
|
151 |
}
|
|
|
152 |
// ********************************************************************************
|
|
|
153 |
// Make Archive
|
|
|
154 |
// ********************************************************************************
|
|
|
155 |
elseif($action == "doarchive")
|
|
|
156 |
{
|
|
|
157 |
if(filesize("./data/news.txt") == 0){ msg("error", "Error !!!", "Sorry but there are no news to be archived", "$PHP_SELF?mod=tools&action=archive"); }
|
|
|
158 |
if(filesize("./data/comments.txt") == 0){ msg("error", "Error !!!", "The comments file is empty and can not be archived", "$PHP_SELF?mod=tools&action=archive"); }
|
|
|
159 |
|
|
|
160 |
$arch_name = time()+($config_date_adjust*60);
|
|
|
161 |
if(!@copy("./data/news.txt","./data/archives/$arch_name.news.arch")) { msg("error","Error !!!","Can not create file ./data/archives/$arch_name.news.arch", "$PHP_SELF?mod=tools&action=archive");}
|
|
|
162 |
if(!@copy("./data/comments.txt","./data/archives/$arch_name.comments.arch")) { msg("error","Error !!!","Can not create file ./data/archives/$arch_name.comments.arch", "$PHP_SELF?mod=tools&action=archive");}
|
|
|
163 |
|
|
|
164 |
$handle = fopen("./data/news.txt","w");
|
|
|
165 |
fclose($handle);
|
|
|
166 |
$handle = fopen("./data/comments.txt","w");
|
|
|
167 |
fclose($handle);
|
|
|
168 |
|
|
|
169 |
msg("archives", "Archive Saved", "  All active news were successfully added to archives file with name <b>$arch_name.news.arch</b>", "$PHP_SELF?mod=tools&action=archive");
|
|
|
170 |
}
|
|
|
171 |
// ********************************************************************************
|
|
|
172 |
// Do Delete Archive
|
|
|
173 |
// ********************************************************************************
|
|
|
174 |
elseif($action == "dodeletearchive"){
|
|
|
175 |
$success = 0;
|
|
|
176 |
if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archive "); }
|
|
|
177 |
while (false !== ($file = readdir($handle))){
|
|
|
178 |
if($file == "$archive.news.arch" or $file == "$archive.comments.arch"){
|
|
|
179 |
unlink("./data/archives/$file"); $success ++;
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
closedir($handle);
|
|
|
183 |
|
|
|
184 |
if($success == 2){
|
|
|
185 |
msg("info", "Arhcive Deleted", "The archive was successfully deleted", "$PHP_SELF?mod=tools&action=archive");
|
|
|
186 |
}elseif($success == 1){
|
|
|
187 |
msg("error", "Error !!!", "Either the comments part or the news part of the archive was not deleted", "$PHP_SELF?mod=tools&action=archive");
|
|
|
188 |
}else{
|
|
|
189 |
msg("error", "Error !!!", "The archive you specified was not deleted, it is not on the server or you don't have permissions to delete it", "$PHP_SELF?mod=tools&action=archive");
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
}
|
|
|
193 |
// ********************************************************************************
|
|
|
194 |
// Backup News and archives
|
|
|
195 |
// ********************************************************************************
|
|
|
196 |
elseif($action == "backup")
|
|
|
197 |
{
|
|
|
198 |
echoheader("options", "Backup");
|
|
|
199 |
echo'
|
|
|
200 |
<script language="javascript">
|
|
|
201 |
function confirmdelete(id){
|
|
|
202 |
var agree=confirm("Do you really want to permanently delete this backup ?");
|
|
|
203 |
if (agree)
|
|
|
204 |
document.location="index.php?mod=tools&action=dodeletebackup&backup="+id;
|
|
|
205 |
}
|
|
|
206 |
function confirmrestore(id){
|
|
|
207 |
var agree=confirm("Do you really want to restore your news from this backup ?\nAll current news and archives will be overwritten.");
|
|
|
208 |
if (agree)
|
|
|
209 |
document.location="index.php?mod=tools&action=dorestorebackup&backup="+id;
|
|
|
210 |
}
|
|
|
211 |
</script>
|
|
|
212 |
<table border=0 cellpading=0 cellspacing=0 width="645" >
|
|
|
213 |
<td width=321 height="33">
|
|
|
214 |
<b>Create BackUp</b>
|
|
|
215 |
<table border=0 cellpading=0 cellspacing=0 class="panel" cellpadding="10" width="390" >
|
|
|
216 |
<form method=post action="'.$PHP_SELF.'">
|
|
|
217 |
<tr>
|
|
|
218 |
<td height="25" width="366">
|
|
|
219 |
Name of the BackUp: <input type=text name=back_name> <input type=submit value=" Proceed ">
|
|
|
220 |
|
|
|
221 |
</td>
|
|
|
222 |
</tr>
|
|
|
223 |
<input type=hidden name=action value=dobackup>
|
|
|
224 |
<input type=hidden name=mod value=tools>
|
|
|
225 |
</form>
|
|
|
226 |
</table>
|
|
|
227 |
<tr>
|
|
|
228 |
<td width=654 height="11">
|
|
|
229 |
<img height=20 border=0 src="skins/images/blank.gif" width=1>
|
|
|
230 |
<br> </tr>
|
|
|
231 |
<tr>
|
|
|
232 |
<td width=654 height=14>
|
|
|
233 |
<b>Available BackUps</b>
|
|
|
234 |
</tr>
|
|
|
235 |
<tr>
|
|
|
236 |
<td width=654 height=1>
|
|
|
237 |
<table width=641 height=100% cellspacing=0 cellpadding=0>
|
|
|
238 |
<tr>
|
|
|
239 |
<td width=2% bgcolor=#F7F6F4> </td>
|
|
|
240 |
<td width=40% bgcolor=#F7F6F4><u>name</u></td>
|
|
|
241 |
<td width=22% bgcolor=#F7F6F4><u>active news</u></td>
|
|
|
242 |
<td width=16% bgcolor=#F7F6F4><u>archives</u></td>
|
|
|
243 |
<td width=20% bgcolor=#F7F6F4><u>action</u></td>
|
|
|
244 |
</tr>';
|
|
|
245 |
|
|
|
246 |
$count = 0;
|
|
|
247 |
if(!$handle = opendir("./data/backup")){ die("<center>Can not open directory $cutepath/data/backup "); }
|
|
|
248 |
while (false !== ($file = readdir($handle)))
|
|
|
249 |
{
|
|
|
250 |
if($file != "." and $file != ".." and is_dir("./data/backup/$file"))
|
|
|
251 |
{
|
|
|
252 |
$archives_count = 0;
|
|
|
253 |
$archives_handle = @opendir("./data/backup/$file/archives");
|
|
|
254 |
while (false !== ($arch = readdir($archives_handle))){
|
|
|
255 |
if(eregi(".news.arch", $arch)){ $archives_count++; }
|
|
|
256 |
}
|
|
|
257 |
closedir($archives_handle);
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
$news_count = count(file("./data/backup/$file/news.txt"));
|
|
|
261 |
echo "<tr>
|
|
|
262 |
<td></td>
|
|
|
263 |
<td>$file</td>
|
|
|
264 |
<td> $news_count</td>
|
|
|
265 |
<td> $archives_count</td>
|
|
|
266 |
<td><a onClick=\"javascript:confirmdelete('$file'); return(false)\" href=\"$PHP_SELF?mod=tools&action=dodeletebackup&backup=$file\">[delete]</a> <a onClick=\"javascript:confirmrestore('$file'); return(false)\" href=\"$PHP_SELF?mod=tools&action=dorestorebackup&backup=$file\">[restore]</a></td>
|
|
|
267 |
</tr>";
|
|
|
268 |
$count++;
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
closedir($handle);
|
|
|
272 |
|
|
|
273 |
if($count == 0){
|
|
|
274 |
echo"<tr><td colspan=5><p align=center><br>There are no backups</p></td></tr>";
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
echo'</table></table>';
|
|
|
278 |
|
|
|
279 |
echofooter();
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
// ********************************************************************************
|
|
|
283 |
// Do Delete Backup
|
|
|
284 |
// ********************************************************************************
|
|
|
285 |
elseif($action == "dodeletebackup")
|
|
|
286 |
{
|
|
|
287 |
|
|
|
288 |
function listdir($dir){
|
|
|
289 |
|
|
|
290 |
$current_dir = opendir($dir);
|
|
|
291 |
while($entryname = readdir($current_dir)){
|
|
|
292 |
if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
|
|
|
293 |
listdir("${dir}/${entryname}");
|
|
|
294 |
}elseif($entryname != "." and $entryname!=".."){
|
|
|
295 |
unlink("${dir}/${entryname}");
|
|
|
296 |
}
|
|
|
297 |
}
|
|
|
298 |
@closedir($current_dir);
|
|
|
299 |
rmdir(${dir});
|
|
|
300 |
}
|
|
|
301 |
listdir("./data/backup/$backup");
|
|
|
302 |
|
|
|
303 |
msg("info", "Backup Deleted", "The backup was successfully deleted.", "$PHP_SELF?mod=tools&action=backup");
|
|
|
304 |
|
|
|
305 |
}
|
|
|
306 |
// ********************************************************************************
|
|
|
307 |
// Do restore backup
|
|
|
308 |
// ********************************************************************************
|
|
|
309 |
elseif($action == "dorestorebackup"){
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
if(!@copy("./data/backup/$backup/news.txt", "./data/news.txt")){ msg("error", "error", "./data/backup/$backup/news.txt", "$PHP_SELF?mod=tools&action=backup"); }
|
|
|
313 |
if(!@copy("./data/backup/$backup/comments.txt", "./data/comments.txt")){ msg("error", "error", "./data/backup/$backup/comments.txt", "$PHP_SELF?mod=tools&action=backup"); }
|
|
|
314 |
|
|
|
315 |
$dirp = opendir("./data/backup/$backup/archives");
|
|
|
316 |
while($entryname = readdir($dirp)){
|
|
|
317 |
if(!is_dir("./data/backup/$backup/archives/$entryname") and $entryname!="." and $entryname!=".."){
|
|
|
318 |
if(!@copy("./data/backup/$backup/archives/$entryname", "./data/archives/$entryname")){ msg("error", "error", "Can not copy ./data/backup/$backup/archives/$entryname"); }
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
msg("info", "Backup Restored", "The backup was successfully restored.", "$PHP_SELF?mod=tools&action=backup");
|
|
|
323 |
}
|
|
|
324 |
// ********************************************************************************
|
|
|
325 |
// Make The BackUp
|
|
|
326 |
// ********************************************************************************
|
|
|
327 |
elseif($action == "dobackup")
|
|
|
328 |
{
|
|
|
329 |
$back_name = eregi_replace(" ", "-", $back_name);
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
if(filesize("./data/news.txt") == 0){msg("error", "Error !!!", "The news file is empty and can not be backed-up", "$PHP_SELF?mod=tools&action=backup");}
|
|
|
333 |
if(filesize("./data/comments.txt") == 0){msg("error", "Error !!!", "The comments file is empty and can not be backed-up", "$PHP_SELF?mod=tools&action=backup");}
|
|
|
334 |
|
|
|
335 |
if(is_readable("./data/backup/$back_name")){ msg("error", "Error !!!", "A backup with this name already exist", "$PHP_SELF?mod=tools&action=backup"); }
|
|
|
336 |
if(!is_readable("./data/backup")){ mkdir("./backup", 0777); }
|
|
|
337 |
if(!is_writable("./data/backup")){ msg("error", "Error !!!", "The directory ./data/backup is not writable, please chmod it"); }
|
|
|
338 |
mkdir("./data/backup/$back_name", 0777);
|
|
|
339 |
mkdir("./data/backup/$back_name/archives", 0777);
|
|
|
340 |
|
|
|
341 |
if(!@copy("./data/news.txt", "./data/backup/$back_name/news.txt")){ die("Can not copy news.txt file to ./data/backup/$back_name :("); }
|
|
|
342 |
if(!@copy("./data/comments.txt","./data/backup/$back_name/comments.txt")){ die("Can not copy comments.txt file to ./data/backup/$back_name :("); }
|
|
|
343 |
|
|
|
344 |
if(!$handle = opendir("./data/archives")){ die("Can not create file"); }
|
|
|
345 |
while(false !== ($file = readdir($handle)))
|
|
|
346 |
{
|
|
|
347 |
if($file != "." and $file != "..")
|
|
|
348 |
{
|
|
|
349 |
if(!@copy("./data/archives/$file", "./data/backup/$back_name/archives/$file")){ die("Can not copy archive file to ./data/backup/$back_name/archives/$file :("); }
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
closedir($handle);
|
|
|
353 |
|
|
|
354 |
msg("info", "Backup", "All news and archives were successfully BackedUp under directory './data/backup/$back_name'", "$PHP_SELF?mod=tools&action=backup");
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
?> |