tweak year/agency modifer for queries
[contractdashboard.git] / cutenews / inc / tools.mdu
blob:a/cutenews/inc/tools.mdu -> blob:b/cutenews/inc/tools.mdu
<?PHP <?PHP
if($member_db[1] != 1){ msg("error", "Access Denied", "You don't have permission for this section"); } if($member_db[1] != 1){ msg("error", "Access Denied", "You don't have permission for this section"); }
$success = FALSE; $success = FALSE;
// ******************************************************************************** // ********************************************************************************
// Archive // Archive
// ******************************************************************************** // ********************************************************************************
if($action == "archive") if($action == "archive")
{ {
// *************************** // ***************************
// Un-Archive // Un-Archive
// *************************** // ***************************
if($subaction == "unarchive" and $aid != "" and isset($aid)){ if($subaction == "unarchive" and $aid != "" and isset($aid)){
if(!$handle = opendir("$cutepath/data/archives")){ die("<center>Unable to open directory $cutepath/data/archive</center>"); } if(!$handle = opendir("$cutepath/data/archives")){ die("<center>Unable to open directory $cutepath/data/archive</center>"); }
while (false !== ($file = readdir($handle))) while (false !== ($file = readdir($handle)))
{ {
if ($file == "$aid.news.arch") if ($file == "$aid.news.arch")
{ {
$newsfile = fopen("$cutepath/data/news.txt", 'a'); $newsfile = fopen("$cutepath/data/news.txt", 'a');
$newsarch = file("$cutepath/data/archives/$file"); $newsarch = file("$cutepath/data/archives/$file");
foreach ($newsarch as $newsline) foreach ($newsarch as $newsline)
{ {
fwrite($newsfile,$newsline); fwrite($newsfile,$newsline);
} }
fclose($newsfile); fclose($newsfile);
unlink("$cutepath/data/archives/$file"); unlink("$cutepath/data/archives/$file");
} }
elseif ($file == "$aid.comments.arch") elseif ($file == "$aid.comments.arch")
{ {
$commfile = fopen("$cutepath/data/comments.txt", 'a'); $commfile = fopen("$cutepath/data/comments.txt", 'a');
$commarch = file("$cutepath/data/archives/$file"); $commarch = file("$cutepath/data/archives/$file");
foreach ($commarch as $commline) foreach ($commarch as $commline)
{ {
fwrite($commfile,$commline); fwrite($commfile,$commline);
} }
fclose($commfile); fclose($commfile);
unlink("$cutepath/data/archives/$file"); unlink("$cutepath/data/archives/$file");
} }
} }
closedir($handle); closedir($handle);
}//end Un-Archive function }//end Un-Archive function
echoheader("archives", "Archives"); echoheader("archives", "Archives");
echo<<<HTML echo<<<HTML
<script language="javascript"> <script language="javascript">
function confirmdelete(id,news){ function confirmdelete(id,news){
var agree=confirm("Do you really want to permanently delete this archive ?\\nAll ("+news+") news and comments in it will be deleted."); var agree=confirm("Do you really want to permanently delete this archive ?\\nAll ("+news+") news and comments in it will be deleted.");
if (agree) if (agree)
document.location="$PHP_SELF?mod=tools&action=dodeletearchive&archive="+id; document.location="$PHP_SELF?mod=tools&action=dodeletearchive&archive="+id;
} }
</script> </script>
<form method=post action="$PHP_SELF"><table border=0 cellpading=0 cellspacing=0 width="645" > <form method=post action="$PHP_SELF"><table border=0 cellpading=0 cellspacing=0 width="645" >
<td width=321 height="33"> <td width=321 height="33">
<b>Send news to archive</b> <b>Send news to archive</b>
<table border=0 cellpading=0 cellspacing=0 width=300 class="panel" cellpadding="10" > <table border=0 cellpading=0 cellspacing=0 width=300 class="panel" cellpadding="10" >
<tr> <tr>
<td width=304 height="25"> <td width=304 height="25">
<p align="center"> <p align="center">
<input type=submit value="Proceed with archiving ..."> <input type=submit value="Proceed with archiving ...">
</tr> </tr>
</table> </table>
<input type=hidden name=action value=doarchive> <input type=hidden name=action value=doarchive>
<input type=hidden name=mod value=tools> <input type=hidden name=mod value=tools>
</form> </form>
<td width=320 height="33" align="center"> <td width=320 height="33" align="center">
<!-- HELP --> <!-- HELP -->
<table height="25" cellspacing="0" cellpadding="0"> <table height="25" cellspacing="0" cellpadding="0">
<tr> <tr>
<td width="25" align=middle><img border="0" src="skins/images/help_small.gif"></td> <td width="25" align=middle><img border="0" src="skins/images/help_small.gif"></td>
<td >&nbsp;<a onClick="javascript:Help('archives')" href="#">Explaining archives and<br> <td >&nbsp;<a onClick="javascript:Help('archives')" href="#">Explaining archives and<br>
&nbsp;Their usage</a></td> &nbsp;Their usage</a></td>
</tr> </tr>
</table> </table>
<tr> <tr>
<td width=654 colspan="2" height="11"> <td width=654 colspan="2" height="11">
<img height=20 border=0 src="skins/images/blank.gif" width=1> <img height=20 border=0 src="skins/images/blank.gif" width=1>
<br> </tr> <br> </tr>
<tr> <tr>
<td width=654 colspan=2 height=14> <td width=654 colspan=2 height=14>
<b>Available archives</b> <b>Available archives</b>
</tr> </tr>
<tr> <tr>
<td width=654 colspan=2 height=1> <td width=654 colspan=2 height=1>
<table width=641 height=100% cellspacing=0 cellpadding=0> <table width=641 height=100% cellspacing=0 cellpadding=0>
<tr> <tr>
<td width=8 bgcolor=#F7F6F4>&nbsp;</td> <td width=8 bgcolor=#F7F6F4>&nbsp;</td>
<td width=160 bgcolor=#F7F6F4><u>archivation date</u></td> <td width=160 bgcolor=#F7F6F4><u>archivation date</u></td>
<td width=222 bgcolor=#F7F6F4><u>duration</u></td> <td width=222 bgcolor=#F7F6F4><u>duration</u></td>
<td width=81 bgcolor=#F7F6F4><u>news</u></td> <td width=81 bgcolor=#F7F6F4><u>news</u></td>
<td width=110 bgcolor=#F7F6F4><u><!--action--></u></td> <td width=110 bgcolor=#F7F6F4><u><!--action--></u></td>
</tr> </tr>
HTML; HTML;
if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archives "); } if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archives "); }
while (false !== ($file = readdir($handle))) while (false !== ($file = readdir($handle)))
{ {
if($file != "." and $file != ".." and !is_dir("./data/archives/$file") and eregi("news.arch", $file)) if($file != "." and $file != ".." and !is_dir("./data/archives/$file") and eregi("news.arch", $file))
{ {
$file_arr = explode(".", $file); $file_arr = explode(".", $file);
$id = $file_arr[0]; $id = $file_arr[0];
$news_lines = file("./data/archives/$file"); $news_lines = file("./data/archives/$file");
$creation_date = date("d F Y",$file_arr[0]); $creation_date = date("d F Y",$file_arr[0]);
$count = count($news_lines); $count = count($news_lines);
$last = $count-1; $last = $count-1;
$first_news_arr = explode("|", $news_lines[$last]); $first_news_arr = explode("|", $news_lines[$last]);
$last_news_arr = explode("|", $news_lines[0]); $last_news_arr = explode("|", $news_lines[0]);
$first_timestamp = $first_news_arr[0]; $first_timestamp = $first_news_arr[0];
$last_timestamp = $last_news_arr[0]; $last_timestamp = $last_news_arr[0];
$duration = (date("d M Y",$first_timestamp) ." - ". date("d M Y",$last_timestamp) ); $duration = (date("d M Y",$first_timestamp) ." - ". date("d M Y",$last_timestamp) );
echo " echo "
<tr> <tr>
<td ></td> <td ></td>
<td >$creation_date</td> <td >$creation_date</td>
<td >$duration</td> <td >$duration</td>
<td >$count</td> <td >$count</td>
<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> <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>
</tr> </tr>
"; ";
} }
} }
closedir($handle); closedir($handle);
if($count == 0){ if($count == 0){
echo"<tr><td align=center colspan=6><br>There are no archives</td></tr>"; echo"<tr><td align=center colspan=6><br>There are no archives</td></tr>";
} }
echo<<<HTML echo<<<HTML
</table> </table>
</table> </table>
HTML; HTML;
echofooter(); echofooter();
} }
// ******************************************************************************** // ********************************************************************************
// Make Archive // Make Archive
// ******************************************************************************** // ********************************************************************************
elseif($action == "doarchive") elseif($action == "doarchive")
{ {
if(filesize("./data/news.txt") == 0){ msg("error", "Error !!!", "Sorry but there are no news to be archived", "$PHP_SELF?mod=tools&action=archive"); } if(filesize("./data/news.txt") == 0){ msg("error", "Error !!!", "Sorry but there are no news to be archived", "$PHP_SELF?mod=tools&action=archive"); }
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"); } 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"); }
$arch_name = time()+($config_date_adjust*60); $arch_name = time()+($config_date_adjust*60);
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");} 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");}
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");} 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");}
$handle = fopen("./data/news.txt","w"); $handle = fopen("./data/news.txt","w");
fclose($handle); fclose($handle);
$handle = fopen("./data/comments.txt","w"); $handle = fopen("./data/comments.txt","w");
fclose($handle); fclose($handle);
msg("archives", "Archive Saved", "&nbsp&nbsp; All active news were successfully added to archives file with name <b>$arch_name.news.arch</b>", "$PHP_SELF?mod=tools&action=archive"); msg("archives", "Archive Saved", "&nbsp&nbsp; All active news were successfully added to archives file with name <b>$arch_name.news.arch</b>", "$PHP_SELF?mod=tools&action=archive");
} }
// ******************************************************************************** // ********************************************************************************
// Do Delete Archive // Do Delete Archive
// ******************************************************************************** // ********************************************************************************
elseif($action == "dodeletearchive"){ elseif($action == "dodeletearchive"){
$success = 0; $success = 0;
if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archive "); } if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archive "); }
while (false !== ($file = readdir($handle))){ while (false !== ($file = readdir($handle))){
if($file == "$archive.news.arch" or $file == "$archive.comments.arch"){ if($file == "$archive.news.arch" or $file == "$archive.comments.arch"){
unlink("./data/archives/$file"); $success ++; unlink("./data/archives/$file"); $success ++;
} }
} }
closedir($handle); closedir($handle);
if($success == 2){ if($success == 2){
msg("info", "Arhcive Deleted", "The archive was successfully deleted", "$PHP_SELF?mod=tools&action=archive"); msg("info", "Arhcive Deleted", "The archive was successfully deleted", "$PHP_SELF?mod=tools&action=archive");
}elseif($success == 1){ }elseif($success == 1){
msg("error", "Error !!!", "Either the comments part or the news part of the archive was not deleted", "$PHP_SELF?mod=tools&action=archive"); msg("error", "Error !!!", "Either the comments part or the news part of the archive was not deleted", "$PHP_SELF?mod=tools&action=archive");
}else{ }else{
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"); 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");
} }
} }
// ******************************************************************************** // ********************************************************************************
// Backup News and archives // Backup News and archives
// ******************************************************************************** // ********************************************************************************
elseif($action == "backup") elseif($action == "backup")
{ {
echoheader("options", "Backup"); echoheader("options", "Backup");
echo' echo'
<script language="javascript"> <script language="javascript">
function confirmdelete(id){ function confirmdelete(id){
var agree=confirm("Do you really want to permanently delete this backup ?"); var agree=confirm("Do you really want to permanently delete this backup ?");
if (agree) if (agree)
document.location="index.php?mod=tools&action=dodeletebackup&backup="+id; document.location="index.php?mod=tools&action=dodeletebackup&backup="+id;
} }
function confirmrestore(id){ function confirmrestore(id){
var agree=confirm("Do you really want to restore your news from this backup ?\nAll current news and archives will be overwritten."); var agree=confirm("Do you really want to restore your news from this backup ?\nAll current news and archives will be overwritten.");
if (agree) if (agree)
document.location="index.php?mod=tools&action=dorestorebackup&backup="+id; document.location="index.php?mod=tools&action=dorestorebackup&backup="+id;
} }
</script> </script>
<table border=0 cellpading=0 cellspacing=0 width="645" > <table border=0 cellpading=0 cellspacing=0 width="645" >
<td width=321 height="33"> <td width=321 height="33">
<b>Create BackUp</b> <b>Create BackUp</b>
<table border=0 cellpading=0 cellspacing=0 class="panel" cellpadding="10" width="390" > <table border=0 cellpading=0 cellspacing=0 class="panel" cellpadding="10" width="390" >
<form method=post action="'.$PHP_SELF.'"> <form method=post action="'.$PHP_SELF.'">
<tr> <tr>
<td height="25" width="366"> <td height="25" width="366">
Name of the BackUp: <input type=text name=back_name>&nbsp; <input type=submit value=" Proceed "> Name of the BackUp: <input type=text name=back_name>&nbsp; <input type=submit value=" Proceed ">
</td> </td>
</tr> </tr>
<input type=hidden name=action value=dobackup> <input type=hidden name=action value=dobackup>
<input type=hidden name=mod value=tools> <input type=hidden name=mod value=tools>
</form> </form>
</table> </table>
<tr> <tr>
<td width=654 height="11"> <td width=654 height="11">
<img height=20 border=0 src="skins/images/blank.gif" width=1> <img height=20 border=0 src="skins/images/blank.gif" width=1>
<br> </tr> <br> </tr>
<tr> <tr>
<td width=654 height=14> <td width=654 height=14>
<b>Available BackUps</b> <b>Available BackUps</b>
</tr> </tr>
<tr> <tr>
<td width=654 height=1> <td width=654 height=1>
<table width=641 height=100% cellspacing=0 cellpadding=0> <table width=641 height=100% cellspacing=0 cellpadding=0>
<tr> <tr>
<td width=2% bgcolor=#F7F6F4>&nbsp;</td> <td width=2% bgcolor=#F7F6F4>&nbsp;</td>
<td width=40% bgcolor=#F7F6F4><u>name</u></td> <td width=40% bgcolor=#F7F6F4><u>name</u></td>
<td width=22% bgcolor=#F7F6F4><u>active news</u></td> <td width=22% bgcolor=#F7F6F4><u>active news</u></td>
<td width=16% bgcolor=#F7F6F4><u>archives</u></td> <td width=16% bgcolor=#F7F6F4><u>archives</u></td>
<td width=20% bgcolor=#F7F6F4><u>action</u></td> <td width=20% bgcolor=#F7F6F4><u>action</u></td>
</tr>'; </tr>';
$count = 0; $count = 0;
if(!$handle = opendir("./data/backup")){ die("<center>Can not open directory $cutepath/data/backup "); } if(!$handle = opendir("./data/backup")){ die("<center>Can not open directory $cutepath/data/backup "); }
while (false !== ($file = readdir($handle))) while (false !== ($file = readdir($handle)))
{ {
if($file != "." and $file != ".." and is_dir("./data/backup/$file")) if($file != "." and $file != ".." and is_dir("./data/backup/$file"))
{ {
$archives_count = 0; $archives_count = 0;
$archives_handle = @opendir("./data/backup/$file/archives"); $archives_handle = @opendir("./data/backup/$file/archives");
while (false !== ($arch = readdir($archives_handle))){ while (false !== ($arch = readdir($archives_handle))){
if(eregi(".news.arch", $arch)){ $archives_count++; } if(eregi(".news.arch", $arch)){ $archives_count++; }
} }
closedir($archives_handle); closedir($archives_handle);
$news_count = count(file("./data/backup/$file/news.txt")); $news_count = count(file("./data/backup/$file/news.txt"));
echo "<tr> echo "<tr>
<td></td> <td></td>
<td>$file</td> <td>$file</td>
<td>&nbsp;$news_count</td> <td>&nbsp;$news_count</td>
<td>&nbsp;$archives_count</td> <td>&nbsp;$archives_count</td>
<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> <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>
</tr>"; </tr>";
$count++; $count++;
} }
} }
closedir($handle); closedir($handle);
if($count == 0){ if($count == 0){
echo"<tr><td colspan=5><p align=center><br>There are no backups</p></td></tr>"; echo"<tr><td colspan=5><p align=center><br>There are no backups</p></td></tr>";
} }
echo'</table></table>'; echo'</table></table>';
echofooter(); echofooter();
} }
// ******************************************************************************** // ********************************************************************************
// Do Delete Backup // Do Delete Backup
// ******************************************************************************** // ********************************************************************************
elseif($action == "dodeletebackup") elseif($action == "dodeletebackup")
{ {
function listdir($dir){ function listdir($dir){
$current_dir = opendir($dir); $current_dir = opendir($dir);
while($entryname = readdir($current_dir)){ while($entryname = readdir($current_dir)){
if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){ if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
listdir("${dir}/${entryname}"); listdir(