<?php

// echo "((".$_POST['tipo']."))";
    
    $_POST['loq_gen']=0;

    include_once ('settings.php');

    $arr_label[323]='conforme';    
    $arr_label[703]='etapas';   

    $arr_label[498]='etapa';  
    $arr_label[1000]='evaluador';  
    $arr_label[315]='estatus';                  
    $arr_label[702]='resultado_revision';   
    $arr_label[503]='proceso';    
    $arr_label[504]='boleta';    
    $arr_label[505]='no_conforme';    
    
    $arr_label[1194]='siglas';    
    $arr_label[289]='seleccione';    
    
    $arr_label[1250]='adm_con_certxt2';
    $arr_label[1251]='adm_con_certxt1';
    $arr_label[1258]='e_firma';
    $arr_label[1259]='cod_verif';
    $arr_label[1260]='firma_e';
    $arr_label[289]='seleccione';
    $arr_label[1261]='generar';
    $arr_label[1262]='comfirmar_firma_e';
    $arr_label[1263]='seleccione_firma_e';
    $arr_label[107]='datos_guardados';
    $arr_label[1257]='formatos';

    $arr_label[133]='nombre';
    $arr_label[1253]='siglas';
    $arr_label[868]='observaciones';
    $arr_label[707]='espere';
    

    $arr_label[1266]='confirm_Genpdf';
    $arr_label[1267]='generando_pdf';
    $arr_label[1268]='guardando_pdf';
    $arr_label[1269]='confirm_Emailpdf';
    $arr_label[1270]='adjuntando_pdf';
    $arr_label[1272]='adm_con_cerlins';
    
    $arr_label[1282]='fecha_rechazo';
    $arr_label[1283]='info_rechazo';
    
    $arr_label[704]='resultado_030208';   
	$arr_label[1249]='usr_030208';    
	$arr_label[1248]='dt_030208';
	$arr_label[1119]='conclusiones_030208';        
	
    $arr_label[1293]='resultado_030207';   
	$arr_label[1294]='usr_030207';    
	$arr_label[1295]='dt_030207';
	$arr_label[1296]='conclusiones_030207';        

    $arr_label[1289]='resultado_030206';
	$arr_label[1290]='usr_030206';
	$arr_label[1291]='dt_030206';
	$arr_label[1292]='conclusiones_030206';

    $arr_label[1285]='resultado_030205';
	$arr_label[1286]='usr_030205';
	$arr_label[1287]='dt_030205';
	$arr_label[1288]='conclusiones_030205';

    $arr_label[1301]='resultado_030209';   
	$arr_label[1302]='usr_030209';    
	$arr_label[1303]='dt_030209';
	$arr_label[1304]='conclusiones_030209';
	
    $arr_label[1797]='GenerateLOQ1';
    $arr_label[1798]='upload_loq';

	$arr_label[83]='numreg';        
    $arr_label[1756]= 'email_enviar';

    $arr_label[1823]='qc_notappli';    
    $arr_label[1824]='qc_pass';    
    $arr_label[1825]='qc_fail';    

    $arr_label[1817]='send-loq';    
    $arr_label[1818]='p-conforme';        
    $arr_label[1819]='p-no_conforme';       
    $arr_label[1827]='approve';        
    $arr_label[1828]='dnapprove';       
    $arr_label[1810]='reassess';       
    $arr_label[1829]='confirmdec';
    $arr_label[1830]='sendback';
    $arr_label[864]='finaldec';
    $arr_label[698]='outcome';
    $arr_label[1807]='toutcome';
    $arr_label[1831]='voutcome';
    $arr_label[1811]='endorse';
    $arr_label[1832]='re-assess';
    
    $arr_label[681] = "salir";
    $arr_label[1379] = "unselect";
    $arr_label[1912] = "carga_pdf_oficiales";
    $arr_label[84]='nomprod';
    

    $arr_lang = "323,703,704,498,1000,315,702,504,505,1119,1194,289,503,1248,1249,1250,1251, 1258, 1259, 1260, 289, 1261, 1262, 1263, 
    07, 1257, 133, 1253, 868, 707, 1266, 1267,  1268, 1269, 1270, 1272, 1282, 1283, 1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,
    1295,1296, 1301,1302,1303,1304,83,1797,1798,1756,1923,1824,1825,1817,1818,1819,1827,1828,1810,1829,1830,864,698,1831,1832,1807,681,1811,1832,1379,1912,84";
    include("form_language.php"); 
    $arr_label['resultado_030209']=$rr_label['resultado_030208'];
    $arr_label['resultado_03020902']=$arr_label['resultado_030208'];

    $_POST['adm_con_sr_file_name']='';
    $show_buttons = true;    
    $user_level=4;
    $user_alias="";
    $sql = "SELECT adm_usr_tpousr, adm_usr_alias FROM adm_usuarios  WHERE adm_usr_ci = '{$_SESSION['ADMusuario_id']}'";

    $result=$connection->Execute($sql);
    if (!$result->EOF) {
        $user_level=$result->fields[0];
        $user_alias=$result->fields[1];
    }
    /*
    if ($_POST['id'] == '03020501' ) { //si es no conforme o conforme 2010-07-22 
        $disabled = " disabled "; 
        $class = "text-view";
        $window = true;//edicion de textarea
    ?>                    
        <script type="text/javascript">
                document.getElementById('graba').className = "buttonDis";
                document.getElementById('graba').disabled = true;
                document.getElementById('limpia').className = "buttonDis";		
                document.getElementById('limpia').disabled = true;
        </script>
    <?php } 
    */
?>
<script src="includes/maskInputMoney_files/jquery_002.js" type="text/javascript"></script>
<script src="includes/maskInputMoney_files/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">

 $(function() {
        if ($("#adm_con_rf_dt")) $("#adm_con_rf_dt").mask("99-99-9999");         
        if ($("#adm_con_issdate")) $("#adm_con_issdate").mask("99-99-9999");         
    });

function open_url1(disabled,detapa,tec_id){
    var tpr=document.getElementById('ctg_tpr_id').value;
    var tpt=document.getElementById('ctg_tpt_id').value;
    var codigo=document.getElementById('codigo').value;
    var tipo=document.getElementById('tipo').value;
    var id=document.getElementById('id').value;
    // var tec_id = '<?=$_SESSION['ADMusuario_id']?>';
    var idetapa = detapa;

    var params="&tpr="+tpr+"&codigo="+codigo+"&idetapa="+idetapa+"&tpt="+tpt+"&tipo="+tipo+"&d_id="+id+"&tec_id="+tec_id;
    //window.open("pestana_imprime.php?"+params, "vent" , "width=1100,height=650,scrollbars=NO");
    //window.open('includes/viewdocs.php?'+params, "vent" , "width=1100,height=650,scrollbars=NO");
    window.open('includes/viewdocs.php?'+params, "_blank");

}

function checkform_standar( form ) {
    var errorCount = 0;

    var campo = document.getElementById('enfoco'); 

    
        if (form.adm_con_rf_dt) {
            
            if( notDate(form.adm_con_rf_dt,'<?php echo $mask_dates?>')) {errorCount++;if (errorCount == 1) {etiqueta = '<?php echo $arr_label['fecha_rechazo']?>';campo.value = 'adm_con_rf_dt';}}

            if( form.adm_con_rf_obs.value == ''){errorCount++;if (errorCount == 1) {etiqueta = '<?=$arr_label['observaciones']?>';campo.value = 'adm_con_rf_obs';}}

        } else {
            
            if (form.res_final) {			
                if (!form.res_final[0].checked &&  !form.res_final[1].checked) {errorCount++;if (errorCount == 1) {etiqueta = '<?=$arr_label['conforme']?>';campo.value = 'res_final1';}}
                if (form.obs_final)
                if (form.obs_final.value == '' && 'res_final1'==2 ){errorCount++;if (errorCount == 1) {etiqueta = '<?=$arr_label['comentarios']?>';campo.value = 'obs_final';}}


                if (document.getElementById('res_final1'))
                if (document.getElementById('res_final1').checked == true) {
                    if (form.siglas) {
                    if (form.siglas.value == ''){errorCount++;if (errorCount == 1) {etiqueta = '<?=$arr_label['siglas']?>';campo.value = 'siglas';}}
                    }
                }
            } else { //aca entra cuando sea 030205
            
        
                if( form.status.value == '0'){errorCount++;if (errorCount == 1) {etiqueta = '<?=$arr_label['resultado']?>';campo.value = 'status';}}        
                
            }		
        }

        if (errorCount) {
            call_dialog_msg(etiqueta);
            var selected = $('#tabs').tabs('option', 'selected');
            $('#tabs').tabs('option', 'selected', 1);        
            return false;
        }

        grabar_load();


    return false;
}

function checkform_standar_local( form,varopt ) {
    var errorCount = 0;
    var campo = document.getElementById('enfoco'); 
    
    if( form.res_st.value == '0' || form.res_st.value == ''){errorCount++;if (errorCount == 1) {etiqueta = '<?=$arr_label['resultado']?>';campo.value = 'res_st';}}

    if (errorCount) {
        call_dialog_msg(etiqueta);
        var selected = $('#tabs').tabs('option', 'selected');
        $('#tabs').tabs('option', 'selected', 1);        
        return false;
    }

    grabar_load();

    return false;
}

function selecciona_etapa(tec_id,etapa_desc,ctg_tpr_id,ctg_tpt_id,codigo,tipo,id,ver){

    var opciones="toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=1024,height=660,left=150,top=100";
//    my_window = window.open("includes/form_adm_control_resultado_final_docs.php?etapa_desc="+etapa_desc+"&ctg_tpr_id="+ctg_tpr_id+"&ctg_tpt_id="+ctg_tpt_id+"&codigo="+codigo+"&tipo="+tipo+"&id="+id,"mywindow",opciones);
    my_window = window.open("includes/form_adm_control_resultado_final_docs.php?yxcwed="+etapa_desc+"&pwmfbd="+ctg_tpr_id+"&tlwdfi="+ctg_tpt_id+"&nwuyg="+codigo+"&vxzyw="+tipo+"&lwrnapvg="+id+"&ver="+ver+"&id_tec="+tec_id,"_blank");

}
function submit_form_print(form){
    var doc=document.getElementById('doc_name1').value;
    var params = "includes/plantillas_pdf/form_pdf.php?codesol=<?=$_POST['numsol']?>&tpr_type=<?=$_POST['tipo']?>&doc_name="+doc;

    my_window = window.open(params);
    document.getElementById('LOQ_gen').value=1; 

    //$_POST['loq_gen']=1;
}
</script>

<script type="text/javascript" src="includes/jquery/ui/ui.tabs.js"></script>
<script type="text/javascript">
$(function() {
    $('#tabs').tabs({ selected: 0 });
});


function show_dias(param){    
    document.getElementById('dias_respuesta').style.display = param;
    document.getElementById('res_ds').value = "";
}

function revisa_noconforme(){
    var inputs = document.getElementsByTagName('input');
    for(var i=0; i<inputs.length; i++){
        if(inputs[i].getAttribute('type')=='radio'){
            conforme = inputs[i];
            if (conforme.value == 3 && conforme.checked) { //si es un no y esta marcado
                document.getElementById('res_final2').checked = true;
            }
        }
    }
}

</script>

<div id="tabs">
        <ul>
        
<?php   if ($_POST['id']!="030208" && $_POST['id']!="030209" && $_POST['id']!="03020901" && $_POST['id']!="03020902" && $_POST['id']!="0302A0901" && $_POST['id']!="0302A0902" && $_POST['id']!="0302B0901" && $_POST['id']!="0302B0902") { //2018-01-15 e-code assignment ?>

        <li><a href="#tabs-1"><?=$arr_label['etapas']?></a></li>
	
<?php }?>
        
<?php
		if ( $_POST['id']=="030208" || $_POST['id']=="0302A08" || $_POST['id']=="0302B08" || $_POST['id']=="03020902"  ) { ?>   
        <li><a href="#tabs-2"><?=$arr_label['resultado_'.$_POST['id']]?></a></li>
<?php   } 

		if ($_POST['id'] == "03020901" || $_POST['id'] == "0302A0901" || $_POST['id'] == "0302B0901") { ?>            
        <li><a href="#tabs-3"><?=$arr_label['e_firma']?></a></li>
<?php   } ?>    


<?php   if ($_POST['id'] == "03020902" || $_POST['id'] == "0302A0902" || $_POST['id'] == "0302B0902") { ?>    
        <li><a href="#tabs-4"><?=$arr_label['formatos']?></a></li>
<?php   } ?>            
<?php   if ($_POST['id'] == "030210" ) { ?>    
        <li><a href="#tabs-41">DOCUMENTOS</a></li>
<?php   } ?>            



<?php   if ($_POST['id'] == "030504") { ?>    
        <li><a href="#tabs-5"><?=$arr_label['info_rechazo']?></a></li>
<?php   } ?>            
         

<?php if ($_POST['id'] == '03020701' ) {// para los 0302 no debe llevar conforme ?>
    <li><a href="#tabs-6"><?=$arr_label['resultado_030208']?></a></li>
<?php }?>

<?php if ($_POST['id'] == '03020702' ) {// para los 0302 no debe llevar conforme ?>
    <li><a href="#tabs-7"><?=$arr_label['resultado_030208']?></a></li>
<?php }?>

<?php if ($_POST['id'] == '03020703' ) {// para los 0302 no debe llevar conforme ?>
    <li><a href="#tabs-8"><?=strtoupper($arr_label['finaldec'])?></a></li>
<?php }?>

