<?php
	require_once("../includes/bootstrap.php");
	$sesion=new sesion();
	$sesion->set('permiso',permisos($_POST['privilegio']));
	
	$academia = bootstrap::initBd($sesion->get('anio'));

?>

<script  type="text/javascript">
var encabActive;
$(function(){
	var weditor=$("#wEditor");
	
	$("#aco-documentos").accordion({ 
	});
	
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		language : "es",
		skin : "o2k7",
		plugins : "autolink,lists,pagebreak,table,advhr,preview,-cmpsInfor",
		theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,dtsColegio,|,dtsEstudiante",
		theme_advanced_buttons2 : "outdent,indent,blockquote,|,undo,redo,|,forecolor,backcolor,|,tablecontrols,|,hr,removeformat,|,code,advhr,|,mysplitbutton,preview",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		oninit:function(){
			weditor.hide();
			}
	});
	
	
	$("#vistaPrevia").linkbutton().click(function(){
		encabActive.html(tinyMCE.get('editordocumentos').getContent());
		
		$.ajax({
			url:"mod_documentos/opera_documentos.php",
			type:"POST",
			dataType:"json",
			data:{
				idedocu:encabActive.attr('aria-id'),
				esqdocu:encabActive.html(),
			},
			beforeSend: function(){
				$.messager.progress({title:dtsLang['project']['empresa'],msg:dtsLang['mod_documentos']['msg_save']})
			},
			success: function(rta){
				if (rta.error!=0){
					if (rta=='session'){
						modulo='global'
					}
					else{
						modulo='mod_colegio'
					}
					jAlert(dtsLang[modulo][rta.error],'error',function(){
						if(rta=='session'){
							location.reload();
						}
					});
				}else{
					$.messager.progress('close');
					notifica_ok(dtsLang['mod_documentos']['msg_exito']);
				}
				$("#aco-editor").show();
				weditor.hide();
			}
		});
		
		
	});
	$("a.open_editor").linkbutton().click(function(){
		encabActive=$("#"+$(this).attr("id_obj"));
		tinyMCE.activeEditor.setContent(encabActive.html());
		weditor.show();
		$("#panelsEncab").hide();
	});

});

</script>
<style>
	.tit_relleno{
		background-color:#CCC; 
		font-size:12px; 
		font-weight:bold;
		padding:2px;
	}
	.separador{
		padding:4px;
	}
</style>
<div id="wEditor">
	<textarea name="editordocumentos" cols="90" rows="20" id="editordocumentos" class="tinymce" ></textarea>
	<div align="center">
		<a href="#" class="easyui-linkbutton" id="vistaPrevia" data-options="iconCls:'icon-save'">Guardar</a>
	</div>
</div>


<div id='aco-editor'>
<div id="aco-documentos" class="easyui-accordion" style="width:750px;height:450px;">  
	<?php
    $cons="SELECT cod_documento, nom_documento, esquema_documento FROM conf_documentos";
	$academia->instruccion($cons);
	while($row = $academia->extraer_registro()) {
			$coddoc=$row['cod_documento'];
            $nomdoc=$row['nom_documento'];
			$esqdoc=$row['esquema_documento'];
	?>
            <div id="aco-opcion<?php echo $coddoc; ?>" aria-id=<?php echo $coddoc; ?> title="<?php echo $nomdoc; ?>" data-options="
            	selected:true,  
                tools:[{  
                	    iconCls:'icon-edit',  
                    	handler:function(){
                        	encabActive=$('#aco-opcion<?php echo $coddoc; ?>');
                        	tinyMCE.activeEditor.setContent($('#aco-opcion<?php echo $coddoc; ?>').html());  
                    		$('#aco-editor').hide();
                            $('#wEditor').show();
                    	}  
                	}]",
                style="overflow:auto;padding:10px;">  
        	<?php echo $esqdoc; ?>
    		</div>  
  	<?php
    }
	$academia->liberar();
	$academia->cerrar();
	?>
</div>
</div>	
