<?php
class Post {
 // DB stuff
    private $conn;
    private $table = 'events2';
// Post Properties
    public $id;
    public $title;
    public $ev_start;
    public $ev_end;
    public $details;
    public $event_url;
    public $venue;
    public $venue_add;
    public $social_url;
    public $sponsors;
    public $textColor;
    public $borderColor;
    public $backgroundColor;
///////////////////////////////////////////////////
// Constructor with DB
    public function __construct($db) {
        $this->conn = $db;
      }
//////////////////////////////////////////////////////
// get data
    public function read() {
// Create query
      $sql = 'SELECT id, title, ev_start, ev_end, details, event_url, venue, venue_add, social_url,sponsors,textColor,borderColor,backgroundColor FROM ' . $this->table . ' ORDER BY ev_start ' ;
// Prepare statement
      $stmt = $this->conn->prepare($sql);
// Execute query
      $stmt->execute();
      return $stmt;
    }
///////////////////////////////////////////////////////////
// get record count
  	  public function thecount() {
// Create query
    	  $query = 'SELECT COUNT(*) FROM ' . $this->table ;
// Prepare statement
      $stmt = $this->conn->prepare($query);
// Execute query
      $stmt->execute();
      return $stmt;
 	   }
}
////logging
 function _log($str) {
    $relcrudpath='';
    $logging = $_SESSION['logging'];
    $relcrudpath = $_SESSION['relcrudpath'];
    // log to the output
    if (substr($str, 1, 5) == '-----') {
        $log_str = "{$str}\r\n"; // no date if separator
    } else {
        $log_str = date('m.d.Y').": {$str}\r\n";
    }
    // log to file if on in UI
    if ($logging) {
	    $file_system_path = $relcrudpath . '/StacksCal.log';
        file_put_contents($file_system_path, $log_str, FILE_APPEND);
    }
}
?>