<?php
add_shortcode('testBoletin', 'test_boletin');
function test_boletin(){
		echo 'entra';
	//	ainia_update_conceptos_personalizados();
		ainia_send_newsletter_conc_personalizados();
}


add_shortcode('proyectos', 'mis_proyectos');
function mis_proyectos( $atts, $content = null  )
{

	return loop_query( array('post_type'=>'project'),true,false,'proyectos' );
}

add_shortcode('entradas', 'ultimas_entradas');
function ultimas_entradas( $atts, $content = null  )
{

	return loop_query( array('post_type'=>'post'),true,true );
}
add_shortcode('buscador', 'buscador_fecha');
function buscador_fecha(){
	$html= $html.'<form role="custom_search" method="get" class="search-form" action="'.home_url( '/busqueda-avanzada/' ).'">';		
	$html= $html.'<label><span>'. _x( 'Search for:', 'label' ).'</span>';
	$html= $html.'<input style="width:99%;margin-bottom:10px;" type="search" class="search-field" placeholder="';
	$html= $html. esc_attr_x( 'Buscar …', 'placeholder' ) .'" name="search" title="'. esc_attr_x( 'Search for:', 'label' ).'" />';
	$html= $html.'</label><br>';
	$html= $html.' <span>'. _x( 'Desde:', 'label' ) .'</span>';
	$html= $html.'<input style="width:100%;margin-bottom:10px;" type="date" name="fechaIni"><br>';
	$html= $html.'<span >'. _x( 'Hasta:', 'label' ) .'</span>';
	$html= $html.'<input style="width:100%;margin-bottom:10px;" type="date" name="fechaFin" ><br>';
	$html= $html.'<input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ).'" />';
	$html= $html.'</form>';
		
	return $html;
	
}


/********************** GRAFICO ENTRADAS POR FUENTE, filtrado por categorías de usuario **************/
add_shortcode('grafico_entradas_x_fuente_usuario','grafico_entradas_x_fuente_usuario_shortcode');
function grafico_entradas_x_fuente_usuario_shortcode(){

$url=home_url('?fuente=');
	?>
	
	<div  style="position:relative;">
			<div id="grafico_fuente_categoria_semana" >
		<?php
		grafico_entradas_x_fuente_usuario_shortcode_semana($url);
		?>
		</div>
		<div id="grafico_fuente_categoria_mes" style="visibility:hidden;position:absolute;top:0;width:100%;">
			<?php
			grafico_entradas_x_fuente_usuario_shortcode_mes($url);
		?>
					</div>
					<div id="grafico_fuente_categoria_trimestre" style="visibility:hidden;position:absolute;top:0;width:100%;">
				<?php
				grafico_entradas_x_fuente_usuario_shortcode_trimestre($url);
		?>
					</div>
					</div>
				<?php

}
/************* GRAFICO ENTRADAS POR CONCEPTO SEGUIMINETO *******/
add_shortcode('graficos_entradas_x_conceptos_seguimiento','graficos_entradas_x_conceptos_seguimiento_shortcode');
function graficos_entradas_x_conceptos_seguimiento_shortcode()
{
?>
<div  style="position:relative;width:49%;float:left;border-bottom:1px dotted grey;">
		<div id="grafico_conc_seg_semana" >
	<?php
	grafico_entradas_x_concepto_seguimiento_semana_shortcode();
	?>
	</div>
	<div id="grafico_conc_seg_mes" style="visibility:hidden;position:absolute;top:0;width:100%;">
		<?php
	grafico_entradas_x_concepto_seguimiento_mes_shortcode();
	?>
				</div>
				<div id="grafico_conc_seg_trimestre" style="visibility:hidden;position:absolute;top:0;width:100%;">
			<?php
	grafico_entradas_x_concepto_seguimiento_trimestre();
	?>
				</div>
				</div>
			<?php
}
/****************GRAFICO ENTRADAS POR CONCEPTO DE USUARIO *****************/

add_shortcode('graficos_entradas_x_conceptos_usuario','graficos_entradas_x_conceptos_usuario_shortcode');
function graficos_entradas_x_conceptos_usuario_shortcode()
{
?>
<div  style="position:relative;width:100%;height:500px;;border-bottom:0px dotted grey;">
		<div id="grafico_semana" >
	<?php
	grafico_entradas_x_concepto_usuario_semana();
	?>
	</div>
	<div id="grafico_mes" style="visibility:hidden;position:absolute;top:0;width:100%;">
		<?php
	grafico_entradas_x_concepto_usuario_mes();
	?>
				</div>
				<div id="grafico_trimestre" style="visibility:hidden;position:absolute;top:0;width:100%;">
			<?php
	grafico_entradas_x_concepto_usuario_trimestre();
	?>
				</div>
				</div>
			<?php
}