</ul>

        
<?php   if ($_POST['id']!="030208" && $_POST['id']!="030209" && $_POST['id']!="0302A09" && $_POST['id']!="0302B09" && $_POST['id']!="03020901" && $_POST['id']!="03020902" && $_POST['id']!="0302A0901" && $_POST['id']!="0302A0902" && $_POST['id']!="0302A0901" && $_POST['id']!="0302B0902") { //2018-01-15 e-code assignment ?>


        <div id="tabs-1">
<?php 
//echo "({$_POST['id']})";

/*
            echo "<table width=100% border=0 cellspacing=0 cellpadding=0 class=\"light_grid ui-corner-all\">
            <thead>
            <td width=20% rowspan=2>".$arr_label['etapa']."
            <td width=18% rowspan=2>".$arr_label['evaluador']."      
            <td width=10% rowspan=2>".$arr_label['estatus']."
            <td width=12% rowspan=2>".$arr_label['comentarios']."
            <td width=15% colspan=3 style='text-align:left'>".$arr_label['resultado_revision']."</tr>
            
            <tr>
            <td width=10%>".$arr_label['conforme']."
            <td width=15% colspan=2>".$arr_label['comentarios']."
            </thead>
            <tbody>";
            
*/

            echo "<table width=100% border=0 cellspacing=0 cellpadding=0 class=\"light_grid ui-corner-all\">
            <thead>
            <td width=25% rowspan=2>".$arr_label['etapa']."
            <td width=25% rowspan=2>".$arr_label['evaluador']."      
            <td width=10% rowspan=2>".$arr_label['estatus']."
            <td width=40%>".$arr_label['comentarios']." 
            </thead>
            <tbody>";
            
            $arr_status["1"] = $arr_label['proceso'];
            $arr_status["2"] = $arr_label['boleta'];
            $arr_status["3"] = $arr_label['no_conforme'];
            $arr_status["4"] = $arr_label['conforme'];
            $arr_status["5"] = $arr_label['evaluador'];

            $sql="SELECT * FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']}_etapas WHERE 
            adm_coe_numsol = '".$_POST['codigo']."' AND 
            adm_coe_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
            adm_coe_tpt_id = '".$_POST['ctg_tpt_id']."' AND ";

            switch ($_POST['id']) {
                case '030205':
                    $sql.="adm_coe_tpe_id BETWEEN '02' AND '042' ORDER BY adm_coe_tpe_orden";
                    break;
                case '0302B0501':
                    $sql.="adm_coe_tpe_id BETWEEN '02' AND '04' ORDER BY adm_coe_tpe_orden";
                    break;
                case '0302A0501':
                    $sql.="adm_coe_tpe_id BETWEEN '02' AND '03' ORDER BY adm_coe_tpe_orden";
                    break;
                case '03020701':
                case '03020702':
                case '03020703':
                case '030208':
                        $sql.="adm_coe_tpe_id IN ('02','03','04','041','042','05') ORDER BY adm_coe_tpe_orden";
                    break;
                case '030207':
                    $sql.="adm_coe_tpe_id IN ('02','03','04','041','042','05','06') ORDER BY adm_coe_tpe_orden";
                break;
                    
                default:
                    $sql.="adm_coe_tpe_id IN ('02','03','04','041','042','05','07') ORDER BY adm_coe_tpe_orden";
                    break;
            }
            // echo $sql."<br>";
            $result=$connection->Execute($sql);
            $error = $connection->ErrorMsg();
            if (!$result->EOF) {

                while ( !$result->EOF ) {
					
					$operador = $result->fields;
                    // echo "(".$operador["adm_coe_tpe_id"].")(".$operador['adm_coe_status'].")";

                    if ($_POST['id'] == "030205" || $_POST['id'] == "030208" || $_POST['id'] == "03020701" || $_POST['id'] == "03020702" || $_POST['id'] == "03020703" || $_POST['id'] == "03020A5" || $_POST['id'] == "0302A06" || $_POST['id'] == "0302A0701" || $_POST['id'] == "0302A0702" || $_POST['id'] == "0302B05" || $_POST['id'] == "0302B06" || $_POST['id'] == "0302B0701" || $_POST['id'] == "0302B0702")
                    //echo "operador (".$operador['adm_coe_tpe_id'].") substr (".substr($_POST['id'],4,2).")";
                   	//if ($operador['adm_coe_tpe_id'] >= substr($_POST['id'],4,2)) 
                    //	break;						
                       
                    $_POST['arr_res_final1'] = "";
                    $_POST['arr_res_final2'] = "";
                    /*
                    $sql="SELECT * FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']}_etapas WHERE 
                    adm_coe_numsol = '".$_POST['codigo']."' AND 
                    adm_coe_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
                    adm_coe_tpt_id = '".$_POST['ctg_tpt_id']."' AND 
                    adm_coe_tpe_id = '".$operador["adm_coe_tpe_id"]."'";
                    //echo $sql."<br>";
                    $result2=$connection->Execute($sql);
                    if (!$result2->EOF) {
                        $operador2 = $result2->fields;
                        */
                        if ($operador["adm_coe_rf_status"] == '4') $_POST['arr_res_final1'] = " checked ";
                        if ($operador["adm_coe_rf_status"] == '3') $_POST['arr_res_final2'] = " checked ";
                        $_POST['arr_obs_final'] = $operador['adm_coe_rf_obs'];

                        /*
                    }                         
                    */
                    $sql="SELECT * FROM ctg_tipo_tramites_etapas WHERE 
                    ctg_tpr_id = '".$operador["adm_coe_tpr_id"]."' AND ctg_tpt_id = '".$operador["adm_coe_tpt_id"]."' AND 
                    ctg_tte_id = '".$operador["adm_coe_tpe_id"]."'";
                    // echo $sql."<br>";
                    $result5=$connection->Execute($sql);
                    if (!$result5->EOF) {
                        $operador5 = $result5->fields;
                        $_POST['adm_coe_etapa_desc'] = $operador5['ctg_tte_desc'];
                    }
                    $_POST['adm_coe_estatus_desc'] = "...";
                    $_POST['adm_coe_tec_name'] = "";
                    switch ($operador["adm_coe_tpe_id"]) {
                        case '02':
                        case '03':
                        case '04':
                        case '041':
                            switch ($operador['adm_coe_status']) {
                                case '1':
                                case '0':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['proceso'];
                                    break;
                                case '5':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['preboleta'];
                                    break;
                                case '2':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['boleta'];
                                    break;
                                case '3':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['no_conforme'];
                                    break;
                                case '4':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['conforme'];
                                    break;
                                                            
                                default:
                                $_POST['adm_coe_estatus_desc']="N/A";
                                break;
                            }
                            break;
                        case '042':
                            switch ($operador['adm_coe_status']) {
                                case '1':
                                case '0':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['qc_notappli'];
                                    break;
                                case '3':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['qc_fail'];
                                    break;
                                case '4':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['qc_pass'];
                                    break;
                                                            
                                default:
                                $_POST['adm_coe_estatus_desc']="N/A";
                                break;
                            }
                            break;
                        case '05':
                            switch ($operador['adm_coe_status']) {
                                case '1':
                                case '0':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['proceso'];
                                    break;
                                case '2':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['send-loq'];
                                    break;
                                case '4':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['conforme'];
                                    break;
                                case '3':
                                    $_POST['adm_coe_estatus_desc']=$arr_label['no_conforme'];
                                    break;
                                                            
                                default:
                                    $_POST['adm_coe_estatus_desc']="N/A";
                                    break;
                            }
                            break;

                    }
                              
                    $sql = "SELECT * FROM adm_usuarios  WHERE adm_usr_ci = '".$operador['adm_coe_tec_id']."'";
                    $result1=$connection->Execute($sql);
                    if (!$result1->EOF) {
                        $_POST['adm_coe_tec_name'] = $result1->fields[6];
                    }

                    if ($disabled == "") $ver = "false"; else $ver = "true";

                    $onClick = " title=\"Click para revisar Expediente: ".$_POST['adm_coe_etapa_desc']."\" onClick=\"selecciona_etapa('".$_POST['adm_coe_tec_id']."','".$_POST['adm_coe_etapa_desc']."','".$_POST['ctg_tpr_id']."','".$_POST['ctg_tpt_id']."','".$_POST['codigo']."','".$_POST['tipo']."','0302".$operador["adm_coe_tpe_id"]."','$ver');\"";

                    echo "<tr>
                    <td >".$_POST['adm_coe_etapa_desc']."
                    <td >".$_POST['adm_coe_tec_name']."</td>
                    <td  title='".$operador['adm_coe_status']."'>". $_POST['adm_coe_estatus_desc']."</td>";
                    
                    if ($_POST['id']) $disabled=" Disabled ";

                    $fec = substr(fecha_usr($operador["adm_coe_res_dt"]),0,10);
                    
                    if (empty($disabled)) {
                        echo "<label for=\"arr_res_final1".$operador["adm_coe_tpe_id"]."\"><a href=\"#\">".$arr_label['si']."</a></label>
                        <input $disabled type=radio id=\"arr_res_final1".$operador["adm_coe_tpe_id"]."\" name=\"arr_res_final[".$operador["adm_coe_tpe_id"]."]\" value=\"4\" ".$_POST['arr_res_final1']." onclick=\"revisa_noconforme()\" style=\"height:10px\">
                        
                        <label for=\"arr_res_final2".$operador["adm_coe_tpe_id"]."\"><a href=\"#\">".$arr_label['no']."</a></label>
                        <input $disabled type=radio id=\"arr_res_final2".$operador["adm_coe_tpe_id"]."\" name=\"arr_res_final[".$operador["adm_coe_tpe_id"]."]\" value=\"3\" ".$_POST['arr_res_final2']." onclick=\"revisa_noconforme()\">";
                        
                        echo "<br>$fec";
                    } else {
                    
                        if (!empty($_POST['arr_res_final1'])) echo $arr_label['si']." ".$fec;
                        if (!empty($_POST['arr_res_final2'])) echo $arr_label['no']." ".$fec;

                    }
                    switch ($operador['adm_coe_tpe_id']) {
                        case '02':
                            $intcode="ADM";
                            break;
                        case '03':
                            $intcode="QUA";
                            break;
                        case '04':
                            $intcode="CLI";
                            break;
                        case '041':
                            $intcode="QCL";
                                break;
                        case '042':
                            $intcode="NCLI";
                            break;
                        case '05':
                            $intcode="QUA";
                                break;
                    }
                    $adm_coe_pdf='';
                    $view_etapas='';
                    $sqle="SELECT * FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']}_docs WHERE 
                    adm_cod_numsol = '".$_POST['codigo']."' AND 
                    adm_cod_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
                    adm_cod_tpt_id = '".$_POST['ctg_tpt_id']."' AND 
                    adm_cod_ttc_id = '".$intcode."' ";
                    $resulte=$connection->Execute($sqle);
                    if (!$resulte->EOF) {
                        $adm_coe_pdf='yes';
                    }
                    $viewetapas='yes';
                    // $sqlve="SELECT * FROM \"vus_tramites_{$_POST['tipo']}1_DOCs\" WHERE 
                    // \"vus_{$_POST['tipo']}DOC_numsol\" = '".$_POST['codigo']."' AND 
                    // \"vus_{$_POST['tipo']}DOC_tpr_id\" = '".$_POST['ctg_tpr_id']."' AND 
                    // \"vus_{$_POST['tipo']}DOC_tpt_id\" = '".$_POST['ctg_tpt_id']."' AND 
                    // \"vus_{$_POST['tipo']}DOC_ttc_id\" = '".$intcode."' ";
                    // $resultve=$connectionVUS->Execute($sqlve);
                    // if (!$resultve->EOF) {
                    //     // $viewetapas='yes';
                    // }                    
                    $varecho="";
                    switch ($operador["adm_coe_tpe_id"]) {
                        case '05':
                        case '042':
                        case '07':
                            $varecho .= "</td>
                            <td width=2%>
                                <table>";
                                if (!empty($viewetapas)){
                                        $varecho .="
                                        <td ></td><textarea $disabled rows=2 cols=40 id='arr_coe_obs_".$operador["adm_coe_tpe_id"]."'>".$operador["adm_coe_obs"]."</textarea>
                                        ";                                    
                                    $varecho .= "
                                    <td>
                                    <ul id=\"icons\" class=\"ui-widget ui-helper-clearfix\">
                                        <li class=\"ui-state-default ui-corner-all\">
                                        <span class=\"ui-icon ui-icon-newwin\" title=\"".$arr_label['textarea_ttt']." ".$arr_label['comentarios']." : ".$_POST['adm_coe_etapa_desc']."\" onClick=\"check_window('arr_coe_obs_".$operador["adm_coe_tpe_id"]."','".$arr_label['comentarios']." : ".$_POST['adm_coe_etapa_desc']."',true)\">
                                        </span>
                                        </li>
                                    </ul>";

                                }
                                $varecho .= "<td>".(empty($adm_coe_pdf) ? "<img src='includes/images/acrodis.png' width=20>" : "<img onclick=open_url1(0,'".$operador["adm_coe_tpe_id"]."','".$operador['adm_coe_tec_id']."') src='includes/images/acroread.png' width=20>")."
                                </table>";
                            break;
                        
                        default:
                            $varecho .= "</td>
                            <td width=2%>
                                <table>";
                                if (!empty($viewetapas)){

                                    $varecho .="
                                        <td ></td><textarea $disabled cols=40 rows=2 id='arr_coe_obs_".$operador["adm_coe_tpe_id"]."'>".$operador["adm_coe_obs"]."</textarea>
                                        ";                                    

                                        $varecho .= "
                                    <td>
                                    <ul id=\"icons\" class=\"ui-widget ui-helper-clearfix\">
                                    <li class=\"ui-state-default ui-corner-all\"><span class=\"ui-icon ui-icon-document\" $onClick ></span></li>
                                    </ul></td>
                                    ";
                                    $varecho .= "
                                    <td>
                                    <ul id=\"icons\" class=\"ui-widget ui-helper-clearfix\">
                                        <li class=\"ui-state-default ui-corner-all\">
                                        <span class=\"ui-icon ui-icon-newwin\" title=\"".$arr_label['textarea_ttt']." ".$arr_label['comentarios']." : ".$_POST['adm_coe_etapa_desc']."\" onClick=\"check_window('arr_coe_obs_".$operador["adm_coe_tpe_id"]."','".$arr_label['comentarios']." : ".$_POST['adm_coe_etapa_desc']."',true)\">
                                        </span>
                                        </li>
                                    </ul>";

                                }
                                $varecho .= "<td>".(empty($adm_coe_pdf) ? "<img src='includes/images/acrodis.png' width=20>" : "<img onclick=open_url1(0,'".$operador["adm_coe_tpe_id"]."','".$operador['adm_coe_tec_id']."') src='includes/images/acroread.png' width=20>")."
                                </table>";
                            break;
                    }
                    echo $varecho;
                    /* este iba antes de la comilla con el punto y coma
                    <td><textarea $disabled style=\"width:100%;height:21px;\" id=\"arr_obs_final".$operador["adm_coe_tpe_id"]."\" name=\"arr_obs_final[".$operador["adm_coe_tpe_id"]."]\" class=\"$class\" title=\"".$arr_label['comentarios']." : ".$_POST['arr_obs_final']."\">".$_POST['arr_obs_final']."</textarea>
                    </tr>
                    */

                    $result->MoveNext ();
                }
                $sql="SELECT * FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']} WHERE 
                adm_con_numsol = '".$_POST['codigo']."' AND 
                adm_con_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
                adm_con_tpt_id = '".$_POST['ctg_tpt_id']."'";
                //echo $sql;
                $result7=$connection->Execute($sql);
                if (!$result7->EOF) {
                    $operador7 = $result7->fields;
                    switch ($_POST['id']) {
                        case '03020702':
                            if ($operador7['adm_con_dec1_st']=='3')
                                $status_desc=$arr_label['dnapprove'];
                            else
                                if ($operador7['adm_con_dec1_st']=='4')
                                    $status_desc=$arr_label['approve'];
                                else
                                    $status_desc=$arr_label['proceso'];
                            echo "<tr>
                            <td >Outcome of assessment
                            <td >".$_POST['adm_coe_tec_name']."</td>
                            <td >".$status_desc." ".fecha_usr(substr($operador7['adm_con_dec1_dt'],0,10))." ".substr($operador7['adm_con_dec1_dt'],11,10)."</td>                            
                            <td align=center nowrap>";
                            echo "</td>
                            <td width=2%>
                                <table>
                                </table>
                            ";    
                            break;
                        case '03020703':
                            if ($operador7['adm_con_dec1_st']=='3')
                                $status_desc=$arr_label['dnapprove'];
                            else
                                if ($operador7['adm_con_dec1_st']=='4')
                                    $status_desc=$arr_label['approve'];
                                else
                                    $status_desc=$arr_label['proceso'];
                            echo "<tr>
                            <td >Outcome of assessment
                            <td >".$_POST['adm_coe_tec_name']."</td>
                            <td >".$status_desc." ".fecha_usr(substr($operador7['adm_con_dec1_dt'],0,10))." ".substr($operador7['adm_con_dec1_dt'],11,10)."</td>                            
                            <td align=center nowrap>";
                            echo "</td>
                            <td width=2%>
                                <table>
                                </table>
                            ";    

                            if ($operador7['adm_con_dec2_st']=='3')
                                $status_desc=$arr_label['dnapprove'];
                            else
                                if ($operador7['adm_con_dec2_st']=='4')
                                    $status_desc=$arr_label['approve'];
                                else
                                    if ($operador7['adm_con_dec2_st']=='7')
                                        $status_desc=$arr_label['reassess'];
                                    else
                                        $status_desc=$arr_label['proceso'];
                            echo "<tr>
                            <td >&nbsp;&nbsp;&nbsp;Verification of outcome
                            <td >".$_POST['adm_coe_tec_name']."</td>
                            <td >".$status_desc." ".fecha_usr(substr($operador7['adm_con_dec2_dt'],0,10))." ".substr($operador7['adm_con_dec2_dt'],11,10)."</td>
                            
                            <td align=center nowrap>";
                            echo "</td>
                            <td width=2%>
                                <table>
                                </table>
                            ";  
                            break;
                        case '030208':
                            if ($operador7['adm_con_dec1_st']=='3')
                                $status_desc=$arr_label['no-conform'];
                            else
                                if ($operador7['adm_con_dec1_st']=='4')
                                    $status_desc='Conform';
                                else
                                    $status_desc='Unselect';
                            echo "<tr>
                            <td >Outcome of assessment
                            <td >".$_POST['adm_coe_tec_name']."</td>
                            <td >".$status_desc." ".fecha_usr(substr($operador7['adm_con_dec1_dt'],0,10))." ".substr($operador7['adm_con_dec1_dt'],11,10)."</td>                            
                            <td align=center nowrap>";
                            echo "</td>
                            <td width=2%>
                                <table>
                                </table>
                            ";        
                            if ($operador7['adm_con_dec2_st']=='3')
                                $status_desc=$arr_label['dnapprove'];
                            else
                                if ($operador7['adm_con_dec2_st']=='4')
                                    $status_desc=$arr_label['approve'];
                                else
                                    if ($operador7['adm_con_dec2_st']=='7')
                                        $status_desc=$arr_label['reassess'];
                                    else
                                        $status_desc=$arr_label['proceso'];
                            echo "<tr>
                            <td >&nbsp;&nbsp;&nbsp;Verification of outcome
                            <td >".$_POST['adm_coe_tec_name']."</td>
                            <td >".$status_desc." ".fecha_usr(substr($operador7['adm_con_dec2_dt'],0,10))." ".substr($operador7['adm_con_dec2_dt'],11,10)."</td>
                            
                            <td align=center nowrap>";
                            echo "</td>
                            <td width=2%>
                                <table>
                                </table>
                            ";  

                            if ($operador7['adm_con_dec3_st']=='3')
                                $status_desc=$arr_label['dnapprove'];
                            else
                                if ($operador7['adm_con_dec3_st']=='7')
                                    $status_desc=$arr_label['reassess'];
                                else
                                    $status_desc=$arr_label['proceso'];
                            
                            echo "<tr>
                            <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Final decision
                            <td >".$_POST['adm_coe_tec_name']."</td>
                            <td >".$status_desc." ".fecha_usr(substr($operador7['adm_con_dec3_dt'],0,10))." ".substr($operador7['adm_con_dec3_dt'],11,10)."</td>
                            
                            <td align=center nowrap>";
                            echo "</td>
                            <td width=2%>
                                <table>
                                </table>
                            ";  
                            break;                    
                        }
                }
        
                echo "</tbody></table>";
            } else {
                echo "</tbody></table>";
                echo "<span class=no_data>".$arr_label['no_data']."</span>";
            }


?>
        <?php 
        
        if ($show_buttons && $_POST['id']=='03020500' && $user_level<>'7') {  ?>

            <table class="form_standar_cap" style="width:90%;align-content: center" >
                <tr>
                    <td class="form_standar_cap" >Document name</td>
                    <td><input class="text-input" name="doc_name1" id="doc_name1" maxlength=100 size=80 value="LOQ_document" type=text ></td>

                    <td  style="width:25%;align-content: center" >
                        <button  style="width:200px; height:32px"  class="button">
                            <a class="button" onclick="return submit_form_print(this.form);" target="_blank" ><?=$arr_label['GenerateLOQ1']?></a>
                        </button>
                    </td>
                </tr>

            </table>

        <?php } else 
            $disabled=" disabled "  ;
        ?>
        </div>
        
        
	
<?php }?>
        		
