示例#1
0
 public function post()
 {
     try {
         $newManufacturer = (object) (['id' => null] + $_POST);
         v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->assert($_POST);
         if ($_FILES['files']['error'] == 4) {
             throw new Exception('O campo imagem é obrigatório');
         }
         if (empty($newManufacturer->manufacturer_featured)) {
             $newManufacturer->manufacturer_featured = null;
         }
         $this->collection->persist($newManufacturer);
         $this->collection->flush();
         foreach ($_FILES as $file) {
             $this->uploaderService->setFile($_POST['name'], 'files');
             $image = (object) ['name' => $this->uploaderService->getFile()->getNameWithExtension(), 'title' => $_POST['name'], 'type' => $this->uploaderService->getFile()->getMimetype(), 'manufacturer_id' => $newManufacturer->id];
             $this->imageCollection->persist($image);
             $this->imageCollection->flush();
             $this->uploaderService->upload();
         }
         header('HTTP/1.1 303 See Other');
         header('Location: /catalog/manufacturers');
     } catch (NestedValidationExceptionInterface $e) {
         return $this->get() + ['manufacturer/addManufacturer' => $newManufacturer, 'messages' => $e->findMessages(['name' => 'O nome deve ser entre 1 e 300 caracteres'])];
     }
 }
function OrderTable($ordersProducts, $connection)
{
    foreach ($ordersProducts as $arrayNumber => $orders_data) {
        echo "<tr class='product'>";
        foreach ($orders_data as $data_key => $data_value) {
            //echo "data-key: ".$data_key." data-value: ".$data_value."<br>";
            switch ($data_key) {
                case "product_id":
                    $product = \App\DB\Products::get($data_value, $connection);
                    $flag = v::arr()->notEmpty()->validate($product);
                    if ($flag) {
                        printProduct($product);
                    } else {
                        echo "<td class='deleted-product' colspan='2'>Товар удален из базы данных</td>";
                    }
                    break;
                case "amount":
                    echo "<td data-amount='{$data_value}'>" . $data_value . "</td></tr>";
                    break;
                default:
                    break;
            }
        }
    }
}
示例#3
0
 private function send($type, array $to, $subject, $template, $params)
 {
     if (!Validator::arr()->each(Validator::email())->validate($to)) {
         throw new InvalidArgumentException('to', 'format_invalid');
     }
     $html = Application::get('templating')->render($template, array_merge(['SUBJECT' => $subject], $params));
     $this->provider->send($type, $to, $subject, $html);
 }
示例#4
0
 /**
  * Set the data content of Response, now the $data variable can be a array or a 
  * ArrayObject instaces, in the future I provide to allow to set a StandardClass obj
  * 
  * @param mixed $data, the value of data
  * @return 
  */
 public function setData($data)
 {
     if (Validator::arr()->validate($data)) {
         $this->data = $data;
     } else {
         throw new InvalidArgumentException("make sure you have passed an array or ArrayObject istances for {$data} parameter", 1);
     }
 }
