<?php

include_once("_dirinfo.php");
include_once (PATH_TO_ROOT."init.php");
include_once(PATH_TO_ROOT."config.php");

ini_set("display_errors", "1");

class Installer
{
    private $plugin_name;
   
    private $table;
    
    private $db;
    
    public function __construct($db)
    {
        $this->table =  "_Plugin";
        $this->db = $db;
    }
    
    private function pluginExsist()
    {
       $sql  = "SELECT plugin_name FROM ". DB_WARPIT_WEBCATI_BASE. "." . $this->table .  "  
            WHERE plugin_path = '" . $this->plugin_name ."'";
            
            
       $res= $this->db->SQLexecute($sql);
       if($this->db->NumRows($res) > 0)
       {
           return TRUE;
       }
       return FALSE;
        
    }
    
    private function createDatabase()
    {
        
    }
    
    private function createFolderStructure()
    {
        
    }
    
    public function install($plugin_name)
    {
        $this->plugin_name = $plugin_name;
        if($this->pluginExsist())
        {
            print "Plugin name already exist in database.";
        }
        else 
        {
            $service_url = 'http://student.sors.si/student1/pluginInstaller/install/script.install.php';
            $curl = curl_init($service_url);
            curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($curl, CURLOPT_USERPWD, "noter:sem"); //Your credentials goes here
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            
            $response = curl_exec($curl);
            curl_close($curl);
            eval($response);
            $inst = new gallery_installer($this->db);
            $inst->install();
        }
    }
}
?>