<?php

        $adm_fec_dac = "";
        $adm_con_calma="";
        $adm_con_sec="";
        $adm_con_perva ="";

        
        $sql="SELECT * FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']} WHERE 
        adm_con_numsol = '".$_POST['codigo']."' AND 
        adm_con_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
        adm_con_tpt_id = '".$_POST['ctg_tpt_id']."'";

        // echo $sql;
        
        $result2=$connection->Execute($sql);
        if (!$result2->EOF) {
            $operador2 = $result2->fields;

            if ($operador2["adm_con_rf_status"] == '4') $_POST['res_final1'] = " checked ";
            if ($operador2["adm_con_rf_status"] == '3') $_POST['res_final2'] = " checked ";

            $_POST['obs_final'] =  $operador2['adm_con_rf_obs'];
            $rd_dt =  substr($operador2['adm_con_rf_dt'],0,10);
            $rd_usr =  $operador2['adm_con_rf_usr'];
            $adm_con_cdv =  $operador2['adm_con_cdv'];
            $cod_verif=$operador2['adm_con_cdv'];
            $adm_con_certxt1 =  trim($operador2['adm_con_certxt1']);
            $adm_con_certxt2 =  trim($operador2['adm_con_certxt2']);
            $adm_con_cerlins =  $operador2['adm_con_cerlins'];
            $adm_con_nomprod =  trim($operador2['adm_con_nomprod']);

            $adm_con_dacdate = $operador2['adm_con_dacdate'];
            $fec_aprob = date("d/m/Y",strtotime($operador2['adm_con_issdate']));
            $adm_con_salescat = $operador2['adm_con_salescat'];
            $adm_con_inicon = $operador2['adm_con_inicon'];
            $adm_con_dci = $operador2['adm_con_dci'];

            $adm_con_rdv=$operador2["adm_con_rdv"];
            $adm_con_calma=$operador2["adm_con_calma"];
            $adm_con_sec=$operador2["adm_con_sec"];
            $adm_con_perva =$operador2["adm_con_perval"];
            $adm_con_preapro =$operador2["adm_con_preapro"];

            /*
            $adm_con_dirname1 = $operador2['adm_con_dirname1'];
            $designation1 = $operador2['adm_con_dirdesi1'];
            $adm_con_dirname2 = $operador2['adm_con_dirname2'];
            $designation2 = $operador2['adm_con_dirdesi2'];
			*/
		}
		/*
        if (empty($adm_con_dirname)) $adm_con_dirname1=$adm_cnf_firma;
        if (empty($adm_con_dirname2)) $adm_con_dirname2=$adm_cnf_firma;
        if (empty($designation1)) $designation1=$adm_cnf_desig1;
        if (empty($designation2)) $designation2=$adm_cnf_desig2;
		*/
        $adm_con_dirname1=$adm_cnf_firma;
        $adm_con_dirname2=$adm_cnf_firma2;
        $designation1=$adm_cnf_desig1;
        $designation2=$adm_cnf_desig2;

		if (empty($rd_dt)) $rd_dt = date("d/m/Y");
		
		if (empty($rd_usr)) $rd_usr = $_SESSION['ADMusuario_id'];
	
		$sql = "SELECT * FROM adm_usuarios  WHERE adm_usr_ci = '$rd_usr'";
		//echo $sql."<br>";
		$result1=$connection->Execute($sql);
		if (!$result1->EOF) {
			$rd_usr = $result1->fields[6];
		}
		
