<?php
ini_set('display_errors', 'on');
error_reporting(1);
/*ini_set('display_errors', 'off');
error_reporting(0);*/
set_time_limit(6000);
ini_set('max_execution_time', 6000);

//response array
$response_request = array();
//fields with errors
$errors = array();
//response from validations
$validations_errors = array();
function AutomaticAssignment($source, $class){
  foreach($source as $key => $value){
    $class->$key = $value;
  }
}
function SanitizeRequest($rules, $exclude){
  $utils = new Utils();
  foreach($_POST as $key => $value){
    if(!in_array($key, $exclude)){
      $_POST[$key]= $utils->SanitizeString($value);
    }
    if(isset($rules[$key])){
      $response = $utils->Validate($_POST[$key],$rules[$key][0], $rules[$key][1]);
      if(count($response)>0){
        array_push($GLOBALS['errors'],$key);
        $GLOBALS['validations_errors'] = array_merge($GLOBALS['validations_errors'], $response);
      }
    }
  }
}


if (!function_exists('_'))
{
  function _($data)
  {
    return $data;
  }
}

function __autoload($class_name)
{
  //class directories
  $directories = array(
    'core/entity/',
    '../core/entity/',
    '../../core/entity/',
    '../../../core/entity/',
    'core/utils/',
    '../core/utils/',
    '../../core/utils/',
    '../../../core/utils/'
  );
  //for each directory
  foreach($directories as $directory)
  {
    //see if the file exsists
    if(file_exists($directory.$class_name . '.php'))
    {
      require_once($directory.$class_name . '.php');
      //only require the class once, so quit after to save effort (if you got more, then name them something else
      return;
    }
  }
}
$utils = new Utils();
$LoggedUser = $utils->ReturnSessionVar("LOGGED-USER");
$LoggedAssociate = $utils->ReturnSessionVar("LOGGED-USER");

$response_request = array();
