Ejemplo n.º 1
0
<?php

use app\traits\login;
use app\models\users;
use app\models\categories;
use app\models\albums;
use app\models\images;
use app\models\orders;
$app->get('/painel', function () use($app) {
    login::estaLogado('user_logado', $app);
    $users = users::where('name', $_SESSION['name']);
    $categories = categories::find('all');
    $albums = albums::find('all');
    $images = images::find('all');
    $orders = orders::find('all');
    $view = $app->view();
    $view->setTemplatesDirectory(TEMPLATE_ADMIN);
    $dados = array('pagina' => 'painel', 'name' => $_SESSION['name'], 'users' => $users, 'categories' => $categories, 'albums' => $albums, 'images' => $images, 'orders' => $orders);
    $app->render('layout.php', $dados);
});
Ejemplo n.º 2
0
        }
    }
});
$app->post('/area-do-cliente/invoice', function () use($app, $twig) {
    $logado = login::banLogado('user_logado', $app);
    if ($logado) {
        $customer = customers::where('name', $_SESSION['name']);
    } else {
    }
    $customer_id = $customer->id;
    $categories = \app\models\categories::listar();
    $album = albums::where('id', $_SESSION['album']);
    $price = $album->price;
    $attributes = array('customer_id' => $customer_id);
    orders::cadastrar($attributes);
    $order = \app\models\orders::find('last');
    $order_id = $order->id;
    $images = \app\models\images::all(array('conditions' => array('purchased = 1')));
    $granTotal = 0;
    foreach ($images as $image) {
        $image_id = $image->id;
        $amount = $app->request()->post("quant-{$image_id}");
        $total = $price * $amount;
        $att = array('order_id' => $order_id, 'image_id' => $image_id, 'amount' => $amount, 'total' => $total);
        item_order::cadastrar($att);
        $granTotal += $total;
        $reset = array('purchased' => 0, 'sale_count' => 1);
        $imageReset = new images();
        $imageReset->atualizar($image_id, $reset);
    }
    $items_order = item_order::all(array('conditions' => array("order_id = {$order_id}")));