<?php
include_once dirname(__FILE__) ."/../inc/dedolib/Config.inc.php";
include_once dirname(__FILE__) ."/../inc/base/functions.inc.php";
include_once dirname(__FILE__) ."/../inc/dedolib/Collection.inc.php";
include_once dirname(__FILE__) ."/../inc/dedolib/Element.inc.php";
include_once dirname(__FILE__) ."/../inc/base/JSON.php";

//miramos si estamos de mantenimiento...
include_once dirname(__FILE__) ."/../inc/base/maintenance.inc.php";

$pagePath = filter_input(INPUT_GET, 'id_pagina', FILTER_SANITIZE_ENCODED);
$id = (int)array_values(explode('-', $pagePath))[0];

$bodyClass = array();



//$metaindex = 'notranslate, noindex, nofollow';
$metaindex = 'notranslate, noimageindex';

$SEOpagDescription = getTextoWeb('seo_description', false);
$SEOpagPicture = getTextoWeb('seo_picture');

//printr($_REQUEST);

include dirname(__FILE__) ."/../admin_paginas/config_paginas_data.inc.php";

if ($id<=0) {
	header('Location: '.WEB_ROOT);
	die();
}
////////////////////////////////////////////////////////
list($action,$ids) = getAction();

$view = '';

if(isset($superAction)) {
	$action = $superAction;
	$id = $superID;
}

$rutaPagina = array();
$rutaPagina[] = 'cat_'.$id;


$_REQUEST['CIID'] = isset($_REQUEST['CIID']) ? filter_var($_REQUEST['CIID'],FILTER_SANITIZE_SPECIAL_CHARS): null;
$defs = new CollectionDefinitions($CONFIG);
$ctxt =& $defs->makeContext(true, $_REQUEST['CIID']);

/*//////////////////////////////////////////////////////
						 ACCIONES
//////////////////////////////////////////////////////*/

if($action == 'publicCard' || $action == '')
{
	$view = 'publicCard';
}
elseif($action == 'bloquePaginas')
{
	$view = 'bloquePaginas';
}

/*//////////////////////////////////////////////////////
						 VISTAS
//////////////////////////////////////////////////////*/

if ($view == 'bloquePaginas')
{

	$ctxt->setDefaultOrderBy('position');
	//$ctxt->setDefaultOrderDir('ASC');

	$ctxt->setPerPage(1000);

	$items = new Collection($defs);

	$wheres = array();

	$wheres[] = "(T0.active = 1)";
	$wheres[] = "(T0.id_pagina <> ".$id.")";

	$where = count($wheres) ? join(" AND ", $wheres) : '';

	if(count($wheres)) $items->addConstraint($where);
	$items->addContextConstraints();
	$items->readFromDBShort();

	$columns = $CONFIG['listing_public'];

	$bloques = array();
	$accordeon = array();
	$id_accordeon = 1;
	$current_id_accordeon = 0;
	$botones = array();
	foreach($items->getList() as $id=>$item) {
		//echo "<pre>";print_r($item->getDataFoto('id_foto'));echo "</pre>";
		$fotoData = explode('|', $item->get('id_foto'));
		//$minH = $CONFIG['members']['id_foto']['h'];
		if((int)$fotoData[0]>0){
			$fileRelativePath = WEB_ROOT . (str_replace("../","",$CONFIG['members']['id_foto']['path']));
			//$fileRelativePath = $CONFIG['members']['id_foto']['path'];
			$foto = $fileRelativePath . '/' . $fotoData[7] . '/' . $fotoData[6] . '-o.' . $fotoData[5];
			$fotoInfo = $item->get('id_foto_altText');
		}else{
			$foto = '';
			$fotoInfo = '';
		}

		$bloques[$id]['uuid'] = $item->get('uuid');
		$bloques[$id]['foto'] = $foto;
		$bloques[$id]['permalink_full'] = stripslashes($item->get('permalink_full', false));
		$bloques[$id]['title'] = stripslashes($item->get('title', false));
		$bloques[$id]['subtitle'] = stripslashes($item->get('subtitle', false));
		//$bloques[$id]['bg_color'] = ($item->get('bg_color')!='') ? $item->get('bg_color') : '#dbdad2';
		//$bloques[$id]['str_color'] = ($item->get('str_color')!='') ? $item->get('str_color') : '#24252D';
	}

	//printr($bloques);

	include "view_paginas_bloques.php";

}
elseif ($view == 'publicCard')
{
    //$rutaPagina[] = "productos_card";

	$item = new Element($defs);
	$item->readFromDB($id);

    moreClicks($CONFIG['table'], $CONFIG['id'], $id);

	$pagTitle[] = $item->getValue('title');
	$pagTitle[] = $item->getValue('subtitle');

	$topName = $item->getValue('title');

	$metaData['title'] = join(' | ', array_reverse(array_filter($pagTitle)));

	if ($item->getValue('seo_descripcion')!='') {
		$SEOpagDescription = $item->getValue('seo_descripcion'); 
	}

	$canonical_url = $item->getValue('permalink_full');

	$doc_vista = "view_paginas_card.php";
	include "../templates/public_view.inc.php";
}
////////////////////////////////////////////////////////

?>
