Location: PHPKode > projects > Yappa-ng > yappa-ng/admin_modules/admin_module_deldir.inc.php
<?php

/*
 * ***********************************************************************************************
 * Filename:     admin_module_deldir.inc.php
 * Module:       Admin-Module
 * Subcategory:  Delete a Photo-Album
 * Description:  Delets an album if there are no other subalbums
 * ***********************************************************************************************
 *
 *
 * Project:     yappa-ng : yet another php photo album - next generation
 * Author:      Fritz Berger <hide@address.com>
 * Copyright:   2003 Fritz Berger
 * $Header: /cvsroot/yappa-ng/yappa-ng/admin_modules/admin_module_deldir.inc.php,v 1.16 2005/04/25 18:02:06 zirkon13 Exp $
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * You may contact the author of yappa-ng by e-mail at:
 * hide@address.com
 *
 * The latest version of yappa-ng can be obtained from:
 *    http://www.zirkon.at/zirkon/scripts/yappa-ng/yappa-ng_main_ger.html (german)
 *    http://www.zirkon.at/zirkon/scripts/yappa-ng/yappa-ng_main_eng.html (english)
 *
 * ***********************************************************************************************
 * ***********************************************************************************************
 * ***                                                                                         ***
 * ***   yappa-ng is based on "YAPPA v1.7 devel - 22.April 2002"                               ***
 * ***                         released on http://sourceforge.net/projects/yappa/              ***
 * ***   YAPPA is Copyright Federico 'pix' Feroldi (hide@address.com)                           ***
 * ***   YAPPA is released under the GNU GPL                                                   ***
 * ***                                                                                         ***
 * ***********************************************************************************************
 * ***********************************************************************************************
 */

?>

<?php

/*
 * Standard Security Check
 */

if (!defined('SecCheck')) {
	die("You Cannot Access This Script Directly - Have a Nice Day.");
}


include_once($config['path_src_include'] . "common.inc.php");

/* function deldir($dir);
 * posted by flexer at cutephp dot com
 * posted at http://us4.php.net/manual/en/function.rmdir.php
 */
function deldir($dir){
	$current_dir = opendir($dir);
	while($entryname = readdir($current_dir)){
		if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
			deldir("${dir}/${entryname}");
		}elseif($entryname != "." and $entryname!=".."){
			unlink("${dir}/${entryname}");
		}
	}
	closedir($current_dir);
	$msg = rmdir(${'dir'});
return $msg;
}


function HandleForm () {
	global $config;
	global $selected_album;

	/* deleting the complete Album */
	$_strSelFolder = singleslash($config["photo_root"] . "/" . $selected_album);
	$msg = deldir($_strSelFolder);

	// log level 1: Administration 
	if((int)"1" & (int)$config["loglevel"]) { 
		$log_msg = date("U") . "|Administration|" . "AlbumAdmin Delete Album: Album $selected_album deleted" . "|" . $_SERVER["REMOTE_ADDR"] . "|-|admin_module_deldir.inc.php|" . __LINE__ . "\n"; 
		@error_log($log_msg, 3, "yappa-ng.log"); 
	} 


	/* delete cache only if album is deleted correctly */
	$_strSelFolder = singleslash($config["cache_root"] . "/" . $selected_album);
	if(@is_dir($_strSelFolder)) {
		$msg2 = deldir($_strSelFolder);
		// log level 1: Administration 
		if((int)"1" & (int)$config["loglevel"]) { 
			$log_msg = date("U") . "|Administration|" . "AlbumAdmin Delete Album: AlbumCache of $selected_album deleted" . "|" . $_SERVER["REMOTE_ADDR"] . "|-|admin_module_deldir.inc.php|" . __LINE__ . "\n"; 
			@error_log($log_msg, 3, "yappa-ng.log"); 
		} 

		/* $msg2 not returned and not commented in page.
		   This is the fast shot for the patch-210_06-del_cache_too -
		   for detailed messages I need all translators!!! - will take a while! */
	}


return $msg;
}

