<?php

/**
 * Created by Sevio®.
 * All rights reserved to Sevio Solutions® SRL
 */
class class_config
{
    protected $term, $value;
    public function class_config()
    {
        $this->term=array();
        $this->value=array();
        $sql = mysql_query("SELECT `term`,`value` FROM `app_config`");
        while($data = mysql_fetch_array($sql))
        {
            array_push($this->term,$data['term']);
            array_push($this->value,$data['value']);
        }
    }
    static public function add($term, $value)
    {
        $sql = mysql_query("INSERT INTO `app_config` (`term`,`value`) VALUES ('" . $term . "','" . $value . "')");
    }
    public function get_value($term)
    {
        $sql = mysql_query("SELECT * FROM `app_config` WHERE `term`='".$term."'");
        $data=mysql_fetch_array($sql);
            return $data['value'];
    }
    public function set_value($term,$value)
    {
        $sql = mysql_query("UPDATE `app_config` SET `value`='" . $value . "' WHERE `term`='" . $term . "'");
    }
    public function del($term)
    {
        mysql_query("DELETE FROM `app_config` WHERE `term`='" . $term . "' ");
    }
	 public function switcher($term)
    {
		$value = $this->get_value($term);
        if($value==0)
            $sql = mysql_query("UPDATE `app_config` SET `value`='1' WHERE `term`='" . $term . "'");
        if($value == 1)
         $sql = mysql_query("UPDATE `app_config` SET `value`='0' WHERE `term`='" . $term . "'");
    }
	public function single_ad()
	{
		$sql = mysql_query("SELECT `term`, COALESCE(SUM(`value`),0) as  `all` FROM `app_config` WHERE `term` LIKE '%ad_%' AND `value` = '1'");
        $data=mysql_fetch_array($sql);
		if($data[all] == 1)
		return str_replace('ad_','',$data[term]);
		else
		return 0;
	}
}
?>