<?php

/**
 * Created by Sevio®.
 * * All rights reserved to Sevio Solutions® SRL
 */
class class_tags
{
    protected $unique, $unique_user, $unique_admin, $name, $website, $tag_type, $ad_type, $valid, $date,$tag_cost;
    public function class_tags($unique)
    {
        $sql = mysql_query("SELECT * FROM `app_tags` WHERE `unique`='" . $unique . "'");
        $data = mysql_fetch_array($sql);
        if ($data) {
            $this->unique=$data['unique'];
            $this->unique_user = $data['unique_user'];
            $this->unique_admin = $data['unique_admin'];
            $this->name = $data['name'];
            $this->website = $data['website'];
            $this->tag_type = $data['tag_type'];
            $this->ad_type = $data['ad_type'];
			$this->tag_cost = $data['tag_cost'];
            $this->valid = $data['valid'];
            $this->date = $data['date'];
        }
    }
    static public function add($unique_user, $name, $website, $tag_type, $ad_type, $tag_cost)
    {
        $key = rand(1,999).uniqid().rand(1,999);
        $sql = mysql_query("INSERT INTO `app_tags` (`unique`,`unique_user`,`unique_admin`,`name`,`website`,`tag_type`,`ad_type`,`valid`,`date`,`tag_cost`) VALUES ('" . $key . "','" . $unique_user . "','','" . $name . "','" . $website . "','" . $tag_type . "','" . $ad_type . "','1','" . date('Y-m-d')."','".$tag_cost."')");
    }
    public function get_unique()
	{
    return $this->unique;
	}
	public function get_user_email()
    {
		$sql = mysql_query("SELECT `email` FROM `app_users` WHERE `unique`='" . $this->unique_user . "'");
        $data = mysql_fetch_array($sql);
        return $data[email];
    }
    public function get_unique_user()
    {
        return $this->unique_user;
    }
	public function get_tag_cost()
    {
        return $this->tag_cost;
    }
    public function get_unique_admin()
    {
        return $this->unique_admin;
    }
    public function get_name()
    {
        return $this->name;
    }
    public function get_website()
    {
        return $this->website;
    }
    public function get_tag_type()
    {
        return $this->tag_type;
    }
    public function get_ad_type()
    {
        return $this->ad_type;
    }
    public function get_valid()
    {
        return $this->valid;
    }
	public function get_status()
    {
        if($this->valid==0)
            return "pending";
        elseif($this->valid==1)
            return "valid";
        elseif($this->valid==2)
            return "hold";
        elseif($this->valid==3)
            return "deny";
    }
    public function get_date()
    {
        return $this->date;
    }
    public function set_unique_user($value)
    {
        $this->unique_user = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `unique_user`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function set_unique_admin($value)
    {
        $this->unique_admin = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `unique_admin`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function set_name($value)
    {
        $this->name = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `name`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function set_website($value)
    {
        $this->website = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `website`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function set_tag_type($value)
    {
        $this->tag_type = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `tag_type`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function set_ad_type($value)
    {
        $this->ad_type = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `ad_type`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function set_tag_cost($value)
    {
        $this->tag_cost = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `tag_cost`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function set_valid($value,$unique_admin)
    {
        $this->valid = $value;
        $this->unique_admin=$unique_admin;
        $sql = mysql_query("UPDATE `app_tags` SET `valid`='" . $value . "',`unique_admin`='".$unique_admin."' WHERE `unique`='" . $this->unique . "'");
        $mail=new module_mail();
        if($value==3)
            $mail->send_email($this->unique_user,"Your tag ".$this->name." has been denied!","Status updated on '".$this->name."' ","mail_notification_admin");
        elseif($value==1)
            $mail->send_email($this->unique_user,"Your tag ".$this->name." has been approved!","Status updated on '".$this->name."' ","mail_notification_admin");
    }
    public function hold()
    {
        if($this->valid==2)
            $sql = mysql_query("UPDATE `app_tags` SET `valid`='1' WHERE `unique`='" . $this->unique . "'");
        elseif($this->valid==1)
            $sql = mysql_query("UPDATE `app_tags` SET `valid`='2' WHERE `unique`='" . $this->unique . "'");
        else return 0;
    }
    public function set_date($value)
    {
        $this->date = $value;
        $sql = mysql_query("UPDATE `app_tags` SET `date`='" . $value . "' WHERE `unique`='" . $this->unique . "'");
    }
    public function del()
    {
        mysql_query("DELETE FROM `app_tags` WHERE `unique`='" . $this->unique . "' ");
    }
}

?>