?>                 
        
 <?php
 
 if ( $_POST['id']=="030208" || $_POST['id']=="0302A08" || $_POST['id']=="0302B08" || $_POST['id']=="03020902"  ) { 
		
        if ($_POST['id']=="030209" || $_POST['id'] == "030208" || $_POST['id'] == "030207" || $_POST['id'] == "0302B08" || $_POST['id']=="0302B09") { 
	        //update a revision de c onforme
	        $sql = "SELECT * FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']}_etapas 
	        WHERE 
	        adm_coe_numsol = '".$_POST['codigo']."' AND 
	        adm_coe_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
	        adm_coe_tpt_id = '".$_POST['ctg_tpt_id']."' AND 
	        adm_coe_tpe_id = '".substr($_POST['id'],4,2)."'";
	        $result = $connection->Execute ( $sql );                        
            if (!$result->EOF) {
	            
	            if (intval($result->fields['adm_coe_status']) == 3 || intval($result->fields['adm_coe_status']) == 4) {
	            	
			        if ($result->fields['adm_coe_status'] == 4)		        
			        	$_POST['res_final1'] = " checked ";
			        
			        if ($result->fields['adm_coe_status'] == 3)		        
			        	$_POST['res_final2'] = " checked ";
			        
				} else {
			       
			        $_POST['obs_final'] = $result->fields['adm_coe_obs'];	
			        $rd_dt = $result->fields['adm_coe_dt'];				
			        $window = false;
			        $class = "text-input";
                    $disabled = "";
	                ?>
                        <script type="text/javascript">
                        document.getElementById('graba').className = "button";
                        document.getElementById('graba').disabled = false;
                        document.getElementById('limpia').className = "button";		
                        document.getElementById('limpia').disabled = false;
                        </script>
	                <?php
				}
	        }  
		}

    ?>                    
	
    <div id="tabs-2">
                
            <table border=0 width=100%>
            <td width=30%>
            <?php if ($_POST['id']=='030208'){?>
                <tr><td width=30% class=form_standar_cap ><?=$arr_label['confirmdec']?></td>
                <td>
                    <table align=left>
                    <tr>                    
					<td><input  type=radio id="res_final1" name="res_final" value="4" <?=$_POST['res_final1']?> onclick="revisa_noconforme()"></td>
                    <td class=form_standar_cap><label for="res_final1"><a href="#"><?=strtoupper($arr_label['approve'])?></a></label></td>
					
                    <td><input  type=radio id="res_final2" name="res_final" value="3" <?=$_POST['res_final2']?>></td>
                    <td class=form_standar_cap><label for="res_final2"><a href="#"><?=strtoupper($arr_label['dnapprove'])?></a></label></td>

                    <!-- <td><input  type=radio id="res_final3" name="res_final" value="7" <?=$_POST['res_final3']?>></td>
                    <td class=form_standar_cap><label for="res_final3"><a href="#"><?=strtoupper($arr_label['sendback'])?></a></label></td> -->

                    </tr>
                    </table>  
 
                </td>
                <!--
                <tr>
                <td class=form_standar_cap ><?=$arr_label['usr_'.$_POST['id']]?></td>
				<td><input type=text class="text-view" readonly value="<?=$rd_usr?>" size=30></td>
                <tr>
				<td class=form_standar_cap ><?=$arr_label['dt_'.$_POST['id']]?></td>
				<td><input type=text class="text-view" readonly value="<?=$rd_dt?>" size=8></td>
				-->
				<td><?php //(!empty($disabled) ? "<a href='#'><img src='includes/images/acroread.png' width=20></a>" : "")?></td>
    
                </tr>

                <?php if (empty($disabled)) { 

                    $sql_txt_look = "SELECT ctg_txt_id, ctg_txt_desc FROM ctg_textos_evaluacion WHERE ctg_tpr_id=\'".$_POST['ctg_tpr_id']."\' and ctg_txt_mod=".intval(substr($_POST['id'],0,2))."&codigo=ctg_txt_id&desc=ctg_txt_desc&orden=ctg_txt_desc";
                    ?>
                    <!--
                    <tr><td class=form_standar_cap valign=middle><?=$arr_label['texto_eval']?></td>
                        <td colspan=6>
                        <ul id="icons" class="ui-widget ui-helper-clearfix">
                        <li class="ui-state-default ui-corner-all" title="<?=$arr_label['busqueda_ttt'].' '.$arr_label['texto_eval']?>"><span class="ui-icon ui-icon-search" style='' onClick="check_look('','obs_final','<?=$sql_txt_look?>','obs_final','<?=$arr_label['texto_eval']?>')"></span></li>
                    -->                
                    <?php } 
                    $accion = $result2->fields[0];
                    $sql = "SELECT ctg_tpt_accion FROM ctg_tipo_tramites WHERE ctg_tpt_id = '{$_POST['ctg_tpt_id']}' AND ctg_tpr_id = '{$_POST['ctg_tpr_id']}'";
                    $result2=$connection->Execute($sql);
                    $accion = intval($result2->fields[0]);                    
                    ?>                
                    
                    <script>
                    var res = '';
                    if (document.getElementById('res_final'))
                        res = document.getElementById('res_final').value;
                    </script>
                    
    
                    <?php if (substr($_POST['id'],0,6) == "03020902" || substr($_POST['id'],0,7) == "0302A0902" || substr($_POST['id'],0,7) == "0302B0902") { ?>
                                                        
                    <script>

                    /*  esta funcion esta bien si desea abrir el pdf en otra ventana
                        function crear_certificado(id,file2,nombre){
                            
                            var param = "tipo=<?=$_POST['tipo']?>";
                            param = param + "&codigo=<?=$_POST['codigo']?>";
                            param = param + "&ctg_tpt_id=<?=$_POST['ctg_tpt_id']?>";
                            param = param + "&ctg_tpr_id=<?=$_POST['ctg_tpr_id']?>";
                            param = param + "&res=" + res;
                            param = param + "&pais=<?=$pais?>";
                            param = param + "&accion=<?=$accion?>";
                            param = param + "&dtb_adm=<?=$_SESSION['dtb_adm']?>";
                            param = param + "&ADMusuario_id=<?=$_SESSION['ADMusuario_id']?>";
                            param = param + "&file2=" + file2 + "&name=" + nombre;
                            
                            if (file2 == 'resultado_final_4_4.php') {

                                var per = document.getElementById('periodo_validez').value;
                                var con = document.getElementById('consideraciones_ad').value;
                                    
                                $.post("includes/form_adm_control_etapa_op.php", { op: "resultado_final_certificados", con:con, per:per },
                                function(data) 
                                {           
                                    param = param + "&token="+data.token;
                                    callofpdf("resultado_final", param);             
                                },'json');
                                
                            } else {
                            
                                    callofpdf("resultado_final", param);                     
                            }
                        }
                    */    
                    </script>                                            

                    <!--
                    <input type="button" style="display:inline" value="PDF" onclick="crear_certificado('resultado_final','res_fin')">
                    -->
            
                <?php }  ?>

                
                </td>
                </tr>  
                <tr><td class=form_standar_cap valign=middle><?=$arr_label['conclusiones_'.$_POST['id']]?></td>
                    <td colspan=6>
                        <table width=100% border=0>
                        <tr>
                        <td width=100%><textarea <?=$disabled?> id="obs_final" name="obs_final" rows=3 style='width:100%' class="<?=$class?>"><?=$_POST['obs_final']?></textarea>
                        <td valign=top>    
                            <ul id="icons" class="ui-widget ui-helper-clearfix">    
                            <li class="ui-state-default ui-corner-all" title="<?=$arr_label['textarea_ttt'].' '.$arr_label['comentarios']?>"><span onClick="check_window('obs_final','<?=$arr_label['comentarios']?>','<?=$window?>')" class="ui-icon ui-icon-newwin"></span></li>
                            </ul>
                        </td>
                        </table>    
                </td>   
                </tr>
                        
        <?php }?>
    <?php 
    if (substr($_POST['id'],0,6) == "030209" || substr($_POST['id'],0,7) == "0302A09" || substr($_POST['id'],0,7) == "03020B9") { 

        if (empty($adm_con_certxt2))
        
            $adm_con_certxt2 = "Adicionalmente debe:

            Remitir Periódicamente, Certificado de Producto Farmacéutico, Certificado de Libre Venta y/o Certificado de Buenas Prácticas de Manufactura, Vigentes.

            Comunicar a través del Centro Nacional de Farmacovigilancia (CENAVIF), cualquier efecto no descrito durante el proceso de evaluación del Registro Sanitario que derive de la actividad farmacológica del mismo o de alguno de sus ingredientes y del cual se tenga conocimiento después de aprobado el producto.

            Presentar cualquier cambio que tenga el producto durante su periodo de Comercialización, relacionado con aspectos de: textos, legales, farmacéuticos y clínicos, empleando los formularios de solicitud de cambio post registro vigentes y/o comunicaciones.

            Comunicar la fecha en la cual se inicie la comercialización del (si es EF primer lote / si es PB primer y segundo lote) elaborado, de manera que los funcionarios acreditados del Instituto Nacional de Higiene “Rafael Rangel”, puedan proceder a captar las muestras correspondientes en el propio sitio de fabricación, o de distribución en el caso de los productos importados; a los fines del estricto cumplimiento del Artículo 60 del Reglamento de la Ley del Ejercicio de la Farmacia vigente, publicado en Gaceta Oficial Nº 4.582 extraordinario de fecha 21 de mayo de 1993.

            ";

        $presentacion = "";                    

        $sql="SELECT * FROM vus_tramites_{$_POST['tipo']}2 WHERE vus_{$_POST['tipo']}_numsol = '{$_POST['codigo']}'";
        $result_=$connectionVUS->Execute($sql);
        //echo $sql;
        if (!$result_->EOF) {
            if ($result_->fields["vus_{$_POST['tipo']}_est_id"]=='9')
                $numreg = $result_->fields["vus_{$_POST['tipo']}_numreg"];
            else
                $numreg = $result_->fields["vus_{$_POST['tipo']}_numsol"];
            
            $formid = $result_->fields["vus_{$_POST['tipo']}_forma"];
            $classid = $result_->fields["vus_{$_POST['tipo']}_gt_clas_id"];
        }
        // echo $sql."<br> no reg ".$numreg;  

        $sql="SELECT ctg_clp_desc FROM ctg_clasif_productos WHERE ctg_clp_id = '$classid'";
        $result_f=$connection->Execute($sql);
        if (!$result_f->EOF) 
            $clas_desc = $result_f->fields[0];
            
        $row['064theracate'] = $clas_desc;

        $sql="SELECT * FROM ctg_productos_{$_POST['tipo']} WHERE adm_{$_POST['tipo']}_numreg = '$numreg' ";
        // echo $sql."<br> no reg ".$numreg;  
        $result_=$connection->Execute($sql);
        if (!$result_->EOF) {
            $fecha    = $result_->fields["adm_{$_POST['tipo']}_autori"]; //APPROVAL DATE
            $dispenid = $result_->fields["adm_{$_POST['tipo']}_dispen"];  //SALES CATEGORY
            $fec_aprob = substr($fecha,8,2)."-".substr($fecha,5,2)."-".substr($fecha,0,4);
            $pervalid=$result_->fields["adm_{$_POST['tipo']}_perval1"];
            $condalmaid=$result_->fields["adm_{$_POST['tipo']}_condalma1"];
            if ($cod_verif=="")
                $cod_verif = $result_->fields["adm_{$_POST['tipo']}_cdv"];
        }

        if ( $adm_con_rdv == "") {
            $sql="SELECT ctg_mve_desc, ctg_mve_obs FROM ctg_mod_venta WHERE ctg_mve_id = '$dispenid'";
            $result_f=$connection->Execute($sql);
            if (!$result_f->EOF) {
                $adm_con_rdv = $result_f->fields[0];
                // $disp_obs = $result_f->fields[1];
            }
        }

        if ( $adm_con_perval == "") {
            $sql="SELECT ctg_pva_desc FROM ctg_per_validez WHERE ctg_pva_id = '$pervalid'";
            $result_f=$connection->Execute($sql);
            if (!$result_f->EOF) {
                $adm_con_perval = $result_f->fields[0];
                // $disp_obs = $result_f->fields[1];
            }
        }
        if ( $adm_con_calma == "") {
            $sql="SELECT ctg_cal_desc FROM ctg_cond_almacenamiento WHERE ctg_cal_id = '$condalmaid'";
            $result_f=$connection->Execute($sql);
            if (!$result_f->EOF) {
                $adm_con_calma = $result_f->fields[0];
                // $disp_obs = $result_f->fields[1];
            }
        }
        // ACTUALIZO CAMPOS EN ADM_CONTROL
        $sql="UPDATE adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']} SET
        adm_con_dacdate = '".$adm_con_dacdate."',
        adm_con_issdate = '".$fec_aprob."',
        adm_con_dirname1 = '".$adm_cnf_firma."',
        adm_con_dirdesi1 = '".$designation1."',
        adm_con_dirname2 = '".$adm_cnf_firma2."',
        adm_con_dirdesi2 = '".$designation2."',
        adm_con_salescat = '".$adm_con_salescat."' WHERE adm_con_numsol = '".$_POST['codigo']."' AND adm_con_tpr_id = '".$_POST['ctg_tpr_id']."' AND adm_con_tpt_id = '".$_POST['ctg_tpt_id']."'";
        
        $result = $connection->Execute($sql);                
        $error = $connection->ErrorMsg();   

        ////  BEGIN OF GENERATE FORMULA

        $sql="SELECT ctg_for_desc FROM ctg_formas WHERE ctg_for_id = '$formid'";
        $result_f=$connection->Execute($sql);
        if (!$result_f->EOF) 
            $form_desc .= $result_f->fields[0];

        // if ($adm_con_certxt1==""){
        //     $formula = "";
        //     $formula1 = "";
        //     $formula2 = "";
        //     $numfor=0;
        //     $numings=0;
        //     $arr_for = array();
        //     $nomgenerico = "Each ".$form_desc." Contains";

        //     $sql = "SELECT COUNT(*) AS numing FROM ctg_productos_{$_POST['tipo']}_formula WHERE \"adm_{$_POST['tipo']}FOR_numreg\" = '{$numreg}' AND \"adm_{$_POST['tipo']}FOR_tipo\" = '1' ";
        //     $result_=$connection->Execute($sql);
        //     $numings=$result_->fields[0];

        //     $sql = "SELECT \"adm_{$_POST['tipo']}FOR_sus_nom\", \"adm_{$_POST['tipo']}FOR_unit_desc\", \"adm_{$_POST['tipo']}FOR_can\", \"adm_{$_POST['tipo']}FOR_cominfo\", \"adm_{$_POST['tipo']}FOR_ume_id\", \"adm_{$_POST['tipo']}FOR_ume_oth\", \"adm_{$_POST['tipo']}FOR_id\", \"adm_{$_POST['tipo']}FOR_atc_id\" FROM ctg_productos_{$_POST['tipo']}_formula WHERE \"adm_{$_POST['tipo']}FOR_numreg\" = '{$numreg}' AND (\"adm_{$_POST['tipo']}FOR_tipo\" = '1' OR \"adm_{$_POST['tipo']}FOR_sus_nom\" LIKE '%WATER FOR INJECTION%') ORDER BY \"adm_{$_POST['tipo']}FOR_id\", \"adm_{$_POST['tipo']}FOR_sus_nom\" ";

        //     $result_=$connection->Execute($sql);
        //     while ( !$result_->EOF ) {
        //         if ($result_->fields[6] != $numfor) {
        //             $numfor=$result_->fields[6];
        //             $atc_id=$result_->fields[7];
        //             if (empty($adm_con_dci)){
        //                 $sql2 = "SELECT ctg_cla_desc FROM ctg_clasif_atc WHERE ctg_cla_id= '{$atc_id}'";
        //                 echo $sql2;
        //                 die();
        //                 $result_2=$connection->Execute($sql2);
        //                 if (!$result_2->EOF ){
        //                     $adm_con_dci=$result_2->fields[0];
        //                 }    
        //             }
        //             $sql2 = "SELECT adm_{$_POST['tipo']}_refe{$result_->fields[6]} FROM ctg_productos_{$_POST['tipo']} WHERE adm_{$_POST['tipo']}_numreg = '{$numreg}'";
        //             $result_2=$connection->Execute($sql2);
                    
        //             $arr_for[] = "Cada " . (empty($result_2->fields[0]) ? $form_desc : $result_2->fields[0]) . " contains:";
        //             if ($numfor == 1){
        //                 $formula1 .= "Cada " . (empty($result_2->fields[0]) ? $form_desc : $result_2->fields[0]) . " contains: ";
        //                 $formula2 = "";                 
        //             } else {
        //                 $formula1 .= $formula2."<br><br>";
        //                 $formula1 .= "Cada " . (empty($result_2->fields[0]) ? $form_desc : $result_2->fields[0]) . " contains: ";
        //                 $formula2 = "";
        //             }
        //         }
        //         $txt = '';
        //         if (!empty($formula))
        //             $formula .= ", ";

        //         $valor = $result_->fields[2];
        //         $valor = floatval($valor);
        //         $txt .= $result_->fields[0]." ".$result_->fields[3]." ".$valor;
        //         $unimed=$result_->fields[4];
        //         switch ($unimed) {
        //             case '1':
        //                 $txt .= 'mg'; break;
        //             case '2':
        //                 $txt .= 'mcg'; break;
        //             case '3':
        //                 $txt .= 'IU'; break;
        //             case '4':
        //                 $txt .= $result_->fields[5]; break;
        //         }
        //         $formula .= $txt;
        //         if (!empty($formula2))
        //             $formula2 .= ", ";
        //         $formula2 .=  $txt;
        //         $arr_for[] = "{$txt},";
        //         $result_->MoveNext ();
        //     }   

        //     $formula1 .= $formula2;
        //     $adm_con_certxt1="";//$formula1;            
        // }

        if (empty($adm_con_dci)){
            $sql = "SELECT \"adm_{$_POST['tipo']}FOR_atc_id\" FROM ctg_productos_{$_POST['tipo']}_formula WHERE \"adm_{$_POST['tipo']}FOR_numreg\" = '{$numreg}' AND \"adm_{$_POST['tipo']}FOR_tipo\" = '1' AND \"adm_{$_POST['tipo']}FOR_atc_id\"<>''";
            $result_=$connection->Execute($sql);
            if ( !$result_->EOF ) {
                $atc_id=$result_->fields[0];
                $sql2 = "SELECT ctg_cla_desc FROM ctg_clasif_atc WHERE ctg_cla_id= '{$atc_id}'";
                $result_2=$connection->Execute($sql2);
                if (!$result_2->EOF ){
                    $adm_con_dci=$result_2->fields[0];
                }    
            }
    
        }
            
        if (substr($_POST['id'],0,6) == "03020902" || substr($_POST['id'],0,7) == "0302A0902" || substr($_POST['id'],0,7) == "0302B0902" ) { // 2015-07-23
            $disabled = "";
            $class = "text-input";
            $window = "";
        }   
        ?>                

        <tr>
            <td class=form_standar_cap><?=$arr_label['numreg']?></td>
            <td><input type=text class="text-view" id=numreg name=numreg readonly value="<?=$numreg?>" size=20></td>
        </tr>
        <tr>
            <td class=form_standar_cap>Codigo de verificación</td>
            <td><input type=text class="text-view" id=no_cdv name=no_cdv readonly value="<?=$cod_verif?>" size=50></td>
        </tr>
        <tr><td class=form_standar_cap valign=middle><?=$arr_label['nomprod']?></td>
            <td colspan=6>
                <table width=100% border=0>
                <tr>
                <td width=100%><textarea <?=$disabled?> id="adm_con_nomprod" name="adm_con_nomprod" rows=2 style='width:100%' onchange="guarda_ajax(this,obj,'./includes/');" class="<?=$class?>"><?=$adm_con_nomprod?></textarea>
                <td valign=top>    
                    <ul id="icons" class="ui-widget ui-helper-clearfix">    
                    <li class="ui-state-default ui-corner-all" title="<?=$arr_label['textarea_ttt'].' '.$arr_label['adm_con_nomprod']?>"><span onClick="check_window('adm_con_nomprod','<?=$arr_label['nomprod']?>','<?=$window?>')" class="ui-icon ui-icon-newwin"></span></li>
                    </ul>
                </td>
                </table>    
            </td>   
        </tr>

        <tr><td class=form_standar_cap valign=middle>Ficha tecnica</td>
            <td colspan=6>
                <table width=100% border=0>
                <tr>
                <td width=100%><textarea <?=$disabled?> id="adm_con_certxt1" name="adm_con_certxt1" rows=3 style='width:100%' onchange="guarda_ajax(this,obj,'./includes/');" class="<?=$class?>"><?=$adm_con_certxt1?></textarea>
                <td valign=top>    
                    <ul id="icons" class="ui-widget ui-helper-clearfix">    
                    <li class="ui-state-default ui-corner-all" title="<?=$arr_label['textarea_ttt'].' '.$arr_label['adm_con_certxt1']?>"><span onClick="check_window('adm_con_certxt1','<?=$arr_label['comentarios']?>','<?=$window?>')" class="ui-icon ui-icon-newwin"></span></li>
                    </ul>
                </td>
                </table>    
            </td>   
        </tr>

        <?php //////////////////////////////////////CONSIDERACIONES ADICIONALES/////////////////////////////////////////////// ?>
            
        <tr><td class=form_standar_cap valign=middle><?=$arr_label['adm_con_certxt2']?></td>
            <td colspan=6>
                <table width=100% border=0>
                <tr>
                <td width=100%><textarea <?=$disabled?> id="adm_con_certxt2" name="adm_con_certxt2" rows=3 style='width:100%' class="<?=$class?>"><?=$adm_con_certxt2?></textarea>
                <td valign=top>    
                    <ul id="icons" class="ui-widget ui-helper-clearfix">    
                    <li class="ui-state-default ui-corner-all" title="<?=$arr_label['textarea_ttt'].' '.$arr_label['adm_con_certxt2']?>"><span onClick="check_window('adm_con_certxt2','<?=$arr_label['comentarios']?>','<?=$window?>')" class="ui-icon ui-icon-newwin"></span></li>
                    </ul>
                </td>
                </table>    
            </td>   
        </tr>


        <script type='text/javascript'>
        <?php
            $arr2['tipo'] = $_POST['tipo'];
            $arr2['codigo'] = $_POST['codigo'];
            $arr2['tpr'] = $_POST['ctg_tpr_id'];
            $arr2['tpt'] = $_POST['ctg_tpt_id'];
            $arr2['tabla'] = "ctg_productos_";
            $arr2['numreg'] = $numreg;
            $arr2['flag'] = "adm_{$_POST['tipo']}_vencim"; //primer flag generar recursivo 
            $arr2['db'] = "adm";

            $arr['dtb'] = $_SESSION['dtb_adm'];
            $arr['tipo'] = $_POST['tipo'];
            $arr['codigo'] = $_POST['codigo'];
            $arr['tpr'] = $_POST['ctg_tpr_id'];
            $arr['tpt'] = $_POST['ctg_tpt_id'];
            $arr['tabla'] = "adm_control_";
            $arr['db'] = "adm";
            $arr['obj2'] = $arr2;
            $arr['flag'] = "adm_con_issdate"; //primer flag generar recursivo 
            $js_array = json_encode($arr);
            echo "var obj = ". $js_array . ";\n";
        ?>
        </script>
        <tr>
            <td class=form_standar_cap>DCI</td>
            <td><input class="text-input" name="adm_con_dci" id ="adm_con_idci" type=text class="text-enter" value="<?=$adm_con_dci?>" maxlength=250 size=84 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>
        <!-- //// REGIMEN DE VENTA -->
        <tr>
            <td class=form_standar_cap>Regimen de venta</td>
            <td><input class="text-input" name="adm_con_rdv" id ="adm_con_rdv" type=text class="text-enter" value="<?=$adm_con_rdv?>" maxlength=250 size=84 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>
        <!-- //// CONDICIONES DE ALMACENAMIENTO -->
        <tr>
            <td class=form_standar_cap>Condiciones de almacenamiento</td>
            <td><input class="text-input" name="adm_con_calma" id ="adm_con_calma" type=text class="text-enter" value="<?=$adm_con_calma?>" maxlength=250 size=84 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>
        <!-- //// SISTEMA ENVASE CIERRE -->
        <tr>
            <td class=form_standar_cap>Sistema envase cierre</td>
            <td width=100%><textarea <?=$disabled?> id="adm_con_sec" name="adm_con_sec" rows=3 style='width:80%' onchange="guarda_ajax(this,obj,'./includes/');" class="<?=$class?>"><?=$adm_con_sec?></textarea>
        </tr>
        <!-- //// PERIODO VALIDEZ -->
        <tr>
            <td class=form_standar_cap>Periodo de Validez</td>
            <td><input class="text-input" name="adm_con_perval" id ="adm_con_perval" type=text class="text-enter" value="<?=$adm_con_perval?>" maxlength=250 size=84 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>

        <tr><td class=form_standar_cap valign=middle><?=$arr_label['adm_con_certxt1']?></td>
            <td colspan=6>
                <table width=100% border=0>
                <tr>
                <td width=100%><textarea <?=$disabled?> id="adm_con_preapro" name="adm_con_preapro" rows=3 style='width:84%' onchange="guarda_ajax(this,obj,'./includes/');" class="<?=$class?>"><?=$adm_con_preapro?></textarea>

                </table>    
            </td>   
        </tr>
        

        <tr>
            <td class=form_standar_cap>Iniciales controladas</td>
            <td><input class="text-input" name="adm_con_inicon" id ="adm_con_inicon" type=text class="text-enter" value="<?=$adm_con_inicon?>" maxlength=60 size=60 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>

        <tr>
            <td class=form_standar_cap>Referencia Junta Revisora</td>
            <td><input class="text-input" name="adm_con_dacdate" id ="adm_con_dacdate" type=text class="text-enter" value="<?=$adm_con_dacdate?>" size=20 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>

        <tr>
            <td class=form_standar_cap>Fecha de emision</td>
            <td><input class="text-input" name="adm_con_issdate" id ="adm_con_issdate" type=text class="text-enter" value="<?=$fec_aprob?>" size=10 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>
            
        <tr>
            <td class=form_standar_cap>Nombre de Presidente(a) del INHRR</td>
            <td><input class="text-input" name="adm_con_dirname2" id ="adm_con_dirname2" type=text class="text-enter" value="<?=$adm_con_dirname2?>" size=60 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>
        <tr>
            <td class=form_standar_cap>Descripcion de Presidente(a) del INHRR</td>
            <td width=100%><textarea <?=$disabled?> id="adm_con_dirname1" name="adm_con_dirname1" rows=3 style='width:80%' onchange="guarda_ajax(this,obj,'./includes/');" class="<?=$class?>"><?=$adm_con_dirname1?></textarea>
        </tr>
        <!-- 
        <tr>
            <td class=form_standar_cap>Designation first page</td>
            <td><input class="text-input" name="adm_con_dirdesi1" id ="adm_con_dirdesi1" type=text class="text-enter" value="<?=$designation1?>" size=40 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr> -->

        <!-- 
        <tr>
            <td class=form_standar_cap>Designation second page</td>
            <td><input class="text-input" name="adm_con_dirdesi2" id ="adm_con_dirdesi2" type=text class="text-enter" value="<?=$designation2?>" size=40 onchange="guarda_ajax(this,obj,'./includes/');"></td>
        </tr>         -->

            <?php //////////////////////////////////////lineas/////////////////////////////////////////////// ad_control_ef1 ?>
        <!--         
        <tr><td class=form_standar_cap valign=middle><?=$arr_label['adm_con_cerlins']?></td>
            <td width=100%>
                <select <?=$disabled?> id="adm_con_cerlins" name="adm_con_cerlins" class="<?=$class?>" >
                <?php for ($i=1;$i<21;$i++) echo "<option value=$i ".($adm_con_cerlins == $i?" selected ":"").">$i</option>"; ?>
                </select>
        </tr> -->
            
        <?php } 
                    
        //desabilita todo otra ves
        if (substr($_POST['id'],0,6) == "03020902" || substr($_POST['id'],0,7) == "0302A0902" || substr($_POST['id'],0,7) == "0302B0902") { // 2015-07-23
            $disabled = " disabled ";
            $class = "text-view";
            $window = 1;        
        }
                    
        ?>

        <?php 

        if (empty($disabled)) { 

            //$sql = "SELECT ctg_tpt_accion FROM ctg_tipo_tramites WHERE ctg_tpt_id = '{$_POST['ctg_tpt_id']}' AND ctg_tpr_id = '{$_POST['ctg_tpr_id']}'";
            //$result2=$connection->Execute($sql);
            //if (!$result2->EOF) {
            
                //echo "({$result2->fields[0]})";
                    
                //if ($result2->fields[0] == 1) {
                if ($accion == 1 && ($_POST['id'] == "030208" || $_POST['id'] == "0302A08" || $_POST['id'] == "0302B08") ) {
                    //$sql = "SELECT ctg_tpr_sig1 ||,|| ctg_tpr_sig2 ||,|| ctg_tpr_sig3 ||,|| ctg_tpr_sig4 ||,|| ctg_tpr_sig5 FROM ctg_tipo_productos WHERE ctg_tpr_id = '{$_POST['ctg_tpr_id']}'";
                    
                    $sql = "SELECT ctg_tpr_sig1||','||ctg_tpr_sig2||','||ctg_tpr_sig3||','|| ctg_tpr_sig4||','||ctg_tpr_sig5 FROM ctg_tipo_productos WHERE ctg_tpr_id = '{$_POST['ctg_tpr_id']}'";
                    
                    //echo $sql;
                    $result2=$connection->Execute($sql);
                    if (!$result2->EOF) {
                        $siglas = $result2->fields[0];
                        
                        $arr_sgl = explode(",",$siglas);
                        echo "<tr>
                        <td class=form_standar_cap valign=middle>{$arr_label['siglas']}</td>
                        <td colspan='4'>
                        <select id=siglas name=siglas>";                                
                        echo "<option value=''>{$arr_label['seleccione']}</option>";                
                        foreach($arr_sgl as $sigla)
                            if (!empty($sigla))
                                echo "<option value='$sigla'>$sigla</option>";                
                        echo "</select>
                        </td></tr>";
                    }        
                }
                ?>

                <?php
            //}                   
        }
        ?>                
                
                </table>    
                
            </div>
            
    <?php 
    }

	//inicia 
	if ($_POST['id'] == "03020901" || $_POST['id'] == "0302A0901" || $_POST['id'] == "0302B0901") { ?>            
        
<script>
    function GeneraCodFir(){

		document.getElementById('guarda_firmae').className = "buttonDis";
		document.getElementById('guarda_firmae').disabled = true;
		
		document.getElementById('firmae_cod').value = "";

		if (document.getElementById('sel_efirma1').checked) {

            $.ajax({
	            type: "POST",
	            url: "includes/form_adm_control_etapa_op.php",
	            data: '&op=firmae&ctg_tpt_id=<?=$_POST['ctg_tpt_id']?>&pais=<?=$pais?>&tipo=<?=$_POST['tipo']?>&codigo=<?=$_POST['codigo']?>',
	            dataType: "json",
	            success: function( response ) {
                                            
            			document.getElementById('firmae_cod').value = response.codigo;
            			document.getElementById('firmae_cor').value = response.correlativo;
                		document.getElementById('guarda_firmae').disabled = false;
            			document.getElementById('guarda_firmae').className = "button";

	            },
	            error: function (xhr, status, error) {					    
		            console.log(xhr);
		            console.log(status);
		            console.log(error);
		            
            		call_dialog_standar_1("alert","",'<?=$arr_label['generar'].' '.$arr_label['firma_e']?>',error);
	            }
            });	        

		}

		if (document.getElementById('sel_efirma1').checked && document.getElementById('sel_efirma1').checked) {
		
		} else {
		
		
    		call_dialog_standar_1("alert","",'<?=$arr_label['generar'].' '.$arr_label['firma_e']?>','<?=$arr_label['seleccione_firma_e']?>');
		}

	        
	    return false;
    }
    
    
    function GuardaCodFir(){
    
        confirmar('<?=$arr_label['comfirmar_firma_e']?>','<?=$arr_label['firma_e']?>',"efirma");

	    return false;	        
    }
    

    function GuardaCodFir2(){
		
            $.ajax({
	            type: "POST",
	            url: "includes/form_adm_control_etapa_op.php",
	            data: '&op=guarda_firmae&ctg_tpt_id=<?=$_POST['ctg_tpt_id']?>&ctg_tpr_id=<?=$_POST['ctg_tpr_id']?>&tipo=<?=$_POST['tipo']?>&codigo=<?=$_POST['codigo']?>&firmae_cod='+document.getElementById('firmae_cod').value+'&firmae_cor='+document.getElementById('firmae_cor').value,
	            
	            dataType: "json",
	            success: function( response ) {
                                            
                    call_dialog_standar_1("info","",'<?=$arr_label['firma_e']?>','<?=$arr_label['datos_guardados']?>');
                    
                    limpiar_datos('limpia');
            			
	            },
	            error: function (xhr, status, error) {					    
		            console.log(xhr);
		            console.log(status);
		            console.log(error);
		            
                    call_dialog_standar_1("alert","",'<?=$arr_label['firma_e']?>',error);
		            
	            }
            });	        
            

		    
	    return false;
	        
    }
    
</script>        

        <div id="tabs-3">
            <table border=0 width=100% cellspacing=2 cellpadding=5>
            <tr style="display:none">


                <td width=5% class=form_standar_cap ><?=$arr_label['seleccione']?></td>
                <td>
                    <table align=left>
                    <tr>
                    <td class=form_standar_cap><label for="sel_efirma1"><a href="#"><?=$arr_label['cod_verif']?></a></label></td>
					<td><input type=radio id="sel_efirma1" name="sel_efirma" value="0" <?=$_POST['sel_efirma1']?> checked></td>
					
                    <td class=form_standar_cap><label for="sel_efirma2"><a href="#"><?=$arr_label['firma_e']?></a></label></td>
                    <td><input type=radio id="sel_efirma2" name="sel_efirma" value="1" <?=$_POST['sel_efirma2']?>></td>
                    
                    </table>   
                </td>   
                <td>            
            </tr>
            <tr> 
                <td></td>   
                <td>            
                <button class="button" name=genera_firmae  id=genera_firmae  onclick="return GeneraCodFir();"><?=$arr_label['generar']?></button>
                </td>
            </tr>                
            <tr> 
                <td></td>   
                <td>            
				<input type=text class="text-view"  id=firmae_cod name=firmae_cod readonly value="<?=$adm_con_cdv?>" size=30>
				<input type=hidden                  id=firmae_cor name=firmae_cor >
                </td>
            </tr>                
            <tr> 
                <td></td>   
                <td>            
                <button class="buttonDis" name=guarda_firmae disabled id=guarda_firmae  onclick="return GuardaCodFir();"><?=$arr_label['graba']?></button>
                </td>
            </tr>                
            </table>   
        </div>
                     
                     
<?php   } ?>            
        
        
<?php

