public function getCategory($id)
 {
     $result['categories'] = $this->category->getCategories();
     $result['title'] = 'Shop';
     $result['currentCategory'] = $id;
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     if ($result['isEditor']) {
         $result['products'] = $this->product->getProductsForCategoryWitnUnavailable($id);
     } else {
         $result['products'] = $this->product->getProductsForCategory($id);
     }
     $all_promotion = $this->promotion->getHighestActivePromotion();
     foreach ($result['products'] as $k => $p) {
         $productPromotion = max($all_promotion['discount'], $p['discount'], $p['category_discount']);
         if (is_numeric($productPromotion)) {
             $result['products'][$k]['promotion_price'] = $p['price'] - $p['price'] * ($productPromotion / 100);
         }
     }
     View::make('index', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->appendTemplateToLayout('catMenu', 'side_bar/category_menu')->render();
 }
 public function getUsers()
 {
     $result['users'] = $this->user->getUsersWithRoles();
     $result['title'] = 'Shop';
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     View::make('admin.roles', $result);
     View::appendTemplateToLayout('topBar', 'top_bar/user');
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function delete($id)
 {
     if (Auth::isUserInRole(array('admin')) || $this->comment->getComment($id)['user_id'] == Auth::getUserId()) {
         if ($this->comment->delete($id) !== 1) {
             Session::setError('something went wrong');
             Redirect::back();
         }
         Session::setMessage('Done');
         Redirect::back();
     }
     Redirect::back();
 }
 public function getAll()
 {
     $result['promotions'] = $this->promotion->getPromotions();
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     View::make('promotion.promotions', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function getAll()
 {
     $cart = array();
     if (Session::containKey('cart')) {
         $cart = Session::get('cart');
     }
     $result['title'] = 'Shop';
     $result['products'] = $this->getProductsFromCart($cart);
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     $result['user_cash'] = $this->user->getUserMoney(Auth::getUserId());
     View::make('cart', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->appendTemplateToLayout('catMenu', 'side_bar/category_menu')->render();
 }
 public function getProducts($id)
 {
     if (!(Auth::isUserInRole(array('admin')) || $id == Auth::getUserId())) {
         Redirect::back();
     }
     $result['products'] = $this->user->getProducts($id);
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     View::make('user.products', $result);
     View::appendTemplateToLayout('topBar', 'top_bar/user');
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
 public function dispatch()
 {
     $uri = $this->request->getURI();
     $uriParams = array_filter(explode('/', $uri), 'strlen');
     $controllerName = '';
     $controllerMethod = '';
     $paramsFromGET = array();
     foreach (Route::getRouters() as $route) {
         $paramsFromGET = array();
         if ($route['method'] != $_SERVER['REQUEST_METHOD']) {
             continue;
         }
         if (in_array('auth', explode('|', $route['details']['before']))) {
             if (!Auth::isAuth()) {
                 continue;
             }
         }
         if (!Auth::isUserInRole(array_filter(explode('|', $route['details']['roles']), 'strlen'))) {
             continue;
         }
         $routeParams = array_filter(explode('/', $route['url']), 'strlen');
         $nonRequiredFieldsForRoute = $this->getNonRequiredFieldsCount($routeParams);
         if (count($uriParams) < count($routeParams) - $nonRequiredFieldsForRoute || count($uriParams) > count($routeParams)) {
             continue;
         }
         for ($i = 0; $i < count($uriParams); $i++) {
             if (!Common::startsWith($routeParams[$i], '{') && !Common::endsWith($routeParams[$i], '}')) {
                 if ($uriParams[$i] != $routeParams[$i]) {
                     continue 2;
                 }
             } else {
                 if (!$this->isParameterValid($uriParams[$i], $routeParams[$i])) {
                     continue 2;
                 }
                 $paramName = $this->getParameterName($routeParams[$i]);
                 $paramsFromGET[$paramName] = $uriParams[$i];
             }
             if (count($uriParams) - 1 == $i) {
                 $controllerData = explode('@', $route['details']['use']);
                 $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $controllerData[0];
                 $controllerMethod = $controllerData[1];
                 break 2;
             }
         }
         $paramsFromGET = array();
         if (in_array('csrf', explode('|', $route['details']['before']))) {
             if (!CSRF::validateToken()) {
                 continue;
             }
         }
     }
     if ($controllerMethod === '') {
         if (App::getInstance()->getConfig()->app['enable_default_routing']) {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . $uriParams[0] . 'Controller';
             $controllerMethod = $uriParams[1];
             $r = new \ReflectionMethod($controllerName, $controllerMethod);
             $params = $r->getParameters();
             $index = 2;
             foreach ($params as $param) {
                 $paramsFromGET[$param->name] = $uriParams[$index];
                 $index++;
             }
             for ($i = $index; $i < count($uriParams); $i++) {
                 $paramsFromGET[$i] = $uriParams[$i];
             }
         } else {
             $controllerName = App::getInstance()->getConfig()->app['controllers_namespace'] . '\\' . App::getInstance()->getConfig()->app['default_controller'];
             $controllerMethod = App::getInstance()->getConfig()->app['default_method'];
         }
     }
     $requestInput = $this->bindDataToControllerMethod($paramsFromGET, $controllerName, $controllerMethod);
     $controller = new $controllerName();
     $controller = DependencyProvider::injectDependenciesToController($controller);
     call_user_func_array(array($controller, $controllerMethod), $requestInput);
     Session::setOldInput(InputData::getInstance()->getPost());
 }
 public function getEdit($id)
 {
     $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin'));
     $result['isAdmin'] = Auth::isUserInRole(array('admin'));
     if ($result['isEditor']) {
         $result = array('product' => $this->product->getProductWitnUnavailable($id));
     } else {
         $result = array('product' => $this->product->getProduct($id));
     }
     $result['title'] = 'Shop';
     $result['action'] = '/product/edit/' . $result['product']['id'];
     $result['submit'] = 'edit';
     $categories = $this->category->getCategories();
     foreach ($categories as $c) {
         $currentCategory = array();
         $currentCategory['text'] = $c['name'];
         $currentCategory['options'] = array('value' => $c['id']);
         if ($id == $c['id']) {
             $currentCategory['options']['selected'] = 'true';
         }
         $result['categories'][] = $currentCategory;
     }
     View::make('product.add', $result);
     if (Auth::isAuth()) {
         View::appendTemplateToLayout('topBar', 'top_bar/user');
     } else {
         View::appendTemplateToLayout('topBar', 'top_bar/guest');
     }
     View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->render();
 }
예제 #9
0
?>
</h3>
                    <h4>Floor: <?php 
echo $estate->floor;
?>
</h4>
                    <h4><?php 
echo $estate->is_furnished ? 'Furnished' : 'Unfurnished';
?>
</h4>
                    <h4>Phone: <?php 
echo $estate->phone;
?>
</h4>
                    <?php 
if (Auth::isUserInRole(array('admin'))) {
    ?>
                        <a class="btn btn-primary" href="<?php 
    echo Common::getBaseURL();
    ?>
/admin/estate/<?php 
    echo $estate->id;
    ?>
/edit">Edit</a>
                        <a onclick="return confirm('Are your sure?')" class="btn btn-danger" href="<?php 
    echo Common::getBaseURL();
    ?>
/admin/estate/<?php 
    echo $estate->id;
    ?>
/delete">Delete</a>