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

/*
 * ***********************************************************************************************
 * Filename:     admin_module_delcomments.inc.php
 * Module:       Admin-Module
 * Subcategory:  Delete UserComments
 * Description:  Lets you delete offending or unwanted UserComments
 * ***********************************************************************************************
 *
 *
 * 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_delcomments.inc.php,v 1.3 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_eng.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                                                   ***
 * ***                                                                                         ***
 * ***********************************************************************************************
 * ***********************************************************************************************
 */


/*
 * 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");
include_once($config['path_src_include'] . "comments.inc.php");
include_once($config['path_src_include'] . "smily.inc.php");



/* ***********************************************************************************************
 * function show_one_comment($image_comment, $comm_counter)
 *
 * This function shows one comment
 *
 * Input: $image_comment: one comment of one image
 *        $comm_counter: number of this comment within all the comments of this image
 *
 * Output: a HTML-table with one UserComment
 *
 * ***********************************************************************************************
 */
function show_one_comment($image_comment, $comm_counter) {

	global $lang_akt;

	?>
	<tr><td colspan="4" width="100%"><table width="100%">
	<tr><td width="100px" class="adminSelection" nowrap><input type="checkbox" name="admin_del_form[<?php print $comm_counter ?>]" value="no">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td colspan="3" width="100%" class='imagedescriptionCell'><table width="100%" class='comTableBorder'>
	<tr><td colspan="2" align="left">
	<?php
	print "<table width='100%'>";
	if($image_comment['name'] != "") {
		print "<tr class='comNameCell'><td witdh='70%'><b>" . $image_comment['name'] . "</b></td>";
	} else {
		print "<tr class='comNameCell'><td witdh='70%'><b>" . $lang_akt['comm_anonymous'] . "</b></td>";
	}
	print "<td width='30%' align='right'><b>" . $lang_akt['com_number_each'] . "</b>" . $comm_counter . "</td></tr>";
	print "</table></td></tr>";

	print "<tr valign='top'><td width='25%' align='left'><table>";
	print "<tr valign='top' class='comLeftCell'><td width='100%' align='left'>" . date('d.m.y-H:i:s', $image_comment['date']) . "</td>";

	if(isset($image_comment['email'])) {
		if(($image_comment['email'] != "") && ($image_comment['email'] != "-")) {
			print "<tr class='comLeftCell'><td width='100%' align='left'>" . $image_comment['email'] . "</td></tr>";
		}
	}
	if(isset($image_comment['location'])) {
		if(($image_comment['location'] != "") && ($image_comment['location'] != "-")) {
			print "<tr><td width='100%' align='left' class='comLeftCell'><i>" . $image_comment['location'] . "</i></td></tr>";
		}
	}
	if($image_comment['mood'] != "6")  {
		print "<tr><td width='100%' align='left' class='comLeftCell'>" . $image_comment['mood'] . "</td></tr>";
	}
	print "</table></td><td class='comRightCell' width='75%'>" . $image_comment['text'] . "</td></tr>";
	?>
	</td></tr>
	</table></td></tr>
	</table></td></tr>
	<?php
}


/* ***********************************************************************************************
 * function Del_Comm_Step_One ($commentlist, $album_url)
 *
 * This function is Part 1 of deleting UserComments
 * 
 * Show the UserComments of the previously selected image and give a checkbox beside each comment to
 * make it selectable for deletion
 * The selected UserComments get sent to function Del_Comm_Step_Two
 *
 * Input: $commentlist: summarylist of all comments of this album
 *        $album_url: complete path from root 
 *
 * ***********************************************************************************************
 */
