<?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;
            }
        }
        if ($user->participation_confirmed) {
            $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();
            $persons = array();
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                $persons[$row['COLUMN_NAME']] = $row['COLUMN_NAME'];
            }
            return $persons;
        } 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 AND participation_confirmed";
        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);
        }
    }

    function get_persons($filter)
    {
        $sql = "SELECT *, NULL as invoice FROM person " . ($filter?  "WHERE " . $filter : '');   

        try {
            $stmt = $this->pdo->prepare($sql);
            $stmt->execute();
            $persons = array();
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                $user = new User();
                $user->init_from_array($row);
                $persons[] = $user;
            }
            return $persons;
        } catch (PDOException $pe) {
            trigger_error('Could not connect to MySQL database. ' . $pe->getMessage(), E_USER_ERROR);
        }
    }
}
