<?php
session_start();


require_once "../../../../config/database.php";

if (empty($_SESSION['username']) && empty($_SESSION['password'])){
    echo "<meta http-equiv='refresh' content='0; url=index.php?alert=1'>";
}

else {
    if ($_GET['act']=='insert') {
        if (isset($_POST['Guardar'])) {
     
			$id  = mysqli_real_escape_string($mysqli, trim($_POST['id']));
            $host  = mysqli_real_escape_string($mysqli, trim($_POST['host']));
			$port  = mysqli_real_escape_string($mysqli, trim($_POST['port']));
            $nombre  = mysqli_real_escape_string($mysqli, trim($_POST['nombre']));
			$usuario  = mysqli_real_escape_string($mysqli, trim($_POST['usuario']));	
			$password  = mysqli_real_escape_string($mysqli, trim($_POST['password']));
            $setname  = mysqli_real_escape_string($mysqli, trim($_POST['setname']));
		
		
		
			
		

  
            $query = mysqli_query($mysqli, "INSERT INTO envio (id,host,port,nombre,usuario,password,setname) 
													  VALUES('$id','$host','$port','$nombre','$usuario','$password','$setname')")
                                            or die('error '.mysqli_error($mysqli));    

        
            if ($query) {
         
                header("location: ../../../../main.php?module=parametro_envio&alert=1");
            }   
        }   
    }
    
 	
	
	   elseif ($_GET['act']=='update') {
        if (isset($_POST['Guardar'])) {
            if (isset($_POST['id'])) {
        
              $id  = mysqli_real_escape_string($mysqli, trim($_POST['id']));
            $host  = mysqli_real_escape_string($mysqli, trim($_POST['host']));
			$port  = mysqli_real_escape_string($mysqli, trim($_POST['port']));
            $nombre  = mysqli_real_escape_string($mysqli, trim($_POST['nombre']));
			$usuario  = mysqli_real_escape_string($mysqli, trim($_POST['usuario']));	
			$password  = mysqli_real_escape_string($mysqli, trim($_POST['password']));
            $setname  = mysqli_real_escape_string($mysqli, trim($_POST['setname']));
              

                $query = mysqli_query($mysqli, "UPDATE envio SET  host       = '$host',
                                                                    port       = '$port',																	
                                                                    nombre     = '$nombre',
																	usuario    = '$usuario',
                                                                    password   = '$password',
                                                                    setname    = '$setname'
																
                                                              WHERE id       = '$id'")
                                                or die('error: '.mysqli_error($mysqli));

    
                if ($query) {
                  
                    header("location: ../../../../main.php?module=parametro_envio&alert=2");
                }         
            }
        }
    }

    elseif ($_GET['act']=='delete') {
        if (isset($_GET['id'])) {
            $id = $_GET['id'];
      
            $query = mysqli_query($mysqli, "DELETE FROM envio WHERE id='$id'")
                                            or die('error '.mysqli_error($mysqli));


            if ($query) {
     
                header("location: ../../../../main.php?module=parametro_envio&alert=3");
            }
        }
    }       
}       
?>