<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<!--<meta http-equiv="X-UA-Compatible" content="IE=7" />-->
<title>Noticias</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="../vistas/css/estilo.css"/>
<!--[if IE]>
    <link href="../vistas/css/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->

<!--jquery-->
    <script type="text/javascript" src="../js/jquery-1.2.6.min.js"></script>
    <script type="text/javascript" src="../js/jquery.validate.pack.js"></script>
    <script type="text/javascript" src="../js/jquery.maskedinput-1.2.2.min.js"></script>
    <script type="text/javascript" src="../js/jquery.datepick.min.js"></script>
    <script type="text/javascript" src="../js/jquery.datepick-es.js"></script>
<!--jquery-->
<script type="text/javascript">
    jQuery(document).ready(function() {
	$("#editar").validate({
		rules: {
			txtTitulo: "required",
			txtSeccion_id: "required",
			txtFecha_publicacion: {
                            required: true,
                            dateISO: true
                        },
			txtContenido: "required"
		},
		messages: {
                        txtTitulo: "Debe ingresar el titulo!",
                        txtSeccion_id: "Debe seleccionar una secci&oacute;n!",
                        txtFecha_publicacion: "Debe ingresar la fecha de publicaci&oacute;n!",
                        txtContenido: "Debe ingresar contenido!"
		},
		submitHandler: function(){
		    //if(confirm("Esta seguro que los datos ingresados son correctos?")) {
			$.ajax({
				type:"post",
				url:"?opcion=editar",
				data:$("#editar").serialize(),
				success:function(data){
                                    document.location.href= '?opcion=listar';
				}
			});
		    //} 
		    //else {
		    //document.location.href= '#';
		    //}
		}
	});
        
    $("#txtFecha_publicacion").mask("9999/99/99").datepick({dateFormat: 'yy/mm/dd'});
    $("#txtFecha_despublicacion").mask("9999/99/99").datepick({dateFormat: 'yy/mm/dd'});

});
</script>

<!-- Load TinyMCE -->
<script type="text/javascript" src="../plugins/tiny_mce/jquery.tinymce.js"></script>
<script type="text/javascript" src="../plugins/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php"></script>
<script type="text/javascript">
	$().ready(function() {
		$('textarea.tinymce').tinymce({
			// Location of TinyMCE script
			script_url : '../plugins/tiny_mce/tiny_mce.js',

			// General options
			theme : "advanced",
			plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
file_browser_callback : "tinyBrowser",
			// Theme options
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom"
			//theme_advanced_resizing : true,

			// Example content CSS (should be your site CSS)
			//content_css : "css/content.css",

			// Drop lists for link/image/media/template dialogs
			//template_external_list_url : "lists/template_list.js",
			//external_link_list_url : "lists/link_list.js",
			//external_image_list_url : "lists/image_list.js",
			//media_external_list_url : "lists/media_list.js",

			// Replace values for the template plugin
			//template_replace_values : {
			//	username : "Some User",
			//	staffid : "991234"
			//}
		});
	});
</script>
<!-- /TinyMCE -->

</head>
<body>
<div id="contenedor">
    <table id="panel">
        <tr>
            <td id="usuario">Bienvenido <?php echo $_SESSION['usuario']; ?></td>
        </tr>
        <tr>
            <td id="sesion"><input type="button" name="salir" class="botones" value="Salir" onClick="window.top.open('','_parent','');window.top.close();"></td>
        </tr>
        <tr>
            <td id="menu">
                <a href="../controladores/noticias.php?opcion=agregar"><img src="../vistas/images/miniDoc.png" /><span>Agregar Noticia</span></a>
                <a href="../controladores/noticias.php?opcion=listar"><img src="../vistas/images/miniListaDoc.png" /><span>Listado Noticias</span></a>
                <a href="../controladores/secciones.php?opcion=agregar"><img src="../vistas/images/miniSec.png" /><span>Agregar Secci&oacute;n</span></a>
                <a href="../controladores/secciones.php?opcion=listar"><img src="../vistas/images/miniListaSec.png" /><span>Listado Secciones</span></a>
            </td>
        </tr>
        <tr>
            <td id="cuerpo">
                <form name="editar" id="editar" method="post" action="">
                    <input type="hidden" name="txtId" value="<?php echo $noticia['id'] ;?>" />
                    <table>
                        <tr>
                            <td width="100px">
                                <label>Titulo:</label>
                            </td>
                            <td colspan="3">
                                <input type="text" name="txtTitulo" id="txtTitulo" class="txt" value="<?php echo $noticia['titulo'] ;?>" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label>Secci&oacute;n:</label>
                            </td>
                            <td>
                                <select name="txtSeccion_id" id="txtSeccion_id" class="txt">
                                    <?php
                                    $seccion = $Noticia->bd->enArray($Noticia->bd->ConsultaSQL("SELECT titulo FROM ".TABLA_SECCIONES." WHERE id = '{$noticia['seccion_id']}'"));
                                    ?>
                                    <option value="<?php echo $noticia['seccion_id'] ;?>"><?php echo $seccion['titulo']; ?></option>
                                    <?php
                                    $seccione = $Noticia->bd->ConsultaSQL("SELECT * FROM ".TABLA_SECCIONES);
                                    while ($select = $Noticia->bd->enArray($seccione)):
                                    ?>
                                    <option value="<?php echo $select['id'] ;?>"><?php echo $select['titulo'] ;?></option>
                                    <?php endwhile;?>
                                </select>
                            </td>
                            <td width="100px">
                                <label>Publicada:</label>
                            </td>
                            <td>
                                    <label>
                                        <input type="radio" name="txtEstado" value="0" <?php echo $noticia['estado']==0?"checked=\"checked\"":""; ?> /> No
                                    </label>
                                    <label>
                                        <input type="radio" name="txtEstado" value="1" <?php echo $noticia['estado']==1?"checked=\"checked\"":""; ?>  /> S&iacute;
                                    </label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label>Fecha Publicaci&oacute;n:</label>
                            </td>
                            <td>
                                <input type="text" name="txtFecha_publicacion" id="txtFecha_publicacion" class="txt" value="<?php echo $noticia['fecha_publicacion'] ;?>" />
                            </td>
                            <td>
                                <label>Fecha fin Publicaci&oacute;n:</label>
                            </td>
                            <td>
                                <input type="text" name="txtFecha_despublicacion" id="txtFecha_despublicacion" value="<?php echo $noticia['fecha_despublicacion'] ;?>" class="txt" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <textarea name="txtContenido" id="txtContenido" rows="15" cols="80" class="tinymce">
                                    <?php echo $noticia['contenido'] ;?>
                                </textarea>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <input type="submit" name="cmd" value="Actualizar" onClick="tinyMCE.triggerSave();" />
                                <input type="reset" name="reset" value="Restablecer" />
                            </td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
    </table>
</div>
</body>
</html>