2016-10-29 15:07:15 +00:00
< ? php session_start ();
ini_set ( 'display_errors' , 'On' );
if ( isset ( $_REQUEST [ 'debug' ])) { ini_set ( 'display_errors' , 'On' );}
include_once ( " $_SESSION[path] /funciones/conex.php " );
echo brigadistas_grabar ( $_POST );
function brigadistas_grabar ( $formulario ) {
$identificador = $_POST [ 'identificador' ];
$control = md5 ( " $identificador " );
$data = $_POST [ 'debugConsole' ];
$imagen = grabar_imagen ( $data , $control );
$texto_url = urlencode ( " #BrigadaDigital " );
$uri = urlencode ( " $_SESSION[url] /images/secure/?file=600/ $imagen " );
$url = " https://twitter.com/share?url= $uri &text= $texto_url " ;
//$respuesta->addScript("window.location.href ='$url';");
$preview = "
< div class = 'row' >
< div class = 'center-block' >
< div class = 'thumbnail' >
< img src = '$_SESSION[url]/images/secure/?file=300/$imagen' >
< a download = 'brigadistas.png' href = '$_SESSION[url]images/secure/?file=600/$imagen' >
< span class = 'btn btn-default' >< i class = 'fa fa-download' ></ i > </ span >
</ a >
< span class = 'btn btn-default' >
< a onclick = \ " javascript:window.location.href =' $url '; \" ><i class='fa fa-twitter'></i> </a>
</ span >
< a href = '?set=$formulario[formulario_id]&embebido' >
< span class = 'btn btn-default' >< i class = 'fa fa-eye' ></ i > </ span >
</ a >
< a href = '#' onclick = \ " javascript:location.reload(); \" >
< span class = 'btn btn-default' >< i class = 'fa fa-refresh' ></ i > </ span >
</ a >
</ div >
</ div >
</ div >
" ;
//$respuesta = new xajaxResponse('utf-8');
//$identificador = $formulario['identificador'];
$id_formulario = $_POST [ 'formulario_id' ];
$campo_imagen = buscar_campo_tipo ( " $id_formulario " , " 15 " );
$_POST [ $campo_imagen [ 0 ]][ 0 ] = $imagen ;
$empresa = remplacetas ( 'form_id' , 'id' , " $id_formulario " , 'id_empresa' , " " ) ;
$id_empresa = $empresa [ 0 ];
include_once ( " $_SESSION[path] /funciones/conex.php " );
//include_once("$_SESSION[url]funciones/conex.php");
$link = Conectarse ();
2016-11-26 06:35:47 +00:00
mysqli_query ( " SET NAMES 'utf8' " );
2016-10-29 15:07:15 +00:00
$ip = obtener_ip ();
$ip = " INET_ATON(' " . $ip . " ') " ;
foreach ( $_POST as $campo => $valor ){
if ( is_array ( $valor )) {
foreach ( $valor as $c => $v ){
$consulta = " INSERT INTO form_datos ( timestamp,id_usuario,id_empresa,form_id,ip,control,id_campo,contenido) VALUES
( UNIX_TIMESTAMP (), '$_SESSION[id]' , '$id_empresa' , '$id_formulario' , '$ip' , '$control' , '$campo' , '$v' )
" ;
2016-11-26 06:35:47 +00:00
$sql = mysqli_query ( $consulta , $link );
2016-10-29 15:07:15 +00:00
// $campos .= " $campo // $valor // $c -> $v $consulta <br>";
}
}
}
$resultado = " $preview $consulta " ;
///$respuesta->addAssign("aviso","innerHTML","$preview");
//$respuesta->addAlert("$resultado");
//$respuesta->addScript("javascript:location.reload(true);");
return $resultado ;
}
function remplacetas ( $tabla , $campo , $valor , $por , $and ){
$link = Conectarse ();
2016-11-26 06:35:47 +00:00
mysqli_query ( " SET NAMES 'utf8' " );
2016-10-29 15:07:15 +00:00
if ( @ $and != '' ){ $AND = " AND $and " ;} else { $AND = " " ;}
//$consulta = "SELECT * , md5(binary $por ) as md5_".$por." FROM $tabla WHERE $campo = '$valor' $AND order by $campo DESC limit 1";
$consulta = " SELECT * , md5(binary $por ) as md5_ " . $por . " FROM $tabla WHERE $campo = ' $valor ' $AND order by id DESC limit 1 " ;
2016-11-26 06:35:47 +00:00
$sql = mysqli_query ( $consulta , $link );
2018-07-02 18:06:01 +00:00
if ( @ mysqli_num_rows ( $sql ) != 0 ){
$resultado [] = mysqli_result ( $sql , 0 , $por );
$resultado [] = mysqli_result ( $sql , 0 , 'id' );
2016-10-29 15:07:15 +00:00
$resultado [] = $consulta ;
2018-07-02 18:06:01 +00:00
$resultado [] = mysqli_result ( $sql , 0 , " md5_ $por " );
2016-10-29 15:07:15 +00:00
} else {
$resultado [ 0 ] = '' ;
$resultado [ 1 ] = " " ;
$resultado [ 2 ] = $consulta ;
$resultado [ 3 ] = NULL ;
}
return $resultado ;
}
function grabar_imagen ( $imagen , $control ) {
$imgData = str_replace ( ' ' , '+' , $imagen );
$imgData = substr ( $imgData , strpos ( $imgData , " , " ) + 1 );
$imgData = base64_decode ( $imgData );
$nombre = $control . " .png " ;
$filePath = " $_SESSION[path] /tmp/ " . $nombre ;
$file = fopen ( $filePath , 'w' );
fwrite ( $file , $imgData );
fclose ( $file );
$full = " $_SESSION[path_images_secure] /full/ " . $nombre ;
if ( ! rename ( $filePath , $full )){}
else {
echo generar_miniatura ( $nombre , " 150 " );
echo generar_miniatura ( $nombre , " 300 " );
echo generar_miniatura ( $nombre , " 600 " );
}
//return "$nombre";
return " $nombre " ;
}
function generar_miniatura ( $file , $width ) {
//$archivo = $file;
$archivo = " $_SESSION[path_images_secure] /full/ " . $file ;
// Ponemos el . antes del nombre del archivo porque estamos considerando que la ruta está a partir del archivo thumb.php
$file_info = getimagesize ( $archivo );
// Obtenemos la relación de aspecto
$ratio = $file_info [ 0 ] / $file_info [ 1 ];
// Calculamos las nuevas dimensiones
$newwidth = $width ;
$newheight = round ( $newwidth / $ratio );
// Sacamos la extensión del archivo
$ext = explode ( " . " , $file );
$ext = strtolower ( $ext [ count ( $ext ) - 1 ]);
if ( $ext == " jpeg " ) $ext = " jpg " ;
// Dependiendo de la extensión llamamos a distintas funciones
switch ( $ext ) {
case " jpg " :
$img = imagecreatefromjpeg ( $archivo );
break ;
case " png " :
$img = imagecreatefrompng ( $archivo );
break ;
case " gif " :
$img = imagecreatefromgif ( $archivo );
break ;
}
// Creamos la miniatura
$thumb = imagecreatetruecolor ( $newwidth , $newheight );
imagealphablending ( $thumb , false );
imagesavealpha ( $thumb , true );
// La redimensionamos
imagecopyresampled ( $thumb , $img , 0 , 0 , 0 , 0 , $newwidth , $newheight , $file_info [ 0 ], $file_info [ 1 ]);
// La mostramos como jpg
//header("Content-type: image/jpeg");
imagejpeg ( $thumb , " $_SESSION[path_images_secure] / " . $width . " / $file " , 80 );
imagepng ( $thumb , " $_SESSION[path_images_secure] / " . $width . " / $file " , 9 );
//imagegif($thumb,"$_SESSION[path_images_secure]/".$width."/$file");
//imagejpeg($thumb,null, 80);
}
function buscar_campo_tipo ( $id , $tipo ) {
//// esta función retorna el id para un campo de un tipo especifico dentro de un formulario.
$consulta = " SELECT form_campos.id, form_campos.campo_nombre FROM form_tipo_campo,form_campos,form_contenido_campos
WHERE form_tipo_campo . id_tipo_campo = form_campos . campo_tipo
AND form_contenido_campos . id_campo = form_campos . id
AND form_tipo_campo . id_tipo_campo = '$tipo'
AND form_contenido_campos . id_form = '$id' " ;
$link = Conectarse ();
2016-11-26 06:35:47 +00:00
mysqli_query ( " SET NAMES 'utf8' " );
$sql = mysqli_query ( $consulta , $link );
2018-07-02 18:06:01 +00:00
if ( mysqli_num_rows ( $sql ) != '0' ){
$resultado [ 0 ] = mysqli_result ( $sql , 0 , " id " );
$resultado [ 1 ] = mysqli_result ( $sql , 0 , " campo_nombre " );
2016-10-29 15:07:15 +00:00
$resultado [ 2 ] = $consulta ;
} else { $resultado [ 0 ] = '' ;
$resultado [ 2 ] = $consulta ;
}
return $resultado ;
}
function obtener_ip ()
{
if ( isset ( $_SERVER [ " HTTP_CLIENT_IP " ]))
{
return $_SERVER [ " HTTP_CLIENT_IP " ];
}
elseif ( isset ( $_SERVER [ " HTTP_X_FORWARDED_FOR " ]))
{
return $_SERVER [ " HTTP_X_FORWARDED_FOR " ];
}
elseif ( isset ( $_SERVER [ " HTTP_X_FORWARDED " ]))
{
return $_SERVER [ " HTTP_X_FORWARDED " ];
}
elseif ( isset ( $_SERVER [ " HTTP_FORWARDED_FOR " ]))
{
return $_SERVER [ " HTTP_FORWARDED_FOR " ];
}
elseif ( isset ( $_SERVER [ " HTTP_FORWARDED " ]))
{
return $_SERVER [ " HTTP_FORWARDED " ];
}
else
{
return $_SERVER [ " REMOTE_ADDR " ];
}
}
?>