$si = '<ul id="icons" class="ui-widget ui-helper-clearfix" style="margin-top:-5px"><li class="ui-state-default ui-corner-all" title="Email enviado"><span class="ui-icon ui-icon-check"></span>'.$arr_label['generar'].' Email</li></ul>';

$no = '<ul id="icons" class="ui-widget ui-helper-clearfix" style="margin-top:-5px"><li class="ui-state-default ui-corner-all" title="Email enviado">'.$arr_label['generar'].'Email<span class="ui-icon ui-icon-cancel"></span></li></ul>';

?>        
        
<?php if ( $_POST['id'] == "03020902" || $_POST['id'] == "0302A0902" || $_POST['id'] == "0302B0902") { ?>  

    <script>

   	function crear_certificado_ajax(id,file2,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id){
	    var param = "tipo=<?=$_POST['tipo']?>";
	    param = param + "&numsol=<?=$_POST['codigo']?>";
	    param = param + "&ctg_tpt_id=<?=$_POST['ctg_tpt_id']?>";
	    param = param + "&ctg_tpr_id=<?=$_POST['ctg_tpr_id']?>";
	    $.ajax({
	        type: "POST",
	        url: "includes/form_adm_control_etapa_op.php",
	        data: "&op=hay_vus_tramites2&" + param,
	        dataType: "json",            
	        success: function( response ) {
		        
		        if (response.res == 1) {
			        	    	
			        //titulo
			        var title = $('#dialog-confirmar').dialog('option', 'title');
			        $('#dialog-confirmar').dialog('option', 'title', nombre_desc);   
			    
			        //botones
			        var buttons = $('#dialog-confirmar').dialog('option', 'buttons');
			        $('#dialog-confirmar').dialog('option', 'buttons', { 
			            "<?php echo $arr_label['cancelar']?>": function() { $(this).dialog('close');},
			            "<?php echo $arr_label['aceptar']?>": function() { 
			               $(this).dialog('close');
			                if (EsCertificado == 1) {
			                    valida_doc(id,file2,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id);
			                } else {
			                    crear_certificado_docname(id,file2,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id);
			                }
			            } 
			        });        

			        //open
			        $('#dialog-confirmar').dialog('open');
			        document.getElementById('dialog-confirmar-conteiner').innerHTML = '<div class=\"dialog_center\"><?=$arr_label['confirm_Genpdf']?></div>';     
			        
		        } else {
		            call_dialog_standar_1("alert","","Inconsistencia de datos","No encontro registro en Vus Tramites 2, Notificar a IT");
				}
	    
	        },
	        error: function (xhr, status, error) {					    
	            console.log(xhr);
	            console.log(status);
	            console.log(error);                
	            call_dialog_standar_1("alert","",nombre_desc,xhr+'\n'+error+'\n'+ status);
	        }
	    });	 
	    return false;
    }


   function valida_doc(id,file2,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id){
        call_dialog_standar_1("info","",nombre_desc,'<?=$arr_label['generando_pdf1']?>validando doc');
        var param = "tipo=<?=$_POST['tipo']?>";
        param = param + "&numsol=<?=$_POST['codigo']?>";
        param = param + "&ctg_tpt_id=" + ctg_tpt_id;
        param = param + "&ttc_id=" + ttc_id;
        param = param + "&ctg_tpr_id=<?=$_POST['ctg_tpr_id']?>";
        param = param + "&id=" + id; //id del formato
        $.ajax({
            type: "POST",
            url: "includes/form_adm_control_etapa_op.php",
            data: "&op=valida_doc&" + param,
            dataType: "json",            
            success: function( response ) {
                console.log(response);
                if (response.res == 1) {
                    crear_certificado_docname(id,file2,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id);
                } else {
                    call_dialog_standar_1("alert","",nombre_desc,"No puede generar no hay documento");
                }
            },
            error: function (xhr, status, error) {					    
                console.log(xhr);
                console.log(status);
                console.log(error);                
                call_dialog_standar_1("alert","",nombre_desc,xhr+'\n'+error+'\n'+ status);
            }
        });	 
    }

   	function crear_certificado_docname(id,file2,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id){

        call_dialog_standar_1("info","",nombre_desc,'<?=$arr_label['generando_pdf']?>');
        
        var param = "tipo=<?=$_POST['tipo']?>";
        param = param + "&numsol=<?=$_POST['codigo']?>";
        param = param + "&ctg_tpt_id=" + ctg_tpt_id;
        param = param + "&ttc_id=" + ttc_id;
        param = param + "&ctg_tpr_id=<?=$_POST['ctg_tpr_id']?>";
        param = param + "&tpt_id=<?=$_POST['ctg_tpt_id']?>";
        param = param + "&id=" + id; //id del formato
                        
        param = param + "&EsCertificado=" + EsCertificado;
        param = param + "&location_adm=<?=$location_adm?>";
        //param = param.replace(/[*]/g,"&");
        
        $.ajax({
            type: "POST",
            url: "includes/form_adm_control_etapa_op.php",            
            data: "&op=certificado_docname&" + param + "&name=" + nombre, //nombre del pdf downloaded
            dataType: "json",            
            success: function( response ) {
            
                console.log(response);
                //param = param.replace(/[&]/g,"*");
                
                if (response.is_dir == true) { //prueba
                
	                param = param + "&path=" + response.path; 
	                param = param + "&name=" + response.nombre; //nombre del pdf downloaded
	                param = param + "&parte=" + response.parte; //nombre del pdf downloaded
	                param = param + "&name_desc=" + nombre_desc; //nombre del pdf downloaded
	                param = param + "&numreg=" + response.numreg; //nombre del pdf downloaded
	                param = param + "&pais=<?=$pais?>";
	                param = param + "&accion=<?=$accion?>";
	                param = param + "&dtb_adm=<?=$_SESSION['dtb_adm']?>";
	                param = param + "&ADMusuario_id=<?=$_SESSION['ADMusuario_id']?>";
	                param = param + "&file2=" + file2; //nombre de plantilla
	                param = param + "&format=F"; //download to server
	                param = param + "&file=resultado_final"; //motor principal de certificados
	                param = param + "&registro=" + response.registro; 
	                param = param + "&adm_cod_tmf_cor=" + response.adm_cod_tmf_cor; 


                //if (file2 == 'resultado_final_4_4.php') {
                
                    var adm_con_certxt1 = '';
                    var adm_con_certxt2 = '';
                    var adm_con_cerlins = 0;

					if (document.getElementById('adm_con_certxt1'))
                    	adm_con_certxt1 = document.getElementById('adm_con_certxt1').value; //periodo validez
					if (document.getElementById('adm_con_certxt2'))
                    	adm_con_certxt2 = document.getElementById('adm_con_certxt2').value; //consideraciones adicionales
					if (document.getElementById('adm_con_certxt3'))
                    	adm_con_cerlins = document.getElementById('adm_con_cerlins').value; 

                    
                    $.post("includes/form_adm_control_etapa_op.php", { op: "CambiosPostRegistro", adm_con_certxt1:adm_con_certxt1, adm_con_certxt2:adm_con_certxt2, adm_con_cerlins:adm_con_cerlins, tipo:"<?=$_POST['tipo']?>", codigo:"<?=$_POST['codigo']?>", ctg_tpr_id:"<?=$_POST['ctg_tpr_id']?>", ctg_tpt_id:"<?=$_POST['ctg_tpt_id']?>" },
                    function(data) {
                        //param = param + "&token="+data.token;
                        if (data.affected == 1) {
	                        console.log("Generando PDF");
	                        console.log(param);
                            window.frames['upload_target'].location.href="includes/html2pdf/html2pdf.php?"+param;
						}
                        else
			                call_dialog_standar_1("alert","","Saving Post Registration Changes ",data.error);
                    },'json');

                //} else {
                //    window.frames['upload_target'].location.href="includes/html2pdf/html2pdf.php?"+param;                    
                //}
					
				} else {					
	                call_dialog_standar_1("alert","","Creation Name and Route","The directory was not generated " + response.path);
				}
                return false;
            },
            error: function (xhr, status, error) {					    
                console.log(xhr);
                console.log(status);
                console.log(error);                
                call_dialog_standar_1("alert","",nombre_desc,xhr+'\n'+error+'\n'+status);
            }
        });	 
    }

    //viene de html2pdf como resultado al finalizar de generar el documento    
    function clean_form(id,ctg_tpt_id,ttc_id,EsCertificado,parte,path,numreg,numsol,name,name_desc,adm_cod_tmf_cor){           
        
        try {

            call_dialog_standar_1("info","",name_desc,'<?=$arr_label['guardando_pdf']?>');

            var param = "tipo=<?=$_POST['tipo']?>";
            param = param + "&numsol=" + numsol; //<?=$_POST['codigo']?>";
            param = param + "&numreg=" + numreg;
            param = param + "&ctg_tpt_id=" + ctg_tpt_id;
            param = param + "&ctg_tpr_id=<?=$_POST['ctg_tpr_id']?>";
            param = param + "&EsCertificado=" + EsCertificado;
            param = param + "&id=" + id; 
            param = param + "&name=" + name;
            param = param + "&parte=" + parte;
            param = param + "&path=" + path;
            param = param + "&name_desc=" + name_desc;
            param = param + "&ttc_id=" + ttc_id;
            param = param + "&adm_cod_tmf_cor=" + adm_cod_tmf_cor;
                
            $.ajax({
                type: "POST",
                url: "includes/form_adm_control_etapa_op.php",
                data: '&op=certificado_docname_save&' + param,            
                dataType: "json",
                success: function( response ) {
                	$('#dialog_standar_1').dialog('close');

                	if (parseInt(response.error) == 0) {

                        var new_path = path.replace("/var/www","");
                        new_path = new_path.replace("/adm/public_html","");
                        new_path = new_path.replace("/html","");

    	                document.getElementById(id).innerHTML = "<img src='includes/images/acroread.png' title='" + name + "' onclick=\"window.open('" + new_path + "/" + name + "', 'pdf', '');\">";

                        document.getElementById(id).innerHTML = "<img src='includes/images/acroread.png' title='" + name + "' onclick=\"window.open('" + new_path + "/" + name + "', 'pdf', '');\">";

    					document.getElementById(id + '_email').innerHTML = "<button class=button onclick=\"return send_email_ajax('" + id + "','" + new_path + "','" + name + "','" + EsCertificado + "','" + name_desc + "','"  + ctg_tpt_id + "','" + ttc_id + "');\" ><span id='" + id + "_email_send'><?=$arr_label['generar1']?>Email</span></button>"; 
    				} else {
                        console.log(response);
    	            	call_dialog_standar_1("alert","",'Saving documents','The document was not generated.-');
    				}
                },
                error: function (xhr, status, error) {	
                    //document.getElementById(id).innerHTML = "";
                    //document.getElementById(id + '_email').innerHTML = "";
                    console.log(xhr);
                    console.log(status);
                    console.log(error);        

                    alert(error);        
                call_dialog_standar_1("alert","",nombre_desc,xhr+'\n'+error+'\n'+ status);
                }
            });	  

        } catch(err) {
            //err.message;
            console.log(err);
        }
    }
     
    function send_email_ajax(id,path,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id){
    
        //titulo
        var title = $('#dialog-confirmar').dialog('option', 'title');
        $('#dialog-confirmar').dialog('option', 'title', 'NOTICE');   
    
        //botones
        var buttons = $('#dialog-confirmar').dialog('option', 'buttons');
        $('#dialog-confirmar').dialog('option', 'buttons', { 
            "<?php echo $arr_label['cancelar']?>": function() { $(this).dialog('close');},
            "<?php echo $arr_label['aceptar']?>": function() { 
                send_email_ajax1(id,path,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id);
                $(this).dialog('close'); 
            } 
        });        

        //open
        $('#dialog-confirmar').dialog('open');
        document.getElementById('dialog-confirmar-conteiner').innerHTML = '<div class=\"dialog_center\"><?=$arr_label['confirm_Emailpdf']?></div>';     
        return false;    

    }

    
    function send_email_ajax1(id,path,nombre,EsCertificado,nombre_desc,ctg_tpt_id,ttc_id){
    
        //call_dialog_standar_1("info","",nombre_desc,'<?=$arr_label['adjuntando_pdf']?>');
        
        var param = "tipo=<?=$_POST['tipo']?>";
        param = param + "&codigo=<?=$_POST['codigo']?>";
        param = param + "&ctg_tpt_id=" + ctg_tpt_id;
        param = param + "&ttc_id=" + ttc_id;
        param = param + "&ctg_tpr_id=<?=$_POST['ctg_tpr_id']?>";
        param = param + "&id=" + id; //id del formato
        param = param + "&EsCertificado=" + EsCertificado;
        param = param + "&location_adm=<?=$location_adm?>";
        param = param + "&name=" + nombre;
        param = param + "&ip_int=<?=$ip_int?>";
        param = param + "&path=" + path;
        param = param + "&tpt_id=<?=$_POST['ctg_tpt_id']?>";
        
        $.ajax({
            type: "POST",
            url: "includes/form_adm_control_etapa_op.php",
            data: "&op=certificado_send&" + param, 
            dataType: "json",            
            success: function( response ) {            
                if (response.send) {
                    call_dialog_standar_1("info","",'<?=$arr_label['genera']?> PDF','Correo electrónico enviado con Exito!!!');
                    $.ajax({
                        type: "POST",
                        url: "includes/form_adm_control_etapa_op.php",
                        data: "&op=certificado_send_save&" + param, 
                        dataType: "json",            
                        success: function( response ) {

                            if (response.affected3 == 0) {                            
                                document.getElementById(id+'_email_send').innerHTML='<?=$si?>';
                                $('#dialog_standar_1').dialog('close');
                            } else {
                                // $('#dialog_standar_1').dialog('close');
                                //call_dialog_standar_1("alert","",nombre_desc,'Error al guardar el email');
                            }
                        },
                        error: function (xhr, status, error) {					    
                            console.log(xhr);
                            console.log(status);
                            console.log(error);                
                        }
                    });	 
                    
                } else {
                    call_dialog_standar_1("alert","",nombre_desc,'Error al enviar el email');
                }
            },
            error: function (xhr, status, error) {					    
                console.log(xhr);
                console.log(status);
                console.log(error);                
                call_dialog_standar_1("alert","",nombre_desc,xhr+'\n'+error+'\n'+ status);
            }
        });	 
            
    }     
   
    function open_url2(myurl){

    var tpr=document.getElementById('ctg_tpr_id').value;
    var tpt=document.getElementById('ctg_tpt_id').value;
    var codigo=document.getElementById('codigo').value;
    var etapa=document.getElementById('etapa').value;
    var tipo=document.getElementById('tipo').value;
    var id=document.getElementById('id').value;
    var tec_id = '<?=$_SESSION['ADMusuario_id']?>';

    var params="&tpr="+ctg_tpr_id+"&codigo="+codigo+"&etapa="+etapa+"&tpt="+ctg_tpt_id+"&tipo="+tipo+"&id="+id+"tec_id="+tec_id;
            //window.open("pestana_imprime.php?"+params, "vent" , "width=1100,height=650,scrollbars=NO");


    //window.open('includes/frmdocs.php?'+params, "vent" , "width=1100,height=650,scrollbars=NO");
    window.open('includes/carga_pdf_oficiales.php', "_blank");
    //window.open(url, '_blank');

    }


    function submit_form_print2(plantilla){
    var doc = "";
    var params = "includes/plantillas_pdf/"+plantilla+"?codesol=<?=$_POST['numsol']?>&tpr_type=<?=$_POST['tipo']?>&doc_name="+doc;
    my_window = window.open(params);
    
    }
    </script>   

    <div id="tabs-4">
            
            <?php
            $final_status="";
            $_POST['cdv']="";
            $sql="SELECT adm_con_rf_status, adm_con_cdv FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']} WHERE 
            adm_con_numsol = '".$_POST['codigo']."' AND 
            adm_con_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
            adm_con_tpt_id = '".$_POST['ctg_tpt_id']."'";
            $result1=$connection->Execute($sql);
            if (!$result1->EOF) {
                if ($result1->fields[0]=="4"){
                    $final_status=strtoupper($arr_label['finaldec']);
                    $final_status .="  <span style = \"color:green\" >".strtoupper($arr_label['approve'])."</span>";
                } else {
                    $final_status=strtoupper($arr_label['finaldec']);
                    $final_status .="  <span style = \"color:red\" >".strtoupper($arr_label['dnapprove'])."</span>";
                }
                $_POST['cdv'] = substr($result1->fields[1],2,33);
            }
            ?>

            <table width=100% cellpadding=5 cellspacing=1 class="light_grid ui-corner-all">
            <td align=center width=75% >
                <?=$final_status?>
            </td>
            <td align=center width=25%>
                
                <style>
                body {font-family: Arial, Helvetica, sans-serif;}

                /* The Modal (background) */
                .modal {
                display: none; /* Hidden by default */
                position: fixed; /* Stay in place */
                z-index: 1; /* Sit on top */
                padding-top: 100px; /* Location of the box */
                left: 0;
                top: 0;
                width: 100%; /* Full width */
                height: 100%; /* Full height */
                overflow: auto; /* Enable scroll if needed */
                background-color: rgb(0,0,0); /* Fallback color */
                background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
                }

                /* Modal Content */
                .modal-content {
                background-color: #fefefe;
                margin: auto;
                padding: 10;
                border: 1px solid #888;
                width: 80%;
                }

                /* The Close Button */
                .close {
                color: #aaaaaa;
                float: right;
                font-size: 28px;
                font-weight: bold;
                }

                .close:hover,
                .close:focus {
                color: #000;
                text-decoration: none;
                cursor: pointer;
                }
                </style>

                <!-- Trigger/Open The Modal -->
                <button class=button width="200px" id="myBtn"><?=$arr_label['carga_pdf_oficiales']?></button>

                <!-- The Modal -->
                <div id="myModal" class="modal">
                    <!-- Modal content -->
                    <div class="modal-content">
                        <span class="close">&times;</span>
                        <iframe
                        id="carga_de_archivos"
                        title="CARGA DE DOCUMENTOS OFICIALES"
                        width="100%"
                        height="75%"
                        src="http://adm.siverc.inhrr.gob.ve/includes/carga_pdf_oficiales.php">
                        </iframe>
                    </div>
                </div>

                <script>
                // Get the modal
                var modal = document.getElementById("myModal");

                // Get the button that opens the modal
                var btn = document.getElementById("myBtn");

                // Get the <span> element that closes the modal
                var span = document.getElementsByClassName("close")[0];

                // When the user clicks the button, open the modal 
                btn.onclick = function() {
                modal.style.display = "block";
                }

                // When the user clicks on <span> (x), close the modal
                span.onclick = function() {
                modal.style.display = "none";
                location.reload(true);
                }

                // When the user clicks anywhere outside of the modal, close it
                window.onclick = function(event) {
                if (event.target == modal) {
                    modal.style.display = "none";
                }
                }
                </script>                
            </td>
            </table>


            <table width=100% cellpadding=5 cellspacing=1 class="light_grid ui-corner-all">
            <thead>
                <tr>
                <td width=2% >ID</td>
                <td width=28% ><?=$arr_label['nombre']?></td>
                <!--
                <td><?=$arr_label['siglas']?></td>
                <td><?=$arr_label['observaciones']?></td>
                -->
                <td width=5% >PDF</td>
                <td width=5% ><?=$arr_label['generar1']?> Ver</td>
                <td width=10% ><?=$arr_label['generar1']?> Enviar</td>
                <td width=10% ><?=$arr_label['generar1']?> Fecha enviado</td>
                </tr>
            </thead>
            <tbody>
            <?php

            $sql = "SELECT b.* FROM ctg_tipo_tramites_formatos a, ctg_tipo_formatos b WHERE a.ctg_tpr_id='".$_POST['ctg_tpr_id']."' AND a.ctg_tpt_id='AO'  AND a.ctg_tpf_dispo = '1' AND a.ctg_tpr_id = b.ctg_tpr_id AND a.ctg_tpf_id = b.ctg_fmt_id ORDER BY b.ctg_fmt_id";
            // echo $sql."<br>";
            $result=$connection->Execute($sql);            
            while ( !$result->EOF ) {
	                $operador = $result->fields;            

	                if ($operador['ctg_fmt_cer'] == 1) {
    	                $ttc = "DR";
    	                $ctg_tpt_id = "AO";
	                } else {
    	                $ttc = "LE";
    	                $ctg_tpt_id = $_POST['ctg_tpt_id'];
	                }
	                
                    $sql = "SELECT vus_{$_POST['tipo']}_numreg, vus_{$_POST['tipo']}_fec_cre, vus_{$_POST['tipo']}_est_id, vus_{$_POST['tipo']}_numsol FROM vus_tramites_{$_POST['tipo']}2 WHERE vus_{$_POST['tipo']}_numsol='{$_POST['codigo']}'";
                    //echo $sql."<br>";
                    $ret=$connectionVUS->Execute($sql);
                    if ($ret->fields["vus_{$_POST['tipo']}_fec_cre"]) {
                    
                                                
                        if ($ret->fields["vus_{$_POST['tipo']}_est_id"]==9)
                            $numreg = $ret->fields["vus_{$_POST['tipo']}_numreg"];
                        else
                            $numreg = $ret->fields["vus_{$_POST['tipo']}_numsol"];                        
                    }
                    $sent_email_dt="";
       
                    $name  = "";
                    $email  = "";
                    $img = "<a><img src='includes/images/acrodis.png' width='30' height='30' border=0></a>";

                    $sql = "SELECT * FROM adm_control_{$_POST['tipo']}1_docs WHERE ".($operador['ctg_fmt_cer'] == 1 ? "adm_cod_numreg = '$numreg'" : "adm_cod_numsol = '{$_POST['numsol']}'")." AND adm_cod_tpt_id = '$ctg_tpt_id' AND adm_cod_tpr_id = '{$_POST['ctg_tpr_id']}' AND adm_cod_ttc_id = '$ttc' AND adm_cod_tmf_id = '{$operador['ctg_fmt_id']}' LIMIT 1";
                    // echo $sql."<br>";
                    $result1=$connection->Execute($sql);
                    if (!$result1->EOF) {
                        $name = $result1->fields["adm_cod_path"].$result1->fields["adm_cod_file"];
                        $send = $result1->fields["adm_cod_email"];
                        $sent_email_dt=fecha_usr($result1->fields["adm_cod_email_sent"]);
                        
                        if ($sent_email_dt=='--')
                            $sent_email_dt='';

                        switch ($ip_int) {
                            case '72.55.131.78':
                                $filename="/var/www/html/siverc".$location_adm.$name;
                                $name = str_replace("/html","",$name);
                                break;
                            default:
                                $filename="/var/www/html/siverc/adm".$name;
                                break;
                        }                       
                        //  echo "<br>file name(".$filename;
                        if (file_exists($filename)) {
                            $email = "<button  class=buttone onclick=\"return send_email_ajax('{$operador['ctg_fmt_id']}','{$filename}','{$operador['ctg_fmt_cer']}','{$operador['ctg_fmt_desc']}','$ctg_tpt_id','$ttc');\" ><span id='{$operador['ctg_fmt_id']}_email_send'>".($send == 1 ? $si : $no)."</span></button>";

                            if ($ip_ext==$ip_int){
                                $url = $ip_ext."/".$location_adm.$name;
                                $onclick = " href='https://".$url."' target='_blank' ";
                            } else {
                                $url = $ip_ext.$location_adm.$name;
                                $onclick = " href='https://".$url."' target='_blank' ";
                            }
                            
                            $img = "<a $onclick><img src='includes/images/acroread.png' width='30' height='30' border=0></a>";

                        } else {
                            $name = "No file";                        
                        }
                    }
                    
                    if (is_file("includes/plantillas_pdf/{$pais}_{$operador['ctg_fmt_nom']}")) {
    	                // $onclick = "<button class=button onclick=\"return crear_certificado_ajax('{$operador['ctg_fmt_id']}','{$operador['ctg_fmt_nom']}','{$operador['ctg_fmt_arc']}','{$operador['ctg_fmt_cer']}','{$operador['ctg_fmt_desc']}','$ctg_tpt_id','$ttc');\" >{$arr_label['generar']}</button>";

					} else {
	                    //$onclick = "{$pais}_{$operador['ctg_fmt_nom']}";
	                    $onclick = "No hay Plantilla";
					}
                    // echo "<tr>
                    // <td>{$operador['ctg_fmt_id']}</td>
                    // <td>{$operador['ctg_fmt_desc']}</td>
                    // <td>{$operador['ctg_fmt_sig']}</td>
                    // <td>{$operador['ctg_fmt_obs']}</td>
                    // <td>$onclick</td>
                    // <td align=center width='100' id='{$operador['ctg_fmt_id']}'>$name</td>
                    // <td align=center width='100' id='{$operador['ctg_fmt_id']}_email'>$email</td>
                    // </tr>";
                    // <a class=\"button\" href=\"includes/TCpdf/formats/{$operador['ctg_fmt_nom']}?nr={$numreg}&ns={$_POST['codigo']}&nt={$_POST['tipo']}&ntc={$_POST['ctg_tpr_id']}&cv={$_POST['cdv']}\" target=\"_blank\" >Generar</a>

                    echo "<tr>
                    <td>{$operador['ctg_fmt_id']}</td>
                    <td>{$operador['ctg_fmt_desc']}</td>
                    <td align=center >
                        <button class=button2 >
                        <a class=\"button\" onclick=\"return submit_form_print2('{$operador['ctg_fmt_nom']}');\" target=\"_blank\" >Generar</a>

                        </button></td>
                    <td align=center width='100' id='{$operador['ctg_fmt_id']}'>$img</td>
                    <td align=center width='100' id='{$operador['ctg_fmt_id']}_email'>$email</td>              
                    <td align=center width='100' id='{$operador['ctg_fmt_email']}'>$sent_email_dt</td>              
                    </tr>";

                    $result->MoveNext ();                    
            }
        ?>
            <tbody>
            </table>
    
        <tr>
            <td>
            <td>
                <?php
                    $sql = "SELECT vus_{$_POST['tipo']}_numreg, vus_{$_POST['tipo']}_fec_cre, vus_{$_POST['tipo']}_est_id FROM vus_tramites_{$_POST['tipo']}2 WHERE vus_{$_POST['tipo']}_numsol='{$_POST['codigo']}'";
                    //echo $sql."<br>";
                    $ret=$connectionVUS->Execute($sql);
                    if ($ret->fields["vus_{$_POST['tipo']}_fec_cre"]) {
                        $numreg = $ret->fields["vus_{$_POST['tipo']}_numreg"];
                    }
                ?>

            </td>
            </td>
        </tr>

        </div>
<?php   } ?>            

