Location: PHPKode > projects > Jarida > jarida_1.0/admin/comment.php
<?php

include("header.php");

if($_GET['article'])
{
  $type = "article";
  $article_id = $_GET['article'];
  $type_link = $type . "=" . $article_id;
  $query = "SELECT comment_id FROM tblArticleComment WHERE comment_article_id = $article_id ORDER BY comment_id DESC";
}
elseif($_GET['photo'])
{
  $type = "photo";
  $photo_id = $_GET['photo'];
  $type_link = $type . "=" . $photo_id;
  $query = "SELECT comment_id FROM tblPhotoComment WHERE comment_photo_id = $photo_id ORDER BY comment_id DESC";
}


if(!$_GET['do'])
{
  //If $do is empty we load the default page listing all comments for this article or photo.

  //We select all comment_id from the database and initialize comment objects...
  $result = $db->doQuery($query);

  while($row = $result->getArray())
    {
      if($type == "article")
	{
	  $comment = new ArticleComment($db, $row['comment_id']);
	}
      elseif($type == "photo")
	{
	  $comment = new PhotoComment($db, $row['comment_id']);
	}      

      $comments[] = array('id' => $comment->getId(),
			  'name' => $comment->getName(),
			  'type_link' => $type_link,
			  'ip' => $comment->getIp(),
			  'title' =>$comment->getTitle());
    }
      
  $template->assign('comments', $comments);
    
}




if($_GET['do'] == "edit")
{
  if($_POST['submit'])
    {
      if($type == "article")
	{
	  $comment = new ArticleComment($db, $_POST['id']);
	}
      elseif($type == "photo")
	{
	  $comment = new PhotoComment($db, $_POST['id']);
	}      

      $comment->setName($_POST['name']);     
      $comment->setWeb($_POST['web']);     
      $comment->setTitle($_POST['title']);     
      $comment->setBody($_POST['body']);

      if(!$comment->edit())
	{
	  $confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
	}
      else
	{
	  $confirm_message = "<p>" . $lang['edit_success'] . "</p>";
	}

      $template->assign('confirm_message', $confirm_message);
    }
  else
    {

      //Lets read the comment first
      if($type == "article")
	{
	  $comment = new ArticleComment($db, $_GET['id']);
	}
      elseif($type == "photo")
	{
	  $comment = new PhotoComment($db, $_GET['id']);
	}      

      //Now lets create a proper array before sending this to the template...
      $comment_arr = array('title' => $comment->getTitle(),		
			   'name' => $comment->getName(),
			   'web' => $comment->getWeb(),
			   'type_link' => $type_link,
			   'body' => $comment->getBody());

      //Now we assign it to the template
      $template->assign('comment', $comment_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 comment from the table and display confirmation
  if($type == "article")
    {
      $comment = new ArticleComment($db, $_GET['id']);
    }
  elseif($type == "photo")
    {
      $comment = new PhotoComment($db, $_GET['id']);
    }      
  if(!$comment->delete())
    {
      $confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
    }
  else
    {
      $confirm_message = "<p>" . $lang['delete_success'] . "</p>";
    }

  $template->assign('confirm_message', $confirm_message);
} 



//Lets display the template
$template->display($config['theme'].'/admin/comment.tpl');


include("footer.php");

?>
Return current item: Jarida