JFIF # -$)%7&).0444#9?92>-240 5+#+4;224;652252222225222220222522225222522;2225222222"B!1AQa"q2B#R3br5CS/!12AQ"aRq#3 ??;}q7:bd%Ո>L8/$rsrQٷf=+e: Rb0Z6pN۰7b 1S`JAT K,-֥7(bNRb9CsD/s,9?}+KA]`,EΞ@@ 3ukq14""tD@D@D@D@D@D@D@D@D@D@D@ȓ|:^Yw-)G%AI/9pwVSнm@6=g7AA5tg18gj>F'J,{C3(q<*#AzX?[$va:Q4SԽ7Uԥ&,c}nF;3mO$DN}RySm\*I"}b%7GLj;gp{{FYs(p_xOJFtStǸMU蓰s95"#H'Uq>7F5[}>v%'Y,&CqMzn}m*Xo vl˳hrӦ V)))g`7$sz^%I-1leE]y%݉>?f}( *BNNñ𜤢S[i'T1 ӥԊ>NlHď~)pKw1.UsD LI/k]Sr\r=ߴMAZNKi+P}| qBS*G*z:Imk\_|l6A7߉H\z0賈'Zt_\u>4 {\#O[ERxzLvP wOLT C0ȴ]BAʷ7uNNINS,(DDDDDDDL8MY݂N$ dMK׭i2FesmNQ=?omKv]OVl^@&pɴ[t5+E`oy.E]Ϳ}$g(7y7&X+imcT\(cHɤ|=. C =yȗXʧpv=&cX*[X_i4 GtfFՓnbMjR@ thv4LO I0zlU-_*G!cH9`nԿ \k-~rS*c[}9]qbi~+%)(h($ s;dՒG_\ё[Q,plq!pEſA RZU0*\n]a~Md_3EZ { &8e:jR*dAkyۛs\B˞0Z5%6e`3;0slSx+Xȇ"*ozkE"vܬWاQ8r @ m5$ [/KNFycgrۑ@ {""""""|xd*@s7o~7BSG|܎vøGtЍL١ѬnK/, f~^~l/Ij+!JI'^;{˚*hӤJarʮ)ڱ[P^$;%.V FLJW̔?2ԭUpJe,~b%iW Yhz̻FAl|3ln"M4kM@$2wmͣp8JY)ݬ.]3vԩİ(P*Tb/1FXTg KŮ*C9jE[69d!GZȩMu!5`H\Cp"=wSAmJjCn&/*Q[kQ~b"zΕ~)aA(2EZ0(FÑp.66_φk}T5 YdRarK ɽLSj"SnR-N-Mz~F^Igb Jq(~X fH'Ӵp5_HN(ܰ,Ȍ䶛DK%a~?FuI}"p=U+j}'p&I_ɑ-x!IٮM:w|q;9M?.6x:ODѪ̬zTL`t^?8xJ$ Q cL4d/_xy ˔ SPGNgwSrrS/`5ӧKj ,hTpI=LѦ(,Pc4*4iESO?5sMz<`&_bsTO)fkX[ xqq::h9ifVۉ\_R }JVg~Jzm`(]:O &6IOghX6+HM 7X]RkUr{HL-"< >~28b{[><@6gF5&\1̹nVŕonZM7 (SF$l\sM];owE+IֹȫzɲDߌPcMQMG)b,N ;*!uo&rHT`s^7įĴz0?P&Ҫ3]@H:hڢFҢM~p{&0s?k}+Ι9׵mw >?"fs+Odٯ̌m(R9T:UpbkW=F*ZQh urk8C8@ҧeUԀyKS '.UP,NBcpFS6n=AJl*7 4<(XY_Cda/D=()b,{yHL>[jrǹ7#M7fO`o/w]GȈEU2f\?7a)#봙݂͠SEg>VRdPfF@PV"Ꮷ_(qCJG_0?1[% NKu$7&ۭ ߡ26U$`/ 3ES:/nek |\tmSg5 س}6/qDT "(*sP4SrX)%T(6y%_ Z9<%]B}oyyY"]76*U*vjijw i3D̍IS \Jnn9ۋ>%o;~)5u56槡'z* B5#5

5#a`,>1TW{Xɘ}G4"ҕ4z5F>e6*[\;%*U0LUUr2cpnݢkɜY͌3+bG0#el۴oe,,jO*M1X/3z)W^,p>s{ İQs:ޝd|w :fIe$~+ajXjnT80'S>KIUP&kNϒT=XlȞNڞ]Yz_K[Qׂގ\gq!nB@IoG *l;_뼳\RUeэkm)qh傢5KNz٘6ba:671k{  $N vfN]S7gxg=VjG;wBx t~l/"ʭl=ԝ6n[Dٛ]@"x)# E):\8Bvkcpv4O*;coJ?4ªMCA'.\zVð'w1USݻSlTyj/ gʕ,:S')ܴ]7!A^b%P׶ٮհU3 o\}XTp,e 597n}dk6UFrVǧ3qaR:BWn>Ѻ}oxKӦK)kܑKL tCs1#?升 v{r:u)?#ZxM=ڝYـ#e}JHBGTG>GsܞG2+~R̅Hש)$[*Hfx-ugx({ I7λwvYm~ |e'X#db@hW,0H8*J5AъA`;jȊY*&sh8Jn]"M>l3z%Րsy=Um'qF sX %,Uv|0W`Gzcy*V0'3R`5ޓ Hڙ>PWbw7;)[U(:krm>/ QU+)P>Hm!r -evY>wT7ԝe)^6_SN⚓ϫ('?2Sj5,[پd|+_Pv'[]t'mΝ2l}z/dz^E|"'J qED)R2ƂSg`9Ոu5~ d!G%>M6%pdcP-P L`ϼTQnA_,24G GneRn,XnߕSzV$ReBfZuE ,Z(yi?vO!clOYA [; c I|vCom+Hꡤ\eaӴ;XS|v4%FcϷAQ[yϢ_s+Ơ&pt}=%^Sb"#gĀ'[ oAUPzr;ȔZTy4t>f種ً>T؟GRgC^-WЖukS,G LV$ܱO餰%cp)[*X_v$@DDӢ3bE-V0֍?zySyadd\ j5": Bxi?;3a]1]ZFD澙rc|8uz/ CȎ3UTqb4'ҥX 6KʖYT2fPe$6 lGzSQTP} OL1q^*rxջQ_K?'?=V MR K IS HERE

MRKShell
Server IP : 104.21.73.244  /  Your IP : 172.71.28.167
Web Server : nginx/1.14.1
System : Linux comtuc2-s-2vcpu-8gb-160gb-intel-nyc3 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User : nginx ( 991)
PHP Version : 7.2.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/comunicacion/produccion/sitio/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /var/www/comunicacion/produccion/sitio/application/models/nota_modelo.php
<?php

class Nota_modelo extends CI_Model {

    public function extraer_string($str, $left, $right) {
        $str = substr(stristr($str, $left), strlen($left));
        $leftLen = strlen(stristr($str, $right));
        $leftLen = $leftLen ? -($leftLen) : strlen($str);
        $str = substr($str, 0, $leftLen);
        return $str;
    }

