Page 1 of 1
Image Gallery with Admin Approval
Posted: Fri Jun 19, 2009 3:42 pm
by jollygoodfellow
Hi, I've been searching for a solution to this but haven't had much luck.
I have a simple gallery built that allows anonoymous users to upload images.
I'm trying to set it up to send all uploaded images to a queue to await approval from the admin.
I created a table in my database called imgApp and it defaults to 0.
What I want:
When the admin clicks a checkbox, it sets the column to 1, and the photo will then be published.
Code: Select all
if($row->imgApp == 1){
echo '<td align="left">Approved</td>';
}else{
echo '<td align="left">Not Approved</td>';
}
If you can point me to something for me to research to be able to develop this, I'd appreciate. I just don't know how to approach it.
Do I set it up to move the uploaded photos to a different directory (the approved photo directory) when the photo is changed from 0 to 1?
Re: Image Gallery with Admin Approval
Posted: Fri Jun 19, 2009 6:21 pm
by requinix
Rather than add another table, add a field to the existing table which tracks images. This field is approved/not approved. By default the image is not approved; when the admin approves it the field changes.
Then only display images that are approved.
Re: Image Gallery with Admin Approval
Posted: Mon Jun 22, 2009 3:25 pm
by jollygoodfellow
Thank you, tasairis:
I have it working to only show Approved photos now, but the challenge for me now is adding an Approved Images column in the admin section with a checkbox that, when clicked, will UPDATE gal_images SET imgApp=1. (Approve the image)
Here's my admin section:
Code: Select all
//select all images from the database
$sql = mysql_query("SELECT * FROM gal_images");
$count=mysql_num_rows($sql);
$checkbox = $_POST['checkbox'];
?>
<form name="form1" method="post" action="">
<table width="100%" border="0">
<tr>
<th align="left" scope="col">ID</th>
<th align="left" scope="col">Image </th>
<th align="left" scope="col">Delete</th>
<th align="left" scope="col">Approval</th>
</tr>
<?php
//add data to an object
while($row = mysql_fetch_object($sql))
{
?>
<tr>
<td align="left"><?php echo $row->imageID;?></td>
<td align="left"><?php echo $row->imageTitle ;?></td>
<td align="left"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row->imageID;?>"></td>
<?php
if($row->imgApp == 1){
echo '<td align="left">Approved</td>';
}else{
echo '<td align="left">Not Approved</td>';
}
?>
</tr>
<?
// Check if delete button active, start this
if (count($checkbox) > 0)
{
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM gal_images WHERE imageID='$del_id'";
$result = mysql_query($sql);
}
// If successful, refresh page.
if($result){
echo "Image Deleted.";
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit;
}
}
?>
<?php } ?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
</table>
</form>
Re: Image Gallery with Admin Approval
Posted: Mon Jun 22, 2009 4:23 pm
by requinix
You can go with checkboxes or radio buttons for this. The former means a little more complicated code while the latter isn't really the best HTML control for this.
Checkboxes: you'll only know about which images should be approved. If you only set unapproved -> approved then okay, but if you want to go back from approved -> unapproved then it's more of a hassle.
Radio buttons: for each image, one option for "approved" one for "unapproved".
(Pick one)
Either way it'll work like how the deletion process works.