<?php 

    function checkAdmin($nik)
	{
        static $admins;
		
		if(empty($admins))
		{
			$res = mysql_query("SELECT * FROM `table_admin`"
								  );
			while($row = mysql_fetch_assoc($res))
			    $admins[] = $row['nick'];
				
        }									  
			return  in_array($nik, $admins);	
			  			
    }


    function checkModer($nik)
	{
        static $moders;
		
		if(empty($admins))
		{
			$res = mysql_query("SELECT * FROM `table_moder`"
								  );
			while($row = mysql_fetch_assoc($res))
			    $moders[] = $row['nick'];
				
        }									  
			return  in_array($nik, $moders);
    }


    function chengUserData($log, $data)
	{
        $text  = @file_get_contents("MySql/base123/reg/$log.dat");
		$udata = explode(":||:", $text);
		 
		for($i = 0; $i < 100; ++$i)
		    if(!empty($data[$i]))
			    $udata[$i] = $data[$i];		
        
		$text  = implode(":||:", $udata); 
		@unlink($log);
//		$log   = iconv('utf-8', 'windows-1251', $log); 
		file_put_contents("MySql/base123/reg/$log.dat", $text);	
	}
	
    function setSmile($msg)
	{
         $smile = array(
                       "%)"    =>     "<img src=\"pic/smiles/cvety.gif\" alt=\"%)\"/>",
                       ":#"    =>     "<img src=\"pic/smiles/mad.gif\" alt=\":#\"/>", 
                       ";)"    =>     "<img src=\"pic/smiles/girl11.gif\" alt=\";)\"/>", 
                       "8D"    =>     "<img src=\"pic/smiles/girl5.gif\" alt=\"8D\"/>", 
                       "0:-)"  =>     "<img src=\"pic/smiles/aa.gif\" alt=\"0:-)\"/>", 
                       ":-)"   =>     "<img src=\"pic/smiles/ab.gif\" alt=\":-)\"/>", 
                       ":-("   =>     "<img src=\"pic/smiles/ac.gif\" alt=\":-(\"/>", 
                       ";-)"   =>     "<img src=\"pic/smiles/ad.gif\" alt=\";-)\"/>", 
                       "8-)"   =>     "<img src=\"pic/smiles/af.gif\" alt=\"8-)\"/>", 
                       ":-["   =>     "<img src=\"pic/smiles/ah.gif\" alt=\":-[\"/>", 
                       "=-0"   =>     "<img src=\"pic/smiles/ai.gif\" alt=\"=-0\"/>", 
                       ":-*"   =>     "<img src=\"pic/smiles/aj.gif\" alt=\":-*\"/>", 
                       ":'("   =>     "<img src=\"pic/smiles/ak.gif\" alt=\":'(\"/>", 
                       ":-|"   =>     "<img src=\"pic/smiles/an.gif\" alt=\":-|\"/>", 
                       ":-\\"  =>     "<img src=\"pic/smiles/ao.gif\" alt=\":-\\\"/>", 
                       "]:-}"  =>     "<img src=\"pic/smiles/ar.gif\" alt=\"]:-}\"/>", 
                       ":-!"   =>     "<img src=\"pic/smiles/at.gif\" alt=\":-!\"/>", 
                       "@="    =>     "<img src=\"pic/smiles/bb.gif\" alt=\"@=\"/>", 
                       "%)"    =>     "<img src=\"pic/smiles/be.gif\" alt=\"%)\"/>", 	 
		               );
					   
		return str_replace(array_keys($smile), array_values($smile), $msg);			   
	}	
		
	
    function formatDate($date = '', $format = true)  
    {  

        if(empty($date))
		    $date = date('Y-m-d H:i:s');
		$month = array( 
						'01' => 'января', 
						'02' => 'февраля', 
						'03' => 'марта', 
						'04' => 'апреля', 
						'05' => 'мая', 
						'06' => 'июня', 
						'07' => 'июля', 
						'08' => 'августа', 
						'09' => 'сентября', 
						'10' => 'октября', 
						'11' => 'ноября', 
						'12' => 'декабря' 
					  );

        $day  = substr($date, 8, 2);          
        $mnt  = $month[substr($date, 5, 2)];         
        $year = substr($date, 0, 4);  
        $time = ''; 
         
        if($format)          
            $time = ' '. substr($date, 11);  

        return $day .' '. $mnt .' '. $year . $time;  
    }	
	
	
    function insertInto($path, $data)
	{
		return @file_put_contents("MySql/base123/$path.dat", "$data\r\n", FILE_APPEND);
	}	
	
    function deleteData($path)
	{
		return @unlink("MySql/base123/$path.dat");
	}		
	
    function selectData($path)
	{
        $text = file_get_contents("MySql/base123/$path.dat");		
		return explode(":||:", $text);
	}		
	
	
	
	