Beispiel #1
0
 public static function pass($key = "")
 {
     return Alert::hasErrors($key) ? false : true;
 }
 public function validate()
 {
     // Check if the uploaded file is actually an image
     if (!in_array($this->mimeType, $this->allowedMimes)) {
         Alert::error("Image Type", "You may not upload that type of image.", 8);
     }
     // Check the file size of the image
     if ($this->filesize <= 0 or $this->filesize > $this->maxFileSize) {
         Alert::error("Image File Size", "The file size must be smaller than " . $this->maxFileSize . " bytes.", 3);
     }
     // Check the minimum and maximum width of the image
     if ($this->minWidth == $this->maxWidth and $this->width != $this->minWidth) {
         Alert::error("Image Width", "The image must be " . $this->minWidth . " pixels in width.");
     } else {
         if ($this->width < $this->minWidth) {
             Alert::error("Image Width", "The image must be " . $this->minWidth . " pixels or greater in width.");
         } else {
             if ($this->width > $this->maxWidth) {
                 Alert::error("Image Width", "The image must be " . $this->maxWidth . " pixels or less in width.");
             }
         }
     }
     // Check the minimum and maximum height of the image
     if ($this->minHeight == $this->maxHeight and $this->height != $this->minHeight) {
         Alert::error("Image Height", "The image must be " . $this->minHeight . " pixels in height.");
     } else {
         if ($this->height < $this->minHeight) {
             Alert::error("Image Height", "The image must be " . $this->minHeight . " pixels or greater in height.");
         } else {
             if ($this->height > $this->maxHeight) {
                 Alert::error("Image Height", "The image must be " . $this->maxHeight . " pixels or less in height.");
             }
         }
     }
     // Set invalid if there are any errors
     if (Alert::hasErrors()) {
         $this->valid = false;
         return false;
     }
     return true;
 }
    if (empty($_POST['location'])) {
        $alertClass->addAlert('Kuitin sijainti oli tyhjä', 'error');
    }
    if (empty($_POST['date'])) {
        $alertClass->addAlert('Kuitin päivämäärä oli tyhjä', 'error');
    }
    if (empty($_POST['sum'])) {
        $alertClass->addAlert('Kuitin summa oli tyhjä', 'error');
    }
    if (!is_numeric($_POST['id'])) {
        $alertClass->addAlert('Virheellinen kuitin tunnus', 'error');
    }
    if (!is_float($_POST['sum'])) {
        $alertClass->addAlert('Virheellinen kuitin summa', 'error');
    }
    if ($alertClass->hasErrors()) {
        $alertClass->redirect('/list_receipts.php');
    }
    $receipt = $receiptClass->getReceipt($_POST['id']);
    if ($receipt == null) {
        $alertClass->addAlert('Kuittia ei löytynyt', 'error');
        $alertClass->redirect('/list_receipts.php');
    }
    if ($receipt['userID'] !== $user['id']) {
        $alertClass->addAlert('Sinulla ei ole oikeuksia tähän kuittiin', 'error');
        $alertClass->redirect('/list_receipts.php');
    }
    $receipt->updateReceipt($_POST['id'], htmlspecialchars($_POST['location']), htmlspecialchars($_POST['date']), $_POST['sum']);
    $alertClass->addAlert('Kuitin päivittäminen onnistui!', 'success');
    $alertClass->redirect("/view_receipt.php?id={$_POST['id']}");
}