View file myprefs.php

File size: 2.46Kb
<?
#######################################################
#                раздача ICQ номерков                 #
#                                                     #
#             	 Автор  :  Неизвестен                 #
#                Автор модификации : Дальше...        #
#               E-mail  :  [email protected]             #
#                  ICQ  :  362548079                  #
#                                                     #
#   		По всем вопросам пишите в ICQ.            #
#######################################################


class MyPrefsList 
	{
	
	function PrefExists($name) 
		{
		if ($res=mysql_query("SELECT * FROM my_prefs WHERE `name`='".addslashes(strip_tags($name))."'"))
			{
			if (mysql_num_rows($res)>0) return true;
			else return false;
			}
		else return false;
		}
	
	function AddPref($name, $value) 
		{
		if (!$name) return false;
		if (mysql_query("INSERT INTO my_prefs (`name`,`value`) VALUES ('".addslashes(strip_tags($name))."','".serialize($value)."')")) return true;
		else return false;
		}
	
	function UpdatePref($name, $value) 
		{
		if (!$name) return false;
		if ($this->PrefExists($name)) 
			{
			if (mysql_query("UPDATE my_prefs SET `value`='".serialize($value)."' WHERE `name`='".addslashes(strip_tags($name))."'")) return true;
			else return false;
			}
		else return $this->AddPref($name,$value); 
		}
	
	function RenamePref($name,$newname) 
		{
		if (!$name||!$newname||!$this->PrefExists($name)) return false;
		if (mysql_query("UPDATE my_prefs SET `name`='".addslashes(strip_tags($newname))."' WHERE `name`='".addslashes(strip_tags($name))."'")) return true;
		else return false;
		}
	
	function DeletePref($name) 
		{
		if (!$name) return false;
		if ($res=mysql_query("DELETE FROM my_prefs WHERE `name`='".addslashes(strip_tags($name))."'")) return true;
		else return false;
		}
	
	function GetPref($name) 
		{
		if (!$name) return false;
		if ($res=mysql_query("SELECT `value` FROM my_prefs WHERE `name`='".addslashes(strip_tags($name))."'"))
			{
			if ($arr=mysql_fetch_array($res)) return unserialize($arr[0]);
			else return false;
			}
		else return false;
		}
	
	function PrintState() 
		{
		if ($res=mysql_query("SELECT `name`,`value` FROM my_prefs"))
			{
			echo "<b>MyPrefs state:</b><br>";
			while ($arr=mysql_fetch_array($res)) 
				{
				echo "\"".stripslashes($arr['name'])."\" has value: ".unserialize($arr['value'])."<br>";
				}
			}
		}
	
	}

?>