    public function traer_id_nota($sd_id) {
        $sql = "SELECT id from nota where sd_id = " . $sd_id;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0]['id'];
        } else {
            return false;
        }
    }

    /* Metodos para obtener informacion de una nota */

    public function traer_datos_nota($nota_id, $test = 0) {
        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.texto, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista, DATE_FORMAT(e.fecha, '%d/%m/%Y') as fecha_edicion, n.lector, n.mayor, n.scroll_inactivo, n.video_en_nota, n.patrocinado
		FROM nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		WHERE n.id = " . $nota_id;
        if ($test == 0) {
            $sql .= " and n.habilitada = 1";
        }

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            $nota = $res[0];

            $nota['seccion'] = $this->dame_array_secciones($nota['id']);
            $nota['temas'] = $this->dame_array_temas($nota['id']);
            $nota['tags'] = $this->dame_array_tags($nota['id']);
            $nota['tituloagregado'] = "";
            $nota['textoagregado'] = "";
            $verifica = explode("xto>", $nota['texto']);
            $verifica_bajada = explode("umario>", $nota['sumario']);
            if (count($verifica) > 1) {
                $texto = $this->extraer_string($nota['texto'], "<texto>", "</texto>");
                $tituloagregado = $this->extraer_string($nota['texto'], "<tituloagregado>", "</tituloagregado>");
                $textoagregado = $this->extraer_string($nota['texto'], "<textoagregado>", "</textoagregado>");
                if ($tituloagregado)
                    $nota['tituloagregado'] = $tituloagregado;
                if ($textoagregado)
                    $nota['textoagregado'] = $textoagregado;
                $nota['texto'] = $texto;
            }
            if (count($verifica_bajada) > 1) {
                $bajada = $this->extraer_string($nota['sumario'], "<sumario>", "</sumario>");
                $nota['sumario'] = $bajada;
            }

            return $nota;
        } else
            return false;
    }

    public function traer_datos_evento($evento_id, $test = 0) {
        $sql = "SELECT e.id, e.tipo, e.titulo, e.descripcion, e.habilitado, e.url,
                DATE_FORMAT(ag.fechai, '%d-%m-%Y') as fecha, ag.horai, DATE_FORMAT(ag.horai, '%H:%i') as hora,
                ( SELECT l.id FROM lugar l INNER JOIN relacion_evento r2 on (l.id = r2.objeto_id) WHERE r2.tipo = 45 and r2.evento_id = e.id LIMIT 1
                ) as lugar
                FROM evento e
                INNER JOIN agenda ag ON e.id = ag.evento_id
                WHERE e.id = " . $evento_id;
        if ($test == 0) {
            $sql .= " and e.habilitado = 1";
        }

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            $evento = $res[0];
            
            $evento['tituloagregado'] = "";
            $evento['textoagregado'] = "";
            $verifica = explode("xto>", $evento['texto']);
            if (count($verifica) > 1) {
                $texto = $this->extraer_string($evento['texto'], "<texto>", "</texto>");
                $tituloagregado = $this->extraer_string($evento['texto'], "<tituloagregado>", "</tituloagregado>");
                $textoagregado = $this->extraer_string($evento['texto'], "<textoagregado>", "</textoagregado>");
                if ($tituloagregado)
                    $evento['tituloagregado'] = $tituloagregado;
                if ($textoagregado)
                    $evento['textoagregado'] = $textoagregado;
                $evento['texto'] = $texto;
            }

            return $evento;
        } else
            return false;
    }

    public function traer_datos_nota_cached($cached_slug) {
        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.texto, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista, DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha_edicion, n.lector, n.mayor, n.scroll_inactivo, n.video_en_nota, n.patrocinado
		FROM nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		WHERE n.cached_slug = '" . $cached_slug . "' and n.habilitada = 1 limit 1";


        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            $nota = $res[0];

            $nota['seccion'] = $this->dame_array_secciones($nota['id']);
            $nota['temas'] = $this->dame_array_temas($nota['id']);
            $nota['tags'] = $this->dame_array_tags($nota['id']);
            $nota['tituloagregado'] = "";
            $nota['textoagregado'] = "";
            $verifica = explode("xto>", $nota['texto']);
            $verifica_bajada = explode("umario>", $nota['sumario']);
            if (count($verifica) > 1) {
                $texto = $this->extraer_string($nota['texto'], "<texto>", "</texto>");
                $tituloagregado = $this->extraer_string($nota['texto'], "<tituloagregado>", "</tituloagregado>");
                $textoagregado = $this->extraer_string($nota['texto'], "<textoagregado>", "</textoagregado>");
                if ($tituloagregado)
                    $nota['tituloagregado'] = $tituloagregado;
                if ($textoagregado)
                    $nota['textoagregado'] = $textoagregado;
                $nota['texto'] = $texto;
            }
            if (count($verifica_bajada) > 1) {
                $bajada = $this->extraer_string($nota['sumario'], "<sumario>", "</sumario>");
                $nota['sumario'] = $bajada;
            }

            return $nota;
        } else
            return false;
    }

    /* Metodos para obtener informacion de una columna */

    public function traer_datos_columna($nota_id, $test = 0) {
        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.texto, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista, DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha_edicion,
		r.objeto_id as firma_id 
		FROM nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		inner join relacion r on (r.nota_id = n.id)
		WHERE r.tipo = 4 and 
		n.id = " . $nota_id;
        if ($test == 0) {
            $sql .= " and n.habilitada = 1";
        }

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            $nota = $res[0];

            $nota['seccion'] = $this->dame_array_secciones($nota['id']);
            $nota['temas'] = $this->dame_array_temas($nota['id']);
            $nota['tags'] = $this->dame_array_tags($nota['id']);
            $nota['tituloagregado'] = "";
            $nota['textoagregado'] = "";
            $verifica = explode("xto>", $nota['texto']);
            $verifica_bajada = explode("umario>", $nota['sumario']);
            if (count($verifica) > 1) {
                $texto = $this->extraer_string($nota['texto'], "<texto>", "</texto>");
                $tituloagregado = $this->extraer_string($nota['texto'], "<tituloagregado>", "</tituloagregado>");
                $textoagregado = $this->extraer_string($nota['texto'], "<textoagregado>", "</textoagregado>");
                if ($tituloagregado)
                    $nota['tituloagregado'] = $tituloagregado;
                if ($textoagregado)
                    $nota['textoagregado'] = $textoagregado;
                $nota['texto'] = $texto;
            }
            if (count($verifica_bajada) > 1) {
                $bajada = $this->extraer_string($nota['sumario'], "<sumario>", "</sumario>");
                $nota['sumario'] = $bajada;
            }

            return $nota;
        } else
            return false;
    }

    /* Metodos para obtener informacion de un blog */

    public function traer_datos_blog($nota_id, $test = 0) {
        $sql = "SELECT n.id, n.titulo, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista, DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha_edicion,
		r.objeto_id as firma_id 
		FROM nota n 
		inner join relacion r on (r.nota_id = n.id)
		WHERE r.tipo = 4 and 
		n.id = " . $nota_id;
        if ($test == 0) {
            $sql .= " and n.habilitada = 1";
        }

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            $nota = $res[0];

            $nota['seccion'] = $this->dame_array_secciones($nota['id']);
            $nota['antetitulo'] = $nota['seccion'][0]['url'];
            $nota['temas'] = $this->dame_array_temas($nota['id']);
            $nota['tags'] = $this->dame_array_tags($nota['id']);
            $nota['tituloagregado'] = "";
            $nota['textoagregado'] = "";
            $verifica = explode("xto>", $nota['texto']);
            $verifica_bajada = explode("umario>", $nota['sumario']);
            if (count($verifica) > 1) {
                $texto = $this->extraer_string($nota['texto'], "<texto>", "</texto>");
                $tituloagregado = $this->extraer_string($nota['texto'], "<tituloagregado>", "</tituloagregado>");
                $textoagregado = $this->extraer_string($nota['texto'], "<textoagregado>", "</textoagregado>");
                if ($tituloagregado)
                    $nota['tituloagregado'] = $tituloagregado;
                if ($textoagregado)
                    $nota['textoagregado'] = $textoagregado;
                $nota['texto'] = $texto;
            }
            if (count($verifica_bajada) > 1) {
                $bajada = $this->extraer_string($nota['sumario'], "<sumario>", "</sumario>");
                $nota['sumario'] = $bajada;
            }

            //echo "<pre>".print_r($nota,true)."</pre>";
            return $nota;
        } else
            return false;
    }

    /* Metodos para obtener las ultimas notas de una determinada seccion para el diagramador */

    public function dameUltimasNotasSeccion($hash_id, $edicion_id, $tag_id, $cant) {
        $edicion_id = $edicion_id - 1;
        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista,  
		(
			select CONCAT(f.ruta,'th_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
 		) as destacada
		FROM nota n 
		inner join relacion_tag r on (r.nota_id = n.id)
		WHERE n.edicion_id >= " . $edicion_id . " and r.tag_id = " . $tag_id . " and n.habilitada = 1 
		AND n.id NOT IN (SELECT id_contenido FROM mockup_contenidos WHERE tipo=1 and hash_id=" . $hash_id . ") 
		order by n.id desc limit " . $cant;

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();

            return $res;
        } else
            return false;
    }

    public function dame_array_secciones($id_nota) {
        $sql = "select s.id, s.nombre, s.template, s.color, s.url, s.alias
		from tag s 
		inner join (
			select id_seccion from nota where id = " . $id_nota . ") as sec on (sec.id_seccion = s.id) where s.tipo_id=5";
        //$query = $this->db->get();
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dame_array_temas($id_nota) {

        /* $this->db->select("t.id, t.tema as nombre");
          $this->db->from("tema t");
          $this->db->join("relacion r","r.objeto_id = t.id and r.tipo=25","inner");
          $this->db->where("r.nota_id",$id_nota); */
        $sql = "select t.id, t.nombre,t.tipo_id 
		from tag t 
		inner join (
			select tag_id from relacion_tag where nota_id = " . $id_nota . " and tipo = 3
		) as temp_tem on (temp_tem.tag_id = t.id) where t.tipo_id = 3";
        //$query = $this->db->get();
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dame_array_tags($id_nota) {
        $this->db->select("s.id,s.nombre");
        $this->db->from("relacion_tag r");
        $this->db->join("tag s", "s.id=r.tag_id", "inner");
        $this->db->where("r.nota_id", $id_nota);
        $ar = array(1, 2, 4);
        $this->db->where_in("r.tipo", $ar);
        $this->db->where_in("s.tipo_id", $ar);
        $query = $this->db->get();
        $res = $query->result_array();
        return $res;
    }

    public function dameFirma($nota_id) {
        $this->db->select("u.id,u.nombre, u.apellido,ui.descripcion");
        $this->db->from("relacion r");
        $this->db->join("usuario u", "u.id=r.objeto_id", "inner");
        $this->db->join("usuario_info ui", "ui.usuario_id=u.id", "inner");
        $this->db->where("r.nota_id", $nota_id);
        $this->db->where("r.tipo", 4);
        $query = $this->db->get();
        $res = $query->result_array();
        if (is_array($res)) {
            if (count($res) > 0)
                return $res[0];
        } else
            return false;
    }

    public function traer_datos_nota_minimos($nota_id) {
        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(n.fechamod, '%d-%m-%Y') as fecha, s.nombre as seccion
		FROM nota n 
		inner join tag s on s.id = n.id_seccion
		WHERE n.id = " . $nota_id;

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            $nota = $res[0];

            //$nota['seccion'] = $this->dame_array_secciones($nota['id']);

            return $nota;
        } else
            return false;
    }

    public function dameNotasRelacionadas($nota_id) {
        $sql = "SELECT n.id, n.titulo, n.url, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color,
					(select s.nombre 
					  from tag s 
					  inner join relacion_tag r on (s.id = r.tag_id and r.tipo=5) 
					  where r.nota_id = n.id and s.tipo_id = 5 limit 1) as seccion
				FROM nota n 
				inner join relacion re on (n.id = re.objeto_id and re.tipo = 32) 
                                INNER JOIN tag t ON (t.id = n.id_seccion AND t.tipo_id=5) 
				WHERE re.nota_id = " . $nota_id . " and n.habilitada = 1";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameNotasRelacionadasConFoto($nota_id) {

        $sql = "SELECT distinct n.id, n.titulo, n.url, n.sumario as bajada, n.antetitulo, 
				n.usuario_id, n.vista, n.url, DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, n.edicion_id,n.um,
				DATE_FORMAT(n.fechamod,'%H:%i') as hora, 
				t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color,
				(
					select concat(f.ruta,f.imagen)
					from foto f 
					inner join relacion r2 on (f.id = r2.objeto_id)
					where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 		) as destacada	 		
				FROM nota n 
				INNER JOIN relacion re ON (n.id = re.objeto_id AND re.tipo = 32)
				inner join edicion e on (e.id = n.edicion_id) 	
				INNER JOIN tag t ON (t.id = n.id_seccion AND t.tipo_id=5) 
				WHERE re.nota_id = " . $nota_id . " and n.habilitada = 1 ORDER BY n.id DESC";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            if (is_array($res)) {
                foreach ($res as $k => $not) {
                    $res[$k]['videos'] = $this->tieneVideo($not['id']);
                }
            }
            return $res;
        } else
            return false;
    }

    public function dameUltimas($edicion_id, $limit) {
        $sql = "SELECT n.id, n.titulo, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora,
		
		(select s.nombre 
		  from tag s 
		  inner join relacion_tag r on (r.tag_id = s.id and r.tipo = 5)
		  where r.nota_id = n.id and s.tipo_id = 5
		  limit 1) as seccion 
		  
		  FROM nota n 
		  inner join edicion e on (e.id = n.edicion_id) 
		  WHERE n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1
		  ORDER BY n.id desc 
		  LIMIT $limit";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameLeidas($edicion_id, $limit, $order) {
        $sql = "SELECT n.id, n.titulo, n.url,
		
		(select s.nombre 
		  from tag s 
		  inner join relacion_tag r on (r.tag_id = s.id and r.tipo = 5)
		  where r.nota_id = n.id and s.tipo_id = 5 
		  limit 1) as seccion 
		
		  FROM nota n 
		  left JOIN nota_visitas nv on (n.id = nv.nota_id)
		  WHERE n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
		  ORDER BY nv.visitas $order 
		  LIMIT $limit";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function rankingMasVistasRecomendadas($edicion_id, $campo = "visitas", $limit = "4", $order = "desc") {
        if ($edicion_id > 0) {
            $sql = "select n.id, n.titulo, n.url, nv." . $campo . ",
				t.nombre as seccion, n.sumario
				from nota n 
				inner join tag t on t.id = n.id_seccion
				left JOIN nota_visitas nv on (n.id = nv.nota_id) 
				where n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
				order by nv." . $campo . " " . $order . " limit " . $limit;
            $query = $this->db->query($sql);
            if ($query->num_rows() > 0) {
                $res = $query->result_array();
                return $res;
            } else
                return false;
        } else
            return false;
    }

    public function rankingMasComentadas($edicion_id, $limit = "4", $order = "desc") {
        if ($edicion_id > 0) {
            $sql = "SELECT n.id, n.titulo, cr.cantidad, (SELECT s.url FROM tag s INNER JOIN relacion_tag r ON s.id = r.tag_id  WHERE r.tipo=5 AND r.nota_id=n.id limit 1) seccion 
			FROM nota n 
			LEFT JOIN (
			SELECT objeto_id, COUNT(id) AS cantidad FROM comentario_min WHERE edicion_id = " . $edicion_id . " AND tipo=32
			GROUP BY objeto_id )cr ON (cr.objeto_id = n.id)  
			WHERE n.edicion_id = " . $edicion_id . " and n.habilitada = 1
			ORDER BY cr.cantidad DESC 
			LIMIT " . $limit;

            $query = $this->db->query($sql);
            if ($query->num_rows() > 0) {
                $res = $query->result_array();

                return $res;
            } else
                return false;
        } else
            return false;
    }

    public function dameEnviadas($edicion_id, $limit, $order) {
        $sql = "SELECT n.id, n.titulo, n.url,
		
		(select s.nombre 
		  from tag s 
		  inner join relacion_tag r on (r.tag_id = s.id and r.tipo = 5)
		  where r.nota_id = n.id and s.tipo_id = 5
		  limit 1) as seccion 
		
		  FROM nota n 
		  left join nota_visitas nv on (n.id = nv.nota_id)
		  WHERE n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
		  ORDER BY nv.enviadas $order 
		  LIMIT $limit";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameMasComentadas($edicion_id, $limit) {
        $sql = "SELECT n.id, n.titulo, n.url,
		
		(select s.nombre 
		  from tag s 
		  inner join relacion_tag r on (r.tag_id = s.id and r.tipo = 5)
		  where r.nota_id = n.id and s.tipo_id = 5
		  limit 1) as seccion 
		
		  FROM nota n 
		  LEFT JOIN 
		  (
		  	select count(c.id) as comentarios, c.objeto_id 
		  	from comentario_min c 
		  	inner join nota ta on (ta.id = c.objeto_id and c.tipo = 32)
		  	where ta.edicion_id = " . $edicion_id . " 
		  	group by c.objeto_id 
		  	order by comentarios desc 
		  	limit 150
		  ) as com_nota on (com_nota.objeto_id = n.id)
		  WHERE n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
		  ORDER BY com_nota.comentarios desc 
		  LIMIT $limit";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameMasComentadasDerecha($edicion_id, $limit) {
        $sql = "SELECT n.id, n.titulo, n.url,DATE_FORMAT(n.fechamod, '%d-%m-%Y') AS fecha, DATE_FORMAT(n.fechamod, '%H:%i') AS hora, s.nombre AS seccion,
		(
			SELECT CONCAT(f.ruta,f.imagen) 
			FROM foto f 
			INNER JOIN relacion r2 ON (f.id = r2.objeto_id)
			WHERE r2.tipo = 30 AND r2.nota_id = n.id ORDER BY r2.destacado DESC LIMIT 1
		) AS foto
		  FROM nota n 
		  LEFT JOIN 
		  (
		  	select count(c.id) as comentarios, c.objeto_id 
		  	from comentario_min c 
		  	inner join nota ta on (ta.id = c.objeto_id and c.tipo = 32)
		  	where ta.edicion_id = " . $edicion_id . " 
		  	group by c.objeto_id 
		  	order by comentarios desc 
		  	limit 150
		  ) as com_nota on (com_nota.objeto_id = n.id)
		INNER JOIN tag s ON (s.id = n.id_seccion)
		WHERE n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
		ORDER BY com_nota.comentarios desc 
		LIMIT $limit";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameInfoMinima($nota_id) {
        $sql = "SELECT n.id, n.titulo, n.sumario, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, n.edicion_id, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, 
		
		(
			select CONCAT_WS('|',s.nombre,s.url) from tag s inner join 
			(select tag_id, orden from relacion_tag 
				where nota_id = " . $nota_id . " and tipo = 5
			) as temp on (temp.tag_id = s.id) 
			where s.tipo_id = 5
			order by orden asc
			limit 1
		) as seccion 
		
		FROM nota n 
		WHERE n.id = " . $nota_id;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0];
        } else {
            return array("id" => "", "titulo" => "", "suamrio" => "", "url" => "", "fechaAlra" => "");
        }
    }

    public function dameUltimasMovil($edicion_id, $limit) {
        $sql = "SELECT n.id, n.titulo, n.url, n.sumario,DATE_FORMAT(n.fechamod, '%H:%i') as hora,n.um,
		
		(select s.nombre 
		  from tag s 
		  inner join relacion_tag r on (r.tag_id = s.id and r.tipo = 5)
		  where r.nota_id = n.id and s.tipo_id = 5
		  limit 1) as seccion, 
		
		  (
			select CONCAT(f.ruta,'th_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 ) as destacada
		  FROM nota n 
		  WHERE n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 and n.um = 1  
		  ORDER BY n.id desc 
		  LIMIT $limit";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameMasLeidasMovil($edicion_id, $limit, $order) {
        $sql = "SELECT n.id, n.titulo, n.url, n.sumario,DATE_FORMAT(n.fechamod, '%H:%i') as hora,n.um,
		
		(select s.nombre 
		  from tag s 
		  inner join relacion_tag r on (r.tag_id = s.id and r.tipo = 5)
		  where r.nota_id = n.id and s.tipo_id = 5 
		  limit 1) as seccion, 
		
		  (
			select CONCAT(f.ruta,'th_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 ) as destacada
		  FROM nota n 
		  inner JOIN nota_visitas nv on (n.id = nv.nota_id)
		  WHERE n.edicion_id = " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
		  ORDER BY nv.visitas $order 
		  LIMIT $limit";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    /*     * ********************FIN**************************** */

    /* Metodos para listado de notas en secciones y temas */

    public function listadoPorSeccion($seccion_id, $edicion_id = 0) {
        $sql = "select n.id, n.antetitulo, n.titulo, n.sumario as bajada, e.fecha as fecha, n.url, 
		(
			select CONCAT(f.ruta,'tmb2_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada
		from nota n 
		inner join relacion_tag r on (r.nota_id = n.id) 
		where r.tipo = 5 and r.tag_id = " . $seccion_id . " and n.habilitada = 1";

        if ($edicion_id > 0)
            $sql .= " and n.edicion_id = " . $edicion_id;
        else
            $sql .= " and n.fechaVencimiento <= '" . date('Y-m-d') . "' and n.fechaInicio >= '" . date('Y-m-d') . "'";

        $sql .= " order by n.id desc";

        $query = $this->db->query($sql);
        $res = $query->result_array();
        return $res;
    }

    public function notasSeccionAtemporal($seccion_id, $edicion_id = 3749) {
        $add = "";
        /* if ($edicion_id > 0)
          {
          $add .= " and n.edicion_id in (";
          for($i=$edicion_id-14; $i<=$edicion_id; $i++)
          {
          $add .= "$i,";
          }
          $add = substr($add,0,strlen($add)-1);
          $add .= ")";
          } */

        $edicion_filtro = $edicion_id - 14;

        $sql = "select n.id, n.antetitulo, n.titulo, n.sumario as bajada, 
		n.url, e.fecha, 
		(
			select CONCAT(f.ruta,'tmb2_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada
		from nota n 
		inner join relacion_tag r on (r.nota_id = n.id) 
		inner join edicion e on (e.id = n.edicion_id) 
		where n.edicion_id between $edicion_filtro and $edicion_id and r.tag_id = " . $seccion_id . " and r.tipo=5 and n.habilitada = 1 and e.habilitada=1";
        $sql .= " order by n.id desc limit 20";
        $query = $this->db->query($sql);
        $res = $query->result_array();
        return $res;
    }

    public function notasSeccionAtemporalDiaria($seccion_id, $edicion_id = 0) {
        $array_vacio = array();
        if ($edicion_id > 0) {
            /* $sql = "select n.id, n.antetitulo, n.titulo, n.sumario as bajada, 
              n.url, e.fecha,
              (
              select CONCAT(f.ruta,'tmb2_',f.imagen)
              from foto f
              inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
              where r2.nota_id = n.id order by r2.destacado desc limit 1
              ) as destacada
              from nota n
              inner join relacion_tag r on (r.nota_id = n.id)
              inner join edicion e on (e.id = n.edicion_id)
              where n.edicion_id = $edicion_id and r.tag_id = ".$seccion_id." and r.tipo=5 and n.habilitada = 1 and e.habilitada=1";
              $sql .= " order by n.id desc limit 50"; */
            $sql = "select n.id, n.antetitulo, n.titulo, n.sumario as bajada, 
			n.url, e.fecha, 
			(
				select CONCAT(f.ruta,'tmb2_',f.imagen) 
				from foto f 
				inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
				where r2.nota_id = n.id order by r2.destacado desc limit 1
			) as destacada
			from nota n 
			inner join relacion_tag r on (r.nota_id = n.id) 
			inner join edicion e on (e.id = n.edicion_id) 
			where r.tag_id = " . $seccion_id . " and r.tipo=5 and n.habilitada = 1 and e.habilitada=1";
            $sql .= " order by n.id desc limit 50";
            $query = $this->db->query($sql);
            $res = $query->result_array();
            return $res;
        } else
            return $array_vacio;
    }

    public function notasUltimoMomento($edicion_id, $limit = 80, $start = 0) {
        $edicion_anterior = $edicion_id - 1;

        $sql = "select n.id, n.anteTitulo as antetitulo, n.titulo, n.sumario as bajada, DATE_FORMAT(n.fechamod,'%H:%i') as hora, n.url, n.edicion_id, DATE_FORMAT(e.fecha,'%d-%m-%Y') as fecha, 
		(
			select f.ruta
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as ruta,
		(
			select f.imagen
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada,
		
		
		CONCAT_WS('|',s.nombre,s.color) as seccion_nombre
		
		from nota n  
		inner join edicion e on (e.id = n.edicion_id)
		inner join tag s on (s.id = n.id_seccion) 
		where n.edicion_id between " . $edicion_anterior . " and " . $edicion_id . " and n.habilitada = 1";


        $sql .= " order by n.edicion_id desc, n.fechamod desc";

        $sql .= " limit " . $start . ',' . $limit;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();

            return $res;
        } else
            return false;
    }

    public function notasPopulares($edicion_id, $limit = 50) {
        $edicion_anterior = $edicion_id - 1;

        $sql = "select n.id, n.anteTitulo as antetitulo, n.titulo, n.sumario as bajada, DATE_FORMAT(n.fechamod,'%H:%i') as hora, n.url, n.um, n.edicion_id, DATE_FORMAT(e.fecha,'%d-%m-%Y') as fecha,  
		(
			select CONCAT(f.ruta,'tmb2_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada,
		
		(
			select CONCAT_WS('|',s.nombre,s.color) as nom
			from tag s 
			inner join relacion_tag re on (re.tag_id = s.id and re.tipo = 5) 
			where re.nota_id = n.id and s.tipo_id = 5
			limit 1
		) as seccion_nombre
		
		from nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		inner join nota_visitas nv on (nv.nota_id = n.id)  
		where n.edicion_id between " . $edicion_anterior . " and " . $edicion_id . " and n.habilitada = 1";

        $sql .= " order by nv.visitas desc, n.id desc limit " . $limit;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            foreach ($res as $key => $not) {
                $info_firma = $this->dameFirma($not['id']);
                if ($info_firma) {
                    $res[$key]['firma_id'] = $info_firma['id'];
                    $res[$key]['firma_nombre'] = $info_firma['nombre'] . ' ' . $info_firma['apellido'];
                }
            }
            return $res;
        } else
            return false;
    }

    public function notasUltimoMomentoFiltradas($edicion_id, $seccion_id, $order = "") {
        if ($edicion_id > 0) {
            $sql = "select n.id, n.anteTitulo as antetitulo, n.titulo, n.sumario as bajada, n.fechamod as fecha, n.url, 
			(
				select CONCAT(f.ruta,'tmb2_',f.imagen) 
				from foto f 
				inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
				where r2.nota_id = n.id order by r2.destacado desc limit 1
			) as destacada,
			
			(
				select CONCAT_WS('|',s.nombre,s.color) as nom
				from tag s 
				inner join relacion_tag re on (re.tag_id = s.id and re.tipo = 5) 
				where re.nota_id = n.id and s.tipo_id = 5
				limit 1
			) as seccion_nombre
			
			from nota n  
			where n.edicion_id = " . $edicion_id . " and n.um = 1 and n.habilitada = 1";

            $sql .= " order by n.id desc limit 80";

            $query = $this->db->query($sql);
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function notasUltimoMomentoDerecha($edicion_id, $limit = 4) {
        $sql = "select n.id, n.titulo, n.fechamod as fecha, n.url, 
		(
			select concat(f.ruta,f.imagen)
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada,
		(
			select s.nombre 
			from tag s 
			inner join relacion_tag re on (re.tag_id = s.id and re.tipo = 5) 
			where re.nota_id = n.id and s.tipo_id = 5
			limit 1
		) as seccion_nombre
		from nota n  
		where n.edicion_id = " . $edicion_id . " and n.um = 1 and n.habilitada = 1";

        $sql .= " order by n.id desc limit " . $limit;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function notasSeccionCiudadeDalede($seccion_id, $fecha, $start = 0) {
        $sql = "select n.id, n.antetitulo, n.titulo, n.sumario as bajada, 
		DATE_FORMAT(e.fecha, '%d/%m/%Y') as fecha, n.url, 
		(
			select CONCAT(f.ruta,'tmb2_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada, 
		(
			select concat(m.titulo,'_',m.descripcion,'_',m.latitud,'_',m.longitud,'_',m.zoom)
			from mapa m 
			inner join relacion r2 on (m.id = r2.objeto_id)
			where r2.tipo = 29 and r2.nota_id = n.id limit 1
 		) as mapa
		from nota n 
		inner join relacion_tag r on (r.nota_id = n.id and r.tipo=5) 
		inner join edicion e on (e.id = n.edicion_id)
		where r.objeto_id = " . $seccion_id . " and n.habilitada = 1";

        if ($fecha != "false" and $fecha != "") {
            $sql .= " and date(e.fecha) = '$fecha'";
        } else {
            $sql .= " and date(e.fecha) < '" . date('Y-m-d') . "'";
        }

        $sql .= " order by n.id desc limit $start,10";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function listadoPorTema($tema_id, $edicion_id, $start = 0) {
        $edicion_ant = $edicion_id - 2000;

        $sql = "select n.id, n.anteTitulo as antetitulo, n.titulo, n.sumario as bajada, 
		DATE_FORMAT(e.fecha, '%d/%m/%Y') as fecha, n.url, 
		(
			select CONCAT(f.ruta,'tmb2_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada,

		(
			select s.nombre 
			from tag s 
			inner join relacion_tag re on (re.tag_id = s.id and re.tipo = 5) 
			where re.nota_id = n.id  and s.tipo_id = 5
			limit 1
		) as seccion_nombre

		from nota n 
		inner join relacion_tag r on (n.id = r.nota_id and r.tipo = 3)  
		where r.tag_id = " . $tema_id . " and n.habilitada = 1 
		AND edicion_id between $edicion_ant and " . $edicion_id . "
		order by n.id desc limit $start,20";


        $query = $this->db->query($sql);
        //echo $this->db->last_query();
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    /*     * ******************Fin******************** */

    public function dameInfoParaEmail($nota_id) {
        $sql = "SELECT n.id, n.titulo, n.sumario as bajada, n.url,
		(select s.nombre 
		  from tag s 
		  inner join relacion_tag r on (r.tag_id = s.id and r.tipo = 5)
		  where r.nota_id = n.id and s.tipo_id = 5
		  limit 1) as seccion 
		  FROM nota n 
		  WHERE n.id = " . $nota_id;
        $query = $this->db->query($sql);

        if ($res = $query->result_array()) {
            $num = $query->num_rows();
            if ($num > 0) {
                foreach ($res as $k => $v) {
                    $res[$k]['imagen'] = $this->dameImagenDestacada($v['id']);
                }
            }
            return $res[0];
        } else {
            return false;
        }
    }

    /*     * ******************Fin******************** */

    public function cargarNoticiasEnLayout($filtro) {

        $sql = "select n.id, n.titulo, e.fecha as fechaAlta";
        $sql .= " from nota n";
        $sql .= " inner join edicion e on (e.id = n.edicion_id)";



        if ($filtro['edicion_desde'] and ! $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  = " . $filtro['edicion_desde'];

        if (!$filtro['edicion_desde'] and $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  = " . $filtro['edicion_hasta'];

        if ($filtro['edicion_desde'] and $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  between " . $filtro['edicion_desde'] . " and " . $filtro['edicion_hasta'];

        if ($filtro['um'] == "true") {
            $sql .= " and n.um = 1";
        }

        if ($filtro['seccion'] <> "") {
            $sql .= " and n.id_seccion = " . $filtro['seccion'];
        }

        if ($filtro['texto'] <> "") {
            $sql .= " and n.titulo like '%" . $filtro['texto'] . "%'";
        }
        $sql .= ' and n.habilitada=1 AND n.id NOT IN (SELECT id_contenido FROM mockup_contenidos WHERE tipo=1 and hash_id in (' . $filtro['grupo_array'] . ')) 
		order by n.id desc limit 50';
        //echo $sql; die();
        $query = $this->db->query($sql);
        if ($res = $query->result_array()) {
            $num = $query->num_rows();
            if ($num > 0) {
                foreach ($res as $k => $v) {
                    $res[$k]['seccion'] = $this->dame_secciones($v['id'], '', ', ');
                    $res[$k]['imagen'] = $this->dameImagenDestacada($v['id']);
                }
            }
            return $res;
        } else {
            return false;
        }
    }

    public function cargarEventosEnLayout($filtro) {

        $sql = "select e.id, e.titulo, a.fechai as fechaAlta";
        $sql .= " from evento e";
        $sql .= " inner join agenda a on (a.evento_id = e.id)";



        if ($filtro['edicion_desde'] and ! $filtro['edicion_hasta'])
            $sql .= " where a.fechai  = '" . $filtro['edicion_desde'] . "'";

        if (!$filtro['edicion_desde'] and $filtro['edicion_hasta'])
            $sql .= " where a.fechai  = '" . $filtro['edicion_hasta'] . "'";

        //if ($filtro['edicion_desde'] and $filtro['edicion_hasta'])
        //   $sql .= " where a.fechai  between '" . $filtro['edicion_desde'] . "' and '" . $filtro['edicion_hasta'] . "'";

        if ($filtro['desde'] and $filtro['hasta'])
            $sql .= " where a.fechai  between '" . $filtro['desde'] . "' and '" . $filtro['hasta'] . "'";

        if ($filtro['um'] == "true") {
            //$sql .= " and e.um = 1";
        }

        if ($filtro['seccion'] <> "") {
            $sql .= " and e.id_seccion = " . $filtro['seccion'];
        }

        if ($filtro['texto'] <> "") {
            $sql .= " and e.titulo like '%" . $filtro['texto'] . "%'";
        }
        $sql .= ' and e.habilitado=1 AND e.id NOT IN (SELECT id_contenido FROM mockup_contenidos WHERE tipo=7 and hash_id in (' . $filtro['grupo_array'] . ')) 
		order by e.id desc limit 50';
        //echo $sql; die();
        $query = $this->db->query($sql);
        if ($res = $query->result_array()) {
            $num = $query->num_rows();
            if ($num > 0) {
                foreach ($res as $k => $v) {
                    //$res[$k]['seccion'] = $this->dame_secciones($v['id'], '', ', ');
                    //$res[$k]['imagen'] = $this->dameImagenDestacada($v['id']);
                }
            }
            return $res;
        } else {
            return false;
        }
    }

    public function cargarColumnasEnLayout($filtro) {
        /* $sql = "select n.id, n.titulo, e.fecha as fechaAlta";
          $sql .= " from nota n";
          $sql .=" inner join edicion e on (e.id = n.edicion_id)";

          if($filtro['seccion']<>"")
          {
          $sql .= " inner join relacion_tag r on (r.nota_id=n.id and r.tipo=5)";
          }


          if ($filtro['edicion_desde'] and !$filtro['edicion_hasta'])
          $sql .= " where n.edicion_id  = ".$filtro['edicion_desde'];

          if (!$filtro['edicion_desde'] and $filtro['edicion_hasta'])
          $sql .= " where n.edicion_id  = ".$filtro['edicion_hasta'];

          if ($filtro['edicion_desde'] and $filtro['edicion_hasta'])
          $sql .= " where n.edicion_id  between ".$filtro['edicion_desde']." and ".$filtro['edicion_hasta'];

          if($filtro['um']=="true")
          {
          $sql .= " and n.um = 1";
          }

          if($filtro['seccion']<>"")
          {
          $sql .= " and r.tag_id = ".$filtro['seccion'];
          }

          if($filtro['texto']<>"")
          {
          $sql .= " and n.titulo like '%".$filtro['texto']."%'";
          }
          $sql .=' and n.habilitada=1 AND n.id NOT IN (SELECT id_contenido FROM mockup_contenidos WHERE tipo=1 and hash_id = '.$filtro['hash_id'].')
          order by n.id desc limit 50'; */

        /* ffffffffffffffffffffffffffff */

        $edicion_id_ant = $filtro['edicion'] - 2;
        $sql = "select n.id, n.titulo, e.fecha as fechaAlta,r.objeto_id as firma_id";
        $sql .= " from nota n";
        $sql .= " inner join edicion e on (e.id = n.edicion_id)";
        $sql .= " inner join relacion r on (r.nota_id = n.id)";

        if ($filtro['seccion'] <> "") {
            $sql .= " inner join relacion_tag r2 on (r2.nota_id=n.id and r2.tipo=5)";
        }

        if ($filtro['edicion_desde'] and ! $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  = " . $filtro['edicion_desde'];

        if (!$filtro['edicion_desde'] and $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  = " . $filtro['edicion_hasta'];

        if ($filtro['edicion_desde'] and $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  between " . $filtro['edicion_desde'] . " and " . $filtro['edicion_hasta'];

        $sql .= ' and r.tipo=4';

        if ($filtro['seccion'] <> "") {
            $sql .= " and r2.tag_id = " . $filtro['seccion'];
        }

        if ($filtro['texto'] <> "") {
            $sql .= " and n.titulo like '%" . $filtro['texto'] . "%'";
        }

        $sql .= ' and n.habilitada=1 AND n.id NOT IN (SELECT id_contenido FROM mockup_contenidos WHERE tipo=12 and hash_id = ' . $filtro['hash_id'] . ') 
		order by n.id desc limit 50';
        //echo $sql; die();
        $query = $this->db->query($sql);
        if ($res = $query->result_array()) {
            $num = $query->num_rows();
            if ($num > 0) {
                foreach ($res as $k => $v) {
                    $res[$k]['seccion'] = $this->dame_secciones($v['id'], '', ', ');
                    //$res[$k]['imagen'] = $this->dameImagenFirmaDestacada($v['id']);
                }
            }
            return $res;
        } else {
            return false;
        }
    }

    public function cargarBlogsEnLayout($filtro) {
        $sql = "select n.id, n.titulo, n.fechaAlta,r.objeto_id as firma_id";
        $sql .= " from nota n";
        //$sql .=" inner join edicion e on (e.id = n.edicion_id)";
        $sql .= " inner join relacion r on (r.nota_id = n.id)";

        if ($filtro['seccion'] <> "") {
            $sql .= " inner join relacion_tag r2 on (r2.nota_id=n.id and r2.tipo=5)";
        }

        $sql .= " where n.edicion_id  = 0";


        if ($filtro['desde'] and $filtro['hasta'])
            $sql .= " and  date(n.fechaAlta)  between '" . $filtro['desde'] . "' and '" . $filtro['hasta'] . "'";

        $sql .= ' and r.tipo=4';

        if ($filtro['seccion'] <> "") {
            $sql .= " and r2.tag_id = " . $filtro['seccion'];
        }

        if ($filtro['texto'] <> "") {
            $sql .= " and n.titulo like '%" . $filtro['texto'] . "%'";
        }

        $sql .= ' and n.habilitada=1 AND n.id NOT IN (SELECT id_contenido FROM mockup_contenidos WHERE tipo=13 and hash_id = ' . $filtro['hash_id'] . ') 
		order by n.id desc limit 50';
        //echo $sql; die();
        $query = $this->db->query($sql);
        if ($res = $query->result_array()) {
            $num = $query->num_rows();
            if ($num > 0) {
                foreach ($res as $k => $v) {
                    $res[$k]['seccion'] = $this->dame_secciones($v['id'], '', ', ');
                    //$res[$k]['imagen'] = $this->dameImagenFirmaDestacada($v['id']);
                }
            }
            return $res;
        } else {
            return false;
        }
    }

    public function dameImagenDestacada($nota_id) {
        $sql = "select CONCAT( f.ruta , 'th_' , f.imagen ) as imagen 
		from foto f 
		inner join relacion r on (f.id = r.objeto_id and r.tipo = 30) 
		where r.nota_id = " . $nota_id . " 
		order by r.destacado desc limit 1";
        //echo $sql;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0]['imagen'];
        } else
            return "";
    }

    public function dameImagenDestacadaSolr($nota_id) {
        $sql = "select CONCAT( f.ruta , 'tmb2_' , f.imagen ) as imagen 
		from foto f 
		inner join relacion r on (f.id = r.objeto_id and r.tipo = 30) 
		where r.nota_id = " . $nota_id . " 
		order by r.destacado desc limit 1";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0]['imagen'];
        } else
            return "";
    }

    public function dameImagenesDestacadas($array_nota_id) {
        $array_nota_id = implode(',', $array_nota_id);
        $sql = "select r.nota_id,CONCAT( f.ruta , 'tmb2_' , f.imagen ) as imagen 
		from foto f 
		inner join relacion r on (f.id = r.objeto_id and r.tipo = 30) 
		where r.nota_id in (" . $array_nota_id . ") and r.destacado = 1
		order by r.destacado desc";

        $query = $this->db->query($sql);
        //echo 'query: '.$this->db->last_query();
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return "";
    }

    public function dame_secciones($id_nota, $pre, $post) {
        $sql = "select s.nombre 
		from tag s 
		inner join (
			select tag_id from relacion_tag where nota_id = " . $id_nota . " and tipo = 5 
		) as sec on (sec.tag_id = s.id)";
        $query = $this->db->query($sql);
        $res = $query->result_array();
        $concat = "";
        if (count($res) > 0) {
            $i = 0;
            foreach ($res as $k => $v) {
                if ($i == 0) {
                    $i = 1;
                    $concat .= $pre . $v['nombre'];
                } else
                    $concat .= $post . $pre . $v['nombre'];
            }
        }
        return $concat;
    }

    public function existe_nota($id, $hash_id) {
        $this->db->select("n.id,c.id as id_cont");
        $this->db->from("nota n");
        $this->db->join("mockup_contenidos c", "c.id_contenido=n.id", "inner");
        $this->db->where("c.hash_id", $hash_id);
        $this->db->where("c.tipo", 1);
        $this->db->where("n.id", $id);
        $query = $this->db->get();
        $res = $query->result_array();
        if (count($res) > 0)
            return $res[0]['id_cont'];
        else
            return false;
    }

    public function existe_evento($id, $hash_id) {
        $this->db->select("e.id,c.id as id_cont");
        $this->db->from("evento e");
        $this->db->join("mockup_contenidos c", "c.id_contenido=e.id", "inner");
        $this->db->where("c.hash_id", $hash_id);
        $this->db->where("c.tipo", 1);
        $this->db->where("e.id", $id);
        $query = $this->db->get();
        $res = $query->result_array();
        if (count($res) > 0)
            return $res[0]['id_cont'];
        else
            return false;
    }

    public function existe_columna($id, $hash_id) {
        $this->db->select("n.id,c.id as id_cont");
        $this->db->from("nota n");
        $this->db->join("mockup_contenidos c", "c.id_contenido=n.id", "inner");
        $this->db->where("c.hash_id", $hash_id);
        $this->db->where("c.tipo", 12);
        $this->db->where("n.id", $id);
        $query = $this->db->get();
        $res = $query->result_array();
        if (count($res) > 0)
            return $res[0]['id_cont'];
        else
            return false;
    }

    public function existe_blog($id, $hash_id) {
        $this->db->select("n.id,c.id as id_cont");
        $this->db->from("nota n");
        $this->db->join("mockup_contenidos c", "c.id_contenido=n.id", "inner");
        $this->db->where("c.hash_id", $hash_id);
        $this->db->where("c.tipo", 13);
        $this->db->where("n.id", $id);
        $query = $this->db->get();
        $res = $query->result_array();
        if (count($res) > 0)
            return $res[0]['id_cont'];
        else
            return false;
    }

    public function actualizar_nota_caja($id_cont, $id, $caja_id, $hash_id, $i) {
        $datos['hash_id'] = $hash_id;
        $datos['caja_id_aux'] = $caja_id;
        $datos['orden_aux'] = $i;
        $this->db->where('id', $id_cont);
        //$this->db->where('id_contenido', $id);
        if ($this->db->update('mockup_contenidos', $datos))
            return true;
        else
            return false;
    }

    public function actualizar_evento_caja($id_cont, $id, $caja_id, $hash_id, $i) {
        $datos['hash_id'] = $hash_id;
        $datos['caja_id_aux'] = $caja_id;
        $datos['orden_aux'] = $i;
        $this->db->where('id', $id_cont);
        //$this->db->where('id_contenido', $id);
        if ($this->db->update('mockup_contenidos', $datos))
            return true;
        else
            return false;
    }

    public function actualizar_columna_caja($id_cont, $id, $caja_id, $hash_id, $i) {
        $datos['hash_id'] = $hash_id;
        $datos['caja_id_aux'] = $caja_id;
        $datos['orden_aux'] = $i;
        $this->db->where('id', $id_cont);
        //$this->db->where('id_contenido', $id);
        if ($this->db->update('mockup_contenidos', $datos))
            return true;
        else
            return false;
    }

    public function actualizar_blog_caja($id_cont, $id, $caja_id, $hash_id, $i) {
        $datos['hash_id'] = $hash_id;
        $datos['caja_id_aux'] = $caja_id;
        $datos['orden_aux'] = $i;
        $this->db->where('id', $id_cont);
        //$this->db->where('id_contenido', $id);
        if ($this->db->update('mockup_contenidos', $datos))
            return true;
        else
            return false;
    }

    public function crear_nota_caja($id, $caja_id, $hash_id, $i, $nota) {
        $this->db->set('nota_antetitulo', $nota['antetitulo']);
        $this->db->set('imagen', $nota['imagen_destacada']);
        $this->db->set('ruta', $nota['ruta_destacada']);
        $this->db->set('marca', $nota['marca_destacada']);
        $this->db->set('hora', $nota['hora']);
        $this->db->set('link', $nota['link']);
        $this->db->set('nota_titulo', $nota['titulo']);
        $this->db->set('nota_bajada', $nota['sumario']);
        $this->db->set('nota_seccion', $nota['nota_seccion']);
        $this->db->set('video_en_nota', $nota['video_en_nota']);
        $this->db->set('patrocinado', $nota['patrocinado']);
        $this->db->set('mapa', $nota['mapa']);
        $this->db->set('hash_id', $hash_id);
        $this->db->set('id_contenido', $id);
        $this->db->set('tipo', 1);
        $this->db->set('caja_id_aux', $caja_id);
        $this->db->set('orden_aux', $i);
        //$this->db->set('lleva_comentarios',$nota['permisoComent']);
        $this->db->set('lleva_comentarios', 1);
        $this->db->set('estilo', 'nhome');
        $this->db->set('tiene_video', $nota['tiene_video']);
        $this->db->set('tiene_galeria', $nota['tiene_galeria']);
        $fecha = explode('-', $nota['fecha']);
        $fecha = $fecha[2] . '-' . $fecha[1] . '-' . $fecha[0];
        $this->db->set('fecha', $fecha);
        $this->db->insert('mockup_contenidos');
        return true;
    }
    
     public function crear_evento_caja($id, $caja_id, $hash_id, $i, $evento) {
        $this->db->set('imagen', $evento['imagen_destacada']);
        $this->db->set('ruta', $evento['ruta_destacada']);
        $this->db->set('hora', $evento['hora']);
        $this->db->set('link', $evento['link']);
        $this->db->set('nota_titulo', $evento['titulo']);
        $this->db->set('hash_id', $hash_id);
        $this->db->set('id_contenido', $id);
        $this->db->set('tipo', 7);
        $this->db->set('caja_id_aux', $caja_id);
        $this->db->set('orden_aux', $i);
        //$this->db->set('lleva_comentarios',$nota['permisoComent']);
        $this->db->set('estilo', 'nhome');
        //$this->db->set('tiene_video', $nota['tiene_video']);
        $fecha = explode('-', $evento['fecha']);
        $fecha = $fecha[2] . '-' . $fecha[1] . '-' . $fecha[0];
        $this->db->set('fecha', $fecha);
        $this->db->insert('mockup_contenidos');
        return true;
    }

    public function crear_columna_caja($id, $caja_id, $hash_id, $i, $nota) {
        $this->db->set('nota_antetitulo', $nota['antetitulo']);
        $this->db->set('imagen', $nota['firma_id']);
        $this->db->set('hora', $nota['hora']);
        $this->db->set('link', $nota['link']);
        $this->db->set('nota_titulo', $nota['titulo']);
        $this->db->set('nota_bajada', $nota['sumario']);
        $this->db->set('nota_seccion', $nota['nota_seccion']);
        $this->db->set('video_en_nota', $nota['video_en_nota']);
        $this->db->set('patrocinado', $nota['patrocinado']);
        $this->db->set('mapa', $nota['mapa']);
        $this->db->set('hash_id', $hash_id);
        $this->db->set('id_contenido', $id);
        $this->db->set('tipo', 12);
        $this->db->set('caja_id_aux', $caja_id);
        $this->db->set('orden_aux', $i);
        //$this->db->set('lleva_comentarios',$nota['permisoComent']);
        $this->db->set('lleva_comentarios', 1);
        $this->db->set('estilo', 'nhome');
        $this->db->set('tiene_video', 0);
        $this->db->set('tiene_galeria', 0);
        $this->db->set('nota_seccion', $nota['nota_seccion']);
        $this->db->insert('mockup_contenidos');
        return true;
    }

    public function crear_blog_caja($id, $caja_id, $hash_id, $i, $nota) {
        $this->db->set('nota_antetitulo', $nota['antetitulo']);
        $this->db->set('imagen', $nota['firma_id']);
        $this->db->set('hora', $nota['hora']);
        $this->db->set('link', $nota['link']);
        $this->db->set('nota_titulo', $nota['titulo']);
        $this->db->set('nota_bajada', $nota['sumario']);
        $this->db->set('nota_seccion', $nota['nota_seccion']);
        $this->db->set('video_en_nota', $nota['video_en_nota']);
        $this->db->set('patrocinado', $nota['patrocinado']);
        $this->db->set('mapa', $nota['mapa']);
        $this->db->set('hash_id', $hash_id);
        $this->db->set('id_contenido', $id);
        $this->db->set('tipo', 13);
        $this->db->set('caja_id_aux', $caja_id);
        $this->db->set('orden_aux', $i);
        //$this->db->set('lleva_comentarios',$nota['permisoComent']);
        $this->db->set('lleva_comentarios', 1);
        $this->db->set('estilo', 'nhome');
        $this->db->set('tiene_video', 0);
        $this->db->set('tiene_galeria', 0);
        $this->db->set('nota_seccion', $nota['nota_seccion']);
        $this->db->insert('mockup_contenidos');
        return true;
    }

    public function dameCantComentariosXml($nota_id) {
        $this->db->select("count(id) as cant");
        $this->db->from("comentario");
        $this->db->where("tipo", 32);
        $this->db->where("objeto_id", $nota_id);
        $query = $this->db->get();
        $res = $query->result_array();
        if (count($res) > 0)
            return $res[0]['cant'];
        else
            return false;
    }

    public function dameComentariosNotasXml($seccion_id) {
        $sql = "SELECT c.id_contenido AS nota_id,(SELECT COUNT(com.id) FROM comentario com WHERE com.objeto_id=c.id_contenido ) AS comentarios FROM layout_contenidos c
WHERE c.seccion_id=" . $seccion_id . " AND c.tipo=1 AND caja_id IS NOT NULL";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function notasRssUM($edicion_id) {
        $sql = "SELECT n.id, n.titulo, n.sumario AS bajada, n.url, (SELECT s.nombre 
				FROM tag s 
				WHERE s.tipo_id = n.id_seccion 
				LIMIT 1) AS seccion, DATE_FORMAT(n.fechaAlta, '%d/%m/%Y %H:%i:%s') AS fecha 
				FROM nota n 
				WHERE n.edicion_id = " . $edicion_id . " AND n.habilitada=1 AND (lector=0 OR lector IS NULL)  
				ORDER BY n.id DESC";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function notasRssSeleccionadas($edicion_id) {
        $sql = "select n.id, n.titulo, n.sumario as bajada, n.url, (select s.nombre 
			from tag s 
			inner join relacion_tag re on (re.tag_id = s.id and re.tipo = 5) 
			where re.nota_id = n.id and s.tipo_id = 5 
			limit 1) as seccion, DATE_FORMAT(n.fechaAlta, '%d/%m/%Y %H:%i:%s') as fecha 
			from nota n 
			where n.edicion_id = " . $edicion_id . " and n.habilitada=1 and n.um = 0 and (lector=0 OR lector IS NULL)    
			order by n.id desc";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function notasRssSeccion($seccion_id, $edicion_id) {
        $sql = "SELECT n.id, n.titulo, n.sumario AS bajada, n.url, (SELECT s.nombre 
			FROM tag s 
			INNER JOIN relacion_tag re ON (re.tag_id = s.id AND re.tipo = 5) 
			WHERE re.nota_id = n.id and s.tipo_id = 5 
			LIMIT 1) AS seccion, DATE_FORMAT(n.fechaAlta, '%d/%m/%Y %H:%i:%s') AS fecha 
			FROM nota n 
			INNER JOIN relacion_tag r ON r.nota_id=n.id			
			WHERE n.edicion_id = '" . $edicion_id . "' AND r.tag_id='" . $seccion_id . "' AND r.tipo=5 and n.habilitada=1 ORDER BY n.fechaAlta desc";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function listadoPorTag($tag_id, $edicion_id, $start = 0, $limit = 20) {
        $edicion_ant = $edicion_id - 100;

        $sql = "select n.id, n.anteTitulo as antetitulo, n.titulo, n.sumario as bajada, 
		DATE_FORMAT(n.fechaAlta, '%d/%m/%Y') as fecha, n.url, 
		(
			select CONCAT(f.ruta,'tmb2_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado limit 1
		) as destacada,
		(
			select s.nombre 
			from tag s 
			inner join relacion_tag re on (re.tag_id = s.id and re.tipo = 5) 
			where re.nota_id = n.id and s.tipo_id = 5 
			limit 1
		) as seccion_nombre
		from nota n 
		inner join relacion_tag r on (n.id = r.nota_id and r.tipo in(1,2,4))  
		where r.tag_id = " . $tag_id . " and n.habilitada = 1 
		and n.edicion_id between $edicion_ant and " . $edicion_id . "
		order by n.id desc limit $start,$limit";


        $query = $this->db->query($sql);
        //echo $this->db->last_query();
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameNotaDesdeVideo($video_id) {
        $sql = "SELECT n.id, n.titulo, n.url, n.edicion_id, 
					(select CONCAT_WS('|',s.nombre,s.url) 
					  from tag s 
					  inner join relacion_tag r on (s.id = r.tag_id and r.tipo=5) 
					  where r.nota_id = n.id and s.tipo_id = 5 order by r.orden limit 1) as seccion,
				(
					select CONCAT(f.ruta,'tmb2_',f.imagen) 
					from foto f 
					inner join relacion r2 on (f.id = r2.objeto_id)
					where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado limit 1
				) as destacada
				FROM nota n 
				inner join relacion re on (n.id = re.nota_id and re.tipo = 2) 
				WHERE re.objeto_id = " . $video_id;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function tieneVideo($nota_id) {
        $sql = "SELECT r.*, v.codigo 
				FROM relacion r
				INNER JOIN video v ON v.id = r.objeto_id
				WHERE r.tipo='2' AND 
				r.nota_id='" . $nota_id . "'";

        $query = $this->db->query($sql);

        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function tieneFoto($nota_id) {
        $sql = "SELECT * FROM relacion WHERE tipo='30' AND nota_id='" . $nota_id . "'";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function tieneGaleria($nota_id) {
        $sql = "SELECT * FROM relacion WHERE tipo='5' AND nota_id='" . $nota_id . "'";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    /* Listado de notas por Tag generico */

    public function notasPorTag($tag_id, $edicion_id, $start = 0, $limit = 20) {
        /* if($edicion_id < 1975)	
          $edicion_id_desde = $edicion_id - 240;
          else */
        $edicion_id_desde = $edicion_id - 1000;
        $resto_query_para_sec = " ";

        $sql = "select n.id, n.antetitulo, n.titulo, n.sumario as bajada, n.usuario_id,
		n.url, DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, n.edicion_id, n.um, n.video_en_nota, n.patrocinado, DATE_FORMAT(n.fechamod,'%H:%i') as hora,
		(
			select f.ruta
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as ruta,
		(
			select f.imagen
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada
		from nota n 
		inner join edicion e on (e.id = n.edicion_id)";

        /* 		if ($listado == 2)
          $sql .= " where n.edicion_id = $edicion_id";
          else
          $sql .= " where n.edicion_id between $edicion_filtro and $edicion_id";
         */
        $sql .= " where n.id_seccion = " . $tag_id;

        $sql .= " and n.edicion_id between " . $edicion_id_desde . " and " . $edicion_id;

        $sql .= " and n.habilitada = 1 and e.habilitada=1";

        $sql .= " order by n.edicion_id desc, n.fechaAlta desc limit $start,$limit";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }
    /* */
    public function getNotasBusqueda($busqueda, $start = 0, $limit = 14) { 
		$texto = explode(" ", $busqueda);
		$total = count($texto);
        $sql = "select distinct n.id, n.antetitulo, n.titulo, n.sumario as bajada, n.usuario_id, n.vista, 
		n.url, DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, n.edicion_id, n.video_en_nota, n.patrocinado, n.um, DATE_FORMAT(n.fechamod,'%H:%i') as hora,
		(
			select concat(f.ruta,f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color, t.alias as alias,
		t2.nombre as subseccion_nombre, t2.id as subseccion_id, t2.color as subseccion_color, 
		t.url as seccion_url  
		from nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
		left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
		left join relacion_tag t3 on (t3.nota_id = n.id and t3.tipo=4)";
		
		if ($total == 1) {
            $sql .= " WHERE (n.titulo like '% $texto[0] %' or n.texto like '% $texto[0] %' or n.antetitulo like '% $texto[0] %' or n.sumario like '% $texto[0] %') AND n.habilitada = 1 ";
        } else {
            $i = 1;
            $ii = 0;
            while ($i < $total) {
                if ($i == 1) {
                    $sql .= " WHERE (n.titulo like '%$texto[0]%' or n.texto like '%$texto[0]%' or n.antetitulo like '%$texto[0]%' or n.sumario like '%$texto[0]%') AND n.habilitada = 1 AND ";
                } else {
                    $sql .= " AND ";
                }
                $sql .= "(n.titulo like '%$texto[$i]%' or n.texto like '%$texto[$i]%' or n.antetitulo like '%$texto[$i]%' or n.sumario like '%$texto[$i]%')";
                $i++;
                $ii++;
            }
        }

       /* $sql .= " where n.habilitada = 1 and e.habilitada = 1 and ( n.titulo LIKE '%".$busqueda."%' or n.antetitulo LIKE '%".$busqueda."%' or n.sumario LIKE '%".$busqueda."%' or n.texto LIKE '%".$busqueda."%' )";*/

		

        $sql .= " order by n.edicion_id desc, n.fechamod desc limit $start, $limit";


        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
 
            return $res;
        }else
        {return false; }
            
        }


        public function cantidadNotasBusqueda($busqueda, $edicion_id) { 

            $max_paginas = 200000000;
            $limit = 14 + (($max_paginas - 1) * 15); 
    
            $edicion_id_desde = $edicion_id - 120;
    
            $sql = "select distinct n.id
            from nota n 
            inner join edicion e on (e.id = n.edicion_id) 
            inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
            left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
            left join relacion_tag t3 on (t3.nota_id = n.id and t3.tipo=4)";
    
    
            $sql .= " where n.titulo LIKE '%".$busqueda."%' and n.habilitada = 1 and e.habilitada = 1";
    
            $sql .= " order by n.edicion_id desc, n.fechamod desc limit 0, $limit";

            $res= $this->db->query($sql);
    
    
            $total_notas = $res->num_rows();
            if($total_notas == $limit) {
                return $max_paginas;
            }elseif($total_notas > 14){
                $aux = $total_notas - 14;
                $aux2 =$aux / 15;
    
                $paginas = ceil($aux2) + 1;
                return $paginas;
            }
            else{
                return 1;
            }
                
            }


    /* Listado de notas por Seccion */

    public function notasPorSeccion($tag_id, $edicion_id, $start = 0, $limit = 30) {
        if($tag_id > 0){ 
            $todos = "(n.id_seccion = " . $tag_id . " or n.id_subseccion = " . $tag_id . " or t3.tag_id = " . $tag_id . ") and";
        } else {
            $todos ='';
        }
        /*$edicion_id_desde = $edicion_id - 120;*/
        $resto_query_para_sec = " ";
        
        $sql = "select distinct n.id, n.antetitulo, n.titulo, n.sumario as bajada, n.usuario_id, n.vista, 
		n.url, DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, n.edicion_id, n.video_en_nota, n.patrocinado, n.um, DATE_FORMAT(n.fechamod,'%H:%i') as hora,
		(
			select concat(f.ruta,f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color, t.alias as alias,
		t2.nombre as subseccion_nombre, t2.id as subseccion_id, t2.color as subseccion_color, 
		t.url as seccion_url  
		from nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
		left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
        left join relacion_tag t3 on (t3.nota_id = n.id and t3.tipo=4)
        where ";

        $sql .= $todos;

        /*$sql .= " n.edicion_id between " . $edicion_id_desde . " and " . $edicion_id;*/

        $sql .= " n.habilitada = 1 and e.habilitada=1";

        $sql .= " order by n.edicion_id desc, n.fechamod desc limit $start, $limit";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            if (is_array($res)) {
                foreach ($res as $k => $not) {
                    $res[$k]['videos'] = $this->tieneVideo($not['id']);
                    $res[$k]['periodista'] = $this->dameFirma($not['id']);
                }
            }
            return $res;
        } else{return false; }
            
       
        
    }

    public function cantidadNotasSeccion($tag_id=0, $edicion_id) {

            if($tag_id > 0){ 
                $todos = "(n.id_seccion = " . $tag_id . " or n.id_subseccion = " . $tag_id . " or t3.tag_id = " . $tag_id . ") and";
            } else {
                $todos ='';
            }

            $max_paginas = 200000000;
            $limit = 14 + (($max_paginas - 1) * 15); 

            /*$edicion_id_desde = $edicion_id - 120;*/

            $sql = "SELECT distinct (n.id) from nota n 
            inner join edicion e on (e.id = n.edicion_id) 
            inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
            left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
            left join relacion_tag t3 on (t3.nota_id = n.id and t3.tipo=4) where";

            $sql .= $todos ;

            /*$sql .= " n.edicion_id between " . $edicion_id_desde . " and " . $edicion_id;*/

            $sql .= " n.habilitada = 1 and e.habilitada=1 limit 0, $limit";

            $res= $this->db->query($sql);

            $total_notas = $res->num_rows();
            if($total_notas == $limit) {
                return $max_paginas;
            }elseif($total_notas > 14){
                $aux = $total_notas - 14;
                $aux2 =$aux / 15;

                $paginas = ceil($aux2) + 1;
                return $paginas;
            }
            else{
                return 1;
            }
        
             

}


        public function cantidadNotasTags($tag_id=0, $edicion_id) { 


            $max_paginas = 200000000;
            $limit = 14 + (($max_paginas - 1) * 15); 

            /*$edicion_id_desde = $edicion_id - 120;*/

            $sql = "SELECT distinct (n.id) from nota n
            inner join edicion e on (e.id = n.edicion_id) 
            inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
            left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
            left join relacion_tag t3 on (t3.nota_id = n.id and t3.tipo=4)";
    
            $sql .= " where (t3.tag_id = " . $tag_id . ")";
    
            /*$sql .= " and n.edicion_id between " . $edicion_id_desde . " and " . $edicion_id;*/
    
            $sql .= " and n.habilitada = 1 and e.habilitada=1";
    
            $sql .= " order by n.edicion_id desc, n.fechamod desc limit 0, $limit";

            $res= $this->db->query($sql);

            $total_notas = $res->num_rows();
            if($total_notas == $limit) {
                return $max_paginas;
            }elseif($total_notas > 14){
                $aux = $total_notas - 14;
                $aux2 =$aux / 15;

                $paginas = ceil($aux2) + 1;
                return $paginas;
            }
            else{
                return 1;
            }
    


            
        }

    public function notasPorSeccionLimitadas($tag_id=0, $edicion_id, $ids = NULL, $start = 0, $limit = 30) {
        $edicion_id_desde = $edicion_id - 120;
        $resto_query_para_sec = " ";

        $sql = "select distinct n.id, n.antetitulo, n.titulo, n.sumario as bajada, n.usuario_id,
		n.url, DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, n.edicion_id, n.video_en_nota, n.patrocinado, n.um, DATE_FORMAT(n.fechamod,'%H:%i') as hora,
		(
			select concat(f.ruta,f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color,
		t2.nombre as subseccion_nombre, t2.id as subseccion_id, t2.color as subseccion_color, 
		t.url as seccion_url  
		from nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
		left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
		left join relacion_tag t3 on (t3.nota_id = n.id and t3.tipo=4)";

        $sql .= " where (n.id_seccion = " . $tag_id . " or n.id_subseccion = " . $tag_id . " or t3.tag_id = " . $tag_id . ")";

        $sql .= " and n.edicion_id between " . $edicion_id_desde . " and " . $edicion_id;

        $sql .= " and n.habilitada = 1 and e.habilitada=1";

        if ($ids)
            $sql .= " and n.id not in (" . $ids . ")";

        $sql .= " order by n.edicion_id desc, n.fechamod desc limit $start,$limit";
        //echo $sql;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            foreach ($res as $k => $not) {
                $res[$k]['videos'] = $this->tieneVideo($not['id']);
                $res[$k]['periodista'] = $this->dameFirma($not['id']);
            }

        
            return $res;
        } else
            return false;
    }

    public function dameTagSeccionDeNota($nota_id) {
        $sql = "select t.id, t.nombre, t.color from tag t 
		inner join (select tag_id from relacion_tag where nota_id = " . $nota_id . " and tipo=5) rel_tg on (rel_tg.tag_id = t.id)";
        $query = $this->db->query($sql);
        $res = $query->result_array();
        return $res[0];
    }

    public function dameHoraUM($nota_id = 0) {
        if ($nota_id > 0) {
            $sql = "select DATE_FORMAT(fechamod,'%H:%I') as hora, um from nota where id = " . $nota_id;
            $query = $this->db->query($sql);
            if ($query->num_rows() > 0) {
                $res = $query->result_array();
                return $res[0];
            } else
                return false;
        } else
            return false;
    }

    public function dameNombreUrlBlog($blog_id) {
        $sql = "select nombre_url from blog where seccion_id = " . $blog_id;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0]['nombre_url'];
        } else
            return false;
    }

    /* nuevo: traer padre */

    public function tienePadre($id) {

        $sql = "select padre_id from tag where id = " . $id;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0]['padre_id'];
        } else
            return false;
    }

    public function dameCompartidas($nota_id) {
        $sql = "select compartidas from nota_visitas where nota_id = " . $nota_id;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0]['compartidas'];
        } else
            return 0;
    }

    /* favoritas */

    public function dameIdNotasFavoritas($usuario_id) {

        $sql = "select nota_id from usuario_nota_reservada where usuario_id =  " . $usuario_id;
        //$sql="select nota_id from usuario_nota_reservada where usuario_id = 108109";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameUsuarioParaNotas($nota_id) {

        $sql = "select u.id, u.usuario,u.estado from usuario u inner join nota n on (n.usuario_id = u.id) 
				where n.id = " . $nota_id;

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res[0];
        } else
            return false;
    }

    public function actualizaCompartidas($nota_id, $compartidas) {
        $sql = "update nota_visitas set compartidas = " . $compartidas . " where nota_id = " . $nota_id;
        if ($this->db->query($sql))
            return true;
        else
            return false;
    }

    public function dameNotasTagHome($edicion_id, $seccion_id, $campo, $not_in = "", $limit = 20) {
        
        if($seccion_id == 0) {$la_seccion = '';}else {$la_seccion = " and n.id_seccion = " . $seccion_id;}
        if ($edicion_id > 0) {
            $edicion_desde = $edicion_id - 60;
            $join = "";
            $where = "";
            if ($campo == "mas_leido") {
                $campo = "mas_leido";
                $join = " inner join nota_visitas nv on (nv.nota_id = n.id)";
            } elseif ($campo == "opinion") {
                $campo = "opinion";
                $join = " inner join relacion rr on (n.id = rr.nota_id)";
                $where = "  rr.nota_id IN ( SELECT * FROM (SELECT MAX(r3.nota_id) as nota_id FROM relacion r3 WHERE r3.tipo = 4 GROUP BY r3.objeto_id LIMIT 100) AS t) and rr.tipo = 4 and";
            } else {
                $campo = "ultimo";
            }

            $sql = "select n.id, n.titulo, n.anteTitulo as antetitulo, n.sumario as bajada, date_format(e.fecha,'%d-%m-%Y') as fecha, n.video_en_nota, n.patrocinado, n.vista,
			(
				select CONCAT(f.ruta,f.imagen) 
				from foto f 
				inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
				where r2.nota_id = n.id order by r2.destacado desc limit 1
			) as destacada, t.nombre as subseccion, t.color as color, t.alias as alias 
			from nota n  
                        INNER JOIN edicion e on (e.id = n.edicion_id)
			" . $join . "
			left join tag t on t.id = n.id_seccion
			where" . $where . " n.edicion_id between " . $edicion_desde . " and " . $edicion_id . $la_seccion . " and n.habilitada = 1";

            if ($not_in != "") {
                $sql .= " and n.id not in (" . $not_in . ")";
            }
            if ($campo == "ultimo") {
                $sql .= " order by n.edicion_id desc, n.id desc";
            } elseif ($campo == "opinion") {
                $sql .= " order by n.edicion_id desc, n.id desc";
            } else {
                $sql .= " order by nv.visitas desc ";
            }
            $sql .= " limit " . $limit;

            $query = $this->db->query($sql);
            if ($query->num_rows() > 0) {
                $res = $query->result_array();
                foreach ($res as $k => $not) {
                    $res[$k]['videos'] = $this->tieneVideo($not['id']);
                    $res[$k]['periodista'] = $this->dameFirma($not['id']);
                }
                
                return $res;
            } else
                return false;
        } else
            return false;
    }

    public function dameBreves() {
        $sql = "SELECT titulo, bajada, orden, estado, url, foto FROM breves where estado != 0 order by id desc limit 10";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function DameEnFoco() {
        $sql = "SELECT titulo,foto , bajada, orden, url, estado FROM enfoco where estado != 0 order by id desc limit 10";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }



    public function dameIdNotasdiagramadas($hash_ids) {
        $sql = "SELECT id_contenido FROM mockup_contenidos WHERE hash_id IN (" . $hash_ids . ")";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function notasEdActual($edicion_id, $start, $limit) {
        $sql = "select n.id, n.titulo, n.fechamod as fecha, n.url, 
		(
			select CONCAT(f.ruta,'th_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada,
		(
			select CONCAT_WS('|',s.nombre,s.color) as nom
			from tag s 
			inner join relacion_tag re on (re.tag_id = s.id and re.tipo = 5) 
			where re.nota_id = n.id and s.tipo_id = 5
			limit 1
		) as seccion_nombre
		from nota n  
		where n.edicion_id = " . $edicion_id . " and n.um = 1 and n.habilitada = 1";

        $sql .= " order by n.id desc limit " . $start . "," . $limit;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    //Metodos para el nuevo diagramador
    public function dameUltimasNotasDiagramador($edicion_id, $cant) {
        $edicion_id = $edicion_id - 1;
        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista,  
		(
			select f.ruta
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
 		) as ruta,
		(
			select f.imagen
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
 		) as destacada,
		(select s.nombre from tag s where s.id = n.id_seccion) as seccion 
		FROM nota n
                INNER JOIN edicion e on (e.id = n.edicion_id)
		WHERE n.edicion_id >= " . $edicion_id . " and n.habilitada = 1 
		AND n.id NOT IN (SELECT objeto_id FROM diagramador_bloque_objeto WHERE tipo=1) 
		order by n.id desc limit " . $cant;


        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();

            return $res;
        } else
            return false;
    }

    public function filtrarNotasDiagramador($filtro) {

        $sql = "select n.id, n.titulo, n.antetitulo, n.sumario, e.fecha as fechaAlta, (
			select CONCAT(f.ruta,'th_',f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
 		) as destacada, s.nombre as seccion";
        $sql .= " from nota n";
        $sql .= " inner join tag s on s.id = n.id_seccion";
        $sql .= " inner join edicion e on (e.id = n.edicion_id)";

        if ($filtro['seccion'] <> "") {
            $sql .= " inner join relacion_tag r on (r.nota_id=n.id and r.tipo=5)";
        }


        if ($filtro['edicion_desde'] and ! $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  = " . $filtro['edicion_desde'];

        if (!$filtro['edicion_desde'] and $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  = " . $filtro['edicion_hasta'];

        if ($filtro['edicion_desde'] and $filtro['edicion_hasta'])
            $sql .= " where n.edicion_id  between " . $filtro['edicion_desde'] . " and " . $filtro['edicion_hasta'];

        if ($filtro['um'] == "true") {
            $sql .= " and n.um = 1";
        }

        if ($filtro['seccion'] <> "") {
            $sql .= " and r.tag_id = " . $filtro['seccion'];
        }

        if ($filtro['texto'] <> "") {
            $sql .= " and n.titulo like '%" . $filtro['texto'] . "%'";
        }
        $sql .= ' and n.habilitada=1 AND n.id NOT IN (SELECT objeto_id FROM diagramador_bloque_objeto WHERE tipo=1 ) order by n.id desc limit 50';
        //echo $sql; die();
        $query = $this->db->query($sql);
        if ($res = $query->result_array()) {
            $num = $query->num_rows();
            if ($num > 0) {
                foreach ($res as $k => $v) {
                    //$res[$k]['seccion']=$this->dame_secciones($v['id'],'',', ');
                    $res[$k]['destacada'] = $this->dameImagenDestacada($v['id']);
                }
            }
            return $res;
        } else {
            return false;
        }
    }

    //Metodo para traer las 3 notas por sección del home
    public function dameUltimasNotasSeccionHome($edicion_id, $tag_id, $bloque_id, $cant = 3) {
        $edicion_id = $edicion_id - 5;
        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.habilitada, n.edicion_id, n.um, 
		n.permisoComent, n.url, n.video_en_nota, n.patrocinado, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
		DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista,  
		(
			select f.ruta
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
 		) as ruta,
		(
			select f.imagen
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
 		) as foto
		FROM nota n 
                INNER JOIN edicion e on (e.id = n.edicion_id)
		inner join relacion_tag r on (r.nota_id = n.id)
		WHERE n.edicion_id >= " . $edicion_id . " and r.tag_id = " . $tag_id . " and n.habilitada = 1 
		AND n.id NOT IN (SELECT objeto_id FROM diagramador_bloque_objeto WHERE tipo=1 and bloque_id <>" . $bloque_id . ") 
		order by n.id desc limit " . $cant;

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();

            return $res;
        } else
            return false;
    }

    public function actualizar_nota_diagramador($nota_id, $datos) {
        $this->db->where('id', $nota_id);
        if ($this->db->update('nota', $datos)) {
            return true;
        } else {
            return false;
        }
    }

    public function dameUltimasDerecha($edicion_id, $limit) {
        $edicion_id = $edicion_id - 1;
        $sql = "SELECT n.id, n.titulo, n.url, DATE_FORMAT(n.fechamod, '%d-%m-%Y') AS fecha, DATE_FORMAT(n.fechamod, '%H:%i') as hora, s.nombre AS seccion,
		  (
			select concat(f.ruta,f.imagen)
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		   ) as foto
		  FROM nota n 
		  INNER JOIN edicion e ON (e.id = n.edicion_id) 
		  INNER JOIN tag s ON (s.id = n.id_seccion) 
		  WHERE n.edicion_id >= " . $edicion_id . " AND n.norank = 0 AND n.habilitada = 1";

        $sql .= " ORDER BY n.edicion_id DESC, n.fechamod DESC LIMIT $limit";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameMasVistasDerecha($edicion_id = 0, $seccion_id = 0, $limit = "10") {
        $edicion_id = ($edicion_id - 2);

        $sql = "SELECT n.id, n.titulo, n.url, n.sumario, DATE_FORMAT(n.fechamod, '%d-%m-%Y') AS fecha, 
		DATE_FORMAT(n.fechamod, '%H:%i') as hora, s.nombre AS seccion, s.color as seccion_color, s.id as seccion_id, 
		s.url as seccion_url, 
		  (
			select concat(f.ruta,f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id)
			where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		   ) as foto, nv.visitas, nv.ranking
		  FROM nota n 
		  INNER JOIN edicion e ON (e.id = n.edicion_id) 
		  INNER JOIN nota_visitas nv ON (nv.nota_id=n.id)
		  INNER JOIN tag s ON (s.id = n.id_seccion) 
		  WHERE n.edicion_id > " . $edicion_id . " AND n.norank = 0 AND n.habilitada = 1";

        /*if ($seccion_id > 0)
            $sql .= " and (n.id_seccion = " . $seccion_id . " or n.id_subseccion = " . $seccion_id . ")"; */

        $sql .= " ORDER BY nv.ranking desc LIMIT " . $limit;

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            /*if (is_array($res)) {
                foreach ($res as $k => $not) {
                    $res[$k]['videos'] = $this->tieneVideo($not['id']);
                }
            }*/
            return $res;
        } else
            return false;
    }

    public function dameNotasRelacionadasVideo($video_id) {
        $sql = "SELECT n.id, n.titulo, n.url, n.sumario, n.anteTitulo,
					(select s.nombre 
					  from tag s 
					  inner join relacion_tag r on (s.id = r.tag_id and r.tipo=5) 
					  where r.nota_id = n.id and s.tipo_id = 5 limit 1) as seccion,
				(
					select concat(f.ruta,f.imagen)
					from foto f 
					inner join relacion r2 on (f.id = r2.objeto_id)
					where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 		) as destacada
				FROM nota n 
				inner join relacion re on (n.id = re.nota_id and re.tipo = 2) 
				WHERE re.objeto_id = " . $video_id . " and n.habilitada = 1 ORDER BY n.id DESC";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function ranking($edicion_id, $campo = "leidas", $limit = "6", $order = "desc") {

        if ($edicion_id > 0) {
            $edicion_id_ant = $edicion_id - 1;
            $res = false;
            switch ($campo) {
                case 'leidas':
                    $sql = "select n.id, n.titulo, n.url,
						t.nombre as seccion, n.sumario,
						(
							select f.ruta
							from foto f 
							inner join relacion r2 on (f.id = r2.objeto_id)
							where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
				 		) as ruta,
						(
							select f.imagen
							from foto f 
							inner join relacion r2 on (f.id = r2.objeto_id)
							where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
				 		) as destacada
						from nota n 
						inner join tag t on t.id = n.id_seccion
						left JOIN nota_visitas nv on (n.id = nv.nota_id) 
						where n.edicion_id between " . $edicion_id_ant . " and " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
						order by nv.visitas " . $order . " limit " . $limit;
                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0) {
                        $res = $query->result_array();
                    }
                    break;
                case 'nuevas':
                    $sql = "select n.id, n.titulo, n.url,
						t.nombre as seccion, n.sumario,
						(
							select f.ruta
							from foto f 
							inner join relacion r2 on (f.id = r2.objeto_id)
							where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
				 		) as ruta,
						(
							select f.imagen
							from foto f 
							inner join relacion r2 on (f.id = r2.objeto_id)
							where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
				 		) as destacada
						from nota n 
						inner join tag t on t.id = n.id_seccion
						where n.edicion_id between " . $edicion_id_ant . " and " . $edicion_id . " and n.norank = 0 and n.habilitada = 1 
						order by n.fechaAlta " . $order . " limit " . $limit;

                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0) {
                        $res = $query->result_array();
                    }
                    break;
            }
            return $res;
        } else
            return false;
    }

    public function dameNotasImpreso($edicion_id) {
        $sql = "select n.id, n.titulo, n.anteTitulo AS antetitulo, n.url, t.nombre as seccion, n.sumario as bajada, n.edicion_id, 
				DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, DATE_FORMAT(n.fechamod,'%H:%i') as hora, 
				(
					select CONCAT(f.ruta,f.imagen) as imagen
					from foto f 
					inner join relacion r2 on (f.id = r2.objeto_id)
					where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 		) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color, 
				t.url as seccion_url  
				from nota n 
				inner join edicion e on (e.id = n.edicion_id) 
				inner join tag t on t.id = n.id_seccion
				where n.edicion_id = " . $edicion_id . " and n.habilitada = 1 and n.um = 0  
				order by t.id ASC, n.id ASC";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameMenu($id_menu, $edicion_id = 0) {

        $sql = "SELECT me.id, me.titulo, me.href, me.onclick, me.target, me.class_desk, me.class_mobile, me.icon, me.titulo_visible
				FROM menu_elementos me
				INNER JOIN menu m ON (m.id = me.menu_id)
				WHERE me.menu_id = " . $id_menu . " AND me.habilitado = 1 AND m.habilitado = 1 
				ORDER BY orden ASC";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            foreach ($res as $key => $menu) {
                $notas = $this->notasPorSeccion($menu['class_mobile'], $edicion_id, 0, 4);
                $subsecciones = $this->dameHijos($menu['class_mobile']);
                $res[$key]['notas'] = $notas;
                $res[$key]['subsecciones'] = $subsecciones;
            }
            return $res;
        } else
            return false;
    }

    public function dameNotasUM($edicion_id) {
        $sql = "select n.id, n.titulo, n.url, t.nombre as seccion, n.sumario as bajada, 
				DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, n.edicion_id, DATE_FORMAT(n.fechamod,'%H:%i') as hora, 
				(
					select CONCAT(f.ruta,f.imagen) as imagen
					from foto f 
					inner join relacion r2 on (f.id = r2.objeto_id)
					where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 		) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color, 
				t.url as seccion_url 
				from nota n 
				inner join edicion e on (e.id = n.edicion_id) 
				inner join tag t on t.id = n.id_seccion
				where n.edicion_id = " . $edicion_id . " and n.habilitada = 1 and n.um = 1  
				order by t.id ASC, n.id ASC";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else
            return false;
    }

    public function dameHijos($tag_id) {
        if($tag_id) {

        
        $sql = "select id, nombre, url from tag where padre_id = " . $tag_id . " order by orden asc";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        }else{return false;}
        } else {return false;}
    }

    public function traer_id_notas_scroll($seccion_id, $nota_id) {
        $sql = "SELECT n.id, n.titulo, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color FROM nota n INNER JOIN tag t ON (t.id = n.id_seccion AND t.tipo_id=5) WHERE n.id_seccion = " . $seccion_id . " AND n.habilitada = 1 AND n.id <> " . $nota_id . " ORDER BY n.id DESC LIMIT 4";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            return $res;
        } else {
            return false;
        }
    }

    public function dameRelacionasSimples($nota_id, $limit) {
        $this->load->library("varios_library");
        $sql = "SELECT  n.id, n.titulo,  
        DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.antetitulo, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color, t.alias as alias,
                (
					select CONCAT(f.ruta,f.imagen) as imagen
					from foto f 
					inner join relacion r2 on (f.id = r2.objeto_id)
					where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 		) as foto
				FROM nota n 
				INNER JOIN relacion r ON (n.id = r.objeto_id AND r.tipo = 32)
				inner join edicion e on (e.id = n.edicion_id) 	
				INNER JOIN tag t ON (t.id = n.id_seccion AND t.tipo_id=5) 
				WHERE r.nota_id = " . $nota_id . " and n.habilitada = 1 ORDER BY n.id DESC LIMIT ". $limit;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            if (is_array($res)) {
                foreach ($res as $k => $not) {
                    $res[$k]['url'] = $this->varios_library->generar_url(32, $not['id'], $not['titulo'], $not['alias']);
                    $res[$k]['thumbnail'] = site_url("fotos/" .  $not['foto']);
                }
            }
            return $res;
        } else
            return null;
    }


    public function dameRellenoSeccion($seccion_id, $nota_id, $notas_relacionadas = 0, $limit) {
        $this->load->library("varios_library");

        $ids = ' ' . $nota_id;

        foreach ($notas_relacionadas as $nota) {
            $ids .= ', ' . $nota["id"];
        }

        $sql = "SELECT n.id, n.titulo,  
        DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.antetitulo,  t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color, t.alias as alias,
                (
					select CONCAT(f.ruta,f.imagen) as imagen
					from foto f 
					inner join relacion r2 on (f.id = r2.objeto_id)
					where r2.tipo = 30 and r2.nota_id = n.id order by r2.destacado desc limit 1
		 		) as foto
                FROM nota n
                INNER JOIN tag t ON (t.id = n.id_seccion AND t.tipo_id=5)
                inner join edicion e on (e.id = n.edicion_id) 	
                WHERE n.id_seccion = " . $seccion_id . " AND n.habilitada = 1 AND n.id NOT IN ( " . $ids . " ) 
                ORDER BY n.id DESC LIMIT ". $limit;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            if (is_array($res)) {
                foreach ($res as $k => $not) {
                    $res[$k]['url'] = $this->varios_library->generar_url(32, $not['id'], $not['titulo'], $not['alias']);
                    $res[$k]['thumbnail'] = site_url("fotos/" .  $not['foto']);

                }
            }
            return $res;
        } else {
            return false;
        }
    }
    /* Listado de notas por Periodista */

    public function notasPorPeriodista($usuario_id, $start = 0, $limit = 30) {

        //COMIENZA FUNCION PARA ID UNICO EN ARRAY
        function unique_multidim_array($array, $key) {
            $temp_array = array();
            $i = 0;
            $key_array = array();

            foreach ($array as $val) {
                if (!in_array($val[$key], $key_array)) {
                    $key_array[$i] = $val[$key];
                    $temp_array[$i] = $val;
                }
                $i++;
            }
            return $temp_array;
        }

        //FIN FUNCION ARRAY
        //FUNCION PARA ORDENAR ARRAY POR CLAVE (ID O LO QUE SEA)
        function array_sort($array, $on, $order = SORT_ASC) {
            $new_array = array();
            $sortable_array = array();

            if (count($array) > 0) {
                foreach ($array as $k => $v) {
                    if (is_array($v)) {
                        foreach ($v as $k2 => $v2) {
                            if ($k2 == $on) {
                                $sortable_array[$k] = $v2;
                            }
                        }
                    } else {
                        $sortable_array[$k] = $v;
                    }
                }

                switch ($order) {
                    case SORT_ASC:
                        asort($sortable_array);
                        break;
                    case SORT_DESC:
                        arsort($sortable_array);
                        break;
                }

                foreach ($sortable_array as $k => $v) {
                    $new_array[$k] = $array[$k];
                }
            }

            return $new_array;
        }

        //FIN FUNCION PARA ORDENAR ARRAY
        $edicion_id_desde = $edicion_id - 120;
        $resto_query_para_sec = " ";

        $sql = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.texto, n.habilitada, n.edicion_id, n.um, 
			n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
			DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista, DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha_edicion,
			r.objeto_id as firma_id,
			(
			select concat(f.ruta,f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
			) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color,
			t2.nombre as subseccion_nombre, t2.id as subseccion_id, t2.color as subseccion_color, 
			t.url as seccion_url 
			FROM nota n 
			inner join edicion e on (e.id = n.edicion_id)
			inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
			left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
			inner join relacion r on (r.nota_id = n.id)
			WHERE r.tipo = 4 and 
			r.objeto_id = " . $usuario_id . " and n.id_seccion = 92 and n.habilitada = 1 and e.habilitada=1";

        $sql .= " order by n.edicion_id desc, n.fechamod desc limit $start,$limit";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            if (is_array($res)) {
                foreach ($res as $k => $not) {
                    $res[$k]['videos'] = $this->tieneVideo($not['id']);
                    $res[$k]['periodista'] = $this->dameFirma($not['id']);
                }
            }
        }
        //YA TRAJIMOS OPINION, AHORA TRAER NOTAS FIRMADAS
        $sql2 = "SELECT n.id, n.titulo, n.antetitulo, n.sumario, n.texto, n.habilitada, n.edicion_id, n.um, 
			n.permisoComent, n.url, DATE_FORMAT(n.fechamod, '%H:%i') as hora, 
			DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha, n.vista, DATE_FORMAT(e.fecha, '%d-%m-%Y') as fecha_edicion,
			r.objeto_id as firma_id,
			(
			select concat(f.ruta,f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
			) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color,
			t2.nombre as subseccion_nombre, t2.id as subseccion_id, t2.color as subseccion_color, 
			t.url as seccion_url 
			FROM nota n 
			inner join edicion e on (e.id = n.edicion_id)
			inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
			left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
			inner join relacion r on (r.nota_id = n.id)
			WHERE r.tipo = 4 and 
			r.objeto_id = " . $usuario_id . " and n.habilitada = 1 and e.habilitada=1";

        $query2 = $this->db->query($sql2);
        if ($query2->num_rows() > 0) {
            $res2 = $query2->result_array();
            if (is_array($res2)) {
                foreach ($res2 as $k => $not) {
                    $res2[$k]['videos'] = $this->tieneVideo($not['id']);
                    $res2[$k]['periodista'] = $this->dameFirma($not['id']);
                }
            }
        }
        //FIN NOTAS FIRMADAS
        //DEFINO ARRAY CON AMBAS CONSULTAS:
        for ($i = 0; $i < count($res); $i++) {
            array_push($res2, $res[$i]);
        }
        $result = unique_multidim_array($res2, 'id');
        //array_merge($res2, $res);
        $result = array_sort($result, 'id', SORT_DESC);
        return $result;
        if (!$result) {
            return false;
        }
    }

    public function dameMapas($nota_id) {
        $this->db->select("m.id,m.titulo, m.descripcion, m.latitud, m.longitud, m.zoom");
        $this->db->from("relacion r");
        $this->db->join("mapa m", "m.id=r.objeto_id", "inner");
        $this->db->where("r.nota_id", $nota_id);
        $this->db->where("r.tipo", 29);
        $query = $this->db->get();
        $res = $query->result_array();
        if (is_array($res)) {
            if (count($res) > 0)
                return $res;
        } else
            return false;
    }
    
    public function notasPorTags($tag_id, $edicion_id, $start = 0, $limit = 30) {
        /*$edicion_id_desde = $edicion_id - 20;*/
        $resto_query_para_sec = " ";

        $sql = "select distinct n.id, n.antetitulo, n.titulo, n.sumario as bajada, n.usuario_id, n.vista, 
		n.url, DATE_FORMAT(e.fecha,'%d/%m/%Y') as fecha, n.edicion_id, n.video_en_nota, n.patrocinado, n.um, DATE_FORMAT(n.fechamod,'%H:%i') as hora,
		(
			select concat(f.ruta,f.imagen) 
			from foto f 
			inner join relacion r2 on (f.id = r2.objeto_id and r2.tipo = 30)
			where r2.nota_id = n.id order by r2.destacado desc limit 1
		) as destacada, t.nombre as seccion_nombre, t.id as seccion_id, t.color as seccion_color, t.alias as alias,
		t2.nombre as subseccion_nombre, t2.id as subseccion_id, t2.color as subseccion_color, 
		t.url as seccion_url  
		from nota n 
		inner join edicion e on (e.id = n.edicion_id) 
		inner join tag t on (t.id = n.id_seccion and t.tipo_id=5) 
		left join tag t2 on (t2.id = n.id_subseccion and t2.tipo_id=5)
		left join relacion_tag t3 on (t3.nota_id = n.id and t3.tipo=4)";

        $sql .= " where (t3.tag_id = " . $tag_id . ")";

        /*$sql .= " and n.edicion_id between " . $edicion_id_desde . " and " . $edicion_id;*/

        $sql .= " and n.habilitada = 1 and e.habilitada=1";

        $sql .= " order by n.edicion_id desc, n.fechamod desc limit $start,$limit";

        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $res = $query->result_array();
            if (is_array($res)) {
                foreach ($res as $k => $not) {
                    $res[$k]['videos'] = $this->tieneVideo($not['id']);
                    $res[$k]['periodista'] = $this->dameFirma($not['id']);
                }
            }
            return $res;
        } else
            return false;
    }

}

?>

Anon7 - 2022
AnonSec Team