<?php
class Mtips extends Model
{
	var $existing_lang = array('hun', 'eng', 'jap');
	
	var $tips_dir = 'public/support/tips/';
	var $tips_src = false;
	var $settings = false;
	
	function Mtips()
	{
		parent::Model();
		
		$this->tips_src = $this->config->item('base_url').$this->tips_dir;
	}
	
	function read_settings($lang)
	{
		$this->settings = @$this->read_xml($this->tips_dir.$lang.'/xml/settings.xml');
		return $this->settings;
	}
		
	function lang_check($lang)
	{
		if(!in_array($lang,$this->existing_lang))
		{
			return 'eng';
		}
		else
		{
			return $lang;
		}
	}
	
	
	function can_edit($lang,$user,$pass)
	{
		$xml = $this->read_xml('data/tipeditors.xml');
		
		foreach($xml->editor as $editor)
		{
			if($editor->user == $user)
			{
				if($editor->password == $pass || $editor->password == md5($pass))
				{
					
					foreach($editor->languages->children() as $language)
					{
						if($language == $lang)
						{
							return true;
						}
					}
				}
			}
		}
	
		return false;
	}
		
	function iterate_version($lang)
	{
		$settings = $this->read_settings($lang);
		
		if(!$settings)
		{
			return false;
		}
		
		$settings->version = $settings->version+1;
		$settings->asXML($this->tips_dir.$lang.'/xml/settings.xml');
		
		return true;
		
	}
			

	function read_xml($filename)
	{
		return simplexml_load_file($filename,'SimpleXMLElement',LIBXML_NOCDATA);
	}
	
	
	
	
}
?>