<?php
include("header.php");
if(!$_GET['do'])
{
//If $do is empty we load the default page listing all photos
//We select all photo_id from the database and initialize photo objects...
$query = "SELECT photo_id FROM tblPhoto ORDER BY photo_id DESC";
$result = $db->doQuery($query);
while($row = $result->getArray())
{
$photo = new Photo($db, $row['photo_id']);
$photos[] = array('id' => $photo->getId(),
'thumbnail' => $photo->getThumbnail(),
'numComments' => $photo->getNumComments(),
'title' =>$photo->getTitle());
}
$template->assign('photos', $photos);
}
if($_GET['do'] == "add")
{
if($_POST['submit'])
{
if($file = add_img("../img/upload/"))
{
$title = $_POST['title'];
$description = $_POST['body'];
$query = "INSERT INTO tblPhoto (photo_title, photo_description, photo_filename)
VALUES('$title', '$description', '$file')";
if(!$result = $db->doQuery($query))
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
else
{
$confirm_message = "<p>" . $lang['add_success'] . "</p><p><a href=\"$PHP_SELF\">" . $lang['manage_photos'] . "</a></p>";
}
$photo = new Photo($db, $result->getID());
$photo->setThumbnail();
}
else
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
//Send to the template
$template->assign('confirm_message', $confirm_message);
}
else
{
//Lets display the available smilies
$query = "SELECT * FROM tblSmilie";
$result = $db->doQuery($query);
while($row = $result->getarray())
{
$smilie = new Smilie($db, $row['smilie_id']);
$smilies[] = array('file' => $smilie->getFile(),
'code' => $smilie->getCode());
}
$template->assign('smilies', $smilies);
}
}
if($_GET['do'] == "edit")
{
if($_POST['submit'])
{
$photo = new Photo($db, $_POST['id']);
$photo->setTitle($_POST['title']);
$photo->setDescription($_POST['body']);
if(!$photo->edit())
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
else
{
$confirm_message = "<p>" . $lang['edit_success'] . "</p><p><a href=\"$PHP_SELF\">" . $lang['manage_photos'] . "</a></p>"; }
$template->assign('confirm_message', $confirm_message);
}
else
{
//Lets read the photo first
$photo = new Photo($db, $_GET['id']);
//Now lets create a proper array before sending this to the template...
$photo_arr = array('title' => $photo->getTitle(),
'description' => $photo->getDescription());
//Now we assign it to the template
$template->assign('photo', $photo_arr);
//Lets display the available smilies
$query = "SELECT * FROM tblSmilie";
$result = $db->doQuery($query);
while($row = $result->getarray())
{
$smilie = new Smilie($db, $row['smilie_id']);
$smilies[] = array('file' => $smilie->getFile(),
'code' => $smilie->getCode());
}
$template->assign('smilies', $smilies);
}
}
if($_GET['do'] == "delete")
{
//This is the delete routine
//Delete the photo from the table and display confirmation
$photo = new Photo($db, $_GET['id']);
if(!$photo->delete())
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
else
{
$confirm_message = "<p>" . $lang['delete_success'] . "</p><p><a href=\"$PHP_SELF\">" . $lang['manage_photos'] . "</a></p>";
}
//Send to the template
$template->assign('confirm_message', $confirm_message);
}
//Lets display the template
$template->display($config['theme'].'/admin/photo.tpl');
include("footer.php");
?>