Location: PHPKode > projects > Pindorama > pindorama/etc/includes/data-form.php
<?php

global $l;
if ($df["language"] == "en-us") {
    $l["form"] = array(
      "fill_required" => "Try correcting the following:",
      "field" => "The field ",
      "mandatory" => " is mandatory.",
      "from_addr" => "Sent from the address ",
      "at" => " at ",
      "");
} else {
    $l["form"] = array(
      "fill_required" => "Experimente corrigir os seguintes erros:",
      "field" => "O campo ",
      "mandatory" => " é obrigatório.",
      "from_addr" => "Enviado do endereço ",
      "at" => " às ",
      "");
}

function make_path ($path) {
	global $c;
	$file = basename($path);
    $diretorio = "";
    $temp = split ("/", $path);
    foreach ($temp as $p) {
        $dir = $dir.$p;
        if (substr($dir, 0, strlen($c["base"])) == $c["base"]) {
            if ($p == $file) {
                return true;
                exit;
            } elseif (!is_dir ($dir) && $dir != "") {
                if (!mkdir($dir, 0775)){
                    echo "o diretório ".$dir." não existe";
                    return false;
                    exit;
                }
                $dir = $dir."/";
            } else {
                $dir = $dir."/";
            }
        } else {
            $dir = $dir."/";
        }
    }
} //make_path

function serialize_jsform ($post)
{
    $str  = "\n\n\nvar post=[];";
    $str .= serialize_js($post);
    echo '<script type="text/javascript" charset="iso-8859-1">'.$str."window.onload=function(){ parse_post(post, document.usr);} ;</script>";
    return true;
}

function serialize_js($el, $name="")
{
    $str = "";
    if (is_array($el)) {
        foreach ($el as $k=>$v) {
            if ($name != "") {
                $k = $name."[$k]";
            }
            $str .= serialize_js($v, $k);
        }
    } else {
        $str .= 'post[post.length] = { name:"'.$name.'", value:"'.str_replace(array("\n", "\r", '"'), array("\\n", "", "&quote;"), $el).'"};';
    }
    return $str;
}

function send_data()
{
    global $df, $l;
    $df["http-cookie"]      = $_SERVER["HTTP_COOKIE"];
    $df["http-host"]        = $_SERVER["HTTP_HOST"];
    $df["http-referer"]     = $_SERVER["HTTP_REFERER"];
    $df["remote-address"]   = $_SERVER["REMOTE_ADDR"];
    $df["remote-port"]      = $_SERVER["REMOTE_PORT"];
    $df["remote-port"]      = $_SERVER["REMOTE_PORT"];
    $df["request-uri"]      = $_SERVER["REQUEST_URI"];
    $df["script-name"]      = $_SERVER["SCRIPT_NAME"];
    $df["date"]             = date("Y-m-d\TH:i:s");
    /*
    echo "<pre>";
    print_r($df);
    echo "</pre>";
    exit();
    */
    if ($df["method"] != "") {
        eval("\$res = {$df['method']}();");
        if (!$res) {
            return false;
        }
    }
    if (is_array($df["to"]) && count($df["to"]) > 0 && !email_message()) {
        //não foi possível mandar o email
        return false;
    }
    // falta armazenar a informação
    
    $contents = $df;
    unset($contents["error-message"]);
    unset($contents["success-message"]);
    unset($contents["content"]);
    unset($contents["elements"]);
    $contents = serialize($contents);
    $file = $df["data-dir"].preg_replace("/^[^:]+\:/", "", $df["id"])."__".$df["remote-address"].".".$df["remote-port"]."-".date("YmdHis");
    $file = preg_replace("/[^a-z\_\-0-9\/\:\.]*/i", "", $file);
    if ($file == "") {
        return false;
    } else if ($contents != "") {
        $dir = dirname($file);
        if (!is_dir($dir)) {
            make_path($file);
        }
        $fd = @fopen ($file, "wb");
        if ($fd != false) {
            fwrite ($fd, $contents);
            fclose ($fd);
            return true;
        } else {
            return false;
        }
    }
    return false;
}

function email_message()
{
    global $df, $l;
    $to = implode(", ", $df["to"]);
    $subject = $df['title'].": ".$df['post']['x']['ref'][$df['elements'][0]['name']];
    $from = "hide@address.com";
    $msg = "";
    $err = "";
    foreach ($df["elements"] as $tmp) {
        //html message
        /*$msg .= "<tr><th>{$tmp['label']}</th><td>".$df['post']['x']['ref'][$tmp['name']]."</td></tr>";*/
        $msg .= "\n";
        if (strlen($tmp['label']) > 20) {
            $msg .= "\n".$tmp['label']."\n".str_repeat(" ", 20);
        } else {
            $msg .= str_pad($tmp['label'], 20);
        }
        $msg .= str_replace("\n", "\n".str_repeat(" ", 20), wordwrap($df['post']['x']['ref'][$tmp['name']], 50, "\n"));
        if ($tmp["required"] == "yes" && !(is_array($df['post']['x']['ref'][$tmp['name']]) || $df['post']['x']['ref'][$tmp['name']] != "")) {
            $err .= "<p>{$l['form']['field']}'{$tmp['label']}'{$l['form']['mandatory']}</p>".$df['post']['x']['ref'][$tmp['name']];
        }
        if ($tmp["type"] == "email" && preg_match("/([a-z0-9\.\-\_]+\@[a-z0-9\.\-\_]+)/i", $df['post']['x']['ref'][$tmp['name']], $matches)) {
            $reply = $matches[1];
        }
    }
    if ($err != "") {
        $df["error-message"] .= "<p>".$l["form"]["fill_required"]."</p>".$err;
        return false;
    }
    //html message
    /*
    $msg = <<<FIM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Entre em contato</title>
<meta name="date" scheme="W3CDTF" content="{$df['date']}" />
<meta name="type" content="text" />
<meta name="format" content="text/html" />
<style type="text/css">* { font-family: Arial, Sans-serif; font-size: small; } th, td { text-align: left; vertical-align: top; padding: 5px 20px 10px 0; } th { width: 100px; color: #999999; }</style>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0">
$msg
</table>
<hr width="1" noshade="noshade" />
<p class="small">{$l["form"]["from_addr"]}{$df["remote-address"]}:{$df["remote-port"]}{$l["form"]["at"]}{$df["date"]}.</p>
</body>
</html>
FIM;
    */
    $msg .= "\n\n".str_repeat("_", 30)."\n{$l['form']['from_addr']}{$df['remote-address']}:{$df['remote-port']}{$l['form']['at']}{$df['date']}.";
    $headers  = "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; 
    $headers .= "From: {$from}\r\n";
    if ($reply != "") {
        $headers .= "Reply-to: {$reply}\r\n";
    }
    $msg = str_replace(array("\r\n", "\n"), array("\n", "\r\n"), $msg); 
	$headers = str_replace(array("\r\n", "\n"), array("\n", "\r\n"), $headers); 
    if (mail($to, $subject, $msg, $headers)){
        return true;
    } else {
        return false;
    }
}
?>
Return current item: Pindorama