Example #1
0
 /**
  * VALIDATE()
  *
  * Valida dados enviados em formulários automaticamente de acordo com regras
  * descritas nos respectivos Models.
  *
  * @param mixed $data Contém os dados para validação
  * @param bool $sub Para verificar Models recursivamente, não deve ser usado
  * externamente.
  * @return bool Se validar, retorna verdadeiro
  */
 public function validate($data, $sub = false)
 {
     /**
      * @todo - verificar $sub
      * 
      * Se $this->invalidate() já foi chamado, não limpa session.
      */
     /**
      * Limpa Session
      */
     if (!$sub && !$this->invalidated) {
         unset($_SESSION["Sys"]["FormHelper"]["notValidated"]);
     }
     /**
      * Inicializa variáveis
      */
     $validationRules = $this->validation;
     $vE = array();
     if (is_array($data)) {
         foreach ($data as $model => $campos) {
             /*
              * Model principal
              */
             if ($model == get_class($this) and !empty($validationRules)) {
                 /**
                  * Campos de um formulário enviado
                  */
                 foreach ($campos as $campo => $valor) {
                     /**
                      * Se o campo possui regras de validação
                      */
                     if (array_key_exists($campo, $validationRules)) {
                         /**
                          * VALIDAÇÃO
                          */
                         $vR = $validationRules[$campo];
                         /**
                          * Uma regra somente
                          */
                         if (array_key_exists("rule", $vR)) {
                             $allRules[] = $vR;
                         } else {
                             if (is_array($vR)) {
                                 foreach ($vR as $subRule) {
                                     if (array_key_exists("rule", $subRule)) {
                                         $allRules[] = $subRule;
                                     }
                                 }
                             }
                         }
                         $paramsToValidate = array("valor" => $valor, "model" => $this, "campo" => $campo, "vR" => $vR);
                         /**
                          * Com todas as regras, faz loop validando
                          */
                         if (!empty($allRules) and is_array($allRules)) {
                             foreach ($allRules as $rule) {
                                 /**
                                  * VALIDA DE FATO
                                  *
                                  * Verifica se funções de validação existem
                                  */
                                 /**
                                  * Função de validação pré-existente
                                  */
                                 if (is_string($rule["rule"]) and method_exists("Validation", $rule["rule"])) {
                                     $result = call_user_func("Validation::" . $rule["rule"], $valor);
                                 } elseif (is_string($rule["rule"]) and method_exists($this, $rule["rule"])) {
                                     $result = $this->{$rule["rule"]}($valor);
                                 } elseif (is_array($rule["rule"]) and method_exists("Validation", reset(array_keys($rule["rule"])))) {
                                     $result = call_user_func("Validation::" . reset(array_keys($rule["rule"])), $valor, reset(array_values($rule["rule"])));
                                 } elseif (is_array($rule["rule"]) and method_exists($this, reset(array_keys($rule["rule"])))) {
                                     $result = $this->{reset(array_keys($rule["rule"]))}($valor, reset(array_values($rule["rule"])));
                                 } else {
                                     if (is_array($rule["rule"])) {
                                         $inexistentRule = reset(array_keys($rule["rule"]));
                                     } elseif (is_string($rule["rule"])) {
                                         $inexistentRule = $rule["rule"];
                                     }
                                     showError("Regra de validação <em>" . $inexistentRule . "</em> do model <em>" . get_class($this) . "</em> inexistente");
                                 }
                                 /**
                                  * [Não validou]
                                  */
                                 if (!$result) {
                                     /*
                                      * Session para formHelper
                                      */
                                     /*
                                      * Pega mensagem
                                      */
                                     if (!empty($rule["message"])) {
                                         $message = $rule["message"];
                                     } else {
                                         if (!empty($rule["m"])) {
                                             $message = $rule["m"];
                                         } else {
                                             if (isDebugMode()) {
                                                 showWarning("Mensagem de validação do campo " . $campo . " não especificada");
                                             }
                                             $message = "Not validated!";
                                         }
                                     }
                                     /**
                                      * Caso seja um model-filho no
                                      * relacionamento de models
                                      */
                                     if ($sub) {
                                         $vE[$campo] = '1';
                                     } else {
                                         $vE[$model][$campo] = '1';
                                     }
                                     $_SESSION["Sys"]["FormHelper"]["notValidated"][$model][$campo]["message"] = $message;
                                 }
                                 // fim [não validou]
                             }
                         }
                         unset($allRules);
                     }
                 }
                 // fim foreach($campos)
             } elseif (empty($validationRules)) {
                 /*
                  * Não faz nada :)
                  */
             } else {
                 if (!$this->{$model}->validate(array($model => $campos), true)) {
                     $vE[$model] = 0;
                 }
             }
         }
     }
     /**
      * $vE: Validations Errors
      */
     /* se já houve invalidações manuais com $this->invalidate() */
     if ($this->invalidated) {
         return false;
     }
     /**
      * Se validou, retorna true
      */
     if (!empty($vE)) {
         return false;
     } else {
         return true;
     }
 }
