Location: PHPKode > projects > MtxEventManager > MtxEventManager-V2-beta1-source-italian/mtxeventmanager/class/search_class_00_em.php
<?php

/**
 * @Author				Tarchini Maurizio
 * @Version				2.0
 * @AuthorEmail			hide@address.com or hide@address.com
 * @AuthorSite			http://www.mtxweb.ch
 * @DocumentDate		20-1-2008
 * @DocumentLicense		PUBLIC -FREE
 * @LicenseDetail		GNU General Public License
 * @LicenseSite			http://www.gnu.org/licenses/gpl.txt
 * @PHPCompatibility	4.2 or later
 * @DevelopmentStatus	stable
 */




/**
 * Search
 *
 * @package lib
 * @author Tarchini Maurizio
 * @copyright 2008
 * @version 2.0
 * @access public
 */
 
class Search
{

	#parametri db
	var $host = "localhost";
	var $password = "password";
	var $user = "utente db";
	var $db = "nome db";
	///Non editare oltre questa riga
	
	#Parametri ricerca
	var $fulltext = "";
	var $table = "";
	#metodo score -> p in percentuale, f in frazione
	var $pf = "p";
	#FINE CONFIGURAZIONE
	var $key;
	var $conn;
	var $res;
	var $total;
	
		function Search($key)
		{
			$this->key = $key;
		}

		function DbConnectAndSelect()
		{
			$this->conn = @mysql_connect($this->host, $this->user, $this->password) or die ("Impossibile stabilire una connessione con il server.<br>MySql risponde: " . mysql_error() . "<br>Il codice errore é:" . mysql_errno());
			
			@mysql_select_db($this->db, $this->conn) or die ("Impossibile connettersi al database $this->db.<br>MySql risponde: " . mysql_error() . "<br>Il codice errore é:" . mysql_errno());
		}

		function GetResource()
		{
			$this->DbConnectAndSelect();
			$sql = "SELECT *, MATCH($this->fulltext) AGAINST('$this->key' IN BOOLEAN MODE) AS tot FROM $this->table WHERE MATCH($this->fulltext) AGAINST('$this->key' IN BOOLEAN MODE) ORDER BY tot DESC";
			$this->res = mysql_query($sql, $this->conn);
			
		}
		
		function CalcScore($tot)
		{
			switch($this->pf)
			{
				case "f":
				$key_array = explode(" ", $this->key);
				$this->total = count($key_array);
				return $tot . " / " . $this->total;
				break;
				case "p":
				$key_array = explode(" ", $this->key);
				$this->total = count($key_array);
				$output = intval($tot / $this->total * 100) . "%";
				return $output;
				break;
				default:
				$key_array = explode(" ", $this->key);
				$this->total = count($key_array);
				return $tot . " / " . $this->total;
				
			}
		}
		
}

#**********************************************************************
#Queste classi child sono create appositamente per questa apllicazione
#**********************************************************************

class SearchEvent extends Search
{
	var $table = "events";
	var $fulltext = "titolo,descrizione";
}

class SearchNews extends Search
{
	var $table = "news";
	var $fulltext = "contenuto";
}


?>
Return current item: MtxEventManager