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

include("header.php");

if(!$_GET['do'])
{
  //If $do is empty we load the default page listing all web links
  
  //We select all link_id from the database and initialize link objects...
  $query = "SELECT link_id FROM tblLink ORDER BY link_id DESC";

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

  while($row = $result->getArray())
    {
      $link = new Link($db, $row['link_id']);
      $links[] = array('id' => $link->getId(),
			 'name' => $link->getName(),
			 'url' => $link->getUrl(),
			 'visits' =>$link->getVisits());
    }
      
  $template->assign('links', $links);
    
}



if($_GET['do'] == "add")
{
  if($_POST['submit'])
    {
      $name = $_POST['name'];
      $url = $_POST['url'];
      $visits = 0;

      $query = "INSERT INTO tblLink (link_name, link_url, link_visits)
                    VALUES('$name', '$url', '$visits')";

      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_links'] . "</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'])
    {
      $link = new Link($db, $_POST['id']);
      $link->setName($_POST['name']);
      $link->setUrl($_POST['url']);

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

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

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

      //Now lets create a proper array before sending this to the template...
      $link_arr = array('name' => $link->getName(),
			  'url' => $link->getUrl());

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

    }
}

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

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

} 



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


include("footer.php");

?>
Return current item: Jarida