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

// Module de gestion des listes d'objets
// Ecrit par Sébastien DIAZ
// Distribue sous license GPL

include "coweb.inc.php";

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

	class lists extends images
	{
		var $root;			// id de l'objet mere
		var $obj;			// objet
		var $table;			// table de la liste d'objets
		var $tableobj;			// table ou se trouvent les objets
		var $result;
		var $nbr;			// Nombre d'items
		var $order;			// Ordre dans la liste
		var $template;			// Template de l'objet
		var $type;			// Type de l'objet

	function lists($id, $table)
	// Constructeur
	{
		if (isset($id))
		{
			$dbl=new db(server, port, database, login, password, type);
			$dbl->Connect();
			$dbl->query("	SELECT id2, ord, template, type, tableobj
					FROM $table
					WHERE id1=$id
					ORDER BY ord
					");
			$this->result=$dbl->result;
			$this->root=$id;
			$this->nbr=$dbl->NbrRows();
		}
		$this->table=$table;
	}

	function Next()
	// Objet Suivant
	{
		$row=mysql_fetch_array($this->result);
		if ($row)
		{
		 	$ido=stripslashes($row["id2"]);
		 	$this->ordr=stripslashes($row["ord"]);
		 	$this->template=stripslashes($row["template"]);
		 	$this->tableobj=stripslashes($row["tableobj"]);
		 	$this->type=stripslashes($row["type"]);
			switch ($this->type)
			{
				case "L":
				{
					$this->obj=new links($ido, $this->tableobj);
					break;
				}
				case "I":
				{
					$this->obj=new images($ido, $this->tableobj);
					break;
				}
				case "B":
				{
					$this->obj=new buttons($ido, $this->tableobj);
					break;
				}
				case "N":
				{
					$this->obj=new news($ido, $this->tableobj);
					break;
				}
			}
			return TRUE;
		}
		else return FALSE;
	}

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

	function Parse($template)
	{
		if (!$this->nbr == 0)
		{
			eval(parse($template));
			while ($this->Next())
			{
				if ($this->obj->flag!=0)
				{
					$t=$t.$this->obj->parse($this->template);
				}
			}
		$template=ereg_replace("\{obj\}",$t, $template);
		return $template;
		}
		else return null;
		
	}

	function Add($obj)
	// Ajout d'un objet dans la liste
	{
		$this->nombre=$this->nombre+1;
		$dbl=new db(server, port, database, login, password, type);
		$dbl->connect();
		$this->nbr=$this->nbr+1;
		$dbl->query("	INSERT $this->table
				VALUES ('$this->root', '$obj->id', '$this->nbr', 'default.html', '$this->type', '$this->tableobj')
				");
		$dbl->fetch();
	}

	function Update()
	// Modifie un objet dans la liste
	{
		$dbl=new db;
		$dbl->connect();
		$l=$this->obj;
		$sql="
			UPDATE $this->table
			SET id1='$this->root',
			id2='$l->id',
			ord='$this->ordr',
			template='$this->template'
			WHERE id1='$this->root'
			AND id2='$l->id'
			";
		$dbl->query($sql);
		$dbl->fetch();
	}

	function Delete($id)
	// Suppression d'un objet dans la liste
	{
		$l = new lists($this->root, $this->table, $this->tableobj);
		while (($l->suivant()) and ($l->obj->id != $id)) {};
		$dbl=new db;
		$dbl->connect();
		$dbl->query("	DELETE FROM $this->table
				WHERE id1=$this->root
				AND id2=$id
				");
		$dbl->fetch();
		$dbl->close();
		$dbl->connect();
		$dbl->query("	UPDATE $this->table
				SET ord=ord-1
				WHERE id1=$this->root
				and ord>$l->ordr
				");
		$dbl->fetch();
	}

	function Up($id)
	// Remonte un objet dans la liste
	{
		$l = new listelien($this->root, $this->table, $this->tableobj);
		while (($l->suivant()) and ($l->obj->id != $id)) {};
		if ($l->ordr != 1)
		{
			$dbl=new db;
			$dbl->connect();
			$dbl->query(" 	UPDATE $this->table
					SET ord=ord+1
					WHERE id1=$this->root
					and ord=$l->ordr-1
					");
			$dbl->fetch();
			$dbl->close();
			$dbl=new db;
			$dbl->connect();
			$dbl->query(" 	UPDATE $this->table
					SET ord=ord-1
					WHERE id1=$this->root
					and id2=$id
					and ord=$l->ordr
					");
			$dbl->fetch();
		}
	}

	function Down($id)
	// Descend un objet dans la liste
	{
		$l = new listelien($this->root, $this->table, $this->tableobj);
		while (($l->suivant()) and ($l->obj->id != $id)) {};
		$dbl=new db;
		$dbl->connect();
		$dbl->query(" 	UPDATE $this->table
				SET ord=ord-1
				WHERE id1=$this->root
				and ord=$l->ordr+1
				");
		$dbl->fetch();
		$dbl->close();
		$dbl=new db;
		$dbl->connect();
		$dbl->query(" 	UPDATE $this->table
				SET ord=ord+1
				WHERE id1=$this->root
				and id2=$id
				and ord=$l->ordr
				");
		$dbl->fetch();
	}

	function Generate()
	// Creaion d'une table de lists
	{
		$dbl=new db(server, port, database, login, password, type);
		$dbl->Connect();
		$dbl->Query( "	CREATE TABLE $this->table (
  				id1 int(11) NOT NULL default '0',
  				id2 int(11) NOT NULL default '0',
  				ord tinyint(4) NOT NULL default '0',
  				template tinytext,
  				type char(1) NOT NULL default '',
  				tableobj varchar(32) NOT NULL default ''
				)
				");
	}
	
	}


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