<?php if ( $_POST['id'] == "030210" ) { ?>  

    <script>
    function open_url2(myurl){

        var tpr=document.getElementById('ctg_tpr_id').value;
        var tpt=document.getElementById('ctg_tpt_id').value;
        var codigo=document.getElementById('codigo').value;
        var etapa=document.getElementById('etapa').value;
        var tipo=document.getElementById('tipo').value;
        var id=document.getElementById('id').value;
        var tec_id = '<?=$_SESSION['ADMusuario_id']?>';

        var params="&tpr="+ctg_tpr_id+"&codigo="+codigo+"&etapa="+etapa+"&tpt="+ctg_tpt_id+"&tipo="+tipo+"&id="+id+"tec_id="+tec_id;
            //window.open("pestana_imprime.php?"+params, "vent" , "width=1100,height=650,scrollbars=NO");


        //window.open('includes/frmdocs.php?'+params, "vent" , "width=1100,height=650,scrollbars=NO");
        window.open('includes/carga_pdf_oficiales.php', "_blank");
        //window.open(url, '_blank');

    }

    }
    </script>   

    <div id="tabs-41">
        
        <?php
        $final_status="";
        $_POST['cdv']="";
        $sql="SELECT adm_con_rf_status, adm_con_cdv FROM adm_control_{$_POST['tipo']}{$_SESSION['dtb_adm']} WHERE 
        adm_con_numsol = '".$_POST['codigo']."' AND 
        adm_con_tpr_id = '".$_POST['ctg_tpr_id']."' AND 
        adm_con_tpt_id = '".$_POST['ctg_tpt_id']."'";
        $result1=$connection->Execute($sql);
        if (!$result1->EOF) {
            if ($result1->fields[0]=="4"){
                $final_status=strtoupper($arr_label['finaldec']);
                $final_status .="  <span style = \"color:green\" >".strtoupper($arr_label['approve'])."</span>";
            } else {
                $final_status=strtoupper($arr_label['finaldec']);
                $final_status .="  <span style = \"color:red\" >".strtoupper($arr_label['dnapprove'])."</span>";
            }
            $_POST['cdv'] = substr($result1->fields[1],2,33);
        }
        ?>

        <table width=100% cellpadding=5 cellspacing=1 class="light_grid ui-corner-all">
        <td align=center width=75% >
            <?=$final_status?>
        </td>

        </table>

        <table width=100% cellpadding=5 cellspacing=1 class="light_grid ui-corner-all">
        <thead>
            <tr>
            <td width=2% >ID</td>
            <td width=28% ><?=$arr_label['nombre']?></td>
            <td width=5% ><?=$arr_label['generar1']?> Ver</td>
            </tr>
        </thead>
        <tbody>
        <?php

        $sql = "SELECT b.* FROM ctg_tipo_tramites_formatos a, ctg_tipo_formatos b WHERE a.ctg_tpr_id='".$_POST['ctg_tpr_id']."' AND a.ctg_tpt_id='AO'  AND a.ctg_tpf_dispo = '1' AND a.ctg_tpr_id = b.ctg_tpr_id AND a.ctg_tpf_id = b.ctg_fmt_id ORDER BY b.ctg_fmt_id";
        // echo $sql."<br>";
        $result=$connection->Execute($sql);            
        while ( !$result->EOF ) {
                $operador = $result->fields;            

                if ($operador['ctg_fmt_cer'] == 1) {
                    $ttc = "DR";
                    $ctg_tpt_id = "AO";
                } else {
                    $ttc = "LE";
                    $ctg_tpt_id = $_POST['ctg_tpt_id'];
                }
                
                $sql = "SELECT vus_{$_POST['tipo']}_numreg, vus_{$_POST['tipo']}_fec_cre, vus_{$_POST['tipo']}_est_id FROM vus_tramites_{$_POST['tipo']}2 WHERE vus_{$_POST['tipo']}_numsol='{$_POST['codigo']}'";
                //echo $sql."<br>";
                $ret=$connectionVUS->Execute($sql);
                if ($ret->fields["vus_{$_POST['tipo']}_fec_cre"]) {
                    if ($result_->fields["vus_{$_POST['tipo']}_est_id"]=='9')
                        $numreg = $result_->fields["vus_{$_POST['tipo']}_numreg"];
                    else
                        $numreg = $result_->fields["vus_{$_POST['tipo']}_numsol"];
                }
                                    
                $name  = "";
                $email  = "";
                $img = "<a><img src='includes/images/acrodis.png' width='30' height='30' border=0></a>";

                $sql = "SELECT * FROM adm_control_{$_POST['tipo']}1_docs WHERE ".($operador['ctg_fmt_cer'] == 1 ? "adm_cod_numreg = '$numreg'" : "adm_cod_numsol = '{$_POST['numsol']}'")." AND adm_cod_tpt_id = '$ctg_tpt_id' AND adm_cod_tpr_id = '{$_POST['ctg_tpr_id']}' AND adm_cod_ttc_id = '$ttc' AND adm_cod_tmf_id = '{$operador['ctg_fmt_id']}' LIMIT 1";
                //echo $sql."<br>";
                $result1=$connection->Execute($sql);
                if (!$result1->EOF) {
                    $name = $result1->fields["adm_cod_path"].$result1->fields["adm_cod_file"];
                    $send = $result1->fields["adm_cod_email"];
                    switch ($ip_int) {
                        case '72.55.131.78':
                            $filename="/var/www/html/siverc".$location_adm.$name;
                            $name = str_replace("/html","",$name);
                            break;
                        default:
                            $filename="/var/www/html/siverc/adm/".$name;
                            break;
                    }                       
                    //  echo "<br>file name(".$filename;
                    if (file_exists($filename)) {
                        if ($ip_ext==$ip_int){
                            $url = $ip_ext."/".$location_adm.$name;
                            $onclick = " href='https://".$url."' target='_blank' ";
                        } else {
                            $url = $ip_ext.$location_adm.$name;
                            $onclick = " href='https://".$url."' target='_blank' ";
                        }
                        
                        $img = "<a $onclick><img src='includes/images/acroread.png' width='30' height='30' border=0></a>";

                    } else {
                        $name = "No file";                        
                    }
                }
                
                if (is_file("includes/plantillas_pdf/{$pais}_{$operador['ctg_fmt_nom']}")) {
                    // $onclick = "<button class=button onclick=\"return crear_certificado_ajax('{$operador['ctg_fmt_id']}','{$operador['ctg_fmt_nom']}','{$operador['ctg_fmt_arc']}','{$operador['ctg_fmt_cer']}','{$operador['ctg_fmt_desc']}','$ctg_tpt_id','$ttc');\" >{$arr_label['generar']}</button>";

                } else {
                    //$onclick = "{$pais}_{$operador['ctg_fmt_nom']}";
                    $onclick = "No hay Plantilla";
                }
                // echo "<tr>
                // <td>{$operador['ctg_fmt_id']}</td>
                // <td>{$operador['ctg_fmt_desc']}</td>
                // <td>{$operador['ctg_fmt_sig']}</td>
                // <td>{$operador['ctg_fmt_obs']}</td>
                // <td>$onclick</td>
                // <td align=center width='100' id='{$operador['ctg_fmt_id']}'>$name</td>
                // <td align=center width='100' id='{$operador['ctg_fmt_id']}_email'>$email</td>
                // </tr>";
                // <a class=\"button\" href=\"includes/TCpdf/formats/{$operador['ctg_fmt_nom']}?nr={$numreg}&ns={$_POST['codigo']}&nt={$_POST['tipo']}&ntc={$_POST['ctg_tpr_id']}&cv={$_POST['cdv']}\" target=\"_blank\" >Generar</a>

                echo "<tr>
                <td>{$operador['ctg_fmt_id']}</td>
                <td>{$operador['ctg_fmt_desc']}</td>
                <td align=center width='100' id='{$operador['ctg_fmt_id']}'>$img</td>
                </tr>";

                $result->MoveNext ();                    
        }
    ?>
        <tbody>
        </table>

    <tr>
        <td>
        <td>
            <?php
                $sql = "SELECT vus_{$_POST['tipo']}_numreg, vus_{$_POST['tipo']}_fec_cre, vus_{$_POST['tipo']}_est_id FROM vus_tramites_{$_POST['tipo']}2 WHERE vus_{$_POST['tipo']}_numsol='{$_POST['codigo']}'";
                //echo $sql."<br>";
                $ret=$connectionVUS->Execute($sql);
                if ($ret->fields["vus_{$_POST['tipo']}_fec_cre"]) {
                    $numreg = $ret->fields["vus_{$_POST['tipo']}_numreg"];
                }
            ?>

        </td>
        </td>
    </tr>

    </div>