function CheckCannotDelete () {
	global $config;
	global $selected_album;

	$msg = false;
	$checkfile = singleslash($config["photo_root"] . "/" . $selected_album . "/cannot-delete-album");
	if (file_exists($checkfile)) {
		$msg = true;
		// log level 8: Warning
		if((int)"8" & (int)$config["loglevel"]) {
			$log_msg = date("U") . "|Warning|" . "AlbumAdmin Delete Album: COULD NOT DELETE the Album '" . $selected_album . "' because the 'cannot-delete-album' lockfile is in place!|" . $_SERVER["REMOTE_ADDR"] . "|-|admin_module_deldir.inc.php|" . __LINE__ . "\n";
			@error_log($log_msg, 3, "yappa-ng.log");
		}
	}

return $msg;

}

$uri_base = str_replace("&admintask=DelAlbum","",$global_var['self_url']);


if(isset($_POST['BeenSubmitted'])) {
	if((isset($_POST['AlbumDelete'])) && (isset($_POST['reallyDelete']))) {
		$msg = HandleForm();
	} else {
		$msg = 5;
	}

}

?>

<?php if((isset($page["subalbums"])) && (count($page["subalbums"]) > 0)) { ?>
	<table cellspacing="0" cellpadding="5" border="0" width="100%">
	<tr valign="top">
	<td class="thumbnailCell">
	<table width="100%" border="0" cellspacing="0" cellpadding="3">

		<tr><td colspan=4 align="center" class="adminHeading"><?php print $lang_akt["admin_deldir_hmain"]; ?></td></tr>
		<tr><td colspan="4" class="passwdAdminCancel" align="center" >
		[ <b><a href="<?php echo $uri_base ?>"><?php echo $lang_akt["passwd_admin_cancel"]; ?></b></a> ]</td></tr>
		<tr><td width="5%">&nbsp;</td><td width="10%">&nbsp;</td><td width="10%">&nbsp;</td><td>&nbsp;</td></tr>
		<tr><td colspan="4" align="center" class="adminStatus">
		<?php
		print $lang_akt["admin_deldir_status3a"];
		print $lang_akt["admin_deldir_status3b"];
		print $lang_akt["admin_deldir_status3c"];
		?>
		</td></tr>
	</table>
	</td>
	</tr>
	</table>
<?php } elseif (CheckCannotDelete()) {
	/* cannot-delete-album file is set. albbum is delete-protected!
	 * you can delete the images, make and delete subalbums, but you CANNOT delete THIS album */
	?>
	<table cellspacing="0" cellpadding="5" border="0" width="100%">
	<tr valign="top">
	<td class="thumbnailCell">
	<table width="100%" border="0" cellspacing="0" cellpadding="3">

		<tr><td colspan=4 align="center" class="adminHeading"><?php print $lang_akt["admin_deldir_hmain"]; ?></td></tr>
		<tr><td colspan="4" class="passwdAdminCancel" align="center" >
		[ <b><a href="<?php echo $uri_base ?>"><?php echo $lang_akt["passwd_admin_cancel"]; ?></b></a> ]</td></tr>
		<tr><td width="5%">&nbsp;</td><td width="10%">&nbsp;</td><td width="10%">&nbsp;</td><td>&nbsp;</td></tr>
		<tr><td colspan="4" align="center" class="adminStatus">
		<?php
		print $lang_akt["admin_deldir_status4a"];
		print $lang_akt["admin_deldir_status4b"];
		print $lang_akt["admin_deldir_status4c"];
		?>
		</td></tr>
	</table>
	</td>
	</tr>
	</table>

<?php } else {
	//  everything normal - go on standard routine
	?>
	<form action="<?php print $global_var['self_url']; ?>" method="post">
	<table cellspacing="0" cellpadding="5" border="0" width="100%">
	<tr valign="top">
	<td class="thumbnailCell">
	<table width="100%" border="0" cellspacing="0" cellpadding="3">

	<tr><td colspan=4 align="center" class="adminHeading"><?php print $lang_akt["admin_deldir_hmain"]; ?></td></tr>
	<tr><td colspan="4" class="passwdAdminCancel" align="center" >
	[ <b><a href="<?php echo $uri_base ?>"><?php echo $lang_akt["passwd_admin_cancel"]; ?></b></a> ]</td></tr>
	<tr><td width="5%">&nbsp;</td><td width="10%">&nbsp;</td><td width="10%">&nbsp;</td><td>&nbsp;</td></tr>
	<tr><td colspan="4" align="center" class="adminStatus">

	<?php if(isset($_POST['BeenSubmitted'])) {
		if(isset($msg)) {
			if($msg == 1) {
				// successfully deleted
				print $lang_akt["admin_deldir_status1"];
				print $lang_akt["admin_deldir_status1b"];
				print $lang_akt["admin_deldir_status1c"];
				?>
				</td></tr>
				<tr><td colspan="4">&nbsp;</td></tr>
				<tr><td colspan="4" class="passwdAdminCancel" align="center" >
				[ <b><a href="<?php print $_SERVER['PHP_SELF'] . "?logout=yes&"; ?>"><?php echo $lang_akt["admin_deldir_linkout"]; ?></b></a> ]</td></tr>
				<tr><td colspan="4">&nbsp;</td></tr>
				</table>
				</td>
				</tr>
				</table>
			<?php } elseif($msg == 5) {
				// not clicked onto both checkboxes
				print $lang_akt["admin_deldir_status3"];
				?>
				</td></tr>
				<tr><td colspan="4">&nbsp;</td></tr>
				</table>
				</td>
				</tr>
				</table>
			<?php } else {
				// ERROR during deletion
				print $lang_akt["admin_deldir_status2a"];
				print $lang_akt["admin_deldir_status2b"];
				print $lang_akt["admin_deldir_status2c"];
				?>
				</td></tr>
				<tr><td colspan="4">&nbsp;</td></tr>
				</table>
				</td>
				</tr>
				</table>
			<?php }
		}
	}  else {
		// not submitted
		?>
		</td></tr>
		<tr><td colspan="4">&nbsp;</td></tr>
		<tr><td colspan=4 class="adminDescription"><?php print $lang_akt["admin_deldir_titleh"]; ?></td></tr>
		<tr><td colspan=4 class="adminComments"><?php print $lang_akt["admin_deldir_titlefull"]; ?></td></tr>
		<tr><td colspan="4">&nbsp;</td></tr>
		<tr><td colspan="4" align="center" class="adminStatus"><?php print $lang_akt["admin_deldir_delete"]; ?></td></tr>
		<tr><td colspan="4" align="center" class="adminStatus"><?php print $selected_album; ?></td></tr>
		<tr><td colspan="4">&nbsp;</td></tr>

		<tr>
		<td>&nbsp;</td>
		<td class="adminSelection" align="right"><input type="checkbox" name="AlbumDelete" value="no"></td>
		<td class="adminComments" align="left" nowrap><?php print $lang_akt["admin_deldir_del"]; ?></td>
		<td>&nbsp;</td>
		</tr>
		<tr><td colspan="4">&nbsp;</td></tr>
		<tr>
		<td>&nbsp;</td>
		<td class="adminSelection" align="right"><input type="checkbox" name="reallyDelete" value="no"></td>
		<td class="adminComments" align="left" nowrap><?php print $lang_akt["admin_deldir_realdel"]; ?></td>
		<td>&nbsp;</td>
		</tr>


		<tr><td colspan="4">&nbsp;</td></tr>
		<tr><td colspan="4" align="center">
			<input type="hidden" name="BeenSubmitted" value="true">
			<input type="submit" name="submit" value="<?php print $lang_akt['submit']; ?>">
		</td>
		</tr>


		</table>
		</td>
		</tr>
		</table>
		</form>
	<?php }

}



?>
Return current item: Yappa-ng