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

include("header.php");

if(!$_GET['do'])
{
  //If $do is empty we load the default page listing all censor words

  //We select all article_id from the database and initialize censor objects...
  $query = "SELECT censor_id FROM tblCensor ORDER BY censor_word";

  $result = $db->doQuery($query);

  while($row = $result->getArray())
    {
      $censor = new Censor($db, $row['censor_id']);
      $censors[] = array('id' => $censor->getId(),
			 'replace' => $censor->getReplace(),
			 'word' =>$censor->getWord());
    }
      
  $template->assign('censors', $censors);
    
}



if($_GET['do'] == "add")
{
  if($_POST['submit'])
    {
      $word = $_POST['word'];
      $replace = $_POST['replace'];

      $query = "INSERT INTO tblCensor (censor_word, censor_replace)
                    VALUES('$word', '$replace')";

      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_censors'] . "</a></p>";
	}

      //Send to the template
      $template->assign('confirm_message', $confirm_message);
    }
  else
    {
      //Seems like there is nothing to do here...
    }
}


if($_GET['do'] == "edit")
{
  if($_POST['submit'])
    {
      $censor = new Censor($db, $_POST['id']);
      $censor->setWord($_POST['word']);
      $censor->setReplace($_POST['replace']);

      if(!$censor->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_censors'] . "</a></p>";
	}

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

      //Lets read the censor first
      $censor = new Censor($db, $_GET['id']);

      //Now lets create a proper array before sending this to the template...
      $censor_arr = array('word' => $censor->getWord(),
			  'replace' => $censor->getReplace());

      //Now we assign it to the template
      $template->assign('censor', $censor_arr);

    }
}

if($_GET['do'] == "delete")
{
  //This is the delete routine
  //Delete the censor from the table and display confirmation
  $censor = new Censor($db, $_GET['id']);
  if(!$censor->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_censors'] . "</a></p>";
    }

  //Send to the template
  $template->assign('confirm_message', $confirm_message);

} 



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


include("footer.php");

?>
Return current item: Jarida