Example #2
0
 /**
  * Efetua conexão via PDO.
  * 
  * Esta função é executada somente se a extensão 'PDO' estiver ativada.
  *
  * @param array $dbConfig Possui dados para conexão no DB
  *      driver: tipo de driver/db (mysql, postgresql, mssql, oracle, etc)
  *      database: nome da base de dados
  *      server: endereço da base de dados
  *      username: nome de usuário para acesso ao db
  *      password: senha para acesso ao db
  */
 protected function PdoInit($dbConfig)
 {
     $dbConfig['driver'] = empty($dbConfig['driver']) ? 'mysql' : $dbonfig['driver'];
     $charset = empty($dbConfig["encoding"]) ? "" : ";charset=" . $dbConfig["encoding"];
     $this->usingPdo = true;
     try {
         $this->conn = new PDO($dbConfig['driver'] . ':host=' . $dbConfig['server'] . ';' . 'dbname=' . $dbConfig['database'] . $charset, $dbConfig['username'], $dbConfig['password'], array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
     } catch (Exception $e) {
         if (isDebugMode()) {
             echo $e->getMessage();
         }
         exit;
     }
     $this->connected = true;
     /**
      * Ajusta charset no Banco de dados
      */
     if (!empty($dbConfig["encoding"])) {
         $this->conn->exec("SET NAMES '" . $dbConfig["encoding"] . "'");
         $this->conn->exec("SET character_set_connection=" . $dbConfig["encoding"]);
         $this->conn->exec("SET character_set_client=" . $dbConfig["encoding"]);
         $this->conn->exec("SET character_set_results=" . $dbConfig["encoding"]);
     }
     if ($this->conn) {
         $this->DBExiste = true;
     }
     //$this->con = $dbConfig[]':host=localhost;dbname=test';
 }
Example #3
0
<?php

/**
 * My Application bootstrap file.
 */
date_default_timezone_set('UTC');
// Load Nette Framework or autoloader generated by Composer
require __DIR__ . '/../vendor/autoload.php';
// Configure application
$configurator = new Nette\Configurator();
if (function_exists('isDebugMode') and isDebugMode($debugArray) == true) {
    $configurator->setDebugMode(true);
}
// Enable RobotLoader - this will load all classes automatically
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->enableDebugger(__DIR__ . '/../log');
$configurator->createRobotLoader()->addDirectory(APP_DIR)->register();
// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/config/config.neon', false);
$configurator->addConfig(__DIR__ . '/config/config.local.neon', false);
if ($configurator->isDebugMode()) {
    define('ENVIRONMENT', 'DEVELOPMENT');
} else {
    define('ENVIRONMENT', 'PRODUCTION');
    $container->application->catchExceptions = true;
}
$container = $configurator->createContainer();
$container->application->run();
Example #4
0
$MT_DIR = "{$APP_DIR}/../mt";
if (!file_exists("{$MT_DIR}/include/http_functions.php")) {
    $MT_DIR = "{$APP_DIR}/../MediaThingy";
}
require_once "{$MT_DIR}/include/http_functions.php";
require_once "{$MT_DIR}/include/text_functions.php";
require_once "{$MT_DIR}/include/debug_functions.php";
require_once "{$MT_DIR}/include/path_functions.php";
require_once "{$MT_DIR}/include/dir_functions.php";
require_once "{$MT_DIR}/include/array_functions.php";
require_once "{$MT_DIR}/include/config_functions.php";
require_once "{$MT_DIR}/include/file_functions.php";
require_once "{$MT_DIR}/include/image_functions.php";
require_once "{$MT_DIR}/include/exif_functions.php";
require_once "{$MT_DIR}/include/ui_functions.php";
require_once "{$MT_DIR}/include/json_xml_functions.php";
require_once "{$MT_DIR}/include/command_functions.php";
require_once "{$MT_DIR}/include/ffmpeg_functions.php";
require_once "{$APP_DIR}/include/SqlManager.php";
require_once "{$APP_DIR}/include/db_functions.php";
require_once "{$APP_DIR}/include/fp_functions.php";
require_once "{$APP_DIR}/include/query_functions.php";
//require_once("$APP_DIR/include/data_html_functions.php");
require_once "{$APP_DIR}/include/email_functions.php";
$fpConfig = readConfigFile("{$APP_DIR}/fp.config");
readConfigFile("{$APP_DIR}/fp.local.config", $fpConfig);
$config = $fpConfig;
if (isDebugMode()) {
    header("Content-Type: text/plain");
}
startTimer();