<?php   } ?>           

<?php if ($_POST['id'] == "030504") { ?>
        
        <div id="tabs-5">

    
    <script type="text/javascript">
    
    document.getElementById('graba').className = "button";
    document.getElementById('graba').disabled = false;
    document.getElementById('limpia').className = "button";		
    document.getElementById('limpia').disabled = false;
	</script>
	
	<table border="0" width="80%" align=center>
	<tr>
	    <td width=100 class=form_standar_cap><?=$arr_label['fecha_rechazo']?></td>
	    <td>
	    	<input size=10 maxlength=10 class="text-input" id="adm_con_rf_dt" name="adm_con_rf_dt" value="<?=$_POST['adm_con_rf_dt']?>"> 
	    	<span class=form_standar_cap><?=$formato_fecha?></span>
	    </td>
	</tr>

	<tr>
		<td class=form_standar_cap valign=middle><?=$arr_label['observaciones']?></td>
	    <td colspan=6>
	        <table width=100% border=0>
	        <tr>
	        <td width=100%>
	        	<textarea id="adm_con_rf_obs" name="adm_con_rf_obs" rows=3 style='width:100%' class="tex-input"><?=$_POST['adm_con_rf_obs']?></textarea>
	        </td>
	        <td valign=top>    
	            <ul id="icons" class="ui-widget ui-helper-clearfix">    
	            <li class="ui-state-default ui-corner-all" title="<?=$arr_label['textarea_ttt'].' '.$arr_label['comentarios']?>"><span onClick="check_window('adm_con_rf_obs','<?=$arr_label['comentarios']?>','')" class="ui-icon ui-icon-newwin"></span></li>
	            </ul>
			</td>
			</tr>
	        </table>    
	    </td>   
	</tr>
	</table>
    </div>
<?php   } ?>   

