<?php
session_start();
foreach($_GET  as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}  
foreach($_POST as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}

include_once('lib_main.php');
if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}
$user_codigo=$_SESSION['user_codigo'];
$user0=data_maes('user',$user_codigo);
$empr0=data_maes('empr',$empr);
     
$dom = new DOMDocument();
     $dom->encoding = 'utf-8';
     $dom->xmlVersion = '1.0';
     $dom->formatOutput = true;

$response=$dom->appendChild($dom->createElement("response"));
$msgswal=$response->appendChild($dom->createElement("msgswal")); 
     $msgswal->setAttribute("id","msgswal");

// echo '*/*/*/'.$_FILES['xfile']['type'];

if(empty($tabla))
     {
          $msgswal->appendChild($dom->createElement("icon","error")); 
          $msgswal->appendChild($dom->createElement("title","Error")); 
          $msgswal->appendChild($dom->createElement("text","Maestro NO VALIDO")); 
     }
elseif(empty($codigo))
     {    
          $msgswal->appendChild($dom->createElement("icon","error")); 
          $msgswal->appendChild($dom->createElement("title","Error")); 
          $msgswal->appendChild($dom->createElement("text","Código NO VALIDO")); 
          if($empr0['empr_ceuser']==1)
          {$msgswal->appendChild($dom->createElement("text","Cédula NO VALIDA"));}
     }
elseif(empty($_FILES['xfile']['name']))
     {    
          $msgswal->appendChild($dom->createElement("icon","error")); 
          $msgswal->appendChild($dom->createElement("title","Error")); 
          $msgswal->appendChild($dom->createElement("text","Archivo NO VALIDO")); 
     }
elseif($_FILES['xfile']['type']!='application/pkcs12' and $_FILES['xfile']['type']!='application/x-pkcs12')
     {    
          $msgswal->appendChild($dom->createElement("icon","error")); 
          $msgswal->appendChild($dom->createElement("title","Error")); 
          $msgswal->appendChild($dom->createElement("text","TIPO de Archivo NO VALIDO")); 
     }
else
     {
          $xpath='../_pk12/';
          $xcad=date("ymd_Hi");
          $xname2=$codigo.'_'.$xcad.'.p12';
          move_uploaded_file($_FILES['xfile']['tmp_name'],$xpath.$xname2);

          $sql_pk12 ='insert into ';
          $sql_pk12.=''.$tabla.'0('.$tabla.'_descri,'.$tabla.'_status,'.$tabla.'_enti,'.$tabla.'_file,'.$tabla.'_pass,'.$tabla.'_iuser,'.$tabla.'_idate)';
          $sql_pk12.='value("'.$_FILES['xfile']['name'].'","-","'.$codigo.'","'.$xname2.'","'.$p12pass.'","'.$user_codigo.'",now())';
          $res_pk12=msql_query($sql_pk12,$link_data);
     
          $msgswal->appendChild($dom->createElement("icon","success")); 
          $msgswal->appendChild($dom->createElement("title","Archivo Cargado")); 
          $msgswal->appendChild($dom->createElement("text",$codigo.' = '.($_FILES['xfile']['name']))); 
     
// p12	application/pkcs-12
// p12	application/x-pkcs12
     
          if($_FILES['xfile']['type']!='image/jpg')
          {}
     
     }
echo $dom->saveXML();

     
?>