<?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'];

// tipo
// empr
// ptov
// mrca


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 ".$codigo)); 
//           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']!='image/png' and $_FILES['xfile']['type']!='image/jpeg')
     {    
          $msgswal->appendChild($dom->createElement("icon","error")); 
          $msgswal->appendChild($dom->createElement("title","Error")); 
          $msgswal->appendChild($dom->createElement("text","TIPO de Archivo NO VALIDO")); 
     }
else
     {
          $xpath='../_logo/';
          $xcad=date("ymd_Hi");
//           $xname2=$codigo.'_'.$xcad.'.png';
          $xname2=$empr0['empr_codigo'].'_'.$tipo.'_'.$ptoe.'_'.$xcad.'.png';
     
          if($empr0['empr_ceuser']==1)
          {$xname2=$codigo.'_'.$xcad.'.png';}
     
          move_uploaded_file($_FILES['xfile']['tmp_name'],$xpath.$xname2);

          $sql_logo ='insert into ';
//           $sql_logo.=''.$tabla.'0('.$tabla.'_descri,'.$tabla.'_tipo,'.$tabla.'_status,'.$tabla.'_enti,'.$tabla.'_file,'.$tabla.'_iuser,'.$tabla.'_idate)';
//           $sql_logo.='value("'.$_FILES['xfile']['name'].'","'.$tipo.'","-","'.$enti.'","'.$xname2.'","'.$user_codigo.'",now())';
          $sql_logo.=''.$tabla.'0('.$tabla.'_descri,'.$tabla.'_tipo,'.$tabla.'_status,'.$tabla.'_enti,'.$tabla.'_ptoe,'.$tabla.'_file,'.$tabla.'_iuser,'.$tabla.'_idate)';
          $sql_logo.='value("'.$_FILES['xfile']['name'].'","'.$tipo.'","-","'.$enti.'","'.$ptoe.'","'.$xname2.'","'.$user_codigo.'",now())';
          $res_logo=msql_query($sql_logo,$link_data);
     
          $msgswal->appendChild($dom->createElement("icon","success")); 
          $msgswal->appendChild($dom->createElement("title","Archivo Cargado")); 
          $msgswal->appendChild($dom->createElement("text",$codigo.' = '.($_FILES['xfile']['name']))); 
     
          if($_FILES['xfile']['type']!='image/jpg')
          {}
     }
echo $dom->saveXML();

     
?>