Location: PHPKode > projects > COWeb (Common Objects for Web) > coweb-0.4.1/include/links.inc.php
<?

// Module de gestion des liens
// Ecrit par Sébastien DIAZ
// Distribue sous license GPL
// Validé pour Mysql le 26/02/2003

include "coweb.inc.php";

if (! defined("LINKS"))
{
	define("LINKS",1);

	class links
	{
		var $id;		// id du lien
		var $label;		// libelle du lien
		var $url;		// url du lien
		var $description;	// description du lien
		var $table;		// table ou se trouve les liens
		var $flag;		// flag d'activation
		var $follow;		// flag lien suiveur
		var $param;		// parametre du suiveur

	function links($id, $table)	// Constructeur
	{
		if (isset($id))
		{
			$dbl=new db(server, port, database, login, password, type);
			$dbl->Connect();
			$dbl->query("	SELECT id, label, url, description, flag, follow, param
					FROM $table
					WHERE id=$id"
					);
			$dbl->fetch();
			$this->id=stripslashes($dbl->row["id"]);
			$this->label=stripslashes($dbl->row["label"]);
			$this->url=stripslashes($dbl->row["url"]);
			$this->description=stripslashes($dbl->row["description"]);
			$this->follow=stripslashes($dbl->row["follow"]);
			$this->param=stripslashes($dbl->row["param"]);
			$this->flag=stripslashes($dbl->row["flag"]);
		}
		else
		{
			$this->id="";
			$this->label="";
			$this->url="";
			$this->description="";
			$this->follow="";
			$this->param="";
			$this->flag="1";
		}
		if ($this->follow==1 and $this->param[0] != "#")
			$this->url=WebRoot."index.php?".$this->param."=".$this->id.ParseParam($this->param);
		else if ($this->follow==1 and $this->param[0] == "#")
		{
			$this->param=ereg_replace("#", "", $this->param);
			$this->url=WebRoot."index.php?".$this->param."=".$this->id;
		};
		$this->table=$table;
	}

	function Show($template)
	// Affichage
	{
		echo $this->Parse($template);
	}

	function Parse($template)
	// Parse mais n'affiche pas
	{
		eval(parse($template));
		return $template;
	}

	function Generate()
	// Creation d'une table de liens
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$sql="	CREATE TABLE $this->table
			(
			id int(11) NOT NULL auto_increment,
			label varchar(64) default NULL,
			url tinytext,
			description tinytext,
			flag char(1) NOT NULL default '1',
			follow tinyint(4) NOT NULL default '0',
			param varchar(16) NOT NULL default '',
			UNIQUE KEY id (id)
			)";
		$dbl->Query($sql);
	}

	function Ungenerate()
	// Suppression d'une table de liens
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$dbl->query("	DROP TABLE IF EXISTS $this->table
			");
		$dbl->fetch();
	}

	function Add()
	// Insertion d'un nouvel Item
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$this->label=addslashes($this->label);
		$this->url=addslashes($this->url);
		$this->description=addslashes($this->description);
		$dbl->Query("	INSERT $this->table
				VALUES ('', '$this->label', '$this->url', '$this->description', '1', '$this->follow', '$this->param')
			");
		$this->id=mysql_insert_id($dbl->id);
	}

	function Delete()
	// Supression d'un Item
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$dbl->Query("	DELETE FROM $this->table
				WHERE id=$this->id
				");
		$dbl->fetch();
	}

	function Update()
	// Modification d'un Item
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$this->label=addslashes($this->label);
		$this->url=addslashes($this->url);
		$this->description=addslashes($this->description);
		$dbl->Query("	UPDATE $this->table
				SET label='$this->label',
				url='$this->url',
				description='$this->description',
				flag='$this->flag',
				follow='$this->follow',
				param='$this->param'
				WHERE id=$this->id
				");
		$dbl->Fetch();
	}

	}
}

?>
Return current item: COWeb (Common Objects for Web)