<?php

include_once "User.php";
include_once "config.php";

use \User as User;

class DB
{

    public $pdo;
    public $log;

    function __construct($log)
    {
        global $DB, $DB_USER, $DB_PASS;
        $this->log = $log;
        try {
            $this->pdo = new PDO($DB, $DB_USER, $DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") );
            if($log)
                $log->info("Connected to database $DB");
        } catch (PDOException $e) {
            echo $e->getMessage();
            if($log)
                $log->error($e->getMessage());
        }
    }

    function add_user(User $user)
    {
        $columns = $this->getColumnNames("person");
        foreach ((array) $user as $key => $value) {
            if (array_key_exists($key, (array) $columns)) {
                $a[$key] = $value;
            }
        }
        $a["participation_confirmed_at"] = date("Y-m-d H:i:s UTC");
        $keys = array_keys($a);
        $sql = "INSERT INTO person (" . implode(", ", $keys) . ") \n";
        $sql .= "VALUES ( :" . implode(", :", $keys) . ")";
        $q = $this->pdo->prepare($sql);
        $i = 1;
        foreach ($a as $value)
            $q->bindParam($i++, $value);
        $this->log->debug($sql);
        $res = $q->execute($a);
        $user->id = $this->pdo->lastInsertId();
        return $res;
    }

    function getColumnNames($table)
    {
        $sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :table";
        try {
            $stmt = $this->pdo->prepare($sql);
            $stmt->bindValue(':table', $table, PDO::PARAM_STR);
            $stmt->execute();
            $output = array();
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                $output[$row['COLUMN_NAME']] = $row['COLUMN_NAME'];
            }
            return $output;
        } catch (PDOException $pe) {
            trigger_error('Could not connect to MySQL database. ' . $pe->getMessage(), E_USER_ERROR);
        }
    }

    function updateInvoice($user) {
        $this->log->debug("updateInvoice");
        $sql = "UPDATE person SET invoice = :invoice WHERE id = :id;";
        $stmt = $this->pdo->prepare($sql);

        $stmt->bindParam(':invoice', $user->invoice, PDO::PARAM_LOB);
        $stmt->bindParam(':id', $user->id);

        return $stmt->execute();
    }

    function mail_count($email)
    {
        $sql = "SELECT COUNT(*) FROM person WHERE email = :email";
        try {
            $stmt = $this->pdo->prepare($sql);
            $stmt->bindValue(':email', $email, PDO::PARAM_STR);
            $stmt->execute();
            $row = $stmt->fetch(PDO::FETCH_ASSOC);
            return $row['COUNT(*)'];
        } catch (PDOException $pe) {
            trigger_error('Could not connect to MySQL database. ' . $pe->getMessage(), E_USER_ERROR);
        }
    }
}
