Exemplo n.º 1
0
 /**
  * @param array id => id {@see ManyToMany::$injectedValue}
  * @return array id => id will be set as {@see ManyToMany::$injectedValue}
  */
 public function validateInjectedValue($injectedValue)
 {
     if ($this->meta->getWhereIsMapped() !== RelationshipMetaDataToMany::MAPPED_THERE) {
         if (ValidationHelper::isValid(array('array'), $injectedValue) and $injectedValue) {
             $injectedValue = array_combine($injectedValue, $injectedValue);
         } else {
             $injectedValue = array();
         }
         return $injectedValue;
     }
 }
Exemplo n.º 2
0
// range, range_start, range_end, desc
$db = new Db();
//$t = new Template("templates/print/print_report_time.tpl.html");
//$t = new Template("templates/print/print_single_booking.tpl.html");
$error = "";
$range = (int) $_GET["range"];
$range_start = urldecode($_GET["range_start"]);
$range_end = urldecode($_GET["range_end"]);
$desc = urldecode($_GET["desc"]);
if ($range < 10 || $range > 50) {
    $error = "Preset should be a number between 1 and 4, you had {$range}.";
} else {
    if ($range == 50) {
        // input range
        $validStart = $range_start && ValidationHelper::isMySqlDateTime($range_start, false);
        $validEnd = $range_end && ValidationHelper::isMySqlDateTime($range_end, false);
        $range_start_ss = $range_start . " 00:00:00";
        $range_end_ss = $range_end . " 00:00:00";
        if ($range_start == "") {
            $error = "Please select a start date or enter one in the format YYYY-MM-DD hh:mm";
        } else {
            if ($validStart !== true) {
                $error = $validStart;
            } else {
                if ($range_end == "") {
                    $error = "Please select an end date or enter one in the format YYYY-MM-DD hh:mm";
                } else {
                    if ($validEnd !== true) {
                        $error = $validEnd;
                    }
                }
Exemplo n.º 3
0
 $validDepart = ValidationHelper::isMySqlDateTime($depart . ":00", true);
 $validArrive = ValidationHelper::isMySqlDateTime($arrive . ":00", true);
 $validSuggestedTime = $suggested_time != 0;
 if ($first_name == "") {
     $error = "Please enter your first name";
     $focusId = "firstname";
 } else {
     if ($last_name == "") {
         $error = "Please enter your last name";
         $focusId = "lastname";
     } else {
         if ($email == "") {
             $error = "Please enter your email address";
             $focusId = "email";
         } else {
             if (!ValidationHelper::isEmail($email)) {
                 $error = "Please enter a valid email address";
                 $focusId = "email";
             } else {
                 if ($phone == "") {
                     $error = "Please enter your phone number";
                     $focusId = "phone";
                 } else {
                     if ($make == "") {
                         $error = "Please enter your vehicle's make and model";
                         $focusId = "make";
                         $showFormPage = 2;
                     } else {
                         if ($reg == "") {
                             $error = "Please enter your vehicle's registration";
                             $focusId = "reg";
 /**
  * Nastavi parametr na hodnotu.
  * @param string
  * @param mixed
  * @return void
  * @throws NotValidException
  */
 private final function setValueHelper($name, $value, $rule)
 {
     if ($value === IEntity::DEFAULT_VALUE) {
         $value = $this->getDefaultValueHelper($name, $rule);
     }
     if ($rule['relationship'] === MetaData::ManyToOne or $rule['relationship'] === MetaData::OneToOne) {
         if ($value instanceof IEntity) {
             if ($model = $this->getModel(false)) {
                 $repo = $model->getRepository($rule['relationshipParam']);
                 $repo->attach($value);
             } else {
                 if ($model = $value->getModel(false)) {
                     $this->fireEvent('onAttachModel', NULL, $model);
                 }
             }
         } else {
             if ($value !== NULL) {
                 $id = (string) $value;
                 $repo = $this->getModel()->getRepository($rule['relationshipParam']);
                 $value = $repo->getById($id);
                 if (!$value and !isset($rule['types']['null'])) {
                     $type = implode('|', $rule['types']);
                     throw new EntityNotFoundException("Entity({$type}) '{$id}' not found in `" . get_class($repo) . "` in " . get_class($this) . "::\${$name}");
                 }
             }
         }
     } else {
         if (isset($rule['injection'])) {
             if (!isset($this->values[$name]) or !$this->values[$name] instanceof IEntityInjection) {
                 $xValues = isset($this->values[$name]) ? $this->values[$name] : NULL;
                 $tmp = $rule['injection']->invoke($this, $xValues);
                 if ($xValues !== $value) {
                     $tmp->setInjectedValue($value);
                 }
             } else {
                 $tmp = $this->values[$name];
                 $tmp->setInjectedValue($value);
             }
             $value = $tmp;
         }
     }
     if (isset($rule['enum'])) {
         if (in_array($value, $rule['enum']['constants'], true)) {
         } else {
             if (($tmp = array_search($value, $rule['enum']['constants'])) !== false) {
                 $value = $rule['enum']['constants'][$tmp];
             } else {
                 if (isset($rule['types']['null']) and $value === NULL) {
                     $value = NULL;
                 } else {
                     throw new NotValidException([$this, $name, $rule['enum']['original'], $value]);
                 }
             }
         }
     }
     if (!ValidationHelper::isValid($rule['types'], $value)) {
         throw new NotValidException([$this, $name, "'" . implode('|', $rule['types']) . "'", $value]);
     }
     $oldValue = isset($this->values[$name]) ? $this->values[$name] : NULL;
     $this->values[$name] = $value;
     $this->valid[$name] = true;
     $this->changed[$name] = true;
     if ($rule['relationship'] === MetaData::ManyToOne or $rule['relationship'] === MetaData::OneToOne) {
         $meta = $rule['relationshipParam'];
         if ($childParam = $meta->getChildParam()) {
             $oldEntity = $oldValue;
             $newEntity = $value;
             $changed = false;
             if ($oldEntity instanceof IEntity and $newEntity instanceof IEntity) {
                 $changed = $oldEntity !== $newEntity;
             } else {
                 if ($newEntity instanceof IEntity and isset($newEntity->id)) {
                     $changed = (string) $newEntity->id !== (string) $oldEntity;
                 } else {
                     if ($newEntity instanceof IEntity) {
                         if ($oldEntity !== NULL) {
                             $repo = $this->getModel()->getRepository($meta->getRepository());
                             $oldEntity = $repo->getById($oldEntity);
                         }
                         $changed = $oldEntity !== $newEntity;
                     } else {
                         if ($newEntity === NULL) {
                             if (!$oldEntity instanceof IEntity and $oldEntity !== NULL) {
                                 $repo = $this->getModel()->getRepository($meta->getRepository());
                                 $oldEntity = $repo->getById($oldEntity);
                             }
                             $changed = $oldEntity !== NULL;
                         }
                     }
                 }
             }
             if ($changed) {
                 if (!$oldEntity instanceof IEntity and $oldEntity !== NULL) {
                     $repo = $this->getModel()->getRepository($meta->getRepository());
                     $oldEntity = $repo->getById($oldEntity);
                 }
                 if ($rule['relationship'] === MetaData::ManyToOne) {
                     if ($oldEntity) {
                         $oldEntity->{$childParam}->remove($this, 'handled by ManyToOne');
                     }
                     if ($newEntity) {
                         $newEntity->{$childParam}->add($this);
                     }
                 } else {
                     if ($rule['relationship'] === MetaData::OneToOne) {
                         if ($oldEntity and $oldEntity->__isset($childParam) and $oldEntity->__get($childParam) === $this) {
                             $oldEntity->__set($childParam, NULL);
                         }
                         if ($newEntity and (!$newEntity->__isset($childParam) or $newEntity->__get($childParam) !== $this)) {
                             $newEntity->__set($childParam, $this);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
<?php

require_once "classes/datetimewrapper.class.php";
require_once "classes/validationhelper.class.php";
$error = "";
$bookings_data = "";
$arrival_value = "";
$departure_value = "";
$quote = 0;
if ($_POST) {
    $arrival_value = $_POST['arrive'];
    $departure_value = $_POST['depart'];
    $valid_arrival = ValidationHelper::isMySqlDateTime($arrival_value, true);
    $valid_departure = ValidationHelper::isMySqlDateTime($departure_value, true);
    if ($valid_arrival !== true) {
        $error = $valid_arrival;
    } else {
        if ($valid_departure !== true) {
            $error = $valid_departure;
        } else {
            $bookings_data = '?' . http_build_query(array('arrive' => $arrival_value, 'depart' => $departure_value));
            $arr = new DateTimeWrapper(0, $arrival_value);
            $dep = new DateTimeWrapper(0, $departure_value);
            $arr_num = $arr->getInt();
            $dep_num = $dep->getInt();
            if ($arr_num > $dep_num) {
                $diff = $arr_num - $dep_num;
            } else {
                $diff = $dep_num - $arr_num;
            }
            $s_in_halfday = 3600 * 12;
Exemplo n.º 6
0
require_once "classes/userhelper.class.php";
require_once "classes/sessionhelper.class.php";
require_once "classes/db.class.php";
require_once "classes/utils.class.php";
require_once "classes/validationhelper.class.php";
require_once "classes/constants.class.php";
$focusId = "email";
$db = new Db();
$t = new Template("templates/admin_page.tpl.html");
$tInner = new Template("templates/forgot_password.tpl.html");
$showForm = true;
$error = "";
$message = "";
if ($_POST) {
    $emailValue = trim($_POST["email"]);
    $emailFilteredValue = ValidationHelper::isEmail($emailValue);
    if ($emailValue == "" || $emailValue == FormFieldTexts::EMAIL) {
        $error = "Please enter email";
        $focusId = "email";
    } else {
        if ($emailFilteredValue === false) {
            $error = "Please enter a valid email address";
            $focusId = "email";
        } else {
            if (!UserHelper::emailExists($db, $emailFilteredValue)) {
                $error = "The email address you entered has not been registered: {$emailFilteredValue}";
                $focusId = "email";
            } else {
                // all good
                $showForm = false;
                $emailResult = UserHelper::forgotPassword($db, $emailFilteredValue);
Exemplo n.º 7
0
        }
    }
}
$prefillEmail = $_POST && $_POST["email"] ? $_POST["email"] : ($_GET && $_GET["email"] ? $_GET["email"] : "");
$prefillEmail = $prefillEmail ? $prefillEmail : CookieHelper::getLoginUser();
$focusId = $prefillEmail ? "password" : "email";
if ($_POST) {
    // posted variables from this page
    //  action form
    $success = true;
    require_once "classes/validationhelper.class.php";
    $required = array();
    $required[] = array("key" => "email", "msg" => "Please enter: email");
    $required[] = array("key" => "password", "msg" => "Please enter: Password");
    foreach ($required as $value) {
        if (!ValidationHelper::required($value["key"], $_POST)) {
            $message = "<span class=\"feedbackNegative\">" . $value["msg"] . "</span>";
            $focusId = $value["key"];
            $success = false;
            break;
        }
    }
    // connect to db
    if ($success) {
        $row = UserHelper::getUserRow($db, $_POST["email"], md5($_POST["password"]));
        if ($row === false) {
            $success = false;
            $message = "<span class=\"feedbackNegative\">Invalid login details</span>";
        } else {
            // restart the session, so there can never be an overlap on one machine.
            // all operations are checked atomically