function get_query_noticias_busqueda(){
	
		$query_noticias='SELECT 
    posts.*, group_concat(categoria_term.name,\'¬¬\') as categoria_name,categoria_tax.term_thumbnail as categoria_thumbnail,group_concat(categoria_term.slug,\'¬¬\') 
as categoria_slug, group_concat(etiqueta_term.name,\'¬¬\') as etiqueta_name,etiqueta_tax.term_thumbnail as etiqueta_thumbnail,group_concat(etiqueta_term.slug,\'¬¬\') as etiqueta_slug,fuente_term.name as
 fuente_name, fuente_term.slug as fuente_slug,rel_user_2.object_type as borrado
FROM
    (SELECT 
        *
    FROM
        wp_posts
    WHERE
         post_type=\'post\' and post_status=\'publish\' #condiciones_posts#) AS posts
        
 STRAIGHT_JOIN wp_term_relationships AS rel_categoria ON posts.ID = rel_categoria.object_id 
 STRAIGHT_JOIN wp_term_taxonomy AS categoria_tax ON rel_categoria.term_taxonomy_id = categoria_tax.term_taxonomy_id AND categoria_tax.taxonomy = \'category\' 
 STRAIGHT_JOIN wp_terms AS categoria_term ON categoria_term.term_id = categoria_tax.term_id  #categorias_usuario#
 STRAIGHT_JOIN wp_term_relationships AS rel_fuente ON rel_fuente.object_id = posts.ID 
 STRAIGHT_JOIN wp_term_taxonomy AS fuente_tax ON fuente_tax.term_taxonomy_id = rel_fuente.term_taxonomy_id AND fuente_tax.taxonomy = \'fuente\' 
 STRAIGHT_JOIN wp_terms AS fuente_term ON fuente_term.term_id = fuente_tax.term_id
 STRAIGHT_JOIN wp_term_relationships AS rel_etiqueta ON rel_etiqueta.object_id = posts.ID 
 STRAIGHT_JOIN wp_term_taxonomy AS etiqueta_tax ON etiqueta_tax.term_taxonomy_id = rel_etiqueta.term_taxonomy_id AND etiqueta_tax.taxonomy = \'post_tag\' 
 STRAIGHT_JOIN wp_terms AS etiqueta_term ON etiqueta_term.term_id = etiqueta_tax.term_id
 LEFT JOIN wp_user_relations as rel_user_2 on rel_user_2.object_id=posts.ID and rel_user_2.user_id=%d
and rel_user_2.object_type=\'delete\' where 1=1 #condiciones_adicionales#  GROUP BY posts.ID ORDER BY post_modified DESC;';
	return $query_noticias;
}

function get_query_noticias_boletin_Ecoembes(){
	
		$query_noticias='SELECT 
    posts.*, group_concat(categoria_term.name,\'¬¬\') as categoria_name,categoria_tax.term_thumbnail as categoria_thumbnail,group_concat(categoria_term.slug,\'¬¬\') 
as categoria_slug, group_concat(etiqueta_term.name,\'¬¬\') as etiqueta_name,etiqueta_tax.term_thumbnail as etiqueta_thumbnail,group_concat(etiqueta_term.slug,\'¬¬\') as etiqueta_slug,fuente_term.name as
 fuente_name, fuente_term.slug as fuente_slug,rel_user_2.object_type as borrado
FROM
    (SELECT 
        *
    FROM
        wp_posts
    WHERE
                post_modified > %s and post_type=\'post\' and post_status=\'publish\') AS posts
        
 STRAIGHT_JOIN wp_term_relationships AS rel_categoria ON posts.ID = rel_categoria.object_id 
 STRAIGHT_JOIN wp_term_taxonomy AS categoria_tax ON rel_categoria.term_taxonomy_id = categoria_tax.term_taxonomy_id AND categoria_tax.taxonomy = \'category\' 
 STRAIGHT_JOIN wp_terms AS categoria_term ON categoria_term.term_id = categoria_tax.term_id  and categoria_term.term_id in (#categorias_usuario#)
 STRAIGHT_JOIN wp_term_relationships AS rel_fuente ON rel_fuente.object_id = posts.ID 
 STRAIGHT_JOIN wp_term_taxonomy AS fuente_tax ON fuente_tax.term_taxonomy_id = rel_fuente.term_taxonomy_id AND fuente_tax.taxonomy = \'fuente\' 
 STRAIGHT_JOIN wp_terms AS fuente_term ON fuente_term.term_id = fuente_tax.term_id
 STRAIGHT_JOIN wp_term_relationships AS rel_etiqueta ON rel_etiqueta.object_id = posts.ID 
 STRAIGHT_JOIN wp_term_taxonomy AS etiqueta_tax ON etiqueta_tax.term_taxonomy_id = rel_etiqueta.term_taxonomy_id AND etiqueta_tax.taxonomy = \'post_tag\' 
 STRAIGHT_JOIN wp_terms AS etiqueta_term ON etiqueta_term.term_id = etiqueta_tax.term_id
 LEFT JOIN wp_user_relations as rel_user_2 on rel_user_2.object_id=posts.ID and rel_user_2.user_id=%d
and rel_user_2.object_type=\'delete\' where 1=1 and #condiciones_adicionales#  GROUP BY posts.ID ORDER BY post_modified DESC;';
	return $query_noticias;
}