<?php if ($_POST['id'] == '03020701' ) {// para los 0302 no debe llevar conforme ?>           
        <div id="tabs-6">
            <table border="0" width="80%" align=center>
                <tr>
                    <td valign=top align=left style='color:yellow'><?=strtoupper($arr_label['toutcome'])?></td>
                </tr>
                <tr>
                    <td aligtn=center>
                        <table >
                            <tr>
                            <td><input type=radio id="res_st1" name="res_st" value="4"   <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['conforme'])?></label></td>

                            <td><input type=radio id="res_st1" name="res_st" value="3"  <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['no_conforme'])?></label></td>

                            <td><input type=radio id="res_st1" name="res_st" value="5"  <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['unselect'])?></label></td>

                        </table>
                    </td>
                    <td>    
                        <table border="0" align=center  width="100%">
                            <tr>
                            <td valign=top align=center >
                                <button type="button" style="width:150px;"  class="button"  onclick="return checkform_standar_local(this.form,1)"><?=$arr_label['graba']?></button>
                            </td>
                            <tr>
                            <td valign=top align=center>
                                <button type="button" style="width:150px;"  class="button"  onclick="return limpiar_datos('limpia')"><?=$arr_label['salir']?></button>
                            </td>
                            </tr>
                        </table>                    
                    </td>
                </tr>    
            </table>
        </div>
    <?php } ?>

    <?php if ($_POST['id'] == '03020702' ) {// para los 0302 no debe llevar conforme ?>           
        <div id="tabs-7">
            <table border="0" width="80%" align=center>
                <tr>
                    <td valign=top align=left style='color:yellow'><?=$arr_label['voutcome']?></td>
                </tr>
                <tr>
                    <td aligtn=center>
                        <table >
                            <tr>
                            <td><input type=radio id="res_st1" name="res_st" value="4"   <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['conforme'])?></label></td>

                            <td><input type=radio id="res_st1" name="res_st" value="3"  <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['no_conforme'])?></label></td>

                            <td><input type=radio id="res_st1" name="res_st" value="7"  <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['re-assess'])?></label></td>

                            <td><input type=radio id="res_st1" name="res_st" value="5"  <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['unselect'])?></label></td>

                        </table>
                    </td>
                    <td>    
                        <table border="0" align=center  width="100%">
                            <tr>
                            <td valign=top align=center >
                                <button type="button" style="width:150px;"  class="button"  onclick="return checkform_standar_local(this.form,2)"><?=$arr_label['graba']?></button>
                            </td>
                            <tr>
                            <td valign=top align=center>
                                <button type="button" style="width:150px;"  class="button"  onclick="return limpiar_datos('limpia')"><?=$arr_label['salir']?></button>
                            </td>
                            </tr>
                        </table>                    
                    </td>
                </tr>    
            </table>
        </div>
    <?php } ?>

    <?php if ($_POST['id'] == '03020703' ) {// para los 0302 no debe llevar conforme ?>           
        <div id="tabs-8">
            <table border="0" width="80%" align=center>
                <tr>
                    <td valign=top align=left style='color:yellow'><?=strtoupper($arr_label['finaldec'])?></td>
                </tr>
                <tr>
                    <td aligtn=center>
                        <table >
                            <tr>
                            <td><input type=radio id="res_st1" name="res_st" value="4"   <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['endorse'])?></label></td>

                            <td><input type=radio id="res_st1" name="res_st" value="7"  <?=$_POST['res_st1']?>></td>
                            <td class=form_standar_cap><label for="res_st1"><?=strtoupper($arr_label['re-assess'])?></label></td>

                        </table>
                    </td>
                    <td>    
                        <table border="0" align=center  width="100%">
                            <tr>
                            <td valign=top align=center >
                                <button type="button" style="width:150px;"  class="button"  onclick="return  checkform_standar_local(this.form,3)"><?=$arr_label['graba']?></button>
                            </td>
                            <tr>
                            <td valign=top align=center>
                                <button type="button" style="width:150px;"  class="button"  onclick="return limpiar_datos('limpia')"><?=$arr_label['salir']?></button>
                            </td>
                            </tr>
                        </table>                    
                    </td>
                </tr>    
            </table>
        </div>
    <?php } ?>

