<?php 

class MojPlugin2
{
    private $table = "_plugin_multiresponse_with_text";
    
    private $database = DB_WARPIT_WEBCATI_BASE;
    
    private $data;
    
    private $db;
    
    public function __construct($db)
    {
        $this->db = $db;
    }
    
    public function load($idProject, $idQuestion)
    {
        $sql = "SELECT * FROM " . $this->database . "." . $this->table . "
            WHERE id_question = " . $idQuestion . " AND id_project = " . $idProject . " AND deleted = 0";
         $res= $this->db->SQLexecute($sql);
         $this->data = $this->db->fetchAssoc($res);
    }
    
    public function getImage()
    {
        return $this->data['image'];
    }
    
    public function getButtonBackgroundNormal()
    {
        if($this->data['button_image_normal'] != '')
            return '"background-image": "url(' . $this->data['button_image_normal'] . ')",';
        else 
            return '"background-color":"' . $this->data['button_color_normal'] .'",';
    }
    
    public function getButtonBackgroundSelected()
    {
        if($this->data['button_image_normal'] != '')
            return 'background-image:url(' . $this->data['button_image_normal'] . ');';
        else
            return 'background-color:'. $this->data['button_color_normal'] . ' ;'; 
    }
    
    
    public function getButtonSize()
    {
        if($this->data['button_width'] != '0' && $this->data['button_height'] != '0')
            return '"width" : "' . $this->data['button_width'] . '", "height" : "' . $this->data['button_height'] . '",';
        else 
            return '';
    }
    
    public function getAnswerBoxSize()
    {
        //defaul values
        $width = 230;
        $height = 50;
        
        if($this->data['answer_box_width'] != 0)
        {
            $width = $this->data['answer_box_width'];
        }
        if($this->data['answer_box_height'] != 0)
        {
            $height  = $this->data['answer_box_height'];
        }
        
        return 'width :' . $width . "px; height : " . $height . "px;";
    }

    public function getSelectedImage()
    {
        return '"background-image": "url(' . $this->data['button_image_clicked'] . ')"';
    }
    
    public function getSelectedImageCss()
    {
        return 'background-image: url(' . $this->data['button_image_clicked'] . ');';
    }
    
}

?>