<?php
class PagezController extends baseController
{
	function index(){

		$id = $this->registry->args[0];
		if (!empty($id)) {
			//echo "ID: " . $id;
			$thispageid = $id;
		}

		//$logosModel   = new logosModel();
		//$shoppModel   = new shoppModel();

		//$logos        = $logosModel->getList();

		if (empty($_GET['latitude']) || empty($_GET['longitude'])) {
			// Chicago, IL
			$_GET['latitude']  = 41.882069;
			$_GET['longitude'] = -87.627892;
		}

		if (empty($_GET['lat']) || empty($_GET['lng'])) {
			// Chicago, IL
			$_GET['lat']  = 41.882069;
			$_GET['lng'] = -87.627892;
		}

		$nearby_cond = [
			// 'distance' => 10,
			'latitude'      => $_GET['latitude'],
			'longitude'   => $_GET['longitude'],
			'lat'      			=> $_GET['lat'],
			'lng'     			=> $_GET['lng'],
			//'is_active'     => 1,
		];

		//$test = "works!!!";

		$pagezModel   = new pagezModel();

		// SUBSCRIBERS MODULE
		//		$subscribersModel  = new subscribersModel();
		//		$total_subscribers_raw = 3150 + $subscribersModel->getTotalCount();
		//		$total_spotsleft_raw = 20000 - $total_subscribers_raw;
		//		$total_subscribers = number_format($total_subscribers_raw,"0","",",");
		//		$total_spotsleft = number_format($total_spotsleft_raw,"0","",",");

		// PAGE STUFF STARTS HERE
		$page = $this->registry->args[1];
		$page = str_replace(['.', '/', '\\'], '', $page);
		$template = "views/content_pages/$page.tpl.php";

		//		if ($page == "somepagename") {

		//		}

		// LOGGED IN USER INFO
		if (isset($_SESSION['user']['id'])) {

			$uid = $_SESSION['user']['id'];

			//			$customer = $authModel->getUser($uid);
			//print_r($customer);

			//			$name = $customer['name'];

			//$balance_in_dollars = $balance/100;

			//$balance_formatted = "$".number_format($balance_in_dollars,2,'.',',');
			//$amt_cents = $amt_formatted * 100;

			//			if (empty($name)) {
			//				$name = "Customer";
			//			} else {
			//				$name = $customer['name'];
			//			}
		}

		if (file_exists($template)) {
			include($template);
		}
	}

	function dynamicPage($page)
	{
		if (in_array('recent_posts', $page['widgets'])) {
			//$projectModel  = new projectModel();

			//			$args = [
			//				'limit' => 8,
			//				'order' => 'timestamp_posted DESC'
			//			];
			//			if ($page['recent_posts_filter_type'] == 'user') {
			//				$args['user_id'] = $page['recent_posts_filter_id'];
			//			}
			//			if ($page['recent_posts_filter_type'] == 'category') {
			//				$args['category_id'] = $page['recent_posts_filter_id'];
			//			}
			//			$recent_posts = $projectModel->getList($args);

			// $recent_posts =  $pageModel->getList(['user_id' => $page['user_id']]);

			// print_r($recent_posts);
		}

		require("views/dynamic_content_pagez.tpl.php");
	}
}