function Del_Comm_Step_One ($commentlist, $album_url) {

	global $config, $config_album;
	global $global_var;
	global $lang_akt;
	global $page;
	// global $album;
	global $selected_album;
	// global $image_name;

	if(isset($_POST['admin_form'])) {
		$l_help = $_POST['admin_form'];
		$image = $l_help['show_del'];

		//$album_url = singleslash($config['photo_root'] . "/" . $selected_album);
		//$commentlist = read_comlist($album_url);
		//$image = $page['image_name'];

		?>
		<tr><td colspan="7">&nbsp;</td></tr>
		<tr><td colspan="7" class="adminDescription"><?php print $lang_akt["admin_delcomm_titleh"];
		?></td></tr>
		<tr><td colspan="7" class="adminComments"><?php print $lang_akt["admin_delcomm_titlefull"];
		?></td></tr>

		<form action="<?php print $global_var['self_url']; ?>" method="post">
		<tr><td>
		<table width="100%" border="0" cellspacing="0" cellpadding="1" class='adminSelection'>

		<?php
		/* prepare all page-navigation links */
		$number = $commentlist[$image]['count'];
		//$prevnext = page_comment($number,$selected_album);
		$comment = array();
		$comment = read_imagecomments($album_url, $image);
		if($config_album['comment_sort'] == "d") {
			$sort_comment = matrix_Sort($comment,"date","d");
		} else {
			$sort_comment = $comment;
		}
		?>
		<?php
		foreach($sort_comment as $key=>$value) {
			$help = array();
			$help = $comment[$key];
			$image_comment = array();
			$image_comment = view_comment($help);
			$help_number = $key + 1;

			show_one_comment($image_comment, $help_number);

		} ?>

		<?php

		?>
		</table>
		</td></tr>
		<tr><td colspan="7">&nbsp;</td></tr>
		<tr><td colspan="7" align="center">
		<input type="hidden" name="Submit_Step_Two" value="true">
		<input type="hidden" name="imagename" value="<?php print $image; ?>">
		<input type="submit" name="submit" value="<?php print $lang_akt['submit']; ?>">
		</td>
		</tr>
		</form>
		<?php
	}
}


/* ***********************************************************************************************
 * function Del_Comm_Step_Two ($commentlist, $album_url)
 *
 * This function is Part 2 of deleting UserComments
 * 
 * Here the actual delete is done and saved to harddisk
 * The Comments get renumbered after one/some comments(s) get deleted
 *
 * Input: $commentlist: summarylist of all comments of this album
 *        $album_url: complete path from root 
 *
 * ***********************************************************************************************
 */
function Del_Comm_Step_Two ($commentlist, $album_url) {

	// global $config, $config_album;
	// global $global_var;
	global $lang_akt;
	// global $page;
	// global $album;
	// global $selected_album, $image_name;
	
	$del_count = 0;
	// check if any UserComment has been selected at all in Part 1
	if(isset($_POST['admin_del_form'])) {
		// image to which the comments belong
		$image = $_POST['imagename'];
		// load the comments to this image
		$comment = array();
		$comment = read_imagecomments($album_url, $image);

		$to_del_comm = array();
		$to_del_comm = $_POST['admin_del_form'];
		// delete the selected comments
		// and decrement the counter in the summmarylist
		foreach($to_del_comm as $key => $value) {
			// print "Nummer: " . $key . ", " . $value . " - name: " . $image . "</br>";
			$l_help = $key - 1;
			unset($comment[$l_help]);
			$commentlist[$image]['count'] = $commentlist[$image]['count'] - 1;
			$del_count++;
		}

		if($commentlist[$image]['count'] <= 0) {
			unset($commentlist[$image]);
			$new_comment = "empty";
		} else {
			// renumber the Comments of this image
			foreach($comment as $key => $value) {
				$new_comment[] = $comment[$key];
			}
		}

		write_comlist($album_url, $commentlist);
		write_imagecomments($album_url, $image, $new_comment);
		return $del_count;
	} else {
		return $del_count;
	}
}


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


$album_url = singleslash($config['photo_root'] . "/" . $selected_album);
$commentlist = read_comlist($album_url);