示例#5
0
 public static function checkUsernameExists(Connection $connection, $username)
 {
     $stmt = $connection->prepare('SELECT * FROM `users`
     WHERE `user_name` = :user_name');
     $stmt->execute([':user_name' => $username]);
     $result = $stmt->fetch(\PDO::FETCH_ASSOC);
     if (v::arr()->notEmpty()->validate($result)) {
         return true;
     } else {
         return false;
     }
 }
示例#6
0
 protected function postChild($categoryId)
 {
     try {
         v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->key('parent_category', v::notEmpty()->int()->equals($categoryId))->assert($_POST);
         $newCategory = (object) (['id' => null] + $_POST);
         $this->collection->persist($newCategory);
         $this->collection->flush();
         header('HTTP/1.1 303 See Other');
         header('Location: ' . $_SERVER['REQUEST_URI']);
     } catch (NestedValidationExceptionInterface $e) {
         return ['category/editCategory' => $editProduct, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars'])];
     }
 }
示例#7
0
 public function post()
 {
     try {
         $newCategory = (object) (['id' => null] + $_POST);
         v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->assert($_POST);
         $this->collection->persist($newCategory);
         $this->collection->flush();
         header('HTTP/1.1 303 See Other');
         header('Location: /catalog/categories');
     } catch (NestedValidationExceptionInterface $e) {
         return $this->get() + ['category/addCategory' => $newCategory, 'messages' => $e->findMessages(['name' => 'O nome deve ser entre 1 e 300 caracteres'])];
     }
 }
示例#8
0
 public function post()
 {
     try {
         v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->key('description', v::string()->length(1, 300))->key('internal_code', v::string()->length(1, 30))->key('about', v::string())->assert($_POST);
         $newProduct = (object) (['id' => null] + $_POST);
         $this->collection->persist($newProduct);
         $this->collection->flush();
         header('HTTP/1.1 303 See Other');
         header('Location: ' . $this->singleProduct->createUri($newProduct->id));
         return $this->get();
     } catch (NestedValidationExceptionInterface $e) {
         return ['category/singleProduct' => $editProduct, 'messages' => $e->findMessages(['name' => 'Name must have between 1 and 300 chars', 'internal_code' => 'Internal Code must have between 1 and 300 chars', 'description' => 'Description must a maximum of 300 chars', 'enabled' => 'Could not enable product', 'about' => 'Invalid description'])];
     }
 }
示例#9
0
 public function post()
 {
     try {
         v::arr()->key('name', v::string()->notEmpty()->length(1, 300))->assert($_POST);
         $newCategory = (object) (['id' => null] + $_POST);
         $this->collection->persist($newCategory);
         $this->collection->flush();
         header('HTTP/1.1 303 See Other');
         header('Location: ' . $this->singleFeature->createUri($newCategory->id));
         return $this->get();
     } catch (NestedValidationExceptionInterface $e) {
         return $e->findMessages(['name']);
     }
 }
示例#10
0
 if (!isset($params['address']) || !Validation::string()->length(null, 50)->validate($params['address'])) {
     array_push($invalids, 'address');
 }
 if (!isset($params['deliver']) || !Validation::int()->min(0, true)->max(1, true)->validate($params['deliver'])) {
     array_push($invalids, 'deliver');
 }
 if (!isset($params['timeFrom']) || !Validation::date('H:i')->validate($params['timeFrom'])) {
     array_push($invalids, 'timeFrom');
 }
 if (!isset($params['timeTo']) || !Validation::date('H:i')->validate($params['timeTo'])) {
     array_push($invalids, 'timeTo');
 }
 if (!isset($params['paid']) || !Validation::int()->min(0, true)->max(1, true)->validate($params['paid'])) {
     array_push($invalids, 'paid');
 }
 if (!isset($params['items']) || !Validation::arr()->length(1, null)->validate($params['items'])) {
     array_push($invalids, 'items');
 }
 foreach ($params['items'] as $index => $product) {
     if (!isset($product['productId']) || !Validation::int()->min(0, true)->validate($product['productId'])) {
         array_push($invalids, 'productId-' . $index);
     }
     if (!isset($product['plu']) || !Validation::int()->max(999999)->validate($product['plu'])) {
         array_push($invalids, 'plu-' . $index);
     }
     if (!isset($product['amount']) || !Validation::int()->validate($product['amount'])) {
         array_push($invalids, 'amount-' . $index);
     }
 }
 if (empty($invalids)) {
     $queryValues = array('userId' => $params['userId'], 'name' => $params['name'], 'phone' => $params['phone'], 'address' => $params['address'], 'dateFrom' => date('Y-m-d'), 'timeFrom' => $params['timeFrom'], 'dateTo' => date('Y-m-d'), 'timeTo' => $params['timeTo'], 'paid' => $params['paid'], 'deliver' => $params['deliver'], 'src' => 'orders/' . date('Y-m-d-H-i-U') . '.txt');
示例#11
0
                        <div class="breadcrumbs">
                            <a href="/">Магазин</a>
                            <p>Удаление категории</p>
                        </div>
                        <div class="row clearfix">
                            <?php 
use Respect\Validation\Validator as v;
include_once $src_path . 'autoload.php';
$connection = new \App\DB\Connection('root', '');
if (isset($_GET['id'])) {
    $id = $_GET['id'];
} else {
    $id = 'error';
}
$category = \App\DB\Categories::get($id, $connection);
$flag = v::arr()->notEmpty()->validate($category);
if (!$flag) {
    echo "Такой категории не существует";
} else {
    $deleteCategory = \App\DB\Categories::deleteCategory($id, $connection);
    if ($deleteCategory) {
        $deleteCategoryId = \App\DB\Products::deleteCategoryId($id, $connection);
    }
    // Back to previous page
    header('Location: ' . \App\Utilities\Options::URL . '/edit-cat-all');
}
?>
                        </div>
                    </div>
                </div>
            </div>
示例#12
0
}
?>
</p>
                    </div>
                    <div class="row clearfix">
                        <?php 
if (empty($_POST)) {
    if (!$flag) {
        echo "<h2>Такой категории не существует";
    } else {
        include_once 'templates/_edit_category.php';
    }
} else {
    $errors = [];
    $catName = catNameValidate($errors, $_POST['category']);
    if (!v::arr()->notEmpty()->validate($errors)) {
        // Check if this category already exists
        $flag = ifCatExists($connection, $catName);
        if ($flag) {
            include_once "templates/_edit_category.php";
            echo "<p>Такая категория уже существует</p>";
        } else {
            $newCategory = \App\DB\Categories::update($id, $catName, $connection);
            header('Refresh: 0; url=/edit-cat-all');
        }
    } else {
        include_once "templates/_edit_category.php";
        include_once "templates/_form-errors.php";
    }
}
?>
<?php

use Respect\Validation\Validator as v;
include_once __DIR__ . '/templates/_header.php';
include_once __DIR__ . '/templates/_top_menu.php';
$flag = false;
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    $id = $_GET['id'];
    $order = \App\DB\Orders::getById($id, $connection);
    if (v::arr()->notEmpty()->validate($order)) {
        $flag = true;
    }
}
?>

<section>
    <div class="container">
        <div class="row clearfix">
            <!-- боковое меню -->
            <?php 
include_once '/templates/_menu.php';
?>
            <div class="column column9">
                <div class="catalog">
                    <!-- хлебные крошки -->
                    <div class="breadcrumbs">
                        <a href="/">Магазин</a>
                        <p>Просмотр заказа</p>
                    </div>
                    <div class="row orders clearfix">
                        <?php 
use Respect\Validation\Validator as v;
$category = \App\DB\Categories::get($products[$i]['category_id'], $connection);
?>
<table class="table-products">
<tbody>
<tr>
    <td><?php 
echo $products[$i]['id'];
?>
</td>
    <td><?php 
echo $products[$i]['title'];
?>
</td>
    <td><?php 
if (v::arr()->notEmpty()->validate($category)) {
    echo $category['title'];
} else {
    echo "Не указана";
}
?>
</td>
    <td><a href="<?php 
echo \App\Utilities\Options::URL;
?>
/edit/?id=<?php 
echo $products[$i]['id'];
?>
" class='edit adm-btn'>Изменить</a></td>
    <td>
        <a href="<?php 
示例#15
0
 /**
  * This halde every non-declared class method called on XenConnectionObj
  *
  * @param mixed $name the name of method and $args the argument of method, 
  *         
  *
  * @return XenResponse
  */
 function __call($name, $args)
 {
     if (!Validator::arr()->validate($args)) {
         $args = array();
     }
     list($mod, $method) = explode('__', $name);
     $response = $this->xenrpc_parseresponse($this->xenrpc_request($this->getUrl(), $this->xenrpc_method($mod . '.' . $method, array_merge(array($this->getSessionId()), $args))));
     return $response;
 }
示例#16
0
文件: Valid.php 项目: tourze/base
 /**
  * 检测输入是否为数组
  *
  * @param mixed $value
  * @return bool
  */
 public static function isArray($value)
 {
     return Validator::arr()->validate($value);
 }
示例#17
0
<?php

define('MAX_SIZE', 3 * 1024 * 1024);
require "vendor/autoload.php";
use Respect\Validation\Validator as v;
$url = $_GET['url'];
$url_parts = parse_url($url);
//error_log(print_r($url_parts,1));
// check valid url.
if (!v::arr()->key('scheme', v::startsWith('http'))->key('host', v::domain())->key('path', v::string())->validate($url_parts)) {
    die_and_log($status = 400, 'invalid url', $url);
}
// head access
$c = new Curl();
$c->setHeader('X-Forwarded-For', getRemoteIP());
$c->setOpt(CURLOPT_NOBODY, true);
$c->setOpt(CURLOPT_RETURNTRANSFER, true);
$c->error(function () {
    die_and_log($status = 500, "head request error");
});
$c->get($url);
error_log($url);
//error_log(print_r($c->response_headers,1));
// check head res
$length = null;
$content_type = null;
foreach ($c->response_headers as $header) {
    if (preg_match("/\\AContent-Length/i", $header)) {
        $length = (int) explode(":", $header, 2)[1];
    } else {
        if (preg_match("/\\AContent-Type/i", $header)) {
示例#18
0
            <div class="breadcrumbs">
                <a href="/">Магазин</a>
                <p>Удаление товара</p>
            </div>
            <div class="row clearfix">
<?php 
use Respect\Validation\Validator as v;
include_once $src_path . 'autoload.php';
$connection = new \App\DB\Connection('root', '');
if (isset($_GET['id'])) {
    $id = $_GET['id'];
} else {
    $id = 'error';
}
$product = \App\DB\Products::get($id, $connection);
$flag = v::arr()->notEmpty()->validate($product);
if (!$flag) {
    echo "Такого товара не существует";
} else {
    $deleteProduct = \App\DB\Products::deleteProduct($id, $connection);
    // Back to previous page
    if (isset($_SERVER['HTTP_REFERER'])) {
        header('Location: ' . $_SERVER['HTTP_REFERER']);
    } else {
        header('Location: / ');
    }
}
?>
            </div>
        </div>
    </div>
 /**
  * @return boolean
  * @param stdClass $user
  */
 public function isValid($user)
 {
     $userValidator = v::attribute('ID', v::numeric())->attribute('USUARIO', v::string()->notEmpty()->noWhitespace())->attribute('NOME', v::string()->notEmpty())->attribute('EMAIL', v::email())->attribute('CPF', v::cpf())->attribute('STATUS', v::numeric())->attribute('UNIDADES', v::arr());
     return $userValidator->validate($user);
 }