$album->read_dir();
$album->sort_dir();

?>

<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="7" align="center" class="adminHeading"><?php print $lang_akt["admin_delcomm_hmain"]; ?></td></tr>
	<tr><td colspan="7" 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 width="70px">&nbsp;</td><td width="70px">&nbsp;</td><td width="70px">&nbsp;</td><td>&nbsp;</td></tr>
	<?php

	if(isset($_POST['Submit_Step_One'])) {
		Del_Comm_Step_One($commentlist, $album_url);
	} else {
		if(isset($_POST['Submit_Step_Two'])) {
			$msg = Del_Comm_Step_Two($commentlist, $album_url);
			$commentlist = read_comlist($album_url);
		}?>
		<tr><td colspan="7">&nbsp;</td></tr>
		<tr><td colspan="7" class="adminDescription"><?php print $lang_akt["admin_delcomm1_titleh"];
		?></td></tr>
		<tr><td colspan="7" class="adminComments"><?php print $lang_akt["admin_delcomm1_titlefull"];
		?></td></tr>
		<?php

		if(isset($_POST['Submit_Step_Two'])) {
			switch($msg) {
				case "0":	$l_help = $lang_akt['admin_delcomm_msg3'];
						break;
				case "1":	$l_help = $msg . " " . $lang_akt['admin_delcomm_msg1'];
						break;
				default:	$l_help = $msg . " " . $lang_akt['admin_delcomm_msg2'];
						break;
			}
			?>
			<tr><td colspan="7" align="center" class="adminStatus"><?php print $l_help; ?></td></tr>
			<?php
		}
		if ($page["album_images"] == "0" ) { ?>
			<tr><td colspan="7" align="center" class="adminStatus"><?php echo
			$lang_akt["admin_modules_noimage"]; ?></td></tr>
		<?php } else { ?>
				<form action="<?php print $global_var['self_url']; ?>" method="post">
				<tr>
				<th>&nbsp;</th>
				<th class="adminComments" align="center"><?php print $lang_akt["admin_picname"]; ?></th>
				<th class="adminComments" align="center"><?php print $lang_akt["admin_image"]; ?></th>
				<th class="adminComments" align="center"><?php print "&nbsp;&nbsp;" .  $lang_akt["admin_delcomm_number"] . "&nbsp;&nbsp;"; ?></th>
				<th class="adminComments" align="center"><?php print "&nbsp;&nbsp;" .  $lang_akt["admin_delcomm_show"] . "&nbsp;&nbsp;"; ?></th>
				<th>&nbsp;</th>
				</tr>
			<?php
			$l_comm_count = 0;
			foreach($commentlist as $image_name => $value) {
				if($image_name != "_AlbumComment_") {
					$l_comm_count++;
					$nav_icon = nav_icons($selected_album, $image_name);

					?>
					<tr>
					<td>&nbsp;</td>
					<td class="adminComments" align="right"><?php print $image_name; ?></td>
					<td align="center"><img src="<?php print $nav_icon['src']; ?>" name="<?php print $image_name; ?>" <?php print $nav_icon['size']; ?> alt="<?php print $image_name; ?>"></td>
					<td class="adminComments" align="center"><?php print $commentlist[$image_name]['count']; ?></td>
					<td class="adminSelection" align="center"><input type="radio" name="admin_form[show_del]" value="<?php print $image_name; ?>"></td>
					<td>&nbsp;</td>
					</tr>
					<?php
				}
			} ?>
			<tr><td colspan="7">&nbsp;</td></tr>
			<tr><td colspan="7" align="center">
				<input type="hidden" name="Submit_Step_One" value="true">
				<input type="submit" name="submit" value="<?php print $lang_akt['submit']; ?>">
			</td>
			</tr>
			</form>
			<?php
		}
	}
	?>
</table>
</td>
</tr>
</table>
</form>
<?php



?>
Return current item: Yappa-ng